I have a gdb session for a core and it indicates that there's a segfault in a dereference of a pointer when reading one of its members. The pointer is non-null in value. I assume this means that the memory address was not accessible to the process. How do I get this information from a postmortem gdb session of the core?
For instance, given the following program:
#include <iostream>
using namespace std;
int
main(int argc, char* argv[])
{
int *ptr = new int(5);
cout << "I can access it here: " << *ptr << endl;
delete ptr;
cout << "But I shouldn't do so here: " << *ptr << endl;
return 0;
}
If I debug this program with gdb:
$ g++ -g -Wall test.cc -o test
$ gdb ./test
(gdb) b 13
...
Breakpoint 1 at 0x400943: file test.cc, line 13.
(gdb) run
Starting program: /usr/home/nfs/bneradt/test/test
I can access it here: 5
Breakpoint 1, main (argc=1, argv=0x7fffffffe348) at test.cc:13
13 cout << "But I shouldn't do so here: " << *ptr << endl;
(gdb)
What kind of memory information can I get from ptr? Can I determine that ptr points to freed memory? Since in the core I'm debugging (not in the toy test binary above) I got a seg fault dereferencing - i.e., reading from, not writing to - a pointer, I suppose the original memory location got paged out and therefore wasn't process-accessible memory? Can I determine that from the gdb session?