* [PATCH] Revised display-linkage-name
@ 2013-05-22 18:28 Michael Eager
2013-05-22 19:28 ` Eli Zaretskii
2013-06-17 17:35 ` Michael Eager
0 siblings, 2 replies; 19+ messages in thread
From: Michael Eager @ 2013-05-22 18:28 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
[-- Attachment #1: Type: text/plain, Size: 2444 bytes --]
Attached is a revised patch to display the linkage name (the linker symbol)
along with the function name when setting, listing, or hitting a breakpoint.
This is a revision of http://sourceware.org/ml/gdb-patches/2013-03/msg00806.html.
(BTW, the gdb-patches mailing list archive doesn't show the original email from
3/18/13, quoted in the referenced message.)
Changes:
Add NEWS and docs.
Add linkage name to "info break" listing.
Add MI annotations.
Add command to set/show display length limit, remove define.
Add test case.
There is a minor inconsistency where the linkage name is displayed.
When setting/hitting a breakpoint, the linkage name is displayed
within brackets following the source name, before the arguments. In
the "info breakpoint" command, the linkage name is displayed in brackets
after the arguments. This is because SYMBOL_PRINT_NAME(sym) returns a
complete function signature, not just the function name.
The test case was added to gdb.cp for convenience, since it uses
the C++ compiler. The patch is not dependent on C++.
Tom -- can you verify that the MI support is correct? I don't have
any way to test this.
gdb/
2013-05-23 Michael Eager <eager@eagercon.com>
* NEWS: Announcement.
* ada-lang.c: Update calls to find_frame_funname.
* disasm.c: Likewise.
* python/py-frame.c: Likewise.
* annotate.c (annotate_linkage_name): New.
* annotate.h (annotate_linkage_name): Declare.
* breakpoint.c (print_breakpoint_location): Print linkage name.
* defs.h (build_address_symbolic): Add linkname arg.
* printcmd.c (print_address_symbolic): Print linkage name.
(build_address_symbolic): Return linkage name.
* stack.c (find_frame_funname): Return linkage name.
(print_frame): Print linkage name.
* stack.h (find_frame_funname): Update declaration.
* top.c (display_linkage_name, display_linkage_name_len): New.
(show_display_linkage_name, show_display_linkage_name_len): New cmds.
* top.h (display_linkage_name, display_linkage_name_len): Declare.
gdb/doc
2013-05-23 Michael Eager <eager@eagercon.com>
* gdb.texinfo: Add description.
gdb/testsuite
2013-05-23 Michael Eager <eager@eagercon.com>
* gdb.cp/display-linkage-name.exp: New.
* gdb.cp/display-linkage-name.cc: New.
--
Michael Eager eager@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306 650-325-8077
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: display-linkage-name.patch --]
[-- Type: text/x-patch; name="display-linkage-name.patch", Size: 26978 bytes --]
commit b7dd81ef7313eebf8ceeb6a592b4d2cb615190d8
Author: Michael Eager <eager@eagercon.com>
Date: Wed May 22 10:48:44 2013 -0700
GDB - Display Linkage Name
Display linkage name (symbol linker uses) where function name is displayed.
gdb:
* NEWS: Announcement.
* ada-lang.c: Update call to find_frame_funname.
* disasm.c (dump_insns): Likewise.
* python/py-frame.c (frapy_is_valid): Likewise.
* annotate.c (annotate_linkage_name): New.
* annotate.h (annotate_linkage_name): Declare.
* breakpoint.c (print_breakpoint_location): Print linkage name.
* defs.h (build_address_symbolic): Add linkname arg.
* printcmd.c (print_address_symbolic): Print linkage name.
(build_address_symbolic): Return linkage name.
* stack.c (find_frame_funname): Return linkage name.
(print_frame): Print linkage name.
* stack.h (find_frame_funname): Update declaration.
* top.c (display_linkage_name, display_linkage_name_len): New.
(show_display_linkage_name, show_display_linkage_name_len): New cmds.
* top.h (display_linkage_name, display_linkage_name_len): Declare.
doc:
* gdb.texinfo: Add description.
testsuite:
* gdb.cp/display-linkage-name.exp: New.
* gdb.cp/display-linkage-name.cc: New.
diff --git a/gdb/NEWS b/gdb/NEWS
index 7cd1646..4185c34 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -45,6 +45,20 @@ show debug nios2
--configuration
Display the details of GDB configure-time options.
+* 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.
+
+set|show display-linkage-name-len
+
+ Set the maximum number of characters to display in the linkage name,
+ if display-linkage-name is on. The default is 20.
+
* The command 'tsave' can now support new option '-ctf' to save trace
buffer in Common Trace Format.
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 3510750..f73e0b1 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -11104,6 +11104,7 @@ is_known_support_routine (struct frame_info *frame)
{
struct symtab_and_line sal;
const char *func_name;
+ const char *linkname;
enum language func_lang;
int i;
const char *fullname;
@@ -11142,7 +11143,7 @@ is_known_support_routine (struct frame_info *frame)
/* 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;
@@ -11209,9 +11210,10 @@ ada_unhandled_exception_name_addr_from_raise (void)
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... */
diff --git a/gdb/annotate.c b/gdb/annotate.c
index ccba5fe..84edeac 100644
--- a/gdb/annotate.c
+++ b/gdb/annotate.c
@@ -582,6 +582,13 @@ breakpoint_changed (struct breakpoint *b)
}
void
+annotate_linkage_name (void)
+{
+ if (annotation_level == 2)
+ printf_filtered (("\n\032\032linkage_name\n"));
+}
+
+void
_initialize_annotate (void)
{
observer_attach_breakpoint_created (breakpoint_changed);
diff --git a/gdb/annotate.h b/gdb/annotate.h
index 72c4f19..33a9a0e 100644
--- a/gdb/annotate.h
+++ b/gdb/annotate.h
@@ -98,5 +98,7 @@ extern void annotate_elt_rep_end (void);
extern void annotate_elt (void);
extern void annotate_array_section_end (void);
+extern void annotate_linkage_name (void);
+
extern void (*deprecated_annotate_signalled_hook) (void);
extern void (*deprecated_annotate_signal_hook) (void);
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index f4f9325..52dbcf4 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -5699,6 +5699,33 @@ print_breakpoint_location (struct breakpoint *b,
ui_out_text (uiout, "in ");
ui_out_field_string (uiout, "func",
SYMBOL_PRINT_NAME (sym));
+ if (display_linkage_name)
+ {
+ struct bound_minimal_symbol msymbol =
+ lookup_minimal_symbol_by_pc (loc->address);
+ if (msymbol.minsym != NULL
+ && strcmp (SYMBOL_LINKAGE_NAME (msymbol.minsym),
+ SYMBOL_PRINT_NAME (sym)) != 0)
+ {
+ ui_out_text (uiout, " [");
+
+ if (strlen (SYMBOL_LINKAGE_NAME (msymbol.minsym)) >
+ display_linkage_name_len)
+ {
+ char *lname = alloca (display_linkage_name_len + 4);
+ strncpy (lname, SYMBOL_LINKAGE_NAME (msymbol.minsym),
+ display_linkage_name_len);
+ lname[display_linkage_name_len] = '\0';
+ strcat (lname, "...");
+ ui_out_field_string (uiout, "linkage-name", lname);
+ }
+ else
+ ui_out_field_string (uiout, "linkage-name",
+ SYMBOL_LINKAGE_NAME (msymbol.minsym));
+
+ ui_out_text (uiout, "]");
+ }
+ }
ui_out_text (uiout, " ");
ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
ui_out_text (uiout, "at ");
diff --git a/gdb/defs.h b/gdb/defs.h
index d8a1adb..9f32ea4 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -86,7 +86,7 @@
/* The O_BINARY flag is defined in fcntl.h on some non-Posix platforms.
It is used as an access modifier in calls to open(), where it acts
similarly to the "b" character in fopen()'s MODE argument. On Posix
- platforms it should be a no-op, so it is defined as 0 here. This
+ platforms it should be a no-op, so it is defined as 0 here. This
ensures that the symbol may be used freely elsewhere in gdb. */
#ifndef O_BINARY
@@ -160,7 +160,7 @@ extern char *debug_file_directory;
handler. Otherwise, SIGINT simply sets a flag; code that might
take a long time, and which ought to be interruptible, checks this
flag using the QUIT macro.
-
+
If GDB is built with Python support, it uses Python's low-level
interface to implement the flag. This approach makes it possible
for Python and GDB SIGINT handling to coexist seamlessly.
@@ -333,10 +333,11 @@ extern int print_address_symbolic (struct gdbarch *, CORE_ADDR,
extern int build_address_symbolic (struct gdbarch *,
CORE_ADDR addr,
- int do_demangle,
- char **name,
- int *offset,
- char **filename,
+ int do_demangle,
+ char **name,
+ char **linkname,
+ int *offset,
+ char **filename,
int *line,
int *unmapped);
@@ -716,9 +717,9 @@ extern int (*deprecated_ui_loop_hook) (int signo);
extern void (*deprecated_init_ui_hook) (char *argv0);
extern void (*deprecated_command_loop_hook) (void);
extern void (*deprecated_show_load_progress) (const char *section,
- unsigned long section_sent,
- unsigned long section_size,
- unsigned long total_sent,
+ unsigned long section_sent,
+ unsigned long section_size,
+ unsigned long total_sent,
unsigned long total_size);
extern void (*deprecated_print_frame_info_listing_hook) (struct symtab * s,
int line,
diff --git a/gdb/disasm.c b/gdb/disasm.c
index e643c2d..62fa34d 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -112,6 +112,7 @@ dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
{
char *filename = NULL;
char *name = NULL;
+ char *linkname = NULL;
QUIT;
if (how_many >= 0)
@@ -127,8 +128,8 @@ dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
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. */
@@ -146,6 +147,7 @@ dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
xfree (filename);
if (name != NULL)
xfree (name);
+ xfree (linkname);
ui_file_rewind (stb);
if (flags & DISASSEMBLY_RAW_INSN)
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 02c2408..5174726 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -15899,8 +15899,31 @@ line 1574.
@}
(@value{GDBP})
@end smallexample
-@end table
+@kindex set display-linkage-name @code{on}|@code{off}
+@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.
+
+@kindex set display-linkage-name-len
+@kindex show display-linkage-name-len
+@cindex list linker symbol names
+@item set display-linkage-name-len @var{len}
+@itemx show display-linkage-name-len @var{len}
+Set the maximum number of characters of linkage name to display. The
+@code{show} command displays the current setting. The default is @code{20}.
+@end table
@node Altering
@chapter Altering Execution
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 2cc33d0..994b503 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -51,6 +51,7 @@
#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. */
@@ -569,17 +570,19 @@ print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr,
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);
+ make_cleanup (free_current_contents, &linkname);
- 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 +594,27 @@ print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr,
else
fputs_filtered ("<", stream);
fputs_filtered (name, stream);
+
+ /* Print linkage name after source name if requested and different. */
+ if (display_linkage_name
+ && linkname != NULL && strcmp (name, linkname) != 0)
+ {
+ fputs_filtered (" [", stream);
+
+ if (strlen (linkname) > display_linkage_name_len)
+ {
+ char *lname = alloca (display_linkage_name_len + 4);
+ strncpy (lname, linkname, display_linkage_name_len);
+ lname[display_linkage_name_len] = '\0';
+ strcat (lname, "...");
+ fputs_filtered (lname, stream);
+ }
+ else
+ fputs_filtered (linkname, stream);
+
+ fputs_filtered ("]", stream);
+ }
+
if (offset != 0)
fprintf_filtered (stream, "+%u", (unsigned int) offset);
@@ -623,6 +647,7 @@ build_address_symbolic (struct gdbarch *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 +662,9 @@ build_address_symbolic (struct gdbarch *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 +757,12 @@ build_address_symbolic (struct gdbarch *gdbarch,
*line = sal.line;
}
}
+
+ /* If we have both symbol names and they are different, let caller know. */
+ if (msymbol != NULL && symbol != NULL
+ && strcmp (SYMBOL_LINKAGE_NAME (msymbol), SYMBOL_LINKAGE_NAME (symbol)) != 0)
+ *linkname = xstrdup (SYMBOL_LINKAGE_NAME (msymbol));
+
return 0;
}
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index e2eb9c5..2b2b64f 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -123,6 +123,7 @@ frapy_name (PyObject *self, PyObject *args)
{
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 *args)
{
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);
diff --git a/gdb/stack.c b/gdb/stack.c
index d10e9b4..5465a2a 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -55,6 +55,7 @@
#include "psymtab.h"
#include "symfile.h"
#include "python/python.h"
+#include "top.h"
void (*deprecated_selected_frame_level_changed_hook) (int);
@@ -1004,15 +1005,19 @@ get_last_displayed_sal (struct symtab_and_line *sal)
/* Attempt to obtain the FUNNAME, FUNLANG and optionally FUNCP of the function
- corresponding to FRAME. */
+ corresponding to FRAME.
+ Set linkname to linkage name (symbol used by linker) if linkname is non-null
+ and linkage name differs from source name. */
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;
@@ -1049,6 +1054,11 @@ find_frame_funname (struct frame_info *frame, const char **funname,
memset (&msymbol, 0, sizeof (msymbol));
if (msymbol.minsym != NULL
+ && strcmp (SYMBOL_LINKAGE_NAME (msymbol.minsym),
+ SYMBOL_LINKAGE_NAME (func)) != 0)
+ *linkname = SYMBOL_LINKAGE_NAME (msymbol.minsym);
+
+ if (msymbol.minsym != NULL
&& (SYMBOL_VALUE_ADDRESS (msymbol.minsym)
> BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
{
@@ -1106,6 +1116,7 @@ print_frame (struct frame_info *frame, int print_level,
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;
@@ -1119,7 +1130,7 @@ print_frame (struct frame_info *frame, int print_level,
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,9 +1161,32 @@ print_frame (struct frame_info *frame, int print_level,
fprintf_symbol_filtered (stb, funname ? funname : "??",
funlang, DMGL_ANSI);
ui_out_field_stream (uiout, "func", stb);
+
+ /* Print linkage name after source name if requested and different. */
+ if ((display_linkage_name || ui_out_is_mi_like_p (uiout))
+ && linkname != NULL && strcmp (funname, linkname) != 0)
+ {
+ annotate_linkage_name ();
+ ui_out_text (uiout, " [");
+
+ if (strlen (linkname) > display_linkage_name_len)
+ {
+ char *lname = alloca (display_linkage_name_len + 4);
+ strncpy (lname, linkname, display_linkage_name_len);
+ lname[display_linkage_name_len] = '\0';
+ strcat (lname, "...");
+ ui_out_text (uiout, lname);
+ }
+ else
+ ui_out_text (uiout, linkname);
+
+ ui_out_text (uiout, "]");
+ ui_out_field_stream (uiout, "linkage_name", stb);
+ }
+
ui_out_wrap_hint (uiout, " ");
annotate_frame_args ();
-
+
ui_out_text (uiout, " (");
if (print_args)
{
diff --git a/gdb/stack.h b/gdb/stack.h
index 841ad43..1e99a72 100644
--- a/gdb/stack.h
+++ b/gdb/stack.h
@@ -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,
diff --git a/gdb/testsuite/gdb.cp/display-linkage-name.cc b/gdb/testsuite/gdb.cp/display-linkage-name.cc
new file mode 100644
index 0000000..93b2ba2
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/display-linkage-name.cc
@@ -0,0 +1,19 @@
+void foo (const char *msg)
+{
+} /* set breakpoint 1 here */
+
+void fun_with_a_long_name (int i, const char *s, double d)
+{
+ foo ("Hello"); /* set breakpoint 2 here */
+}
+
+void goo (void)
+{
+ fun_with_a_long_name (1, "abc", 3.14);
+}
+
+int main (void)
+{
+ goo();
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.cp/display-linkage-name.exp b/gdb/testsuite/gdb.cp/display-linkage-name.exp
new file mode 100644
index 0000000..aa077c4
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/display-linkage-name.exp
@@ -0,0 +1,153 @@
+# Copyright 2013 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This file was written by Michael Eager (eager@eagercon.com).
+
+if { [skip_cplus_tests] } { continue }
+
+standard_testfile .cc
+
+if [get_compiler_info "c++"] {
+ return -1
+}
+
+if { [prepare_for_testing display-linkage-name.exp display-linkage-name display-linkage-name.cc {debug c++}] } {
+ return -1
+}
+set srcfile display-linkage-name.cc
+
+set bp1 [gdb_get_line_number "set breakpoint 1 here"]
+set bp2 [gdb_get_line_number "set breakpoint 2 here"]
+
+#
+# test display-linkage-name commands.
+#
+
+gdb_test "set display-linkage-name off" ""
+
+#
+# set break at functions
+#
+gdb_test "break foo" \
+ "Breakpoint.*at.* file .*$srcfile, line $bp1.*" \
+ "breakpoint function"
+
+gdb_test "break fun_with_a_long_name" \
+ "Breakpoint.*at.* file .*$srcfile, line $bp2.*" \
+ "breakpoint function"
+
+gdb_test "info break" \
+ "Num Type\[ \]+Disp Enb Address\[\t \]+What.*
+1\[\t \]+breakpoint keep y.* in foo(.*) at .*$srcfile:$bp1.*
+2\[\t \]+breakpoint keep y.* in fun_with_a_long_name(.*) at .*$srcfile:$bp2.*" \
+ "info breakpoint - display off"
+
+gdb_run_cmd
+gdb_expect {
+ -re "Breakpoint 2, fun_with_a_long_name (.*) at .*$srcfile:$bp2.*$gdb_prompt $" {
+ pass "run until breakpoint - display off"
+ }
+ -re "$gdb_prompt $" {
+ fail "run until breakpoint - display off"
+ }
+ timeout {
+ fail "run until breakpoint - display off (timeout)"
+ }
+}
+
+gdb_test continue "Continuing\\..*Breakpoint 1, foo (.*) at .*$srcfile:$bp1.*\[\t \]+\\}.*" \
+ "continue until function breakpoint - display off"
+
+set bttable "#0 foo (.*) at.*\[\r\n\]"
+append bttable "#1 \[0-9a-fx\]+ in fun_with_a_long_name (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#2 \[0-9a-fx\]+ in goo (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#3 \[0-9a-fx\]+ in main (.*) at .*$srcfile:.*"
+
+gdb_test "backtrace" $bttable "backtrace - display off"
+
+########################
+# Test with display-linkage-name on
+
+gdb_test "set display-linkage-name on" ""
+
+gdb_test "info break" \
+ "Num Type\[ \]+Disp Enb Address\[\t \]+What.*
+1\[\t \]+breakpoint keep y.* in foo(.*) \\\[_Z3fooPKc\\\] at .*$srcfile:$bp1.*
+2\[\t \]+breakpoint keep y.* in fun_with_a_long_name(.*) \\\[_Z20fun_with_a_long_\.\.\.\\\] at .*$srcfile:$bp2.*" \
+ "info breakpoint - display on"
+
+gdb_run_cmd
+gdb_expect {
+ -re "Breakpoint 2, fun_with_a_long_name \\\[_Z20fun_with_a_long_\.\.\.\\\] (.*) at .*$srcfile:$bp2.*$gdb_prompt $" {
+ pass "run until function breakpoint - display on"
+ }
+ -re "$gdb_prompt $" {
+ fail "run until function breakpoint - display on"
+ }
+ timeout {
+ fail "run until function breakpoint (timeout) - display on"
+ }
+}
+
+gdb_test continue "Continuing\\..*Breakpoint 1, foo \\\[_Z3fooPKc\\\] (.*) at .*$srcfile:$bp1.*\[\t \]+\\}.*" \
+ "continue until function breakpoint - display on"
+
+set bttable "#0 foo \\\[_Z3fooPKc\\\] (.*) at.*\[\r\n\]"
+append bttable "#1 \[0-9a-fx\]+ in fun_with_a_long_name \\\[_Z20fun_with_a_long_\.\.\.\\\] (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#2 \[0-9a-fx\]+ in goo \\\[_Z3goov\\\] (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#3 \[0-9a-fx\]+ in main (.*) at .*$srcfile:.*"
+
+gdb_test "backtrace" $bttable "backtrace - display on"
+
+########################
+# Test set/show display-linkage-name-len
+
+gdb_test "show display-linkage-name-len" \
+ "Length of linkage name \\(symbol used by linker\\) to be displayed is 20."
+
+gdb_test "set display-linkage-name-len 10" ""
+
+gdb_test "show display-linkage-name-len" \
+ "Length of linkage name \\(symbol used by linker\\) to be displayed is 10."
+
+gdb_test "info break" \
+ "Num Type\[ \]+Disp Enb Address\[\t \]+What.*
+1\[\t \]+breakpoint keep y.* in foo(.*) \\\[_Z3fooPKc\\\] at .*$srcfile:$bp1.*
+2\[\t \]+breakpoint keep y.* in fun_with_a_long_name(.*) \\\[_Z20fun_wi\.\.\.\\\] at .*$srcfile:$bp2.*" \
+ "info breakpoint - display 10"
+
+gdb_run_cmd
+gdb_expect {
+ -re "Breakpoint 2, fun_with_a_long_name \\\[_Z20fun_wi\.\.\.\\\] (.*) at .*$srcfile:$bp2.*$gdb_prompt $" {
+ pass "run until function breakpoint - display 10"
+ }
+ -re "$gdb_prompt $" {
+ fail "run until function breakpoint - display 10"
+ }
+ timeout {
+ fail "run until function breakpoint (timeout) - display 10"
+ }
+}
+
+gdb_test continue "Continuing\\..*Breakpoint 1, foo \\\[_Z3fooPKc\\\] (.*) at .*$srcfile:$bp1.*\[\t \]+\\}.*" \
+ "continue until function breakpoint - display 10"
+
+set bttable "#0 foo \\\[_Z3fooPKc\\\] (.*) at.*\[\r\n\]"
+append bttable "#1 \[0-9a-fx\]+ in fun_with_a_long_name \\\[_Z20fun_wi\.\.\.\\\] (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#2 \[0-9a-fx\]+ in goo \\\[_Z3goov\\\] (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#3 \[0-9a-fx\]+ in main (.*) at .*$srcfile:.*"
+
+gdb_test "backtrace" $bttable "backtrace - display 10"
+
diff --git a/gdb/top.c b/gdb/top.c
index 480b67e..fb65ecc 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -298,6 +298,29 @@ quit_cover (void)
quit_command ((char *) 0, 0);
}
#endif /* defined SIGHUP */
+
+/* Flag for whether we want to print linkage name for functions.
+ Length of linkage name to print. */
+
+int display_linkage_name = 1; /* Default is yes. */
+int display_linkage_name_len = 20; /* Default is first 20 chars. */
+
+static void
+show_display_linkage_name (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);
+}
+static void
+show_display_linkage_name_len (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c, const char *value)
+{
+ fprintf_filtered (file, _("\
+Length of linkage name (symbol used by linker) to be displayed is %s.\n"),
+ value);
+}
\f
/* 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
@@ -1813,7 +1836,22 @@ Use \"on\" to enable the notification, and \"off\" to disable it."),
When set, GDB uses the specified path to search for data files."),
set_gdb_datadir, NULL,
&setlist,
- &showlist);
+ &showlist);
+
+ add_setshow_boolean_cmd ("display-linkage-name", class_support, &display_linkage_name, _("\
+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_display_linkage_name,
+ &setlist, &showlist);
+
+ add_setshow_zinteger_cmd ("display-linkage-name-len", class_support, &display_linkage_name_len, _("\
+Set number of characters of linkage name to display."), _("\
+Show number of characters of linkage name to display."), NULL,
+ NULL,
+ show_display_linkage_name_len,
+ &setlist, &showlist);
+
}
void
diff --git a/gdb/top.h b/gdb/top.h
index 44aefb1..bb75189 100644
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -26,6 +26,8 @@ extern int saved_command_line_size;
extern FILE *instream;
extern int in_user_command;
extern int confirm;
+extern int display_linkage_name;
+extern int display_linkage_name_len;
extern char gdb_dirbuf[1024];
extern int inhibit_gdbinit;
extern char gdbinit[];
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Revised display-linkage-name
2013-05-22 18:28 [PATCH] Revised display-linkage-name Michael Eager
@ 2013-05-22 19:28 ` Eli Zaretskii
2013-05-22 21:42 ` Michael Eager
2013-06-17 17:35 ` Michael Eager
1 sibling, 1 reply; 19+ messages in thread
From: Eli Zaretskii @ 2013-05-22 19:28 UTC (permalink / raw)
To: Michael Eager; +Cc: gdb-patches, tromey
> Date: Wed, 22 May 2013 11:03:22 -0700
> From: Michael Eager <eager@eagerm.com>
> CC: Tom Tromey <tromey@redhat.com>
>
> Changes:
> Add NEWS and docs.
> Add linkage name to "info break" listing.
> Add MI annotations.
> Add command to set/show display length limit, remove define.
> Add test case.
Thanks.
> +set|show display-linkage-name-len
> +
> + Set the maximum number of characters to display in the linkage name,
> + if display-linkage-name is on. The default is 20.
Do we really need this? Why not display the whole name always?
> +@kindex set display-linkage-name @code{on}|@code{off}
Please remove the on|off part from the index entry. Just the command
is enough.
> +@cindex list linker symbol names
Is "linker symbol name" how users would expect this to be called? I
wouldn't. Index entries should use phrases that readers might have in
mind when they are looking for the stuff described in this section.
I think the correct terminology is "linkage name".
> +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.
Isn't it confusing to have 2 subtly different settings that actually
achieve almost the same? How about a single setting, perhaps a
tristate, instead of 2 separate booleans?
> +@kindex set display-linkage-name-len
> +@kindex show display-linkage-name-len
> +@cindex list linker symbol names
^^^^^^^^^^^^^^^^^^^^^^^^
Copy/paste error? You already have an identical index entry a few
lines above.
> +@item set display-linkage-name-len @var{len}
> +@itemx show display-linkage-name-len @var{len}
> +Set the maximum number of characters of linkage name to display. The
> +@code{show} command displays the current setting. The default is @code{20}.
I think we don't need this setting. After all, we show source-level
function names in their full glory, right?
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Revised display-linkage-name
2013-05-22 19:28 ` Eli Zaretskii
@ 2013-05-22 21:42 ` Michael Eager
0 siblings, 0 replies; 19+ messages in thread
From: Michael Eager @ 2013-05-22 21:42 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches, tromey
On 05/22/2013 12:28 PM, Eli Zaretskii wrote:
>> Date: Wed, 22 May 2013 11:03:22 -0700
>> From: Michael Eager <eager@eagerm.com>
>> CC: Tom Tromey <tromey@redhat.com>
>>
>> Changes:
>> Add NEWS and docs.
>> Add linkage name to "info break" listing.
>> Add MI annotations.
>> Add command to set/show display length limit, remove define.
>> Add test case.
>
> Thanks.
>
>> +set|show display-linkage-name-len
>> +
>> + Set the maximum number of characters to display in the linkage name,
>> + if display-linkage-name is on. The default is 20.
>
> Do we really need this? Why not display the whole name always?
With C++, and especially with templates, the linker name can become
very long.
>
>> +@kindex set display-linkage-name @code{on}|@code{off}
>
> Please remove the on|off part from the index entry. Just the command
> is enough.
OK.
>
>> +@cindex list linker symbol names
>
> Is "linker symbol name" how users would expect this to be called? I
> wouldn't. Index entries should use phrases that readers might have in
> mind when they are looking for the stuff described in this section.
>
> I think the correct terminology is "linkage name".
The only reference I find using Google to "linkage name" is in DWARF.
I don't consider this to be common or widely used terminology. I
personally would look for "symbol name", which unfortunately has multiple
meanings.
I'm happy to use "linkage name", but I don't think that this is a
phrase readers might have in mind, unless they had just been reading
the DWARF spec.
>
>> +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.
>
> Isn't it confusing to have 2 subtly different settings that actually
> achieve almost the same? How about a single setting, perhaps a
> tristate, instead of 2 separate booleans?
I don't think it is confusing.
The two options are significantly different, both in implementation and
definition. Asm-demangle is only mentioned as contrast in information provided.
The functionality provided by display-linkage-name is not related to C++.
There is no demangling being performed. Trying to combine two unrelated
options into one would make a hash of the coding for both.
>
>> +@kindex set display-linkage-name-len
>> +@kindex show display-linkage-name-len
>> +@cindex list linker symbol names
> ^^^^^^^^^^^^^^^^^^^^^^^^
> Copy/paste error? You already have an identical index entry a few
> lines above.
Oops.
>
>> +@item set display-linkage-name-len @var{len}
>> +@itemx show display-linkage-name-len @var{len}
>> +Set the maximum number of characters of linkage name to display. The
>> +@code{show} command displays the current setting. The default is @code{20}.
>
> I think we don't need this setting. After all, we show source-level
> function names in their full glory, right?
Source level names are limited in size. Linker names may be thousands
of characters long.
--
Michael Eager eager@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306 650-325-8077
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Revised display-linkage-name
2013-05-22 18:28 [PATCH] Revised display-linkage-name Michael Eager
2013-05-22 19:28 ` Eli Zaretskii
@ 2013-06-17 17:35 ` Michael Eager
2013-07-10 16:17 ` Michael Eager
1 sibling, 1 reply; 19+ messages in thread
From: Michael Eager @ 2013-06-17 17:35 UTC (permalink / raw)
To: gdb-patches
Ping!
On 05/22/2013 11:03 AM, Michael Eager wrote:
> Attached is a revised patch to display the linkage name (the linker symbol)
> along with the function name when setting, listing, or hitting a breakpoint.
> This is a revision of http://sourceware.org/ml/gdb-patches/2013-03/msg00806.html.
> (BTW, the gdb-patches mailing list archive doesn't show the original email from
> 3/18/13, quoted in the referenced message.)
>
> Changes:
> Add NEWS and docs.
> Add linkage name to "info break" listing.
> Add MI annotations.
> Add command to set/show display length limit, remove define.
> Add test case.
>
> There is a minor inconsistency where the linkage name is displayed.
> When setting/hitting a breakpoint, the linkage name is displayed
> within brackets following the source name, before the arguments. In
> the "info breakpoint" command, the linkage name is displayed in brackets
> after the arguments. This is because SYMBOL_PRINT_NAME(sym) returns a
> complete function signature, not just the function name.
>
> The test case was added to gdb.cp for convenience, since it uses
> the C++ compiler. The patch is not dependent on C++.
>
> Tom -- can you verify that the MI support is correct? I don't have
> any way to test this.
>
>
> gdb/
> 2013-05-23 Michael Eager <eager@eagercon.com>
>
> * NEWS: Announcement.
> * ada-lang.c: Update calls to find_frame_funname.
> * disasm.c: Likewise.
> * python/py-frame.c: Likewise.
> * annotate.c (annotate_linkage_name): New.
> * annotate.h (annotate_linkage_name): Declare.
> * breakpoint.c (print_breakpoint_location): Print linkage name.
> * defs.h (build_address_symbolic): Add linkname arg.
> * printcmd.c (print_address_symbolic): Print linkage name.
> (build_address_symbolic): Return linkage name.
> * stack.c (find_frame_funname): Return linkage name.
> (print_frame): Print linkage name.
> * stack.h (find_frame_funname): Update declaration.
> * top.c (display_linkage_name, display_linkage_name_len): New.
> (show_display_linkage_name, show_display_linkage_name_len): New cmds.
> * top.h (display_linkage_name, display_linkage_name_len): Declare.
>
> gdb/doc
> 2013-05-23 Michael Eager <eager@eagercon.com>
>
> * gdb.texinfo: Add description.
>
> gdb/testsuite
> 2013-05-23 Michael Eager <eager@eagercon.com>
>
> * gdb.cp/display-linkage-name.exp: New.
> * gdb.cp/display-linkage-name.cc: New.
>
--
Michael Eager eager@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306 650-325-8077
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Revised display-linkage-name
2013-06-17 17:35 ` Michael Eager
@ 2013-07-10 16:17 ` Michael Eager
2013-07-11 23:28 ` Keith Seitz
0 siblings, 1 reply; 19+ messages in thread
From: Michael Eager @ 2013-07-10 16:17 UTC (permalink / raw)
To: gdb-patches
Ping!
Can someone review and approve this patch?
On 06/17/13 10:31, Michael Eager wrote:
> Ping!
>
> On 05/22/2013 11:03 AM, Michael Eager wrote:
>> Attached is a revised patch to display the linkage name (the linker symbol)
>> along with the function name when setting, listing, or hitting a breakpoint.
>> This is a revision of http://sourceware.org/ml/gdb-patches/2013-03/msg00806.html.
>> (BTW, the gdb-patches mailing list archive doesn't show the original email from
>> 3/18/13, quoted in the referenced message.)
>>
>> Changes:
>> Add NEWS and docs.
>> Add linkage name to "info break" listing.
>> Add MI annotations.
>> Add command to set/show display length limit, remove define.
>> Add test case.
>>
>> There is a minor inconsistency where the linkage name is displayed.
>> When setting/hitting a breakpoint, the linkage name is displayed
>> within brackets following the source name, before the arguments. In
>> the "info breakpoint" command, the linkage name is displayed in brackets
>> after the arguments. This is because SYMBOL_PRINT_NAME(sym) returns a
>> complete function signature, not just the function name.
>>
>> The test case was added to gdb.cp for convenience, since it uses
>> the C++ compiler. The patch is not dependent on C++.
>>
>> Tom -- can you verify that the MI support is correct? I don't have
>> any way to test this.
>>
>>
>> gdb/
>> 2013-05-23 Michael Eager <eager@eagercon.com>
>>
>> * NEWS: Announcement.
>> * ada-lang.c: Update calls to find_frame_funname.
>> * disasm.c: Likewise.
>> * python/py-frame.c: Likewise.
>> * annotate.c (annotate_linkage_name): New.
>> * annotate.h (annotate_linkage_name): Declare.
>> * breakpoint.c (print_breakpoint_location): Print linkage name.
>> * defs.h (build_address_symbolic): Add linkname arg.
>> * printcmd.c (print_address_symbolic): Print linkage name.
>> (build_address_symbolic): Return linkage name.
>> * stack.c (find_frame_funname): Return linkage name.
>> (print_frame): Print linkage name.
>> * stack.h (find_frame_funname): Update declaration.
>> * top.c (display_linkage_name, display_linkage_name_len): New.
>> (show_display_linkage_name, show_display_linkage_name_len): New cmds.
>> * top.h (display_linkage_name, display_linkage_name_len): Declare.
>>
>> gdb/doc
>> 2013-05-23 Michael Eager <eager@eagercon.com>
>>
>> * gdb.texinfo: Add description.
>>
>> gdb/testsuite
>> 2013-05-23 Michael Eager <eager@eagercon.com>
>>
>> * gdb.cp/display-linkage-name.exp: New.
>> * gdb.cp/display-linkage-name.cc: New.
>>
>
>
--
Michael Eager eager@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306 650-325-8077
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Revised display-linkage-name
2013-07-10 16:17 ` Michael Eager
@ 2013-07-11 23:28 ` Keith Seitz
2013-07-12 21:17 ` Michael Eager
0 siblings, 1 reply; 19+ messages in thread
From: Keith Seitz @ 2013-07-11 23:28 UTC (permalink / raw)
To: Michael Eager; +Cc: gdb-patches
On 07/10/2013 09:17 AM, Michael Eager wrote:
> Can someone review and approve this patch?
Tom's been a little busy of late, so I thought I would try to help out
here a little. You'll be one step closer to approval!
Your patches no longer apply cleanly to HEAD, so I fixed them up to play
with them. I'll be commenting on this version.
> diff --git a/gdb/NEWS b/gdb/NEWS
> index e469f1e..40addb1 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -56,6 +56,20 @@ show range-stepping
> --configuration
> Display the details of GDB configure-time options.
>
> +* 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:
"prepends" or "prefixes"?
> +
> +set|show display-linkage-name [off|on]
> +
> + The default is "off", to not display the linkage name.
> +
> +set|show display-linkage-name-len
> +
> + Set the maximum number of characters to display in the linkage name,
> + if display-linkage-name is on. The default is 20.
> +
> * The command 'tsave' can now support new option '-ctf' to save trace
> buffer in Common Trace Format.
>
> diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
> index 8240fee..e9e0002 100644
> --- a/gdb/ada-lang.c
> +++ b/gdb/ada-lang.c
> @@ -11114,6 +11114,7 @@ is_known_support_routine (struct frame_info *frame)
> {
> struct symtab_and_line sal;
> char *func_name;
> + const char *linkname;
> enum language func_lang;
> int i;
> const char *fullname;
> @@ -11152,7 +11153,7 @@ is_known_support_routine (struct frame_info *frame)
>
> /* 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;
>
`linkname' is unused here -- more about this later.
> @@ -11225,9 +11226,10 @@ ada_unhandled_exception_name_addr_from_raise (void)
> while (fi != NULL)
> {
> 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)
> {
> make_cleanup (xfree, func_name);
Likewise.
> diff --git a/gdb/annotate.c b/gdb/annotate.c
> index ccba5fe..84edeac 100644
> --- a/gdb/annotate.c
> +++ b/gdb/annotate.c
> @@ -582,6 +582,13 @@ breakpoint_changed (struct breakpoint *b)
> }
>
> void
> +annotate_linkage_name (void)
> +{
> + if (annotation_level == 2)
> + printf_filtered (("\n\032\032linkage_name\n"));
> +}
> +
This is a new function and will require a (trivial) comment.
> +void
> _initialize_annotate (void)
> {
> observer_attach_breakpoint_created (breakpoint_changed);
> diff --git a/gdb/annotate.h b/gdb/annotate.h
> index 72c4f19..33a9a0e 100644
> --- a/gdb/annotate.h
> +++ b/gdb/annotate.h
> @@ -98,5 +98,7 @@ extern void annotate_elt_rep_end (void);
> extern void annotate_elt (void);
> extern void annotate_array_section_end (void);
>
> +extern void annotate_linkage_name (void);
> +
Likewise.
> extern void (*deprecated_annotate_signalled_hook) (void);
> extern void (*deprecated_annotate_signal_hook) (void);
> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
> index 4d09b30..b717021 100644
> --- a/gdb/breakpoint.c
> +++ b/gdb/breakpoint.c
> @@ -5704,6 +5704,33 @@ print_breakpoint_location (struct breakpoint *b,
> ui_out_text (uiout, "in ");
> ui_out_field_string (uiout, "func",
> SYMBOL_PRINT_NAME (sym));
> + if (display_linkage_name)
> + {
> + struct bound_minimal_symbol msymbol =
> + lookup_minimal_symbol_by_pc (loc->address);
> + if (msymbol.minsym != NULL
> + && strcmp (SYMBOL_LINKAGE_NAME (msymbol.minsym),
> + SYMBOL_PRINT_NAME (sym)) != 0)
> + {
> + ui_out_text (uiout, " [");
> +
> + if (strlen (SYMBOL_LINKAGE_NAME (msymbol.minsym)) >
> + display_linkage_name_len)
Operators should never end a line -- move '>' to the beginning of the next.
> + {
> + char *lname = alloca (display_linkage_name_len + 4);
I believe we are now requiring a blank line after variable declarations.
> + strncpy (lname, SYMBOL_LINKAGE_NAME (msymbol.minsym),
> + display_linkage_name_len);
> + lname[display_linkage_name_len] = '\0';
> + strcat (lname, "...");
> + ui_out_field_string (uiout, "linkage-name", lname);
> + }
> + else
> + ui_out_field_string (uiout, "linkage-name",
> + SYMBOL_LINKAGE_NAME (msymbol.minsym));
> +
> + ui_out_text (uiout, "]");
> + }
> + }
> ui_out_text (uiout, " ");
> ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
> ui_out_text (uiout, "at ");
There's no mention of this [optional] MI parameter in the manual. There
probably should be.
> diff --git a/gdb/defs.h b/gdb/defs.h
> index 014d7d4..de5f785 100644
> --- a/gdb/defs.h
> +++ b/gdb/defs.h
> @@ -87,7 +87,7 @@
> /* The O_BINARY flag is defined in fcntl.h on some non-Posix platforms.
> It is used as an access modifier in calls to open(), where it acts
> similarly to the "b" character in fopen()'s MODE argument. On Posix
> - platforms it should be a no-op, so it is defined as 0 here. This
> + platforms it should be a no-op, so it is defined as 0 here. This
> ensures that the symbol may be used freely elsewhere in gdb. */
Superfluous whitespace change?
>
> #ifndef O_BINARY
> @@ -161,7 +161,7 @@ extern char *debug_file_directory;
> handler. Otherwise, SIGINT simply sets a flag; code that might
> take a long time, and which ought to be interruptible, checks this
> flag using the QUIT macro.
> -
> +
Likewise?
> If GDB is built with Python support, it uses Python's low-level
> interface to implement the flag. This approach makes it possible
> for Python and GDB SIGINT handling to coexist seamlessly.
> @@ -334,10 +334,11 @@ extern int print_address_symbolic (struct gdbarch *, CORE_ADDR,
>
> extern int build_address_symbolic (struct gdbarch *,
> CORE_ADDR addr,
> - int do_demangle,
> - char **name,
> - int *offset,
> - char **filename,
> + int do_demangle,
> + char **name,
> + char **linkname,
> + int *offset,
> + char **filename,
> int *line,
> int *unmapped);
More here? [I see that there is one actual change here, but it is buried
inside several unnecessary changes.]
>
> @@ -717,9 +718,9 @@ extern int (*deprecated_ui_loop_hook) (int signo);
> extern void (*deprecated_init_ui_hook) (char *argv0);
> extern void (*deprecated_command_loop_hook) (void);
> extern void (*deprecated_show_load_progress) (const char *section,
> - unsigned long section_sent,
> - unsigned long section_size,
> - unsigned long total_sent,
> + unsigned long section_sent,
> + unsigned long section_size,
> + unsigned long total_sent,
> unsigned long total_size);
More superfluous whitespace changes?
> extern void (*deprecated_print_frame_info_listing_hook) (struct symtab * s,
> int line,
> diff --git a/gdb/disasm.c b/gdb/disasm.c
> index e643c2d..62fa34d 100644
> --- a/gdb/disasm.c
> +++ b/gdb/disasm.c
> @@ -112,6 +112,7 @@ dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
> {
> char *filename = NULL;
> char *name = NULL;
> + char *linkname = NULL;
>
> QUIT;
> if (how_many >= 0)
> @@ -127,8 +128,8 @@ dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
> 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. */
> @@ -146,6 +147,7 @@ dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
> xfree (filename);
> if (name != NULL)
> xfree (name);
> + xfree (linkname);
>
> ui_file_rewind (stb);
> if (flags & DISASSEMBLY_RAW_INSN)
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index fae54e4..5d7b249 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -15933,8 +15933,31 @@ line 1574.
> @}
> (@value{GDBP})
> @end smallexample
> -@end table
>
> +@kindex set display-linkage-name @code{on}|@code{off}
> +@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.
"prefix" or "prepend"? [Yeah, that's a nit (again): I don't want to see
slang creep into the manual. Eli to have final word on the use of that
"word."]
> +
> +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.
Should that be "C@t{++}"?
> +
> +@kindex set display-linkage-name-len
> +@kindex show display-linkage-name-len
> +@cindex list linker symbol names
> +@item set display-linkage-name-len @var{len}
> +@itemx show display-linkage-name-len @var{len}
> +Set the maximum number of characters of linkage name to display. The
> +@code{show} command displays the current setting. The default is @code{20}.
> +@end table
>
> @node Altering
> @chapter Altering Execution
> diff --git a/gdb/mt-tdep.c b/gdb/mt-tdep.c
> index a863cee..22e1cbc 100644
> --- a/gdb/mt-tdep.c
> +++ b/gdb/mt-tdep.c
> @@ -718,7 +718,7 @@ mt_registers_info (struct gdbarch *gdbarch,
> print_spaces_filtered (15 - strlen (gdbarch_register_name
> (gdbarch, regnum)),
> file);
> - get_raw_print_options (&opts);
> + get_no_prettyformat_print_options (&opts);
> opts.deref_ref = 1;
> val_print (register_type (gdbarch, regnum), buf,
> 0, 0, file, 0, NULL,
This is not mentioned in the ChangeLog, and it is superfluous anyway.
I'm guessing to workaround the recent build breakage?
> diff --git a/gdb/printcmd.c b/gdb/printcmd.c
> index 99d4dba..66dc6a5 100644
> --- a/gdb/printcmd.c
> +++ b/gdb/printcmd.c
> @@ -51,6 +51,7 @@
> #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. */
> @@ -569,17 +570,19 @@ print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr,
> 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. */
s/both//
> struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name);
> make_cleanup (free_current_contents, &filename);
> + make_cleanup (free_current_contents, &linkname);
>
> - 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 +594,27 @@ print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr,
> else
> fputs_filtered ("<", stream);
> fputs_filtered (name, stream);
> +
> + /* Print linkage name after source name if requested and different. */
> + if (display_linkage_name
> + && linkname != NULL && strcmp (name, linkname) != 0)
> + {
> + fputs_filtered (" [", stream);
> +
> + if (strlen (linkname) > display_linkage_name_len)
> + {
> + char *lname = alloca (display_linkage_name_len + 4);
A blank line needed here.
> + strncpy (lname, linkname, display_linkage_name_len);
> + lname[display_linkage_name_len] = '\0';
> + strcat (lname, "...");
> + fputs_filtered (lname, stream);
> + }
> + else
> + fputs_filtered (linkname, stream);
Could you double-check the indentation of this block? It doesn't look right.
> +
> + fputs_filtered ("]", stream);
> + }
> +
> if (offset != 0)
> fprintf_filtered (stream, "+%u", (unsigned int) offset);
>
> @@ -623,6 +647,7 @@ build_address_symbolic (struct gdbarch *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 +662,9 @@ build_address_symbolic (struct gdbarch *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)
> @@ -740,6 +768,12 @@ build_address_symbolic (struct gdbarch *gdbarch,
> *line = sal.line;
> }
> }
> +
> + /* If we have both symbol names and they are different, let caller know. */
> + if (msymbol != NULL && symbol != NULL
> + && strcmp (SYMBOL_LINKAGE_NAME (msymbol), SYMBOL_LINKAGE_NAME (symbol)) != 0)
> + *linkname = xstrdup (SYMBOL_LINKAGE_NAME (msymbol));
> +
> return 0;
> }
>
> diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
> index f960b08..0b0dd8b 100644
> --- a/gdb/python/py-frame.c
> +++ b/gdb/python/py-frame.c
> @@ -123,6 +123,7 @@ frapy_name (PyObject *self, PyObject *args)
> {
> struct frame_info *frame;
> char *name = NULL;
> + const char *linkname;
> enum language lang;
> PyObject *result;
> volatile struct gdb_exception except;
> @@ -131,7 +132,7 @@ frapy_name (PyObject *self, PyObject *args)
> {
> FRAPY_REQUIRE_VALID (self, frame);
>
> - find_frame_funname (frame, &name, &lang, NULL);
> + find_frame_funname (frame, &name, &linkname, &lang, NULL);
> }
>
`linkname' is also not used here (see below).
> if (except.reason < 0)
> diff --git a/gdb/stack.c b/gdb/stack.c
> index 313d57f..67e230d 100644
> --- a/gdb/stack.c
> +++ b/gdb/stack.c
> @@ -55,6 +55,7 @@
> #include "psymtab.h"
> #include "symfile.h"
> #include "python/python.h"
> +#include "top.h"
>
> void (*deprecated_selected_frame_level_changed_hook) (int);
>
> @@ -1000,15 +1001,20 @@ get_last_displayed_sal (struct symtab_and_line *sal)
>
>
> /* Attempt to obtain the FUNNAME, FUNLANG and optionally FUNCP of the function
> - corresponding to FRAME. FUNNAME needs to be freed by the caller. */
> + corresponding to FRAME.
> + Set linkname to linkage name (symbol used by linker) if linkname is non-null
> + and linkage name differs from source name.
> + FUNNAME needs to be freed by the caller. */
You want to use linkname here in caps, since it is the value of
`linkname' that is being referred to (just as for FUNNAME, FUNLANG, FUNCP).
>
> void
> find_frame_funname (struct frame_info *frame, 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;
It seems that a lot of callers of find_frame_funname don't actually
use/care about LINKNAME. Why not treat it like FUNCP and make it
optional, allowing callers to explicitly pass NULL for this (optional)
parameter? What do you think?
> @@ -1045,6 +1051,11 @@ find_frame_funname (struct frame_info *frame, char **funname,
> memset (&msymbol, 0, sizeof (msymbol));
>
> if (msymbol.minsym != NULL
> + && strcmp (SYMBOL_LINKAGE_NAME (msymbol.minsym),
> + SYMBOL_LINKAGE_NAME (func)) != 0)
> + *linkname = SYMBOL_LINKAGE_NAME (msymbol.minsym);
> +
> + if (msymbol.minsym != NULL
> && (SYMBOL_VALUE_ADDRESS (msymbol.minsym)
> > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
> {
> @@ -1102,6 +1113,7 @@ print_frame (struct frame_info *frame, int print_level,
> struct gdbarch *gdbarch = get_frame_arch (frame);
> struct ui_out *uiout = current_uiout;
> char *funname = NULL;
> + const char *linkname = NULL;
> enum language funlang = language_unknown;
> struct ui_file *stb;
> struct cleanup *old_chain, *list_chain;
> @@ -1115,7 +1127,7 @@ print_frame (struct frame_info *frame, int print_level,
> 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);
> make_cleanup (xfree, funname);
>
> annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
> @@ -1147,9 +1159,32 @@ print_frame (struct frame_info *frame, int print_level,
> fprintf_symbol_filtered (stb, funname ? funname : "??",
> funlang, DMGL_ANSI);
> ui_out_field_stream (uiout, "func", stb);
> +
> + /* Print linkage name after source name if requested and different. */
> + if ((display_linkage_name || ui_out_is_mi_like_p (uiout))
> + && linkname != NULL && strcmp (funname, linkname) != 0)
> + {
> + annotate_linkage_name ();
> + ui_out_text (uiout, " [");
> +
> + if (strlen (linkname) > display_linkage_name_len)
> + {
> + char *lname = alloca (display_linkage_name_len + 4);
A blank line is needed here.
> + strncpy (lname, linkname, display_linkage_name_len);
> + lname[display_linkage_name_len] = '\0';
> + strcat (lname, "...");
> + ui_out_text (uiout, lname);
> + }
> + else
> + ui_out_text (uiout, linkname);
> +
> + ui_out_text (uiout, "]");
> + ui_out_field_stream (uiout, "linkage_name", stb);
> + }
> +
> ui_out_wrap_hint (uiout, " ");
> annotate_frame_args ();
> -
> +
Unnecessary whitespace change?
> ui_out_text (uiout, " (");
> if (print_args)
> {
> diff --git a/gdb/stack.h b/gdb/stack.h
> index 4badf19..9248c85 100644
> --- a/gdb/stack.h
> +++ b/gdb/stack.h
> @@ -23,7 +23,8 @@
> void select_frame_command (char *level_exp, int from_tty);
>
> void find_frame_funname (struct frame_info *frame, 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,
> diff --git a/gdb/testsuite/gdb.cp/display-linkage-name.cc b/gdb/testsuite/gdb.cp/display-linkage-name.cc
> new file mode 100644
> index 0000000..93b2ba2
> --- /dev/null
> +++ b/gdb/testsuite/gdb.cp/display-linkage-name.cc
> @@ -0,0 +1,19 @@
You should probably add a copyright header to this file. It might be
optional (one of the maintainers to verify), but IMO better safe than
sorry. FWIW, I *always* add a copyright header to any new file I commit.
> +void foo (const char *msg)
> +{
> +} /* set breakpoint 1 here */
> +
> +void fun_with_a_long_name (int i, const char *s, double d)
> +{
> + foo ("Hello"); /* set breakpoint 2 here */
> +}
> +
> +void goo (void)
> +{
> + fun_with_a_long_name (1, "abc", 3.14);
> +}
> +
> +int main (void)
> +{
> + goo();
> + return 0;
> +}
> diff --git a/gdb/testsuite/gdb.cp/display-linkage-name.exp b/gdb/testsuite/gdb.cp/display-linkage-name.exp
> new file mode 100644
> index 0000000..aa077c4
> --- /dev/null
> +++ b/gdb/testsuite/gdb.cp/display-linkage-name.exp
> @@ -0,0 +1,153 @@
> +# Copyright 2013 Free Software Foundation, Inc.
> +
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +
> +# This file was written by Michael Eager (eager@eagercon.com).
I guess some are now discouraging adding any attribution, but I don't
necessarily agree with that. Just a preemptive warning that another
maintainer might ask you to remove this. [But *I* am not. :-)]
> +
> +if { [skip_cplus_tests] } { continue }
> +
> +standard_testfile .cc
> +
> +if [get_compiler_info "c++"] {
[My personal nit] Please add '{'/'}' around all expressions. [I realize
you probably just cut-n-paste much of this like many of us do...]
> + return -1
> +}
> +
> +if { [prepare_for_testing display-linkage-name.exp display-linkage-name display-linkage-name.cc {debug c++}] } {
Eek. That's a really long line. While I don't think we have any hard
rules about wrapping in the test suite, could you split this up a bit?
[You can insert '\' somewhere in that.]
Actually, I think you can shorten this using the globals set by
standard_testfile:
if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}} {
... }
> + return -1
> +}
> +set srcfile display-linkage-name.cc
This should not be necessary -- standard_testfile should set that for you.
> +
> +set bp1 [gdb_get_line_number "set breakpoint 1 here"]
> +set bp2 [gdb_get_line_number "set breakpoint 2 here"]
> +
> +#
> +# test display-linkage-name commands.
> +#
> +
> +gdb_test "set display-linkage-name off" ""
You can use gdb_test_no_output to do this.
> +
> +#
> +# set break at functions
> +#
> +gdb_test "break foo" \
> + "Breakpoint.*at.* file .*$srcfile, line $bp1.*" \
> + "breakpoint function"
> +
> +gdb_test "break fun_with_a_long_name" \
> + "Breakpoint.*at.* file .*$srcfile, line $bp2.*" \
> + "breakpoint function"
You can use the convenience function gdb_breakpoint to set these
breakpoints. These two tests also have the same name; they should be
different.
> +
> +gdb_test "info break" \
> + "Num Type\[ \]+Disp Enb Address\[\t \]+What.*
> +1\[\t \]+breakpoint keep y.* in foo(.*) at .*$srcfile:$bp1.*
> +2\[\t \]+breakpoint keep y.* in fun_with_a_long_name(.*) at .*$srcfile:$bp2.*" \
> + "info breakpoint - display off"
> +
> +gdb_run_cmd
> +gdb_expect {
> + -re "Breakpoint 2, fun_with_a_long_name (.*) at .*$srcfile:$bp2.*$gdb_prompt $" {
> + pass "run until breakpoint - display off"
> + }
> + -re "$gdb_prompt $" {
> + fail "run until breakpoint - display off"
> + }
> + timeout {
> + fail "run until breakpoint - display off (timeout)"
> + }
> +}
> +
> +gdb_test continue "Continuing\\..*Breakpoint 1, foo (.*) at .*$srcfile:$bp1.*\[\t \]+\\}.*" \
> + "continue until function breakpoint - display off"
> +
You can replace most of this with a call (or two) to
gdb_continue_to_breakpoint. [And you would want gdb_test_multiple
instead of gdb_expect here anyway.]
> +set bttable "#0 foo (.*) at.*\[\r\n\]"
> +append bttable "#1 \[0-9a-fx\]+ in fun_with_a_long_name (.*) at .*$srcfile:.*\[\r\n\]"
> +append bttable "#2 \[0-9a-fx\]+ in goo (.*) at .*$srcfile:.*\[\r\n\]"
> +append bttable "#3 \[0-9a-fx\]+ in main (.*) at .*$srcfile:.*"
We have the global "hex" that you can use.
> +
> +gdb_test "backtrace" $bttable "backtrace - display off"
> +
> +########################
> +# Test with display-linkage-name on
> +
> +gdb_test "set display-linkage-name on" ""
> +
> +gdb_test "info break" \
> + "Num Type\[ \]+Disp Enb Address\[\t \]+What.*
> +1\[\t \]+breakpoint keep y.* in foo(.*) \\\[_Z3fooPKc\\\] at .*$srcfile:$bp1.*
> +2\[\t \]+breakpoint keep y.* in fun_with_a_long_name(.*) \\\[_Z20fun_with_a_long_\.\.\.\\\] at .*$srcfile:$bp2.*" \
> + "info breakpoint - display on"
> +
> +gdb_run_cmd
> +gdb_expect {
> + -re "Breakpoint 2, fun_with_a_long_name \\\[_Z20fun_with_a_long_\.\.\.\\\] (.*) at .*$srcfile:$bp2.*$gdb_prompt $" {
> + pass "run until function breakpoint - display on"
> + }
> + -re "$gdb_prompt $" {
> + fail "run until function breakpoint - display on"
> + }
> + timeout {
> + fail "run until function breakpoint (timeout) - display on"
> + }
> +}
> +
> +gdb_test continue "Continuing\\..*Breakpoint 1, foo \\\[_Z3fooPKc\\\] (.*) at .*$srcfile:$bp1.*\[\t \]+\\}.*" \
> + "continue until function breakpoint - display on"
> +
Same here with gdb_continue_to_breakpoint.
> +set bttable "#0 foo \\\[_Z3fooPKc\\\] (.*) at.*\[\r\n\]"
> +append bttable "#1 \[0-9a-fx\]+ in fun_with_a_long_name \\\[_Z20fun_with_a_long_\.\.\.\\\] (.*) at .*$srcfile:.*\[\r\n\]"
> +append bttable "#2 \[0-9a-fx\]+ in goo \\\[_Z3goov\\\] (.*) at .*$srcfile:.*\[\r\n\]"
> +append bttable "#3 \[0-9a-fx\]+ in main (.*) at .*$srcfile:.*"
> +
and $hex.
> +gdb_test "backtrace" $bttable "backtrace - display on"
> +
In fact, all these tests are so similar, you could probably stick all
this in a proc and run it multiple times:
proc test_expected_frame {with_linkage_name} {
# ...
set bttable ...
if {$with_linkage_name} {
set linkage_name "\\\[_Z20fun_with_a_long\.\.\.\\\]"
} else {
set linkage_name ""
}
append bttable "#1 $hex+ in fun_with_a_long_name $linkage_name (.*) ..."
# ...
if {$with_linkage_name} {
set with "on"
} else {
set with "off"
}
gdb_test "backtrace" $bttable "backtrace - display $with"
}
Then:
test_expected_frame 0
gdb_test_no_output "set display_linkage_name on"
test_expected_frame 1
You can probably also fold in the remaining test, too:
> +########################
> +# Test set/show display-linkage-name-len
> +
> +gdb_test "show display-linkage-name-len" \
> + "Length of linkage name \\(symbol used by linker\\) to be displayed is 20."
> +
> +gdb_test "set display-linkage-name-len 10" ""
> +
> +gdb_test "show display-linkage-name-len" \
> + "Length of linkage name \\(symbol used by linker\\) to be displayed is 10."
> +
> +gdb_test "info break" \
> + "Num Type\[ \]+Disp Enb Address\[\t \]+What.*
> +1\[\t \]+breakpoint keep y.* in foo(.*) \\\[_Z3fooPKc\\\] at .*$srcfile:$bp1.*
> +2\[\t \]+breakpoint keep y.* in fun_with_a_long_name(.*) \\\[_Z20fun_wi\.\.\.\\\] at .*$srcfile:$bp2.*" \
> + "info breakpoint - display 10"
> +
> +gdb_run_cmd
> +gdb_expect {
> + -re "Breakpoint 2, fun_with_a_long_name \\\[_Z20fun_wi\.\.\.\\\] (.*) at .*$srcfile:$bp2.*$gdb_prompt $" {
> + pass "run until function breakpoint - display 10"
> + }
> + -re "$gdb_prompt $" {
> + fail "run until function breakpoint - display 10"
> + }
> + timeout {
> + fail "run until function breakpoint (timeout) - display 10"
> + }
> +}
> +
> +gdb_test continue "Continuing\\..*Breakpoint 1, foo \\\[_Z3fooPKc\\\] (.*) at .*$srcfile:$bp1.*\[\t \]+\\}.*" \
> + "continue until function breakpoint - display 10"
> +
> +set bttable "#0 foo \\\[_Z3fooPKc\\\] (.*) at.*\[\r\n\]"
> +append bttable "#1 \[0-9a-fx\]+ in fun_with_a_long_name \\\[_Z20fun_wi\.\.\.\\\] (.*) at .*$srcfile:.*\[\r\n\]"
> +append bttable "#2 \[0-9a-fx\]+ in goo \\\[_Z3goov\\\] (.*) at .*$srcfile:.*\[\r\n\]"
> +append bttable "#3 \[0-9a-fx\]+ in main (.*) at .*$srcfile:.*"
> +
> +gdb_test "backtrace" $bttable "backtrace - display 10"
by adding another parameter for the length of the linkage name to the
proc. [The tcl command "string range" will be useful to automate this.]
But this is starting to get a little elaborate (and I suspect beyond
your familiarity with Tcl/expect). So if you can't do it, don't sweat
it; I'm not going to stop this patch from going in because of test suite
minutia like this. I'm happy to see someone so thorough with testing!
> +
> diff --git a/gdb/top.c b/gdb/top.c
> index 46faaa7..e9476ab 100644
> --- a/gdb/top.c
> +++ b/gdb/top.c
> @@ -287,6 +287,29 @@ quit_cover (void)
> quit_command ((char *) 0, 0);
> }
> #endif /* defined SIGHUP */
> +
> +/* Flag for whether we want to print linkage name for functions.
> + Length of linkage name to print. */
> +
> +int display_linkage_name = 1; /* Default is yes. */
> +int display_linkage_name_len = 20; /* Default is first 20 chars. */
NEWS and gdb.texinfo say the default is "no". [Keeping it on by default
also causes 250+ test regressions!]
> +
> +static void
> +show_display_linkage_name (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);
Not all functions have the same linkage name, so it should be "Whether
to display linkage names for functions". Do we really need to explain
what a linkage name is here? I don't think so, but perhaps others will
disagree. Also, I believe it is more correct to use "of" instead of
"for," the linkage names of functions.
> +}
> +static void
> +show_display_linkage_name_len (struct ui_file *file, int from_tty,
> + struct cmd_list_element *c, const char *value)
> +{
> + fprintf_filtered (file, _("\
> +Length of linkage name (symbol used by linker) to be displayed is %s.\n"),
> + value);
> +}
"names"
> \f
> /* 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
> @@ -1809,7 +1832,22 @@ Use \"on\" to enable the notification, and \"off\" to disable it."),
> When set, GDB uses the specified path to search for data files."),
> set_gdb_datadir, NULL,
> &setlist,
> - &showlist);
> + &showlist);
> +
> + add_setshow_boolean_cmd ("display-linkage-name", class_support, &display_linkage_name, _("\
> +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_display_linkage_name,
> + &setlist, &showlist);
"names"/"of"
> +
> + add_setshow_zinteger_cmd ("display-linkage-name-len", class_support, &display_linkage_name_len, _("\
> +Set number of characters of linkage name to display."), _("\
> +Show number of characters of linkage name to display."), NULL,
"names". Missing "the": Set/Show the number of characters...
> + NULL,
> + show_display_linkage_name_len,
> + &setlist, &showlist);
> +
> }
>
> void
> diff --git a/gdb/top.h b/gdb/top.h
> index 2f70539..5acb311 100644
> --- a/gdb/top.h
> +++ b/gdb/top.h
> @@ -26,6 +26,8 @@ extern int saved_command_line_size;
> extern FILE *instream;
> extern int in_user_command;
> extern int confirm;
> +extern int display_linkage_name;
> +extern int display_linkage_name_len;
> extern char gdb_dirbuf[1024];
> extern int inhibit_gdbinit;
> extern const char gdbinit[];
Keith
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Revised display-linkage-name
2013-07-11 23:28 ` Keith Seitz
@ 2013-07-12 21:17 ` Michael Eager
2013-07-17 18:51 ` Michael Eager
0 siblings, 1 reply; 19+ messages in thread
From: Michael Eager @ 2013-07-12 21:17 UTC (permalink / raw)
To: Keith Seitz; +Cc: gdb-patches
On 07/11/13 16:28, Keith Seitz wrote:
> On 07/10/2013 09:17 AM, Michael Eager wrote:
>> Can someone review and approve this patch?
>
> Tom's been a little busy of late, so I thought I would try to help out here a little. You'll be one
> step closer to approval!
>
> Your patches no longer apply cleanly to HEAD, so I fixed them up to play with them. I'll be
> commenting on this version.
>
...
> Keith
Thanks. I'll look at your comments and submit an update.
I'll eliminate the whitespace changes; I find them annoying as well.
I'll allow passing a NULL for the linkname where the result is
not used. I'm not sure how the default got set to "on"; that was
not intentional, and yes, it causes a lot of noise regressions.
"Prepend" appears to be listed in some dictionaries as a synonym
for "prefix," but it may sound like jargon; I'll change it.
I'll look at the suggestions about the test suite. I've reasonable
experience with tcl/expect, but tcl always seems to turn into a tar pit.
If you have a different term for "linkage name" I'd be happy to
hear it. The only use of this that I was able to find is in the
DWARF Standard. Or I can add a definition to the docs to clarify.
--
Michael Eager eager@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306 650-325-8077
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Revised display-linkage-name
2013-07-12 21:17 ` Michael Eager
@ 2013-07-17 18:51 ` Michael Eager
2013-07-17 19:14 ` Eli Zaretskii
2013-07-22 17:48 ` Keith Seitz
0 siblings, 2 replies; 19+ messages in thread
From: Michael Eager @ 2013-07-17 18:51 UTC (permalink / raw)
To: Keith Seitz; +Cc: gdb-patches, Eli Zaretskii, Tom Tromey
[-- Attachment #1: Type: text/plain, Size: 3034 bytes --]
On 07/12/13 14:17, Michael Eager wrote:
> On 07/11/13 16:28, Keith Seitz wrote:
>> On 07/10/2013 09:17 AM, Michael Eager wrote:
>>> Can someone review and approve this patch?
>>
>> Tom's been a little busy of late, so I thought I would try to help out here a little. You'll be one
>> step closer to approval!
>>
>> Your patches no longer apply cleanly to HEAD, so I fixed them up to play with them. I'll be
>> commenting on this version.
>>
>
> ...
>
>> Keith
>
> Thanks. I'll look at your comments and submit an update.
>
> I'll eliminate the whitespace changes; I find them annoying as well.
> I'll allow passing a NULL for the linkname where the result is
> not used. I'm not sure how the default got set to "on"; that was
> not intentional, and yes, it causes a lot of noise regressions.
> "Prepend" appears to be listed in some dictionaries as a synonym
> for "prefix," but it may sound like jargon; I'll change it.
>
> I'll look at the suggestions about the test suite. I've reasonable
> experience with tcl/expect, but tcl always seems to turn into a tar pit.
>
> If you have a different term for "linkage name" I'd be happy to
> hear it. The only use of this that I was able to find is in the
> DWARF Standard. Or I can add a definition to the docs to clarify.
I believe I have addressed your comments, as well as Eli's previous
notes about the docs. I didn't merge the tests cases into a single proc.
BTW, "prepend" appears in several places in the docs. I replaced it this
patch with prefix. If there is a concern that "prepend" sounds like jargon,
then the other uses should be changed as well.
gdb/
2013-07-17 Michael Eager <eager@eagercon.com>
* NEWS: Announcement.
* ada-lang.c: Update calls to find_frame_funname (pass NULL for linkname).
* disasm.c: Likewise.
* python/py-frame.c: Likewise.
* annotate.c (annotate_linkage_name): New.
* annotate.h (annotate_linkage_name): New decl.
* breakpoint.c (print_breakpoint_location): Print linkage name.
* defs.h (build_address_symbolic): Add linkname arg.
* printcmd.c (print_address_symbolic): Print linkage name.
(build_address_symbolic): Return linkage name.
* annotate.c (annotate_linkage_name): New.
* annotate.h (annotate_linkage_name): Declare.
* stack.c (find_frame_funname): Return linkage name.
(print_frame): Print linkage name.
* stack.h (find_frame_funname): Update declaration.
* top.c (display_linkage_name, display_linkage_name_len): New.
(show_display_linkage_name, show_display_linkage_name_len): New cmds.
* top.h (display_linkage_name, display_linkage_name_len): Declare.
gdb/doc
2013-07-17 Michael Eager <eager@eagercon.com>
* gdb.texinfo: Add description.
gdb/testsuite
2013-07-17 Michael Eager <eager@eagercon.com>
* gdb.cp/display-linkage-name.exp: New.
* gdb.cp/display-linkage-name.cc: New.
--
Michael Eager eager@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306 650-325-8077
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-GDB-display-linkage-name-command.patch --]
[-- Type: text/x-patch; name="0001-GDB-display-linkage-name-command.patch", Size: 24516 bytes --]
From bc509670f21f11aee21084aba60b58dd46391435 Mon Sep 17 00:00:00 2001
From: Michael Eager <eager@eagercon.com>
Date: Wed, 17 Jul 2013 11:37:04 -0700
Subject: [PATCH] GDB - display linkage name command
---
gdb/NEWS | 14 +++
gdb/ada-lang.c | 5 +-
gdb/annotate.c | 7 ++
gdb/annotate.h | 2 +
gdb/breakpoint.c | 28 ++++++
gdb/defs.h | 1 +
gdb/disasm.c | 4 +-
gdb/doc/gdb.texinfo | 28 +++++-
gdb/printcmd.c | 43 ++++++++-
gdb/python/py-frame.c | 2 +-
gdb/stack.c | 44 ++++++++-
gdb/stack.h | 3 +-
gdb/testsuite/gdb.cp/display-linkage-name.cc | 36 +++++++
gdb/testsuite/gdb.cp/display-linkage-name.exp | 129 ++++++++++++++++++++++++++
gdb/top.c | 40 +++++++-
gdb/top.h | 2 +
16 files changed, 373 insertions(+), 15 deletions(-)
create mode 100644 gdb/testsuite/gdb.cp/display-linkage-name.cc
create mode 100644 gdb/testsuite/gdb.cp/display-linkage-name.exp
diff --git a/gdb/NEWS b/gdb/NEWS
index e469f1e..ac62062 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -56,6 +56,20 @@ show range-stepping
--configuration
Display the details of GDB configure-time options.
+* 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
+ prefixes 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.
+
+set|show display-linkage-name-len
+
+ Set the maximum number of characters to display in the linkage name,
+ if display-linkage-name is on. The default is 20.
+
* The command 'tsave' can now support new option '-ctf' to save trace
buffer in Common Trace Format.
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index dc5f2b6..3430e3f 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -11114,6 +11114,7 @@ is_known_support_routine (struct frame_info *frame)
{
struct symtab_and_line sal;
char *func_name;
+ const char *linkname;
enum language func_lang;
int i;
const char *fullname;
@@ -11152,7 +11153,7 @@ is_known_support_routine (struct frame_info *frame)
/* Check whether the function is a GNAT-generated entity. */
- find_frame_funname (frame, &func_name, &func_lang, NULL);
+ find_frame_funname (frame, &func_name, NULL, &func_lang, NULL);
if (func_name == NULL)
return 1;
@@ -11227,7 +11228,7 @@ ada_unhandled_exception_name_addr_from_raise (void)
char *func_name;
enum language func_lang;
- find_frame_funname (fi, &func_name, &func_lang, NULL);
+ find_frame_funname (fi, &func_name, NULL, &func_lang, NULL);
if (func_name != NULL)
{
make_cleanup (xfree, func_name);
diff --git a/gdb/annotate.c b/gdb/annotate.c
index ccba5fe..84edeac 100644
--- a/gdb/annotate.c
+++ b/gdb/annotate.c
@@ -582,6 +582,13 @@ breakpoint_changed (struct breakpoint *b)
}
void
+annotate_linkage_name (void)
+{
+ if (annotation_level == 2)
+ printf_filtered (("\n\032\032linkage_name\n"));
+}
+
+void
_initialize_annotate (void)
{
observer_attach_breakpoint_created (breakpoint_changed);
diff --git a/gdb/annotate.h b/gdb/annotate.h
index 72c4f19..33a9a0e 100644
--- a/gdb/annotate.h
+++ b/gdb/annotate.h
@@ -98,5 +98,7 @@ extern void annotate_elt_rep_end (void);
extern void annotate_elt (void);
extern void annotate_array_section_end (void);
+extern void annotate_linkage_name (void);
+
extern void (*deprecated_annotate_signalled_hook) (void);
extern void (*deprecated_annotate_signal_hook) (void);
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 4d09b30..e40af59 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -5704,6 +5704,34 @@ print_breakpoint_location (struct breakpoint *b,
ui_out_text (uiout, "in ");
ui_out_field_string (uiout, "func",
SYMBOL_PRINT_NAME (sym));
+ if (display_linkage_name)
+ {
+ struct bound_minimal_symbol msymbol =
+ lookup_minimal_symbol_by_pc (loc->address);
+ if (msymbol.minsym != NULL
+ && strcmp (SYMBOL_LINKAGE_NAME (msymbol.minsym),
+ SYMBOL_PRINT_NAME (sym)) != 0)
+ {
+ ui_out_text (uiout, " [");
+
+ if (strlen (SYMBOL_LINKAGE_NAME (msymbol.minsym))
+ > display_linkage_name_len)
+ {
+ char *lname = alloca (display_linkage_name_len + 4);
+
+ strncpy (lname, SYMBOL_LINKAGE_NAME (msymbol.minsym),
+ display_linkage_name_len);
+ lname[display_linkage_name_len] = '\0';
+ strcat (lname, "...");
+ ui_out_field_string (uiout, "linkage-name", lname);
+ }
+ else
+ ui_out_field_string (uiout, "linkage-name",
+ SYMBOL_LINKAGE_NAME (msymbol.minsym));
+
+ ui_out_text (uiout, "]");
+ }
+ }
ui_out_text (uiout, " ");
ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
ui_out_text (uiout, "at ");
diff --git a/gdb/defs.h b/gdb/defs.h
index 014d7d4..0d10a0d 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -336,6 +336,7 @@ extern int build_address_symbolic (struct gdbarch *,
CORE_ADDR addr,
int do_demangle,
char **name,
+ char **linkname,
int *offset,
char **filename,
int *line,
diff --git a/gdb/disasm.c b/gdb/disasm.c
index e643c2d..396dce9 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -127,8 +127,8 @@ dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
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, NULL, &offset,
+ &filename, &line, &unmapped))
{
/* We don't care now about line, filename and
unmapped. But we might in the future. */
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index fae54e4..4f48c4c 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -15933,8 +15933,31 @@ line 1574.
@}
(@value{GDBP})
@end smallexample
-@end table
+@kindex set display-linkage-name
+@cindex list linkage 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 linkage name for the symbol name within brackets if it is
+different from the name in the source.
+
+The linkage name is the name used by the linker for a symbol. This may be
+the same as the symbol's name in the source, or may be different if the compiler
+adds a prefix to the name (for example, an underscore) or modifies it, such
+as by C@t{++} name mangling.
+
+This is different from "set print asm-demangle on" which only displays
+the linkage name for C@t{++} symbols and does not display the source name.
+
+@kindex show display-linkage-name-len
+@itemx show display-linkage-name-len @var{len}
+Set the maximum number of characters of linkage name to display. The
+@code{show} command displays the current setting. The default is @code{20}.
+@end table
@node Altering
@chapter Altering Execution
@@ -29250,6 +29273,9 @@ is not.
@item what
Some extra data, the exact contents of which are type-dependent.
+@item linkage-name
+The name used by the linker for this function.
+
@end table
For example, here is what the output of @code{-break-insert}
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 99d4dba..e3b8c21 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -51,6 +51,7 @@
#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. */
@@ -569,17 +570,19 @@ print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr,
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 name, linkname, and filename. */
struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name);
make_cleanup (free_current_contents, &filename);
+ make_cleanup (free_current_contents, &linkname);
- 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 +594,28 @@ print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr,
else
fputs_filtered ("<", stream);
fputs_filtered (name, stream);
+
+ /* Print linkage name after source name if requested and different. */
+ if (display_linkage_name
+ && linkname != NULL && strcmp (name, linkname) != 0)
+ {
+ fputs_filtered (" [", stream);
+
+ if (strlen (linkname) > display_linkage_name_len)
+ {
+ char *lname = alloca (display_linkage_name_len + 4);
+
+ strncpy (lname, linkname, display_linkage_name_len);
+ lname[display_linkage_name_len] = '\0';
+ strcat (lname, "...");
+ fputs_filtered (lname, stream);
+ }
+ else
+ fputs_filtered (linkname, stream);
+
+ fputs_filtered ("]", stream);
+ }
+
if (offset != 0)
fprintf_filtered (stream, "+%u", (unsigned int) offset);
@@ -623,6 +648,7 @@ build_address_symbolic (struct gdbarch *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 +663,10 @@ build_address_symbolic (struct gdbarch *gdbarch,
/* Let's say it is mapped (not unmapped). */
*unmapped = 0;
+ /* Let's say the link name is the same as the symbol name. */
+ if (linkname)
+ *linkname = 0;
+
/* Determine if the address is in an overlay, and whether it is
mapped. */
if (overlay_debugging)
@@ -740,6 +770,13 @@ build_address_symbolic (struct gdbarch *gdbarch,
*line = sal.line;
}
}
+
+ /* If we have both symbol names and they are different, let caller know. */
+ if (msymbol != NULL && symbol != NULL
+ && strcmp (SYMBOL_LINKAGE_NAME (msymbol), SYMBOL_LINKAGE_NAME (symbol)) != 0)
+ if (linkname)
+ *linkname = xstrdup (SYMBOL_LINKAGE_NAME (msymbol));
+
return 0;
}
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index f960b08..6b48140 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -131,7 +131,7 @@ frapy_name (PyObject *self, PyObject *args)
{
FRAPY_REQUIRE_VALID (self, frame);
- find_frame_funname (frame, &name, &lang, NULL);
+ find_frame_funname (frame, &name, NULL, &lang, NULL);
}
if (except.reason < 0)
diff --git a/gdb/stack.c b/gdb/stack.c
index 313d57f..4bc8824 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -55,6 +55,7 @@
#include "psymtab.h"
#include "symfile.h"
#include "python/python.h"
+#include "top.h"
void (*deprecated_selected_frame_level_changed_hook) (int);
@@ -1000,15 +1001,19 @@ get_last_displayed_sal (struct symtab_and_line *sal)
/* Attempt to obtain the FUNNAME, FUNLANG and optionally FUNCP of the function
- corresponding to FRAME. FUNNAME needs to be freed by the caller. */
+ corresponding to FRAME. FUNNAME needs to be freed by the caller.
+ Set LINKNAME to linkage name (symbol used by linker) if LINKNAME is non-null
+ and linkage name differs from source name. */
void
find_frame_funname (struct frame_info *frame, 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 +1050,12 @@ find_frame_funname (struct frame_info *frame, char **funname,
memset (&msymbol, 0, sizeof (msymbol));
if (msymbol.minsym != NULL
+ && strcmp (SYMBOL_LINKAGE_NAME (msymbol.minsym),
+ SYMBOL_LINKAGE_NAME (func)) != 0)
+ if (linkname)
+ *linkname = SYMBOL_LINKAGE_NAME (msymbol.minsym);
+
+ if (msymbol.minsym != NULL
&& (SYMBOL_VALUE_ADDRESS (msymbol.minsym)
> BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
{
@@ -1102,6 +1113,7 @@ print_frame (struct frame_info *frame, int print_level,
struct gdbarch *gdbarch = get_frame_arch (frame);
struct ui_out *uiout = current_uiout;
char *funname = NULL;
+ const char *linkname = NULL;
enum language funlang = language_unknown;
struct ui_file *stb;
struct cleanup *old_chain, *list_chain;
@@ -1115,7 +1127,7 @@ print_frame (struct frame_info *frame, int print_level,
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);
make_cleanup (xfree, funname);
annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
@@ -1147,9 +1159,33 @@ print_frame (struct frame_info *frame, int print_level,
fprintf_symbol_filtered (stb, funname ? funname : "??",
funlang, DMGL_ANSI);
ui_out_field_stream (uiout, "func", stb);
+
+ /* Print linkage name after source name if requested and different. */
+ if ((display_linkage_name || ui_out_is_mi_like_p (uiout))
+ && linkname != NULL && strcmp (funname, linkname) != 0)
+ {
+ annotate_linkage_name ();
+ ui_out_text (uiout, " [");
+
+ if (strlen (linkname) > display_linkage_name_len)
+ {
+ char *lname = alloca (display_linkage_name_len + 4);
+
+ strncpy (lname, linkname, display_linkage_name_len);
+ lname[display_linkage_name_len] = '\0';
+ strcat (lname, "...");
+ ui_out_text (uiout, lname);
+ }
+ else
+ ui_out_text (uiout, linkname);
+
+ ui_out_text (uiout, "]");
+ ui_out_field_stream (uiout, "linkage_name", stb);
+ }
+
ui_out_wrap_hint (uiout, " ");
annotate_frame_args ();
-
+
ui_out_text (uiout, " (");
if (print_args)
{
diff --git a/gdb/stack.h b/gdb/stack.h
index 4badf19..9248c85 100644
--- a/gdb/stack.h
+++ b/gdb/stack.h
@@ -23,7 +23,8 @@
void select_frame_command (char *level_exp, int from_tty);
void find_frame_funname (struct frame_info *frame, 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,
diff --git a/gdb/testsuite/gdb.cp/display-linkage-name.cc b/gdb/testsuite/gdb.cp/display-linkage-name.cc
new file mode 100644
index 0000000..d9db673
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/display-linkage-name.cc
@@ -0,0 +1,36 @@
+/* This test script is part of GDB, the GNU debugger.
+
+ Copyright 2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+void foo (const char *msg)
+{
+} /* set breakpoint 1 here */
+
+void fun_with_a_long_name (int i, const char *s, double d)
+{
+ foo ("Hello"); /* set breakpoint 2 here */
+}
+
+void goo (void)
+{
+ fun_with_a_long_name (1, "abc", 3.14);
+}
+
+int main (void)
+{
+ goo();
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.cp/display-linkage-name.exp b/gdb/testsuite/gdb.cp/display-linkage-name.exp
new file mode 100644
index 0000000..6cde8af
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/display-linkage-name.exp
@@ -0,0 +1,129 @@
+# Copyright 2013 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This file was written by Michael Eager (eager@eagercon.com).
+
+if { [skip_cplus_tests] } { continue }
+
+standard_testfile .cc
+
+if {[get_compiler_info "c++"]} {
+ return -1
+}
+
+if { [prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}] } {
+ return -1
+}
+
+# set break at functions
+
+set bp1 [gdb_get_line_number "set breakpoint 1 here"]
+set bp2 [gdb_get_line_number "set breakpoint 2 here"]
+
+if {![gdb_breakpoint "foo"]} {
+ fail "set breakpoint foo"
+}
+
+if {![gdb_breakpoint "fun_with_a_long_name"]} {
+ fail "set breakpoint fun_with_a_long_name"
+}
+
+########################
+# Test with display-linkage-name off
+
+gdb_test_no_output "set display-linkage-name off" ""
+
+gdb_test "info break" \
+ "Num Type\[ \]+Disp Enb Address\[\t \]+What.*
+1\[\t \]+breakpoint keep y.* in foo(.*) at .*$srcfile:$bp1.*
+2\[\t \]+breakpoint keep y.* in fun_with_a_long_name(.*) at .*$srcfile:$bp2.*" \
+ "info breakpoint - display off"
+
+gdb_run_cmd
+set test "break at fun_with_a_long_name"
+gdb_test_multiple "continue" $test {
+ -re "Breakpoint 2, fun_with_a_long_name (.*) at.*$srcfile.$bp2.*$gdb_prompt $" {
+ pass $test
+ break
+ }
+}
+
+set bttable "#0 foo (.*) at.*\[\r\n\]"
+append bttable "#1 $hex in fun_with_a_long_name (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#2 $hex in goo (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#3 $hex in main (.*) at .*$srcfile:.*"
+
+gdb_test "backtrace" $bttable "backtrace - display off"
+
+########################
+# Test with display-linkage-name on
+
+gdb_test_no_output "set display-linkage-name on" ""
+
+gdb_test "info break" \
+ "Num Type\[ \]+Disp Enb Address\[\t \]+What.*
+1\[\t \]+breakpoint keep y.* in foo(.*) \\\[_Z3fooPKc\\\] at .*$srcfile:$bp1.*
+2\[\t \]+breakpoint keep y.* in fun_with_a_long_name(.*) \\\[_Z20fun_with_a_long_\.\.\.\\\] at .*$srcfile:$bp2.*" \
+ "info breakpoint - display on"
+
+gdb_run_cmd
+set test "break at fun_with_a_long_name - display on"
+gdb_test_multiple "continue" $test {
+ -re "Breakpoint 2, fun_with_a_long_name \\\[_Z20fun_with_a_long_...\\\] (.*) at.*$srcfile.$bp2.*$gdb_prompt $" {
+ pass $test
+ break
+ }
+}
+
+set bttable "#0 foo \\\[_Z3fooPKc\\\] (.*) at.*\[\r\n\]"
+append bttable "#1 $hex in fun_with_a_long_name \\\[_Z20fun_with_a_long_\.\.\.\\\] (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#2 $hex in goo \\\[_Z3goov\\\] (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#3 $hex in main (.*) at .*$srcfile:.*"
+
+gdb_test "backtrace" $bttable "backtrace - display on"
+
+########################
+# Test set/show display-linkage-name-len
+
+gdb_test "show display-linkage-name-len" \
+ "Length of linkage names \\(symbol used by linker\\) to be displayed is 20."
+
+gdb_test_no_output "set display-linkage-name-len 10" ""
+
+gdb_test "show display-linkage-name-len" \
+ "Length of linkage names \\(symbol used by linker\\) to be displayed is 10."
+
+gdb_test "info break" \
+ "Num Type\[ \]+Disp Enb Address\[\t \]+What.*
+1\[\t \]+breakpoint keep y.* in foo(.*) \\\[_Z3fooPKc\\\] at .*$srcfile:$bp1.*
+2\[\t \]+breakpoint keep y.* in fun_with_a_long_name(.*) \\\[_Z20fun_wi\.\.\.\\\] at .*$srcfile:$bp2.*" \
+ "info breakpoint - display 10"
+
+gdb_run_cmd
+set test "break at fun_with_a_long_name - display 10"
+gdb_test_multiple "continue" $test {
+ -re "Breakpoint 2, fun_with_a_long_name \\\[_Z20fun_wi\.\.\.\\\] (.*) at .*$srcfile:$bp2.*$gdb_prompt $" {
+ pass $test
+ break
+ }
+}
+
+set bttable "#0 foo \\\[_Z3fooPKc\\\] (.*) at.*\[\r\n\]"
+append bttable "#1 $hex in fun_with_a_long_name \\\[_Z20fun_wi\.\.\.\\\] (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#2 $hex in goo \\\[_Z3goov\\\] (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#3 $hex in main (.*) at .*$srcfile:.*"
+
+gdb_test "backtrace" $bttable "backtrace - display 10"
+
diff --git a/gdb/top.c b/gdb/top.c
index 46faaa7..c0f6f25 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -287,6 +287,29 @@ quit_cover (void)
quit_command ((char *) 0, 0);
}
#endif /* defined SIGHUP */
+
+/* Flag for whether we want to print linkage name for functions.
+ Length of linkage name to print. */
+
+int display_linkage_name = 0; /* Default is no. */
+int display_linkage_name_len = 20; /* Default is first 20 chars. */
+
+static void
+show_display_linkage_name (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) of functions is %s.\n"),
+ value);
+}
+static void
+show_display_linkage_name_len (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c, const char *value)
+{
+ fprintf_filtered (file, _("\
+Length of linkage names (symbol used by linker) to be displayed is %s.\n"),
+ value);
+}
\f
/* 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
@@ -1809,7 +1832,22 @@ Use \"on\" to enable the notification, and \"off\" to disable it."),
When set, GDB uses the specified path to search for data files."),
set_gdb_datadir, NULL,
&setlist,
- &showlist);
+ &showlist);
+
+ add_setshow_boolean_cmd ("display-linkage-name", class_support, &display_linkage_name, _("\
+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_display_linkage_name,
+ &setlist, &showlist);
+
+ add_setshow_zinteger_cmd ("display-linkage-name-len", class_support, &display_linkage_name_len, _("\
+Set number of characters of linkage name to display."), _("\
+Show number of characters of linkage name to display."), NULL,
+ NULL,
+ show_display_linkage_name_len,
+ &setlist, &showlist);
+
}
void
diff --git a/gdb/top.h b/gdb/top.h
index 2f70539..5acb311 100644
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -26,6 +26,8 @@ extern int saved_command_line_size;
extern FILE *instream;
extern int in_user_command;
extern int confirm;
+extern int display_linkage_name;
+extern int display_linkage_name_len;
extern char gdb_dirbuf[1024];
extern int inhibit_gdbinit;
extern const char gdbinit[];
--
1.8.1.4
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Revised display-linkage-name
2013-07-17 18:51 ` Michael Eager
@ 2013-07-17 19:14 ` Eli Zaretskii
2013-07-22 17:48 ` Keith Seitz
1 sibling, 0 replies; 19+ messages in thread
From: Eli Zaretskii @ 2013-07-17 19:14 UTC (permalink / raw)
To: Michael Eager; +Cc: keiths, gdb-patches, tromey
> Date: Wed, 17 Jul 2013 11:51:03 -0700
> From: Michael Eager <eager@eagerm.com>
> CC: gdb-patches@sourceware.org, Eli Zaretskii <eliz@gnu.org>,
> Tom Tromey <tromey@redhat.com>
>
> I believe I have addressed your comments, as well as Eli's previous
> notes about the docs. I didn't merge the tests cases into a single proc.
>
> BTW, "prepend" appears in several places in the docs. I replaced it this
> patch with prefix. If there is a concern that "prepend" sounds like jargon,
> then the other uses should be changed as well.
>
>
>
> gdb/
> 2013-07-17 Michael Eager <eager@eagercon.com>
>
> * NEWS: Announcement.
> * ada-lang.c: Update calls to find_frame_funname (pass NULL for linkname).
> * disasm.c: Likewise.
> * python/py-frame.c: Likewise.
> * annotate.c (annotate_linkage_name): New.
> * annotate.h (annotate_linkage_name): New decl.
> * breakpoint.c (print_breakpoint_location): Print linkage name.
> * defs.h (build_address_symbolic): Add linkname arg.
> * printcmd.c (print_address_symbolic): Print linkage name.
> (build_address_symbolic): Return linkage name.
> * annotate.c (annotate_linkage_name): New.
> * annotate.h (annotate_linkage_name): Declare.
> * stack.c (find_frame_funname): Return linkage name.
> (print_frame): Print linkage name.
> * stack.h (find_frame_funname): Update declaration.
> * top.c (display_linkage_name, display_linkage_name_len): New.
> (show_display_linkage_name, show_display_linkage_name_len): New cmds.
> * top.h (display_linkage_name, display_linkage_name_len): Declare.
>
> gdb/doc
> 2013-07-17 Michael Eager <eager@eagercon.com>
>
> * gdb.texinfo: Add description.
>
> gdb/testsuite
> 2013-07-17 Michael Eager <eager@eagercon.com>
>
> * gdb.cp/display-linkage-name.exp: New.
> * gdb.cp/display-linkage-name.cc: New.
>
Thanks, the documentation parts are OK.
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Revised display-linkage-name
2013-07-17 18:51 ` Michael Eager
2013-07-17 19:14 ` Eli Zaretskii
@ 2013-07-22 17:48 ` Keith Seitz
2013-07-22 20:07 ` Michael Eager
1 sibling, 1 reply; 19+ messages in thread
From: Keith Seitz @ 2013-07-22 17:48 UTC (permalink / raw)
To: Michael Eager; +Cc: gdb-patches@sourceware.org ml
On 07/17/2013 11:51 AM, Michael Eager wrote:
> BTW, "prepend" appears in several places in the docs. I replaced it this
> patch with prefix. If there is a concern that "prepend" sounds like
> jargon, then the other uses should be changed as well.
I will audit the manual. Maybe that's just my pedantic side showing through.
> diff --git a/gdb/annotate.c b/gdb/annotate.c
> index ccba5fe..84edeac 100644
> --- a/gdb/annotate.c
> +++ b/gdb/annotate.c
> @@ -582,6 +582,13 @@ breakpoint_changed (struct breakpoint *b)
> }
>
> void
> +annotate_linkage_name (void)
> +{
> + if (annotation_level == 2)
> + printf_filtered (("\n\032\032linkage_name\n"));
> +}
> +
This is still missing a (trivial) comment. [IIRC, we require comments
for *all* functions, even if they are pretty trivial.]
> +void
> _initialize_annotate (void)
> {
> observer_attach_breakpoint_created (breakpoint_changed);
> diff --git a/gdb/annotate.h b/gdb/annotate.h
> index 72c4f19..33a9a0e 100644
> --- a/gdb/annotate.h
> +++ b/gdb/annotate.h
> @@ -98,5 +98,7 @@ extern void annotate_elt_rep_end (void);
> extern void annotate_elt (void);
> extern void annotate_array_section_end (void);
>
> +extern void annotate_linkage_name (void);
> +
> extern void (*deprecated_annotate_signalled_hook) (void);
> extern void (*deprecated_annotate_signal_hook) (void);
> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
> index 4d09b30..e40af59 100644
> --- a/gdb/breakpoint.c
> +++ b/gdb/breakpoint.c
> @@ -5704,6 +5704,34 @@ print_breakpoint_location (struct breakpoint *b,
> ui_out_text (uiout, "in ");
> ui_out_field_string (uiout, "func",
> SYMBOL_PRINT_NAME (sym));
> + if (display_linkage_name)
I believe we are now asking all these types of checks to be explicit "!=
NULL".
> + {
> + struct bound_minimal_symbol msymbol =
Can you double-check this? GIT is showing me that there is extra
whitespace at the end of the (above) line.
> + lookup_minimal_symbol_by_pc (loc->address);
Need a blank line here.
> + if (msymbol.minsym != NULL
> + && strcmp (SYMBOL_LINKAGE_NAME (msymbol.minsym),
> + SYMBOL_PRINT_NAME (sym)) != 0)
> + {
> + ui_out_text (uiout, " [");
> +
> + if (strlen (SYMBOL_LINKAGE_NAME (msymbol.minsym))
> + > display_linkage_name_len)
This indentation looks off. Can you double-check this?
> + {
> + char *lname = alloca (display_linkage_name_len + 4);
> +
> + strncpy (lname, SYMBOL_LINKAGE_NAME (msymbol.minsym),
> + display_linkage_name_len);
> + lname[display_linkage_name_len] = '\0';
> + strcat (lname, "...");
> + ui_out_field_string (uiout, "linkage-name", lname);
> + }
> + else
> + ui_out_field_string (uiout, "linkage-name",
> + SYMBOL_LINKAGE_NAME (msymbol.minsym));
> +
From gdbint.info: "Any two or more lines in code should be wrapped in
braces [...]". See '(gdbint.info)Coding Standards'.
> + ui_out_text (uiout, "]");
> + }
> + }
> ui_out_text (uiout, " ");
> ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
> ui_out_text (uiout, "at ");
> diff --git a/gdb/defs.h b/gdb/defs.h
> index 014d7d4..0d10a0d 100644
> --- a/gdb/defs.h
> +++ b/gdb/defs.h
> @@ -336,6 +336,7 @@ extern int build_address_symbolic (struct gdbarch *,
> CORE_ADDR addr,
> int do_demangle,
> char **name,
> + char **linkname,
GIT is showing extra whitespace at the end of this line, too.
> int *offset,
> char **filename,
> int *line,
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index fae54e4..4f48c4c 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -15933,8 +15933,31 @@ line 1574.
> @}
> (@value{GDBP})
> @end smallexample
> -@end table
>
> +@kindex set display-linkage-name
> +@cindex list linkage 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 linkage name for the symbol name within brackets if it is
> +different from the name in the source.
There appears to be some more whitespace at the end of this line.
> +
> +The linkage name is the name used by the linker for a symbol. This may be
> +the same as the symbol's name in the source, or may be different if the compiler
> +adds a prefix to the name (for example, an underscore) or modifies it, such
> +as by C@t{++} name mangling.
> +
> +This is different from "set print asm-demangle on" which only displays
> +the linkage name for C@t{++} symbols and does not display the source name.
> +
> +@kindex show display-linkage-name-len
> +@itemx show display-linkage-name-len @var{len}
> +Set the maximum number of characters of linkage name to display. The
> +@code{show} command displays the current setting. The default is @code{20}.
> +@end table
>
> @node Altering
> @chapter Altering Execution
> @@ -29250,6 +29273,9 @@ is not.
> @item what
> Some extra data, the exact contents of which are type-dependent.
>
> +@item linkage-name
> +The name used by the linker for this function.
> +
> @end table
>
> For example, here is what the output of @code{-break-insert}
> diff --git a/gdb/printcmd.c b/gdb/printcmd.c
> index 99d4dba..e3b8c21 100644
> --- a/gdb/printcmd.c
> +++ b/gdb/printcmd.c
> @@ -51,6 +51,7 @@
> #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. */
> @@ -569,17 +570,19 @@ print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr,
> 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 name, linkname, and filename. */
> struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name);
> make_cleanup (free_current_contents, &filename);
> + make_cleanup (free_current_contents, &linkname);
>
> - 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 +594,28 @@ print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr,
> else
> fputs_filtered ("<", stream);
> fputs_filtered (name, stream);
> +
> + /* Print linkage name after source name if requested and different. */
> + if (display_linkage_name
> + && linkname != NULL && strcmp (name, linkname) != 0)
> + {
> + fputs_filtered (" [", stream);
> +
> + if (strlen (linkname) > display_linkage_name_len)
> + {
> + char *lname = alloca (display_linkage_name_len + 4);
> +
> + strncpy (lname, linkname, display_linkage_name_len);
> + lname[display_linkage_name_len] = '\0';
> + strcat (lname, "...");
> + fputs_filtered (lname, stream);
> + }
> + else
> + fputs_filtered (linkname, stream);
> +
> + fputs_filtered ("]", stream);
> + }
> +
> if (offset != 0)
> fprintf_filtered (stream, "+%u", (unsigned int) offset);
>
> @@ -623,6 +648,7 @@ build_address_symbolic (struct gdbarch *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 +663,10 @@ build_address_symbolic (struct gdbarch *gdbarch,
> /* Let's say it is mapped (not unmapped). */
> *unmapped = 0;
>
> + /* Let's say the link name is the same as the symbol name. */
> + if (linkname)
"!= NULL" and there appears to be extra whitespace at the end of this line.
> + *linkname = 0;
> +
s/0/NULL/g . From '(gdbint.info)Coding Standards': "Zero constant (0) is
not interchangeable with a null pointer constant (NULL) anywhere."
> /* Determine if the address is in an overlay, and whether it is
> mapped. */
> if (overlay_debugging)
> @@ -740,6 +770,13 @@ build_address_symbolic (struct gdbarch *gdbarch,
> *line = sal.line;
> }
> }
> +
> + /* If we have both symbol names and they are different, let caller know. */
> + if (msymbol != NULL && symbol != NULL
> + && strcmp (SYMBOL_LINKAGE_NAME (msymbol), SYMBOL_LINKAGE_NAME (symbol)) != 0)
> + if (linkname)
> + *linkname = xstrdup (SYMBOL_LINKAGE_NAME (msymbol));
The "strcmp..." line exceeds 80 columns.
This reads oddly. I think it would be better to merge the two tests,
adding the "linkname != NULL" before the strcmp:
if (linkname != NULL && msymbol != NULL && symbol != NULL
&& strcmp ...)
There's little point to doing the strcmp if the linkage name is not
required.
> +
> return 0;
> }
>
> diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
> index f960b08..6b48140 100644
> --- a/gdb/python/py-frame.c
> +++ b/gdb/python/py-frame.c
> @@ -131,7 +131,7 @@ frapy_name (PyObject *self, PyObject *args)
> {
> FRAPY_REQUIRE_VALID (self, frame);
>
> - find_frame_funname (frame, &name, &lang, NULL);
> + find_frame_funname (frame, &name, NULL, &lang, NULL);
> }
>
> if (except.reason < 0)
> diff --git a/gdb/stack.c b/gdb/stack.c
> index 313d57f..4bc8824 100644
> --- a/gdb/stack.c
> +++ b/gdb/stack.c
> @@ -55,6 +55,7 @@
> #include "psymtab.h"
> #include "symfile.h"
> #include "python/python.h"
> +#include "top.h"
>
> void (*deprecated_selected_frame_level_changed_hook) (int);
>
> @@ -1000,15 +1001,19 @@ get_last_displayed_sal (struct symtab_and_line *sal)
>
>
> /* Attempt to obtain the FUNNAME, FUNLANG and optionally FUNCP of the function
> - corresponding to FRAME. FUNNAME needs to be freed by the caller. */
> + corresponding to FRAME. FUNNAME needs to be freed by the caller.
> + Set LINKNAME to linkage name (symbol used by linker) if LINKNAME is non-null
> + and linkage name differs from source name. */
>
> void
> find_frame_funname (struct frame_info *frame, char **funname,
> - enum language *funlang, struct symbol **funcp)
> + const char **linkname, enum language *funlang,
> + struct symbol **funcp)
> {
> struct symbol *func;
>
> *funname = NULL;
> + *linkname = NULL;
linkname could be NULL; *linkname would be bad. :-)
> *funlang = language_unknown;
> if (funcp)
> *funcp = NULL;
> @@ -1045,6 +1050,12 @@ find_frame_funname (struct frame_info *frame, char **funname,
> memset (&msymbol, 0, sizeof (msymbol));
>
> if (msymbol.minsym != NULL
> + && strcmp (SYMBOL_LINKAGE_NAME (msymbol.minsym),
> + SYMBOL_LINKAGE_NAME (func)) != 0)
> + if (linkname)
> + *linkname = SYMBOL_LINKAGE_NAME (msymbol.minsym);
> +
Same comment about merging these two tests.
> + if (msymbol.minsym != NULL
> && (SYMBOL_VALUE_ADDRESS (msymbol.minsym)
> > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
> {
> @@ -1102,6 +1113,7 @@ print_frame (struct frame_info *frame, int print_level,
> struct gdbarch *gdbarch = get_frame_arch (frame);
> struct ui_out *uiout = current_uiout;
> char *funname = NULL;
> + const char *linkname = NULL;
> enum language funlang = language_unknown;
> struct ui_file *stb;
> struct cleanup *old_chain, *list_chain;
> @@ -1115,7 +1127,7 @@ print_frame (struct frame_info *frame, int print_level,
> 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);
> make_cleanup (xfree, funname);
>
> annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
> @@ -1147,9 +1159,33 @@ print_frame (struct frame_info *frame, int print_level,
> fprintf_symbol_filtered (stb, funname ? funname : "??",
> funlang, DMGL_ANSI);
> ui_out_field_stream (uiout, "func", stb);
> +
> + /* Print linkage name after source name if requested and different. */
> + if ((display_linkage_name || ui_out_is_mi_like_p (uiout))
> + && linkname != NULL && strcmp (funname, linkname) != 0)
> + {
> + annotate_linkage_name ();
> + ui_out_text (uiout, " [");
> +
> + if (strlen (linkname) > display_linkage_name_len)
> + {
> + char *lname = alloca (display_linkage_name_len + 4);
> +
> + strncpy (lname, linkname, display_linkage_name_len);
> + lname[display_linkage_name_len] = '\0';
> + strcat (lname, "...");
> + ui_out_text (uiout, lname);
> + }
> + else
> + ui_out_text (uiout, linkname);
> +
> + ui_out_text (uiout, "]");
> + ui_out_field_stream (uiout, "linkage_name", stb);
> + }
> +
> ui_out_wrap_hint (uiout, " ");
> annotate_frame_args ();
> -
> +
More whitespace here.
> ui_out_text (uiout, " (");
> if (print_args)
> {
> diff --git a/gdb/testsuite/gdb.cp/display-linkage-name.exp b/gdb/testsuite/gdb.cp/display-linkage-name.exp
> new file mode 100644
> index 0000000..6cde8af
> --- /dev/null
> +++ b/gdb/testsuite/gdb.cp/display-linkage-name.exp
> @@ -0,0 +1,129 @@
> +# Copyright 2013 Free Software Foundation, Inc.
> +
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see<http://www.gnu.org/licenses/>.
> +
> +# This file was written by Michael Eager (eager@eagercon.com).
> +
> +if { [skip_cplus_tests] } { continue }
> +
> +standard_testfile .cc
> +
> +if {[get_compiler_info "c++"]} {
> + return -1
> +}
> +
> +if { [prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}] } {
> + return -1
> +}
> +
> +# set break at functions
> +
> +set bp1 [gdb_get_line_number "set breakpoint 1 here"]
> +set bp2 [gdb_get_line_number "set breakpoint 2 here"]
> +
> +if {![gdb_breakpoint "foo"]} {
> + fail "set breakpoint foo"
> +}
> +
> +if {![gdb_breakpoint "fun_with_a_long_name"]} {
> + fail "set breakpoint fun_with_a_long_name"
> +}
> +
> +########################
> +# Test with display-linkage-name off
> +
> +gdb_test_no_output "set display-linkage-name off" ""
> +
> +gdb_test "info break" \
> + "Num Type\[ \]+Disp Enb Address\[\t \]+What.*
> +1\[\t \]+breakpoint keep y.* in foo(.*) at .*$srcfile:$bp1.*
> +2\[\t \]+breakpoint keep y.* in fun_with_a_long_name(.*) at .*$srcfile:$bp2.*" \
> + "info breakpoint - display off"
> +
> +gdb_run_cmd
> +set test "break at fun_with_a_long_name"
There's extra whitespace at the end of this line.
> +gdb_test_multiple "continue" $test {
> + -re "Breakpoint 2, fun_with_a_long_name (.*) at.*$srcfile.$bp2.*$gdb_prompt $" {
> + pass $test
> + break
> + }
> +}
You can use gdb_continue_to_breakpoint to simplify the above.
[gdb_continue_to_breakpoint takes an optional location pattern argument.]
> +set bttable "#0 foo (.*) at.*\[\r\n\]"
> +append bttable "#1 $hex in fun_with_a_long_name (.*) at .*$srcfile:.*\[\r\n\]"
> +append bttable "#2 $hex in goo (.*) at .*$srcfile:.*\[\r\n\]"
> +append bttable "#3 $hex in main (.*) at .*$srcfile:.*"
> +
> +gdb_test "backtrace" $bttable "backtrace - display off"
> +
> +########################
> +# Test with display-linkage-name on
> +
> +gdb_test_no_output "set display-linkage-name on" ""
> +
> +gdb_test "info break" \
> + "Num Type\[ \]+Disp Enb Address\[\t \]+What.*
> +1\[\t \]+breakpoint keep y.* in foo(.*) \\\[_Z3fooPKc\\\] at .*$srcfile:$bp1.*
> +2\[\t \]+breakpoint keep y.* in fun_with_a_long_name(.*) \\\[_Z20fun_with_a_long_\.\.\.\\\] at .*$srcfile:$bp2.*" \
> + "info breakpoint - display on"
> +
> +gdb_run_cmd
> +set test "break at fun_with_a_long_name - display on"
There is extra trailing whitespace here, too.
> +gdb_test_multiple "continue" $test {
> + -re "Breakpoint 2, fun_with_a_long_name \\\[_Z20fun_with_a_long_...\\\] (.*) at.*$srcfile.$bp2.*$gdb_prompt $" {
> + pass $test
> + break
> + }
> +}
gdb_continue_to_breakpoint
> +
> +set bttable "#0 foo \\\[_Z3fooPKc\\\] (.*) at.*\[\r\n\]"
> +append bttable "#1 $hex in fun_with_a_long_name \\\[_Z20fun_with_a_long_\.\.\.\\\] (.*) at .*$srcfile:.*\[\r\n\]"
> +append bttable "#2 $hex in goo \\\[_Z3goov\\\] (.*) at .*$srcfile:.*\[\r\n\]"
> +append bttable "#3 $hex in main (.*) at .*$srcfile:.*"
> +
> +gdb_test "backtrace" $bttable "backtrace - display on"
> +
> +########################
> +# Test set/show display-linkage-name-len
> +
> +gdb_test "show display-linkage-name-len" \
> + "Length of linkage names \\(symbol used by linker\\) to be displayed is 20."
> +
> +gdb_test_no_output "set display-linkage-name-len 10" ""
> +
> +gdb_test "show display-linkage-name-len" \
> + "Length of linkage names \\(symbol used by linker\\) to be displayed is 10."
> +
> +gdb_test "info break" \
> + "Num Type\[ \]+Disp Enb Address\[\t \]+What.*
> +1\[\t \]+breakpoint keep y.* in foo(.*) \\\[_Z3fooPKc\\\] at .*$srcfile:$bp1.*
> +2\[\t \]+breakpoint keep y.* in fun_with_a_long_name(.*) \\\[_Z20fun_wi\.\.\.\\\] at .*$srcfile:$bp2.*" \
> + "info breakpoint - display 10"
> +
> +gdb_run_cmd
> +set test "break at fun_with_a_long_name - display 10"
trailing whitespace
> +gdb_test_multiple "continue" $test {
> + -re "Breakpoint 2, fun_with_a_long_name \\\[_Z20fun_wi\.\.\.\\\] (.*) at .*$srcfile:$bp2.*$gdb_prompt $" {
> + pass $test
> + break
> + }
> +}
gdb_continue_to_breakpoint
> +
> +set bttable "#0 foo \\\[_Z3fooPKc\\\] (.*) at.*\[\r\n\]"
> +append bttable "#1 $hex in fun_with_a_long_name \\\[_Z20fun_wi\.\.\.\\\] (.*) at .*$srcfile:.*\[\r\n\]"
> +append bttable "#2 $hex in goo \\\[_Z3goov\\\] (.*) at .*$srcfile:.*\[\r\n\]"
> +append bttable "#3 $hex in main (.*) at .*$srcfile:.*"
> +
> +gdb_test "backtrace" $bttable "backtrace - display 10"
> +
> diff --git a/gdb/top.c b/gdb/top.c
> index 46faaa7..c0f6f25 100644
> --- a/gdb/top.c
> +++ b/gdb/top.c
> @@ -287,6 +287,29 @@ quit_cover (void)
> quit_command ((char *) 0, 0);
> }
> #endif /* defined SIGHUP */
> +
> +/* Flag for whether we want to print linkage name for functions.
> + Length of linkage name to print. */
> +
> +int display_linkage_name = 0; /* Default is no. */
> +int display_linkage_name_len = 20; /* Default is first 20 chars. */
> +
> +static void
> +show_display_linkage_name (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) of functions is %s.\n"),
> + value);
> +}
> +static void
> +show_display_linkage_name_len (struct ui_file *file, int from_tty,
> + struct cmd_list_element *c, const char *value)
> +{
> + fprintf_filtered (file, _("\
> +Length of linkage names (symbol used by linker) to be displayed is %s.\n"),
> + value);
> +}
> \f
> /* 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
> @@ -1809,7 +1832,22 @@ Use \"on\" to enable the notification, and \"off\" to disable it."),
> When set, GDB uses the specified path to search for data files."),
> set_gdb_datadir, NULL,
> &setlist,
> - &showlist);
> + &showlist);
Unnecessary whitespace change?
> +
> + add_setshow_boolean_cmd ("display-linkage-name", class_support, &display_linkage_name, _("\
> +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_display_linkage_name,
> + &setlist, &showlist);
> +
> + add_setshow_zinteger_cmd ("display-linkage-name-len", class_support, &display_linkage_name_len, _("\
> +Set number of characters of linkage name to display."), _("\
> +Show number of characters of linkage name to display."), NULL,
> + NULL,
> + show_display_linkage_name_len,
> + &setlist, &showlist);
> +
> }
I think with these minor things fixed, a global maintainer should give a
final review (and approval).
Keith
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Revised display-linkage-name
2013-07-22 17:48 ` Keith Seitz
@ 2013-07-22 20:07 ` Michael Eager
2013-07-22 21:55 ` Keith Seitz
0 siblings, 1 reply; 19+ messages in thread
From: Michael Eager @ 2013-07-22 20:07 UTC (permalink / raw)
To: Keith Seitz; +Cc: gdb-patches@sourceware.org ml
[-- Attachment #1: Type: text/plain, Size: 795 bytes --]
On 07/22/13 10:48, Keith Seitz wrote:
> On 07/17/2013 11:51 AM, Michael Eager wrote:
>> void
>> +annotate_linkage_name (void)
>> +{
>> + if (annotation_level == 2)
>> + printf_filtered (("\n\032\032linkage_name\n"));
>> +}
>> +
>
> This is still missing a (trivial) comment. [IIRC, we require comments for *all* functions, even if
> they are pretty trivial.]
The Changelog contains
* annotate.c (annotate_linkage_name): New.
* annotate.h (annotate_linkage_name): New decl.
Is something else needed?
>
> I think with these minor things fixed, a global maintainer should give a final review (and approval).
I believe that the attached updated patch addresses all of your comments.
--
Michael Eager eager@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306 650-325-8077
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-GDB-display-linkage-name-command.patch --]
[-- Type: text/x-patch; name="0001-GDB-display-linkage-name-command.patch", Size: 24278 bytes --]
From dffcd88d0f76ebe969b67eddacfc459373e2e5fb Mon Sep 17 00:00:00 2001
From: Michael Eager <eager@eagercon.com>
Date: Mon, 22 Jul 2013 12:56:42 -0700
Subject: [PATCH] GDB - display linkage name command
---
gdb/NEWS | 14 ++++
gdb/ada-lang.c | 5 +-
gdb/annotate.c | 7 ++
gdb/annotate.h | 2 +
gdb/breakpoint.c | 31 +++++++
gdb/defs.h | 1 +
gdb/disasm.c | 4 +-
gdb/doc/gdb.texinfo | 28 ++++++-
gdb/printcmd.c | 43 +++++++++-
gdb/python/py-frame.c | 2 +-
gdb/stack.c | 42 +++++++++-
gdb/stack.h | 3 +-
gdb/testsuite/gdb.cp/display-linkage-name.cc | 36 ++++++++
gdb/testsuite/gdb.cp/display-linkage-name.exp | 114 ++++++++++++++++++++++++++
gdb/top.c | 40 ++++++++-
gdb/top.h | 2 +
16 files changed, 360 insertions(+), 14 deletions(-)
create mode 100644 gdb/testsuite/gdb.cp/display-linkage-name.cc
create mode 100644 gdb/testsuite/gdb.cp/display-linkage-name.exp
diff --git a/gdb/NEWS b/gdb/NEWS
index e469f1e..ac62062 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -56,6 +56,20 @@ show range-stepping
--configuration
Display the details of GDB configure-time options.
+* 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
+ prefixes 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.
+
+set|show display-linkage-name-len
+
+ Set the maximum number of characters to display in the linkage name,
+ if display-linkage-name is on. The default is 20.
+
* The command 'tsave' can now support new option '-ctf' to save trace
buffer in Common Trace Format.
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index dc5f2b6..3430e3f 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -11114,6 +11114,7 @@ is_known_support_routine (struct frame_info *frame)
{
struct symtab_and_line sal;
char *func_name;
+ const char *linkname;
enum language func_lang;
int i;
const char *fullname;
@@ -11152,7 +11153,7 @@ is_known_support_routine (struct frame_info *frame)
/* Check whether the function is a GNAT-generated entity. */
- find_frame_funname (frame, &func_name, &func_lang, NULL);
+ find_frame_funname (frame, &func_name, NULL, &func_lang, NULL);
if (func_name == NULL)
return 1;
@@ -11227,7 +11228,7 @@ ada_unhandled_exception_name_addr_from_raise (void)
char *func_name;
enum language func_lang;
- find_frame_funname (fi, &func_name, &func_lang, NULL);
+ find_frame_funname (fi, &func_name, NULL, &func_lang, NULL);
if (func_name != NULL)
{
make_cleanup (xfree, func_name);
diff --git a/gdb/annotate.c b/gdb/annotate.c
index ccba5fe..84edeac 100644
--- a/gdb/annotate.c
+++ b/gdb/annotate.c
@@ -582,6 +582,13 @@ breakpoint_changed (struct breakpoint *b)
}
void
+annotate_linkage_name (void)
+{
+ if (annotation_level == 2)
+ printf_filtered (("\n\032\032linkage_name\n"));
+}
+
+void
_initialize_annotate (void)
{
observer_attach_breakpoint_created (breakpoint_changed);
diff --git a/gdb/annotate.h b/gdb/annotate.h
index 72c4f19..33a9a0e 100644
--- a/gdb/annotate.h
+++ b/gdb/annotate.h
@@ -98,5 +98,7 @@ extern void annotate_elt_rep_end (void);
extern void annotate_elt (void);
extern void annotate_array_section_end (void);
+extern void annotate_linkage_name (void);
+
extern void (*deprecated_annotate_signalled_hook) (void);
extern void (*deprecated_annotate_signal_hook) (void);
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 4d09b30..ba37c5e 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -5704,6 +5704,37 @@ print_breakpoint_location (struct breakpoint *b,
ui_out_text (uiout, "in ");
ui_out_field_string (uiout, "func",
SYMBOL_PRINT_NAME (sym));
+ if (display_linkage_name)
+ {
+ struct bound_minimal_symbol msymbol =
+ lookup_minimal_symbol_by_pc (loc->address);
+
+ if (msymbol.minsym != NULL
+ && strcmp (SYMBOL_LINKAGE_NAME (msymbol.minsym),
+ SYMBOL_PRINT_NAME (sym)) != 0)
+ {
+ ui_out_text (uiout, " [");
+
+ if (strlen (SYMBOL_LINKAGE_NAME (msymbol.minsym))
+ > display_linkage_name_len)
+ {
+ char *lname = alloca (display_linkage_name_len + 4);
+
+ strncpy (lname, SYMBOL_LINKAGE_NAME (msymbol.minsym),
+ display_linkage_name_len);
+ lname[display_linkage_name_len] = '\0';
+ strcat (lname, "...");
+ ui_out_field_string (uiout, "linkage-name", lname);
+ }
+ else
+ {
+ ui_out_field_string (uiout, "linkage-name",
+ SYMBOL_LINKAGE_NAME (msymbol.minsym));
+ }
+
+ ui_out_text (uiout, "]");
+ }
+ }
ui_out_text (uiout, " ");
ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
ui_out_text (uiout, "at ");
diff --git a/gdb/defs.h b/gdb/defs.h
index 014d7d4..15e9a54 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -336,6 +336,7 @@ extern int build_address_symbolic (struct gdbarch *,
CORE_ADDR addr,
int do_demangle,
char **name,
+ char **linkname,
int *offset,
char **filename,
int *line,
diff --git a/gdb/disasm.c b/gdb/disasm.c
index e643c2d..396dce9 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -127,8 +127,8 @@ dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
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, NULL, &offset,
+ &filename, &line, &unmapped))
{
/* We don't care now about line, filename and
unmapped. But we might in the future. */
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index fae54e4..d230e01 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -15933,8 +15933,31 @@ line 1574.
@}
(@value{GDBP})
@end smallexample
-@end table
+@kindex set display-linkage-name
+@cindex list linkage 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 linkage name for the symbol name within brackets if it is
+different from the name in the source.
+
+The linkage name is the name used by the linker for a symbol. This may be
+the same as the symbol's name in the source, or may be different if the compiler
+adds a prefix to the name (for example, an underscore) or modifies it, such
+as by C@t{++} name mangling.
+
+This is different from "set print asm-demangle on" which only displays
+the linkage name for C@t{++} symbols and does not display the source name.
+
+@kindex show display-linkage-name-len
+@itemx show display-linkage-name-len @var{len}
+Set the maximum number of characters of linkage name to display. The
+@code{show} command displays the current setting. The default is @code{20}.
+@end table
@node Altering
@chapter Altering Execution
@@ -29250,6 +29273,9 @@ is not.
@item what
Some extra data, the exact contents of which are type-dependent.
+@item linkage-name
+The name used by the linker for this function.
+
@end table
For example, here is what the output of @code{-break-insert}
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 99d4dba..de174d6 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -51,6 +51,7 @@
#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. */
@@ -569,17 +570,19 @@ print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr,
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 name, linkname, and filename. */
struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name);
make_cleanup (free_current_contents, &filename);
+ make_cleanup (free_current_contents, &linkname);
- 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 +594,28 @@ print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr,
else
fputs_filtered ("<", stream);
fputs_filtered (name, stream);
+
+ /* Print linkage name after source name if requested and different. */
+ if (display_linkage_name
+ && linkname != NULL && strcmp (name, linkname) != 0)
+ {
+ fputs_filtered (" [", stream);
+
+ if (strlen (linkname) > display_linkage_name_len)
+ {
+ char *lname = alloca (display_linkage_name_len + 4);
+
+ strncpy (lname, linkname, display_linkage_name_len);
+ lname[display_linkage_name_len] = '\0';
+ strcat (lname, "...");
+ fputs_filtered (lname, stream);
+ }
+ else
+ fputs_filtered (linkname, stream);
+
+ fputs_filtered ("]", stream);
+ }
+
if (offset != 0)
fprintf_filtered (stream, "+%u", (unsigned int) offset);
@@ -623,6 +648,7 @@ build_address_symbolic (struct gdbarch *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 +663,10 @@ build_address_symbolic (struct gdbarch *gdbarch,
/* Let's say it is mapped (not unmapped). */
*unmapped = 0;
+ /* Let's say the link name is the same as the symbol name. */
+ if (linkname != NULL)
+ *linkname = NULL;
+
/* Determine if the address is in an overlay, and whether it is
mapped. */
if (overlay_debugging)
@@ -740,6 +770,13 @@ build_address_symbolic (struct gdbarch *gdbarch,
*line = sal.line;
}
}
+
+ /* If we have both symbol names and they are different, let caller know. */
+ if (linkname != NULL && msymbol != NULL && symbol != NULL
+ && strcmp (SYMBOL_LINKAGE_NAME (msymbol),
+ SYMBOL_LINKAGE_NAME (symbol)) != 0)
+ *linkname = xstrdup (SYMBOL_LINKAGE_NAME (msymbol));
+
return 0;
}
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index f960b08..6b48140 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -131,7 +131,7 @@ frapy_name (PyObject *self, PyObject *args)
{
FRAPY_REQUIRE_VALID (self, frame);
- find_frame_funname (frame, &name, &lang, NULL);
+ find_frame_funname (frame, &name, NULL, &lang, NULL);
}
if (except.reason < 0)
diff --git a/gdb/stack.c b/gdb/stack.c
index 313d57f..49d6acb 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -55,6 +55,7 @@
#include "psymtab.h"
#include "symfile.h"
#include "python/python.h"
+#include "top.h"
void (*deprecated_selected_frame_level_changed_hook) (int);
@@ -1000,15 +1001,20 @@ get_last_displayed_sal (struct symtab_and_line *sal)
/* Attempt to obtain the FUNNAME, FUNLANG and optionally FUNCP of the function
- corresponding to FRAME. FUNNAME needs to be freed by the caller. */
+ corresponding to FRAME. FUNNAME needs to be freed by the caller.
+ Set LINKNAME to linkage name (symbol used by linker) if LINKNAME is non-null
+ and linkage name differs from source name. */
void
find_frame_funname (struct frame_info *frame, char **funname,
- enum language *funlang, struct symbol **funcp)
+ const char **linkname, enum language *funlang,
+ struct symbol **funcp)
{
struct symbol *func;
*funname = NULL;
+ if (linkname != NULL)
+ *linkname = NULL;
*funlang = language_unknown;
if (funcp)
*funcp = NULL;
@@ -1044,6 +1050,11 @@ find_frame_funname (struct frame_info *frame, char **funname,
else
memset (&msymbol, 0, sizeof (msymbol));
+ if (linkname != NULL && msymbol.minsym != NULL
+ && strcmp (SYMBOL_LINKAGE_NAME (msymbol.minsym),
+ SYMBOL_LINKAGE_NAME (func)) != 0)
+ *linkname = SYMBOL_LINKAGE_NAME (msymbol.minsym);
+
if (msymbol.minsym != NULL
&& (SYMBOL_VALUE_ADDRESS (msymbol.minsym)
> BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
@@ -1102,6 +1113,7 @@ print_frame (struct frame_info *frame, int print_level,
struct gdbarch *gdbarch = get_frame_arch (frame);
struct ui_out *uiout = current_uiout;
char *funname = NULL;
+ const char *linkname = NULL;
enum language funlang = language_unknown;
struct ui_file *stb;
struct cleanup *old_chain, *list_chain;
@@ -1115,7 +1127,7 @@ print_frame (struct frame_info *frame, int print_level,
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);
make_cleanup (xfree, funname);
annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
@@ -1147,6 +1159,30 @@ print_frame (struct frame_info *frame, int print_level,
fprintf_symbol_filtered (stb, funname ? funname : "??",
funlang, DMGL_ANSI);
ui_out_field_stream (uiout, "func", stb);
+
+ /* Print linkage name after source name if requested and different. */
+ if ((display_linkage_name || ui_out_is_mi_like_p (uiout))
+ && linkname != NULL && strcmp (funname, linkname) != 0)
+ {
+ annotate_linkage_name ();
+ ui_out_text (uiout, " [");
+
+ if (strlen (linkname) > display_linkage_name_len)
+ {
+ char *lname = alloca (display_linkage_name_len + 4);
+
+ strncpy (lname, linkname, display_linkage_name_len);
+ lname[display_linkage_name_len] = '\0';
+ strcat (lname, "...");
+ ui_out_text (uiout, lname);
+ }
+ else
+ ui_out_text (uiout, linkname);
+
+ ui_out_text (uiout, "]");
+ ui_out_field_stream (uiout, "linkage_name", stb);
+ }
+
ui_out_wrap_hint (uiout, " ");
annotate_frame_args ();
diff --git a/gdb/stack.h b/gdb/stack.h
index 4badf19..9248c85 100644
--- a/gdb/stack.h
+++ b/gdb/stack.h
@@ -23,7 +23,8 @@
void select_frame_command (char *level_exp, int from_tty);
void find_frame_funname (struct frame_info *frame, 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,
diff --git a/gdb/testsuite/gdb.cp/display-linkage-name.cc b/gdb/testsuite/gdb.cp/display-linkage-name.cc
new file mode 100644
index 0000000..d9db673
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/display-linkage-name.cc
@@ -0,0 +1,36 @@
+/* This test script is part of GDB, the GNU debugger.
+
+ Copyright 2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+void foo (const char *msg)
+{
+} /* set breakpoint 1 here */
+
+void fun_with_a_long_name (int i, const char *s, double d)
+{
+ foo ("Hello"); /* set breakpoint 2 here */
+}
+
+void goo (void)
+{
+ fun_with_a_long_name (1, "abc", 3.14);
+}
+
+int main (void)
+{
+ goo();
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.cp/display-linkage-name.exp b/gdb/testsuite/gdb.cp/display-linkage-name.exp
new file mode 100644
index 0000000..19c6191
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/display-linkage-name.exp
@@ -0,0 +1,114 @@
+# Copyright 2013 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This file was written by Michael Eager (eager@eagercon.com).
+
+if { [skip_cplus_tests] } { continue }
+
+standard_testfile .cc
+
+if {[get_compiler_info "c++"]} {
+ return -1
+}
+
+if { [prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}] } {
+ return -1
+}
+
+# set break at functions
+
+set bp1 [gdb_get_line_number "set breakpoint 1 here"]
+set bp2 [gdb_get_line_number "set breakpoint 2 here"]
+
+if {![gdb_breakpoint "foo"]} {
+ fail "set breakpoint foo"
+}
+
+if {![gdb_breakpoint "fun_with_a_long_name"]} {
+ fail "set breakpoint fun_with_a_long_name"
+}
+
+########################
+# Test with display-linkage-name off
+
+gdb_test_no_output "set display-linkage-name off" ""
+
+gdb_test "info break" \
+ "Num Type\[ \]+Disp Enb Address\[\t \]+What.*
+1\[\t \]+breakpoint keep y.* in foo(.*) at .*$srcfile:$bp1.*
+2\[\t \]+breakpoint keep y.* in fun_with_a_long_name(.*) at .*$srcfile:$bp2.*" \
+ "info breakpoint - display off"
+
+gdb_run_cmd
+set test "break at fun_with_a_long_name"
+gdb_continue_to_breakpoint "fun_with_a_long_name (.*) at.*$srcfile.$bp2"
+
+set bttable "#0 foo (.*) at.*\[\r\n\]"
+append bttable "#1 $hex in fun_with_a_long_name (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#2 $hex in goo (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#3 $hex in main (.*) at .*$srcfile:.*"
+
+gdb_test "backtrace" $bttable "backtrace - display off"
+
+########################
+# Test with display-linkage-name on
+
+gdb_test_no_output "set display-linkage-name on" ""
+
+gdb_test "info break" \
+ "Num Type\[ \]+Disp Enb Address\[\t \]+What.*
+1\[\t \]+breakpoint keep y.* in foo(.*) \\\[_Z3fooPKc\\\] at .*$srcfile:$bp1.*
+2\[\t \]+breakpoint keep y.* in fun_with_a_long_name(.*) \\\[_Z20fun_with_a_long_\.\.\.\\\] at .*$srcfile:$bp2.*" \
+ "info breakpoint - display on"
+
+gdb_run_cmd
+set test "break at fun_with_a_long_name - display on"
+gdb_continue_to_breakpoint "fun_with_a_long_name \\\[_Z20fun_with_a_long_...\\\] (.*) at.*$srcfile.$bp2"
+
+set bttable "#0 foo \\\[_Z3fooPKc\\\] (.*) at.*\[\r\n\]"
+append bttable "#1 $hex in fun_with_a_long_name \\\[_Z20fun_with_a_long_\.\.\.\\\] (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#2 $hex in goo \\\[_Z3goov\\\] (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#3 $hex in main (.*) at .*$srcfile:.*"
+
+gdb_test "backtrace" $bttable "backtrace - display on"
+
+########################
+# Test set/show display-linkage-name-len
+
+gdb_test "show display-linkage-name-len" \
+ "Length of linkage names \\(symbol used by linker\\) to be displayed is 20."
+
+gdb_test_no_output "set display-linkage-name-len 10" ""
+
+gdb_test "show display-linkage-name-len" \
+ "Length of linkage names \\(symbol used by linker\\) to be displayed is 10."
+
+gdb_test "info break" \
+ "Num Type\[ \]+Disp Enb Address\[\t \]+What.*
+1\[\t \]+breakpoint keep y.* in foo(.*) \\\[_Z3fooPKc\\\] at .*$srcfile:$bp1.*
+2\[\t \]+breakpoint keep y.* in fun_with_a_long_name(.*) \\\[_Z20fun_wi\.\.\.\\\] at .*$srcfile:$bp2.*" \
+ "info breakpoint - display 10"
+
+gdb_run_cmd
+set test "break at fun_with_a_long_name - display 10"
+gdb_continue_to_breakpoint "fun_with_a_long_name \\\[_Z20fun_wi\.\.\.\\\] (.*) at .*$srcfile:$bp2"
+
+set bttable "#0 foo \\\[_Z3fooPKc\\\] (.*) at.*\[\r\n\]"
+append bttable "#1 $hex in fun_with_a_long_name \\\[_Z20fun_wi\.\.\.\\\] (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#2 $hex in goo \\\[_Z3goov\\\] (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#3 $hex in main (.*) at .*$srcfile:.*"
+
+gdb_test "backtrace" $bttable "backtrace - display 10"
+
diff --git a/gdb/top.c b/gdb/top.c
index 46faaa7..c0f6f25 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -287,6 +287,29 @@ quit_cover (void)
quit_command ((char *) 0, 0);
}
#endif /* defined SIGHUP */
+
+/* Flag for whether we want to print linkage name for functions.
+ Length of linkage name to print. */
+
+int display_linkage_name = 0; /* Default is no. */
+int display_linkage_name_len = 20; /* Default is first 20 chars. */
+
+static void
+show_display_linkage_name (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) of functions is %s.\n"),
+ value);
+}
+static void
+show_display_linkage_name_len (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c, const char *value)
+{
+ fprintf_filtered (file, _("\
+Length of linkage names (symbol used by linker) to be displayed is %s.\n"),
+ value);
+}
\f
/* 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
@@ -1809,7 +1832,22 @@ Use \"on\" to enable the notification, and \"off\" to disable it."),
When set, GDB uses the specified path to search for data files."),
set_gdb_datadir, NULL,
&setlist,
- &showlist);
+ &showlist);
+
+ add_setshow_boolean_cmd ("display-linkage-name", class_support, &display_linkage_name, _("\
+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_display_linkage_name,
+ &setlist, &showlist);
+
+ add_setshow_zinteger_cmd ("display-linkage-name-len", class_support, &display_linkage_name_len, _("\
+Set number of characters of linkage name to display."), _("\
+Show number of characters of linkage name to display."), NULL,
+ NULL,
+ show_display_linkage_name_len,
+ &setlist, &showlist);
+
}
void
diff --git a/gdb/top.h b/gdb/top.h
index 2f70539..5acb311 100644
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -26,6 +26,8 @@ extern int saved_command_line_size;
extern FILE *instream;
extern int in_user_command;
extern int confirm;
+extern int display_linkage_name;
+extern int display_linkage_name_len;
extern char gdb_dirbuf[1024];
extern int inhibit_gdbinit;
extern const char gdbinit[];
--
1.8.1.4
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Revised display-linkage-name
2013-07-22 20:07 ` Michael Eager
@ 2013-07-22 21:55 ` Keith Seitz
2013-07-24 15:55 ` Michael Eager
0 siblings, 1 reply; 19+ messages in thread
From: Keith Seitz @ 2013-07-22 21:55 UTC (permalink / raw)
To: Michael Eager; +Cc: gdb-patches@sourceware.org ml
On 07/22/2013 01:06 PM, Michael Eager wrote:
> On 07/22/13 10:48, Keith Seitz wrote:
>> On 07/17/2013 11:51 AM, Michael Eager wrote:
>
>>> void
>>> +annotate_linkage_name (void)
>>> +{
>>> + if (annotation_level == 2)
>>> + printf_filtered (("\n\032\032linkage_name\n"));
>>> +}
>>> +
>>
>> This is still missing a (trivial) comment. [IIRC, we require comments
>> for *all* functions, even if
>> they are pretty trivial.]
>
> The Changelog contains
> * annotate.c (annotate_linkage_name): New.
> * annotate.h (annotate_linkage_name): New decl.
>
> Is something else needed?
Yes, all functions need a comment, e.g.,
/* Emit an annotation for a symbol's linkage name. */
void
annotate_linkage_name (void)
{
/* ... */
}
> I believe that the attached updated patch addresses all of your comments.
Pretty much. Just two really minor nits:
> diff --git a/gdb/annotate.c b/gdb/annotate.c
> index ccba5fe..84edeac 100644
> --- a/gdb/annotate.c
> +++ b/gdb/annotate.c
> @@ -582,6 +582,13 @@ breakpoint_changed (struct breakpoint *b)
> }
>
> void
> +annotate_linkage_name (void)
> +{
> + if (annotation_level == 2)
> + printf_filtered (("\n\032\032linkage_name\n"));
> +}
You know about this one already. :-)
> diff --git a/gdb/testsuite/gdb.cp/display-linkage-name.exp b/gdb/testsuite/gdb.cp/display-linkage-name.exp
> new file mode 100644
> index 0000000..19c6191
> --- /dev/null
> +++ b/gdb/testsuite/gdb.cp/display-linkage-name.exp
> @@ -0,0 +1,114 @@
> +# Copyright 2013 Free Software Foundation, Inc.
> +
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see<http://www.gnu.org/licenses/>.
> +
> +# This file was written by Michael Eager (eager@eagercon.com).
> +
> +if { [skip_cplus_tests] } { continue }
> +
> +standard_testfile .cc
> +
> +if {[get_compiler_info "c++"]} {
> + return -1
> +}
> +
> +if { [prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}] } {
> + return -1
> +}
> +
> +# set break at functions
> +
> +set bp1 [gdb_get_line_number "set breakpoint 1 here"]
> +set bp2 [gdb_get_line_number "set breakpoint 2 here"]
> +
> +if {![gdb_breakpoint "foo"]} {
> + fail "set breakpoint foo"
> +}
> +
> +if {![gdb_breakpoint "fun_with_a_long_name"]} {
> + fail "set breakpoint fun_with_a_long_name"
> +}
> +
> +########################
> +# Test with display-linkage-name off
> +
> +gdb_test_no_output "set display-linkage-name off" ""
You can omit the trailing quotes. gdb_test_no_output will then use the
command name. Fortunately, this is only used once so the test's name is
unique.
> +
> +gdb_test "info break" \
> + "Num Type\[ \]+Disp Enb Address\[\t \]+What.*
> +1\[\t \]+breakpoint keep y.* in foo(.*) at .*$srcfile:$bp1.*
> +2\[\t \]+breakpoint keep y.* in fun_with_a_long_name(.*) at .*$srcfile:$bp2.*" \
> + "info breakpoint - display off"
> +
> +gdb_run_cmd
> +set test "break at fun_with_a_long_name"
> +gdb_continue_to_breakpoint "fun_with_a_long_name (.*) at.*$srcfile.$bp2"
> +
> +set bttable "#0 foo (.*) at.*\[\r\n\]"
> +append bttable "#1 $hex in fun_with_a_long_name (.*) at .*$srcfile:.*\[\r\n\]"
> +append bttable "#2 $hex in goo (.*) at .*$srcfile:.*\[\r\n\]"
> +append bttable "#3 $hex in main (.*) at .*$srcfile:.*"
> +
> +gdb_test "backtrace" $bttable "backtrace - display off"
> +
> +########################
> +# Test with display-linkage-name on
> +
> +gdb_test_no_output "set display-linkage-name on" ""
Likewise.
> +
> +gdb_test "info break" \
> + "Num Type\[ \]+Disp Enb Address\[\t \]+What.*
> +1\[\t \]+breakpoint keep y.* in foo(.*) \\\[_Z3fooPKc\\\] at .*$srcfile:$bp1.*
> +2\[\t \]+breakpoint keep y.* in fun_with_a_long_name(.*) \\\[_Z20fun_with_a_long_\.\.\.\\\] at .*$srcfile:$bp2.*" \
> + "info breakpoint - display on"
> +
> +gdb_run_cmd
> +set test "break at fun_with_a_long_name - display on"
> +gdb_continue_to_breakpoint "fun_with_a_long_name \\\[_Z20fun_with_a_long_...\\\] (.*) at.*$srcfile.$bp2"
> +
> +set bttable "#0 foo \\\[_Z3fooPKc\\\] (.*) at.*\[\r\n\]"
> +append bttable "#1 $hex in fun_with_a_long_name \\\[_Z20fun_with_a_long_\.\.\.\\\] (.*) at .*$srcfile:.*\[\r\n\]"
> +append bttable "#2 $hex in goo \\\[_Z3goov\\\] (.*) at .*$srcfile:.*\[\r\n\]"
> +append bttable "#3 $hex in main (.*) at .*$srcfile:.*"
> +
> +gdb_test "backtrace" $bttable "backtrace - display on"
> +
> +########################
> +# Test set/show display-linkage-name-len
> +
> +gdb_test "show display-linkage-name-len" \
> + "Length of linkage names \\(symbol used by linker\\) to be displayed is 20."
NOTE 1 (see below)
> +
> +gdb_test_no_output "set display-linkage-name-len 10" ""
> +
Likewise.
> +gdb_test "show display-linkage-name-len" \
> + "Length of linkage names \\(symbol used by linker\\) to be displayed is 10."
NOTE 2: These two tests output the same test name. You should supply the
(optional) third parameter to gdb_test (MESSAGE) to uniquely identify
this test. [You could simply use "show display-linkage-name-len 20" and
"show display-linkage-name-len 10".]
For future reference, you can use:
$ make check RUNTESTFLAGS="my-test.exp"
$ cat testsuite/gdb.sum | grep "PASS" | sort | uniq -c | sort -n
to determine whether all the test names in your test file are unique. I
apologize, I missed this earlier.
> +
> +gdb_test "info break" \
> + "Num Type\[ \]+Disp Enb Address\[\t \]+What.*
> +1\[\t \]+breakpoint keep y.* in foo(.*) \\\[_Z3fooPKc\\\] at .*$srcfile:$bp1.*
> +2\[\t \]+breakpoint keep y.* in fun_with_a_long_name(.*) \\\[_Z20fun_wi\.\.\.\\\] at .*$srcfile:$bp2.*" \
> + "info breakpoint - display 10"
> +
> +gdb_run_cmd
> +set test "break at fun_with_a_long_name - display 10"
> +gdb_continue_to_breakpoint "fun_with_a_long_name \\\[_Z20fun_wi\.\.\.\\\] (.*) at .*$srcfile:$bp2"
> +
> +set bttable "#0 foo \\\[_Z3fooPKc\\\] (.*) at.*\[\r\n\]"
> +append bttable "#1 $hex in fun_with_a_long_name \\\[_Z20fun_wi\.\.\.\\\] (.*) at .*$srcfile:.*\[\r\n\]"
> +append bttable "#2 $hex in goo \\\[_Z3goov\\\] (.*) at .*$srcfile:.*\[\r\n\]"
> +append bttable "#3 $hex in main (.*) at .*$srcfile:.*"
> +
> +gdb_test "backtrace" $bttable "backtrace - display 10"
> +
> diff --git a/gdb/top.c b/gdb/top.c
> index 46faaa7..c0f6f25 100644
> --- a/gdb/top.c
> +++ b/gdb/top.c
> @@ -287,6 +287,29 @@ quit_cover (void)
> quit_command ((char *) 0, 0);
> }
> #endif /* defined SIGHUP */
> +
> +/* Flag for whether we want to print linkage name for functions.
> + Length of linkage name to print. */
> +
> +int display_linkage_name = 0; /* Default is no. */
> +int display_linkage_name_len = 20; /* Default is first 20 chars. */
> +
> +static void
> +show_display_linkage_name (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) of functions is %s.\n"),
> + value);
> +}
> +static void
> +show_display_linkage_name_len (struct ui_file *file, int from_tty,
> + struct cmd_list_element *c, const char *value)
> +{
> + fprintf_filtered (file, _("\
> +Length of linkage names (symbol used by linker) to be displayed is %s.\n"),
> + value);
> +}
As silly as it seems, these two new functions need a comment.
> \f
> /* 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
> @@ -1809,7 +1832,22 @@ Use \"on\" to enable the notification, and \"off\" to disable it."),
> When set, GDB uses the specified path to search for data files."),
> set_gdb_datadir, NULL,
> &setlist,
> - &showlist);
> + &showlist);
> +
> + add_setshow_boolean_cmd ("display-linkage-name", class_support, &display_linkage_name, _("\
> +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_display_linkage_name,
> + &setlist, &showlist);
> +
> + add_setshow_zinteger_cmd ("display-linkage-name-len", class_support, &display_linkage_name_len, _("\
> +Set number of characters of linkage name to display."), _("\
> +Show number of characters of linkage name to display."), NULL,
> + NULL,
> + show_display_linkage_name_len,
> + &setlist, &showlist);
> +
> }
>
> void
After you fix those trivial things, I don't think there is anything more
for me to review. You've already got documentation approval from Eli, so
all that's left is a global maintainer's stamp of approval.
Keith
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Revised display-linkage-name
2013-07-22 21:55 ` Keith Seitz
@ 2013-07-24 15:55 ` Michael Eager
2013-07-26 18:42 ` Tom Tromey
0 siblings, 1 reply; 19+ messages in thread
From: Michael Eager @ 2013-07-24 15:55 UTC (permalink / raw)
To: Keith Seitz; +Cc: gdb-patches@sourceware.org ml
[-- Attachment #1: Type: text/plain, Size: 3113 bytes --]
On 07/22/13 14:55, Keith Seitz wrote:
> On 07/22/2013 01:06 PM, Michael Eager wrote:
>> On 07/22/13 10:48, Keith Seitz wrote:
>>> On 07/17/2013 11:51 AM, Michael Eager wrote:
>>
>>>> void
>>>> +annotate_linkage_name (void)
>>>> +{
>>>> + if (annotation_level == 2)
>>>> + printf_filtered (("\n\032\032linkage_name\n"));
>>>> +}
>>>> +
>>>
>>> This is still missing a (trivial) comment. [IIRC, we require comments
>>> for *all* functions, even if
>>> they are pretty trivial.]
>>
>> The Changelog contains
>> * annotate.c (annotate_linkage_name): New.
>> * annotate.h (annotate_linkage_name): New decl.
>>
>> Is something else needed?
>
> Yes, all functions need a comment, e.g.,
>
> /* Emit an annotation for a symbol's linkage name. */
>
> void
> annotate_linkage_name (void)
> {
> /* ... */
> }
This is pretty pointless busywork, serving no useful purpose.
There are 66 annotate_<whatever> functions in annotate.c. Only
one function has a comment. This comment actually provides
additional information which would not simply repeat the function name.
I added a comment. Now there are two commented annotate functions,
one of which is meaningful.
>> diff --git a/gdb/testsuite/gdb.cp/display-linkage-name.exp
>> +
>> +gdb_test_no_output "set display-linkage-name off" ""
>
> You can omit the trailing quotes. gdb_test_no_output will then use the command name. Fortunately,
> this is only used once so the test's name is unique.
Done.
>> +gdb_test_no_output "set display-linkage-name on" ""
>
> Likewise.
Done.
>
> NOTE 2: These two tests output the same test name. You should supply the (optional) third parameter
> to gdb_test (MESSAGE) to uniquely identify this test. [You could simply use "show
> display-linkage-name-len 20" and "show display-linkage-name-len 10".]
>
> For future reference, you can use:
>
> $ make check RUNTESTFLAGS="my-test.exp"
> $ cat testsuite/gdb.sum | grep "PASS" | sort | uniq -c | sort -n
Or
$ cat testsuite/gdb.sum | grep "PASS" | sort | uniq -d
>> +static void
>> +show_display_linkage_name (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) of functions is %s.\n"),
>> + value);
>> +}
>> +static void
>> +show_display_linkage_name_len (struct ui_file *file, int from_tty,
>> + struct cmd_list_element *c, const char *value)
>> +{
>> + fprintf_filtered (file, _("\
>> +Length of linkage names (symbol used by linker) to be displayed is %s.\n"),
>> + value);
>> +}
>
> As silly as it seems, these two new functions need a comment.
Done. Silly is perhaps a nicer term than I would use.
> After you fix those trivial things, I don't think there is anything more for me to review. You've
> already got documentation approval from Eli, so all that's left is a global maintainer's stamp of
> approval.
Thanks for your help.
Revised (hopefully final) patch attached.
--
Michael Eager eager@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306 650-325-8077
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-GDB-display-linkage-name-command.patch --]
[-- Type: text/x-patch; name="0001-GDB-display-linkage-name-command.patch", Size: 24438 bytes --]
From 87273ea62aa93d1d0aad7e9b1223044becc70e5f Mon Sep 17 00:00:00 2001
From: Michael Eager <eager@eagercon.com>
Date: Wed, 24 Jul 2013 08:40:40 -0700
Subject: [PATCH] GDB - display linkage name command
---
gdb/NEWS | 14 ++++
gdb/ada-lang.c | 5 +-
gdb/annotate.c | 9 ++
gdb/annotate.h | 2 +
gdb/breakpoint.c | 31 +++++++
gdb/defs.h | 1 +
gdb/disasm.c | 4 +-
gdb/doc/gdb.texinfo | 28 ++++++-
gdb/printcmd.c | 43 +++++++++-
gdb/python/py-frame.c | 2 +-
gdb/stack.c | 42 +++++++++-
gdb/stack.h | 3 +-
gdb/testsuite/gdb.cp/display-linkage-name.cc | 36 ++++++++
gdb/testsuite/gdb.cp/display-linkage-name.exp | 116 ++++++++++++++++++++++++++
gdb/top.c | 43 +++++++++-
gdb/top.h | 2 +
16 files changed, 367 insertions(+), 14 deletions(-)
create mode 100644 gdb/testsuite/gdb.cp/display-linkage-name.cc
create mode 100644 gdb/testsuite/gdb.cp/display-linkage-name.exp
diff --git a/gdb/NEWS b/gdb/NEWS
index e469f1e..ac62062 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -56,6 +56,20 @@ show range-stepping
--configuration
Display the details of GDB configure-time options.
+* 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
+ prefixes 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.
+
+set|show display-linkage-name-len
+
+ Set the maximum number of characters to display in the linkage name,
+ if display-linkage-name is on. The default is 20.
+
* The command 'tsave' can now support new option '-ctf' to save trace
buffer in Common Trace Format.
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index dc5f2b6..3430e3f 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -11114,6 +11114,7 @@ is_known_support_routine (struct frame_info *frame)
{
struct symtab_and_line sal;
char *func_name;
+ const char *linkname;
enum language func_lang;
int i;
const char *fullname;
@@ -11152,7 +11153,7 @@ is_known_support_routine (struct frame_info *frame)
/* Check whether the function is a GNAT-generated entity. */
- find_frame_funname (frame, &func_name, &func_lang, NULL);
+ find_frame_funname (frame, &func_name, NULL, &func_lang, NULL);
if (func_name == NULL)
return 1;
@@ -11227,7 +11228,7 @@ ada_unhandled_exception_name_addr_from_raise (void)
char *func_name;
enum language func_lang;
- find_frame_funname (fi, &func_name, &func_lang, NULL);
+ find_frame_funname (fi, &func_name, NULL, &func_lang, NULL);
if (func_name != NULL)
{
make_cleanup (xfree, func_name);
diff --git a/gdb/annotate.c b/gdb/annotate.c
index ccba5fe..6f8d811 100644
--- a/gdb/annotate.c
+++ b/gdb/annotate.c
@@ -581,6 +581,15 @@ breakpoint_changed (struct breakpoint *b)
annotate_breakpoints_invalid ();
}
+/* Annotate linkage name. */
+
+void
+annotate_linkage_name (void)
+{
+ if (annotation_level == 2)
+ printf_filtered (("\n\032\032linkage_name\n"));
+}
+
void
_initialize_annotate (void)
{
diff --git a/gdb/annotate.h b/gdb/annotate.h
index 72c4f19..33a9a0e 100644
--- a/gdb/annotate.h
+++ b/gdb/annotate.h
@@ -98,5 +98,7 @@ extern void annotate_elt_rep_end (void);
extern void annotate_elt (void);
extern void annotate_array_section_end (void);
+extern void annotate_linkage_name (void);
+
extern void (*deprecated_annotate_signalled_hook) (void);
extern void (*deprecated_annotate_signal_hook) (void);
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 4d09b30..ba37c5e 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -5704,6 +5704,37 @@ print_breakpoint_location (struct breakpoint *b,
ui_out_text (uiout, "in ");
ui_out_field_string (uiout, "func",
SYMBOL_PRINT_NAME (sym));
+ if (display_linkage_name)
+ {
+ struct bound_minimal_symbol msymbol =
+ lookup_minimal_symbol_by_pc (loc->address);
+
+ if (msymbol.minsym != NULL
+ && strcmp (SYMBOL_LINKAGE_NAME (msymbol.minsym),
+ SYMBOL_PRINT_NAME (sym)) != 0)
+ {
+ ui_out_text (uiout, " [");
+
+ if (strlen (SYMBOL_LINKAGE_NAME (msymbol.minsym))
+ > display_linkage_name_len)
+ {
+ char *lname = alloca (display_linkage_name_len + 4);
+
+ strncpy (lname, SYMBOL_LINKAGE_NAME (msymbol.minsym),
+ display_linkage_name_len);
+ lname[display_linkage_name_len] = '\0';
+ strcat (lname, "...");
+ ui_out_field_string (uiout, "linkage-name", lname);
+ }
+ else
+ {
+ ui_out_field_string (uiout, "linkage-name",
+ SYMBOL_LINKAGE_NAME (msymbol.minsym));
+ }
+
+ ui_out_text (uiout, "]");
+ }
+ }
ui_out_text (uiout, " ");
ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
ui_out_text (uiout, "at ");
diff --git a/gdb/defs.h b/gdb/defs.h
index 014d7d4..15e9a54 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -336,6 +336,7 @@ extern int build_address_symbolic (struct gdbarch *,
CORE_ADDR addr,
int do_demangle,
char **name,
+ char **linkname,
int *offset,
char **filename,
int *line,
diff --git a/gdb/disasm.c b/gdb/disasm.c
index e643c2d..396dce9 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -127,8 +127,8 @@ dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
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, NULL, &offset,
+ &filename, &line, &unmapped))
{
/* We don't care now about line, filename and
unmapped. But we might in the future. */
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index fae54e4..d230e01 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -15933,8 +15933,31 @@ line 1574.
@}
(@value{GDBP})
@end smallexample
-@end table
+@kindex set display-linkage-name
+@cindex list linkage 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 linkage name for the symbol name within brackets if it is
+different from the name in the source.
+
+The linkage name is the name used by the linker for a symbol. This may be
+the same as the symbol's name in the source, or may be different if the compiler
+adds a prefix to the name (for example, an underscore) or modifies it, such
+as by C@t{++} name mangling.
+
+This is different from "set print asm-demangle on" which only displays
+the linkage name for C@t{++} symbols and does not display the source name.
+
+@kindex show display-linkage-name-len
+@itemx show display-linkage-name-len @var{len}
+Set the maximum number of characters of linkage name to display. The
+@code{show} command displays the current setting. The default is @code{20}.
+@end table
@node Altering
@chapter Altering Execution
@@ -29250,6 +29273,9 @@ is not.
@item what
Some extra data, the exact contents of which are type-dependent.
+@item linkage-name
+The name used by the linker for this function.
+
@end table
For example, here is what the output of @code{-break-insert}
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 99d4dba..de174d6 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -51,6 +51,7 @@
#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. */
@@ -569,17 +570,19 @@ print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr,
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 name, linkname, and filename. */
struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name);
make_cleanup (free_current_contents, &filename);
+ make_cleanup (free_current_contents, &linkname);
- 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 +594,28 @@ print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr,
else
fputs_filtered ("<", stream);
fputs_filtered (name, stream);
+
+ /* Print linkage name after source name if requested and different. */
+ if (display_linkage_name
+ && linkname != NULL && strcmp (name, linkname) != 0)
+ {
+ fputs_filtered (" [", stream);
+
+ if (strlen (linkname) > display_linkage_name_len)
+ {
+ char *lname = alloca (display_linkage_name_len + 4);
+
+ strncpy (lname, linkname, display_linkage_name_len);
+ lname[display_linkage_name_len] = '\0';
+ strcat (lname, "...");
+ fputs_filtered (lname, stream);
+ }
+ else
+ fputs_filtered (linkname, stream);
+
+ fputs_filtered ("]", stream);
+ }
+
if (offset != 0)
fprintf_filtered (stream, "+%u", (unsigned int) offset);
@@ -623,6 +648,7 @@ build_address_symbolic (struct gdbarch *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 +663,10 @@ build_address_symbolic (struct gdbarch *gdbarch,
/* Let's say it is mapped (not unmapped). */
*unmapped = 0;
+ /* Let's say the link name is the same as the symbol name. */
+ if (linkname != NULL)
+ *linkname = NULL;
+
/* Determine if the address is in an overlay, and whether it is
mapped. */
if (overlay_debugging)
@@ -740,6 +770,13 @@ build_address_symbolic (struct gdbarch *gdbarch,
*line = sal.line;
}
}
+
+ /* If we have both symbol names and they are different, let caller know. */
+ if (linkname != NULL && msymbol != NULL && symbol != NULL
+ && strcmp (SYMBOL_LINKAGE_NAME (msymbol),
+ SYMBOL_LINKAGE_NAME (symbol)) != 0)
+ *linkname = xstrdup (SYMBOL_LINKAGE_NAME (msymbol));
+
return 0;
}
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index f960b08..6b48140 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -131,7 +131,7 @@ frapy_name (PyObject *self, PyObject *args)
{
FRAPY_REQUIRE_VALID (self, frame);
- find_frame_funname (frame, &name, &lang, NULL);
+ find_frame_funname (frame, &name, NULL, &lang, NULL);
}
if (except.reason < 0)
diff --git a/gdb/stack.c b/gdb/stack.c
index 313d57f..49d6acb 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -55,6 +55,7 @@
#include "psymtab.h"
#include "symfile.h"
#include "python/python.h"
+#include "top.h"
void (*deprecated_selected_frame_level_changed_hook) (int);
@@ -1000,15 +1001,20 @@ get_last_displayed_sal (struct symtab_and_line *sal)
/* Attempt to obtain the FUNNAME, FUNLANG and optionally FUNCP of the function
- corresponding to FRAME. FUNNAME needs to be freed by the caller. */
+ corresponding to FRAME. FUNNAME needs to be freed by the caller.
+ Set LINKNAME to linkage name (symbol used by linker) if LINKNAME is non-null
+ and linkage name differs from source name. */
void
find_frame_funname (struct frame_info *frame, char **funname,
- enum language *funlang, struct symbol **funcp)
+ const char **linkname, enum language *funlang,
+ struct symbol **funcp)
{
struct symbol *func;
*funname = NULL;
+ if (linkname != NULL)
+ *linkname = NULL;
*funlang = language_unknown;
if (funcp)
*funcp = NULL;
@@ -1044,6 +1050,11 @@ find_frame_funname (struct frame_info *frame, char **funname,
else
memset (&msymbol, 0, sizeof (msymbol));
+ if (linkname != NULL && msymbol.minsym != NULL
+ && strcmp (SYMBOL_LINKAGE_NAME (msymbol.minsym),
+ SYMBOL_LINKAGE_NAME (func)) != 0)
+ *linkname = SYMBOL_LINKAGE_NAME (msymbol.minsym);
+
if (msymbol.minsym != NULL
&& (SYMBOL_VALUE_ADDRESS (msymbol.minsym)
> BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
@@ -1102,6 +1113,7 @@ print_frame (struct frame_info *frame, int print_level,
struct gdbarch *gdbarch = get_frame_arch (frame);
struct ui_out *uiout = current_uiout;
char *funname = NULL;
+ const char *linkname = NULL;
enum language funlang = language_unknown;
struct ui_file *stb;
struct cleanup *old_chain, *list_chain;
@@ -1115,7 +1127,7 @@ print_frame (struct frame_info *frame, int print_level,
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);
make_cleanup (xfree, funname);
annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
@@ -1147,6 +1159,30 @@ print_frame (struct frame_info *frame, int print_level,
fprintf_symbol_filtered (stb, funname ? funname : "??",
funlang, DMGL_ANSI);
ui_out_field_stream (uiout, "func", stb);
+
+ /* Print linkage name after source name if requested and different. */
+ if ((display_linkage_name || ui_out_is_mi_like_p (uiout))
+ && linkname != NULL && strcmp (funname, linkname) != 0)
+ {
+ annotate_linkage_name ();
+ ui_out_text (uiout, " [");
+
+ if (strlen (linkname) > display_linkage_name_len)
+ {
+ char *lname = alloca (display_linkage_name_len + 4);
+
+ strncpy (lname, linkname, display_linkage_name_len);
+ lname[display_linkage_name_len] = '\0';
+ strcat (lname, "...");
+ ui_out_text (uiout, lname);
+ }
+ else
+ ui_out_text (uiout, linkname);
+
+ ui_out_text (uiout, "]");
+ ui_out_field_stream (uiout, "linkage_name", stb);
+ }
+
ui_out_wrap_hint (uiout, " ");
annotate_frame_args ();
diff --git a/gdb/stack.h b/gdb/stack.h
index 4badf19..9248c85 100644
--- a/gdb/stack.h
+++ b/gdb/stack.h
@@ -23,7 +23,8 @@
void select_frame_command (char *level_exp, int from_tty);
void find_frame_funname (struct frame_info *frame, 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,
diff --git a/gdb/testsuite/gdb.cp/display-linkage-name.cc b/gdb/testsuite/gdb.cp/display-linkage-name.cc
new file mode 100644
index 0000000..d9db673
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/display-linkage-name.cc
@@ -0,0 +1,36 @@
+/* This test script is part of GDB, the GNU debugger.
+
+ Copyright 2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+void foo (const char *msg)
+{
+} /* set breakpoint 1 here */
+
+void fun_with_a_long_name (int i, const char *s, double d)
+{
+ foo ("Hello"); /* set breakpoint 2 here */
+}
+
+void goo (void)
+{
+ fun_with_a_long_name (1, "abc", 3.14);
+}
+
+int main (void)
+{
+ goo();
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.cp/display-linkage-name.exp b/gdb/testsuite/gdb.cp/display-linkage-name.exp
new file mode 100644
index 0000000..1f56e18
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/display-linkage-name.exp
@@ -0,0 +1,116 @@
+# Copyright 2013 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This file was written by Michael Eager (eager@eagercon.com).
+
+if { [skip_cplus_tests] } { continue }
+
+standard_testfile .cc
+
+if {[get_compiler_info "c++"]} {
+ return -1
+}
+
+if { [prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}] } {
+ return -1
+}
+
+# set break at functions
+
+set bp1 [gdb_get_line_number "set breakpoint 1 here"]
+set bp2 [gdb_get_line_number "set breakpoint 2 here"]
+
+if {![gdb_breakpoint "foo"]} {
+ fail "set breakpoint foo"
+}
+
+if {![gdb_breakpoint "fun_with_a_long_name"]} {
+ fail "set breakpoint fun_with_a_long_name"
+}
+
+########################
+# Test with display-linkage-name off
+
+gdb_test_no_output "set display-linkage-name off"
+
+gdb_test "info break" \
+ "Num Type\[ \]+Disp Enb Address\[\t \]+What.*
+1\[\t \]+breakpoint keep y.* in foo(.*) at .*$srcfile:$bp1.*
+2\[\t \]+breakpoint keep y.* in fun_with_a_long_name(.*) at .*$srcfile:$bp2.*" \
+ "info breakpoint - display off"
+
+gdb_run_cmd
+set test "break at fun_with_a_long_name"
+gdb_continue_to_breakpoint "fun_with_a_long_name (.*) at.*$srcfile.$bp2"
+
+set bttable "#0 foo (.*) at.*\[\r\n\]"
+append bttable "#1 $hex in fun_with_a_long_name (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#2 $hex in goo (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#3 $hex in main (.*) at .*$srcfile:.*"
+
+gdb_test "backtrace" $bttable "backtrace - display off"
+
+########################
+# Test with display-linkage-name on
+
+gdb_test_no_output "set display-linkage-name on"
+
+gdb_test "info break" \
+ "Num Type\[ \]+Disp Enb Address\[\t \]+What.*
+1\[\t \]+breakpoint keep y.* in foo(.*) \\\[_Z3fooPKc\\\] at .*$srcfile:$bp1.*
+2\[\t \]+breakpoint keep y.* in fun_with_a_long_name(.*) \\\[_Z20fun_with_a_long_\.\.\.\\\] at .*$srcfile:$bp2.*" \
+ "info breakpoint - display on"
+
+gdb_run_cmd
+set test "break at fun_with_a_long_name - display on"
+gdb_continue_to_breakpoint "fun_with_a_long_name \\\[_Z20fun_with_a_long_...\\\] (.*) at.*$srcfile.$bp2"
+
+set bttable "#0 foo \\\[_Z3fooPKc\\\] (.*) at.*\[\r\n\]"
+append bttable "#1 $hex in fun_with_a_long_name \\\[_Z20fun_with_a_long_\.\.\.\\\] (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#2 $hex in goo \\\[_Z3goov\\\] (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#3 $hex in main (.*) at .*$srcfile:.*"
+
+gdb_test "backtrace" $bttable "backtrace - display on"
+
+########################
+# Test set/show display-linkage-name-len
+
+gdb_test "show display-linkage-name-len" \
+ "Length of linkage names \\(symbol used by linker\\) to be displayed is 20." \
+ "show display linkage name 20"
+
+gdb_test_no_output "set display-linkage-name-len 10"
+
+gdb_test "show display-linkage-name-len" \
+ "Length of linkage names \\(symbol used by linker\\) to be displayed is 10." \
+ "show display linkage name 10"
+
+gdb_test "info break" \
+ "Num Type\[ \]+Disp Enb Address\[\t \]+What.*
+1\[\t \]+breakpoint keep y.* in foo(.*) \\\[_Z3fooPKc\\\] at .*$srcfile:$bp1.*
+2\[\t \]+breakpoint keep y.* in fun_with_a_long_name(.*) \\\[_Z20fun_wi\.\.\.\\\] at .*$srcfile:$bp2.*" \
+ "info breakpoint - display 10"
+
+gdb_run_cmd
+set test "break at fun_with_a_long_name - display 10"
+gdb_continue_to_breakpoint "fun_with_a_long_name \\\[_Z20fun_wi\.\.\.\\\] (.*) at .*$srcfile:$bp2"
+
+set bttable "#0 foo \\\[_Z3fooPKc\\\] (.*) at.*\[\r\n\]"
+append bttable "#1 $hex in fun_with_a_long_name \\\[_Z20fun_wi\.\.\.\\\] (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#2 $hex in goo \\\[_Z3goov\\\] (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#3 $hex in main (.*) at .*$srcfile:.*"
+
+gdb_test "backtrace" $bttable "backtrace - display 10"
+
diff --git a/gdb/top.c b/gdb/top.c
index 46faaa7..35efc44 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -287,6 +287,32 @@ quit_cover (void)
quit_command ((char *) 0, 0);
}
#endif /* defined SIGHUP */
+
+/* Flag for whether we want to print linkage name for functions.
+ Length of linkage name to print. */
+
+int display_linkage_name = 0; /* Default is no. */
+int display_linkage_name_len = 20; /* Default is first 20 chars. */
+
+/* Show display-linkage-name. */
+static void
+show_display_linkage_name (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) of functions is %s.\n"),
+ value);
+}
+
+/* Show display-linkage-name-len. */
+static void
+show_display_linkage_name_len (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c, const char *value)
+{
+ fprintf_filtered (file, _("\
+Length of linkage names (symbol used by linker) to be displayed is %s.\n"),
+ value);
+}
\f
/* 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
@@ -1809,7 +1835,22 @@ Use \"on\" to enable the notification, and \"off\" to disable it."),
When set, GDB uses the specified path to search for data files."),
set_gdb_datadir, NULL,
&setlist,
- &showlist);
+ &showlist);
+
+ add_setshow_boolean_cmd ("display-linkage-name", class_support, &display_linkage_name, _("\
+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_display_linkage_name,
+ &setlist, &showlist);
+
+ add_setshow_zinteger_cmd ("display-linkage-name-len", class_support, &display_linkage_name_len, _("\
+Set number of characters of linkage name to display."), _("\
+Show number of characters of linkage name to display."), NULL,
+ NULL,
+ show_display_linkage_name_len,
+ &setlist, &showlist);
+
}
void
diff --git a/gdb/top.h b/gdb/top.h
index 2f70539..5acb311 100644
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -26,6 +26,8 @@ extern int saved_command_line_size;
extern FILE *instream;
extern int in_user_command;
extern int confirm;
+extern int display_linkage_name;
+extern int display_linkage_name_len;
extern char gdb_dirbuf[1024];
extern int inhibit_gdbinit;
extern const char gdbinit[];
--
1.8.1.4
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Revised display-linkage-name
2013-07-24 15:55 ` Michael Eager
@ 2013-07-26 18:42 ` Tom Tromey
2013-07-26 20:18 ` Michael Eager
0 siblings, 1 reply; 19+ messages in thread
From: Tom Tromey @ 2013-07-26 18:42 UTC (permalink / raw)
To: Michael Eager; +Cc: Keith Seitz, gdb-patches@sourceware.org ml
>>>>> "Michael" == Michael Eager <eager@eagerm.com> writes:
Michael> This is pretty pointless busywork, serving no useful purpose.
It's part of the currently-agreed-upon coding style.
You're always welcome to propose changes.
Michael> +set|show display-linkage-name-len
It's more gdb-ish to spell out "length".
Michael> + /* Print linkage name after source name if requested and different. */
Michael> + if ((display_linkage_name || ui_out_is_mi_like_p (uiout))
Michael> + && linkname != NULL && strcmp (funname, linkname) != 0)
Michael> + {
Michael> + annotate_linkage_name ();
FWIW there isn't much need to add new annotations. Annotations are
officially deprecated. It's fine by me if you want to leave this in for
some reason though.
Michael> + ui_out_text (uiout, " [");
Michael> +
Michael> + if (strlen (linkname) > display_linkage_name_len)
Michael> + {
Michael> + char *lname = alloca (display_linkage_name_len + 4);
Michael> +
Michael> + strncpy (lname, linkname, display_linkage_name_len);
Michael> + lname[display_linkage_name_len] = '\0';
Michael> + strcat (lname, "...");
Michael> + ui_out_text (uiout, lname);
Michael> + }
Michael> + else
Michael> + ui_out_text (uiout, linkname);
Michael> +
Michael> + ui_out_text (uiout, "]");
Michael> + ui_out_field_stream (uiout, "linkage_name", stb);
This is emitting the linkage name using ui_out_text. That is wrong for
MI.
Then this emits the linkage_name field with the contents from "stb" --
which is reusing a result computed previously (look up for the
fprintf_symbol_filtered).
I tend to think that limiting the name length should only be done in the
not-MI case. That is, for MI, it is better to always print the whole
thing.
Tom
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Revised display-linkage-name
2013-07-26 18:42 ` Tom Tromey
@ 2013-07-26 20:18 ` Michael Eager
2013-07-29 17:48 ` Tom Tromey
0 siblings, 1 reply; 19+ messages in thread
From: Michael Eager @ 2013-07-26 20:18 UTC (permalink / raw)
To: Tom Tromey; +Cc: Keith Seitz, gdb-patches@sourceware.org ml
On 07/26/13 11:41, Tom Tromey wrote:
>>>>>> "Michael" == Michael Eager <eager@eagerm.com> writes:
>
> Michael> +set|show display-linkage-name-len
>
> It's more gdb-ish to spell out "length".
OK.
> Michael> + /* Print linkage name after source name if requested and different. */
> Michael> + if ((display_linkage_name || ui_out_is_mi_like_p (uiout))
> Michael> + && linkname != NULL && strcmp (funname, linkname) != 0)
> Michael> + {
> Michael> + annotate_linkage_name ();
>
> FWIW there isn't much need to add new annotations. Annotations are
> officially deprecated. It's fine by me if you want to leave this in for
> some reason though.
I added the annotations at your request (4/19/13):
>> I think for MI it is better to make this a real field.
>> Also I wonder whether this should be emitted unconditionally if
>> mi-like. Say:
Perhaps I misunderstood what you meant by "make this a real field".
> Michael> + ui_out_text (uiout, " [");
> Michael> +
> Michael> + if (strlen (linkname) > display_linkage_name_len)
> Michael> + {
> Michael> + char *lname = alloca (display_linkage_name_len + 4);
> Michael> +
> Michael> + strncpy (lname, linkname, display_linkage_name_len);
> Michael> + lname[display_linkage_name_len] = '\0';
> Michael> + strcat (lname, "...");
> Michael> + ui_out_text (uiout, lname);
> Michael> + }
> Michael> + else
> Michael> + ui_out_text (uiout, linkname);
> Michael> +
> Michael> + ui_out_text (uiout, "]");
> Michael> + ui_out_field_stream (uiout, "linkage_name", stb);
>
> This is emitting the linkage name using ui_out_text. That is wrong for
> MI.
What should it be? ui_out_field_string()? Something else?
> Then this emits the linkage_name field with the contents from "stb" --
> which is reusing a result computed previously (look up for the
> fprintf_symbol_filtered).
>
> I tend to think that limiting the name length should only be done in the
> not-MI case. That is, for MI, it is better to always print the whole
> thing.
OK.
--
Michael Eager eager@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306 650-325-8077
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Revised display-linkage-name
2013-07-26 20:18 ` Michael Eager
@ 2013-07-29 17:48 ` Tom Tromey
2013-08-01 19:36 ` Michael Eager
0 siblings, 1 reply; 19+ messages in thread
From: Tom Tromey @ 2013-07-29 17:48 UTC (permalink / raw)
To: Michael Eager; +Cc: Keith Seitz, gdb-patches@sourceware.org ml
>>>>> "Michael" == Michael Eager <eager@eagerm.com> writes:
Tom> FWIW there isn't much need to add new annotations. Annotations are
Tom> officially deprecated. It's fine by me if you want to leave this in for
Tom> some reason though.
Michael> I added the annotations at your request (4/19/13):
Tom>> I think for MI it is better to make this a real field.
Tom>> Also I wonder whether this should be emitted unconditionally if
Tom>> mi-like. Say:
Michael> Perhaps I misunderstood what you meant by "make this a real field".
Yeah, I'm sorry I wasn't clearer.
"annotations" refers to annotate.[ch] and the corresponding command-line
option. This is an old way to communicate gdb state changes to a GUI,
mainly Emacs.
By "a real field" I meant using ui_out_*.
Michael> + ui_out_text (uiout, linkname);
Tom> This is emitting the linkage name using ui_out_text. That is wrong for
Tom> MI.
It maybe wasn't clear but I was referring to the quoted line above when
I said this.
Michael> What should it be? ui_out_field_string()? Something else?
Yes, ui_out_field_string.
Tom
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Revised display-linkage-name
2013-07-29 17:48 ` Tom Tromey
@ 2013-08-01 19:36 ` Michael Eager
2013-08-01 20:56 ` Tom Tromey
0 siblings, 1 reply; 19+ messages in thread
From: Michael Eager @ 2013-08-01 19:36 UTC (permalink / raw)
To: Tom Tromey; +Cc: Keith Seitz, gdb-patches@sourceware.org ml
[-- Attachment #1: Type: text/plain, Size: 2435 bytes --]
On 07/29/13 10:48, Tom Tromey wrote:
>>>>>> "Michael" == Michael Eager <eager@eagerm.com> writes:
>
> Tom> FWIW there isn't much need to add new annotations. Annotations are
> Tom> officially deprecated. It's fine by me if you want to leave this in for
> Tom> some reason though.
>
> Michael> I added the annotations at your request (4/19/13):
>
> Tom>> I think for MI it is better to make this a real field.
> Tom>> Also I wonder whether this should be emitted unconditionally if
> Tom>> mi-like. Say:
>
> Michael> Perhaps I misunderstood what you meant by "make this a real field".
>
> Yeah, I'm sorry I wasn't clearer.
>
> "annotations" refers to annotate.[ch] and the corresponding command-line
> option. This is an old way to communicate gdb state changes to a GUI,
> mainly Emacs.
>
> By "a real field" I meant using ui_out_*.
>
> Michael> + ui_out_text (uiout, linkname);
>
> Tom> This is emitting the linkage name using ui_out_text. That is wrong for
> Tom> MI.
>
> It maybe wasn't clear but I was referring to the quoted line above when
> I said this.
>
> Michael> What should it be? ui_out_field_string()? Something else?
>
> Yes, ui_out_field_string.
I eliminated the annotations and made the other requested changes.
gdb/
2013-08-01 Michael Eager <eager@eagercon.com>
* NEWS: Announcement.
* ada-lang.c: Update calls to find_frame_funname.
* disasm.c: Likewise.
* python/py-frame.c: Likewise.
* breakpoint.c (print_breakpoint_location): Print linkage name.
* defs.h (build_address_symbolic): Add linkname arg.
* printcmd.c (print_address_symbolic): Print linkage name.
(build_address_symbolic): Return linkage name.
* stack.c (find_frame_funname): Return linkage name.
(print_frame): Print linkage name.
* stack.h (find_frame_funname): Update declaration.
* top.c (display_linkage_name, display_linkage_name_length): New.
(show_display_linkage_name, show_display_linkage_name_length): New cmds.
* top.h (display_linkage_name, display_linkage_name_length): Declare.
gdb/doc
2013-08-01 Michael Eager <eager@eagercon.com>
* gdb.texinfo: Add description.
gdb/testsuite
2013-08-01 Michael Eager <eager@eagercon.com>
* gdb.cp/display-linkage-name.exp: New.
* gdb.cp/display-linkage-name.cc: New.
--
Michael Eager eager@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306 650-325-8077
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-GDB-display-linkage-name-command.patch --]
[-- Type: text/x-patch; name="0001-GDB-display-linkage-name-command.patch", Size: 23540 bytes --]
From 0d5e9c5b5458bb574319df01bca0b6f7a64a3b37 Mon Sep 17 00:00:00 2001
From: Michael Eager <eager@eagercon.com>
Date: Thu, 1 Aug 2013 11:56:03 -0700
Subject: [PATCH] GDB - display linkage name command
---
gdb/NEWS | 14 +++
gdb/ada-lang.c | 5 +-
gdb/breakpoint.c | 31 +++++++
gdb/defs.h | 1 +
gdb/disasm.c | 4 +-
gdb/doc/gdb.texinfo | 28 ++++++-
gdb/printcmd.c | 43 +++++++++-
gdb/python/py-frame.c | 2 +-
gdb/stack.c | 41 ++++++++-
gdb/stack.h | 3 +-
gdb/testsuite/gdb.cp/display-linkage-name.cc | 36 ++++++++
gdb/testsuite/gdb.cp/display-linkage-name.exp | 116 +++++++++++++++++++++++++
gdb/top.c | 44 +++++++++-
gdb/top.h | 2 +
14 files changed, 356 insertions(+), 14 deletions(-)
create mode 100644 gdb/testsuite/gdb.cp/display-linkage-name.cc
create mode 100644 gdb/testsuite/gdb.cp/display-linkage-name.exp
diff --git a/gdb/NEWS b/gdb/NEWS
index 6ee82f7..8dc0165 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -61,6 +61,20 @@ show range-stepping
--configuration
Display the details of GDB configure-time options.
+* 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
+ prefixes 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.
+
+set|show display-linkage-name-length
+
+ Set the maximum number of characters to display in the linkage name,
+ if display-linkage-name is on. The default is 20.
+
* The command 'tsave' can now support new option '-ctf' to save trace
buffer in Common Trace Format.
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index dc5f2b6..3430e3f 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -11114,6 +11114,7 @@ is_known_support_routine (struct frame_info *frame)
{
struct symtab_and_line sal;
char *func_name;
+ const char *linkname;
enum language func_lang;
int i;
const char *fullname;
@@ -11152,7 +11153,7 @@ is_known_support_routine (struct frame_info *frame)
/* Check whether the function is a GNAT-generated entity. */
- find_frame_funname (frame, &func_name, &func_lang, NULL);
+ find_frame_funname (frame, &func_name, NULL, &func_lang, NULL);
if (func_name == NULL)
return 1;
@@ -11227,7 +11228,7 @@ ada_unhandled_exception_name_addr_from_raise (void)
char *func_name;
enum language func_lang;
- find_frame_funname (fi, &func_name, &func_lang, NULL);
+ find_frame_funname (fi, &func_name, NULL, &func_lang, NULL);
if (func_name != NULL)
{
make_cleanup (xfree, func_name);
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 1e89407..66be85c 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -5735,6 +5735,37 @@ print_breakpoint_location (struct breakpoint *b,
ui_out_text (uiout, "in ");
ui_out_field_string (uiout, "func",
SYMBOL_PRINT_NAME (sym));
+ if (display_linkage_name)
+ {
+ struct bound_minimal_symbol msymbol =
+ lookup_minimal_symbol_by_pc (loc->address);
+
+ if (msymbol.minsym != NULL
+ && strcmp (SYMBOL_LINKAGE_NAME (msymbol.minsym),
+ SYMBOL_PRINT_NAME (sym)) != 0)
+ {
+ ui_out_text (uiout, " [");
+
+ if (strlen (SYMBOL_LINKAGE_NAME (msymbol.minsym))
+ > display_linkage_name_length)
+ {
+ char *lname = alloca (display_linkage_name_length + 4);
+
+ strncpy (lname, SYMBOL_LINKAGE_NAME (msymbol.minsym),
+ display_linkage_name_length);
+ lname[display_linkage_name_length] = '\0';
+ strcat (lname, "...");
+ ui_out_field_string (uiout, "linkage-name", lname);
+ }
+ else
+ {
+ ui_out_field_string (uiout, "linkage-name",
+ SYMBOL_LINKAGE_NAME (msymbol.minsym));
+ }
+
+ ui_out_text (uiout, "]");
+ }
+ }
ui_out_text (uiout, " ");
ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what"));
ui_out_text (uiout, "at ");
diff --git a/gdb/defs.h b/gdb/defs.h
index 014d7d4..15e9a54 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -336,6 +336,7 @@ extern int build_address_symbolic (struct gdbarch *,
CORE_ADDR addr,
int do_demangle,
char **name,
+ char **linkname,
int *offset,
char **filename,
int *line,
diff --git a/gdb/disasm.c b/gdb/disasm.c
index e643c2d..396dce9 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -127,8 +127,8 @@ dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
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, NULL, &offset,
+ &filename, &line, &unmapped))
{
/* We don't care now about line, filename and
unmapped. But we might in the future. */
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index cb393e8..e7e557c 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -15950,8 +15950,31 @@ line 1574.
@}
(@value{GDBP})
@end smallexample
-@end table
+@kindex set display-linkage-name
+@cindex list linkage 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 linkage name for the symbol name within brackets if it is
+different from the name in the source.
+
+The linkage name is the name used by the linker for a symbol. This may be
+the same as the symbol's name in the source, or may be different if the compiler
+adds a prefix to the name (for example, an underscore) or modifies it, such
+as by C@t{++} name mangling.
+
+This is different from "set print asm-demangle on" which only displays
+the linkage name for C@t{++} symbols and does not display the source name.
+
+@kindex show display-linkage-name-length
+@itemx show display-linkage-name-length @var{len}
+Set the maximum number of characters of linkage name to display. The
+@code{show} command displays the current setting. The default is @code{20}.
+@end table
@node Altering
@chapter Altering Execution
@@ -29267,6 +29290,9 @@ is not.
@item what
Some extra data, the exact contents of which are type-dependent.
+@item linkage-name
+The name used by the linker for this function.
+
@end table
For example, here is what the output of @code{-break-insert}
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 1cc248d..3c8df26 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -51,6 +51,7 @@
#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. */
@@ -573,17 +574,19 @@ print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr,
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 name, linkname, and filename. */
struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name);
make_cleanup (free_current_contents, &filename);
+ make_cleanup (free_current_contents, &linkname);
- 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;
@@ -595,6 +598,28 @@ print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr,
else
fputs_filtered ("<", stream);
fputs_filtered (name, stream);
+
+ /* Print linkage name after source name if requested and different. */
+ if (display_linkage_name
+ && linkname != NULL && strcmp (name, linkname) != 0)
+ {
+ fputs_filtered (" [", stream);
+
+ if (strlen (linkname) > display_linkage_name_length)
+ {
+ char *lname = alloca (display_linkage_name_length + 4);
+
+ strncpy (lname, linkname, display_linkage_name_length);
+ lname[display_linkage_name_length] = '\0';
+ strcat (lname, "...");
+ fputs_filtered (lname, stream);
+ }
+ else
+ fputs_filtered (linkname, stream);
+
+ fputs_filtered ("]", stream);
+ }
+
if (offset != 0)
fprintf_filtered (stream, "+%u", (unsigned int) offset);
@@ -627,6 +652,7 @@ build_address_symbolic (struct gdbarch *gdbarch,
CORE_ADDR addr, /* IN */
int do_demangle, /* IN */
char **name, /* OUT */
+ char **linkname, /* OUT */
int *offset, /* OUT */
char **filename, /* OUT */
int *line, /* OUT */
@@ -641,6 +667,10 @@ build_address_symbolic (struct gdbarch *gdbarch,
/* Let's say it is mapped (not unmapped). */
*unmapped = 0;
+ /* Let's say the link name is the same as the symbol name. */
+ if (linkname != NULL)
+ *linkname = NULL;
+
/* Determine if the address is in an overlay, and whether it is
mapped. */
if (overlay_debugging)
@@ -744,6 +774,13 @@ build_address_symbolic (struct gdbarch *gdbarch,
*line = sal.line;
}
}
+
+ /* If we have both symbol names and they are different, let caller know. */
+ if (linkname != NULL && msymbol != NULL && symbol != NULL
+ && strcmp (SYMBOL_LINKAGE_NAME (msymbol),
+ SYMBOL_LINKAGE_NAME (symbol)) != 0)
+ *linkname = xstrdup (SYMBOL_LINKAGE_NAME (msymbol));
+
return 0;
}
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index f960b08..6b48140 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -131,7 +131,7 @@ frapy_name (PyObject *self, PyObject *args)
{
FRAPY_REQUIRE_VALID (self, frame);
- find_frame_funname (frame, &name, &lang, NULL);
+ find_frame_funname (frame, &name, NULL, &lang, NULL);
}
if (except.reason < 0)
diff --git a/gdb/stack.c b/gdb/stack.c
index d89ff89..8fdba86 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -55,6 +55,7 @@
#include "psymtab.h"
#include "symfile.h"
#include "python/python.h"
+#include "top.h"
void (*deprecated_selected_frame_level_changed_hook) (int);
@@ -1004,15 +1005,20 @@ get_last_displayed_sal (struct symtab_and_line *sal)
/* Attempt to obtain the FUNNAME, FUNLANG and optionally FUNCP of the function
- corresponding to FRAME. FUNNAME needs to be freed by the caller. */
+ corresponding to FRAME. FUNNAME needs to be freed by the caller.
+ Set LINKNAME to linkage name (symbol used by linker) if LINKNAME is non-null
+ and linkage name differs from source name. */
void
find_frame_funname (struct frame_info *frame, char **funname,
- enum language *funlang, struct symbol **funcp)
+ const char **linkname, enum language *funlang,
+ struct symbol **funcp)
{
struct symbol *func;
*funname = NULL;
+ if (linkname != NULL)
+ *linkname = NULL;
*funlang = language_unknown;
if (funcp)
*funcp = NULL;
@@ -1048,6 +1054,11 @@ find_frame_funname (struct frame_info *frame, char **funname,
else
memset (&msymbol, 0, sizeof (msymbol));
+ if (linkname != NULL && msymbol.minsym != NULL
+ && strcmp (SYMBOL_LINKAGE_NAME (msymbol.minsym),
+ SYMBOL_LINKAGE_NAME (func)) != 0)
+ *linkname = SYMBOL_LINKAGE_NAME (msymbol.minsym);
+
if (msymbol.minsym != NULL
&& (SYMBOL_VALUE_ADDRESS (msymbol.minsym)
> BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
@@ -1106,6 +1117,7 @@ print_frame (struct frame_info *frame, int print_level,
struct gdbarch *gdbarch = get_frame_arch (frame);
struct ui_out *uiout = current_uiout;
char *funname = NULL;
+ const char *linkname = NULL;
enum language funlang = language_unknown;
struct ui_file *stb;
struct cleanup *old_chain, *list_chain;
@@ -1119,7 +1131,7 @@ print_frame (struct frame_info *frame, int print_level,
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);
make_cleanup (xfree, funname);
annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
@@ -1151,6 +1163,29 @@ print_frame (struct frame_info *frame, int print_level,
fprintf_symbol_filtered (stb, funname ? funname : "??",
funlang, DMGL_ANSI);
ui_out_field_stream (uiout, "func", stb);
+
+ /* Print linkage name after source name if requested and different. */
+ if ((display_linkage_name || ui_out_is_mi_like_p (uiout))
+ && linkname != NULL && strcmp (funname, linkname) != 0)
+ {
+ ui_out_text (uiout, " [");
+
+ if (strlen (linkname) > display_linkage_name_length)
+ {
+ char *lname = alloca (display_linkage_name_length + 4);
+
+ strncpy (lname, linkname, display_linkage_name_length);
+ lname[display_linkage_name_length] = '\0';
+ strcat (lname, "...");
+ ui_out_text (uiout, lname);
+ }
+ else
+ ui_out_field_string (uiout, "linkage name", linkname);
+
+ ui_out_text (uiout, "]");
+ ui_out_field_stream (uiout, "linkage_name", stb);
+ }
+
ui_out_wrap_hint (uiout, " ");
annotate_frame_args ();
diff --git a/gdb/stack.h b/gdb/stack.h
index 4badf19..9248c85 100644
--- a/gdb/stack.h
+++ b/gdb/stack.h
@@ -23,7 +23,8 @@
void select_frame_command (char *level_exp, int from_tty);
void find_frame_funname (struct frame_info *frame, 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,
diff --git a/gdb/testsuite/gdb.cp/display-linkage-name.cc b/gdb/testsuite/gdb.cp/display-linkage-name.cc
new file mode 100644
index 0000000..d9db673
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/display-linkage-name.cc
@@ -0,0 +1,36 @@
+/* This test script is part of GDB, the GNU debugger.
+
+ Copyright 2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+void foo (const char *msg)
+{
+} /* set breakpoint 1 here */
+
+void fun_with_a_long_name (int i, const char *s, double d)
+{
+ foo ("Hello"); /* set breakpoint 2 here */
+}
+
+void goo (void)
+{
+ fun_with_a_long_name (1, "abc", 3.14);
+}
+
+int main (void)
+{
+ goo();
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.cp/display-linkage-name.exp b/gdb/testsuite/gdb.cp/display-linkage-name.exp
new file mode 100644
index 0000000..1e83c3c
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/display-linkage-name.exp
@@ -0,0 +1,116 @@
+# Copyright 2013 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This file was written by Michael Eager (eager@eagercon.com).
+
+if { [skip_cplus_tests] } { continue }
+
+standard_testfile .cc
+
+if {[get_compiler_info "c++"]} {
+ return -1
+}
+
+if { [prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}] } {
+ return -1
+}
+
+# set break at functions
+
+set bp1 [gdb_get_line_number "set breakpoint 1 here"]
+set bp2 [gdb_get_line_number "set breakpoint 2 here"]
+
+if {![gdb_breakpoint "foo"]} {
+ fail "set breakpoint foo"
+}
+
+if {![gdb_breakpoint "fun_with_a_long_name"]} {
+ fail "set breakpoint fun_with_a_long_name"
+}
+
+########################
+# Test with display-linkage-name off
+
+gdb_test_no_output "set display-linkage-name off"
+
+gdb_test "info break" \
+ "Num Type\[ \]+Disp Enb Address\[\t \]+What.*
+1\[\t \]+breakpoint keep y.* in foo(.*) at .*$srcfile:$bp1.*
+2\[\t \]+breakpoint keep y.* in fun_with_a_long_name(.*) at .*$srcfile:$bp2.*" \
+ "info breakpoint - display off"
+
+gdb_run_cmd
+set test "break at fun_with_a_long_name"
+gdb_continue_to_breakpoint "fun_with_a_long_name (.*) at.*$srcfile.$bp2"
+
+set bttable "#0 foo (.*) at.*\[\r\n\]"
+append bttable "#1 $hex in fun_with_a_long_name (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#2 $hex in goo (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#3 $hex in main (.*) at .*$srcfile:.*"
+
+gdb_test "backtrace" $bttable "backtrace - display off"
+
+########################
+# Test with display-linkage-name on
+
+gdb_test_no_output "set display-linkage-name on"
+
+gdb_test "info break" \
+ "Num Type\[ \]+Disp Enb Address\[\t \]+What.*
+1\[\t \]+breakpoint keep y.* in foo(.*) \\\[_Z3fooPKc\\\] at .*$srcfile:$bp1.*
+2\[\t \]+breakpoint keep y.* in fun_with_a_long_name(.*) \\\[_Z20fun_with_a_long_\.\.\.\\\] at .*$srcfile:$bp2.*" \
+ "info breakpoint - display on"
+
+gdb_run_cmd
+set test "break at fun_with_a_long_name - display on"
+gdb_continue_to_breakpoint "fun_with_a_long_name \\\[_Z20fun_with_a_long_...\\\] (.*) at.*$srcfile.$bp2"
+
+set bttable "#0 foo \\\[_Z3fooPKc\\\] (.*) at.*\[\r\n\]"
+append bttable "#1 $hex in fun_with_a_long_name \\\[_Z20fun_with_a_long_\.\.\.\\\] (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#2 $hex in goo \\\[_Z3goov\\\] (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#3 $hex in main (.*) at .*$srcfile:.*"
+
+gdb_test "backtrace" $bttable "backtrace - display on"
+
+########################
+# Test set/show display-linkage-name-length
+
+gdb_test "show display-linkage-name-length" \
+ "Length of linkage names \\(symbol used by linker\\) to be displayed is 20." \
+ "show display linkage name 20"
+
+gdb_test_no_output "set display-linkage-name-length 10"
+
+gdb_test "show display-linkage-name-length" \
+ "Length of linkage names \\(symbol used by linker\\) to be displayed is 10." \
+ "show display linkage name 10"
+
+gdb_test "info break" \
+ "Num Type\[ \]+Disp Enb Address\[\t \]+What.*
+1\[\t \]+breakpoint keep y.* in foo(.*) \\\[_Z3fooPKc\\\] at .*$srcfile:$bp1.*
+2\[\t \]+breakpoint keep y.* in fun_with_a_long_name(.*) \\\[_Z20fun_wi\.\.\.\\\] at .*$srcfile:$bp2.*" \
+ "info breakpoint - display 10"
+
+gdb_run_cmd
+set test "break at fun_with_a_long_name - display 10"
+gdb_continue_to_breakpoint "fun_with_a_long_name \\\[_Z20fun_wi\.\.\.\\\] (.*) at .*$srcfile:$bp2"
+
+set bttable "#0 foo \\\[_Z3fooPKc\\\] (.*) at.*\[\r\n\]"
+append bttable "#1 $hex in fun_with_a_long_name \\\[_Z20fun_wi\.\.\.\\\] (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#2 $hex in goo \\\[_Z3goov\\\] (.*) at .*$srcfile:.*\[\r\n\]"
+append bttable "#3 $hex in main (.*) at .*$srcfile:.*"
+
+gdb_test "backtrace" $bttable "backtrace - display 10"
+
diff --git a/gdb/top.c b/gdb/top.c
index 33a78da..bbf29dd 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -288,6 +288,32 @@ quit_cover (void)
quit_command ((char *) 0, 0);
}
#endif /* defined SIGHUP */
+
+/* Flag for whether we want to print linkage name for functions.
+ Length of linkage name to print. */
+
+int display_linkage_name = 0; /* Default is no. */
+int display_linkage_name_length = 20; /* Default is first 20 chars. */
+
+/* Show display-linkage-name. */
+static void
+show_display_linkage_name (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) of functions is %s.\n"),
+ value);
+}
+
+/* Show display-linkage-name-length. */
+static void
+show_display_linkage_name_length (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c, const char *value)
+{
+ fprintf_filtered (file, _("\
+Length of linkage names (symbol used by linker) to be displayed is %s.\n"),
+ value);
+}
\f
/* 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
@@ -1827,7 +1853,23 @@ Use \"on\" to enable the notification, and \"off\" to disable it."),
When set, GDB uses the specified path to search for data files."),
set_gdb_datadir, NULL,
&setlist,
- &showlist);
+ &showlist);
+
+ add_setshow_boolean_cmd ("display-linkage-name", class_support, &display_linkage_name, _("\
+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_display_linkage_name,
+ &setlist, &showlist);
+
+ add_setshow_zinteger_cmd ("display-linkage-name-length", class_support,
+ &display_linkage_name_length, _("\
+Set number of characters of linkage name to display."), _("\
+Show number of characters of linkage name to display."), NULL,
+ NULL,
+ show_display_linkage_name_length,
+ &setlist, &showlist);
+
}
void
diff --git a/gdb/top.h b/gdb/top.h
index 2f70539..781548d 100644
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -26,6 +26,8 @@ extern int saved_command_line_size;
extern FILE *instream;
extern int in_user_command;
extern int confirm;
+extern int display_linkage_name;
+extern int display_linkage_name_length;
extern char gdb_dirbuf[1024];
extern int inhibit_gdbinit;
extern const char gdbinit[];
--
1.7.1
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Revised display-linkage-name
2013-08-01 19:36 ` Michael Eager
@ 2013-08-01 20:56 ` Tom Tromey
2013-08-02 18:00 ` Michael Eager
0 siblings, 1 reply; 19+ messages in thread
From: Tom Tromey @ 2013-08-01 20:56 UTC (permalink / raw)
To: Michael Eager; +Cc: Keith Seitz, gdb-patches@sourceware.org ml
>>>>> "Michael" == Michael Eager <eager@eagerm.com> writes:
Michael> I eliminated the annotations and made the other requested changes.
Michael> + if (strlen (SYMBOL_LINKAGE_NAME (msymbol.minsym))
Michael> + > display_linkage_name_length)
Michael> + {
I think this should also check ui_out_is_mi_like_p.
Michael> + /* Print linkage name after source name if requested and different. */
Michael> + if ((display_linkage_name || ui_out_is_mi_like_p (uiout))
Michael> + && linkname != NULL && strcmp (funname, linkname) != 0)
Michael> + {
Michael> + ui_out_text (uiout, " [");
Michael> +
Michael> + if (strlen (linkname) > display_linkage_name_length)
Michael> + {
Here too.
Michael> + char *lname = alloca (display_linkage_name_length + 4);
Michael> +
Michael> + strncpy (lname, linkname, display_linkage_name_length);
Michael> + lname[display_linkage_name_length] = '\0';
Michael> + strcat (lname, "...");
Michael> + ui_out_text (uiout, lname);
Here you emit it as text...
Michael> + }
Michael> + else
Michael> + ui_out_field_string (uiout, "linkage name", linkname);
... here with a field name with spaces...
Michael> +
Michael> + ui_out_text (uiout, "]");
Michael> + ui_out_field_stream (uiout, "linkage_name", stb);
... and here with an underscore. Another part of the patch used
"linkage-name", with a hyphen. I think the hyphen one should be
preferred.
Also, this last bit looks the same as an earlier revision to me.
"stb" simply isn't valid here -- your code isn't printing to it, it was
set up earlier; I'm surprised it is even still live.
Tom
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Revised display-linkage-name
2013-08-01 20:56 ` Tom Tromey
@ 2013-08-02 18:00 ` Michael Eager
0 siblings, 0 replies; 19+ messages in thread
From: Michael Eager @ 2013-08-02 18:00 UTC (permalink / raw)
To: Tom Tromey; +Cc: Keith Seitz, gdb-patches@sourceware.org ml
On 08/01/13 13:55, Tom Tromey wrote:
>>>>>> "Michael" == Michael Eager <eager@eagerm.com> writes:
>
> Michael> I eliminated the annotations and made the other requested changes.
>
> Michael> + if (strlen (SYMBOL_LINKAGE_NAME (msymbol.minsym))
> Michael> + > display_linkage_name_length)
> Michael> + {
>
> I think this should also check ui_out_is_mi_like_p.
>
> Michael> + /* Print linkage name after source name if requested and different. */
> Michael> + if ((display_linkage_name || ui_out_is_mi_like_p (uiout))
> Michael> + && linkname != NULL && strcmp (funname, linkname) != 0)
> Michael> + {
> Michael> + ui_out_text (uiout, " [");
> Michael> +
> Michael> + if (strlen (linkname) > display_linkage_name_length)
> Michael> + {
>
> Here too.
>
> Michael> + char *lname = alloca (display_linkage_name_length + 4);
> Michael> +
> Michael> + strncpy (lname, linkname, display_linkage_name_length);
> Michael> + lname[display_linkage_name_length] = '\0';
> Michael> + strcat (lname, "...");
> Michael> + ui_out_text (uiout, lname);
>
> Here you emit it as text...
>
> Michael> + }
> Michael> + else
> Michael> + ui_out_field_string (uiout, "linkage name", linkname);
>
> ... here with a field name with spaces...
>
> Michael> +
> Michael> + ui_out_text (uiout, "]");
> Michael> + ui_out_field_stream (uiout, "linkage_name", stb);
>
> ... and here with an underscore. Another part of the patch used
> "linkage-name", with a hyphen. I think the hyphen one should be
> preferred.
>
> Also, this last bit looks the same as an earlier revision to me.
> "stb" simply isn't valid here -- your code isn't printing to it, it was
> set up earlier; I'm surprised it is even still live.
Thanks. I'll rework the MI stuff. I have no experience/understanding
of how this is supposed to work.
--
Michael Eager eager@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306 650-325-8077
^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2013-08-02 18:00 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-22 18:28 [PATCH] Revised display-linkage-name Michael Eager
2013-05-22 19:28 ` Eli Zaretskii
2013-05-22 21:42 ` Michael Eager
2013-06-17 17:35 ` Michael Eager
2013-07-10 16:17 ` Michael Eager
2013-07-11 23:28 ` Keith Seitz
2013-07-12 21:17 ` Michael Eager
2013-07-17 18:51 ` Michael Eager
2013-07-17 19:14 ` Eli Zaretskii
2013-07-22 17:48 ` Keith Seitz
2013-07-22 20:07 ` Michael Eager
2013-07-22 21:55 ` Keith Seitz
2013-07-24 15:55 ` Michael Eager
2013-07-26 18:42 ` Tom Tromey
2013-07-26 20:18 ` Michael Eager
2013-07-29 17:48 ` Tom Tromey
2013-08-01 19:36 ` Michael Eager
2013-08-01 20:56 ` Tom Tromey
2013-08-02 18:00 ` Michael Eager
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox