From: Fred Fish Date: Fri, 16 Feb 1996 06:14:15 +0000 (+0000) Subject: * demangle.c (is_cplus_marker): New function, checks if a X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=81afee37d0a016cd3e671693c165916893ac3e60;p=binutils-gdb.git * demangle.c (is_cplus_marker): New function, checks if a character is one of the commonly used C++ marker characters. * defs.h (is_cplus_marker): Add prototype. * c-typeprint.c (c_type_print_base), ch-lang.c (chill_demangle), cp-valprint.c (cp_print_class_method), mdebugread.c (parse_symbol), stabsread.c (define_symbol, read_member_functions, read_struct_fields), symtab.h (OPNAME_PREFIX_P, VTBL_PREFIX_P, DESTRUCTOR_PREFIX_P), values.c (vb_match): Use is_cplus_marker instead of comparison with CPLUS_MARKER. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9433d4de096..37fd73a093c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,15 @@ +Thu Feb 15 21:40:52 1996 Peter Schauer (pes@regent.e-technik.tu-muenchen.de) + + * demangle.c (is_cplus_marker): New function, checks if a + character is one of the commonly used C++ marker characters. + * defs.h (is_cplus_marker): Add prototype. + * c-typeprint.c (c_type_print_base), ch-lang.c (chill_demangle), + cp-valprint.c (cp_print_class_method), mdebugread.c (parse_symbol), + stabsread.c (define_symbol, read_member_functions, read_struct_fields), + symtab.h (OPNAME_PREFIX_P, VTBL_PREFIX_P, DESTRUCTOR_PREFIX_P), + values.c (vb_match): Use is_cplus_marker instead of comparison + with CPLUS_MARKER. + Thu Feb 15 18:08:13 1996 Fred Fish * symfile.h (INLINE_ADD_PSYMBOL): Default this to 0 and possibly diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c index 9be2d52c8ad..a7a5341c177 100644 --- a/gdb/c-typeprint.c +++ b/gdb/c-typeprint.c @@ -1,5 +1,5 @@ /* Support for printing C and C++ types for GDB, the GNU debugger. - Copyright 1986, 1988, 1989, 1991, 1993, 1994 + Copyright 1986, 1988, 1989, 1991, 1993, 1994, 1995, 1996 Free Software Foundation, Inc. This file is part of GDB. @@ -582,8 +582,8 @@ c_type_print_base (type, stream, show, level) { QUIT; /* Don't print out virtual function table. */ - if ((TYPE_FIELD_NAME (type, i))[5] == CPLUS_MARKER && - !strncmp (TYPE_FIELD_NAME (type, i), "_vptr", 5)) + if (STREQN (TYPE_FIELD_NAME (type, i), "_vptr", 5) + && is_cplus_marker ((TYPE_FIELD_NAME (type, i))[5])) continue; /* If this is a C++ class we can print the various C++ section @@ -737,7 +737,7 @@ c_type_print_base (type, stream, show, level) free (mangled_name); } else if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_' - && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == CPLUS_MARKER) + && is_cplus_marker (TYPE_FN_FIELD_PHYSNAME (f, j)[1])) cp_type_print_method_args (TYPE_FN_FIELD_ARGS (f, j) + 1, "~", method_name, 0, stream); else diff --git a/gdb/ch-lang.c b/gdb/ch-lang.c index 9988a3c07a2..904dc6b71f4 100644 --- a/gdb/ch-lang.c +++ b/gdb/ch-lang.c @@ -1,5 +1,5 @@ /* Chill language support routines for GDB, the GNU debugger. - Copyright 1992 Free Software Foundation, Inc. + Copyright 1992, 1995, 1996 Free Software Foundation, Inc. This file is part of GDB. @@ -35,11 +35,20 @@ char * chill_demangle (mangled) const char *mangled; { - char *joiner; + const char *joiner = NULL; char *demangled; + const char *cp = mangled; - joiner = strchr (mangled, CPLUS_MARKER); - if (joiner != NULL && *(joiner + 1) == CPLUS_MARKER) + while (*cp) + { + if (is_cplus_marker (*cp)) + { + joiner = cp; + break; + } + cp++; + } + if (joiner != NULL && *(joiner + 1) == *joiner) { demangled = savestring (mangled, joiner - mangled); } diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c index f68b7530138..7046007ea26 100644 --- a/gdb/cp-valprint.c +++ b/gdb/cp-valprint.c @@ -1,5 +1,5 @@ /* Support for printing C++ values for GDB, the GNU debugger. - Copyright 1986, 1988, 1989, 1991, 1994, 1995 + Copyright 1986, 1988, 1989, 1991, 1994, 1995, 1996 Free Software Foundation, Inc. This file is part of GDB. @@ -124,7 +124,7 @@ cp_print_class_method (valaddr, type, stream) c_type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (f, j), stream, 0, 0); fprintf_unfiltered (stream, kind); if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_' - && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == CPLUS_MARKER) + && is_cplus_marker (TYPE_FN_FIELD_PHYSNAME (f, j)[1])) { cp_type_print_method_args (TYPE_FN_FIELD_ARGS (f, j) + 1, "~", TYPE_FN_FIELDLIST_NAME (domain, i), diff --git a/gdb/defs.h b/gdb/defs.h index af94db80b67..47de9f23ef2 100644 --- a/gdb/defs.h +++ b/gdb/defs.h @@ -1,5 +1,5 @@ /* Basic, host-specific, and target-specific definitions for GDB. - Copyright (C) 1986, 1989, 1991, 1992, 1993, 1994, 1995 + Copyright (C) 1986, 1989, 1991, 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc. This file is part of GDB. @@ -22,6 +22,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #define DEFS_H #include +#include /* System call error return status */ + +/* Just in case they're not defined in stdio.h. */ + +#ifndef SEEK_SET +#define SEEK_SET 0 +#endif +#ifndef SEEK_CUR +#define SEEK_CUR 1 +#endif /* First include ansidecl.h so we can use the various macro definitions here and in all subsequent file inclusions. */ @@ -70,7 +80,8 @@ typedef bfd_vma CORE_ADDR; the program's identifiers (such as $this and $$vptr). */ #define CPLUS_MARKER '$' /* May be overridden to '.' for SysV */ -#include /* System call error return status */ +/* Check if a character is one of the commonly used C++ marker characters. */ +extern int is_cplus_marker PARAMS ((int)); extern int quit_flag; extern int immediate_quit; @@ -263,38 +274,38 @@ extern int fputc_unfiltered PARAMS ((int c, GDB_FILE *)); extern int putchar_unfiltered PARAMS ((int c)); -extern void puts_filtered PARAMS ((char *)); +extern void puts_filtered PARAMS ((const char *)); -extern void puts_unfiltered PARAMS ((char *)); +extern void puts_unfiltered PARAMS ((const char *)); -extern void vprintf_filtered PARAMS ((char *, va_list)) +extern void vprintf_filtered PARAMS ((const char *, va_list)) ATTR_FORMAT(printf, 1, 0); -extern void vfprintf_filtered PARAMS ((FILE *, char *, va_list)) +extern void vfprintf_filtered PARAMS ((FILE *, const char *, va_list)) ATTR_FORMAT(printf, 2, 0); -extern void fprintf_filtered PARAMS ((FILE *, char *, ...)) +extern void fprintf_filtered PARAMS ((FILE *, const char *, ...)) ATTR_FORMAT(printf, 2, 3); -extern void fprintfi_filtered PARAMS ((int, FILE *, char *, ...)) +extern void fprintfi_filtered PARAMS ((int, FILE *, const char *, ...)) ATTR_FORMAT(printf, 3, 4); -extern void printf_filtered PARAMS ((char *, ...)) +extern void printf_filtered PARAMS ((const char *, ...)) ATTR_FORMAT(printf, 1, 2); -extern void printfi_filtered PARAMS ((int, char *, ...)) +extern void printfi_filtered PARAMS ((int, const char *, ...)) ATTR_FORMAT(printf, 2, 3); -extern void vprintf_unfiltered PARAMS ((char *, va_list)) +extern void vprintf_unfiltered PARAMS ((const char *, va_list)) ATTR_FORMAT(printf, 1, 0); -extern void vfprintf_unfiltered PARAMS ((FILE *, char *, va_list)) +extern void vfprintf_unfiltered PARAMS ((FILE *, const char *, va_list)) ATTR_FORMAT(printf, 2, 0); -extern void fprintf_unfiltered PARAMS ((FILE *, char *, ...)) +extern void fprintf_unfiltered PARAMS ((FILE *, const char *, ...)) ATTR_FORMAT(printf, 2, 3); -extern void printf_unfiltered PARAMS ((char *, ...)) +extern void printf_unfiltered PARAMS ((const char *, ...)) ATTR_FORMAT(printf, 1, 2); extern void print_spaces PARAMS ((int, GDB_FILE *)); @@ -648,7 +659,7 @@ extern void free (); #endif /* MALLOC_INCOMPATIBLE */ -#ifndef WIN32 +#ifndef __WIN32__ #ifndef strchr extern char *strchr (); @@ -670,7 +681,7 @@ extern char *strtok (); extern char *strerror (); #endif -#endif /* !WIN32 */ +#endif /* !__WIN32__ */ /* Various possibilities for alloca. */ #ifndef alloca @@ -909,7 +920,7 @@ extern int use_windows; #endif #ifndef SLASH_P -#if defined(__GO32__)||defined(WIN32) +#if defined(__GO32__)||defined(__WIN32__) #define SLASH_P(X) ((X)=='\\') #else #define SLASH_P(X) ((X)=='/') @@ -917,7 +928,7 @@ extern int use_windows; #endif #ifndef SLASH_CHAR -#if defined(__GO32__)||defined(WIN32) +#if defined(__GO32__)||defined(__WIN32__) #define SLASH_CHAR '\\' #else #define SLASH_CHAR '/' @@ -925,7 +936,7 @@ extern int use_windows; #endif #ifndef SLASH_STRING -#if defined(__GO32__)||defined(WIN32) +#if defined(__GO32__)||defined(__WIN32__) #define SLASH_STRING "\\" #else #define SLASH_STRING "/" diff --git a/gdb/demangle.c b/gdb/demangle.c index 4abc84c86ac..bb3f0922485 100644 --- a/gdb/demangle.c +++ b/gdb/demangle.c @@ -1,5 +1,5 @@ /* Basic C++ demangling support for GDB. - Copyright 1991, 1992 Free Software Foundation, Inc. + Copyright 1991, 1992, 1996 Free Software Foundation, Inc. Written by Fred Fish at Cygnus Support. This file is part of GDB. @@ -162,6 +162,31 @@ set_demangling_style (style) set_demangling_command ((char *) NULL, 0); } +/* In order to allow a single demangler executable to demangle strings + using various common values of CPLUS_MARKER, as well as any specific + one set at compile time, we maintain a string containing all the + commonly used ones, and check to see if the marker we are looking for + is in that string. CPLUS_MARKER is usually '$' on systems where the + assembler can deal with that. Where the assembler can't, it's usually + '.' (but on many systems '.' is used for other things). We put the + current defined CPLUS_MARKER first (which defaults to '$'), followed + by the next most common value, followed by an explicit '$' in case + the value of CPLUS_MARKER is not '$'. + + We could avoid this if we could just get g++ to tell us what the actual + cplus marker character is as part of the debug information, perhaps by + ensuring that it is the character that terminates the gcc_compiled + marker symbol (FIXME). */ + +static char cplus_markers[] = { CPLUS_MARKER, '.', '$', '\0' }; + +int +is_cplus_marker (c) + int c; +{ + return c && strchr (cplus_markers, c) != NULL; +} + void _initialize_demangler () { diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c index 07dca2b3b00..96c59f85971 100644 --- a/gdb/mdebugread.c +++ b/gdb/mdebugread.c @@ -785,7 +785,7 @@ parse_symbol (sh, ax, ext_sh, bigend, section_offsets) top_stack->numargs++; /* Special GNU C++ name. */ - if (name[0] == CPLUS_MARKER && name[1] == 't' && name[2] == 0) + if (is_cplus_marker (name[0]) && name[1] == 't' && name[2] == 0) name = "this"; /* FIXME, not alloc'd in obstack */ s = new_symbol (name); diff --git a/gdb/stabsread.c b/gdb/stabsread.c index 4ea4ba34ebd..dd0373b198f 100644 --- a/gdb/stabsread.c +++ b/gdb/stabsread.c @@ -1,5 +1,5 @@ /* Support routines for decoding "stabs" debugging information format. - Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995 + Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc. This file is part of GDB. @@ -565,7 +565,7 @@ define_symbol (valu, string, desc, type, objfile) SYMBOL_LINE(sym) = 0; /* unknown */ } - if (string[0] == CPLUS_MARKER) + if (is_cplus_marker (string[0])) { /* Special GNU C++ names. */ switch (string[1]) @@ -2000,7 +2000,7 @@ read_member_functions (fip, pp, type, objfile) make_cleanup (free, new_fnlist); memset (new_fnlist, 0, sizeof (struct next_fnfieldlist)); - if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && (*pp)[2] == CPLUS_MARKER) + if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && is_cplus_marker ((*pp)[2])) { /* This is a completely wierd case. In order to stuff in the names that might contain colons (the usual name delimiter), @@ -2535,12 +2535,9 @@ read_struct_fields (fip, pp, type, objfile) /* If is starts with CPLUS_MARKER it is a special abbreviation, unless the CPLUS_MARKER is followed by an underscore, in which case it is just the name of an anonymous type, which we - should handle like any other type name. We accept either '$' - or '.', because a field name can never contain one of these - characters except as a CPLUS_MARKER (we probably should be - doing that in most parts of GDB). */ + should handle like any other type name. */ - if ((*p == '$' || *p == '.') && p[1] != '_') + if (is_cplus_marker (p[0]) && p[1] != '_') { if (!read_cpp_abbrev (fip, pp, type, objfile)) return 0; diff --git a/gdb/symtab.h b/gdb/symtab.h index 0a20db51dd6..49b0c1aa86e 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -931,7 +931,7 @@ struct partial_symtab Note that this macro is g++ specific (FIXME). */ #define OPNAME_PREFIX_P(NAME) \ - ((NAME)[0] == 'o' && (NAME)[1] == 'p' && (NAME)[2] == CPLUS_MARKER) + ((NAME)[0] == 'o' && (NAME)[1] == 'p' && is_cplus_marker ((NAME)[2])) /* Macro that yields non-zero value iff NAME is the prefix for C++ vtbl names. Note that this macro is g++ specific (FIXME). @@ -939,15 +939,16 @@ struct partial_symtab style, using thunks (where '$' is really CPLUS_MARKER). */ #define VTBL_PREFIX_P(NAME) \ - ((NAME)[3] == CPLUS_MARKER && (NAME)[0] == '_' \ + ((NAME)[0] == '_' \ && (((NAME)[1] == 'V' && (NAME)[2] == 'T') \ - || ((NAME)[1] == 'v' && (NAME)[2] == 't'))) + || ((NAME)[1] == 'v' && (NAME)[2] == 't')) \ + && is_cplus_marker ((NAME)[3])) /* Macro that yields non-zero value iff NAME is the prefix for C++ destructor names. Note that this macro is g++ specific (FIXME). */ #define DESTRUCTOR_PREFIX_P(NAME) \ - ((NAME)[0] == '_' && (NAME)[1] == CPLUS_MARKER && (NAME)[2] == '_') + ((NAME)[0] == '_' && is_cplus_marker ((NAME)[1]) && (NAME)[2] == '_') /* External variables and functions for the objects described above. */ @@ -964,6 +965,10 @@ extern int current_source_line; extern struct objfile *current_objfile; +/* True if we are nested inside psymtab_to_symtab. */ + +extern int currently_reading_symtab; + /* From utils.c. */ extern int demangle; extern int asm_demangle; diff --git a/gdb/values.c b/gdb/values.c index f95c831601d..991d374a84d 100644 --- a/gdb/values.c +++ b/gdb/values.c @@ -1,5 +1,5 @@ /* Low level packing and unpacking of values for GDB, the GNU Debugger. - Copyright 1986, 1987, 1989, 1991, 1993, 1994, 1995 + Copyright 1986, 1987, 1989, 1991, 1993, 1994, 1995, 1996 Free Software Foundation, Inc. This file is part of GDB. @@ -1039,7 +1039,7 @@ vb_match (type, index, basetype) if (*name != '_') return 0; /* gcc 2.4 uses _vb$. */ - if (name[1] == 'v' && name[2] == 'b' && name[3] == CPLUS_MARKER) + if (name[1] == 'v' && name[2] == 'b' && is_cplus_marker (name[3])) field_class_name = name + 4; /* gcc 2.5 will use __vb_. */ if (name[1] == '_' && name[2] == 'v' && name[3] == 'b' && name[4] == '_')