cs01 / cs01/gdbgui

GDB hangs infinitely traversing pretty printers

Open
#514 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
10.4k
Forks
521
PR merge metrics
No merged PRs in 30d

Description

I have found a relatively general case where the controlled GDB process hangs.

Consider the following:
1. I use GDB pretty printers on pointers to make them expandable. This makes perfect sense, since otherwise pointers look like dead hex values in the debugger.
2. The pointer / children graph of some data structures have loops. This makes perfect sense again, there so many data structures with all kind of backlinks that make pointer graph cyclic.
3. I get into unlucky situation where debugger forces GDB to deep-print cyclic data structure... which never ends.

Steps to reproduce the behavior:
1. Clone "gdbgui" branch of this repository: https://github.com/stgatilov/vscode-gdb-pretty-printers-hangs-repro-code/tree/gdbgui
2. Build the code with CMake.
3. Load the built executable into gdbgui.
4. Start debugging.
5. Execute "source path/to/printers.py".
6. Make sure the file was found and loaded!
7. Set breakpoint on the last line of "badfunc" function.
8. Continue execution until the new breakpoint triggers.
9. Notice that gdb hangs completely.

I captured MI commands using strace, and this is the last command before hanging:

1-stack-list-variables --simple-values

As far as I know, `--simple-values` means that pointer variables have their values printed (for some reason, they are "simple"). But due to how GDB works by default, it actually tries to deep-print the value, which is an infinitely large task since the children graph has loops.

Other debuggers also have this problem:
* VS Code: https://github.com/microsoft/vscode-cpptools/issues/14487
* KDevelop: https://bugs.kde.org/show_bug.cgi?id=522317

Contributor guide

Open the contributing guide

Research direction

Build the linked gdbgui reproduction with CMake, load it in gdbgui, source printers.py, and stop in badfunc while observing 1-stack-list-variables --simple-values. Done means the controlled GDB session no longer hangs while traversing the cyclic pretty-printer graph; the issue does not identify a gdbgui file or test to edit.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, python, typescript
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.