Home | History | Annotate | Line # | Download | only in gdb.dwarf2
      1 # Copyright 2023-2024 Free Software Foundation, Inc.
      2 
      3 # This program is free software; you can redistribute it and/or modify
      4 # it under the terms of the GNU General Public License as published by
      5 # the Free Software Foundation; either version 3 of the License, or
      6 # (at your option) any later version.
      7 #
      8 # This program is distributed in the hope that it will be useful,
      9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11 # GNU General Public License for more details.
     12 #
     13 # You should have received a copy of the GNU General Public License
     14 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15 
     16 # Test that tilde expansion works for the 'save gdb-index' command.
     17 
     18 # This test relies on using the $HOME directory.  We could make this
     19 # work for remote hosts, but right now, this isn't supported.
     20 require {!is_remote host}
     21 
     22 # Can't save an index with readnow.
     23 require !readnow
     24 
     25 standard_testfile main.c
     26 
     27 # Create a directory to generate an index file into.
     28 set full_dir [standard_output_file "index_files"]
     29 remote_exec host "mkdir -p ${full_dir}"
     30 
     31 # The users home directory.
     32 set home $::env(HOME)
     33 
     34 # Check that FULL_DIR is within the $HOME directory.  If it's not, then
     35 # that's fine, but we can't test tilde expansion in this case.
     36 if { [string compare -length [string length $home] $full_dir $home] != 0 } {
     37     unsupported "test not run within home directory"
     38     return -1
     39 }
     40 
     41 # Convert the $HOME prefix in to ~.
     42 set dir "~[string range $full_dir [string length $home] end]"
     43 
     44 # Build the test executable.
     45 if { [prepare_for_testing "failed to prepare" "${testfile}" ${srcfile}] } {
     46     return -1
     47 }
     48 
     49 # Start GDB and load in the executable.
     50 clean_restart ${binfile}
     51 
     52 # If the executable was built with an index, or lacks the debug
     53 # information required to create an index, then we'll not be able to
     54 # generate an index, so lets not even try.
     55 set has_index false
     56 set can_dump_index false
     57 gdb_test_multiple "maint print objfile $binfile" "check we can generate an index" {
     58     -re "\r\n\\.gdb_index: version ${decimal}(?=\r\n)" {
     59 	set has_index true
     60 	gdb_test_lines "" $gdb_test_name ".*"
     61     }
     62     -re "\r\n\\.debug_names: exists(?=\r\n)" {
     63 	set has_index true
     64 	gdb_test_lines "" $gdb_test_name ".*"
     65     }
     66     -re "\r\n(Cooked index in use:|Psymtabs)(?=\r\n)" {
     67 	set can_dump_index true
     68 	gdb_test_lines "" $gdb_test_name ".*"
     69     }
     70     -re -wrap "" {
     71     }
     72 }
     73 
     74 if { $has_index } {
     75     unsupported "already have an index"
     76     return -1
     77 }
     78 
     79 if { !$can_dump_index } {
     80     unsupported "lacks debug information needed to dump index"
     81     return -1
     82 }
     83 
     84 # Generate an index file.
     85 gdb_test_no_output "save gdb-index $dir" \
     86     "save gdb-index to tilde based directory"
     87 gdb_exit
     88 
     89 # Confirm that the index file exists.
     90 set index_filename "${full_dir}/${gdb_test_file_name}.gdb-index"
     91 gdb_assert { [remote_file host exists $index_filename] } \
     92     "confirm the index file exists"
     93