From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id GmS2AweEAmrmuzEAWB0awg (envelope-from ) for ; Mon, 11 May 2026 21:36:07 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20251104 header.b=Wh46Qwef; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id F03231E067; Mon, 11 May 2026 21:36:06 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-10.9 required=5.0 tests=ARC_SIGNED,ARC_VALID, BAYES_00,DKIMWL_WL_MED,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,USER_IN_DEF_DKIM_WL 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 5D86D1E067 for ; Mon, 11 May 2026 21:36:05 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1A5184B920A9 for ; Tue, 12 May 2026 01:35:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1A5184B920A9 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20251104 header.b=Wh46Qwef Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by sourceware.org (Postfix) with ESMTPS id 3446E4BB58D7 for ; Tue, 12 May 2026 01:35:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3446E4BB58D7 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=google.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3446E4BB58D7 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::830 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778549721; cv=none; b=Of7M5xspinq4RWBFAh9KMuQUC6bgncp73v+KPeIhfiOi5WwOSuELkBWj0OMkBL0d2AyFdfr7HbSU7d2cVjABj6Pjvb7369OtJa1ZNsEPfnT0QXw9pGntco9znJJ3pR/QPPDbxHQ+dqDb5VBBtTAPrgKbCfm0jZ5fyXIx5tXId04= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778549721; c=relaxed/simple; bh=/Bx7kFzRvxbuMBIRM9lRcdFYdX6NWaLuHJtmStLXTo8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=j/1wszCfLomn4u/mH/xYzwuBjuht8rLbtsWRPjRPuHdFdv96V4n1Y7IWgvzcNJYIQ26ZPUTJbrO53s4P6qr6upWC6yVL7D2N3ZHhBnuliIItNOOA3Xx5Qqn6NJBBw7R5+bHx87vWm1pTGY1x2f9DfDycAMZyW93H39dT2UL+fVY= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20251104 header.b=Wh46Qwef DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3446E4BB58D7 Received: by mail-qt1-x830.google.com with SMTP id d75a77b69052e-50d864c23bdso4141cf.1 for ; Mon, 11 May 2026 18:35:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1778549720; x=1779154520; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BgnNyGj0XnUAJjMOBUQGgMKSWGPABhmfTWEebWQhZpE=; b=Wh46QwefCQbnAZR9Z71qXLjId7irOM/Es9NaFw4q61o9XP2+X3I83gBlj7ZG8lM357 l5rJ7eOyLMo9EqN6tBoNHPkK0n/JjnQpsy/BvpY9kabcw049uPc4HOETfThRgPLDrzjj GLeZ/CEhzKGHYeHaWHB64zm82p7KB0j9ZGkgRK/+OTi7ksEkQlYbb0uZGegiIIh/hgt0 lEZbi2sUmO+MWX/AOWZatP2umnBGrR5v4LtQtWWoiT4X1hoUvIe+M822Duw06V28F4IA Z9ab8DAZfNr95zFFAexdutKBZkS3ltSSDcf70OHCVu8gd1cLUps1s67eLRHDvZK+hEWH 1VuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778549720; x=1779154520; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=BgnNyGj0XnUAJjMOBUQGgMKSWGPABhmfTWEebWQhZpE=; b=NrbJD86n03bTQYGT0sOJ8BK6nwhAfBmpZfXaAxeG3Y53ev2bRODkiVqJDnY1l7pJAh /PdDObP54xO0o+DAGAfqsEVaasy7c6JDs3+r1DPQChjB0WmFVB/mkU2Czy+VoeXCPP/q e3nEOBBkEO79dahu/g+zNFhw1xn3GCKOchna22uIJiE3jqFTzA3Fm3Gh/M/F6uU2hJPO zq6M5g/R1M1NntcBG8XyXPFqiaGu8ZLv4fDTQ8vNY1WSTEFydSS4AenHsL5brFJcpZW5 /oVpFEITrfBIdxcUuXJ1N4YyQaQ7p2QQB1MNNgvg3E9SCHrSmpd3mkKk2z/Sq33x/6m7 9o9w== X-Gm-Message-State: AOJu0YzvpkaK4uAZSl8fFSxFx10lU6dKRLoajqaAVFHw188aaBu0Eo+7 CPpRYmlWhcVNUHVIqENtjfwH40aKffsHHhSfJ7FSQQ4Ox78riRKLF1iJyEEsw1D0avhTVKGno42 31aAvBYiW X-Gm-Gg: Acq92OGDQqWPWkE+xPseceDqUSM0pv7112wC4P3PfV9xr9wKP0aQ0zAw43yfzlsW7az d+q2UV4zc7pjMXdf9FlflNtnY3OMBRqFRbgQi4dYCIorSWGPPKsaMOTQVQq7tUiUe+pBUHnc+Ej 7YBZ9mgGK6t3Iy4pAZUZNz0r14/R8luqpYnDbD5CDYovmi5NXaAffUIqdS7PWse2h0YeZK5gHz9 N9qIY1/U2o7i9ez85XDE1eSBPoUDFdoSYZZH1CztReq3GJ9k2xSYfvn7jUlJ5XJSzKIPNFbjW+r t403MyM17A/R2pqcqz2D2vZFW7oMmUdlDNrH2HD1qLOz7oZna6JTF4If256I6F0fFM9ZERTTyVG Xn3eHLsl17cAsld50ulIDEsCuuO4APhgfWdIxQeDD6XrDE8r5r74LwHsUSHw0oH9sXsPDY5q01W 64FQaLtSMvu3v6YtwAIH5jNasdlArnGCYnQ8sE2BCUY+yjNNsu7I7ZPui0opiXJr79Nq2REP0YF ltry1d8q7PUSlPoG3FXji9z X-Received: by 2002:a05:622a:5c08:b0:501:4eae:dbfc with SMTP id d75a77b69052e-514d451c3f0mr3209251cf.5.1778549719979; Mon, 11 May 2026 18:35:19 -0700 (PDT) Received: from ztop.w.home.arpa (ool-45706b36.dyn.optonline.net. [69.112.107.54]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8b53ce7e73dsm327879716d6.42.2026.05.11.18.35.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 18:35:19 -0700 (PDT) From: Zander Work To: gdb-patches@sourceware.org Cc: guinevere@redhat.com, tom@tromey.com, Zander Work Subject: [PATCH v2] Use "output-radix" setting to format function offsets Date: Mon, 11 May 2026 18:32:38 -0700 Message-ID: <20260512013237.646630-2-zdw@google.com> X-Mailer: git-send-email 2.54.0.563.g4f69b47b94-goog In-Reply-To: <350b3a8d-3174-4703-b532-4ba49fe5ea05@redhat.com> References: <350b3a8d-3174-4703-b532-4ba49fe5ea05@redhat.com> MIME-Version: 1.0 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 Thank you for the review Guinevere! I fixed the formatting issue you flagged, and added your review tag. Global maintainers: I haven't done a FSF copyright assignment, please let me know how I should do that. Below is the full original patch context. ~~~~~ 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. I also have not personally completed a FSF copyright assignment form. 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 Reviewed-By: Guinevere Larsen --- gdb/disasm.c | 18 ++++++++++--- gdb/printcmd.c | 2 +- gdb/testsuite/gdb.base/radix.c | 35 ++++++++++++++++++++++++++ gdb/testsuite/gdb.base/radix.exp | 43 ++++++++++++++++++++++++++++++++ gdb/valprint.c | 13 ++++++++++ gdb/valprint.h | 6 +++++ 6 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 gdb/testsuite/gdb.base/radix.c diff --git a/gdb/disasm.c b/gdb/disasm.c index 81c466c188a..64a9289e070 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); + } + 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..8a4d1287208 --- /dev/null +++ b/gdb/testsuite/gdb.base/radix.c @@ -0,0 +1,35 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2026 Free Software Foundation, Inc. + + 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 + +static int v; + +int +main (void) +{ + v = 0; + + puts ("hello world"); + + printf ("this is another string\n"); + + v += 3; + + return v; +} diff --git a/gdb/testsuite/gdb.base/radix.exp b/gdb/testsuite/gdb.base/radix.exp index 7a4320bbf36..4b8e2d74b49 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,41 @@ 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/i with output-radix $oradix" + + gdb_test_multiple "x/i \$pc" "$test 1" { + -re -wrap ":.*" { + pass $gdb_test_name + } + } + + gdb_test "ni 3" "\[0-9\]+.*" "Next instruction for radix $oradix" + + gdb_test_multiple "x/i \$pc" "$test 2" { + -re -wrap ":.*" { + pass $gdb_test_name + } + } + } + + test_pc_offset_radix 8 {0[0-7]+} + test_pc_offset_radix 10 {[1-9][0-9]*} + test_pc_offset_radix 16 {0x[0-9a-f]+} + + 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..d0d0472ca7a 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -171,6 +171,19 @@ show_output_radix (struct ui_file *file, int from_tty, value); } +/* See valprint.h. */ + +std::string +format_pc_offset (int offset) +{ + std::string sign = (offset < 0) ? "-" : "+"; + + std::string body = int_string (offset < 0 ? -offset : offset, output_radix, + 0, 0, 1); + + return sign + body; +} + /* 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. -- 2.54.0.563.g4f69b47b94-goog