C++, STL, GDB: Cannot evaluate function maybe inlined

前端 未结 2 877
后悔当初
后悔当初 2021-01-17 23:26

I want to be able to get the address and print a single pair from an STL container using GDB.

E.g., given the following toy program:

#include 

        
2条回答
  •  一整个雨季
    2021-01-17 23:59

    This is because amap.begin() does not exist in resulting binary. This is how C++ templates work: if you don't use or explicitly instantiate some template method it is not generated in resulting binary.

    If you do want to call amap.begin() from gdb you have to instantiate it. One way to do it is to instantiate all methods of std::map:

    #include 
    
    template class std::map;
    
    int main()
    {
      std::map amap;
      amap.insert(std::make_pair(1,2));
    }
    

    gdb session:

    (gdb) p amap.begin()
    $1 = {first = 1, second = 2}
    

提交回复
热议问题