C ++, STL, GDB: it is impossible to evaluate a function, possibly built-in

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

IE: Given the following toy program:

#include <map>

int main() 
{
  std::map<int,int> amap;
  amap.insert(std::make_pair(1,2));

}

when I try to learn one map element (e.g. p amap.begin ()), I get:

"Unable to evaluate function - may be nested"

Removing optimization and enabling full debug mode ie (-O0 and -g3) does not work.

Why is this happening and how do I get around it?

+4
source share
2 answers

, amap.begin() . ++: , .

amap.begin() gdb, . - std::map:

#include <map>

template class std::map<int,int>;

int main()
{
  std::map<int,int> amap;
  amap.insert(std::make_pair(1,2));
}

gdb:

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

@ks1322 . , .

, std:: map debuginfo:

(gdb) info functions std::map
All functions matching regular expression "std::map":

File /usr/include/c++/6/bits/stl_map.h:
std::pair<std::_Rb_tree_iterator<std::pair<int const, int> >, bool> std::map<int, int, std::less<int>, std::allocator<std::pair<int const, int> > >::insert<std::pair<int, int>, void>(std::pair<int, int>&&);
void std::map<int, int, std::less<int>, std::allocator<std::pair<int const, int> > >::map();
void std::map<int, int, std::less<int>, std::allocator<std::pair<int const, int> > >::~map();

, , :

(gdb) p amap.size()
$1 = 1
(gdb) p amap.empty()
$2 = false

, gdb -, xmethods, API- python , , . libstd++ . , :

(gdb) disable xmethod
(gdb) p amap.size()
Cannot evaluate function -- may be inlined
(gdb) p amap.empty()
Cannot evaluate function -- may be inlined
(gdb) 
+1

Source: https://habr.com/ru/post/1660947/


All Articles