To avoid code duplication, create a new function 'stack.c:find_symbol_funname', which will be used in 'stack.c:find_frame_funname'. The function will also be used in a following commit. --- gdb/stack.c | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/gdb/stack.c b/gdb/stack.c index ffca1cb0865..805142b2f9b 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -1273,6 +1273,33 @@ get_last_displayed_sal () return sal; } +/* Find the function name for the symbol SYM. */ + +static gdb::unique_xmalloc_ptr +find_symbol_funname (const symbol *sym) +{ + gdb::unique_xmalloc_ptr funname; + const char *print_name = sym->print_name (); + + if (sym->language () == language_cplus) + { + /* It seems appropriate to use print_name () here, + to display the demangled name that we already have + stored in the symbol table, but we stored a version + with DMGL_PARAMS turned on, and here we don't want to + display parameters. So remove the parameters. */ + funname = cp_remove_params (print_name); + } + + if (funname == nullptr) + { + /* If we didn't hit the C++ case above, set *funname here. */ + funname = make_unique_xstrdup (print_name); + } + + return funname; +} + /* Attempt to obtain the name, FUNLANG and optionally FUNCP of the function corresponding to FRAME. */ @@ -1291,25 +1318,10 @@ find_frame_funname (const frame_info_ptr &frame, enum language *funlang, func = get_frame_function (frame); if (func) { - const char *print_name = func->print_name (); - *funlang = func->language (); if (funcp) *funcp = func; - if (*funlang == language_cplus) - { - /* It seems appropriate to use print_name() here, - to display the demangled name that we already have - stored in the symbol table, but we stored a version - with DMGL_PARAMS turned on, and here we don't want to - display parameters. So remove the parameters. */ - funname = cp_remove_params (print_name); - } - - /* If we didn't hit the C++ case above, set *funname - here. */ - if (funname == NULL) - funname = make_unique_xstrdup (print_name); + funname = find_symbol_funname (func); } else { -- 2.34.1