[3/4] Allow display of negative offsets in print_address_symbolic()

Message ID 20190608195434.26512-4-kevinb@redhat.com
State New, archived
Headers

Commit Message

Kevin Buettner June 8, 2019, 7:54 p.m. UTC
  When examining addresses associated with blocks with non-contiguous
address ranges, it's not uncommon to see large positive offsets which,
for some address width, actually represent a smaller negative offset.
Here's an example taken from the test case:

    (gdb) x/i foo_cold
       0x40110d <foo+4294967277>:	push   %rbp

This commit causes cases like the above to be displayed like this (below)
instead:

    (gdb) x/i foo_cold
       0x40110d <foo-19>:	push   %rbp

gdb/ChangeLog:

	* printcmd.c (print_address_symbolic): Print negative offsets.
	(build_address_symbolic): Force signed arithmetic when computing
	offset.
---
 gdb/printcmd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Pedro Alves June 21, 2019, 2:45 p.m. UTC | #1
On 6/8/19 8:54 PM, Kevin Buettner wrote:
> When examining addresses associated with blocks with non-contiguous
> address ranges, it's not uncommon to see large positive offsets which,
> for some address width, actually represent a smaller negative offset.
> Here's an example taken from the test case:
> 
>     (gdb) x/i foo_cold
>        0x40110d <foo+4294967277>:	push   %rbp
> 
> This commit causes cases like the above to be displayed like this (below)
> instead:
> 
>     (gdb) x/i foo_cold
>        0x40110d <foo-19>:	push   %rbp
> 
> gdb/ChangeLog:
> 
> 	* printcmd.c (print_address_symbolic): Print negative offsets.
> 	(build_address_symbolic): Force signed arithmetic when computing
> 	offset.

Seems reasonable to me, if we assume that the symbol name to put
within <> is "foo".

This change makes makes me doubt that, though.  We're looking at
the lower level, disassembly code.  I think I'd want to see

  0x40110d <foo_cold+0>:

there?

E.g., I might want to follow up with
disassemble foo_cold.

But the present state of things, I wouldn't be able to see the
foo_cold symbol, where it starts?

Maybe a larger disassemble output including several cold sections
in view would help determine the best output.

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index e00a9c671a..8ceddd633a 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -537,7 +537,7 @@  print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr,
     fputs_filtered ("<", stream);
   fputs_styled (name.c_str (), function_name_style.style (), stream);
   if (offset != 0)
-    fprintf_filtered (stream, "+%u", (unsigned int) offset);
+    fprintf_filtered (stream, "%+d", offset);
 
   /* Append source filename and line number if desired.  Give specific
      line # of this addr, if we have it; else line # of the nearest symbol.  */
@@ -666,7 +666,7 @@  build_address_symbolic (struct gdbarch *gdbarch,
       && name_location + max_symbolic_offset > name_location)
     return 1;
 
-  *offset = addr - name_location;
+  *offset = (LONGEST) addr - name_location;
 
   *name = name_temp;