From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id Yd4BFdVKHGmIMw8AWB0awg (envelope-from ) for ; Tue, 18 Nov 2025 05:30:45 -0500 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=A2lxfcf+; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 4D5591E0B6; Tue, 18 Nov 2025 05:30:45 -0500 (EST) 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 server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (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 B36A71E08D for ; Tue, 18 Nov 2025 05:30:44 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 67957385781B for ; Tue, 18 Nov 2025 10:30:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 67957385781B 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=A2lxfcf+ Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 45AE93857810 for ; Tue, 18 Nov 2025 10:29:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 45AE93857810 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 45AE93857810 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1763461742; cv=none; b=tByHx7U5p4o8tHrdZzg2YusJCDdwnJxm6wVJVQCztEx6cxx6VlN+2OKHcD7jfwL2UoAbaEZFgAzGRaMIb+ITqSQn0fydyx05XLWoAawu5tm8rK8GAUa9QFP2BX05i7fZTyXKysaYGmdryYB1FelE0Sha0+QmKtV/p7NPGMT1V5g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1763461742; c=relaxed/simple; bh=2Z/wIk5mnTArMpFnDynON5GjxFoN7NuYonPHcC5LbHE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=jIbyzPY/9i+lpNnP0Ebi+qpNvbvTkCYpJcurpGaovf6yM7YDGQ/lM5KyRqfZJFxdilNqmSbBiN20GXwEm3pmgSXYS+QaWquRDlQJtS3OcTd/ZK1fqywBFS3OwhSpg7zpH0SKZEKD4ur6tslRoCwgIWuuHxe7x4ZG+IU4oFrU5yU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 45AE93857810 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763461742; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lz2tdriAmbVzra880VDhm2UgA1L/ifVzA/Aw0ryaASY=; b=A2lxfcf+ZxHB1+kfRFSRo+NIBiPtExwQ9CgLDeCuxRZIHDR22SVFbx0m85X6TFLglpMf2t sFoNILlcKFoBTDM3s7Jezu2cQpSo5rsGBEdHB9AAfqz1aBxEeKvtQxfLBYO3W+vWGnU7QS FyJzOBnjwR5+iJp6cV0uvTkLe9t/4Rw= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-517-w6VGXl3NOg-lMyYX6OKJXw-1; Tue, 18 Nov 2025 05:29:00 -0500 X-MC-Unique: w6VGXl3NOg-lMyYX6OKJXw-1 X-Mimecast-MFC-AGG-ID: w6VGXl3NOg-lMyYX6OKJXw_1763461739 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-429c95fdba8so578754f8f.0 for ; Tue, 18 Nov 2025 02:29:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763461739; x=1764066539; 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=lz2tdriAmbVzra880VDhm2UgA1L/ifVzA/Aw0ryaASY=; b=BIoAEwFOb9T3OX9aQAj6PIf6XxydU8OLJG9NwL+B9OMR+mZ4eiS6DqCPv79lsSPeuH toJFBRJnNWbf2LgZeMAewUIzIrd4CQmAf+iizydV1iDKQigW6XuHbjfpKIlEEITeLu0B FJsVDqGmKXiiRo3Iu0XytF6gOZ9mbSJ4WZ+raS5yD4fVoDUoAVVBX4kwwBRljoquMgHH b8L8FMFxHBSbF/MAf6ff3SXCScDglj5gEXbGoUVanFBOPD8SpmLJ2tyi8Ddic/xVTtbr MhQy+tJOGY2S2qdvoP0gMtWeW94Br3FZqIxpTRnXYRwLv+dWTBP+54EGp6zBHdpGQMwI bQOA== X-Gm-Message-State: AOJu0YwEqCvYiALuR+fygOg4gz9jFuDpDXgHRerB0zJ1HuMfYcfOWTNf 1DaOPKwT2p0TZa/fF1JVW4jf4spsXkZUqHclv+SdVrtBm6c6KhL3Pi/X9Ofxhh40TCuRlJSQe9I LKv+umUcnuxnJxYInAdw4LxGRB39KGCOIc/FKXa0dKOWh+mInu0QNjVAGBIhQYvLlEKXsZLdVqJ rrs+tE3gMAISfn7GS/9wy3Cn1IqbWnR4saC4vLpSmqqCKDIco= X-Gm-Gg: ASbGnct/gmuEvXPO+Yz+GL2Z+ne7iNvG3yHpBOrX/vflRc9w7XtmcVtURCPWk5WQvZc BIzWcwUzaMKE3yID24mhoEJygTTPUCS0a9M1+qmy5m5jEhdyjUn+WAGGD5wmV8AzkmJ1kgDNXxn 4VNN/p21AlkRZv9DDiHQYImqUQCcdsns+uNEoL0P2AoOyI7Dt8g6qjRFJXaiaBSIF9KjSmrIgoU V0ymeUbypx9vUiO2FSwQzMoGg3nJXyvmrYpIaBod1WdH1kHzAOstGoCa5QDHbZ24tQkarx3qaB8 opgyqbSBHx3YxPv49Zi/qV1IKBttVZLGCfNt2gjBK3YGSYr00Cw4HmRiLU3pBkI3l2yOtY5C3bk J5HYU X-Received: by 2002:a05:6000:1845:b0:42b:3aee:429e with SMTP id ffacd0b85a97d-42b5938a9d7mr14401989f8f.56.1763461738989; Tue, 18 Nov 2025 02:28:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IE2xLuZkyS+AnW3JewoRhFgBT2SQ2e9WlfriAtxSBJL+uUtk2aD45d4AF2K1MXoJ0Z5iRhSEA== X-Received: by 2002:a05:6000:1845:b0:42b:3aee:429e with SMTP id ffacd0b85a97d-42b5938a9d7mr14401966f8f.56.1763461738518; Tue, 18 Nov 2025 02:28:58 -0800 (PST) Received: from localhost ([31.111.84.207]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42b53e982d6sm31446444f8f.21.2025.11.18.02.28.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Nov 2025 02:28:58 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 2/2] gdb: display a symbol more often in multi-file list output Date: Tue, 18 Nov 2025 10:28:53 +0000 Message-ID: X-Mailer: git-send-email 2.47.1 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: mhnT9azVMd7ojKkg1JwyXnuI9_3atpVxGXPtPUO9w5Q_1763461739 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true 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 I noticed that when a command line 'list foo.c:10' displays multiple files, the symbol would always be shown as "???", e.g.: file: "/tmp/foo.c", line number: 10, symbol: "???" this is because, when the symtab_and_line is created for the 'foo.c:10', the pc and symbol are never filled in. In this commit, I propose that, when we decide that the above header line needs to be printed, we should attempt to lookup a symbol for the relevant line, and if one is found, we can use that. The symbol lookup is done by first calling find_pc_for_line, and then using find_symbol_for_pc to find a suitable symbol. --- gdb/cli/cli-cmds.c | 8 ++++++++ gdb/testsuite/gdb.base/list-multi-source.exp | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 300b77dbafe..4534c670730 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -2174,6 +2174,14 @@ print_sal_location (const symtab_and_line &sal) const char *sym_name = NULL; if (sal.symbol != NULL) sym_name = sal.symbol->print_name (); + else if (CORE_ADDR line_pc; + find_pc_for_line (sal.symtab, sal.line, &line_pc)) + { + struct symbol *sym = find_symbol_for_pc (line_pc); + if (sym != nullptr) + sym_name = sym->print_name (); + } + gdb_printf (_("file: \"%s\", line number: %ps, symbol: \"%s\"\n"), symtab_to_filename_for_display (sal.symtab), styled_string (line_number_style.style (), diff --git a/gdb/testsuite/gdb.base/list-multi-source.exp b/gdb/testsuite/gdb.base/list-multi-source.exp index 7809167bd0f..33bd49ad14b 100644 --- a/gdb/testsuite/gdb.base/list-multi-source.exp +++ b/gdb/testsuite/gdb.base/list-multi-source.exp @@ -63,13 +63,13 @@ set last_linenum [expr {$linenum + 4}] # List using FILE:LINE for a filename that is ambiguous. gdb_test "list foo.c:$linenum" \ [multi_line \ - "file: \"\[^\r\n\]+/a/foo.c\", line number: $linenum, symbol: \"\[^\r\n\]+\"" \ + "file: \"\[^\r\n\]+/a/foo.c\", line number: $linenum, symbol: \"get_value_common\"" \ "$first_linenum\\s+\[^\r\n\]+" \ ".*" \ "$linenum\\s+[string_to_regexp {return 3; /* List this line. */}]" \ ".*" \ "$last_linenum\\s+\[^\r\n\]+" \ - "file: \"\[^\r\n\]+/b/foo.c\", line number: $linenum, symbol: \"\[^\r\n\]+\"" \ + "file: \"\[^\r\n\]+/b/foo.c\", line number: $linenum, symbol: \"get_value_common\"" \ "$first_linenum\\s+\[^\r\n\]+" \ ".*" \ "$linenum\\s+[string_to_regexp {return -3; /* List this line. */}]" \ -- 2.47.1