1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2017-2021 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Skip this test if btrace is disabled.
20 if { [skip_btrace_tests] } {
21 untested "skipping btrace tests"
27 if { [gdb_compile_pthreads "$srcdir/$subdir/$srcfile" "$binfile" executable {debug} ] != "" } {
28 untested "failed to prepare"
31 clean_restart $testfile
33 # Skip this test if python is disabled.
35 load_lib gdb-python.exp
36 if { [skip_python_tests] } {
37 untested "skipping python tests"
41 if { ![runto_main] } {
42 untested "failed to run to main"
47 gdb_breakpoint $srcfile:[gdb_get_line_number "bp1" $srcfile]
48 gdb_breakpoint $srcfile:[gdb_get_line_number "bp2" $srcfile]
51 gdb_continue_to_breakpoint "cont to bp.1" ".*bp1.*"
52 gdb_test_no_output "record btrace"
53 gdb_continue_to_breakpoint "cont to bp.2" ".*bp2.*"
55 # acquire the record objects for thread 1 and thread 2
56 gdb_test "thread 1" ".*"
57 gdb_test "record function-call-history" ".*" "fch thread 1"
58 gdb_test_no_output "python rec1 = gdb.current_recording()"
59 gdb_test "thread 2" ".*"
60 gdb_test "record function-call-history" ".*" "fch thread 2"
61 gdb_test_no_output "python rec2 = gdb.current_recording()"
63 # Thread 1 is supposed to call func1 (), thread 2 is supposed to call func2 ().
64 # Check that the function call history for the current thread contains a call
65 # to the right function and does not contain a call to the wrong function.
66 proc check_insn_for_thread { self other } {
67 with_test_prefix "checking thread $self" {
68 gdb_test_no_output "python fch = rec$self.function_call_history"
69 gdb_test_no_output "python f1calls = \{x for x in fch if x.symbol and x.symbol.name == \"func1\"\}"
70 gdb_test_no_output "python f2calls = \{x for x in fch if x.symbol and x.symbol.name == \"func2\"\}"
72 gdb_test "python print(not f${self}calls)" "False"
73 gdb_test "python print(not f${other}calls)" "True"
77 foreach_with_prefix thread { 1 2 } {
78 gdb_test "thread $thread"
79 check_insn_for_thread 1 2
80 check_insn_for_thread 2 1