Add functions in gdb at runtime
Posted
by Michael Anderson
on Stack Overflow
See other posts from Stack Overflow
or by Michael Anderson
Published on 2010-04-09T02:14:44Z
Indexed on
2010/04/09
2:23 UTC
Read the original article
Hit count: 499
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.
© Stack Overflow or respective owner