Add functions in gdb at runtime
- by Michael Anderson
I'm trying to debug some STL based C++ code in gdb.
The code has something like
int myfunc()
{
std::map<int,int> m;
...
}
Now in gdb, inside myfunc using "print m" gives something very ugly.
What I've seen recommended is compiling something like
void printmap( std::map<int,int> m )
{
for( std::map<int,int>::iterator it = ... )
{
printf("%d : %d", it->first, it->second );
}
}
Then in gdb doing
(gdb) call printmap( m )
This seems like a good way to handle the issue... but can I put printmap into a seperate object file (or even dynamic library) that I then load into gdb at runtime rather than compiling it into my binary - as recompiling the binary every time I want to look at another STL variable is not fun .. while compiling and loading a single .o file for the print routine may be acceptable.