Message ID | 20190704045503.1250-5-kevinb@redhat.com |
---|---|
State | New, archived |
Headers |
Received: (qmail 62114 invoked by alias); 4 Jul 2019 05:05:23 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: <gdb-patches.sourceware.org> List-Unsubscribe: <mailto:gdb-patches-unsubscribe-##L=##H@sourceware.org> List-Subscribe: <mailto:gdb-patches-subscribe@sourceware.org> List-Archive: <http://sourceware.org/ml/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-help@sourceware.org>, <http://sourceware.org/ml/#faqs> Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 62094 invoked by uid 89); 4 Jul 2019 05:05:23 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=UD:style X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 04 Jul 2019 05:03:40 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 04D8B59442 for <gdb-patches@sourceware.org>; Thu, 4 Jul 2019 04:55:36 +0000 (UTC) Received: from f30-1.lan (ovpn-117-224.phx2.redhat.com [10.3.117.224]) by smtp.corp.redhat.com (Postfix) with ESMTP id CA39D8351E; Thu, 4 Jul 2019 04:55:35 +0000 (UTC) From: Kevin Buettner <kevinb@redhat.com> To: gdb-patches@sourceware.org Cc: Kevin Buettner <kevinb@redhat.com> Subject: [PATCH v2 4/5] Allow display of negative offsets in print_address_symbolic() Date: Wed, 3 Jul 2019 21:55:02 -0700 Message-Id: <20190704045503.1250-5-kevinb@redhat.com> In-Reply-To: <20190704045503.1250-1-kevinb@redhat.com> References: <20190704045503.1250-1-kevinb@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes |
Commit Message
Kevin Buettner
July 4, 2019, 4:55 a.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 (using the dw2-ranges-func-lo-cold executable): (gdb) x/5i foo_cold 0x40110d <foo+4294967277>: push %rbp 0x40110e <foo+4294967278>: mov %rsp,%rbp 0x401111 <foo+4294967281>: callq 0x401106 <baz> 0x401116 <foo+4294967286>: nop 0x401117 <foo+4294967287>: 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 <foo_cold>: push %rbp 0x40110e <foo-18>: mov %rsp,%rbp 0x401111 <foo-15>: callq 0x401106 <baz> 0x401116 <foo-10>: nop 0x401117 <foo-9>: pop %rbp Note that the address of foo_cold is now (due to another patch) being displayed as <foo_cold> instead of <foo+BigOffset>. 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 <bar> 0x0000000000401129 <+9>: mov 0x2ef1(%rip),%eax # 0x404020 <e> 0x000000000040112f <+15>: test %eax,%eax 0x0000000000401131 <+17>: je 0x401138 <foo+24> 0x0000000000401133 <+19>: callq 0x40110d <foo+4294967277> 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 <baz> 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 <bar> 0x0000000000401129 <+9>: mov 0x2ef1(%rip),%eax # 0x404020 <e> 0x000000000040112f <+15>: test %eax,%eax 0x0000000000401131 <+17>: je 0x401138 <foo+24> 0x0000000000401133 <+19>: callq 0x40110d <foo_cold> 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 <baz> 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/printcmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Comments
I somehow missed pushing this commit when I pushed the rest of the series. It was strange though - that second hunk of the patch was in, but the first was not. Moreover, I didn't see an actual commit in master. Regardless, it should be in now. Thanks to Tom de Vries for his help in finding this problem. Kevin On Wed, 3 Jul 2019 21:55:02 -0700 Kevin Buettner <kevinb@redhat.com> 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 (using the > dw2-ranges-func-lo-cold executable): > > (gdb) x/5i foo_cold > 0x40110d <foo+4294967277>: push %rbp > 0x40110e <foo+4294967278>: mov %rsp,%rbp > 0x401111 <foo+4294967281>: callq 0x401106 <baz> > 0x401116 <foo+4294967286>: nop > 0x401117 <foo+4294967287>: 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 <foo_cold>: push %rbp > 0x40110e <foo-18>: mov %rsp,%rbp > 0x401111 <foo-15>: callq 0x401106 <baz> > 0x401116 <foo-10>: nop > 0x401117 <foo-9>: pop %rbp > > Note that the address of foo_cold is now (due to another patch) being > displayed as <foo_cold> instead of <foo+BigOffset>. 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 <bar> > 0x0000000000401129 <+9>: mov 0x2ef1(%rip),%eax # 0x404020 <e> > 0x000000000040112f <+15>: test %eax,%eax > 0x0000000000401131 <+17>: je 0x401138 <foo+24> > 0x0000000000401133 <+19>: callq 0x40110d <foo+4294967277> > 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 <baz> > 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 <bar> > 0x0000000000401129 <+9>: mov 0x2ef1(%rip),%eax # 0x404020 <e> > 0x000000000040112f <+15>: test %eax,%eax > 0x0000000000401131 <+17>: je 0x401138 <foo+24> > 0x0000000000401133 <+19>: callq 0x40110d <foo_cold> > 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 <baz> > 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/printcmd.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/gdb/printcmd.c b/gdb/printcmd.c > index 1109cb3046..dce6ab2db9 100644 > --- a/gdb/printcmd.c > +++ b/gdb/printcmd.c > @@ -539,7 +539,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. */ > @@ -679,7 +679,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.21.0 >
diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 1109cb3046..dce6ab2db9 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -539,7 +539,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. */ @@ -679,7 +679,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;