Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-recurse-unwind.py
CommitLineData
88b9d363 1# Copyright (C) 2016-2022 Free Software Foundation, Inc.
bb1fe4ac
KB
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# This unwinder never does any unwinding. It'll (pretend to) "sniff"
17# the frame and ultimately return None, indicating that actual unwinding
18# should be performed by some other unwinder.
13123da8 19#
bb1fe4ac
KB
20# But, prior to returning None, it will attempt to obtain the value
21# associated with a symbol via a call to gdb.parse_and_eval(). In
22# the course of doing this evaluation, GDB will potentially access
23# some frames, leading to the possibility of a recursive invocation of
24# this unwinder. If that should happen, code contained herein detects
25# that and prints a message which will cause some of the associated
26# tests to FAIL.
27
28import gdb
29from gdb.unwinder import Unwinder
30
13123da8 31
bb1fe4ac
KB
32class TestUnwinder(Unwinder):
33
34 count = 0
35
36 @classmethod
13123da8 37 def reset_count(cls):
bb1fe4ac
KB
38 cls.count = 0
39
40 @classmethod
13123da8 41 def inc_count(cls):
bb1fe4ac
KB
42 cls.count += 1
43
13123da8 44 test = "check_undefined_symbol"
1a2f3d7f
KB
45
46 @classmethod
13123da8
SM
47 def set_test(cls, test):
48 cls.test = test
1a2f3d7f 49
bb1fe4ac
KB
50 def __init__(self):
51 Unwinder.__init__(self, "test unwinder")
52 self.recurse_level = 0
53
54 def __call__(self, pending_frame):
55
bb1fe4ac
KB
56 if self.recurse_level > 0:
57 gdb.write("TestUnwinder: Recursion detected - returning early.\n")
58 return None
59
60 self.recurse_level += 1
61 TestUnwinder.inc_count()
62
13123da8 63 if TestUnwinder.test == "check_user_reg_pc":
1a2f3d7f 64
13123da8
SM
65 pc = pending_frame.read_register("pc")
66 pc_as_int = int(pc.cast(gdb.lookup_type("int")))
1a2f3d7f
KB
67 # gdb.write("In unwinder: pc=%x\n" % pc_as_int)
68
13123da8 69 elif TestUnwinder.test == "check_pae_pc":
1a2f3d7f 70
13123da8
SM
71 pc = gdb.parse_and_eval("$pc")
72 pc_as_int = int(pc.cast(gdb.lookup_type("int")))
1a2f3d7f
KB
73 # gdb.write("In unwinder: pc=%x\n" % pc_as_int)
74
13123da8 75 elif TestUnwinder.test == "check_undefined_symbol":
1a2f3d7f
KB
76
77 try:
78 val = gdb.parse_and_eval("undefined_symbol")
bb1fe4ac 79
1a2f3d7f
KB
80 except Exception as arg:
81 pass
bb1fe4ac
KB
82
83 self.recurse_level -= 1
84
85 return None
86
13123da8 87
bb1fe4ac
KB
88gdb.unwinder.register_unwinder(None, TestUnwinder(), True)
89gdb.write("Python script imported\n")
This page took 0.701709 seconds and 4 git commands to generate.