gdb rbreak和命令(或dprintf行为)?

gdb rbreak和命令(或dprintf行为)?,gdb,Gdb,以-为例,当我使用rbreak时,我得到如下结果: (gdb) rb TestFixture.h:. Breakpoint 1 at 0x4008b6: file TestFixture.h, line 5. void TestFixture::setUp(); Breakpoint 2 at 0x4008d4: file TestFixture.h, line 6. void TestFixture::tearDown(); Breakpoint 3 at 0x4008f2: file Tes

以-为例,当我使用
rbreak
时,我得到如下结果:

(gdb) rb TestFixture.h:.
Breakpoint 1 at 0x4008b6: file TestFixture.h, line 5.
void TestFixture::setUp();
Breakpoint 2 at 0x4008d4: file TestFixture.h, line 6.
void TestFixture::tearDown();
Breakpoint 3 at 0x4008f2: file TestFixture.h, line 7.
void TestFixture::testA();
Breakpoint 4 at 0x400910: file TestFixture.h, line 8.
void TestFixture::testB();
(gdb) info breakpoints
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x00000000004008b6 in TestFixture::setUp() at TestFixture.h:5
2       breakpoint     keep y   0x00000000004008d4 in TestFixture::tearDown() at TestFixture.h:6
3       breakpoint     keep y   0x00000000004008f2 in TestFixture::testA() at TestFixture.h:7
4       breakpoint     keep y   0x0000000000400910 in TestFixture::testB() at TestFixture.h:8
#0 Searcher::FlagFromCmd(this=0x7fffffffaed8,cmd=808) <- FindLiveStrip::GrabToggles
#0 Searcher::FlagFromCmd(this=0x7fffffffaed8,cmd=807) <- FindLiveStrip::ToggleChanged
现在,我想要的基本上是一个类似于
dprintf
-的行为:一旦命中其中一个断点,我只想打印出函数名,然后
继续
(基本上是一个函数调用跟踪)

然而,按照我对
gdb
的理解,为了做到这一点,我会先发出
rbreak[regex]
,然后我会得到一堆断点,然后我必须手动键入每一个断点:

commands [number-of-breakpoint]
print "[name of function]"
continue
end
。。。这很快就变成了一件麻烦事,尤其是如果你最后得到的断点比上面例子中的4个要多得多(比如说几百个)

现在,如果我能使用“regex dprintf”或
rdprintf
之类的东西,那就太酷了,如:

rdprintf TestFixture.h:., "%s\n", $__breakname__
。。。但据我所知,没有这样的命令

或者,如果在发出
rbreak TestFixture.h:.
之后,我可以将这些断点的
命令作为目标:

commands 1-4
print $__breakname__
continue
end
。。。但是,我认为这也不存在

那么,有没有一种方法可以使用
gdb
提供这种函数调用跟踪打印输出,而无需我手动键入断点及其命令的名称,类似于
rbreak
如何允许您使用一个命令设置多个断点



编辑:刚找到-
记录函数调用历史记录/ilc
可能很有趣,但似乎没有办法限制要跟踪的函数的范围,比如使用正则表达式…

好的,通过上面的链接,找到-结果是,您可以为多个断点发出
命令,正如
rbreak
所发现的那样;要打印函数名,只需使用
backtrace 1

(gdb) command 1-36
Type commands for breakpoint(s) 1-36, one per line.
End with a line saying just "end".
>silent
>bt 1
>continue
>end
(gdb) r
。。。或者使用python,在
bt 0
处打印帧及其父帧名称:

command 1-36
silent
python print("{} <- {}".format( gdb.execute("bt 0", False, True).strip(), gdb.newest_frame().older().name() ))
continue
end
。。。它将打印如下内容:

(gdb) rb TestFixture.h:.
Breakpoint 1 at 0x4008b6: file TestFixture.h, line 5.
void TestFixture::setUp();
Breakpoint 2 at 0x4008d4: file TestFixture.h, line 6.
void TestFixture::tearDown();
Breakpoint 3 at 0x4008f2: file TestFixture.h, line 7.
void TestFixture::testA();
Breakpoint 4 at 0x400910: file TestFixture.h, line 8.
void TestFixture::testB();
(gdb) info breakpoints
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x00000000004008b6 in TestFixture::setUp() at TestFixture.h:5
2       breakpoint     keep y   0x00000000004008d4 in TestFixture::tearDown() at TestFixture.h:6
3       breakpoint     keep y   0x00000000004008f2 in TestFixture::testA() at TestFixture.h:7
4       breakpoint     keep y   0x0000000000400910 in TestFixture::testB() at TestFixture.h:8
#0 Searcher::FlagFromCmd(this=0x7fffffffaed8,cmd=808) <- FindLiveStrip::GrabToggles
#0 Searcher::FlagFromCmd(this=0x7fffffffaed8,cmd=807) <- FindLiveStrip::ToggleChanged
#0 Searcher::FlagFromCmd(this=0x7fffffaed8,cmd=808)