From a1530dc7319595b5980e8501092782724c946351 Mon Sep 17 00:00:00 2001 From: Kevin Buettner Date: Sun, 2 Jun 2019 18:12:28 -0700 Subject: [PATCH] Allow display of negative offsets in print_address_symbolic() 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 (using the dw2-ranges-func-lo-cold executable): (gdb) x/5i foo_cold 0x40110d : push %rbp 0x40110e : mov %rsp,%rbp 0x401111 : callq 0x401106 0x401116 : nop 0x401117 : pop %rbp This commit, in conjuction with an earlier patch from this series, causes cases like the above to be displayed like this (below) instead: (gdb) x/5i foo_cold 0x40110d : push %rbp 0x40110e : mov %rsp,%rbp 0x401111 : callq 0x401106 0x401116 : nop 0x401117 : pop %rbp Note that the address of foo_cold is now (due to another patch) being displayed as instead of . The subsequent lines are shown as negative offsets from foo. Disassembly using the "disassemble" command is somewhat affected by these changes: Before: (gdb) disassemble foo_cold Dump of assembler code for function foo: Address range 0x401120 to 0x40113b: 0x0000000000401120 <+0>: push %rbp 0x0000000000401121 <+1>: mov %rsp,%rbp 0x0000000000401124 <+4>: callq 0x401119 0x0000000000401129 <+9>: mov 0x2ef1(%rip),%eax # 0x404020 0x000000000040112f <+15>: test %eax,%eax 0x0000000000401131 <+17>: je 0x401138 0x0000000000401133 <+19>: callq 0x40110d 0x0000000000401138 <+24>: nop 0x0000000000401139 <+25>: pop %rbp 0x000000000040113a <+26>: retq Address range 0x40110d to 0x401119: 0x000000000040110d <+-19>: push %rbp 0x000000000040110e <+-18>: mov %rsp,%rbp 0x0000000000401111 <+-15>: callq 0x401106 0x0000000000401116 <+-10>: nop 0x0000000000401117 <+-9>: pop %rbp 0x0000000000401118 <+-8>: retq End of assembler dump. After: (gdb) disassemble foo_cold Dump of assembler code for function foo: Address range 0x401120 to 0x40113b: 0x0000000000401120 <+0>: push %rbp 0x0000000000401121 <+1>: mov %rsp,%rbp 0x0000000000401124 <+4>: callq 0x401119 0x0000000000401129 <+9>: mov 0x2ef1(%rip),%eax # 0x404020 0x000000000040112f <+15>: test %eax,%eax 0x0000000000401131 <+17>: je 0x401138 0x0000000000401133 <+19>: callq 0x40110d 0x0000000000401138 <+24>: nop 0x0000000000401139 <+25>: pop %rbp 0x000000000040113a <+26>: retq Address range 0x40110d to 0x401119: 0x000000000040110d <-19>: push %rbp 0x000000000040110e <-18>: mov %rsp,%rbp 0x0000000000401111 <-15>: callq 0x401106 0x0000000000401116 <-10>: nop 0x0000000000401117 <-9>: pop %rbp 0x0000000000401118 <-8>: retq End of assembler dump. Note that negative offsets are now displayed without the leading "+". Also, the callq to foo_cold is now displayed as such instead of a callq to foo with a large positive offset. gdb/ChangeLog: * printcmd.c (print_address_symbolic): Print negative offsets. (build_address_symbolic): Force signed arithmetic when computing offset. --- gdb/ChangeLog | 10 ++++++---- gdb/printcmd.c | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 00e681938e4..4d9ec41c696 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2019-07-30 Kevin Buettner + + * printcmd.c (print_address_symbolic): Print negative offsets. + (build_address_symbolic): Force signed arithmetic when computing + offset. + 2019-07-30 Christian Biesinger PR/24474: Add a function to lookup static variables. @@ -84,10 +90,6 @@ * dwarf2-frame.c (dwarf2_frame_cache): Don't decode FDE instructions for entry pc when entry pc is out of range for that FDE. - * printcmd.c (print_address_symbolic): Print negative offsets. - (build_address_symbolic): Force signed arithmetic when computing - offset. - 2019-07-26 Brian Callahan PR gdb/24839: diff --git a/gdb/printcmd.c b/gdb/printcmd.c index efe6874d39b..1faa09eee71 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -540,7 +540,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. */ @@ -680,7 +680,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; -- 2.30.2