如何正确使用rbreak命令

How to use the command of rbreak correcly?

本文关键字:rbreak 命令 何正确      更新时间:2023-10-16

我想在Test::Say((处设置中断。break-Test::Say((的方法可以做到。但是,rbbreak-TestSay(

(gdb(rbbreak测试::Say((找不到名为"main.cpp:'Test::Say(("的命名空间、类、结构或联合的成员提示:尝试'main.cpp:'Test::Say(('或'main.cpp:'Test:(('(注意前导单引号。(
   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以exected:的方式工作

$ 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)