Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Sort symtabs using their display filename
@ 2026-06-09 16:34 Tom Tromey
  2026-06-10 16:01 ` Andrew Burgess
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2026-06-09 16:34 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Sort symtabs using their display filename
  2026-06-09 16:34 [PATCH] Sort symtabs using their display filename Tom Tromey
@ 2026-06-10 16:01 ` Andrew Burgess
  2026-06-10 20:21   ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Burgess @ 2026-06-10 16:01 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches; +Cc: Tom Tromey

Tom Tromey <tromey@adacore.com> writes:

> 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.

I think this sounds like the right thing to do.  Just a couple of minor
nits...

>
> 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.

Copy and paste comment?  This doesn't seem to describe this test.

> +
> +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"
>

For completeness, would it be worth adding a third test here using "set
filename-display absolute"?

With these two issues fixed:

Approved-By: Andrew Burgess <aburgess@redhat.com>

Thanks,
Andrew

> base-commit: 1eed06ae51d73a195b78ce0903ada9c9c2c14cfb
> -- 
> 2.54.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Sort symtabs using their display filename
  2026-06-10 16:01 ` Andrew Burgess
@ 2026-06-10 20:21   ` Tom Tromey
  0 siblings, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2026-06-10 20:21 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: Tom Tromey, gdb-patches

>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:

Andrew> Copy and paste comment?  This doesn't seem to describe this test.

Yeah.

Andrew> For completeness, would it be worth adding a third test here using "set
Andrew> filename-display absolute"?

Makes sense, I added this.

Andrew> With these two issues fixed:

Andrew> Approved-By: Andrew Burgess <aburgess@redhat.com>

Thanks.

Tom

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-06-10 20:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-09 16:34 [PATCH] Sort symtabs using their display filename Tom Tromey
2026-06-10 16:01 ` Andrew Burgess
2026-06-10 20:21   ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox