Bug 578118 - Debugging with GDB fails for unknown reasons
Summary: Debugging with GDB fails for unknown reasons
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-debug (show other bugs)
Version: 10.5.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: cdt-debug-inbox@eclipse.org CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-01-08 16:37 EST by Sven Köhler CLA
Modified: 2022-01-10 11:43 EST (History)
3 users (show)

See Also:


Attachments
project that cannot be debugged (11.22 KB, application/gzip)
2022-01-08 16:37 EST, Sven Köhler CLA
no flags Details
screenshot of empty Variables view (166.28 KB, image/png)
2022-01-08 16:38 EST, Sven Köhler CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sven Köhler CLA 2022-01-08 16:37:17 EST
Created attachment 287796 [details]
project that cannot be debugged

Find attached a project that I simply cannot step through (debug mode) with Eclipse 2021-12 (CDT 10.5.0). I have also attached a screenshot taken right after launching the application. The application stops at the main (breakpoint) and on the upper right you should see the list of local variables -- except you don't. It's not there. I cannot step through the program or do anything else meaningful. Even stopping the app fails with some error message.

It get's better if I remove a couple of lines from main.cpp (especially the lambda expression). So maybe the lambda is the culprit here?

I'm running Eclipse 2021-12 on Arch Linux with all latest updates. GDB version is 11.1 and GCC is 11.1.0.
Comment 1 Sven Köhler CLA 2022-01-08 16:38:50 EST
Created attachment 287797 [details]
screenshot of empty Variables view

The variables view should show the local variables, but it just shows some ">" marks indicating that there is something to unfold. I can even click the items in the list, but stay empty.
Comment 2 Sven Köhler CLA 2022-01-08 16:44:38 EST
Hmm, it's not related to the lambda expression. I shorted main as follows:

int main(int argc, const char * const argv[]) {
	std::unordered_set<string> features;
	argparse::ArgumentParser args(argv[0], "", argparse::default_arguments::help);
}


The problem still occurs.
Comment 3 Jonah Graham CLA 2022-01-10 11:01:25 EST
I can reproduce this GCC 10.3 and GDB 9.2 (the defaults on my Ubuntu 20.04 machine).

I can see that GDB has stopped responding (Eclipse is waiting for a response to 337,806 41-var-list-children var3) - this indicates a possible GDB bug. I will try to reduce it further.
Comment 4 Jonah Graham CLA 2022-01-10 11:43:17 EST
Hi Sven,

The problem here is in the Python pretty printers that are part of GBD/GCC. They are getting in an infinite loop when trying to calculate the content of the "features" variable in your main.

You can work around the problem in one of three ways:

1) Make sure you don't hit a breakpoint before features is populated. You can do this by disabling the automatic breakpoint at main (in the Launch Configuration dialog uncheck "Start on startup" https://imgur.com/Oyq7Jxv.png) and adding a breakpoint a bit later in the code.
2) Disable the pretty printers. In preferences -> C/C++ -> Debug -> GDB uncheck Enable pretty printers: https://imgur.com/H1PyYno.png 
3) Sending SIGINT to GDB to force the a KeyboardException in the Python code (e.g. killall -s SIGINT gdb). You may want to turn on the Show GDB Traces so you can see the command that is stuck: https://imgur.com/H1PyYno.png 

Please submit a bug to GDB or GCC to get the underlying bug resolved.

Eclipse CDT could do better here by offering to user to abort the stuck command in GDB. In my experiments SIGINTing seems to bring things back to life, however at the time of the SIGINT Python returns huge quantity of data which CDT pauses slightly while processing as well.

To reproduce at the command line (useful for submitting bug to GDB/GCC):

Build project and start GDB in MI mode:
$ gdb --interpreter=mi2 nameofexecutable

Then run these commands to setup GDB:
1-enable-pretty-printing
2-gdb-set print object on
b main
run

Then run these commands to cause GDB to hang in the Python side:
3-var-create --thread 1 --frame 0 - * features
4-var-list-children var1

If you then SIGINT GDB you (normally) get output like this:
^C&"Python Exception <class 'KeyboardInterrupt'> <class 'KeyboardInterrupt'>: \n"
4^done,numchild="34936",children=[child={name="var1.[0]",exp="[0]",numchild="0",type="std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >",thread-id="1",displayhint="string",dynamic="1"},child={name="var1.[1]",exp="[1]",numchild="0",type="std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> [... continues for a long time, depending on how quickly SIGINT was done)