Debugging (1) Admin * Welcome back from break! * Sorry about the pre-break breaks * I should be available the rest of the semester, and maybe even a bit organized. * Debugging, testing/experimentation, and design for the next few weeks Debugging * Why? - Most code is buggy (which we learn from our unit tests) * What? - "Where" is the bug? - What caused the bug? * How? - Look at error messages for crash "Segmentation Fault" - Print statements to track program state * In C, print statements can eliminate segfaults. E.g., int foo[10]; printf ("I declared foo.\n"); foo[10] = 4; * Someone talented with a debugger can acheive same result with much less effort. - Use a debugger - Static analysis - Go through the program by hand - Extreme: Write pre/post, invariants, etc. - Program analyzer - Static - -Wall - Dynamic - E.g. valgrind for checking memory Example Code * int ibs(int A[], int len, int v) - returns index or -1 * Explore * Try different sizes of the array * Try the empty array * Try odd and even length arrays * Write unit tests (yay!) * Write an interactive experiment Idea: ibs-expt VAL A[0] A[1] ... A[N-1] * Fix gdb basics If time: Designing a list interface (because we often do things too specifically)