131 Week 10 - Debugging Flashcards
Compilation time bugs
Bugs that occur during compilation of the program.
e.g., syntax error, variable used before definition.
Run time bugs
Bugs that occur while the program is running. Program is syntactically correct but does work as expected.
e.g., logic error
Divide and conquer debugging
Gradually remove/add code to create the smallest source file that contains the bug.
Either remove code until the bug stops and examine last removed lines.
Or start with smallest running program and add code until the program breaks and examine last added lines.
Debugging using logging
Insert logging statements (e.g., printf) to see values of variables at different points during runtime.
Has flaws as it can take many log statements or logging statements could even change program behaviour such as timings or the stack - called heisenbug errors.
Micro:bit logging debugging
You can use a serial/UART interface to output logging statements to your computers terminal by connecting your micro:bit and using uBit.serial.printf to output logging statements.
Debugger
Software that provides tools to assist with debugging such as:
- stepping
- breakpoints
- investigating machine state
- investigating crashes
Debuggers are generally language dependent but some can support multiple languages.
Some debuggers require hardware support.
Can be GUI or command line
GDB
Open-source command line debugger designed for the C language.
Using GDB
Compile using gcc -g fileName.c -o executableName
-g tells compiler to generate debugging symbols
Use break lineNumber to set a breakpoint e.g., break 5
Use run to start running the program.
Big endian
Most significant byte is stored first
Little endian
Least significant byte stored first
How is a Micro:bit debugged
Use DAPLink to debug a running Micro:bit
On-chip debugger (OCB) allows remote debugging.
Can integrate with VS Code to use a powerful debugging environment.