5

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 ?

Apoorva sahay
  • 1,900
  • 3
  • 28
  • 45

3 Answers3

2

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.

Apoorva sahay
  • 1,900
  • 3
  • 28
  • 45
0

You can try:

$ p abc->c_str()
unwind
  • 391,730
  • 64
  • 469
  • 606
0
p objPtr->a 

will print the data member type and value of variable a

SunDontShine
  • 128
  • 2
  • 13