c++ - listing all function of class in gdb -
i trying larn debugging using gdb. have got starting.
i want know possible list functions of class including default 1 provided compiler?
or other way without using , ide
thanks
=============================================================================
the code trying:
#include <iostream> class myclass { public: void hello() { } int a; }; int main(int argc, char **argv) { myclass a; myclass b = a; myclass c; c = a; homecoming 0; }
=update 3====================================================================
i want list compiler provided function name, if possible in gdb.
my question in add-on question posted at
how list class methods in gdb?
you have written simple class. advice:
once have executable loaded in gdb, type break (or b) , nail tab key.
is right in general in case mingw not create myclass. compiled programme mingw , disassembled it:
(gdb) disassemble /m main dump of assembler code function main(int, char**): 13 { 0x0040138c <+0>: force %ebp 0x0040138d <+1>: mov %esp,%ebp 0x0040138f <+3>: , $0xfffffff0,%esp 0x00401392 <+6>: sub $0x10,%esp 0x00401395 <+9>: phone call 0x40193c <__main> 14 myclass a; 15 myclass b = a; 0x0040139a <+14>: mov 0xc(%esp),%eax 0x0040139e <+18>: mov %eax,0x8(%esp) 16 myclass c; 17 c = a; 0x004013a2 <+22>: mov 0xc(%esp),%eax 0x004013a6 <+26>: mov %eax,0x4(%esp) 18 homecoming 0; 0x004013aa <+30>: mov $0x0,%eax 19 } 0x004013af <+35>: leave 0x004013b0 <+36>: ret end of assembler dump.
as can see move instructions. illustration assigments c = a;
results in 2 move instructions , no function calls:
0x004013a2 <+22>: mov 0xc(%esp),%eax 0x004013a6 <+26>: mov %eax,0x4(%esp)
as can see compiler chose not generate class. in sentiment chose simple illustration larn want.
i made illustration little bit more complex
#include <iostream> class myclass { public: void hello() { std::cout << "hello\n"; } int a; }; int main(int argc, char **argv) { myclass a; a.hello(); myclass b = a; myclass c; c = a; homecoming 0; }
and under gdb
break shows this:
(gdb) b myclass myclass myclass::hello() (gdb) b myclass
and output of nm:
d:\src-c++\test.names>nm -c ./m.exe | grep myclass 00404060 r .eh_frame$_zn7myclass5helloev 00401c20 t .text$_zn7myclass5helloev 00401c20 t myclass::hello()
i wanted see default function generated class, if 1 not write it
change fellow member class variable 'int a' std::string , see default functions generated compiler
#include <iostream> #include <string> class myclass { public: void hello() { } std::string a; }; int main(int argc, char **argv) { myclass a; myclass b = a; myclass c; c = a; homecoming 0; }
and these compile-generated functions:
>nm -c ./a.out | grep 00000000004009b8 w myclass::myclass(myclass const&) 0000000000400964 w myclass::myclass() 000000000040097c w myclass::~myclass() 0000000000400994 w myclass::operator=(myclass const&)
c++ gdb g++
No comments:
Post a Comment