Reputation: 1930
Hi I am currently debugging my code base in linux machine through GDB. I am currently facing an issue in getting value of a data member from object ptr of a class. To print the location for object ptr we can use either "p" (print) or "display" command.
For Eg: I have class like this
class abc
{
string a;
};
So in my code if I am using a pointer for class abc, then
abc* objPtr = new abc();
so after breaking at above line i will get objPtr and now I want to check value of datamember a (abc::a) value. how I could do that?
(gdb) p objPtr
$2 = {px = 0x3ba6430690, pn = {pi_ = 0x3ba6430698}}
Moreover Is there a different way to check a data member which is a list / vector ?
Upvotes: 5
Views: 7685
Reputation: 158
p objPtr->a
will print the data member type and value of variable a
Upvotes: 0
Reputation: 1930
I got the answer.
$p/a objPtr->datamember->[if datamember also has some data member then we can call it in recurcion / can also call member function].
for list/vector we could refer to http://sourceware.org/ml/gdb/2008-02/msg00064/stl-views.gdb.
Upvotes: 2