2017-10-10 65 views
0

我在遗留项目中工作,偶然发现修改用例。我的分析总结为一堂课。我能够追踪班上的一些方法,但随着我的进行,在分析中变得有点乏味。列出派生类中的所有方法/变量

是否有一种机制/方法可以让我知道给定类的所有方法(用户定义/继承等)及其成员变量,尤其是Linux平台?

+1

每个IDE都应该为您完成这项工作。另外vim和ctags能够给你一个定义列表。最后一个可能没有继承... – Klaus

+0

阅读定义,并且父级别中每个类的定义是最简单的方法,但如果成员函数是内联定义的,则可能涉及通过大量代码涉水。 – user2079303

回答

0

你可以使用gdb,但这意味着你必须导航到代码的那一部分。如果我有一个小程序:

struct AAA { 
    int iii; 
    int aonly; 
    void foo() { 
    } 
}; 

struct BBB: public AAA { 
    int iii; 
    int bonly; 
    void fooB() { 
    } 
}; 

int main (int argc, const char* argv[]) { 
    BBB b; 
    b.iii = 1; 
    return 0; 
} 

我可以调试符号(-g在G ++)编译,设置一个断点并打印对象:

[email protected]:/tmp/ttt$ g++ -g a.cpp 
[email protected]:/tmp/ttt$ gdb a.out 
*** output flushed *** 
(gdb) b 18 
Breakpoint 1 at 0x4004e8: file a.cpp, line 18. 
(gdb) R 
Starting program: /tmp/ttt/a.out 

Breakpoint 1, main (argc=1, argv=0x7fffffffe278) at a.cpp:18 
18  return 0; 
(gdb) ptype b 
type = struct BBB : public AAA { 
    int iii; 
    int bonly; 
    public: 
    void fooB(void); 
} 
(gdb) p b 
$1 = {<AAA> = {iii = -7568, aonly = 32767}, iii = 1, bonly = 0} 
(gdb) p b.iii 
$2 = 1 
(gdb) p b.AAA::iii 
$3 = -7568 

有你所看到的BBB从继承AAA。这并不好,但总比没有好。

+0

很多感谢指针。我可以调试对象创建本身 - 正在调用哪个类构造函数并继续前进 – Prakash