如何正确使用break命令?
How to use the command of rbreak correcly?
我想在 Test::Say() 处设置休息时间。 break Test::Say() 的方式可以做到。但是rbreak TestSay()的方式不行,报错信息如下:
(gdb) rbreak Test::Say()
Can't find member of namespace, class, struct, or union named "main.cpp:'Test::Say()"
Hint: try 'main.cpp:'Test::Say()' or 'main.cpp:'Test::Say()'
(Note leading single quote.)
class Test
{
public:
Test()
{
}
void Say()
{
printf("Hello word!");
}
};
int main ()
{
Test a;
a.Say();
getchar();
return 0;
}
我建议将 gdb 升级到最新版本。我已经用 gdb 版本 7.2 重现了你的错误:
/usr/bin/gdb ./a.out
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-60.el6_4.1)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/rbreak/a.out...done.
(gdb) rbreak Test::Say()
Can't find member of namespace, class, struct, or union named "main.cpp:'Test::Say()"
Hint: try 'main.cpp:'Test::Say()'<TAB> or 'main.cpp:'Test::Say()'<ESC-?>
(Note leading single quote.)
Breakpoint 1 (main.cpp:'Test::Say()') pending.
void Test::Say();
(gdb)
然而,对于最新的 gdb 版本 7.9,rbreak 可以正常工作:
$ \gdb ./a.out
GNU gdb (GDB) 7.9.1
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./a.out...done.
(gdb) rbreak Test::Say()
Breakpoint 1 at 0x400626: file main.cpp, line 12.
void Test::Say();
(gdb) r
Starting program: /home/rbreak/a.out
Breakpoint 1, Test::Say (this=0x7fffffffdd7f) at main.cpp:12
12 printf("Hello word!");
(gdb)
我想在 Test::Say() 处设置休息时间。 break Test::Say() 的方式可以做到。但是rbreak TestSay()的方式不行,报错信息如下:
(gdb) rbreak Test::Say() Can't find member of namespace, class, struct, or union named "main.cpp:'Test::Say()" Hint: try 'main.cpp:'Test::Say()' or 'main.cpp:'Test::Say()' (Note leading single quote.)
class Test
{
public:
Test()
{
}
void Say()
{
printf("Hello word!");
}
};
int main ()
{
Test a;
a.Say();
getchar();
return 0;
}
我建议将 gdb 升级到最新版本。我已经用 gdb 版本 7.2 重现了你的错误:
/usr/bin/gdb ./a.out
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-60.el6_4.1)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/rbreak/a.out...done.
(gdb) rbreak Test::Say()
Can't find member of namespace, class, struct, or union named "main.cpp:'Test::Say()"
Hint: try 'main.cpp:'Test::Say()'<TAB> or 'main.cpp:'Test::Say()'<ESC-?>
(Note leading single quote.)
Breakpoint 1 (main.cpp:'Test::Say()') pending.
void Test::Say();
(gdb)
然而,对于最新的 gdb 版本 7.9,rbreak 可以正常工作:
$ \gdb ./a.out
GNU gdb (GDB) 7.9.1
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./a.out...done.
(gdb) rbreak Test::Say()
Breakpoint 1 at 0x400626: file main.cpp, line 12.
void Test::Say();
(gdb) r
Starting program: /home/rbreak/a.out
Breakpoint 1, Test::Say (this=0x7fffffffdd7f) at main.cpp:12
12 printf("Hello word!");
(gdb)