diff options
author | Michael Tiemann <tiemann@cygnus> | 1991-11-18 00:32:34 +0000 |
---|---|---|
committer | Michael Tiemann <tiemann@cygnus> | 1991-11-18 00:32:34 +0000 |
commit | 572acbbedcc289fad1de4ef807c4c47634338a0a (patch) | |
tree | 4de133102f8c71dc1b3517b72db505678cc06cc9 /gdb/cplus-dem.c | |
parent | a89f7423b41371db9e223441e48c3b5bce71e659 (diff) | |
download | gdb-572acbbedcc289fad1de4ef807c4c47634338a0a.zip gdb-572acbbedcc289fad1de4ef807c4c47634338a0a.tar.gz gdb-572acbbedcc289fad1de4ef807c4c47634338a0a.tar.bz2 |
Make changes needed to handle code which uses ANSI-mangled names (and
new G++ 1.95 dbxout output).
Diffstat (limited to 'gdb/cplus-dem.c')
-rw-r--r-- | gdb/cplus-dem.c | 263 |
1 files changed, 196 insertions, 67 deletions
diff --git a/gdb/cplus-dem.c b/gdb/cplus-dem.c index e7f9d86..2398ffb 100644 --- a/gdb/cplus-dem.c +++ b/gdb/cplus-dem.c @@ -2,31 +2,33 @@ Copyright (C) 1989 Free Software Foundation, Inc. written by James Clark (jjc@jclark.uucp) -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* This is for g++ 1.36.1 (November 6 version). It will probably require changes for any other version. Modified for g++ 1.36.2 (November 18 version). - Modified for g++ 1.90.06 (December 31 version). */ + Modified for g++ 1.90.06 (December 31 version). + + Modified for g++ 1.95.03 (November 13 verison). */ /* This file exports one function char *cplus_demangle (const char *name, int mode) - + If NAME is a mangled function name produced by GNU C++, then a pointer to a malloced string giving a C++ representation of the name will be returned; otherwise NULL will be returned. @@ -108,44 +110,81 @@ static int typevec_size = 0; const static struct optable { const char *in; const char *out; + int ansi; } optable[] = { - "nw", " new", /* new (1.92) */ - "dl", " delete", /* new (1.92) */ - "new", " new", /* old (1.91, and 1.x) */ - "delete", " delete", /* old (1.91, and 1.x) */ - "ne", "!=", - "eq", "==", - "ge", ">=", - "gt", ">", - "le", "<=", - "lt", "<", - "plus", "+", - "minus", "-", - "mult", "*", - "convert", "+", /* unary + */ - "negate", "-", /* unary - */ - "trunc_mod", "%", - "trunc_div", "/", - "truth_andif", "&&", - "truth_orif", "||", - "truth_not", "!", - "postincrement", "++", - "postdecrement", "--", - "bit_ior", "|", - "bit_xor", "^", - "bit_and", "&", - "bit_not", "~", - "call", "()", - "cond", "?:", - "alshift", "<<", - "arshift", ">>", - "component", "->", - "indirect", "*", - "method_call", "->()", - "addr", "&", /* unary & */ - "array", "[]", - "compound", ",", - "nop", "", /* for operator= */ + "nw", " new", 1, /* new (1.92, ansi) */ + "dl", " delete", 1, /* new (1.92, ansi) */ + "new", " new", 0, /* old (1.91, and 1.x) */ + "delete", " delete", 0, /* old (1.91, and 1.x) */ + "as", "=", 1, /* ansi */ + "ne", "!=", 1, /* old, ansi */ + "eq", "==", 1, /* old, ansi */ + "ge", ">=", 1, /* old, ansi */ + "gt", ">", 1, /* old, ansi */ + "le", "<=", 1, /* old, ansi */ + "lt", "<", 1, /* old, ansi */ + "plus", "+", 0, /* old */ + "pl", "+", 1, /* ansi */ + "apl", "+=", 1, /* ansi */ + "minus", "-", 0, /* old */ + "mi", "-", 1, /* ansi */ + "ami", "-=", 1, /* ansi */ + "mult", "*", 0, /* old */ + "ml", "*", 1, /* ansi */ + "aml", "*=", 1, /* ansi */ + "convert", "+", 0, /* old (unary +) */ + "negate", "-", 0, /* old (unary -) */ + "trunc_mod", "%", 0, /* old */ + "md", "%", 1, /* ansi */ + "amd", "%=", 1, /* ansi */ + "trunc_div", "/", 0, /* old */ + "dv", "/", 1, /* ansi */ + "adv", "/=", 1, /* ansi */ + "truth_andif", "&&", 0, /* old */ + "aa", "&&", 1, /* ansi */ + "truth_orif", "||", 0, /* old */ + "oo", "||", 1, /* ansi */ + "truth_not", "!", 0, /* old */ + "nt", "!", 1, /* ansi */ + "postincrement", "++", 0, /* old */ + "pp", "++", 1, /* ansi */ + "postdecrement", "--", 0, /* old */ + "mm", "--", 1, /* ansi */ + "bit_ior", "|", 0, /* old */ + "or", "|", 1, /* ansi */ + "aor", "|=", 1, /* ansi */ + "bit_xor", "^", 0, /* old */ + "er", "^", 1, /* ansi */ + "aer", "^=", 1, /* ansi */ + "bit_and", "&", 0, /* old */ + "ad", "&", 1, /* ansi */ + "aad", "&=", 1, /* ansi */ + "bit_not", "~", 0, /* old */ + "co", "~", 1, /* ansi */ + "call", "()", 0, /* old */ + "cl", "()", 1, /* ansi */ + "alshift", "<<", 0, /* old */ + "ls", "<<", 1, /* ansi */ + "als", "<<=", 1, /* ansi */ + "arshift", ">>", 0, /* old */ + "rs", ">>", 1, /* ansi */ + "ars", ">>=", 1, /* ansi */ + "component", "->", 0, /* old */ + "rf", "->", 1, /* ansi */ + "indirect", "*", 0, /* old */ + "method_call", "->()", 0, /* old */ + "addr", "&", 0, /* old (unary &) */ + "array", "[]", 0, /* old */ + "vc", "[]", 1, /* ansi */ + "compound", ",", 0, /* old */ + "cm", ",", 1, /* ansi */ + "cond", "?:", 0, /* old */ + "cn", "?:", 1, /* psuedo-ansi */ + "max", ">?", 0, /* old */ + "mx", ">?", 1, /* psuedo-ansi */ + "min", "<?", 0, /* old */ + "mn", "<?", 1, /* psuedo-ansi */ + "nop", "", 0, /* old (for operator=) */ }; /* Beware: these aren't '\0' terminated. */ @@ -200,16 +239,24 @@ static void remember_type (); #endif /* Takes operator name as e.g. "++" and returns mangled - operator name (e.g. "postincrement_expr"), or NULL if not found. */ + operator name (e.g. "postincrement_expr"), or NULL if not found. + + If ARG_MODE == 1, return the ANSI name; + if ARG_MODE == 0 return the old GNU name. */ char * -cplus_mangle_opname (opname) +cplus_mangle_opname (opname, arg_mode) char *opname; + int arg_mode; { int i, len = strlen (opname); + if (arg_mode != 0 && arg_mode != 1) + error ("invalid arg_mode"); + for (i = 0; i < sizeof (optable)/sizeof (optable[0]); i++) { if (strlen (optable[i].out) == len + && arg_mode == optable[i].ansi && memcmp (optable[i].out, opname, len) == 0) return (char *)optable[i].in; } @@ -251,19 +298,30 @@ cplus_demangle (type, arg_mode) /* destructor */ if (type[0] == '_' && type[1] == CPLUS_MARKER && type[2] == '_') { - destructor = 1; - p = type; + int n = (strlen (type) - 3)*2 + 3 + 2 + 1; + char *tem = (char *) xmalloc (n); + strcpy (tem, type + 3); + strcat (tem, "::~"); + strcat (tem, type + 3); + if (print_arg_types) + strcat (tem, "()"); + return tem; } /* static data member */ - if (*type != '_' && (strchr (type, CPLUS_MARKER) != NULL)) + if (*type != '_' && (p = strchr (type, CPLUS_MARKER)) != NULL) { - static_type = 1; - p = type; + int n = strlen (type) + 2; + char *tem = (char *) xmalloc (n); + memcpy (tem, type, p - type); + strcpy (tem + (p - type), "::"); + strcpy (tem + (p - type) + 2, p + 1); + return tem; } - /* virtual table "_vt$" */ + /* virtual table "_vt$" */ if (type[0] == '_' && type[1] == 'v' && type[2] == 't' && type[3] == CPLUS_MARKER) { - char *tem = (char *) xmalloc (strlen (type + 4) + 14 + 1); + int n = strlen (type + 4) + 14 + 1; + char *tem = (char *) xmalloc (n); strcpy (tem, type + 4); strcat (tem, " virtual table"); return tem; @@ -283,17 +341,32 @@ cplus_demangle (type, arg_mode) } else if (p == type) { - if (!isdigit (p[2])) + if (!isdigit (p[2]) && ('t' != p[2])) { - string_delete (&decl); - return NULL; + p += 1; + while (*p != '\0' && !(*p == '_' && p[1] == '_')) + p++; + string_appendn (&decl, type, p - type); + *(decl.p) = '\0'; + munge_function_name (&decl, 1); + if (decl.b[0] == '_') + { + string_delete (&decl); + return NULL; + } + else + p += 2; + } + else + { + constructor = 1; + p += 2; } - constructor = 1; - p += 2; } else { string_appendn (&decl, type, p - type); + *(decl.p) = '\0'; munge_function_name (&decl, arg_mode); p += 2; } @@ -1048,7 +1121,10 @@ munge_function_name (name, arg_mode) string *name; int arg_mode; { - if (!string_empty (name) && name->p - name->b >= 3 + if (string_empty (name)) + return; + + if (name->p - name->b >= 3 && name->b[0] == 'o' && name->b[1] == 'p' && name->b[2] == CPLUS_MARKER) { int i; @@ -1087,8 +1163,7 @@ munge_function_name (name, arg_mode) } return; } - else if (!string_empty (name) && name->p - name->b >= 5 - && memcmp (name->b, "type$", 5) == 0) + else if (name->p - name->b >= 5 && memcmp (name->b, "type$", 5) == 0) { /* type conversion operator */ string type; @@ -1102,6 +1177,60 @@ munge_function_name (name, arg_mode) return; } } + /* ANSI. */ + else if (name->b[2] == 'o' && name->b[3] == 'p') + { + /* type conversion operator. */ + string type; + const char *tem = name->b + 4; + if (do_type (&tem, &type)) + { + string_clear (name); + string_append (name, "operator "); + string_appends (name, &type); + string_delete (&type); + return; + } + } + else if (name->b[0] == '_' && name->b[1] == '_' + && name->b[2] >= 'a' && name->b[2] <= 'z' + && name->b[3] >= 'a' && name->b[3] <= 'z') + { + int i; + + if (name->b[4] == '\0') + { + /* Operator. */ + for (i = 0; i < sizeof (optable)/sizeof (optable[0]); i++) + { + if (strlen (optable[i].in) == 2 + && memcmp (optable[i].in, name->b + 2, 2) == 0) + { + string_clear (name); + string_append (name, "operator"); + string_append (name, optable[i].out); + return; + } + } + } + else + { + if (name->b[2] != 'a' || name->b[5] != '\0') + return; + /* Assignment. */ + for (i = 0; i < sizeof (optable)/sizeof (optable[0]); i++) + { + if (strlen (optable[i].in) == 3 + && memcmp (optable[i].in, name->b + 2, 3) == 0) + { + string_clear (name); + string_append (name, "operator"); + string_append (name, optable[i].out); + return; + } + } + } + } } /* a mini string-handling package */ |