Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH] Sort symtabs using their display filename
Date: Tue,  9 Jun 2026 10:34:16 -0600	[thread overview]
Message-ID: <20260609163416.3421440-1-tromey@adacore.com> (raw)

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:

    <e3d>   DW_AT_name        : (indirect string, offset: 0xdd4): pck.adb
    ...
    <e45>   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 <http://www.gnu.org/licenses/>.
+
+# 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


             reply	other threads:[~2026-06-09 16:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-09 16:34 Tom Tromey [this message]
2026-06-10 16:01 ` Andrew Burgess
2026-06-10 20:21   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260609163416.3421440-1-tromey@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox