gdb 可以中断隐式类方法吗?

编译器会生成一些类方法,如复制构造函数、析构函数等.是否可以在这些方法上设置 gdb 中断,例如,观察对象被复制或销毁的位置?

The compiler generates some class methods like copy constructors, destructors, etc. Is it possible to have gdb break on those methods to, e.g., observe where objects are being copied or destroyed?

推荐答案

gdb 可以中断隐式类方法吗?

Can gdb break on implicit class methods?

是的,当然可以.

(gdb) break MyClass::MyClass(const MyClass &)     // break when copied
(gdb) break MyClass::~MyClass()                   // break when object destroyed

就这么简单.这些是基于断点的,不是基于文件:行,而是基于函数名.如果你有一个包装类的命名空间,那么请确保为它提供完全限定的名称,例如

as simple as that. These are breakpoints based, NOT on file:line, but on function names. If you've a namespace wrapping the class then make sure you give the fully qualified name for it e.g.

(gdb) break NyNamespace::MyClass::MyClass(const MyClass &)

在这里查看列表在 GDB 中指定断点的方法.

Look here for a list of ways to specify breakpoints in GDB.

相关文章