This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Finding argument lists in demangled names
- To: gcc-patches at gcc dot gnu dot org
- Subject: Finding argument lists in demangled names
- From: Jim Blandy <jimb at zwingli dot cygnus dot com>
- Date: 16 Mar 2001 01:12:50 -0500
This is kind of gross. As always, suggestions for better approaches
are welcome.
libiberty/ChangeLog:
2001-03-15 Jim Blandy <jimb@redhat.com>
* cp-demangle.c (gnu_v3_demangle_function_with_args): New function.
(struct demangling_def): New members, `args_start' and `args_end'.
(demangle_encoding): Clear the starting and ending positions if
what we demangled wasn't a function.
(demangle_bare_function_type): Record the starting and ending
positions of the argument list in the demangled string.
include/ChangeLog:
2001-03-16 Jim Blandy <jimb@redhat.com>
* demangle.h (gnu_v3_demangle_function_with_args): New declaration.
*** libiberty/cp-demangle.c.ctor-dtor~ Thu Mar 15 23:48:58 2001
--- libiberty/cp-demangle.c Fri Mar 16 01:00:22 2001
*************** struct demangling_def
*** 181,186 ****
--- 181,190 ----
indicates what sort of destructor this is; see demangle.h. */
enum gnu_v3_dtor_kinds is_destructor;
+ /* If the symbol being demangled is a function, these give the
+ starting and ending positions of its argument list. Otherwise,
+ these are -1. */
+ int args_start, args_end;
};
typedef struct demangling_def *demangling_t;
*************** demangle_encoding (dm)
*** 1000,1005 ****
--- 1004,1010 ----
int start_position;
template_arg_list_t old_arg_list = current_template_arg_list (dm);
char peek = peek_char (dm);
+ int was_function = 0;
DEMANGLE_TRACE ("encoding", dm);
*************** demangle_encoding (dm)
*** 1019,1024 ****
--- 1024,1031 ----
if (!end_of_name_p (dm)
&& peek_char (dm) != 'E')
{
+ was_function = 1;
+
if (encode_return_type)
/* Template functions have their return type encoded. The
return type should be inserted at start_position. */
*************** demangle_encoding (dm)
*** 1036,1041 ****
--- 1043,1055 ----
mangling of this name, to restore the old template context. */
pop_to_template_arg_list (dm, old_arg_list);
+ /* If the object whose name we just demangled wasn't a function,
+ wipe out any record of an argument list position stored in dm; it
+ may have gotten set in the process of demangling some inner type,
+ but we only care about the top-level object. */
+ if (! was_function)
+ dm->args_start = dm->args_end = -1;
+
return STATUS_OK;
}
*************** demangle_bare_function_type (dm, return_
*** 2688,2695 ****
--- 2702,2714 ----
int sequence =
(return_type_pos == BFT_NO_RETURN_TYPE ? 0 : -1);
+ /* The start and end positions of the argument list in the demangled
+ name. */
+ int args_start = -1, args_end = -1;
+
DEMANGLE_TRACE ("bare-function-type", dm);
+ args_start = result_caret_pos (dm);
RETURN_IF_ERROR (result_add_char (dm, '('));
while (!end_of_name_p (dm) && peek_char (dm) != 'E')
{
*************** demangle_bare_function_type (dm, return_
*** 2714,2720 ****
return_type))
status = STATUS_ALLOCATION_FAILED;
else
! *return_type_pos += dyn_string_length (return_type);
}
dyn_string_delete (return_type);
--- 2733,2743 ----
return_type))
status = STATUS_ALLOCATION_FAILED;
else
! {
! int len = dyn_string_length (return_type);
! *return_type_pos += len;
! args_start += len;
! }
}
dyn_string_delete (return_type);
*************** demangle_bare_function_type (dm, return_
*** 2741,2746 ****
--- 2764,2770 ----
++sequence;
}
RETURN_IF_ERROR (result_add_char (dm, ')'));
+ args_end = result_caret_pos (dm);
/* We should have demangled at least one parameter type (which would
be void, for a function that takes no parameters), plus the
*************** demangle_bare_function_type (dm, return_
*** 2750,2755 ****
--- 2774,2786 ----
else if (sequence == 0)
return "Missing function parameter.";
+ /* Record the start and end position of the argument list. Since we
+ do this last in the function, we overwrite any argument list
+ positions stored by recursive calls, and get the outermost ---
+ which is what we want. */
+ dm->args_start = args_start;
+ dm->args_end = args_end;
+
return STATUS_OK;
}
*************** is_gnu_v3_mangled_dtor (const char *name
*** 3891,3896 ****
--- 3922,3975 ----
enum gnu_v3_dtor_kinds result = dm->is_destructor;
demangling_delete (dm);
return result;
+ }
+ else
+ return 0;
+ }
+
+
+ /* Given SYMBOL, a mangled name for a function, return a malloc'ed
+ copy of its demangled form. Furthermore, set *ARGS_START_P to the
+ index in the returned string of the start of the argument list (the
+ opening parenthesis) and set *ARGS_END_P to the index after the end
+ of the argument list (one character after the closing parenthesis).
+ If SYMBOL isn't a mangled function name, then set *ARGS_START_P and
+ *ARGS_END_P to -1.
+
+ This is helpful for showing function invocations on the stack.
+ For example, a mangled symbol name like:
+
+ _ZNVK22const_vol_method_class3bazERi
+
+ demangles to:
+
+ const_vol_method_class::baz(int&) volatile const
+
+ in the V3 C++ ABI. When we get a backtrace in GDB containing that
+ function, we'd like to see something like:
+
+ const_vol_method_class::baz(ir=@0xbfffe4e4) volatile const
+
+ In other words, we want to see the arguments substituted into the
+ demangled name. This function gives us the information we need
+ to show the demangled name with the argument list appearing at
+ the proper place. */
+ char *
+ gnu_v3_demangle_function_with_args (const char *symbol,
+ int *args_start_p,
+ int *args_end_p)
+ {
+ demangling_t dm = demangle_v3_with_details (symbol);
+
+ if (dm)
+ {
+ dyn_string_t result
+ = dyn_string_new (dyn_string_length (result_string (dm)) + 1);
+ dyn_string_copy (result, result_string (dm));
+ *args_start_p = dm->args_start;
+ *args_end_p = dm->args_end;
+ demangling_delete (dm);
+ return dyn_string_release (result);
}
else
return 0;
*** include/demangle.h.ctor-dtor~ Fri Mar 16 01:07:37 2001
--- include/demangle.h Thu Mar 15 23:05:57 2001
*************** enum gnu_v3_dtor_kinds {
*** 155,158 ****
--- 155,189 ----
extern enum gnu_v3_dtor_kinds is_gnu_v3_mangled_dtor (const char *name);
+ /* Given SYMBOL, a mangled name for a function, return a malloc'ed
+ copy of its demangled form. Furthermore, set *ARGS_START_P to the
+ index in the returned string of the start of the argument list (the
+ opening parenthesis) and set *ARGS_END_P to the index after the end
+ of the argument list (one character after the closing parenthesis).
+ If SYMBOL isn't a mangled function name, then set *ARGS_START_P and
+ *ARGS_END_P to -1.
+
+ This is helpful for showing function invocations on the stack.
+ For example, a mangled symbol name like:
+
+ _ZNVK22const_vol_method_class3bazERi
+
+ demangles to:
+
+ const_vol_method_class::baz(int&) volatile const
+
+ in the V3 C++ ABI. When we get a backtrace in GDB containing that
+ function, we'd like to see something like:
+
+ const_vol_method_class::baz(ir=@0xbfffe4e4) volatile const
+
+ In other words, we want to see the arguments substituted into the
+ demangled name. This function gives us the information we need
+ to show the demangled name with the argument list appearing at
+ the proper place. */
+ extern char *gnu_v3_demangle_function_with_args (const char *symbol,
+ int *args_start_p,
+ int *args_end_p);
+
+
#endif /* DEMANGLE_H */