c++/2477: print object on + NULL pointer => gdb error

ppluzhnikov@google.com ppluzhnikov@google.com
Mon Jul 14 16:08:00 GMT 2008


>Number:         2477
>Category:       c++
>Synopsis:       print object on + NULL pointer => gdb error
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jul 14 16:08:01 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator:     ppluzhnikov@google.com
>Release:        6.8.50.20080711-cvs
>Organization:
>Environment:
x86_64-unknown-linux-gnu
>Description:
With "set print object on" (which is very useful when dealing with
pointers to base classes), one can't print NULL pointers:

cat foo.cc
struct Foo {
 Foo() : next(0) { }
 virtual ~Foo() { }
 Foo *next;
};

void fn(Foo *p) { }
int main()
{
 Foo foo;
 fn(&foo);
}


g++ -g foo.cc
gdb64 -q a.out

(gdb) b fn
Breakpoint 1 at 0x4002e0: file foo.cc, line 7.
(gdb) r

Breakpoint 1, fn (p=0x7fffffffe6b0) at foo.cc:7
7       void fn(Foo *p) { }
(gdb) set print object on
(gdb) p p
$1 = (Foo *) 0x7fffffffe6b0
(gdb) p p.next
$2 = (Cannot access memory at address 0x0


This in itself is a minor annoyance; but it also aborts "canned
commands", which is a major annoyance. For example:


(gdb) b fn
Breakpoint 1 at 0x4002e0: file foo.cc, line 7.
(gdb) commands 1
> p p
> p p->next
> cont
> end

(gdb) r

Breakpoint 1, fn (p=0x7fffffffe6b0) at foo.cc:7
7       void fn(Foo *p) { }
$1 = (Foo *) 0x7fffffffe6b0
$2 = (Foo *) 0x0

Program exited normally.

(gdb) commands 1
> set print object on
> p p
> p p->next
> c
> end
(gdb) r

Breakpoint 1, fn (p=0x7fffffffe6b0) at foo.cc:7
7       void fn(Foo *p) { }
$3 = (Foo *) 0x7fffffffe6b0
$4 = (Cannot access memory at address 0x0
(gdb)             # command sequence aborted, continue not done :(
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gdb-prs mailing list