如何在 gdb 中列出类方法?

How to list class methods in gdb?(如何在 gdb 中列出类方法?)
本文介绍了如何在 gdb 中列出类方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在谷歌上搜索并检查 gdb 手册,但似乎无法找到我正在尝试做的事情的答案.

I've been googling for this and checking through the gdb manual but can't seem to find an answer to what I'm trying to do.

有没有办法让 gdb 打印出给定类类型的所有方法的列表?print 命令似乎只显示数据成员和字段,没有显示任何方法.

Is there a way to get gdb to print out a listing of all the methods for a given class type? The print command only seems to show the data members and fields, none of the methods are displayed for it.

此外,更进一步,有没有办法打印给定基 * 指针的所有正确虚拟方法?比如说:

Additionally, to take it a step further, is there a way to print all the correct virtual methods given a base *pointer? Say like for example:

struct A
{
  virtual void foo() {}
};

struct B : public A
{
  void foo() {}
};

int main()
{
  A *b = new B;
}

如何让 gdb 打印变量 *b 并让它显示正确的虚拟方法?

How can I get gdb to print variable *b and have it show the correct virtual method(s)?

谢谢

推荐答案

你可以使用ptype.

假设我将这些行添加到您的示例中:

Suppose I add these lines to your example:

A alpha;
B beta;

现在在 gdb 中,我可以要求对类类型(或类类型的实例)进行描述:

Now in gdb I can ask for a description of a class type (or an instance of one):

(gdb) ptype alpha
type = class A {
  public:
    virtual void foo();
}

(gdb) ptype A
type = class A {
  public:
    virtual void foo();
}

(gdb) ptype beta
type = class B : public A {
  public:
    virtual void foo();
}

(gdb) ptype B
type = class B : public A {
  public:
    virtual void foo();
}

如果我用指针尝试,我会得到声明的类型:

If I try that with a pointer, I get the declared type:

(gdb) ptype b
type = class A {
  public:
    virtual void foo();
} *

如果我想要真正的类型,我必须设置`print object'变量:

(gdb) set print object on
(gdb) ptype b
type = /* real type = B * */
class A {
  public:
    virtual void foo();
} *

然后再调用ptype,看看B有什么(一步都不知道怎么弄).

and then call ptype again to see what B has (I don't know how to do it in one step).

这篇关于如何在 gdb 中列出类方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Rising edge interrupt triggering multiple times on STM32 Nucleo(在STM32 Nucleo上多次触发上升沿中断)
How to use va_list correctly in a sequence of wrapper functions calls?(如何在一系列包装函数调用中正确使用 va_list?)
OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?(OpenGL透视投影裁剪多边形,顶点在视锥外=错误的纹理映射?)
How does one properly deserialize a byte array back into an object in C++?(如何正确地将字节数组反序列化回 C++ 中的对象?)
What free tiniest flash file system could you advice for embedded system?(您可以为嵌入式系统推荐什么免费的最小闪存文件系统?)
Volatile member variables vs. volatile object?(易失性成员变量与易失性对象?)