GDB maintainers:

I have found two bugs worth reporting to you in gdb 4.18.  The bugs
also occur in 4.17, as well as in the latest egcs snapshot of gdb.
Both of these bugs occur under Solaris2.7, and the first one occurs
under linux also.  'uname -a' on the Sun box reports
  SunOS bat 5.7 Generic_106541-08 sun4u sparc SUNW,Ultra-Enterprise

The second bug is very significant, since it prevents developers from
printing the return value of function under gdb.

Thanks in advance for any assistance you can provide.
-- David Magerman
[EMAIL PROTECTED]

1) Given the following program:

foo.C:
---------
int baz(int k) { return k; }
int main() { int i = baz(15); return 0; }

compiled using g++-2.95.2, I get the following behavior:

bat:~> g++-2.95.2 -g foo.C
bat:~> /home/glen/gdb-4.18/gdb/gdb a.out
GNU gdb 4.18
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "sparc-sun-solaris2.7"...
(gdb) break main
Breakpoint 1 at 0x10568: file foo.C, line 2.
(gdb) run
Starting program: /home/magerman/a.out 

Breakpoint 1, main () at foo.C:2
2       int main() { int i = baz(15); return 0; }
(gdb) print baz(20)
Segmentation Fault
bat:~>

Since gdb crashes, I tried debugging gdb with gdb itself.  Here is the
result:

bat:~> /home/glen/gdb-4.18/gdb/gdb /home/glen/gdb-4.18/gdb/gdb
GNU gdb 4.18
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "sparc-sun-solaris2.7"...
(gdb) run a.out
Starting program: /home/glen/gdb-4.18/gdb/gdb a.out
GNU gdb 4.18
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "sparc-sun-solaris2.7"...
(gdb) break main
Breakpoint 1 at 0x10568: file foo.C, line 2.
(gdb) run
Starting program: /home/magerman/a.out 

Breakpoint 1, main () at foo.C:2
2       int main() { int i = baz(15); return 0; }
(gdb) print baz(20)

Program received signal SIGSEGV, Segmentation fault.
0x45ea4 in find_overload_match (arg_types=0x217ac8, nargs=1, name=0x0, 
    method=0, lax=1, obj=0x0, fsym=0x1c5bb8, valp=0x0, symp=0xffbed7a4, 
    staticp=0x0) at valops.c:2652
2652          nparms = method ? TYPE_NFIELDS (fns_ptr[ix].type)
(gdb) bt
#0  0x45ea4 in find_overload_match (arg_types=0x217ac8, nargs=1, name=0x0, 
    method=0, lax=1, obj=0x0, fsym=0x1c5bb8, valp=0x0, symp=0xffbed7a4, 
    staticp=0x0) at valops.c:2652
#1  0x40690 in evaluate_subexp_standard (expect_type=0x2, exp=0x2c12b0, 
    pos=0xffbed99c, noside=EVAL_NORMAL) at eval.c:924
#2  0x3ee14 in evaluate_expression (exp=0x2c12b0) at eval.c:71
#3  0x4cb04 in print_command_1 (exp=0x1a4c56 "baz(20)", inspect=0, voidprint=1)
    at printcmd.c:869
#4  0x4ccb4 in print_command (exp=0x1a4c56 "baz(20)", from_tty=1)
    at printcmd.c:934
#5  0xd123c in execute_command (p=0x1a4c5c ")", from_tty=1) at top.c:1268
#6  0xd1424 in command_loop () at top.c:1365
#7  0xd8d68 in main (argc=2, argv=0xffbede34) at main.c:635
(gdb) quit
bat:~>

Based on snooping around the source code a little, I found what might
be the problem (or at least *a* problem).  

In symtab.c, the function make_symbol_overload_list, on line 4411,
loops over all 'minimum_symbols' in an object file and tries to add
them to the overload list.  The problem with adding minimum_symbols to
the overload list is that the TYPE field in the minimum_symbol
structure is an enum, not a pointer.  However, this list eventually
gets passed to find_overload_match, which dereferences the TYPE field
to get the TYPE_NFIELDS.  If I comment out lines 4411-4415 in
symtab.c, gdb no longer crashes.

However, this leads us to bug #2:

2) Given the same program

foo.C:
---------
int baz(int k) { return k; }
int main() { int i = baz(15); return 0; }

compiled using g++-2.95.2, using the patched gdb, I get the following behavior:

bat:~> /home/glen/gdb-4.18/gdb/gdb a.out
GNU gdb 4.18
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "sparc-sun-solaris2.7"...
(gdb) break main
Breakpoint 1 at 0x10568: file foo.C, line 2.
(gdb) run
Starting program: /home/magerman/a.out 

Breakpoint 1, main () at foo.C:2
2       int main() { int i = baz(15); return 0; }
(gdb) print baz(20)

Program received signal SIGSEGV, Segmentation fault.
<function called from gdb>
The program being debugged stopped while in a function called from GDB.
When the function (baz(int)) is done executing, GDB will silently
stop (instead of continuing to evaluate the expression containing
the function call).
(gdb) quit
bat:~>

This behavior happens under gdb-4.17 also.  It does not happen on
linux, however, and it does not occur on Solaris2.7 machines with a
patch level of 106541-07 or below.

Reply via email to