1 /* Helper routines for C++ support in GDB.
2 Copyright 2002 Free Software Foundation, Inc.
4 Contributed by MontaVista Software.
6 This file is part of GDB.
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.
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.
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,
21 Boston, MA 02111-1307, USA. */
24 #include "cp-support.h"
25 #include "gdb_string.h"
28 /* Find the last component of the demangled C++ name NAME. NAME
29 must be a method name including arguments, in order to correctly
30 locate the last component.
32 This function return a pointer to the first colon before the
33 last component, or NULL if the name had only one component. */
36 find_last_component (const char *name
)
41 /* Functions can have local classes, so we need to find the
42 beginning of the last argument list, not the end of the first
44 p
= name
+ strlen (name
) - 1;
45 while (p
> name
&& *p
!= ')')
51 /* P now points at the `)' at the end of the argument list. Walk
52 back to the beginning. */
55 while (p
> name
&& depth
> 0)
57 if (*p
== '<' || *p
== '(')
59 else if (*p
== '>' || *p
== ')')
67 while (p
> name
&& *p
!= ':')
70 if (p
== name
|| p
== name
+ 1 || p
[-1] != ':')
76 /* Return the name of the class containing method PHYSNAME. */
79 class_name_from_physname (const char *physname
)
84 char *demangled_name
= cplus_demangle (physname
, DMGL_ANSI
);
86 if (demangled_name
== NULL
)
89 end
= find_last_component (demangled_name
);
92 ret
= xmalloc (end
- demangled_name
+ 1);
93 memcpy (ret
, demangled_name
, end
- demangled_name
);
94 ret
[end
- demangled_name
] = '\0';
97 xfree (demangled_name
);
101 /* Return the name of the method whose linkage name is PHYSNAME. */
104 method_name_from_physname (const char *physname
)
109 char *demangled_name
= cplus_demangle (physname
, DMGL_ANSI
);
111 if (demangled_name
== NULL
)
114 end
= find_last_component (demangled_name
);
123 /* Find the argument list, if any. */
124 args
= strchr (end
, '(');
126 len
= strlen (end
+ 2);
132 len
= args
- end
+ 1;
134 ret
= xmalloc (len
+ 1);
135 memcpy (ret
, end
, len
);
139 xfree (demangled_name
);
This page took 0.033066 seconds and 4 git commands to generate.