From: ro@techfak.uni-bielefeld.DE (Rainer Orth)
Subject: gdb 4.6 bugs on Solaris 2.0
Organization: GNUs Not Usenet
Distribution: gnu
Date: Fri, 2 Oct 1992 01:27:38 GMT

I've just built gdb 4.6 on a Sparcstation ELC running Solaris 2.0, using
gcc 2.2.2 ss-920925.

It was configured using

	configure --prefix=/vol/gnu sparc-sun-solaris2.0

To get it compile, it was necessary to override `CFLAGS=-g -xs' in
config/mh-solaris via `CFLAGS=-g -O', since gcc doesn't know about -xs. 

At first, gdb/munch created an invalid gdb/init.c if used with GNU egrep 1.6:

It uses egrep '|__?initialize_', which is interpreted as 

	<empty pattern> OR __?initialize.

This matches every line of the nm output.  The RE should be replaced by
'\|__?initialize_', which works both with /bin/egrep and GNU egrep.

The resulting gdb runs fine most of the time, but crashed in one case with
a segfault in strcmp.  Here's a script of the relevant session:

ro@efeu 1 > gdb gdb-4.6
GDB is free software and you are welcome to 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.
GDB 4.6, Copyright 1992 Free Software Foundation, Inc...
Setting up the environment for debugging gdb.
Breakpoint 1 at 0x44d18: file utils.c, line 274.
Breakpoint 2 at 0x22950: file main.c, line 1658.
(top-gdb) cd /vol/gnu/src/gdb-4.6/gdb
Working directory /vol/gnu/src/gdb-4.6/gdb
 (canonically /volumes/gnu/src/gdb-4.6/gdb).
(top-gdb) ro@efeu 2 > gdb gdb-4.6
GDB is free software and you are welcome to 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.
GDB 4.6, Copyright 1992 Free Software Foundation, Inc...
Setting up the environment for debugging gdb.
Breakpoint 1 at 0x44d18: file utils.c, line 274.
Breakpoint 2 at 0x22950: file main.c, line 1658.
(top-gdb) run
Starting program: /vol/gnu/bin/gdb-4.6 
GDB is free software and you are welcome to 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.
GDB 4.6, Copyright 1992 Free Software Foundation, Inc.
Setting up the environment for debugging gdb.
No symbol table is loaded.  Use the "file" command.
(gdb) cd /vol/local/src/amd/A.sun4_sos5
Working directory /vol/local/src/amd/A.sun4_sos5
 (canonically /volumes/local/src/amd/A.sun4_sos5).
(gdb) file amd
Reading symbols from amd...done.
(gdb) b main

Program received signal 11, Segmentation fault
0xef752c90 in strcmp ()
(top-gdb) where
#0  0xef752c90 in strcmp ()
#1  0x64c3c in read_func_scope (dip=0xeffff120, thisdie=0x170f87 "", 
    enddie=0x170fc4 "", objfile=0x150d08) at ./dwarfread.c:1533
#2  0x64f68 in process_dies (thisdie=0x170f87 "", enddie=0x175a30 "xxt", 
    objfile=0x150d08) at ./dwarfread.c:1725
#3  0x64e24 in read_file_scope (dip=0xeffff290, thisdie=0x165008 "", 
    enddie=0x175a30 "xxt", objfile=0x150d08) at ./dwarfread.c:1648
#4  0x64f3c in process_dies (thisdie=0x165008 "", enddie=0x175a30 "xxt", 
    objfile=0x150d08) at ./dwarfread.c:1719
#5  0x65440 in read_ofile_symtab (pst=0x4887d0) at ./dwarfread.c:2048
#6  0x65570 in psymtab_to_symtab_1 (pst=0x4887d0) at ./dwarfread.c:2108
#7  0x6564c in dwarf_psymtab_to_symtab (pst=0x4887d0) at ./dwarfread.c:2165
#8  0x3d264 in psymtab_to_symtab (pst=0x4887d0) at symfile.c:303
#9  0x3a2d0 in find_pc_symtab (pc=185156) at symtab.c:992
#10 0x39990 in lookup_symbol (name=0xeffff650 "main", block=0x162c60, 
    namespace=VAR_NAMESPACE, is_a_field_of_this=0x10a400, symtab=0xeffff6d0)
    at symtab.c:581
#11 0x3b3c4 in decode_line_1 (argptr=0xeffff7ec, funfirstline=1, 
    default_symtab=0x0, default_line=0) at symtab.c:1793
#12 0x25ee4 in break_command_1 (arg=0x10f00e "", tempflag=0, from_tty=1)
    at breakpoint.c:1493
#13 0x261a4 in break_command (arg=0x10f00a "main", from_tty=1)
    at breakpoint.c:1578
---Type <return> to continue---
#14 0x21bb8 in execute_command (p=0x10f00a "main", from_tty=1) at main.c:915
#15 0x21d78 in command_loop () at main.c:976
#16 0x21a1c in main (argc=1, argv=0xeffffbdc) at main.c:853
(top-gdb) up
#1  0x64c3c in read_func_scope (dip=0xeffff120, thisdie=0x170f87 "", 
    enddie=0x170fc4 "", objfile=0x150d08) at ./dwarfread.c:1533
Source file is more recent than executable.
1533      if (STREQ (dip -> at_name, "main"))   /* FIXME: hardwired name */
(top-gdb) *dip
$2 = {die = 0x170f87 "", die_length = 30, die_ref = 2836959, die_tag = 20, 
  at_padding = 0, at_sibling = 2837020, at_location = 0x0, at_name = 0x0, 
  at_fund_type = 0, at_mod_fund_type = 0x0, at_user_def_type = 0, 
  at_mod_u_d_type = 0x0, at_ordering = 0, at_subscr_data = 0x0, 
  at_byte_size = 0, at_bit_offset = 0, at_bit_size = 0, at_element_list = 0x0, 
  at_stmt_list = 0, at_low_pc = 186068, at_high_pc = 186096, at_language = 0, 
  at_member = 0, at_discr = 0, at_discr_value = 0x0, at_visibility = 0, 
  at_import = 0, at_string_length = 0x0, at_comp_dir = 0x0, at_producer = 0x0, 
  at_frame_base = 0, at_start_scope = 0, at_stride_size = 0, at_src_info = 0, 
  at_prototyped = 0x0, has_at_low_pc = 1, has_at_stmt_list = 0, 
  short_element_list = 0}
(top-gdb) quit
The program is running.  Quit anyway? (y or n) y

GDB crashes in dwarfread.c (read_func_scope) since one argument to strcmp
is a NULL pointer.  A quick and dirty fix is to check for this in the STREQ
and STREQN macros, both here and in elfread.c.  But I'm not shure if this
is the correct fix or if the crash is triggered by a bug in gcc, producing
wrong symbol tables.

===================================================================
RCS file: RCS/dwarfread.c,v
retrieving revision 1.1
diff -u -r1.1 dwarfread.c
--- dwarfread.c	1992/07/14 07:34:23	1.1
+++ dwarfread.c	1992/09/30 21:06:29
@@ -83,8 +83,8 @@
 #define CFRONT_PRODUCER "CFRONT "	/* A wild a** guess... */
 #endif
 
-#define STREQ(a,b)		(strcmp(a,b)==0)
-#define STREQN(a,b,n)		(strncmp(a,b,n)==0)
+#define STREQ(a,b)		(a != NULL && b != NULL && strcmp(a,b)==0)
+#define STREQN(a,b,n)		(a != NULL && b != NULL && strncmp(a,b,n)==0)
 
 /* Flags to target_to_host() that tell whether or not the data object is
    expected to be signed.  Used, for example, when fetching a signed
===================================================================
RCS file: RCS/elfread.c,v
retrieving revision 1.1
diff -u -r1.1 elfread.c
--- elfread.c	1992/07/06 17:10:45	1.1
+++ elfread.c	1992/09/30 21:06:49
@@ -46,7 +46,7 @@
 #include <sys/types.h>		/* For off_t for gdb-stabs.h */
 #include "gdb-stabs.h"
 
-#define STREQ(a,b) (strcmp((a),(b))==0)
+#define STREQ(a,b) ((a) != NULL && (b) != NULL && strcmp((a),(b))==0)
 
 /* The struct elfinfo is available only during ELF symbol table and
    psymtab reading.  It is destroyed at the complation of psymtab-reading.

-----------------------------------------------------------------------------
Rainer Orth, Technical Computer Science, University of Bielefeld

Internet: ro@TechFak.Uni-Bielefeld.DE


Newsgroups: gnu.gdb.bug