Master the fundamental concepts of debugging mastery through this focused micro-challenge.
GDB includes a Python API that lets you write custom pretty-printers to display complex data structures in human-readable form. Without them, inspecting a linked list in GDB shows raw pointer addresses instead of the values you actually care about.
A pretty-printer is a Python class with a to_string() method:
gdb.Value: Represents a value in the debugged programgdb.Type: Represents the C type of a valueval['field_name']: Access struct fieldsval.dereference(): Follow a pointerFor example, given struct Node { int data; struct Node* next; }, a pretty-printer walks the list and displays [1 -> 2 -> 3 -> NULL] instead of 0x7fff1234.
Load the script with source pretty_printer.py inside GDB.
You will define a linked list in C and document how a GDB Python pretty-printer would display it. This skill matters when debugging custom allocators, tree structures, and any non-trivial data type in production code.
Pretty-printers register with gdb.printing.register_pretty_printer and match types by name or regex. A printer for struct Node checks val.type.name and returns a NodePrinter instance. The children() method lets GDB expand tree nodes interactively. Teams ship pretty-printer collections for internal data structures so every developer sees readable output during post-mortem debugging sessions.
Write a C program that mimics a GDB Python pretty-printer for a singly linked list: read the node data values from stdin, build the list, optionally reverse it (emulating the effect of a finish at reverse_list), then print the exact display a NodePrinter.to_string() would produce.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it works