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?
            Asked
            
        
        
            Active
            
        
            Viewed 3,319 times
        
    2
            
            
        - 
                    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 Answers
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
- 
                    Unfortunately this method doesn't work with local (automatic) variables. – user202729 Dec 04 '21 at 07:59
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
