26

How can I configure Qt Creator and/or gdb so that while debugging my program using Qt libraries the debugger would avoid stepping into Qt's source files?

Piotr Dobrogost
  • 41,292
  • 40
  • 236
  • 366

4 Answers4

16

You need to turn off auto-solib-add. From a normal gdb prompt you would type:

(gdb) set auto-solib-add off

In Qt Creator, under Options->Debugger->Gdb you can specify a Gdb startup script. Create a file with the "set auto-solib-add off" command in it and then set your Gdb startup script to that file.

atomice
  • 3,062
  • 17
  • 23
  • 2
    wont work with static build of course (it's in the name auto-SOlib-add). – Mr. Developerdude Oct 19 '14 at 20:08
  • That doesn't work when you want it to stop stepping through all (STL) header files. Almost all code is compiled from header files anyway. Need a way to skip THOSE. ```(gdb) s std::forward (__t=@0x7fffffffccff: false) at /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/11.1.0/../../../../include/c++/11.1.0/bits/move.h:78 78 { return static_cast<_Tp&&>(__t); } ``` – Carlo Wood Sep 16 '21 at 12:03
3

The feature you want (as described by rpg) is not available from GDB, and IMHO would be difficult to use if it were implemented.

A similar, but simpler to use fstep feature is proposed for GDB. Given:

foo((string("Hello") + string(" World!)).c_str());

the fstep would skip all calls on the current line, except the last one (thus skipping string constructors, operator+(), and c_str(), and stepping only into foo).

This hasn't been implemented either, but likely will be in a couple of month (it's very useful for C++ debugging).

In the mean time, you can approximate the feature by setting a temporary breakpoint:

(gdb) list
1       #include <string>
2       #include <iostream>
3       using namespace std;
4
5       void foo(const char *s)
6       {
7         cout << s << endl;
8       }
9
10      int main()
11      {
12        foo((string("Hello") + string(" World!")).c_str());
13        return 0;
14      }
(gdb) b main
Breakpoint 2 at 0x8048901: file t.cc, line 12.
(gdb) run

Breakpoint 1, main () at t.cc:12
12        foo((string("Hello") + string(" World!")).c_str());
(gdb) tb foo
Breakpoint 3 at 0x80488ca: file t.cc, line 7.
(gdb) c
foo (s=0x804a1f4 "Hello World!") at t.cc:7
7         cout << s << endl;
(gdb) q
Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • 1
    What do you think about Andy's proposition to just remove/hide library's source files? – Piotr Dobrogost Sep 26 '09 at 11:51
  • 1
    You can try it, but I don't think it would do you any good: GDB will still step into the functions you don't want, it will just not show the source for them. Arguably that's worse than what you started with. In addition, if you are on ELF platform (e.g. Linux), then you'd have to actually remove library headers -- compiler embeds full path to them into your executable (IOW, modifying GDB startup script will likely prove futile). – Employed Russian Sep 26 '09 at 16:25
  • @Employed: It's 2012 and fstep still isn't part of GDB. Is there any other alternative? (Or a patch I could apply to gdb sources) This is indeed a must for C++ development. – nimrodm Nov 12 '12 at 11:38
  • 1
    @nimrodm There is a very similar feature request here: http://sourceware.org/bugzilla/show_bug.cgi?id=8287 that has been fixed. Not quite fstep, but you can blacklist un-interesting functions while stepping. – Employed Russian Nov 12 '12 at 16:49
  • 4
    The command is now called "skip" and is available in gdb 7.4 and newer. – nimrodm Nov 15 '12 at 08:53
1

Update after comment clarification:

In gdb you can specify which source directories are searched - if it can't find them, it won't be able to go into them.

For gdb to be entering the source files of the qt libraries it must know where they are - it's likely that qt-creator is telling gdb where they are when it launches the debugger. Look around qt-creator for the gdb startup script - they might be specified in there.

If they aren't specified in the startup script and it's gdb finding the source files on it's own you should be able to modify the gdb startup script to clear any directories with the directory command (see the link above for syntax etc.)

You may also be able to view the gdb console by going to "Debug -> Views -> Gdb" to get information about which source directories it is currently using with the show directories command in gdb, and clearing any off manually if you want to do this on a case-by-case basis.

Andy
  • 3,794
  • 24
  • 28
  • Here's what I think Piotr wants: you have a call like foo(QVariant::fromValue(MySuperClass(QString("hi %1").arg("Andy")))). When stepping into, the debugger should skip arg, the QString constructor, the fromValue call and enter only MySuperClass and foo. AFAIK, Qt Creator can't do this. There was some discussion about skipping the sig/slot machinery when stepping through code, but I don't know if they implemented it. – rpg Sep 22 '09 at 07:58
  • 1
    Andy, what you are describing is called STEP OUT and STEP OVER and has always been possible in pretty much every debugger. I don't want to **manually** step out/over Qt's source code. I want debugger to step over it **automatically**. rpg is right in his comment and he describes the feature I was asking about. – Piotr Dobrogost Sep 23 '09 at 14:02
1

Maybe not exactly a perfect solution to this question, but maybe it would help to exclude the directories where your project is not (ie. 3rd party libraries, system headers (like STL), etc). If so, take a look at https://stackoverflow.com/a/31629136/5155476 and https://stackoverflow.com/a/42721326/5155476. The former allows you to specify directories (and all subdirectories) to skip when stepping while running GDB (so you can change the set whenever you like), but it requires you to build GDB. The latter allows the same functionality but pre-set before running GDB, and does not require building GDB.

codesniffer
  • 1,033
  • 9
  • 22