Search code examples
c++stlvectorgdbicc

How do I examine the contents of an std::vector in gdb, using the icc compiler?


I want to examine the contents of a std::vector in gdb but I don't have access to _M_impl because I'm using icc, not gcc, how do I do it? Let's say it's a std::vector for the sake of simplicity.

There is a very nice answer here but this doesn't work if I use icc, the error message is "There is no member or method named _M_impl". There appears to be a nice debug toolset here but it also relies on _M_impl.


Solution

  • Not sure this will work with your vector, but it worked for me.

    #include <string>
    #include <vector>
    
    int main() {
        std::vector<std::string> vec;
        vec.push_back("Hello");
        vec.push_back("world");
        vec.push_back("!");
        return 0;
    }
    

    gdb:

    (gdb) break source.cpp:8
    (gdb) run
    (gdb) p vec.begin()
    $1 = {
       _M_current = 0x300340
    }
    (gdb) p $1._M_current->c_str()
    $2 = 0x3002fc "Hello"
    (gdb) p $1._M_current +1
    $3 = (string *) 0x300344
    (gdb) p $3->c_str()
    $4 = 0x30032c "world"