How to get item value in gdb?

Hi, I am currently debugging my code base in a Linux machine via GDB. I am currently facing the problem of getting the value of a data item from a ptr object of a class. To print the location of the ptr object, we can use the p command (print) or display.

For example: I have a class like this

class abc { string a; }; 

So in my code, if I use a pointer to the abc class, then

 abc* objPtr = new abc(); 

so after breaking above the line, I get objPtr, and now I want to check the value of datamember a (abc :: a). how could i do that?

 (gdb) p objPtr $2 = {px = 0x3ba6430690, pn = {pi_ = 0x3ba6430698}} 

Also, is there another way to check for a data item that is a list / vector?

+4
source share
2 answers

I got an 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 a list / vector, we could reference http://sourceware.org/ml/gdb/2008-02/msg00064/stl-views.gdb .

+1
source

You may try:

 $ p abc->c_str() 
0
source

Source: https://habr.com/ru/post/1415122/


All Articles