• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

修订版be01fded5c79b543d9f28974a625fe4b05162a92 (tree)
时间2004-01-05 07:42:41
作者Daniel Jacobowitz <drow@fals...>
CommiterDaniel Jacobowitz

Log Message

* Makefile.in (cp_names_h): Remove.
(cp_demangle_h): New.
(cp-names.tab.o, cp-names-main.tab.o): Use $(cp_demangle_h) and
remove $(cp_names_h).
(cp-support.o): Use $(cp_demangle_h).
* cp-names.y: Don't include cp-names.h.
(cp_comp_to_string): Export.
(cp_canonicalize_string): Move to cp-support.c.
(demangled_name_to_comp, mangled_name_to_comp): New functions.
* cp-support.c: Include "cp-demangle.h".
(cp_canonicalize_string): New function, moved from cp-names.y and
updated.
(class_name_from_physname, method_name_from_physname): Rewritten.
(find_last_component): Removed.
* cp-support.h: Add new opaque types and prototypes.
* dwarf2read.c: Don't include cp-names.h.
* cp-names.h: Remove file.

更改概述

差异

--- a/gdb/ChangeLog.cplus
+++ b/gdb/ChangeLog.cplus
@@ -1,3 +1,23 @@
1+2003-01-04 Daniel Jacobowitz <drow@mvista.com>
2+
3+ * Makefile.in (cp_names_h): Remove.
4+ (cp_demangle_h): New.
5+ (cp-names.tab.o, cp-names-main.tab.o): Use $(cp_demangle_h) and
6+ remove $(cp_names_h).
7+ (cp-support.o): Use $(cp_demangle_h).
8+ * cp-names.y: Don't include cp-names.h.
9+ (cp_comp_to_string): Export.
10+ (cp_canonicalize_string): Move to cp-support.c.
11+ (demangled_name_to_comp, mangled_name_to_comp): New functions.
12+ * cp-support.c: Include "cp-demangle.h".
13+ (cp_canonicalize_string): New function, moved from cp-names.y and
14+ updated.
15+ (class_name_from_physname, method_name_from_physname): Rewritten.
16+ (find_last_component): Removed.
17+ * cp-support.h: Add new opaque types and prototypes.
18+ * dwarf2read.c: Don't include cp-names.h.
19+ * cp-names.h: Remove file.
20+
121 2004-01-04 Daniel Jacobowitz <drow@mvista.com>
222
323 * Makefile.in (cp-names.tab.o, cp-names-main.tab.o, test-cpnames):
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -579,6 +579,7 @@ coff_sym_h = $(INCLUDE_DIR)/coff/sym.h
579579 coff_symconst_h = $(INCLUDE_DIR)/coff/symconst.h
580580 coff_ecoff_h = $(INCLUDE_DIR)/coff/ecoff.h
581581 coff_internal_h = $(INCLUDE_DIR)/coff/internal.h
582+cp_demangle_h = $(INCLUDE_DIR)/cp-demangle.h
582583 dis_asm_h = $(INCLUDE_DIR)/dis-asm.h $(bfd_h)
583584 elf_reloc_macros_h = $(INCLUDE_DIR)/elf/reloc-macros.h
584585 elf_sh_h = $(INCLUDE_DIR)/elf/sh.h
@@ -654,7 +655,6 @@ command_h = command.h
654655 complaints_h = complaints.h
655656 completer_h = completer.h
656657 cp_abi_h = cp-abi.h
657-cp_names_h = cp-names.h
658658 cp_support_h = cp-support.h $(symtab_h)
659659 dcache_h = dcache.h
660660 defs_h = defs.h $(config_h) $(ansidecl_h) $(gdb_locale_h) $(gdb_signals_h) \
@@ -1439,11 +1439,9 @@ c-exp.tab.c: c-exp.y
14391439 -rm c-exp.tmp
14401440 mv c-exp.new ./c-exp.tab.c
14411441
1442-cp-names.tab.o: cp-names.tab.c $(safe_ctype_h) $(cp_names_h) \
1443- $(srcdir)/../include/cp-demangle.h
1442+cp-names.tab.o: cp-names.tab.c $(safe_ctype_h) $(cp_demangle_h)
14441443
1445-cp-names-main.tab.o: cp-names.tab.c $(safe_ctype_h) $(cp_names_h) \
1446- $(srcdir)/../include/cp-demangle.h
1444+cp-names-main.tab.o: cp-names.tab.c $(safe_ctype_h) $(cp_demangle_h)
14471445 $(CC) -c $(INTERNAL_CFLAGS) -DTEST_CPNAMES \
14481446 -o cp-names-main.tab.o cp-names.tab.c
14491447 test-cpnames: cp-names-main.tab.o $(LIBIBERTY)
@@ -1708,7 +1706,8 @@ cp-namespace.o: cp-namespace.c $(defs_h) $(cp_support_h) $(gdb_obstack_h) \
17081706 $(gdbtypes_h) $(dictionary_h) $(command_h)
17091707 cp-support.o: cp-support.c $(defs_h) $(cp_support_h) $(gdb_string_h) \
17101708 $(demangle_h) $(gdb_assert_h) $(gdbcmd_h) $(dictionary_h) \
1711- $(objfiles_h) $(frame_h) $(symtab_h) $(block_h) $(complaints_h)
1709+ $(objfiles_h) $(frame_h) $(symtab_h) $(block_h) $(complaints_h) \
1710+ $(cp_demangle_h)
17121711 cpu32bug-rom.o: cpu32bug-rom.c $(defs_h) $(gdbcore_h) $(target_h) \
17131712 $(monitor_h) $(serial_h) $(regcache_h) $(m68k_tdep_h)
17141713 cp-valprint.o: cp-valprint.c $(defs_h) $(gdb_obstack_h) $(symtab_h) \
--- a/gdb/cp-names.h
+++ /dev/null
@@ -1,24 +0,0 @@
1-/* YACC parser for C++ names, for GDB.
2-
3- Copyright 2003
4- Free Software Foundation, Inc.
5-
6-This file is part of GDB.
7-
8-This program is free software; you can redistribute it and/or modify
9-it under the terms of the GNU General Public License as published by
10-the Free Software Foundation; either version 2 of the License, or
11-(at your option) any later version.
12-
13-This program is distributed in the hope that it will be useful,
14-but WITHOUT ANY WARRANTY; without even the implied warranty of
15-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16-GNU General Public License for more details.
17-
18-You should have received a copy of the GNU General Public License
19-along with this program; if not, write to the Free Software
20-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21-
22-/* Return the canonicalized form of STRING, or NULL if STRING can not be
23- parsed. */
24-char *cp_canonicalize_string (const char *string);
--- a/gdb/cp-names.y
+++ b/gdb/cp-names.y
@@ -43,8 +43,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
4343 #define IN_GDB
4444 #include "cp-demangle.h"
4545
46-#include "cp-names.h"
47-
4846 static const char *lexptr, *prev_lexptr;
4947
5048 static struct d_comp *d_qualify (struct d_comp *, int, int);
@@ -2005,7 +2003,7 @@ symbol_end (const char *lexptr)
20052003 return p;
20062004 }
20072005
2008-static char *
2006+char *
20092007 cp_comp_to_string (struct d_comp *result, int estimated_len)
20102008 {
20112009 char *str, *prefix = NULL, *buf;
@@ -2036,26 +2034,57 @@ cp_comp_to_string (struct d_comp *result, int estimated_len)
20362034 return (buf);
20372035 }
20382036
2039-/* Return the canonicalized form of STRING, or NULL if STRING can not be
2040- parsed. */
2037+/* Convert a demangled name to a d_comp tree. *DI_P is set to the
2038+ struct d_info that should be freed when finished with the tree. */
20412039
2042-char *
2043-cp_canonicalize_string (const char *string)
2040+struct d_comp *
2041+demangled_name_to_comp (const char *demangled_name, struct d_info **di_p)
20442042 {
2045- int len = strlen (string);
2046- char *ret;
2043+ int len = strlen (demangled_name);
20472044
20482045 len = len + len / 8;
2046+ lexptr = demangled_name;
20492047
2050- lexptr = string;
20512048 di = cp_v3_d_init_info_alloc (NULL, DMGL_PARAMS | DMGL_ANSI, len);
2049+
20522050 if (yyparse () || result == NULL)
2053- return NULL;
2051+ {
2052+ cp_v3_d_free_info (di);
2053+ return NULL;
2054+ }
20542055
2055- ret = cp_comp_to_string (result, len);
2056+ *di_p = di;
2057+ return result;
2058+}
2059+
2060+/* Convert a mangled name to a d_comp tree. *DI_P is set to the
2061+ struct d_info that should be freed when finished with the tree.
2062+ DEMANGLED_P is set to the char * that should be freed when finished
2063+ with the tree. OPTIONS will be passed to the demangler.
2064+
2065+ This could be done much more efficiently for v3 mangled names by exposing
2066+ d_demangle from the demangler. */
2067+
2068+struct d_comp *
2069+mangled_name_to_comp (const char *mangled_name, int options,
2070+ struct d_info **di_p, char **demangled_p)
2071+{
2072+ char *demangled_name = cplus_demangle (mangled_name, options);
2073+ int len;
2074+ struct d_comp *ret;
20562075
2057- cp_v3_d_free_info (di);
2076+ if (demangled_name == NULL)
2077+ return NULL;
2078+
2079+ ret = demangled_name_to_comp (demangled_name, di_p);
2080+
2081+ if (ret == NULL)
2082+ {
2083+ free (demangled_name);
2084+ return NULL;
2085+ }
20582086
2087+ *demangled_p = demangled_name;
20592088 return ret;
20602089 }
20612090
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -1,5 +1,5 @@
11 /* Helper routines for C++ support in GDB.
2- Copyright 2002, 2003 Free Software Foundation, Inc.
2+ Copyright 2002, 2003, 2004 Free Software Foundation, Inc.
33
44 Contributed by MontaVista Software.
55
@@ -35,6 +35,9 @@
3535 #include "complaints.h"
3636 #include "gdbtypes.h"
3737
38+#define IN_GDB
39+#include "cp-demangle.h"
40+
3841 /* Functions related to demangled name parsing. */
3942
4043 static const char *find_last_component (const char *name);
@@ -63,78 +66,31 @@ struct cmd_list_element *maint_cplus_cmd_list = NULL;
6366 static void maint_cplus_command (char *arg, int from_tty);
6467 static void first_component_command (char *arg, int from_tty);
6568
66-/* Here are some random pieces of trivia to keep in mind while trying
67- to take apart demangled names:
68-
69- - Names can contain function arguments or templates, so the process
70- has to be, to some extent recursive: maybe keep track of your
71- depth based on encountering <> and ().
72-
73- - Parentheses don't just have to happen at the end of a name: they
74- can occur even if the name in question isn't a function, because
75- a template argument might be a type that's a function.
76-
77- - Conversely, even if you're trying to deal with a function, its
78- demangled name might not end with ')': it could be a const or
79- volatile class method, in which case it ends with "const" or
80- "volatile".
81-
82- - Parentheses are also used in anonymous namespaces: a variable
83- 'foo' in an anonymous namespace gets demangled as "(anonymous
84- namespace)::foo".
85-
86- - And operator names can contain parentheses or angle brackets. */
87-
88-/* FIXME: carlton/2003-03-13: We have several functions here with
89- overlapping functionality; can we combine them? Also, do they
90- handle all the above considerations correctly? */
91-
92-/* Find the last component of the demangled C++ name NAME. NAME
93- must be a method name including arguments, in order to correctly
94- locate the last component.
69+/* Return the canonicalized form of STRING, or NULL if STRING can not be
70+ parsed. */
9571
96- This function return a pointer to the first colon before the
97- last component, or NULL if the name had only one component. */
72+/* FIXME: Should we also return NULL for things that trivially do not require
73+ any change? i.e. alphanumeric strings. */
9874
99-static const char *
100-find_last_component (const char *name)
75+char *
76+cp_canonicalize_string (const char *string)
10177 {
102- const char *p;
103- int depth;
78+ struct d_info *di;
79+ struct d_comp *ret_comp;
80+ char *ret;
81+ int len = strlen (string);
10482
105- /* Functions can have local classes, so we need to find the
106- beginning of the last argument list, not the end of the first
107- one. */
108- p = name + strlen (name) - 1;
109- while (p > name && *p != ')')
110- p--;
83+ len = len + len / 8;
11184
112- if (p == name)
85+ ret_comp = demangled_name_to_comp (string, &di);
86+ if (ret_comp == NULL)
11387 return NULL;
11488
115- /* P now points at the `)' at the end of the argument list. Walk
116- back to the beginning. */
117- p--;
118- depth = 1;
119- while (p > name && depth > 0)
120- {
121- if (*p == '<' || *p == '(')
122- depth--;
123- else if (*p == '>' || *p == ')')
124- depth++;
125- p--;
126- }
127-
128- if (p == name)
129- return NULL;
89+ ret = cp_comp_to_string (ret_comp, len);
13090
131- while (p > name && *p != ':')
132- p--;
91+ cp_v3_d_free_info (di);
13392
134- if (p == name || p == name + 1 || p[-1] != ':')
135- return NULL;
136-
137- return p - 1;
93+ return ret;
13894 }
13995
14096 /* Return the name of the class containing method PHYSNAME. */
@@ -142,22 +98,63 @@ find_last_component (const char *name)
14298 char *
14399 class_name_from_physname (const char *physname)
144100 {
145- char *ret = NULL;
146- const char *end;
147- int depth = 0;
148- char *demangled_name = cplus_demangle (physname, DMGL_ANSI | DMGL_PARAMS);
101+ struct d_info *di;
102+ char *demangled_name, *ret;
103+ struct d_comp *ret_comp, *prev_comp;
104+ int done;
149105
150- if (demangled_name == NULL)
106+ ret_comp = mangled_name_to_comp (physname, DMGL_ANSI, &di, &demangled_name);
107+ if (ret_comp == NULL)
151108 return NULL;
152109
153- end = find_last_component (demangled_name);
154- if (end != NULL)
110+ done = 0;
111+ prev_comp = NULL;
112+ while (!done)
113+ switch (ret_comp->type)
114+ {
115+ case D_COMP_TYPED_NAME:
116+ prev_comp = NULL;
117+ ret_comp = d_right (ret_comp);
118+ break;
119+ case D_COMP_QUAL_NAME:
120+ case D_COMP_LOCAL_NAME:
121+ prev_comp = ret_comp;
122+ ret_comp = d_right (ret_comp);
123+ break;
124+ case D_COMP_CONST:
125+ case D_COMP_RESTRICT:
126+ case D_COMP_VOLATILE:
127+ case D_COMP_CONST_THIS:
128+ case D_COMP_RESTRICT_THIS:
129+ case D_COMP_VOLATILE_THIS:
130+ case D_COMP_VENDOR_TYPE_QUAL:
131+ prev_comp = NULL;
132+ ret_comp = d_left (ret_comp);
133+ break;
134+ case D_COMP_NAME:
135+ case D_COMP_TEMPLATE:
136+ case D_COMP_CTOR:
137+ case D_COMP_DTOR:
138+ case D_COMP_OPERATOR:
139+ case D_COMP_EXTENDED_OPERATOR:
140+ done = 1;
141+ break;
142+ default:
143+ done = 1;
144+ prev_comp = NULL;
145+ ret_comp = NULL;
146+ break;
147+ }
148+
149+ ret = NULL;
150+ if (prev_comp != NULL)
155151 {
156- ret = xmalloc (end - demangled_name + 1);
157- memcpy (ret, demangled_name, end - demangled_name);
158- ret[end - demangled_name] = '\0';
152+ *prev_comp = *d_left (prev_comp);
153+ /* The ten is completely arbitrary; we don't have a good estimate. */
154+ ret = cp_comp_to_string (prev_comp, 10);
159155 }
160156
157+ cp_v3_d_free_info (di);
161158 xfree (demangled_name);
162159 return ret;
163160 }
@@ -167,43 +164,84 @@ class_name_from_physname (const char *physname)
167164 char *
168165 method_name_from_physname (const char *physname)
169166 {
170- char *ret = NULL;
171- const char *end;
172- int depth = 0;
173- char *demangled_name = cplus_demangle (physname, DMGL_ANSI | DMGL_PARAMS);
167+ struct d_info *di;
168+ char *demangled_name, *ret;
169+ struct d_comp *ret_comp;
170+ int done;
174171
175- if (demangled_name == NULL)
172+ ret_comp = mangled_name_to_comp (physname, DMGL_ANSI, &di, &demangled_name);
173+ if (ret_comp == NULL)
176174 return NULL;
177175
178- end = find_last_component (demangled_name);
179- if (end != NULL)
180- {
181- char *args;
182- int len;
176+ done = 0;
177+ while (!done)
178+ switch (ret_comp->type)
179+ {
180+ case D_COMP_QUAL_NAME:
181+ case D_COMP_LOCAL_NAME:
182+ case D_COMP_TYPED_NAME:
183+ ret_comp = d_right (ret_comp);
184+ break;
185+ case D_COMP_CONST:
186+ case D_COMP_RESTRICT:
187+ case D_COMP_VOLATILE:
188+ case D_COMP_CONST_THIS:
189+ case D_COMP_RESTRICT_THIS:
190+ case D_COMP_VOLATILE_THIS:
191+ case D_COMP_VENDOR_TYPE_QUAL:
192+ ret_comp = d_left (ret_comp);
193+ break;
194+ case D_COMP_NAME:
195+ case D_COMP_TEMPLATE:
196+ case D_COMP_CTOR:
197+ case D_COMP_DTOR:
198+ case D_COMP_OPERATOR:
199+ case D_COMP_EXTENDED_OPERATOR:
200+ done = 1;
201+ break;
202+ default:
203+ done = 1;
204+ ret_comp = NULL;
205+ break;
206+ }
183207
184- /* Skip "::". */
185- end = end + 2;
186-
187- /* Find the argument list, if any. */
188- args = strchr (end, '(');
189- if (args == NULL)
190- len = strlen (end + 2);
191- else
192- {
193- args --;
194- while (*args == ' ')
195- args --;
196- len = args - end + 1;
197- }
198- ret = xmalloc (len + 1);
199- memcpy (ret, end, len);
200- ret[len] = 0;
201- }
208+ ret = NULL;
209+ if (ret_comp != NULL)
210+ /* The ten is completely arbitrary; we don't have a good estimate. */
211+ ret = cp_comp_to_string (ret_comp, 10);
202212
213+ cp_v3_d_free_info (di);
203214 xfree (demangled_name);
204215 return ret;
205216 }
206217
218+/* Here are some random pieces of trivia to keep in mind while trying
219+ to take apart demangled names:
220+
221+ - Names can contain function arguments or templates, so the process
222+ has to be, to some extent recursive: maybe keep track of your
223+ depth based on encountering <> and ().
224+
225+ - Parentheses don't just have to happen at the end of a name: they
226+ can occur even if the name in question isn't a function, because
227+ a template argument might be a type that's a function.
228+
229+ - Conversely, even if you're trying to deal with a function, its
230+ demangled name might not end with ')': it could be a const or
231+ volatile class method, in which case it ends with "const" or
232+ "volatile".
233+
234+ - Parentheses are also used in anonymous namespaces: a variable
235+ 'foo' in an anonymous namespace gets demangled as "(anonymous
236+ namespace)::foo".
237+
238+ - And operator names can contain parentheses or angle brackets. */
239+
240+/* FIXME: carlton/2003-03-13: We have several functions here with
241+ overlapping functionality; can we combine them? Also, do they
242+ handle all the above considerations correctly? */
243+
244+
207245 /* This returns the length of first component of NAME, which should be
208246 the demangled name of a C++ variable/function/method/etc.
209247 Specifically, it returns the index of the first colon forming the
--- a/gdb/cp-support.h
+++ b/gdb/cp-support.h
@@ -1,5 +1,5 @@
11 /* Helper routines for C++ support in GDB.
2- Copyright 2002, 2003 Free Software Foundation, Inc.
2+ Copyright 2002, 2003, 2004 Free Software Foundation, Inc.
33
44 Contributed by MontaVista Software.
55 Namespace support contributed by David Carlton.
@@ -35,6 +35,8 @@ struct obstack;
3535 struct block;
3636 struct objfile;
3737 struct type;
38+struct d_comp;
39+struct d_info;
3840
3941 /* This struct is designed to store data from using directives. It
4042 says that names from namespace INNER should be visible within
@@ -52,6 +54,8 @@ struct using_direct
5254
5355 /* Functions from cp-support.c. */
5456
57+extern char *cp_canonicalize_string (const char *string);
58+
5559 extern char *class_name_from_physname (const char *physname);
5660
5761 extern char *method_name_from_physname (const char *physname);
@@ -108,6 +112,18 @@ extern struct type *cp_lookup_nested_type (struct type *parent_type,
108112 extern void cp_check_possible_namespace_symbols (const char *name,
109113 struct objfile *objfile);
110114
115+/* Functions from cp-names.y. */
116+
117+extern struct d_comp *demangled_name_to_comp (const char *demangled_name,
118+ struct d_info **di_p);
119+
120+extern struct d_comp *mangled_name_to_comp (const char *mangled_name,
121+ int options,
122+ struct d_info **di_p,
123+ char **demangled_p);
124+
125+extern char *cp_comp_to_string (struct d_comp *result, int estimated_len);
126+
111127 /* The list of "maint cplus" commands. */
112128
113129 extern struct cmd_list_element *maint_cplus_cmd_list;
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -1,5 +1,5 @@
11 /* DWARF 2 debugging format support for GDB.
2- Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
2+ Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
33 Free Software Foundation, Inc.
44
55 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
@@ -44,7 +44,6 @@
4444 #include "dwarf2expr.h"
4545 #include "dwarf2loc.h"
4646 #include "cp-support.h"
47-#include "cp-names.h"
4847
4948 #include <fcntl.h>
5049 #include "gdb_string.h"