This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Add set/show display-linkname command


On 03/21/2013 01:55 PM, Michael Eager wrote:
On 03/21/2013 12:49 PM, Eli Zaretskii wrote:
Date: Thu, 21 Mar 2013 12:04:34 -0700
From: Michael Eager <eager@eagerm.com>

Updated patch which fixes garbled output.

Thanks.  This needs a suitable patch for the manual, to document this
new command, and also for NEWS.

Will do.

+  add_setshow_boolean_cmd ("display-linkname", class_support, &disp_linkname, _("\
+Set whether to display linkage name for functions."), _("\
+Show whether to display linkage name for functions."), NULL,
+               NULL,
+                show_disp_linkname,
+               &setlist, &showlist);

If this setting controls display of linkage name, why is the command
called "display-linkname" and not "display-linkage-name"?

Just saving keystrokes.   I can change this.

Also, I think we need to explain what is a "linkage name" in the doc
string, because otherwise this doc string is 100% unhelpful, as it
says nothing at all about its purpose.

I'll update the patch with a more descriptive description.

Updated patch attached.

Changelog
gdb:
    * 2013-03-27  Michael Eager <eager@eagercon.com>

    * NEWS (set|show display-linkage-name): Announcement.
    * ada-lang.c (is_known_support_routine): Add linkname, modify
    find_frame_funname() call.
    (ada_unhandled_exception_name_addr_from_raise): Likewise.
    * defs.h (build_address_symbolic): Add linkname arg.
    * disasm.c (dump_insns): Add linkname, modify build_address_symbolic() call.
    * printcmd.c (MAX_LINKNAME_LEN): Define.
    (print_address_symbolic): Add linkname, modify build_address_symbolic() call.
    (print_address_symbolic): Print linkname if requested.
    (build_address_symbolic): Add linkname argument, return linkage name
    if different from symbol name.
    * python/py-frame.c (frapy_is_valid): Add linkname, modify find_frame_funname()
    call.
    * stack.c (MAX_LINKNAME_LEN): Define.
    (find_frame_funname): Add linkname argument, return linkage name if
    different from symbol name.
    (print_frame): Add linkname, modify find_frame_funname() call, print
    linkname if requested.
    * stack.h(find_frame_funname): Add linkname.
    * top.c (disp_linkname): Define.
    (show_disp_linkname): Display show linkage name status.
    (init_main): Add "set/show display-linkname" command.
    * top.h (disp_linkname): Declare.

doc:
    * gdb.texinfo (set|show display-linkage-name): Document.


--
Michael Eager	 eager@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306  650-325-8077
Index: gdb/NEWS
===================================================================
RCS file: /cvs/src/src/gdb/NEWS,v
retrieving revision 1.576
diff -u -p -u -r1.576 NEWS
--- gdb/NEWS	21 Mar 2013 17:37:29 -0000	1.576
+++ gdb/NEWS	27 Mar 2013 19:36:23 -0000
@@ -10,6 +10,15 @@ maint set|show per-command time
 maint set|show per-command symtab
   Enable display of per-command gdb resource usage.
 
+* New commands have been added to select whether to display the 
+  linker symbol name for functions in addition to the name used in the
+  source.  This may be useful when debugging programs where the compiler
+  prepends characters to the source symbol, such as a leading underscore:
+
+set|show display-linkage-name [off|on]
+
+  The default is "off", to not display the linkage name.  
+
 * The command 'tsave' can now support new option '-ctf' to save trace
   buffer in Common Trace Format.
 
Index: gdb/ada-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.397
diff -u -p -u -r1.397 ada-lang.c
--- gdb/ada-lang.c	13 Mar 2013 18:34:53 -0000	1.397
+++ gdb/ada-lang.c	27 Mar 2013 19:36:23 -0000
@@ -11107,6 +11107,7 @@ is_known_support_routine (struct frame_i
 {
   struct symtab_and_line sal;
   const char *func_name;
+  const char *linkname;
   enum language func_lang;
   int i;
   const char *fullname;
@@ -11145,7 +11146,7 @@ is_known_support_routine (struct frame_i
 
   /* Check whether the function is a GNAT-generated entity.  */
 
-  find_frame_funname (frame, &func_name, &func_lang, NULL);
+  find_frame_funname (frame, &func_name, &linkname, &func_lang, NULL);
   if (func_name == NULL)
     return 1;
 
@@ -11212,9 +11213,10 @@ ada_unhandled_exception_name_addr_from_r
   while (fi != NULL)
     {
       const char *func_name;
+      const char *linkname;
       enum language func_lang;
 
-      find_frame_funname (fi, &func_name, &func_lang, NULL);
+      find_frame_funname (fi, &func_name, &linkname, &func_lang, NULL);
       if (func_name != NULL
           && strcmp (func_name, data->exception_info->catch_exception_sym) == 0)
         break; /* We found the frame we were looking for...  */
Index: gdb/defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.329
diff -u -p -u -r1.329 defs.h
--- gdb/defs.h	4 Feb 2013 12:57:44 -0000	1.329
+++ gdb/defs.h	27 Mar 2013 19:36:23 -0000
@@ -335,6 +335,7 @@ extern int build_address_symbolic (struc
 				   CORE_ADDR addr,
 				   int do_demangle, 
 				   char **name, 
+				   char **linkname, 
 				   int *offset, 
 				   char **filename, 
 				   int *line, 	
Index: gdb/disasm.c
===================================================================
RCS file: /cvs/src/src/gdb/disasm.c,v
retrieving revision 1.51
diff -u -p -u -r1.51 disasm.c
--- gdb/disasm.c	11 Mar 2013 08:53:17 -0000	1.51
+++ gdb/disasm.c	27 Mar 2013 19:36:23 -0000
@@ -112,6 +112,7 @@ dump_insns (struct gdbarch *gdbarch, str
     {
       char *filename = NULL;
       char *name = NULL;
+      char *linkname = NULL;
 
       QUIT;
       if (how_many >= 0)
@@ -127,8 +128,8 @@ dump_insns (struct gdbarch *gdbarch, str
 	ui_out_text (uiout, pc_prefix (pc));
       ui_out_field_core_addr (uiout, "address", gdbarch, pc);
 
-      if (!build_address_symbolic (gdbarch, pc, 0, &name, &offset, &filename,
-				   &line, &unmapped))
+      if (!build_address_symbolic (gdbarch, pc, 0, &name, &linkname, &offset, 
+				   &filename, &line, &unmapped))
 	{
 	  /* We don't care now about line, filename and
 	     unmapped. But we might in the future.  */
Index: gdb/printcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/printcmd.c,v
retrieving revision 1.226
diff -u -p -u -r1.226 printcmd.c
--- gdb/printcmd.c	20 Mar 2013 18:35:22 -0000	1.226
+++ gdb/printcmd.c	27 Mar 2013 19:36:23 -0000
@@ -51,11 +51,15 @@
 #include "cli/cli-utils.h"
 #include "format.h"
 #include "source.h"
+#include "top.h"
 
 #ifdef TUI
 #include "tui/tui.h"		/* For tui_active et al.   */
 #endif
 
+/* Maximum length of linkname to print.  */
+#define MAX_LINKNAME_LEN 20
+
 struct format_data
   {
     int count;
@@ -569,17 +573,18 @@ print_address_symbolic (struct gdbarch *
 			int do_demangle, char *leadin)
 {
   char *name = NULL;
+  char *linkname = NULL;
   char *filename = NULL;
   int unmapped = 0;
   int offset = 0;
   int line = 0;
 
-  /* Throw away both name and filename.  */
+  /* Throw away both name, linkname, and filename.  */
   struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name);
   make_cleanup (free_current_contents, &filename);
 
-  if (build_address_symbolic (gdbarch, addr, do_demangle, &name, &offset,
-			      &filename, &line, &unmapped))
+  if (build_address_symbolic (gdbarch, addr, do_demangle, &name, &linkname,
+			      &offset, &filename, &line, &unmapped))
     {
       do_cleanups (cleanup_chain);
       return 0;
@@ -591,6 +596,24 @@ print_address_symbolic (struct gdbarch *
   else
     fputs_filtered ("<", stream);
   fputs_filtered (name, stream);
+
+  /* Print linkage name after source name if requested and different.  */
+  if (disp_linkname && linkname && strcmp (name, linkname))
+    {
+      char *lname = linkname;
+
+      if (strlen (lname) > MAX_LINKNAME_LEN) 
+        {
+          lname = alloca (MAX_LINKNAME_LEN + 4);
+	  strncpy (lname, linkname, MAX_LINKNAME_LEN);
+	  lname[MAX_LINKNAME_LEN] = '\0';
+	  strcat (lname, "...");
+ 	}
+      fputs_filtered (" [", stream);
+      fputs_filtered (lname, stream);
+      fputs_filtered ("]", stream);
+    }
+
   if (offset != 0)
     fprintf_filtered (stream, "+%u", (unsigned int) offset);
 
@@ -623,6 +646,7 @@ build_address_symbolic (struct gdbarch *
 			CORE_ADDR addr,  /* IN */
 			int do_demangle, /* IN */
 			char **name,     /* OUT */
+			char **linkname, /* OUT */
 			int *offset,     /* OUT */
 			char **filename, /* OUT */
 			int *line,       /* OUT */
@@ -637,6 +661,9 @@ build_address_symbolic (struct gdbarch *
   /* Let's say it is mapped (not unmapped).  */
   *unmapped = 0;
 
+  /* Let's say the link name is the same as the symbol name.  */
+  *linkname = 0;
+
   /* Determine if the address is in an overlay, and whether it is
      mapped.  */
   if (overlay_debugging)
@@ -729,6 +756,12 @@ build_address_symbolic (struct gdbarch *
 	  *line = sal.line;
 	}
     }
+
+  /* If we have both symbol names and they are different, let caller know.  */
+  if (msymbol && symbol 
+      && strcmp (SYMBOL_LINKAGE_NAME (msymbol), SYMBOL_LINKAGE_NAME (symbol)))
+    *linkname = xstrdup (SYMBOL_LINKAGE_NAME (msymbol));
+
   return 0;
 }
 
Index: gdb/stack.c
===================================================================
RCS file: /cvs/src/src/gdb/stack.c,v
retrieving revision 1.268
diff -u -p -u -r1.268 stack.c
--- gdb/stack.c	20 Mar 2013 18:35:22 -0000	1.268
+++ gdb/stack.c	27 Mar 2013 19:36:23 -0000
@@ -54,6 +54,10 @@
 
 #include "psymtab.h"
 #include "symfile.h"
+#include "top.h"
+
+/* Maximum length of linkname to print.  */
+#define MAX_LINKNAME_LEN 20
 
 void (*deprecated_selected_frame_level_changed_hook) (int);
 
@@ -1007,11 +1011,13 @@ get_last_displayed_sal (struct symtab_an
 
 void
 find_frame_funname (struct frame_info *frame, const char **funname,
-		    enum language *funlang, struct symbol **funcp)
+		    const char **linkname, enum language *funlang, 
+		    struct symbol **funcp)
 {
   struct symbol *func;
 
   *funname = NULL;
+  *linkname = NULL;
   *funlang = language_unknown;
   if (funcp)
     *funcp = NULL;
@@ -1045,6 +1051,10 @@ find_frame_funname (struct frame_info *f
 	msymbol
 	  = lookup_minimal_symbol_by_pc (get_frame_address_in_block (frame));
 
+      if (msymbol 
+	  && strcmp (SYMBOL_LINKAGE_NAME (msymbol), SYMBOL_LINKAGE_NAME (func)))
+	*linkname = SYMBOL_LINKAGE_NAME (msymbol);
+
       if (msymbol != NULL
 	  && (SYMBOL_VALUE_ADDRESS (msymbol)
 	      > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
@@ -1103,6 +1113,7 @@ print_frame (struct frame_info *frame, i
   struct gdbarch *gdbarch = get_frame_arch (frame);
   struct ui_out *uiout = current_uiout;
   const char *funname = NULL;
+  const char *linkname = NULL;
   enum language funlang = language_unknown;
   struct ui_file *stb;
   struct cleanup *old_chain, *list_chain;
@@ -1116,7 +1127,7 @@ print_frame (struct frame_info *frame, i
   stb = mem_fileopen ();
   old_chain = make_cleanup_ui_file_delete (stb);
 
-  find_frame_funname (frame, &funname, &funlang, &func);
+  find_frame_funname (frame, &funname, &linkname, &funlang, &func);
 
   annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
 			gdbarch, pc);
@@ -1150,6 +1161,22 @@ print_frame (struct frame_info *frame, i
   ui_out_wrap_hint (uiout, "   ");
   annotate_frame_args ();
       
+  /* Print linkage name after source name if requested and different.  */
+  if (disp_linkname && linkname && strcmp (funname, linkname))
+    {
+      char *lname = (char *)linkname;
+
+      if (strlen (lname) > MAX_LINKNAME_LEN) 
+        {
+          lname = alloca (MAX_LINKNAME_LEN + 4);
+	  strncpy (lname, linkname, MAX_LINKNAME_LEN);
+	  strcat (lname, "...");
+ 	}
+      ui_out_text (uiout, " [");
+      ui_out_text (uiout, lname);
+      ui_out_text (uiout, "]");
+    }
+
   ui_out_text (uiout, " (");
   if (print_args)
     {
Index: gdb/stack.h
===================================================================
RCS file: /cvs/src/src/gdb/stack.h,v
retrieving revision 1.16
diff -u -p -u -r1.16 stack.h
--- gdb/stack.h	1 Jan 2013 06:32:51 -0000	1.16
+++ gdb/stack.h	27 Mar 2013 19:36:23 -0000
@@ -23,7 +23,8 @@
 void select_frame_command (char *level_exp, int from_tty);
 
 void find_frame_funname (struct frame_info *frame, const char **funname,
-			 enum language *funlang, struct symbol **funcp);
+			 const char **linkname, enum language *funlang, 
+			 struct symbol **funcp);
 
 typedef void (*iterate_over_block_arg_local_vars_cb) (const char *print_name,
 						      struct symbol *sym,
Index: gdb/top.c
===================================================================
RCS file: /cvs/src/src/gdb/top.c,v
retrieving revision 1.231
diff -u -p -u -r1.231 top.c
--- gdb/top.c	27 Mar 2013 12:14:09 -0000	1.231
+++ gdb/top.c	27 Mar 2013 19:36:24 -0000
@@ -297,6 +297,18 @@ quit_cover (void)
   quit_command ((char *) 0, 0);
 }
 #endif /* defined SIGHUP */
+
+/* Flag for whether we want to print linkage name for functions.  */
+
+int disp_linkname = 0;		/* Default is no. */
+static void
+show_disp_linkname (struct ui_file *file, int from_tty,
+	      struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("\
+Whether to display linkage name (symbol used by linker) for functions is %s.\n"),
+		    value);
+}
 
 /* Line number we are currently in, in a file which is being sourced.  */
 /* NOTE 1999-04-29: This variable will be static again, once we modify
@@ -1700,6 +1712,13 @@ When set, GDB uses the specified path to
                            set_gdb_datadir, NULL,
                            &setlist,
                            &showlist);
+
+  add_setshow_boolean_cmd ("display-linkage-name", class_support, &disp_linkname, _("\
+Set whether to display linkage name (symbol used by linker) for functions."), _("\
+Show whether to display linkage name (symbol used by linker) for functions."), NULL,
+			   NULL,
+ 			   show_disp_linkname,
+			   &setlist, &showlist);
 }
 
 void
Index: gdb/top.h
===================================================================
RCS file: /cvs/src/src/gdb/top.h,v
retrieving revision 1.36
diff -u -p -u -r1.36 top.h
--- gdb/top.h	7 Jan 2013 16:40:36 -0000	1.36
+++ gdb/top.h	27 Mar 2013 19:36:24 -0000
@@ -26,6 +26,7 @@ extern int saved_command_line_size;
 extern FILE *instream;
 extern int in_user_command;
 extern int confirm;
+extern int disp_linkname;
 extern char gdb_dirbuf[1024];
 extern int inhibit_gdbinit;
 extern char gdbinit[];
Index: gdb/doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.1064
diff -u -p -u -r1.1064 gdb.texinfo
--- gdb/doc/gdb.texinfo	22 Mar 2013 00:58:53 -0000	1.1064
+++ gdb/doc/gdb.texinfo	27 Mar 2013 19:36:25 -0000
@@ -15664,6 +15664,22 @@ line 1574.
 @}
 (@value{GDBP})
 @end smallexample
+
+@kindex set display-linkage-name
+@kindex show display-linkage-name
+@cindex list linker symbol names
+@item set display-linkage-name
+@itemx show display-linkage-name
+Control displaying linker symbol names for functions.
+
+The default is @code{off}, which means that @value{GDBN} will only 
+display the function name used in the source.  When @code{on}, @value{GDBN}
+will also display the symbol name used by the linker within brackets if it is
+different from the name in the source.  This can be useful with compilers
+which may prepend characters to a source name, for example, an underscore.  
+
+This is different from "set print asm-demangle on" which only displays
+the linkage name for C++ symbols and does not display the source name.
 @end table
 
 
Index: gdb/python/py-frame.c
===================================================================
RCS file: /cvs/src/src/gdb/python/py-frame.c,v
retrieving revision 1.29
diff -u -p -u -r1.29 py-frame.c
--- gdb/python/py-frame.c	23 Jan 2013 19:59:11 -0000	1.29
+++ gdb/python/py-frame.c	27 Mar 2013 19:36:25 -0000
@@ -123,6 +123,7 @@ frapy_name (PyObject *self, PyObject *ar
 {
   struct frame_info *frame;
   const char *name;
+  const char *linkname;
   enum language lang;
   PyObject *result;
   volatile struct gdb_exception except;
@@ -131,7 +132,7 @@ frapy_name (PyObject *self, PyObject *ar
     {
       FRAPY_REQUIRE_VALID (self, frame);
 
-      find_frame_funname (frame, &name, &lang, NULL);
+      find_frame_funname (frame, &name, &linkname, &lang, NULL);
     }
   GDB_PY_HANDLE_EXCEPTION (except);
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]