Bugs and Debugging
Bugs. Ugh. Nobody likes them but every programmer will surely encounter them, regardless of how much experience he or she has. A bug is an error in our code, logical or otherwise, such that the behavior is not quite what we expect, whether it be that we allow inputs from users that cause our program to fail, that our program suffers a segmentation fault, or that our program crashes every time we run it. In this section, we explore techniques for rooting out bugs in our programs using certain tools, in particular eprintf()
, a CS50 library function; help50
, a command-line tool that helps us understand messages from clang and other tools; and debug50
, a graphical debugger built upon a popular command-line debugger called gdb.
-
Lecture (Part 0)
-
Lecture (Part 1)
-
Notes
-
Thought Questions
debug50
is noticeably more complex than simply writing printf statements in our code. Why should we bother using it? What advantages and/or disadvantages exist there?- What types of bugs/logical errors seem particularly easy to make?
- What other kinds of bugs are there besides logical bugs? (Bugs where your program works, but doesn’t have the desired effect?)
- What types of bugs have you encountered in terms of compiler messages you don’t understand?
-
Problems