| 1 | # Copyright 2014-2019 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 | standard_testfile .c |
| 17 | set executable ${testfile} |
| 18 | |
| 19 | # The plain remote target can't do multiple inferiors. |
| 20 | if [use_gdb_stub] { |
| 21 | return |
| 22 | } |
| 23 | |
| 24 | if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug}]} { |
| 25 | return -1 |
| 26 | } |
| 27 | |
| 28 | # Inferior 1 stops at f1. |
| 29 | |
| 30 | if ![runto f1] then { |
| 31 | fail "can't run to f1" |
| 32 | return 0 |
| 33 | } |
| 34 | |
| 35 | gdb_test "add-inferior -exec ${binfile}" \ |
| 36 | "Added inferior 2.*" \ |
| 37 | "add inferior 2 with -exec ${executable}" |
| 38 | gdb_test "inferior 2" "witching to inferior 2 .*" "switch to inferior 2" |
| 39 | |
| 40 | delete_breakpoints |
| 41 | |
| 42 | # Inferior 2 stops at f2. |
| 43 | |
| 44 | if ![runto f2] then { |
| 45 | fail "can't run to f2" |
| 46 | return 0 |
| 47 | } |
| 48 | |
| 49 | gdb_breakpoint commonfun |
| 50 | |
| 51 | # Check the stack bactrace in inferior INF. PREFIX is the test |
| 52 | # message prefix. |
| 53 | |
| 54 | proc check_bt { inf prefix } { |
| 55 | with_test_prefix "$prefix" { |
| 56 | gdb_test "bt 1" "#0 f$inf .*" "bt in inferior $inf" |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | # Do inferior call commonfun () in inferior 2 and inferior 1, but |
| 61 | # finish it in inferior INF1 first and then inferior INF2. Check |
| 62 | # the stack backtrace in each inferior is still correct after |
| 63 | # inferior call. |
| 64 | |
| 65 | proc test { inf1 inf2 } { |
| 66 | |
| 67 | with_test_prefix "inf $inf1 first" { |
| 68 | gdb_test "inferior 2" "witching to inferior 2 .*" \ |
| 69 | "switch to inferior 2 (1)" |
| 70 | check_bt 2 "before infcall" |
| 71 | gdb_test "p commonfun()" "Breakpoint .*The program being debugged stopped while in a function called from GDB.*" "infcall in inferior 2" |
| 72 | |
| 73 | gdb_test "inferior 1" "witching to inferior 1 .*" \ |
| 74 | "switch to inferior 1 (1)" |
| 75 | check_bt 1 "before infcall" |
| 76 | gdb_test "p commonfun()" "Breakpoint .*The program being debugged stopped while in a function called from GDB.*" "infcall in inferior 1" |
| 77 | |
| 78 | gdb_test "maintenance print dummy-frames" ": id={stack=.*}.*: id=.*" \ |
| 79 | "two dummy frames" |
| 80 | |
| 81 | gdb_test "inferior $inf1" "witching to inferior $inf1 .*" \ |
| 82 | "switch to inferior $inf1 (2)" |
| 83 | gdb_test "finish" "Run till exit from #0 commonfun .*" \ |
| 84 | "finish in inferior $inf1" |
| 85 | check_bt $inf1 "after infcall" |
| 86 | |
| 87 | gdb_test "inferior $inf2" "witching to inferior $inf2 .*" \ |
| 88 | "switch to inferior $inf2 (2)" |
| 89 | gdb_test "finish" "Run till exit from #0 commonfun .*" \ |
| 90 | "finish in inferior $inf2" |
| 91 | check_bt $inf2 "after infcall" |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | # Do the test in different orders. |
| 96 | test 1 2 |
| 97 | test 2 1 |