Oracle® Developer Studio 12.5:使用 dbx 调试程序

退出打印视图

更新时间: 2016 年 6 月
 
 

查看变量、成员、类型和类

whatis 命令可输出标识符、结构、类型和 C++ 类的声明或定义,或者表达式类型。您可以查找的标识符包括变量、函数、字段、数组和枚举常量。

有关更多信息,请参见whatis 命令

查找变量、成员和函数的定义

使用 whatis 命令可输出标识符的声明:

(dbx) whatis identifier

根据需要使用文件和函数信息来限定标识符名。

对于 C++ 程序,whatis 会列出函数模板实例。可使用 whatis -t 显示模板定义(请参见查找类型和类的定义)。

对于 Java 程序,whatis identifier 会列出类的声明、当前类中的方法、当前帧中的局部变量或当前类中的字段。

要输出成员函数,请键入以下命令:

(dbx) whatis block::draw
void block::draw(unsigned long pw);
(dbx) whatis table::draw
void table::draw(unsigned long pw);
(dbx) whatis block::pos
class point *block::pos();
(dbx) whatis table::pos
class point *block::pos();
:

要输出数据成员

(dbx) whatis block::movable
int movable;

对于变量,whatis 命令将提供变量的类型。

(dbx) whatis the-table
class table *the-table;
.

对于字段,whatis 命令将提供字段的类型。

(dbx) whatis the-table->draw
void table::draw(unsigned long pw);

当程序在成员函数中停止时,可以查找 this 指针。

(dbx) stop in brick::draw
(dbx) cont
(dbx) where 1
brick::draw(this = 0x48870, pw = 374752), line 124 in
     "block-draw.cc"
(dbx) whatis this
class brick *this;

查找类型和类的定义

whatis 命令的 -t 选项可显示类型的定义。 对于 C++,whatis -t 显示的列表包括模板定义和类模板实例。

要输出类型或 C++ 类的声明:

(dbx) whatis -t class-name

要仅查看数据成员,请使用 whatis 命令以及 –a 选项。该选项仅输出特定类的数据成员的列表(而不输出成员的函数)。它显示该信息的顺序与 –r 选项相同,即先从基类开始。

(dbx) whatis -t -a class-name

要查看 基类中的成员,可以在 whatis 命令中使用 -r 选项(用于递归)。这样将显示指定类的声明以及它从基类继承的成员。

(dbx) whatis -t -r  class-name

whatis -r 查询的输出可能会很长,具体取决于类分层结构以及类的大小。输出将显示继承的数据成员的列表,从最原始的类开始。插入的注释行将成员列表分到其各自的父类中。

要查看类的继承成员的根目录,可以在 whatis 命令中使用 -u 选项,以显示类型定义的根目录。如果不使用 -u 选项,则 whatis 命令将显示值历史记录中的最近值。这与 gdb 中使用的 ptype 命令类似。

在下面的两个示例中,使用了类 table,它是父类 load-bearing-block 的子类,而该父类又是 block 的子类。

如果不使用 -rwhatis 会报告在类 table 中声明的成员。

(dbx) whatis -t class table
class table : public load-bearing-block {
public:
    table::table(char *name, int w, int h, const class point &pos);
    virtual char *table::type();
    virtual void table::draw(unsigned long pw);
};

以下示例显示了对子类使用 whatis -r 来查看它所继承的成员时的结果。

(dbx) whatis -t -r class table
class table : public load-bearing-block {
public:
  /* from base class table::load-bearing-block::block */
  block::block();
  block::block(char *name, int w, int h, const class point &pos, class load-bearing-block *blk);
    virtual char *block::type();
    char *block::name();
    int block::is-movable();
//  deleted several members from example protected:
    char *nm;
    int movable;
    int width;
    int height;
    class point  position;
    class load-bearing-block *supported-by;
    Panel-item panel-item;
    /* from base class table::load-bearing-block */
public:
    load-bearing-block::load-bearing-block();
    load-bearing-block::load-bearing-block(char *name, int w, int h,
        const class point &pos, class load-bearing-block *blk);
    virtual int load-bearing-block::is-load-bearing();
    virtual class list *load-bearing-block::supported-blocks();
    void load-bearing-block::add-supported-block(class block &b);
    void load-bearing-block::remove-supported-block(class block &b);
    virtual void load-bearing-block::print-supported-blocks();
    virtual void load-bearing-block::clear-top();
    virtual void load-bearing-block::put-on(class block &object);
    class point load-bearing-block::get-space(class block &object);
    class point load-bearing-block::find-space(class block &object);
    class point load-bearing-block::make-space(class block &object);
protected:
    class list *support-for;
    /* from class table */
public:
    table::table(char *name, int w, int h, const class point &pos);
    virtual char *table::type();
    virtual void table::draw(unsigned long pw);
};