If I have some C++ program, e.g.:
#include <string>
std::string foo()
{
return "bar";
}
int main()
{
foo();
return 0;
}
where there is a call to some function (e.g. foo
) and I step over it (and thus I cannot perform finish
that would otherwise show the return value). If this function returns some value (e.g. of type std::string
), how can I print the value returned by the function I just stepped over?
If the returned value is scalar, I can see the returned value in the appropriate register (i.e. in $rax
on Intel's x64 architecture).
If the returned value is structured value, in rax
register I just see a pointer. I failed to persuade gdb
to pretty-print the underlying structured value to which $rax
points. I would be able to specify the C++ type by casing $rax
to the appropriate pointer type as long as I do not have to cite mangled version of C++ types.
If, instead of just stepping over the function (with next
gdb command) I "step in" in the function (with step
gdb command) and then subsequently finishing the function (with finish
gdb command), the returned value is pretty-printed and I can see it. This is a usable workaround, but I am interested in proper way, if it exists.
If gdb
does not provide such command out of the box, is it possible to define some Python or Scheme macro that would (pretty-) print the returned value?