Menu

Reading gdb like a map
📰

Reading gdb like a map

DEV Community: cpp·Abdelrahman Ahmed Abdelazeez·3 days ago
#RdR8SqRh
#devtocpp#devto#dev#program#instead
Long article (1186 words) — no AI summary yet.
Reading 0:00
15s threshold

The Python side of this visualizer was easy in one specific way: the interpreter will tell you anything you ask. Frames, locals, object types, what refers to what. You walk its own data structures and write them down.

C++ has no such thing. There is no interpreter to ask, no runtime registry of live objects, no way to say "give me everything reachable from this local". The only thing in the system that knows where the values are is the debugger, and the debugger knows it in the least friendly form possible: addresses, types, and the raw bytes at those addresses.

So for C++ the tracer does not introspect the program. It runs inside gdb.

The shape of the thing

The worker is a Python script that gdb loads:

gdb -nx -batch -q -x cpp_gdb_worker.py

Enter fullscreen mode

Exit fullscreen mode

It steps the program one source line at a time with gdb's own step , and after every line it writes one snapshot: stack frames, the variables in each frame, and the objects reachable from them.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.