🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gdb.bug
Article #157

patch for GDB 4.6; fixes Sun C++2.1 bug

#157
From: Renner
Date: Mon, 03 Aug 1992 19:31
143 lines
5301 bytes
GDB-4.6 does not work on binaries produced with Sun C++2.1 (1Mar1991)
on a Sun-4 running SunOS 4.1.2.  GDB generates a segmentation violation
while reading the symbol table.

The problem is due to the way Sun C++2.1 writes its symbol table.  When 
it's time to generate N_SO symbols for a new file, Sun C++2.1 generates
*three* N_SOs.  The first N_SO symbol specifies the directory.  The second
and third are duplicates, each specifying the file name.  GDB-4.6 doesn't
handle this properly.

The following patch to the "partial-stab.h" file corrects this problem
for Sun C++2.1.

===================================================================
RCS file: /usr/local/src/gdb-4.6/gdb/RCS/partial-stab.h,v
retrieving revision 1.2
retrieving revision 1.1
diff -c4 -r1.2 -r1.1
*** /tmp/RCSAa05445	Mon Aug  3 14:36:55 1992
--- /tmp/RCSBa05445	Mon Aug  3 14:36:55 1992
***************
*** 208,215 ****
--- 208,225 ----
  	  SET_NAMESTRING();
  
  	  valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
  
+ 	  if (pst)
+ 	    {
+ 	      END_PSYMTAB (pst, psymtab_include_list, includes_used,
+ 			   symnum * symbol_size, valu,
+ 			   dependency_list, dependencies_used);
+ 	      pst = (struct partial_symtab *) 0;
+ 	      includes_used = 0;
+ 	      dependencies_used = 0;
+ 	    }
+ 
  	  /* Some compilers (including gcc) emit a pair of initial N_SOs.
  	     The first one is a directory name; the second the file name.
  	     If pst exists, is empty, and has a filename ending in '/',
  	     we assume the previous N_SO was a directory name. */
***************
*** 217,249 ****
  	  p = strrchr (namestring, '/');
  	  if (p && *(p+1) == '\000')
  	    {
  	      dir_so_symnum = symnum;
- 	      last_so_symnum = -10;     /* Don't ignore next SO */
  	      continue;		/* Simply ignore directory name SOs */
  	    }
  
  	  /* Some other compilers (C++ ones in particular) emit useless
! 	     SOs for non-existant .c files. Also, Sun C++2.1 (1Mar1991)
! 	     emits *two* SOs for each new file.  We want to ignore the
! 	     second one. */
  
  	  if (last_so_symnum == symnum - 1)
  	    continue;		/* Ignore repeated SOs */
- 
- 	  /* OK, this SO represents a new file.  End the current psymtab */
- 	  
- 	  if (pst)
- 	    {
- 	      END_PSYMTAB (pst, psymtab_include_list, includes_used,
- 			   symnum * symbol_size, valu,
- 			   dependency_list, dependencies_used);
- 	      pst = (struct partial_symtab *) 0;
- 	      includes_used = 0;
- 	      dependencies_used = 0;
- 	    }
- 
  	  last_so_symnum = symnum;
  	  past_first_source_file = 1;
  
  	  if (dir_so_symnum == symnum - 1) /* Was prev. SO a directory? */
  	    tmp = dir_so_symnum;
--- 227,244 ----
  	  p = strrchr (namestring, '/');
  	  if (p && *(p+1) == '\000')
  	    {
  	      dir_so_symnum = symnum;
  	      continue;		/* Simply ignore directory name SOs */
  	    }
  
  	  /* Some other compilers (C++ ones in particular) emit useless
! 	     SOs for non-existant .c files. */
  
  	  if (last_so_symnum == symnum - 1)
  	    continue;		/* Ignore repeated SOs */
  	  last_so_symnum = symnum;
+ 
  	  past_first_source_file = 1;
  
  	  if (dir_so_symnum == symnum - 1) /* Was prev. SO a directory? */
  	    tmp = dir_so_symnum;
***************
*** 433,442 ****
  				   objfile->static_psymbols, CUR_SYMBOL_VALUE);
  	      continue;
  	    default:
  	      /* Skip if the thing following the : is
! 		 not a letter (which indicates declaration of a local
! 		 variable, which we aren't interested in).  */
  	      continue;
  	    }
  
  	case N_FUN:
--- 428,437 ----
  				   objfile->static_psymbols, CUR_SYMBOL_VALUE);
  	      continue;
  	    default:
  	      /* Skip if the thing following the : is
! 	         not a letter (which indicates declaration of a local
! 	         variable, which we aren't interested in).  */
  	      continue;
  	    }
  
  	case N_FUN:
***************
*** 511,519 ****
  				   objfile->static_psymbols, CUR_SYMBOL_VALUE);
  	      continue;
  
  	      /* Global functions were ignored here, but now they
! 		 are put into the global psymtab like one would expect.
  		 They're also in the misc fn vector... 
  		 FIXME, why did it used to ignore these?  That broke
  		 "i fun" on these functions.  */
  	    case 'F':
--- 506,514 ----
  				   objfile->static_psymbols, CUR_SYMBOL_VALUE);
  	      continue;
  
  	      /* Global functions were ignored here, but now they
! 	         are put into the global psymtab like one would expect.
  		 They're also in the misc fn vector... 
  		 FIXME, why did it used to ignore these?  That broke
  		 "i fun" on these functions.  */
  	    case 'F':
===================================================================
Scott Renner
The MITRE Corporation
sar@mitre.org
Technical Details
Message-ID: <1992Aug3.193116.3588@linus.mitre.org>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!mbunix.mitre.org!sar

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gdb.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!mbunix.mitre.org!sar
From: sar@mbunix.mitre.org (Renner)
Subject: patch for GDB 4.6; fixes Sun C++2.1 bug
Message-ID: <1992Aug3.193116.3588@linus.mitre.org>
Sender: gnulists@ai.mit.edu
Organization: The MITRE Corporation, Bedford, MA
Distribution: gnu
Date: Mon, 3 Aug 1992 19:31:16 GMT
Approved: bug-gdb@prep.ai.mit.edu
Lines: 144