[PATCH v2 4/9] gdb: Refactor 'find_symbol_funname' and 'info_frame_command_core' in stack.c.

Christina Schimpe
2026-01-23T08:07:26Z

[-- Attachment #1: Type: text/plain, Size: 2291 bytes --]

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<char>
+find_symbol_funname (const symbol *sym)
+{
+ gdb::unique_xmalloc_ptr<char> 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

[-- Attachment #2.1: Type: text/plain, Size: 329 bytes --]

Intel Deutschland GmbH
Registered Address: Dornacher Straße 1, 85622 Feldkirchen, Germany
Tel: +49 89 991 430, www.intel.de
Managing Directors: Harry Demas, Jeffrey Schneiderman, Yin Chong Sorrell
Chairperson of the Supervisory Board: Nicole Lau
Registered Seat: Munich
Commercial Register: Amtsgericht München HRB 186928

[-- Attachment #2.2: Type: text/html, Size: 357 bytes --]