Lecture Notes for Advanced Programming II

15 February 2001 - Debugging


  1. debugging

    1. some technology, some psychology

    2. technology - unchecked array access; explicit dynamic storage management; complex rules

    3. psychology - hard to see your mistakes; hard to face your mistakes

    4. terminology - there's the cause, then there's the symptoms

  2. understand the symptoms

    1. make sure it's a problem - proper behavior, fast execution

    2. make sure you know what the problem is - sometimes it's obvious, sometimes it isn't

  3. look for clues

    1. what data causes the symptoms

    2. what was changed last - use source code revision; sccs, rcs, cvs

  4. create your own clues

    1. use assert statements to check arguments and results

      1. #include <cassert>
        void set(unsigned x)
          assert(x < x_extent);
        

      2. can also use #include <assert.h>

    2. program defensively

      1. 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() }
        

      2. always have a default switch branch

    3. use debugging print statements

  5. finding the cause

    1. know your mistakes

  6. debuggers and other tools

    1. know how to use the debugger - just the basics; stack trace, stop, print

    2. enable everything on the compiler - ansi standards, extra checks and warnings, debugging code

    3. use other tools - lint, purify, malloc debug libraries, other languages


This page last modified on 27 February 2001.