Cannot evaluate function -- may be in-lined error in GDB for STL template container
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 <map>
template class std::map<int,int>;
int main()
{
std::map<int,int> amap;
amap.insert(std::make_pair(1,2));
}
gdb session:
(gdb) p amap.begin()
$1 = {first = 1, second = 2}
gdb stl functions still show as inlined after disabling optimizations
My question is why are the functions showing up as inlined even after Disabling optimizations with -O0 options?
g++ will only instantiate templates that are actually used by your program, and your program doesn't actually use the size
method.
You can check this using nm
:
$ nm -C q|grep size
$
If I change your program to use return ivec.size()
, then I can:
(gdb) p ivec.size()
$1 = 0
This whole situation with inlining and non-instantiation is why the gdb xmethod
support was written. And, libstdc++ has some xmethods (though I didn't check if it specifically has this one). I recommend using that.
Inspecting standard container (std::map) contents with gdb
I think there isn't, at least not if your source is optimized etc. However, there are some macros for gdb that can inspect STL containers for you:
http://sourceware.org/ml/gdb/2008-02/msg00064.html
However, I don't use this, so YMMV
Possible to call inline functions in gdb and/or emit them using GCC?
One way to get the compiler to generate a callable version of an inline function is to include code that takes the address of the function. There is also an option you can give to gcc
. From the gcc documentation on inline functions:
When a function is both inline and static, if all calls to the function are
integrated into the caller, and the function's address is never used, then the
function's own assembler code is never referenced. In this case, GCC does not
actually output assembler code for the function, unless you specify the option
-fkeep-inline-functions.
Having GDB print a big std::map fully while debugging
Do you know any simpler way to print everything ?
(gdb) set print elements 0
Documentation.
Related Topics
Conversion from Derived** to Base**
How to Initialize the Reference Member Variable of a Class
Sorting Std::Strings with Numbers in Them
How to Save Hicon to an .Ico File
Parse Int or Double Using Boost Spirit (Longest_D)
Boost Asio - How to Write Console Server
Are Variadic MACros Nonstandard
Does C++11 Allow Dollar Signs in Identifiers
Why Must Virtual Base Classes Be Constructed by the Most Derived Class
Can Void* Be Used to Store Function Pointers
What Is the Class Keyword Before a Function Argument
Load 32-Bit Shared Library from 64-Bit Application
Using Bind1St for a Method That Takes Argument by Reference
Programmatically Getting System Boot Up Time in C++ (Windows)