15 Debugging in C
15 Debugging in C
1
Administrivia
Reminder: Midpoint Deadline Friday November 6th at 9pm PST
-Will post grades to canvas sometime the week after
int factorial(int x) {
if (x == 0) {
return x;
} else {
return x * factorial(x-1);
}
}
Base factorial(0) 0! = 1 1 0
Recursive factorial(1) 1! = 1 1 0
Recursive factorial(2) 2! = 1 * 2 2 0
Recursive factorial(3) 3! = 1 * 2 * 3 6 0
Base factorial(0) 0! = 1 1 1
Recursive factorial(1) 1! = 1 1 1
Recursive factorial(2) 2! = 1 * 2 2 2
Recursive factorial(3) 3! = 1 * 2 * 3 6 6
▪‘gdb’ -> gnu debugger, standard part of linux development, supports many lan gyages
-techniques are the same as in most debugging tools
-can examine a running file
-can also examine core files of previous crashed programs
▪Software Test: a separate piece of code that exercises the code you are assessing by providing
input to your code and finishes with an assertion of what the result should be.
1. Isolate
2. Break your code into small modules
3. Build in increments
4. Make a plan from simplest to most complex cases
5. Test as you go
6. As your code grows, so should your tests
▪White Box
-Includes an understanding of the implementation
-Written by the author as they develop their code
-Break apart requirements into smaller steps
-“unit tests” break implementation into single assertions
Forbidden Input
-What are all the ways the user can mess up?
Empty/Null
-Protect yourself!
-How do things get started?
Boundary/Edge Cases
-First
-last
Scale
-Is there a difference between 10, 100, 1000, 10000 items?