From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id Jey4OqlAKGopDT4AWB0awg (envelope-from ) for ; Tue, 09 Jun 2026 12:34:49 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=e1cs2kGj; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id DE5D31E070; Tue, 09 Jun 2026 12:34:49 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED 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 E45DA1E070 for ; Tue, 09 Jun 2026 12:34:48 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A1CC64C31860 for ; Tue, 9 Jun 2026 16:34:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A1CC64C31860 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=e1cs2kGj Received: from mail-oa1-x33.google.com (mail-oa1-x33.google.com [IPv6:2001:4860:4864:20::33]) by sourceware.org (Postfix) with ESMTPS id 9DE554BAD17F for ; Tue, 9 Jun 2026 16:34:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9DE554BAD17F Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9DE554BAD17F Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2001:4860:4864:20::33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1781022860; cv=none; b=OSPBznjPBrzcoT1ioMa56A7siwQzsLu1rQwF6dbcMpz/6DR1L9AvOBgOHNZsb/teTfuAZK2bjPT/vHilSyQs03ao5appjmzNg5dHRnAumwSVHmWX+wVo9Wmn21YucvFFkCTLlFYq0KMw1qCjU9AGWjgLM3kevcKC3CkROP7JlJM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1781022860; c=relaxed/simple; bh=s4RnZ2eDSNfMpksu/tYgjZw3EG1LKIIeBiMyq4HmhN8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=nmkWj9qJsTqEA7rVwxVFpSHlHQyKxn+30+lYGC2jIJqA3hD0riubWLN7zEI74uSYjGxtsm8CObUwLmqFXhvdn8cU+HpDKedG14tl9Y0mjKRVBa2yK2K1Mbc6WhsloyQO80ll49eJtxeIi9lMVKNjV42lFjykkYV5aOcxtCJ6Wcg= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=e1cs2kGj DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9DE554BAD17F Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-43d2ff651f2so4638637fac.2 for ; Tue, 09 Jun 2026 09:34:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1781022860; x=1781627660; 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=mSGJcNfERHXGyTnbrSMSLwfEkZIcgKEbTsQZ1aG4TPw=; b=e1cs2kGjs7aGcttDqthZKLxlgI6Xsixw4lzKQFsmdwMCROqPnCIweys4dn0qIeh5J/ YSE2waO18C2X32le3+LibWqR3RfP28rtewocGpdTS5S838kIs2zsaiyI/ama/L8M/qrc Auw9lFEXJtGu1xlMcRRaZhYILKmpbfNHBNhoaEIXJEX2IDk4wtJZ6QaBqMyFvPgQli3H FGi3ChW19zyI44dKAF8xmz0MjGkbTQu2Dbt5vfgGoDJ2OwdTVXuUqaqtGLju/lEgg5Qk hY50PbRzBybFSyfLaoQFyKO8gfqGT7/EGTNw1M9BS+bDRpVlhW+YKLkc5tyAvePuWHMV 9IOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781022860; x=1781627660; 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=mSGJcNfERHXGyTnbrSMSLwfEkZIcgKEbTsQZ1aG4TPw=; b=da4m+vbDFLJt4udxN0Zqqnd9eNkSDdO0D48aqXx4SxSXPSF/eK59jKmHadlH5iaDjR NP9v2G9u6xH9dA7mGZYZ8PxoknGYisw51srRIFe+AWVmGsvt3fNXCakMc2wVJHhPrTnm R4qATBFsPb91xDjc8MsYsLJTfI74WCCi8JUHibl8fEcnllJoPx+ibh2DtrIWP/bi9iZJ Rj+JrtOr9S1lYDfW90HUobAn+su+zvggDXS7l/JJl/en/4kdR51k0NPD10UwOMO/dWMi ZIszpK4vQmznTgkhPfBnWHEn4hD1/4Ca2EDsB2IH9ytKJ6hKPDzzmsoltbm6XMZu9T2h etWw== X-Gm-Message-State: AOJu0Yz9FJ0b6ba5DQVNKiYj+OIqYzUJAkTnQj5znLdm7DTEtdtlKANX 73OLMacEaVyPX8wbeGL97KrfltzudQ4D+2P3cMsnPtp07KK7sRGbZ0lQdg606PvspPUZ/9CezJh vruw= X-Gm-Gg: Acq92OHQnlBG+akrQf+iEJfCkUsDILBlWPMxeYxvEeXg6RmAy1BSx5PQj+Y6wFwlLw4 0eLPvJOb6gjdyhSL7DOwYANNWrfBPTLTtSo+tVRwBfOhJd2z2C6W4iTiT/XWxH9Iws4YKlCoTN5 jrhbh3dJY3TKHAwCbrTPZWC2+lRCR/1T6/2k1N1TeGGyBZ1vPSPm9yQnjwNFQ9Z2vDyNJU6Z7AE pbUZ9n8EEfEPwzm9PbMcmoxCLTaSn5acJOtp7QfKUF0xo7vp7zqg1pNb+YgWpM2iiGJF8cCGq2X L8Ekic49MwMHSql1uU2Pq8NTipOw0swxWRN+1JXC1u1qbHqI1fxU05ssYZP1wM2xdtFm3UjZzxT Fm8KKvO9zHwSMB0l4gklmokfrHErzrzCPfTPM2J7MXKW2expwOPkTN2zQ9RyoOGT2XV3ULSXbJ2 gRfD+8aBg9f0CWFzboEGxQLvFoH9/adoOak6nQY8PywjSdP0TxR+imXi2T4EPkkNDx X-Received: by 2002:a05:6808:d49:b0:479:e869:5424 with SMTP id 5614622812f47-4868dc7df9bmr11871278b6e.19.1781022859652; Tue, 09 Jun 2026 09:34:19 -0700 (PDT) Received: from bapiya (75-166-225-82.hlrn.qwest.net. [75.166.225.82]) by smtp.gmail.com with ESMTPSA id 5614622812f47-4865b977c46sm17797497b6e.14.2026.06.09.09.34.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2026 09:34:19 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Sort symtabs using their display filename Date: Tue, 9 Jun 2026 10:34:16 -0600 Message-ID: <20260609163416.3421440-1-tromey@adacore.com> X-Mailer: git-send-email 2.54.0 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 While working on gnat-llvm, I found that many tests in gdb.ada/info_auto_lang.exp were failing. Investigating this, the difference turned out to be a different sort order for the output. I then tracked this down to gnat-llvm emitting: DW_AT_name : (indirect string, offset: 0xdd4): pck.adb ... DW_AT_comp_dir : (indirect string, offset: 0xddc): /home/tromey/AdaCore/binutils-gdb/gdb/testsuite/gdb.ada/mi_dyn_arr/ ... whereas GCC emits: <108b> DW_AT_name : (indirect line string, offset: 0x10f): /home/tromey/gdb/binutils-gdb/gdb/testsuite/gdb.ada/mi_dyn_arr/pck.adb <108f> DW_AT_comp_dir : (indirect line string, offset: 0): /home/tromey/gdb/build/gdb/testsuite/outputs/gdb.ada/mi_dyn_arr This distinction isn't relevant to the test, so I tried "set filename-display basename". However, this setting had no effect. It seems to me that, for "info types" and the like, the output should be sorted according to the user's display preferences. This patch implements this and adds a new DWARF assembler test. Finally, this updates info_auto_lang.exp to be insensitive to this quirk of gnat-llvm. --- gdb/symtab.c | 6 +- gdb/testsuite/gdb.ada/info_auto_lang.exp | 18 ++-- gdb/testsuite/gdb.dwarf2/symtab-sorting.exp | 108 ++++++++++++++++++++ 3 files changed, 122 insertions(+), 10 deletions(-) create mode 100644 gdb/testsuite/gdb.dwarf2/symtab-sorting.exp diff --git a/gdb/symtab.c b/gdb/symtab.c index 3c10e1fd750..00205c31975 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -4610,8 +4610,10 @@ symbol_search::compare_search_syms (const symbol_search &sym_a, { int c; - c = FILENAME_CMP (sym_a.symbol->symtab ()->filename (), - sym_b.symbol->symtab ()->filename ()); + /* The output is going to be displayed to the user, so sort the file + names according to how they will be shown. */ + c = FILENAME_CMP (symtab_to_filename_for_display (sym_a.symbol->symtab ()), + symtab_to_filename_for_display (sym_b.symbol->symtab ())); if (c != 0) return c; diff --git a/gdb/testsuite/gdb.ada/info_auto_lang.exp b/gdb/testsuite/gdb.ada/info_auto_lang.exp index e717802a8d2..2b060a4939b 100644 --- a/gdb/testsuite/gdb.ada/info_auto_lang.exp +++ b/gdb/testsuite/gdb.ada/info_auto_lang.exp @@ -44,6 +44,8 @@ if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug]] != "" } clean_restart ${testfile} +gdb_test_no_output "set filename-display basename" + set bp_location [gdb_get_line_number "STOP" ${testdir}/some_c.c] if {![runto "some_c.c:$bp_location"]} { return @@ -119,10 +121,10 @@ foreach_with_prefix language_choice { "auto" "ada" "c" } { [multi_line \ "All functions matching regular expression \"proc_in_\":" \ "" \ - "File .*proc_in_ada.adb:" \ + "File proc_in_ada.adb:" \ $func_in_ada($ada_match) \ "" \ - "File .*some_c.c:" \ + "File some_c.c:" \ $func_in_c($c_match) ] @@ -130,10 +132,10 @@ foreach_with_prefix language_choice { "auto" "ada" "c" } { [multi_line \ "All types matching regular expression \"some_type\":" \ "" \ - "File .*global_pack.ads:" \ + "File global_pack.ads:" \ $type_in_ada($ada_match)\ "" \ - "File .*some_c.c:" \ + "File some_c.c:" \ $type_in_c($c_match) ] @@ -141,18 +143,18 @@ foreach_with_prefix language_choice { "auto" "ada" "c" } { [multi_line \ "All variables matching regular expression \"some_struct\":" \ "" \ - "File .*global_pack.ads:" \ + "File global_pack.ads:" \ $var_in_ada($ada_match) \ "" \ - "File .*some_c.c:" \ + "File some_c.c:" \ $var_in_c($c_match) ] gdb_test "rbreak proc_in_" \ [multi_line \ - "Breakpoint.*file .*proc_in_ada.adb,.*" \ + "Breakpoint.*file proc_in_ada.adb,.*" \ $rbreak_func_in_ada($ada_match) \ - "Breakpoint.*file .*some_c.c,.*" \ + "Breakpoint.*file some_c.c,.*" \ $rbreak_func_in_c($c_match) \ "Successfully created breakpoints $decimal-$decimal." ] diff --git a/gdb/testsuite/gdb.dwarf2/symtab-sorting.exp b/gdb/testsuite/gdb.dwarf2/symtab-sorting.exp new file mode 100644 index 00000000000..833c08ec4f1 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/symtab-sorting.exp @@ -0,0 +1,108 @@ +# 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 . + +# Test handling of an array type whose bound comes from the field of a +# structure. + +load_lib dwarf.exp + +# This test can only be run on targets which support DWARF-2 and use gas. +require dwarf2_support + +standard_testfile main.c -debug.S + +# Set up the DWARF for the test. + +set asm_file [standard_output_file $srcfile2] +Dwarf::assemble $asm_file { + global srcdir subdir srcfile + + cu {} { + DW_TAG_compile_unit { + DW_AT_language @DW_LANG_C + DW_AT_name /tmp/aaaa.c + } { + DW_TAG_base_type { + DW_AT_byte_size 1 DW_FORM_sdata + DW_AT_encoding @DW_ATE_unsigned + DW_AT_name byte1 + } + } + } + cu {} { + DW_TAG_compile_unit { + DW_AT_language @DW_LANG_C + DW_AT_name bbbb.c + DW_AT_comp_dir /tmp + } { + DW_TAG_base_type { + DW_AT_byte_size 1 DW_FORM_sdata + DW_AT_encoding @DW_ATE_unsigned + DW_AT_name byte2 + } + } + } + cu {} { + DW_TAG_compile_unit { + DW_AT_language @DW_LANG_C + DW_AT_name /tmp/cccc.c + } { + DW_TAG_base_type { + DW_AT_byte_size 1 DW_FORM_sdata + DW_AT_encoding @DW_ATE_unsigned + DW_AT_name byte3 + } + } + } +} + +if { [prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $asm_file] {nodebug}] } { + return +} + +gdb_test_no_output "set filename-display relative" + +# Here, bbbb.c is at the end because it sorts after "/tmp/cccc.c". +gdb_test "info types byte" \ + [multi_line \ + "All types matching regular expression \"byte\":" \ + "" \ + "File /tmp/aaaa.c:" \ + " byte1" \ + "" \ + "File /tmp/cccc.c:" \ + " byte3" \ + "" \ + "File bbbb.c:" \ + " byte2"] \ + "info types relative filenames" + +gdb_test_no_output "set filename-display basename" + +# Here the order is by basename. +gdb_test "info types byte" \ + [multi_line \ + "All types matching regular expression \"byte\":" \ + "" \ + "File aaaa.c:" \ + " byte1" \ + "" \ + "File bbbb.c:" \ + " byte2" \ + "" \ + "File cccc.c:" \ + " byte3"] \ + "info types basenames" base-commit: 1eed06ae51d73a195b78ce0903ada9c9c2c14cfb -- 2.54.0