如何创建类的实例并将其分配给变量?
对于使用 gdb 调试时的 C++ 代码: 1)如何在gdb中创建变量?使用 gdb/mi 命令? 2)如何在gdb中创建类的实例。 3)如何将创建的实例分配给gdb中创建的变量以供将来使用? 例如:
C++ code:
class C { public:int value; }
gdb commands (pseudo-code):
var v = new C()
print v.value
For C++ code when debugging using gdb:
1) How to create a variable in gdb? Using gdb/mi command?
2) How to create a instance of a class in gdb.
3) How to assign the created instance to the created variable in gdb to make use in the future?
For example:
C++ code:
class C { public:int value; }
gdb commands (pseudo-code):
var v = new C()
print v.value
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
gdb 目前不支持“new”。它根本不在解析器中处理。如果您想跟踪其进度,gdb bugzilla 中存在一个针对此问题的错误。有人(咳咳)正在研究它。
同时,我想也许你可以手动完成。不过我从来没有真正尝试过这个。这个想法是这样的:
但是,您可能在该调用中需要其他参数,因为 C++ ABI 指定了一些神奇的隐藏参数。
另一种方法是在程序中创建一个调试便利函数:
然后您可以直接从 gdb 调用它。
"new" is not currently supported in gdb. It isn't handled in the parser at all. There is a bug open for this in gdb bugzilla if you want to track progress on it. Someone (cough cough) is working on it.
Meanwhile, I think maybe you can do it manually. I have never tried this for real though. The idea is something like:
However, you may need additional arguments in that call, since the C++ ABI specifies some magical hidden arguments.
Another approach is to make a debugging convenience function in your program:
Then you can just call this directly from gdb.