This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
uninitialized memory, pretty printers and full backtraces
- From: Phil Muldoon <pmuldoon at redhat dot com>
- To: Project Archer <archer at sourceware dot org>
- Date: Thu, 22 Jan 2009 15:18:13 +0000
- Subject: uninitialized memory, pretty printers and full backtraces
I was working on another pretty printing task, when I noted the
behaviour below. I'm not sure how to fix it. Thought it worth discussing
here.
The basic premise is that in a "bt full" condition, the pretty printers
appear to try and grok (and pretty print) all local variables in a frame
- even if they are not initialized at the time the "bt full" was
requested. I believe this is not so different from existing GDB
behaviour. But with the Python pretty printers, the problem is
magnified as the printers will attempt to read, and interpret assorted
random memory addresses in an uninitialized class.
Take a simple C++ program:
#include <string>
#include <iostream>
using namespace std;
class foo
{
std::string message;
public:
foo (const char *c) : message (c)
{
}
void print()
{
cout << message << endl;
}
};
main ()
{
int i;
i++;
i++;
foo test("hello world");
test.print();
}
... and build it in the usual fashion and load into GDB:
./gdb ~/pretty_print_bug
<snips lots of GDB output>
(gdb) python
execfile("/home/pmuldoon/pretty_printing_python_tree/archer/gdb/python/lib/gdb/libstdcxx/v6/printers.py")
(gdb) set print pretty on
(gdb) b main
(gdb) r
Starting program: /home/pmuldoon/pretty_print_bug
Breakpoint 1, main () at /home/pmuldoon/pretty_print_bug.cpp:26
26 i++;
As the the "test" instantiation of foo has not happened yet, a "bt full"
will fail.
(gdb) bt full
#0 main () at /home/pmuldoon/pretty_print_bug.cpp:27
i = 1
test = {
message = Traceback (most recent call last):
File
"/home/pmuldoon/pretty_printing_python_tree/archer/gdb/python/lib/gdb/libstdcxx/v6/printers.py",
line 458, in to_string
return self.val['_M_dataplus']['_M_p'].string(encoding)
RuntimeError: Input/output error
If you step past the instantiation later:
(pg-gdb) n
29 foo test("hello world");
(pg-gdb) n
30 test.print();
(pg-gdb) bt full
#0 main () at /home/pmuldoon/pretty_print_bug.cpp:30
i = 2
test = {
message = "hello world"
}
Everything works. The "test" instantiation has been properly initialized
and the pretty printers can grok the contents of the class. The printers
fail in various ways with random "Cannot access memory at address 0x0"
or the error above, or lots of others ;) The backtrace also seems to
stop at that point (though I have not tested that in many scenarios.).
Anyway, the errors are just covering up that pretty printers are trying
to read and interpret garbage.
Regards
Phil