From: Daniel Jacobowitz <drow@false.org>
To: gdb-patches@sourceware.org
Subject: RFC: Strip the ISA bit when printing symbol offsets
Date: Fri, 13 Nov 2009 21:27:00 -0000 [thread overview]
Message-ID: <20091113212716.GA28795@caradoc.them.org> (raw)
When you compile a function in ARM's Thumb mode, the low bit of the
function's address is set to indicate the use of an alternate
instruction set.
This currently causes failures in two tests (mi-var-child.exp and
member-ptr.exp), because we print $hex <function+1> instead of the
expected $hex <function>.
What do you think of this patch, which causes us to strip off the low
bit when computing the offset if FUNCTION is a function symbol (rather
than a data variable)?
It's not 100% honest - if the function contains embedded data, for
instance, we might print the altered offset for something that isn't
an instruction. But it's right more often than what we have now,
since the address including low bit set jumps to the first instruction
of FUNCTION.
Comments? OK to commit?
Tested on arm-none-eabi and x86_64-linux.
2009-11-13 Daniel Jacobowitz <dan@codesourcery.com>
* defs.h (print_address_symbolic, build_address_symbolic): Update
prototypes.
* printcmd.c (print_address_symbolic): Take a gdbarch argument.
Pass it to build_address_symbolic. All callers updated.
(build_address_symbolic): Take a gdbarch argument. Use
gdbarch_addr_bits_remove for functions. All callers updated.
---
gdb/breakpoint.c | 3 ++-
gdb/defs.h | 7 ++++---
gdb/disasm.c | 2 +-
gdb/printcmd.c | 21 +++++++++++++++------
gdb/tui/tui-stack.c | 3 ++-
5 files changed, 24 insertions(+), 12 deletions(-)
Index: gdb-mainline/gdb/breakpoint.c
===================================================================
--- gdb-mainline.orig/gdb/breakpoint.c 2009-11-13 10:57:09.000000000 -0800
+++ gdb-mainline/gdb/breakpoint.c 2009-11-13 10:57:11.000000000 -0800
@@ -3862,7 +3862,8 @@ static void print_breakpoint_location (s
}
else
{
- print_address_symbolic (loc->address, stb->stream, demangle, "");
+ print_address_symbolic (loc->gdbarch, loc->address, stb->stream,
+ demangle, "");
ui_out_field_stream (uiout, "at", stb);
}
Index: gdb-mainline/gdb/defs.h
===================================================================
--- gdb-mainline.orig/gdb/defs.h 2009-11-13 10:57:09.000000000 -0800
+++ gdb-mainline/gdb/defs.h 2009-11-13 10:57:11.000000000 -0800
@@ -596,10 +596,11 @@ extern int info_verbose;
extern void set_next_address (struct gdbarch *, CORE_ADDR);
-extern void print_address_symbolic (CORE_ADDR, struct ui_file *, int,
- char *);
+extern void print_address_symbolic (struct gdbarch *, CORE_ADDR,
+ struct ui_file *, int, char *);
-extern int build_address_symbolic (CORE_ADDR addr,
+extern int build_address_symbolic (struct gdbarch *,
+ CORE_ADDR addr,
int do_demangle,
char **name,
int *offset,
Index: gdb-mainline/gdb/disasm.c
===================================================================
--- gdb-mainline.orig/gdb/disasm.c 2009-11-13 10:57:09.000000000 -0800
+++ gdb-mainline/gdb/disasm.c 2009-11-13 10:57:11.000000000 -0800
@@ -116,7 +116,7 @@ dump_insns (struct gdbarch *gdbarch, str
ui_out_text (uiout, pc_prefix (pc));
ui_out_field_core_addr (uiout, "address", gdbarch, pc);
- if (!build_address_symbolic (pc, 0, &name, &offset, &filename,
+ if (!build_address_symbolic (gdbarch, pc, 0, &name, &offset, &filename,
&line, &unmapped))
{
/* We don't care now about line, filename and
Index: gdb-mainline/gdb/printcmd.c
===================================================================
--- gdb-mainline.orig/gdb/printcmd.c 2009-11-13 10:57:09.000000000 -0800
+++ gdb-mainline/gdb/printcmd.c 2009-11-13 11:01:17.000000000 -0800
@@ -562,7 +562,8 @@ set_next_address (struct gdbarch *gdbarc
settings of the demangle and asm_demangle variables. */
void
-print_address_symbolic (CORE_ADDR addr, struct ui_file *stream,
+print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr,
+ struct ui_file *stream,
int do_demangle, char *leadin)
{
char *name = NULL;
@@ -575,7 +576,7 @@ print_address_symbolic (CORE_ADDR addr,
struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name);
make_cleanup (free_current_contents, &filename);
- if (build_address_symbolic (addr, do_demangle, &name, &offset,
+ if (build_address_symbolic (gdbarch, addr, do_demangle, &name, &offset,
&filename, &line, &unmapped))
{
do_cleanups (cleanup_chain);
@@ -615,7 +616,8 @@ print_address_symbolic (CORE_ADDR addr,
success, when all the info in the OUT paramters is valid. Return 1
otherwise. */
int
-build_address_symbolic (CORE_ADDR addr, /* IN */
+build_address_symbolic (struct gdbarch *gdbarch,
+ CORE_ADDR addr, /* IN */
int do_demangle, /* IN */
char **name, /* OUT */
int *offset, /* OUT */
@@ -658,6 +660,13 @@ build_address_symbolic (CORE_ADDR addr,
if (symbol)
{
+ /* If this is a function (i.e. a code address), strip out any
+ non-address bits. For instance, display a pointer to the
+ first instruction of a Thumb function as <function>; the
+ second instruction will be <function+2>, even though the
+ pointer is <function+3>. This matches the ISA behavior. */
+ addr = gdbarch_addr_bits_remove (gdbarch, addr);
+
name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol));
if (do_demangle || asm_demangle)
name_temp = SYMBOL_PRINT_NAME (symbol);
@@ -722,7 +731,7 @@ print_address (struct gdbarch *gdbarch,
CORE_ADDR addr, struct ui_file *stream)
{
fputs_filtered (paddress (gdbarch, addr), stream);
- print_address_symbolic (addr, stream, asm_demangle, " ");
+ print_address_symbolic (gdbarch, addr, stream, asm_demangle, " ");
}
/* Return a prefix for instruction address:
@@ -763,11 +772,11 @@ print_address_demangle (struct gdbarch *
else if (opts.addressprint)
{
fputs_filtered (paddress (gdbarch, addr), stream);
- print_address_symbolic (addr, stream, do_demangle, " ");
+ print_address_symbolic (gdbarch, addr, stream, do_demangle, " ");
}
else
{
- print_address_symbolic (addr, stream, do_demangle, "");
+ print_address_symbolic (gdbarch, addr, stream, do_demangle, "");
}
}
\f
Index: gdb-mainline/gdb/tui/tui-stack.c
===================================================================
--- gdb-mainline.orig/gdb/tui/tui-stack.c 2009-11-13 10:57:09.000000000 -0800
+++ gdb-mainline/gdb/tui/tui-stack.c 2009-11-13 10:57:11.000000000 -0800
@@ -218,7 +218,8 @@ tui_get_function_from_frame (struct fram
struct ui_file *stream = tui_sfileopen (256);
char *p;
- print_address_symbolic (get_frame_pc (fi), stream, demangle, "");
+ print_address_symbolic (get_frame_arch (fi), get_frame_pc (fi),
+ stream, demangle, "");
p = tui_file_get_strbuf (stream);
/* Use simple heuristics to isolate the function name. The symbol
--
Daniel Jacobowitz
CodeSourcery
next reply other threads:[~2009-11-13 21:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-13 21:27 Daniel Jacobowitz [this message]
2009-11-13 22:25 ` Joel Brobecker
2009-12-28 21:12 ` Daniel Jacobowitz
2009-11-14 9:28 ` Eli Zaretskii
2009-11-14 15:47 ` Daniel Jacobowitz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20091113212716.GA28795@caradoc.them.org \
--to=drow@false.org \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox