Program Introspection


When printf-debugging isn’t good enough: use a debugger.

Debuggers let you interact with the execution of a program, letting you do things like:


GDB and LLDB. Supports many C-like languages.

Let’s look at example.c. Compile with debug flags: gcc -g -o example example.c.

Open GDB:

gdb example

Some commands:


PDB is the Python debugger.

Insert import pdb; pdb.set_trace() where you want to drop into PDB, basically a hybrid of a debugger (like GDB) and a Python shell.

Web browser Developer Tools

Another example of a debugger, this time with a graphical interface.


Observe system calls a program makes: strace {program}.


Types of profiling: CPU, memory, etc.

Simplest profiler: time.


Run test code with CPU profiler: go test -cpuprofile=cpu.out

Analyze profile: go tool pprof -web cpu.out

Run test code with Memory profiler: go test -memprofile=mem.out

Analyze profile: go tool pprof -web mem.out


Basic performance stats: perf stat {command}

Run a program with the profiler: perf record {command}

Analyze profile: perf report

Edit this page.

Licensed under CC BY-NC-SA.