[binutils-gdb] Sort symtabs using their display filename
Tom Tromey via Gdb-cvs <[email protected]> Wed, 10 Jun 2026 20:27:24 +0000 (GMT)
| Newsgroups | gmane.comp.gdb.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a1c5e3df26f8d43954b9482e5f8e6d4b9b0fba3f commit a1c5e3df26f8d43954b9482e5f8e6d4b9b0fba3f Author: Tom Tromey <[email protected]> Date: Tue Jun 9 06:51:02 2026 -0600 Sort symtabs using their display filename 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. Approved-By: Andrew Burgess <[email protected]> Diff: --- gdb/symtab.c | 6 +- gdb/testsuite/gdb.ada/info_auto_lang.exp | 18 ++-- gdb/testsuite/gdb.dwarf2/symtab-sorting.exp | 125 ++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+), 10 deletions(-) diff --git a/gdb/symtab.c b/gdb/symtab.c index 9fde2e6e6c9..1aaaf446a87 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..738e9e191e6 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/symtab-sorting.exp @@ -0,0 +1,125 @@ +# 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 that symtabs are sorted by the displayed file name in "info +# types". + +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" + +gdb_test_no_output "set filename-display absolute" + +# Here the order is by the full name. +gdb_test "info types byte" \ + [multi_line \ + "All types matching regular expression \"byte\":" \ + "" \ + "File /tmp/aaaa.c:" \ + " byte1" \ + "" \ + "File /tmp/bbbb.c:" \ + " byte2" \ + "" \ + "File /tmp/cccc.c:" \ + " byte3"] \ + "info types absolute"