Lecture Notes for Advanced Programming II
15 February 2001 - Debugging
- debugging
- some technology, some psychology
- technology - unchecked array access; explicit dynamic storage
management; complex rules
- psychology - hard to see your mistakes; hard to face your mistakes
- terminology - there's the cause, then there's the symptoms
- understand the symptoms
- make sure it's a problem - proper behavior, fast execution
- make sure you know what the problem is - sometimes it's obvious,
sometimes it isn't
- look for clues
- what data causes the symptoms
- what was changed last - use source code revision; sccs, rcs, cvs
- create your own clues
- use assert statements to check arguments and results
-
#include <cassert>
void set(unsigned x)
assert(x < x_extent);
- can also use
#include <assert.h>
- program defensively
-
if (line.is_horizontal()) // blah blah blah
else if (line.is_vertical()) // blah blah blah
else { cerr << "line isn't horizontal or vertical\n" ; abort() }
- always have a default switch branch
- use debugging print statements
- finding the cause
- know your mistakes
- debuggers and other tools
- know how to use the debugger - just the basics; stack trace, stop,
print
- enable everything on the compiler - ansi standards, extra checks and
warnings, debugging code
- use other tools - lint, purify, malloc debug libraries, other languages
This page last modified on 27 February 2001.