Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-unwind-user-regs.exp
CommitLineData
88b9d363 1# Copyright (C) 2021-2022 Free Software Foundation, Inc.
61e2dde2
AB
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# Setup an unwinder that uses gdb.UnwindInfo.add_saved_register with
17# the register's 'pc' and 'sp'. On some (all?) targets, these
18# registers are implemented as user-registers, and so can't normally
19# be written to directly.
20#
21# The Python unwinder now includes code similar to how the expression
22# evaluator would handle something like 'set $pc=0x1234', we fetch the
23# value of '$pc', and then use the value's location to tell us which
24# register to write to.
25#
26# The unwinder defined here deliberately breaks the unwind by setting
27# the unwound $pc and $sp to be equal to the current frame's $pc and
28# $sp. GDB will spot this as a loop in the backtrace and terminate
29# the unwind.
30#
31# However, by the time the unwind terminates we have already shown
32# that it is possible to call add_saved_register with a user-register,
33# so the test is considered passed.
34#
35# For completeness this test checks two cases, calling
36# add_saved_register with a gdb.RegisterDescriptor and calling
37# add_saved_register with a string containing the register name.
38
39load_lib gdb-python.exp
40
41standard_testfile
42
43if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
44 return -1
45}
46
47# Skip all tests if Python scripting is not enabled.
48if { [skip_python_tests] } { continue }
49
50if ![runto_main] then {
51 fail "can't run to main"
52 return 0
53}
54
55set pyfile [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py]
56
57gdb_breakpoint [gdb_get_line_number "Break here"]
58gdb_continue_to_breakpoint "stop at test breakpoint"
59
60# Load the script containing the unwinders. There are actually two
61# unwinders defined here that will catch the same function, so we
62# immediately disable one of the unwinders.
63gdb_test_no_output "source ${pyfile}"\
64 "import python scripts"
65gdb_test "disable unwinder global \"break unwinding using strings\"" \
66 "1 unwinder disabled" "disable the unwinder that uses strings"
67
68# At this point we are using the unwinder that passes a
69# gdb.RegisterDescriptor to add_saved_register.
70gdb_test_sequence "bt" "Backtrace corrupted by descriptor based unwinder" {
71 "\\r\\n#0 \[^\r\n\]* foo \\(\\) at "
72 "\\r\\n#1 \[^\r\n\]* bar \\(\\) at "
73 "Backtrace stopped: previous frame inner to this frame \\(corrupt stack\\?\\)"
74}
75
76# Disable the unwinder that calls add_saved_register with a
77# gdb.RegisterDescriptor, and enable the unwinder that calls
78# add_saved_register with a string (containing the register name).
79gdb_test "disable unwinder global \"break unwinding using descriptors\"" \
80 "1 unwinder disabled" "disable the unwinder that uses descriptors"
81gdb_test "enable unwinder global \"break unwinding using strings\"" \
82 "1 unwinder enabled" "enable the unwinder that uses strings"
83gdb_test_sequence "bt" "Backtrace corrupted by string based unwinder" {
84 "\\r\\n#0 \[^\r\n\]* foo \\(\\) at "
85 "\\r\\n#1 \[^\r\n\]* bar \\(\\) at "
86 "Backtrace stopped: previous frame inner to this frame \\(corrupt stack\\?\\)"
87}
88
89# Just for completeness, disable the string unwinder again (neither of
90# our special unwinders are now enabled), and check the backtrace. We
91# now get the complete stack back to main.
92gdb_test "disable unwinder global \"break unwinding using strings\"" \
93 "1 unwinder disabled" "disable the unwinder that uses strings again"
94gdb_test_sequence "bt" "Backtrace not corrupted when using no unwinder" {
95 "\\r\\n#0 \[^\r\n\]* foo \\(\\) at "
96 "\\r\\n#1 \[^\r\n\]* bar \\(\\) at "
97 "\\r\\n#2 \[^\r\n\]* main \\(\\) at "
98}
This page took 0.03654 seconds and 4 git commands to generate.