2

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?

ks1322
  • 33,961
  • 14
  • 109
  • 164
ricab
  • 2,697
  • 4
  • 23
  • 28
  • If the operating system fits: Try valgrind –  Oct 30 '13 at 12:30
  • What do you mean by saying "variables are pointing to this vector". Do you mean the pointer variable that holds the vector object address? – Alexey Teplyakov Oct 30 '13 at 12:33
  • @AlexeyTeplyakov: which are the C++ variables whose current value is that vector – ricab Oct 30 '13 at 14:02
  • Does this answer your question? [How to get the symbol name for a memory address in GDB?](https://stackoverflow.com/questions/762628/how-to-get-the-symbol-name-for-a-memory-address-in-gdb) – user202729 Dec 07 '21 at 01:51

2 Answers2

3

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.

ks1322
  • 33,961
  • 14
  • 109
  • 164
1

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

Alexey Teplyakov
  • 316
  • 3
  • 10