]> Git Repo - binutils.git/blob - gdb/testsuite/gdb.python/py-unwind-user-regs.exp
Automatic date update in version.in
[binutils.git] / gdb / testsuite / gdb.python / py-unwind-user-regs.exp
1 # Copyright (C) 2021-2022 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 # 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
39 load_lib gdb-python.exp
40
41 standard_testfile
42
43 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
44     return -1
45 }
46
47 # Skip all tests if Python scripting is not enabled.
48 if { [skip_python_tests] } { continue }
49
50 if {![runto_main]} {
51     return 0
52 }
53
54 set pyfile [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py]
55
56 gdb_breakpoint [gdb_get_line_number "Break here"]
57 gdb_continue_to_breakpoint "stop at test breakpoint"
58
59 # Load the script containing the unwinders.  There are actually two
60 # unwinders defined here that will catch the same function, so we
61 # immediately disable one of the unwinders.
62 gdb_test_no_output "source ${pyfile}"\
63     "import python scripts"
64 gdb_test "disable unwinder global \"break unwinding using strings\"" \
65     "1 unwinder disabled" "disable the unwinder that uses strings"
66
67 # At this point we are using the unwinder that passes a
68 # gdb.RegisterDescriptor to add_saved_register.
69 gdb_test_sequence "bt"  "Backtrace corrupted by descriptor based unwinder" {
70     "\\r\\n#0 \[^\r\n\]* foo \\(\\) at "
71     "\\r\\n#1 \[^\r\n\]* bar \\(\\) at "
72     "Backtrace stopped: previous frame inner to this frame \\(corrupt stack\\?\\)"
73 }
74
75 # Disable the unwinder that calls add_saved_register with a
76 # gdb.RegisterDescriptor, and enable the unwinder that calls
77 # add_saved_register with a string (containing the register name).
78 gdb_test "disable unwinder global \"break unwinding using descriptors\"" \
79     "1 unwinder disabled" "disable the unwinder that uses descriptors"
80 gdb_test "enable unwinder global \"break unwinding using strings\"" \
81     "1 unwinder enabled" "enable the unwinder that uses strings"
82 gdb_test_sequence "bt"  "Backtrace corrupted by string based unwinder" {
83     "\\r\\n#0 \[^\r\n\]* foo \\(\\) at "
84     "\\r\\n#1 \[^\r\n\]* bar \\(\\) at "
85     "Backtrace stopped: previous frame inner to this frame \\(corrupt stack\\?\\)"
86 }
87
88 # Just for completeness, disable the string unwinder again (neither of
89 # our special unwinders are now enabled), and check the backtrace.  We
90 # now get the complete stack back to main.
91 gdb_test "disable unwinder global \"break unwinding using strings\"" \
92     "1 unwinder disabled" "disable the unwinder that uses strings again"
93 gdb_test_sequence "bt"  "Backtrace not corrupted when using no unwinder" {
94     "\\r\\n#0 \[^\r\n\]* foo \\(\\) at "
95     "\\r\\n#1 \[^\r\n\]* bar \\(\\) at "
96     "\\r\\n#2 \[^\r\n\]* main \\(\\) at "
97 }
This page took 0.02844 seconds and 4 git commands to generate.