Find all variables pointing to an address in gdb

+1 vote
asked Oct 30, 2013 by ricab

For context, my particular case is the following: I got a segfault and am analyzing the core; the stack trace shows the program called exit but crashed before completing it, within some vector's d'tor; I can get the address of the vector, but I am not familiar with the code and I don't know what variable it corresponds to; I would like to find out what variables are pointing to this vector to inspect related code. Any suggestions?

2 Answers

+3 votes
answered Oct 30, 2013 by ks1322

I can get the address of the vector... I would like to find out what variables are pointing to this vector

Having the address of some variable you can use info symbol command to print the name of a variable like this:

(gdb) info symbol 0x4005BDC

See Examining the Symbol Table in gdb documentation.

0 votes
answered Nov 29 by alexey-teplyakov

You can make a breakpoint right before the crash and print all the variables within the std::vector.

print *(your_vector._M_impl._M_start)@your_vector.size()

for example:

with std::vector<int> vec(3); you would write print *(vec._M_impl._M_start)@3

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
...