| 1 | # Copyright 2009-2017 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 multi-exec / multi-process features that work for all configurations, |
| 17 | # even ones that cannot run multiple processes simultaneously. |
| 18 | |
| 19 | set testfile "multi-arch" |
| 20 | |
| 21 | # The plain remote target can't do multiple inferiors. |
| 22 | if [target_info exists use_gdb_stub] { |
| 23 | return |
| 24 | } |
| 25 | |
| 26 | # The 64-bit compile may succeed for i386-linux, but gdb won't be able |
| 27 | # to load the file. |
| 28 | if [istarget "i?86-*linux*"] { |
| 29 | return |
| 30 | } |
| 31 | |
| 32 | # Can't use standard_testfile, we want executables with specialized |
| 33 | # names. |
| 34 | set exec1 "ma-hello" |
| 35 | set srcfile1 hello.c |
| 36 | set binfile1 [standard_output_file ${exec1}] |
| 37 | |
| 38 | set exec2 "ma-hangout" |
| 39 | set srcfile2 hangout.c |
| 40 | set binfile2 [standard_output_file ${exec2}] |
| 41 | |
| 42 | # Build two executables, one for each arch. |
| 43 | |
| 44 | if [istarget "s390*-*-*"] { |
| 45 | set march1 "-m64" |
| 46 | set march2 "-m31" |
| 47 | } elseif { [istarget "aarch64*-*-*"] } { |
| 48 | set march1 "" |
| 49 | set march2 "" |
| 50 | } else { |
| 51 | set march1 "-m64" |
| 52 | set march2 "-m32" |
| 53 | } |
| 54 | |
| 55 | if { [prepare_for_testing "failed to prepare" ${exec1} "${srcfile1}" \ |
| 56 | [list debug additional_flags=${march1}]] } { |
| 57 | return -1 |
| 58 | } |
| 59 | |
| 60 | set options [list debug] |
| 61 | |
| 62 | if [istarget "aarch64*-*-*"] { |
| 63 | if {[info exists ARM_CC_FOR_TARGET]} { |
| 64 | lappend options "compiler=${ARM_CC_FOR_TARGET}" |
| 65 | } else { |
| 66 | unsupported "ARM compiler is not known" |
| 67 | return -1 |
| 68 | } |
| 69 | } else { |
| 70 | lappend options "additional_flags=${march2}" |
| 71 | } |
| 72 | |
| 73 | if { [prepare_for_testing "failed to prepare" ${exec2} "${srcfile2}" \ |
| 74 | $options]} { |
| 75 | return -1 |
| 76 | } |
| 77 | |
| 78 | # Start inferior 1 |
| 79 | |
| 80 | clean_restart ${exec1} |
| 81 | if ![runto_main] then { |
| 82 | fail "starting inferior 1" |
| 83 | } |
| 84 | |
| 85 | # Add and start inferior 2 |
| 86 | |
| 87 | gdb_test "add-inferior" "Added inferior 2.*" "add empty inferior 2" |
| 88 | gdb_test "inferior 2" "Switching to inferior 2.*" "switch to inferior 2" |
| 89 | gdb_load ${binfile2} |
| 90 | |
| 91 | if ![runto_main] then { |
| 92 | fail "starting inferior 2" |
| 93 | } |
| 94 | |
| 95 | # Check we do have two inferiors loaded. |
| 96 | |
| 97 | gdb_test "info inferiors" \ |
| 98 | "Executable.*${exec1}.*${exec2}.*" |
| 99 | |
| 100 | # Now select inferior 2, and trigger an event in inferior 1. This |
| 101 | # tries to check that GDB doesn't incorrectly uses the architecture of |
| 102 | # inferior 2 when parsing the expedited registers in a stop reply for |
| 103 | # inferior 1 (when remote debugging). |
| 104 | |
| 105 | gdb_test_no_output "set schedule-multiple on" |
| 106 | |
| 107 | with_test_prefix "inf1 event with inf2 selected" { |
| 108 | gdb_test "inferior 2" "Switching to inferior 2.*thread 2\.1.*main.*${srcfile2}.*" |
| 109 | gdb_test "b hello_loop" "Breakpoint .* at .*${srcfile1}.*" |
| 110 | gdb_test "c" " hello_loop.*" "continue to hello_loop" |
| 111 | } |
| 112 | |
| 113 | delete_breakpoints |
| 114 | |
| 115 | # Same, but the other way around: select inferior 1 and trigger an |
| 116 | # event in inferior 2. |
| 117 | |
| 118 | with_test_prefix "inf2 event with inf1 selected" { |
| 119 | gdb_test "inferior 1" "Switching to inferior 1.*thread 1\.1.*hello_loop.*${srcfile1}.*" |
| 120 | gdb_test "b hangout_loop" "Breakpoint .* at .*${srcfile2}.*" |
| 121 | gdb_test "c" " hangout_loop.*" "continue to hangout_loop" |
| 122 | } |