Home | History | Annotate | Line # | Download | only in gdb.base
      1 # Copyright 2007-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 # This is a test for the gcore script (not the gcore command from
     17 # inside GDB).  It also tests the gcore script being run without its
     18 # accessible terminal.
     19 
     20 standard_testfile
     21 require {!is_remote host}
     22 require {!is_remote target}
     23 require has_gcore_script
     24 require can_spawn_for_attach
     25 
     26 set corefile [standard_output_file ${testfile}.core]
     27 
     28 if {[build_executable "failed to build" $testfile ${srcfile}] == -1 } {
     29      return -1
     30 }
     31 
     32 # Cleanup.
     33 
     34 proc core_clean {} {
     35     global corefile
     36 
     37     foreach file [glob -nocomplain [join [list $corefile *] ""]] {
     38 	verbose "Delete file $file" 1
     39 	remote_file target delete $file
     40     }
     41 }
     42 core_clean
     43 
     44 # Generate the core file.
     45 proc test_body { detached } {
     46     global binfile
     47     global GCORE
     48     global corefile
     49     global GDB_DATA_DIRECTORY
     50 
     51     # We can't use gdb_test_multiple here because GDB is not started.
     52     set res [remote_spawn target "$binfile $detached $GCORE $GDB_DATA_DIRECTORY $corefile"]
     53     if { ![gdb_assert { ![expr {$res < 0 || $res == ""}] } \
     54 	"spawned gcore"] } {
     55             return
     56 	}
     57 
     58     set saw_corefile_created false
     59     set testname "Spawned gcore finished"
     60     remote_expect target 20 {
     61 	timeout {
     62 	    fail "$testname (timeout)"
     63 	    remote_exec target "kill -9 -[exp_pid -i $res]"
     64 	    return
     65 	}
     66 	-re "Saved corefile \[^\r\n\]+\r\n" {
     67 	    set saw_corefile_created true
     68 	    exp_continue
     69 	}
     70 	eof {
     71 	    gdb_assert { $saw_corefile_created } $testname
     72 	}
     73     }
     74 
     75     gdb_assert {1 == [llength [glob -nocomplain [join [list $corefile *] ""]]]}\
     76 	"Core file generated by gcore"
     77     core_clean
     78 }
     79 
     80 foreach_with_prefix detached { detached standard } {
     81     test_body $detached
     82 }
     83