CS 452/652 Winter 2022 - Lecture 17
February 14, 2022
often ad-hoc activity - reflect on it...
software: model ↔ implementation
debugging: reconcile model and implementation
(your) program vs. environment (soft- and hardware)
what's in a bug?
error in model?
design: your model is incorrect
coding: your implementation does not realize your model
interface: your understanding of the environment is incorrect
internals: there is an unknown bug in the environment (unlikely)
debugging helps with
basic technique: inspect and compare → alert
rule out or confirm problems
start with most likely problem?
or start with most easy to rule out?
debugging fundamentally uses scientific methodology
build model → gather data → compare
no amount of experimentation can ever prove a model correct!
interactive debugging: breakpoints, single-stepping
post-mortem (reset keeps most RAM): gdb or custom software
source or binary instrumentation
stack backtrace? see 'man backtrace' on Linux
not available in newlib, you could re-implement...
str pc, <location>
new correctness criterion: timing
"benign" program changes (such as print) change timing behaviour
concurrency and races → non-determinism
non-determinism → bug might appear/disappear, seemingly at random, and/or after minor changes
real-time → interactive debugging difficult
program suspended, but real world (trains) keeps moving!
"regular" hosted environment (such as Linux)
hardware: special instruction, exception
write to code segment of process
breakpoint - write special instruction, handle exception
continue - rewrite original code, resume execution
single step - breakpoint at next instruction (or source code line)
example: see 'man ptrace' on Linux
otherwise: remote operation
gdb stub/server co-located with target
EP 9302: gdb stub in RedBoot
communication over serial link or network (TCP)
breakpoint implemented as 'undefined instruction' (udf)
udf handler accessed via branch in
, destination in
udf handler invokes gdb stub
are not modified from reset defaults!
works for breakpoints/single-stepping kernel code (in SVC mode)
debug operation: run user tasks in System mode
⇒ breakpoints/single-stepping should work for most code
however, assignment submissions must run user tasks in User mode!!
EP 9302 reset does not wipe all RAM (only RedBoot memory) → use for post-mortem
gdb's 'disassemble' command disassembles arbitrary memory regions with
online disassembler at