From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id jFRKA7MR+Wk0axMAWB0awg (envelope-from ) for ; Mon, 04 May 2026 17:37:55 -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=t/n8y0Gx; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id E69771E0BA; Mon, 04 May 2026 17:37:54 -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 ADD5C1E067 for ; Mon, 04 May 2026 17:37:53 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id CB2C34BAD16C for ; Mon, 4 May 2026 21:37:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB2C34BAD16C 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=t/n8y0Gx Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id 560934BA2E06 for ; Mon, 4 May 2026 21:37:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 560934BA2E06 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 560934BA2E06 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::634 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777930637; cv=none; b=egCmbfn9+rJ+8hRlRUQX/6ep3wDuzMk3Z9M9Uyypubk9vM/WhPw+AvM3ni4ozVEFHc9czkfnQdzS5JtyLpvjQfaSu1c497AerhqpqzFeR+QXTtZHcP0GMPu+51rpVxVQoW2YLZgVvnCqkHp6ZgOgXAGMJLZ8JhcdzeqAhRzY41A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777930637; c=relaxed/simple; bh=C8cuQz4BtPbmn2HzWJRmf3GRSAvQ4U8eBwjOHZMme1I=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=baDXaBgbqHS1UXqMMnT0XPkY5C+mt4KOlg6rfGYDvXyiPBdYDXZ4zqp0c7BoHzWbxoxeDU+upiRZf8+XozKN61Jny20TfgVDsBbI+ll8nK7+LHiau5kO/P37BpY3I2qu30OJVJH3V53RsvMVa/UAu1cW0gFk3sj4QAr3YBihWtk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 560934BA2E06 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-2b2e8b95bdbso14625ad.0 for ; Mon, 04 May 2026 14:37:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777930636; x=1778535436; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=n3pxNO+abpSc6UDNUe2Ey8LmsQaodpmRjibpxaXBlOY=; b=t/n8y0GxVn0OJIBaiBWQ/yPePDYIxCQg0IiI3ps91+iN/CMctqrE9xyJO85yU5HcAx tOTtCtZR8LCNyFBu87at4G3phhyrm0S8h1RGb+xVxK3XwEHfXyCIlRiRmUD9v8tiUE9s K25fRHPP+JFtGlKSMapChZbooU06m4el4iRsw7/8q+GySOD0qUShzKWBEA1wIBrTyG9q KtFbVafvH0CCPX7qO+xHfkbEOxwdm2n7qRb0E6M7e4WE4aA27q5EfdvDJTMy34sshhd8 MNFCbhWC7AZVE0wQe8NBDgy6lpJOqLvpbz2b94rAkd6i1O+AWk+DyF+08jIVWWiHBeWQ UXXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777930636; x=1778535436; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=n3pxNO+abpSc6UDNUe2Ey8LmsQaodpmRjibpxaXBlOY=; b=pBpsIiP0svCWLmnSBqG2LS8SUOrEBTX7drsIetfdQpT36DSosRiylPWNDEqufY+E5S 4iObn0xWLr5/mDY4azSFumOzvifC/BZJJaGr89kVkfsJ4IPYNdQHZqXPjQGUiRtpQ6cS bDl+Jt4Uhbxe6QLO31KFZDxzADjeT+oEs5x9/aUIAvbrj8dHq9FxNNFh8PDOBlYmU5aG pA+0z8L6hUrLjSklQF86y/o1NO2Yyou9YrdS/MJowf1O6r4CDnm72eq7+Ioi21r0Clbz vD6TbT5CPHemFgGoe/hBJgBKw0vVYNwNkZUIu1jYAMuvhBTN9MqffaNWhUST+y51623B UuMw== X-Gm-Message-State: AOJu0Yw/IT9Quo7ug7frwCzw54bPerXAw6PrMc8EvaNRMA3ZxAww0A1i gJ5R1P3INh6K0Ee5hoP/2yXEpd8K8esJCQrIsf8woFdeZJW35ObeS270T9qElKL8GkFCCZn1SwO zRrCROG6+ X-Gm-Gg: AeBDievdvsug5/7u2ElEpjcK48UKC6t1fVGyZNnIyR/KO8s8k3hSwK5JLHE5KRoECZE W/sPRbmIK/mzmuAz8J2CXzjzMWDHztneXKnBBJ01f33GR56IpO7X0IAZdEaLUvCd11o6NFqikla ClsJ0ASlGgYXhWkNIqupjgROvGbgKPzwJct0EMKDuS7J7ON4pXyymDOsLynGFyWXUcihRMS257C xNkQZboSptC6tD+46xJSJa4grjBIbuOsJ771qu/2IKHFlO0/R8DGSKEdk+hZ9xtnrCrR2shqT3A dhq32bLqnoZjpA0YILrw88UBFjXcO/1pqUI4pta8jnc5u5MjJ7Dg605HUEh1HjuVBGozUcuUKzC sr+V6FsZnniJXNatWyZxIsUbnRcT7u7KO1Gyz/hyNEbAdRn6T1Gve+rxpKZbev8QrE7R2ILXRpP O0QszDZYPzHdLzp966CdEOyvzvEqNJckpQXmG0G4Knwr4hSI4/pLwm1H6P0yU= X-Received: by 2002:a17:903:2cd:b0:2ae:6755:a24f with SMTP id d9443c01a7336-2ba4f5f1f93mr1449725ad.0.1777930635719; Mon, 04 May 2026 14:37:15 -0700 (PDT) Received: from ztop ([50.45.162.246]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-83943de45e0sm75849b3a.9.2026.05.04.14.37.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 May 2026 14:37:15 -0700 (PDT) From: Zander Work To: gdb-patches@sourceware.org Cc: Zander Work Subject: [PATCH] Use "output-radix" setting to format function offsets Date: Mon, 4 May 2026 14:37:10 -0700 Message-ID: <20260504213710.209740-1-zdw@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog 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 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 --- 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); + } + 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. + + 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() +{ + puts("hello world"); + /* Don't let the test case run forever. */ + alarm (60); + + 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 { + -re ":\[^\r\n\]*\r\n(?:\[^\r\n\]*\r\n)*$gdb_prompt $" { + pass $gdb_test_name + } + } + } + + test_pc_offset_radix 8 {0[0-7]{2,}} + test_pc_offset_radix 10 {[1-9][0-9]+} + 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); } +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); + return std::string (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.545.g6539524ca2-goog