From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id wSHGNAPp/Wn8tiMAWB0awg (envelope-from ) for ; Fri, 08 May 2026 09:45:39 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TR95UrL8; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id D22A31E067; Fri, 08 May 2026 09:45:39 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id B22A61E067 for ; Fri, 08 May 2026 09:45:38 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3E9394BA2E13 for ; Fri, 8 May 2026 13:45:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3E9394BA2E13 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TR95UrL8 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 55B8E4BA2E07 for ; Fri, 8 May 2026 13:45:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 55B8E4BA2E07 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 55B8E4BA2E07 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778247908; cv=none; b=ZNUPUSVJq5WmvzlA+GlYA1jCKlx++JJWHcfb8EUGyuQGDuKjcWf9lA3O3e0dr2QUT2ed+j8vB/XUHutQSk36s+RRZNBWZIHoiLsIknwSofizAVnsjjMtYMpdp3Sgdc6oXk1Kh7iHg17LkclaaWt20xTS4C/U2R6RpCSZMJXu2bM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778247908; c=relaxed/simple; bh=FMKaYS8WdWJFYKEoNmj7/wT5Gw6shmJYCZvoO1nIos4=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=uY//tngoilgH6wONUbT1682xNNxcXyDkZW7gq79UM8/daU05uYKXoYODGdu2CfiVmPilKF1cylhhPaLmmQqFRGDuK7fGkniLAFhrgbEKcoZ+wjnPGwr23stQ00CdHMNdxXUijFJyONvrLdOfX+49SlcdFLrCO+DJj9KmRpwr1xs= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TR95UrL8 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 55B8E4BA2E07 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778247907; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lt94qLx78GtMhVv3pxS3xos+cAEyAx/AkQ3SrJ54p60=; b=TR95UrL8U44+1G7yIa3ViaW6pL39eqIKNWz7LP23CHZRVAe3jV75JCeI07JqyqoR0ntiJB iAYnTOk3VWOxDy9KgjnP5w6PTyWmO5ny0kRyhyc36tvyRY9qwcC/29D93KOXUvUhfHLe9z Ef1zCiJGP1vmMHKlotYEUnrgQMEeEq0= Received: from mail-dl1-f71.google.com (mail-dl1-f71.google.com [74.125.82.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-184-Va9O7jveN76iI-vxg3p8OQ-1; Fri, 08 May 2026 09:45:04 -0400 X-MC-Unique: Va9O7jveN76iI-vxg3p8OQ-1 X-Mimecast-MFC-AGG-ID: Va9O7jveN76iI-vxg3p8OQ_1778247902 Received: by mail-dl1-f71.google.com with SMTP id a92af1059eb24-1309f4ee96dso5120205c88.1 for ; Fri, 08 May 2026 06:45:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778247902; x=1778852702; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lt94qLx78GtMhVv3pxS3xos+cAEyAx/AkQ3SrJ54p60=; b=CLKn3jySqeb5YmGTerhWaN8jAQZu1ZZUzhGrcYuTHypRRPKcRRuFp/1kP+lM5eU02R FsHuFbY5EbppOXtlAAwSJoKK8X+F7yK/Oi2X5UxB1PIV8dkU+k/ZkQ3IEvbzdQDBt3sY 6WgsSZ+njTqXU9LSScQlRP8jGzYRV30LezfDuKf5FMpa1+yVa8XY6YXQLuSzGNRKhSuS gtlbYYq3ZAUZL3gN/Os3I/h+LqqmqnS+i2W56raRSCFbMQnZPm/yJsTDSPLy4otLBcDw Xg7mLXTFOdtL6E7A//+pFVeiVJYfYi+f9lEI6FNVjN21EFSqIGLb9JSfn9lmcabLjf1Y gxCw== X-Forwarded-Encrypted: i=1; AFNElJ/Vu7kT+JBE7yMRc+Qtk8MLPrONIdmT1sffUXAI7LrjRmbhWaRUaxLVoqNrCj0oPB0l1RimGch51HnewQ==@sourceware.org X-Gm-Message-State: AOJu0YyMaOJisawXLFvWIc82ObAOP7j3I50WlEYRw3gpouoT71cVIyNf saGbn9GEOVEu4IIX1kMc9UeVqGXYHbk5f/wcNhDlEXTb+9Upn7SlyUBninF+eBZ5oYg8aRK1B63 utSA1cDgPuwAIiVvYSEHTyWBZAZJUakqIdhKXGgfBx89OsYW+60XE+VuVPMVpoRU= X-Gm-Gg: AeBDieuJL8IFb5nhD8h/fnb13u/Wl4d8Jf8HMqXxWVk4a8KO2i13nZLgKPSBzJRg2I0 zibjuYGFXxps8ueFjwXuTSnu2U5oqbQ2tzZHVmkqn+HaoAiCOjY4dDBrLyhaTJuUfnz71yRqyA3 TUlIw09sDt7LgHK/OuBSJ18O/6Q3d7+dU9Yu2F2vtdk9H3GQx2CwJWEl1YQB0kMJIatzhodDWrk TNNDjmUkNP2jM02UqDc4G/xgY219ZNmjbfdhmlX/9mpU7XQ7wmlc1oo6+PHdyUWtq8YsYv1QkFD 8k3DymCIhUz/xOW4yQnhCqjx4jgbJJGjVv1/ii243T3GRHyKbJZ/AbgS7XWv7+LKncLkf2zxKou Xsyy0KE0HgCWNP0cEV+jDcUgnOd2+fHqyvB9Q5ClKzQ== X-Received: by 2002:a05:7022:4182:b0:130:73ed:214 with SMTP id a92af1059eb24-131967d5111mr5894321c88.1.1778247901849; Fri, 08 May 2026 06:45:01 -0700 (PDT) X-Received: by 2002:a05:7022:4182:b0:130:73ed:214 with SMTP id a92af1059eb24-131967d5111mr5894300c88.1.1778247901101; Fri, 08 May 2026 06:45:01 -0700 (PDT) Received: from ?IPV6:2804:14d:8084:993e::75d? ([2804:14d:8084:993e::75d]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1327821fc59sm2518082c88.7.2026.05.08.06.44.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 08 May 2026 06:45:00 -0700 (PDT) Message-ID: Date: Fri, 8 May 2026 10:44:56 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] Use "output-radix" setting to format function offsets To: Zander Work , gdb-patches@sourceware.org, Tom Tromey References: <20260504213710.209740-1-zdw@google.com> From: Guinevere Larsen In-Reply-To: <20260504213710.209740-1-zdw@google.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: q-4fDQySaITL4AgCXvAIjJRL4Y0xOuk4kDtO1C9-60s_1778247902 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org On 5/4/26 6:37 PM, Zander Work wrote: > This is a patch for a discussion [1] I had previously where it was > determined that it was a bug for GDB to not use the "output-radix" > setting for function offsets. > > This patch includes updates to the radix.exp tests, and I verified that > there were no new breakages added when running the full gdb testsuite > with this patch. > > I didn't make any changes to NEWS or a /gdb/ Changelog entry for this, > if I should please let me know. Hi! Thank you for working on this! Changelog entries are definitely no  longer required, and I don't think this would need a NEWS entry either. I have some minor comments, mostly about styling or wondering about a few choices, but in general I think this patch is in the right direction! > > I also have not personally completed a FSF copyright assignment form. Yeah, for a patch this size, it will definitely be necessary. I'm adding Tom Tromey in CC since I know he knows about the assignment process (more than me, at least) > > Sample output with this patch: > > ``` > (gdb) disas main > Dump of assembler code for function main: > 0x0000000000001149 <+0>: endbr64 > 0x000000000000114d <+4>: push %rbp > 0x000000000000114e <+5>: mov %rsp,%rbp > 0x0000000000001151 <+8>: lea 0xeac(%rip),%rax # 0x2004 > 0x0000000000001158 <+15>: mov %rax,%rdi > 0x000000000000115b <+18>: mov $0x0,%eax > 0x0000000000001160 <+23>: call 0x1050 > 0x0000000000001165 <+28>: mov $0x0,%eax > 0x000000000000116a <+33>: pop %rbp > 0x000000000000116b <+34>: ret > End of assembler dump. > (gdb) set radix 0x10 > Input and output radices now set to decimal 16, hex 10, octal 20. > (gdb) disas main > Dump of assembler code for function main: > 0x0000000000001149 <+0x0>: endbr64 > 0x000000000000114d <+0x4>: push %rbp > 0x000000000000114e <+0x5>: mov %rsp,%rbp > 0x0000000000001151 <+0x8>: lea 0xeac(%rip),%rax # 0x2004 > 0x0000000000001158 <+0xf>: mov %rax,%rdi > 0x000000000000115b <+0x12>: mov $0x0,%eax > 0x0000000000001160 <+0x17>: call 0x1050 > 0x0000000000001165 <+0x1c>: mov $0x0,%eax > 0x000000000000116a <+0x21>: pop %rbp > 0x000000000000116b <+0x22>: ret > End of assembler dump. > ``` > > [1] https://sourceware.org/pipermail/gdb/2026-April/052170.html > --- > gdb/disasm.c | 18 +++++++++++++---- > gdb/printcmd.c | 2 +- > gdb/testsuite/gdb.base/radix.c | 31 +++++++++++++++++++++++++++++ > gdb/testsuite/gdb.base/radix.exp | 34 ++++++++++++++++++++++++++++++++ > gdb/valprint.c | 10 ++++++++++ > gdb/valprint.h | 6 ++++++ > 6 files changed, 96 insertions(+), 5 deletions(-) > create mode 100644 gdb/testsuite/gdb.base/radix.c > > diff --git a/gdb/disasm.c b/gdb/disasm.c > index 81c466c188a..5d19dea72b6 100644 > --- a/gdb/disasm.c > +++ b/gdb/disasm.c > @@ -375,10 +375,20 @@ gdb_pretty_print_disassembler::pretty_print_insn (const struct disasm_insn *insn > m_uiout->field_string ("func-name", name, > function_name_style.style ()); > /* For negative offsets, avoid displaying them as +-N; the sign of > - the offset takes the place of the "+" here. */ > - if (offset >= 0) > - m_uiout->text ("+"); > - m_uiout->field_signed ("offset", offset); > + the offset takes the place of the "+" here. For MI consumers, > + emit the integer value; otherwise, print the formatted offset based > + on the current 'output-radix'. */ > + if (m_uiout->is_mi_like_p ()) > + { > + if (offset >= 0) > + m_uiout->text ("+"); > + m_uiout->field_signed ("offset", offset); I'm not familiar with the radix functionality, so this is a genuine quesiton, but shouldn't the MI interface also honor the radix request? It seems to me like it would make sense, but if other MI messages don't, your approach here seems right. > + } > + else > + { > + std::string s = format_pc_offset (offset); > + m_uiout->field_string ("offset", s.c_str ()); > + } > m_uiout->text (">:\t"); > } > else > diff --git a/gdb/printcmd.c b/gdb/printcmd.c > index ae498395436..5fb8c666447 100644 > --- a/gdb/printcmd.c > +++ b/gdb/printcmd.c > @@ -567,7 +567,7 @@ print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr, > gdb_puts ("<", stream); > fputs_styled (name.c_str (), function_name_style.style (), stream); > if (offset != 0) > - gdb_printf (stream, "%+d", offset); > + gdb_puts (format_pc_offset (offset).c_str (), stream); > > /* Append source filename and line number if desired. Give specific > line # of this addr, if we have it; else line # of the nearest symbol. */ > diff --git a/gdb/testsuite/gdb.base/radix.c b/gdb/testsuite/gdb.base/radix.c > new file mode 100644 > index 00000000000..191c374d466 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/radix.c > @@ -0,0 +1,31 @@ > +/* This testcase is part of GDB, the GNU debugger. > + > + Copyright 2013-2026 Free Software Foundation, Inc. The copyright year can be only 2026. > + > + 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 . */ > + > +#include > +#include > + > +int v; > + > +int main() Testsuite should also follow the coding style, so main should be in column 0 of the next line and have a space between function name and parenthesis. > +{ > + puts("hello world"); > + /* Don't let the test case run forever. */ > + alarm (60); This feels overly complex for what you want to test. Is there any reason why a simple int main () {   return 0; } wouldn't be enough for the test? > + > + for (;;) > + ; > +} > diff --git a/gdb/testsuite/gdb.base/radix.exp b/gdb/testsuite/gdb.base/radix.exp > index 7a4320bbf36..99256b98df3 100644 > --- a/gdb/testsuite/gdb.base/radix.exp > +++ b/gdb/testsuite/gdb.base/radix.exp > @@ -17,6 +17,11 @@ > # This file was written by Fred Fish. (fnf@cygnus.com) > # And rewritten by Michael Chastain (mec.gnu@mindspring.com) > > +standard_testfile > + > +if {[build_executable "failed to prepare" $testfile $srcfile debug]} { > + return -1 > +} > > # Start with a fresh gdb. > > @@ -189,3 +194,32 @@ gdb_test "set radix 7" \ > gdb_test "show output-radix" \ > "Default output radix for printing of values is 10\\." \ > "output radix unchanged after rejection through set radix command" > + > +with_test_prefix "pc offset radix" { > + clean_restart $testfile > + > + if { ![runto_main] } { > + return -1 > + } > + > + proc test_pc_offset_radix { oradix offset_re } { > + global gdb_prompt > + > + gdb_test "set output-radix $oradix" \ > + "Output radix now set to decimal $oradix.*\\." > + > + set test "x/10i main with output-radix $oradix" > + gdb_test_multiple "x/10i main" $test { I wonder if using x/i or x/2i would be enough. I think it's good to minimize the amount of stuff emitted by GDB, so that we don't fill a buffer on slow/overworked machines and get unreliable tests > + -re ":\[^\r\n\]*\r\n(?:\[^\r\n\]*\r\n)*$gdb_prompt $" { This can be simplified in a few ways. First, you can use -wrap to wrap your regular expression in the stuff that gdb_test adds around it, so you won't need to add $gdb_prompt at the end and some stuff at the start, and second, the whole "\[^\r\n\]*\r\n(?:\[^\r\n\]*\r\n)*" is just "any number of lines with any amount of characters", so there's no reason to not use a simple ".*" there. We just avoid .* when the exact amount of lines, or that something is in the same line, is important, which isn't the case in this test. > + pass $gdb_test_name > + } > + } > + } > + > + test_pc_offset_radix 8 {0[0-7]{2,}} > + test_pc_offset_radix 10 {[1-9][0-9]+} This regex fails if the number is exactly 0, but if you use multiple instructions and -wrap, I don't think it is a big deal.... > + test_pc_offset_radix 16 {0x[0-9a-f]{2,}} > + > + gdb_test "set output-radix 10" "Output radix now set to decimal 10.*\\." \ > + "restore output-radix" > +} > diff --git a/gdb/valprint.c b/gdb/valprint.c > index 62b1b33bb66..ea4bece0416 100644 > --- a/gdb/valprint.c > +++ b/gdb/valprint.c > @@ -171,6 +171,16 @@ show_output_radix (struct ui_file *file, int from_tty, > value); > } > There should be a comment here like /* See valprint.h.  */ > +std::string > +format_pc_offset (int offset) > +{ > + const char *sign = (offset < 0) ? "-" : "+"; > + ULONGEST uoffset = (offset < 0) ? -(ULONGEST) offset : (ULONGEST) offset; > + > + std::string body = int_string (uoffset, output_radix, 0, 0, 1); since uoffset is ULONGEST, you should use pulongest. However, I don't even think you need this extra variable, you can just pass (offset < 0) -offset : offset to the int_string call. > + return std::string (sign) + body; why not declare sign as an std::string? I think it would make things a little more readable. > +} > + > /* By default we print arrays without printing the index of each element in > the array. This behavior can be changed by setting PRINT_ARRAY_INDEXES. */ > > diff --git a/gdb/valprint.h b/gdb/valprint.h > index 0ce3e0781f6..5511707cba3 100644 > --- a/gdb/valprint.h > +++ b/gdb/valprint.h > @@ -320,6 +320,12 @@ extern int build_address_symbolic (struct gdbarch *, > int *line, > int *unmapped); > > +/* Format OFFSET, the offset portion of a "" display, as > + a string with an explicit sign prefix ("+" or "-"). The numeric > + portion is rendered using the current "output-radix". */ > + > +extern std::string format_pc_offset (int offset); > + > /* Check to see if RECURSE is greater than or equal to the allowed > printing max-depth (see 'set print max-depth'). If it is then print an > ellipsis expression to STREAM and return true, otherwise return false. -- Cheers, Guinevere Larsen It/she