From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id CzZZLTydHWk0xBIAWB0awg (envelope-from ) for ; Wed, 19 Nov 2025 05:34:36 -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=aPmHicZg; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id A57AB1E08D; Wed, 19 Nov 2025 05:34:36 -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 141BF1E08D for ; Wed, 19 Nov 2025 05:34:36 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A1B23384D16A for ; Wed, 19 Nov 2025 10:34:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A1B23384D16A 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=aPmHicZg 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 47C71384D178 for ; Wed, 19 Nov 2025 10:32:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 47C71384D178 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 47C71384D178 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1763548372; cv=none; b=xe70mrb1xJRNHlKg5D5zMDQX59mrksqSgvYMjfhJSQTqKg+bgsBakrEp79jp3OWuQHns2APA9FQdHT41tSJ6OQFGp4MoD3DjQYEjJmGhoawipN0OlwKlXEi/eBtJf4uAqK147hzzUJIyUzh4c4qJ+dX/vg5Q4BwHdJGuL+BpINo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1763548372; c=relaxed/simple; bh=Qyd07uibLYmH887aubDA+OCN2yVzSNdLrGv5keLI0HM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=GDcqcg3OqQ/7dsShs1oHkd8aE3Y9zncoWlquQCWBZaNbsyidC2L2Gl2OCOhExm92sc1Nw3l3NkFwT12YEHN8KUFaM+54wthZpza6ZpNDVAyjMqIJd42K9a17c6lB50zSQs++PPbW7bN7e2jHsw48DK6ANZIiyq0uGAkkWCKZ40w= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 47C71384D178 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763548372; 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=+85qfeqmdCCFnHWa/uRqFaugrSDJezGWvuajq7eEPAA=; b=aPmHicZg3lXlaRpfBOuW+jrtXFBeS2LR8p5udCi3I2AOcQf9wiVDIswnwIFoBgzg+jWDkT orm4BAn5WGkooEYayKNWuNF/qXStBQJNEq/sOaWTVDjazFdFZGE7sY/Kr9EeivrQpxxVpv xqhMY4WtkClJGf0tCjLmpGpNcuZBRwY= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-92--Lq77W-RPhWfa3jpKiCvlg-1; Wed, 19 Nov 2025 05:32:50 -0500 X-MC-Unique: -Lq77W-RPhWfa3jpKiCvlg-1 X-Mimecast-MFC-AGG-ID: -Lq77W-RPhWfa3jpKiCvlg_1763548370 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-477a027877eso36455375e9.2 for ; Wed, 19 Nov 2025 02:32:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763548369; x=1764153169; 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=+85qfeqmdCCFnHWa/uRqFaugrSDJezGWvuajq7eEPAA=; b=GwWhgN362eFGw4f5zVE85gsewqUTPpYXpbqYb/rX1h57s0OZ09WA6DZ0Rw7pmNOpUB Utnx01qA2urTzu0As3xJXwqJcke3uUV3++tl2uxh5QjmnWz1SrpmSUT5E/+IKMN8Y0O8 O1Fl5bFNyr/XSiiSPNXEUHDImr5Gd/Dk7r+a5FkXaEusqWA2QTEc/X1xw7PGEVh2LYjC 3inDnEbfX5324GM504htIbcM1GAheSL0UZOClU5rCHu9AfPQqEJ1bD1msTOiih1MG3lE 3UOGHWN1dP9E7ykbqaSWFWFoHQjlE+xF1y7Ic6QuGup2+Ot3b4P2TVFGI7gGlk6NzN3F NV3Q== X-Gm-Message-State: AOJu0Yy8pc5SfsmyWDUK4sHxp1nkCjY7XMxlzW0ZLOFK/LLtr9sLj7Xg 8Ffqtk+sdoRIIToWfE0ZrX2VpA8xApTw2V2h7NoVgOhC3scb7q696WQV/FfQWZIwHqqMoI5WH2u 1g9G37p5pV1gjo7XXkMwdSb9WanJxJREPI7m6zuV/LPwiA9RK/LPZykQJZ11RJ+swkdGFy9z7Oa t5FTU5/peabSkK3LDpF49pGLxQKdF6NtGoQIl6JVPTB07F0oE= X-Gm-Gg: ASbGncvMy6hbznGdD/AmlD5eXrFrxWGr4pvcrUGj9jAoBhQTRqksEw44bqAaZfpQwcr sMzzmHMgNgvuRm6aBddWCN9ui2XGaEi31ZRwpvp6iPOYIP0fofoybwhRfPvy100zeuWecD+UfYU q2FpDXu8YfqwMk6X64EWbKpg526hzxAobpjyANMlM57LCZ1khJxpRTekAAIVP+kmXVi2EV4rtTw 3hUx9M3SNQNuoj58YMtYc5c6VPHF08iRk/Go167l0pzM46fDR6yswDsRFDWg0DT3M072ewzb6/S uFWwCRgQh5YcSNePcIMP/Nqjm8FDiQChDuvgXzY+w3HN8lsnN4lqLfHCqF1QBcrioKYJmBtfBy0 hDQ9S X-Received: by 2002:a05:600c:1c20:b0:477:5b0a:e616 with SMTP id 5b1f17b1804b1-4778fe4f635mr193913245e9.5.1763548369255; Wed, 19 Nov 2025 02:32:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IGTSlFUU80Zwog1B3/zJZMaE3SdrACKciL4vcBbjHz7ijfCGKNcDF/soy2VldiuKX/68Py5rA== X-Received: by 2002:a05:600c:1c20:b0:477:5b0a:e616 with SMTP id 5b1f17b1804b1-4778fe4f635mr193912885e9.5.1763548368807; Wed, 19 Nov 2025 02:32:48 -0800 (PST) Received: from localhost ([31.111.84.207]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42b53f17cbfsm37290893f8f.35.2025.11.19.02.32.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Nov 2025 02:32:48 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 2/2] gdb: display a symbol more often in multi-file list output Date: Wed, 19 Nov 2025 10:32:39 +0000 Message-ID: <9675f8737b6636b6f0ebbe60fe8cdefee9e0a67c.1763548233.git.aburgess@redhat.com> 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: ozipAKIgrh4aiWsvsVCk0yYwK9F89wg2GCsAB1OIT80_1763548370 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 43c1bc7a96f..cf5571c5419 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -2182,6 +2182,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: \"%ps\", line number: %ps, symbol: \"%s\"\n"), styled_string (file_name_style.style (), symtab_to_filename_for_display (sal.symtab)), diff --git a/gdb/testsuite/gdb.base/list-multi-source.exp b/gdb/testsuite/gdb.base/list-multi-source.exp index 66f6582fdff..887ff961933 100644 --- a/gdb/testsuite/gdb.base/list-multi-source.exp +++ b/gdb/testsuite/gdb.base/list-multi-source.exp @@ -97,13 +97,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