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
@ks1322 has the correct answer. Here are some additional information that may be useful in the future.
Only the constructor, destructor and insert methods on std::map are in the debuginfo:
(gdb) info functions std::map
All functions matching regular expression "std::map":
File /usr/include/c++/6/bits/stl_map.h:
std::pair >, bool> std::map, std::allocator > >::insert, void>(std::pair&&);
void std::map, std::allocator > >::map();
void std::map, std::allocator > >::~map();
Still, we can call both the size and empty methods:
(gdb) p amap.size()
$1 = 1
(gdb) p amap.empty()
$2 = false
That's because gdb has something called xmethods, a python API for calling mockup functions meant to work identically to the functions that have not been instantiated. The libstdc++ xmethods can be found here. If we disable them, then the same error message appears:
(gdb) disable xmethod
(gdb) p amap.size()
Cannot evaluate function -- may be inlined
(gdb) p amap.empty()
Cannot evaluate function -- may be inlined
(gdb)