简体   繁体   English

成员函数的C ++ GDB断点

[英]C++ GDB breakpoint for member functions

I am having trouble with using GDB on my c++ program. 我在c ++程序中使用GDB时遇到问题。 I want to set up a break point for my class member function and I'm not sure on the syntax of how to do it. 我想为我的类成员函数设置一个断点,我不确定如何做的语法。 My program is working find right now and I'm just trying to learn to use GDB. 我的程序现在正在查找,我只是想学习使用GDB。 My problem is all the information I find on line only really deals with just a main() file and no other functions or classes and if they involve classes its only using a function with a void return statement. 我的问题是我在线找到的所有信息只是真正处理一个main()文件而没有其他函数或类,如果它们涉及类,它只使用带有void return语句的函数。

I have a binary search tree class. 我有一个二叉搜索树类。 I want to set a break point at a function in my program. 我想在程序中的函数中设置一个断点。 here's the section of my header file. 这是我头文件的一部分。

class BST
{
    BST()
    ...
    private:
    int add((BST * root, BST *src);
}

I am telneting into a command line linux server for school. 我正在telneting到学校的命令行linux服务器。 I can get GDB running with my program just fine with g++ -g *.cpp (there are other files that are working fine) and the file is saved as a.out. 我可以使用g ++ -g * .cpp(还有其他正常工作的文件)使用我的程序运行GDB,并将文件保存为a.out。 I run GDB with 我用GDB运行

gdb ./a.out

and I get into GDB. 然后我进入了GDB。 I can get a break point for the void display function just fine with 我可以很好地获得空白显示功能的断点

b BST::disp_block()

but how do I do it with the add function I have tried 但是如何使用我尝试的添加功能来完成它

b BST::int add(BST*, BST *)
b int BST::add(BST*, BST *)
b BST::add(BST*, BST *)

and I even tried with the argument names 我甚至尝试过参数名称

b BST::int add(BST * root, BST * src)
b int BST::add(BST * root, BST * src)
b BST::add(BST * root, BST * src)

and I keep getting the error 而且我一直收到错误

Function "____" not defined.
Make break point pending on future shared library load? (y or [n])

How do I set up a break point for a member function like this one? 如何为像这样的成员函数设置断点? Im assuming watch points would be the same format, if not could you explain that too. 我假设观察点是相同的格式,如果没有,你能解释一下吗?

As Dark Falcon said, break BST::add should work if you don't have overloads. 正如Dark Falcon所说,如果你没有超载, break BST::add应该可行。

You can also type: 你也可以输入:

(gdb) break 'BST::add(<TAB>

(note the single quote). (注意单引号)。 This should prompt GDB to perform tab-completion, and finish the line like so: 这应该提示GDB执行tab-completion,并完成这样的行:

(gdb) break 'BST::add(BST*, BST*)

and which point you can add the terminating ' ' and hit Enter to add the breakpoint. 哪一点你可以添加终止' '并按Enter键添加断点。

I can get a break point for the void display function 我可以获得void显示功能的断点

Function return type is not part of its signature and has nothing to do with what's happening. 函数返回类型不是其签名的一部分,与正在发生的事情无关

You may need to specify the namespace if any defined for the class. 如果为类定义了任何名称空间,则可能需要指定名称空间。 If it other than the standard namespace std. 如果它不是标准命名空间std。 The file name is optional, if you are executing the correct binary. 如果您正在执行正确的二进制文件,则文件名是可选的。 You can verify if the symbol exists on the executable via. 您可以验证可执行文件上是否存在该符号。 "nm -C" command, where -C handles name mangling for C++. “nm -C”命令,其中-C处理C ++的名称重整。

So to summarise with an Example: If the namespace is "mySpace" and the class is "X" whose member is "Y", then the breakpoint should be like the one below, "(gdb) b mySpace::X::Y" 所以用一个例子来概括:如果命名空间是“mySpace”而类是“X”,其成员是“Y”,那么断点应该像下面那样,“(gdb)b mySpace :: X :: Y “

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM