[v4,06/13] gdb: Refactor 'find_symbol_funname' and 'info_frame_command_core' in stack.c.

Message ID 20260708143639.2214689-7-christina.schimpe@intel.com
State New
Headers
Series Add new command to print the shadow stack backtrace |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed

Commit Message

Schimpe, Christina July 8, 2026, 2:36 p.m. UTC
  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.

Approved-By: Tom Tromey <tom@tromey.com>
---
 gdb/stack.c | 44 ++++++++++++++++++++++++++++----------------
 1 file changed, 28 insertions(+), 16 deletions(-)
  

Patch

diff --git a/gdb/stack.c b/gdb/stack.c
index 61cd73b8367..f5196c384fd 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -1211,6 +1211,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.  */
@@ -1229,25 +1256,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
     {