在文件中的类成员函数上设置断点
(gdb) b breakpoints.cpp:X::X()
Can't find member of namespace, class, struct, or union named "breakpoints.cpp:X::X"
Hint: try 'breakpoints.cpp:X::X()<TAB> or 'breakpoints.cpp:X::X()<ESC-?>
(Note leading single quote.)
Make breakpoint pending on future shared library load? (y or [n]) n
在以下代码上:
#include <stdio.h>
#include <iostream>
class X
{
public:
X ()
{
std :: cout << "\nIn the default constructor";
}
X (int)
{
std :: cout << "\nIn the parameterized constructor";
}
~X () {}
};
int main (int argc, char *argv[])
{
X xObjA;
X xObjB (11);
while (--argc > 0)
{
printf("\n%s ", argv [argc]);
}
std :: cout << std :: endl << std :: endl;
}
文件名是:breakpoints.cpp
我缺少的要点是什么?
(gdb) b breakpoints.cpp:X::X()
Can't find member of namespace, class, struct, or union named "breakpoints.cpp:X::X"
Hint: try 'breakpoints.cpp:X::X()<TAB> or 'breakpoints.cpp:X::X()<ESC-?>
(Note leading single quote.)
Make breakpoint pending on future shared library load? (y or [n]) n
on the following code:
#include <stdio.h>
#include <iostream>
class X
{
public:
X ()
{
std :: cout << "\nIn the default constructor";
}
X (int)
{
std :: cout << "\nIn the parameterized constructor";
}
~X () {}
};
int main (int argc, char *argv[])
{
X xObjA;
X xObjB (11);
while (--argc > 0)
{
printf("\n%s ", argv [argc]);
}
std :: cout << std :: endl << std :: endl;
}
File's name is: breakpoints.cpp
What's the point that I am missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这才是设置断点的正确方法。
您要么在错误的可执行文件上尝试(将breakpoints.cpp放入目录中并使用g++ -g Breakpoints.cpp进行编译,然后在a.out可执行文件上使用gdb),代码与发布的代码不同并且可能具有名称空间,或者您由于使用过时的 gdb 版本而偶然发现了一个旧错误。
That is the correct way to set a breakpoint.
You are either trying that on a wrong executable (put breakspoints.cpp in a directory and compile with g++ -g breakpoints.cpp and then use the gdb on the a.out executable), code that is different than posted and maybe having namespaces, or you stumbled on an old bug due to using an outdated gdb version.
也许您需要在没有文件名的情况下定义断点。以下内容对我有用:
我想这仅在类唯一时才有效,因此它应该位于命名空间中。
注意
如果有多个地方可以放置断点,我认为gdb会尝试在所有地方放置断点,所以你最终会得到一些 >像下面的:
Perhaps you need to define your breakpoints without the file name. The following works for me:
I imagine this only works when the class is unique however, so it should be in a namespace.
Note
If there are multiple places where the breakpoint can be placed, I think gdb will try to place breakpoints on all of the places, so you will end up with something like the following:
如果为类定义了命名空间,您可能需要指定命名空间。如果它不是标准命名空间 std。
如果您正在执行正确的二进制文件,则文件名是可选的。
您可以通过以下方式验证该符号是否存在于可执行文件中。 “nm -C”命令,其中 -C 处理 C++ 的名称修改。
用一个例子来总结一下:
如果命名空间是“mySpace”,类是“X”,其成员是“Y”,
那么断点应该像下面这样,
“(gdb)b mySpace::X::Y”
You may need to specify the namespace if any defined for the class. If it other than the standard namespace 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++.
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"