Lion Cipher Lab

Automate a gdb session: log every call of a function with breakpoint commands and the Python API

Why it matters

Stepping through a program by hand is how you learn it, but it does not scale. An analyst facing an unfamiliar validation routine, a decoder, or a function called hundreds of times wants a log, not a hundred keystrokes: every call, every argument, in order. gdb can be scripted, from simple breakpoint commands up to a full Python API, so one script can run the program and write that log for you while you do something else. Scripted tracing is also repeatable: you can hand the script to a colleague, rerun it on the next version, and diff the logs. This lab teaches the technique on a toy license…

What you'll learn

Steps in this lab

  1. The problem: a function you want a log of
  2. Build the toy license check
  3. The slow way, so you feel why scripting helps
  4. Breakpoint commands: log and keep going
  5. Filter without code: a conditional breakpoint
  6. A first taste of the Python API
  7. Write the trace as a Python Breakpoint subclass
  8. Check the log against the source, then make it stop on purpose
  9. When NOT to script gdb, what it cannot do, and how a pro does it better

Open the full interactive lab →

Keep learning