From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19994 invoked by alias); 5 Aug 2004 20:08:58 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 19987 invoked from network); 5 Aug 2004 20:08:57 -0000 Received: from unknown (HELO mail-out3.apple.com) (17.254.13.22) by sourceware.org with SMTP; 5 Aug 2004 20:08:57 -0000 Received: from mailgate1.apple.com (a17-128-100-225.apple.com [17.128.100.225]) by mail-out3.apple.com (8.12.11/8.12.11) with ESMTP id i75KAEJq010867 for ; Thu, 5 Aug 2004 13:10:14 -0700 (PDT) Received: from relay4.apple.com (relay4.apple.com) by mailgate1.apple.com (Content Technologies SMTPRS 4.3.12) with ESMTP id ; Thu, 5 Aug 2004 13:08:56 -0700 Received: from [17.201.22.21] (moleja.apple.com [17.201.22.21]) by relay4.apple.com (8.12.11/8.12.11) with ESMTP id i75K8ZLe006274; Thu, 5 Aug 2004 13:08:36 -0700 (PDT) Mime-Version: 1.0 (Apple Message framework v670) To: gdb-patches@sources.redhat.com Message-Id: <4F2AF76A-E71B-11D8-B4BD-000A9569836A@apple.com> Content-Type: multipart/mixed; boundary=Apple-Mail-3--387284711 Cc: Jim Blandy , Mark Kettenis , Eli Zaretskii , Devang Patel Subject: RFA/patch stabs reader: Recognize language hint in SO stab From: Jason Molenda Date: Thu, 05 Aug 2004 20:08:00 -0000 X-SW-Source: 2004-08/txt/msg00136.txt.bz2 --Apple-Mail-3--387284711 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed Content-length: 2717 Hi, this follows up to the note I posted to gdb a couple days ago, http://sources.redhat.com/ml/gdb/2004-08/msg00015.html The patch below uses the 'desc' 16-bit field in the SO stab's nlist record to indicate the language of the compilation unit, akin to the DW_AT_language DWARF attribute. The Sun compiler has used it like this for a long time; we even had the language values in include/aout/stab_gnu.h but they were not used. (I added the Fortran90 value from Mark's e-mail, thanks Mark). The stabs reader currently checks the filename suffix of the source file or header files to detect the type of the language. My change will use the value of the desc field, if present, and will only use the filename suffix heuristics if no desc field setting has already been seen. The most potentially controversial part of this patch, I expect, is that I needed to add two language codes for languages in use on MacOS X -- Objective-C and Objective-C++. I don't have a way of communicating these codes back to Sun, and I don't want to have Sun and gcc using the same value for different languages, so I added ObjC/ObjC++ up at value 50 (the Sun languages range from 1 to 7). The number 50 was, obviously, chosen completely at random. Eli, I added a table documenting these values to stabs.texinfo. Do you think this is a correct use of a texinfo table? I am not very experienced with texinfo. Devang Patel will add the compiler support for this once we get agreement on the language code values here on the gdb list. As always, I'm not committed to the particularly names of functions or method of implementing this -- I'll incorporate any feedback speedily and re-post. Thanks! [include/ChangeLog] 004-08-05 Jason Molenda (jmolenda@apple.com) * aout/stab_gnu.h: Update N_SO table with FORTRAN90 addition from Sun's Stabs Interface Manual (Version 4.0). Add Objective-C and Objective-C++ non-Sun language codes. [gdb/ChangeLog] 2004-08-05 Jason Molenda (jmolenda@apple.com) * dbxread.c (read_so_stab_language_hint): New function. (read_dbx_symtab): Prefer language from SO stab's desc field over language based on the suffix of the source filename. (start_psymtab): Only use the source filename suffix if the language hasn't been already set. (process_one_symbol): When expanding psymtab to symtab, use the desc field to set the language if it contains anything meaningful. [gdb/doc/ChangeLog] 2004-08-05 Jason Molenda (jmolenda@apple.com) * stabs.texinfo (Paths and Names of the Source Files): Document the meaning of values in the 'desc' field of a SO stab. --Apple-Mail-3--387284711 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; x-unix-mode=0644; name="pa.txt" Content-Disposition: attachment; filename=pa.txt Content-length: 9090 Index: include/aout/stab_gnu.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/include/aout/stab_gnu.h,v retrieving revision 1.2 diff -u -p -r1.2 stab_gnu.h --- include/aout/stab_gnu.h 14 Mar 2001 02:27:43 -0000 1.2 +++ include/aout/stab_gnu.h 5 Aug 2004 19:57:58 -0000 @@ -40,6 +40,9 @@ LAST_UNUSED_STAB_CODE #define N_SO_CC 4 /* C++ */ #define N_SO_FORTRAN 5 #define N_SO_PASCAL 6 +#define N_SO_FORTRAN90 7 +#define N_SO_OBJC 50 /* Non-Sun language code: Objective-C */ +#define N_SO_OBJCPLUS 51 /* Non-Sun language code: Objective-C++ */ =20 /* Solaris2: Floating point type values in basic types. */ =20 Index: gdb/dbxread.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/dbxread.c,v retrieving revision 1.69 diff -u -p -r1.69 dbxread.c --- gdb/dbxread.c 1 Jul 2004 20:25:53 -0000 1.69 +++ gdb/dbxread.c 5 Aug 2004 19:57:58 -0000 @@ -292,6 +292,8 @@ static struct partial_symtab *start_psym struct partial_symbol **, struct partial_symbol **); =20 +static enum language read_so_stab_language_hint (short unsigned n_desc); + /* Free up old header file tables */ =20 void @@ -1506,7 +1508,11 @@ read_dbx_symtab (struct objfile *objfile =20 /* Null name means end of .o file. Don't start a new one. */ if (*namestring =3D=3D '\000') - continue; + { + /* Reset the current language */ + psymtab_language =3D language_unknown; + continue; + } =20 /* Some compilers (including gcc) emit a pair of initial N_SOs. The first one is a directory name; the second the file name. @@ -1522,6 +1528,9 @@ read_dbx_symtab (struct objfile *objfile continue;=09=09 } =20 + /* Try getting the file's language from SO stab's 'desc' field= */ + psymtab_language =3D read_so_stab_language_hint (nlist.n_desc); + /* Some other compilers (C++ ones in particular) emit useless SOs for non-existant .c files. We ignore all subsequent SOs that immediately follow the first. */ @@ -1547,16 +1556,23 @@ read_dbx_symtab (struct objfile *objfile read_dbx_symtab function returns */ =20 namestring =3D set_namestring (objfile, nlist); - tmp_language =3D deduce_language_from_filename (namestring); =20 - /* Only change the psymtab's language if we've learned - something useful (eg. tmp_language is not language_unknown). - In addition, to match what start_subfile does, never change - from C++ to C. */ - if (tmp_language !=3D language_unknown - && (tmp_language !=3D language_c - || psymtab_language !=3D language_cplus)) - psymtab_language =3D tmp_language; + /* psymtab_language may have already been set by a SO stab + from the compiler. If not, try to guess it from the + source filename extension. */ + if (psymtab_language =3D=3D language_unknown) + { + tmp_language =3D deduce_language_from_filename (namestring); + + /* Only change the psymtab's language if we've learned + something useful (eg. tmp_language is not language_unknown). + In addition, to match what start_subfile does, never change + from C++ to C. */ + if (tmp_language !=3D language_unknown + && (tmp_language !=3D language_c + || psymtab_language !=3D language_cplus)) + psymtab_language =3D tmp_language; + } =20 if (pst =3D=3D NULL) { @@ -1580,16 +1596,23 @@ read_dbx_symtab (struct objfile *objfile /* Mark down an include file in the current psymtab */ =20 namestring =3D set_namestring (objfile, nlist); - tmp_language =3D deduce_language_from_filename (namestring); =20 - /* Only change the psymtab's language if we've learned - something useful (eg. tmp_language is not language_unknown). - In addition, to match what start_subfile does, never change - from C++ to C. */ - if (tmp_language !=3D language_unknown - && (tmp_language !=3D language_c - || psymtab_language !=3D language_cplus)) - psymtab_language =3D tmp_language; + /* psymtab_language may have already been set by a SO stab + from the compiler. If not, try to guess it from the + source filename extension. */ + if (psymtab_language =3D=3D language_unknown) + { + tmp_language =3D deduce_language_from_filename (namestring); + + /* Only change the psymtab's language if we've learned + something useful (eg. tmp_language is not language_unknown). + In addition, to match what start_subfile does, never change + from C++ to C. */ + if (tmp_language !=3D language_unknown + && (tmp_language !=3D language_c + || psymtab_language !=3D language_cplus)) + psymtab_language =3D tmp_language; + } =20 /* In C++, one may expect the same filename to come round many times, when code is coming alternately from the main file @@ -2153,8 +2176,9 @@ start_psymtab (struct objfile *objfile,=20 if successful. */ elfstab_offset_sections (objfile, result); =20 - /* Deduce the source language from the filename for this psymtab. */ - psymtab_language =3D deduce_language_from_filename (filename); + /* As a last resort, use the source filename to determine the language. = */ + if (psymtab_language =3D=3D language_unknown) + psymtab_language =3D deduce_language_from_filename (filename); =20 return result; } @@ -2877,6 +2901,9 @@ process_one_symbol (int type, int desc,=20 if (previous_stab_code =3D=3D (unsigned char) N_SO) { patch_subfile_names (current_subfile, name); + /* Set the language if the SO stab indicates it. */ + if (read_so_stab_language_hint (desc) !=3D language_unknown) + current_subfile->language =3D read_so_stab_language_hint (= desc); break; /* Ignore repeated SOs */ } end_symtab (valu, objfile, SECT_OFF_TEXT (objfile)); @@ -3468,6 +3495,35 @@ stabsect_build_psymtabs (struct objfile=20 dbx_symfile_read (objfile, 0); } =0C +/* The compiler may indicate the source language in the SO stab's "desc"=20 + field. This was originally a Sun extension, but being tres useful, + it's been adopted by gcc as well. */ +static enum language +read_so_stab_language_hint (short unsigned n_desc) +{ + switch (n_desc)=20 + { + case N_SO_AS: + return language_asm; + case N_SO_C: + return language_c; + case N_SO_ANSI_C: + return language_c; + case N_SO_CC: + return language_cplus; + case N_SO_FORTRAN: + return language_fortran; + case N_SO_PASCAL: + return language_pascal; + case N_SO_FORTRAN90: + return language_fortran; + case N_SO_OBJC: + return language_objc; + default: + return language_unknown; + } +} +=0C static struct sym_fns aout_sym_fns =3D { bfd_target_aout_flavour, Index: gdb/doc/stabs.texinfo =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/doc/stabs.texinfo,v retrieving revision 1.15 diff -u -p -r1.15 stabs.texinfo --- gdb/doc/stabs.texinfo 14 Jun 2004 22:26:34 -0000 1.15 +++ gdb/doc/stabs.texinfo 5 Aug 2004 19:57:58 -0000 @@ -422,9 +422,33 @@ file. This information is contained in=20 value of the symbol is the start address of the portion of the text section corresponding to that file. =20 -With the Sun Solaris2 compiler, the desc field contains a -source-language code. -@c Do the debuggers use it? What are the codes? -djm +Some compilers use the desc field to indicate the language of the +source file. Sun's compilers started this usage, and the first +constants are derived from their documentation. Languages added +by gcc/gdb start at 0x32 to avoid conflict with languages Sun may +add in the future. A desc field with a value 0 indicates that no +language has been specified via this mechanism. + +@table @code +@item 0x1 N_SO_AS +Assembly language +@item 0x2 N_SO_C +K&R traditional C +@item 0x3 N_SO_ANSI_C +ANSI C +@item 0x4 N_SO_CC +C++ +@item 0x5 N_SO_FORTRAN +Fortran +@item 0x6 N_SO_PASCAL +Pascal +@item 0x7 N_SO_FORTRAN90 +Fortran90 +@item 0x32 N_SO_OBJC +Objective-C +@item 0x33 N_SO_OBJCPLUS +Objective-C++ +@end table =20 Some compilers (for example, GCC2 and SunOS4 @file{/bin/cc}) also include the directory in which the source was compiled, in a second --Apple-Mail-3--387284711--