lecture27 - CIS 450 Computer Architecture and Organization...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
CIS 450 – Computer Architecture and Organization Lecture 27: Debugging and Profiling Mitch Neilsen (neilsen@ksu.edu ) 219D Nichols Hall
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Topics ± Defensive programming ± Know your bugs ± Debugging tricks ± Overview of available tools
Background image of page 2
Defensive Programming 5-20 Bugs per 1000 lines of code (InfoWorld, Oct. 2003) Programmers must anticipate bugs, even if your code is bug-free. How? ± Check for errors at all possible opportunities: detecting bugs early eases finding the root cause. ± Maintain a clean, modular structure with documented interfaces: goto’s, global variables, long-jumps, clever/obscure macros , etc. are considered dangerous. ± Anticipate common errors: buffer overrun, off-by-one,… ± Consider corner cases: 0/1 loops, empty lists, … ± Provide debugging support in your program: debugging messages, data structure checkers (like heap checkers for malloc ), print- function for complicated structures, test-case generators, … ± Add redundancy ± Maintain test cases for regression testing: use version control systems (CVS, RCS, BitKeeper, Subversion, …) ± Use all the help you can get: heed compiler warnings, use debuggers, verifyers, IDE’s, code generators, high-level tools,…
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Assertions Explicitly state what you expect to be true in your program: invariants, argument ranges, etc. Assert-macro (ISO9899, ANSI C): Generates no tests if “NODEBUG” is defined #include <assert.h> #define MAX_ARRAY_SIZE 10 void foo(double a[], double b[], int n) { int i; double *a_ptr = a, *b_ptr = b; assert(n > 1 & n for (i = n; --i;) { /* . .. */ a_ptr++; /* . .. */ b_ptr++; } assert(a_ptr == &(a[n]) && b_ptr == &(b[n])); }
Background image of page 4
Assertions (cont.) Reasons for using assertions: ± Catch failures early ± Verify and document interfaces ± Express invariants to aid in debugging
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Debug Messages Use of cpp -macros and conditional compilation: #ifdef DEBUG extern int debug_level; #define DEBUG_PRINT(level, format, args. ..) \ { if((level) < debug_level) {\ fprintf(stderr, “DEBUG_PRINT line=%d in file='%s':\n",\ __LINE__, __FILE__);\ fprintf(stderr, format , ## args);}\ } #else #define DEBUG_PRINT(level, format, args. ..) #endif foo(int a, int b) { DEBUG_PRINT(0, "foo(a=%d, b=%d) started\n", a, b); }
Background image of page 6
Add Redundancy Engineering tradeoff between robustness and performance. Extreme case Google: ± Data structures have software maintained checksums ± Distributed system (> 10,000 machines): need fail-stop characteristic, handle failures at higher level Simple Cases: ± Count item and compare to pointer difference (see assertion example) ± Compute simple, inexpensive invariants (for example: the sum of allocated and free memory objects in the heap ought to equal the heap size)
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Integrated Development Environment Program-editor (with syntax support), version control system, compiler, debugger, build-system, profiler, graphical user interface, and integration = IDE ± Microsoft’s Visual Studio ± IBM’s Eclipse project ± Kdevelop (open source) ± Pro: convenience ± Con: often platform dependent ± No silver bullet
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/09/2008 for the course CIS 450 taught by Professor Neilsen,mitch during the Spring '08 term at Kansas State University.

Page1 / 31

lecture27 - CIS 450 Computer Architecture and Organization...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online