I have found a relatively general case where the controlled GDB process hangs.
Consider the following:
- 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.
- 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.
- I get into unlucky situation where debugger forces GDB to deep-print cyclic data structure... which never ends.
Steps to reproduce the behavior:
- Clone "gdbgui" branch of this repository: https://github.com/stgatilov/vscode-gdb-pretty-printers-hangs-repro-code/tree/gdbgui
- Build the code with CMake.
- Load the built executable into gdbgui.
- Start debugging.
- Execute "source path/to/printers.py".
- Make sure the file was found and loaded!
- Set breakpoint on the last line of "badfunc" function.
- Continue execution until the new breakpoint triggers.
- 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:
I have found a relatively general case where the controlled GDB process hangs.
Consider the following:
Steps to reproduce the behavior:
I captured MI commands using strace, and this is the last command before hanging:
As far as I know,
--simple-valuesmeans 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: