]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.python/py-recurse-unwind.py
Fix PR20789 - relaxation with negative valued diff relocs
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-recurse-unwind.py
1 # Copyright (C) 2016 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 # 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.
19 #
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
28 import gdb
29 from gdb.unwinder import Unwinder
30
31 class TestUnwinder(Unwinder):
32
33 count = 0
34
35 @classmethod
36 def reset_count (cls):
37 cls.count = 0
38
39 @classmethod
40 def inc_count (cls):
41 cls.count += 1
42
43 def __init__(self):
44 Unwinder.__init__(self, "test unwinder")
45 self.recurse_level = 0
46
47 def __call__(self, pending_frame):
48
49
50 if self.recurse_level > 0:
51 gdb.write("TestUnwinder: Recursion detected - returning early.\n")
52 return None
53
54 self.recurse_level += 1
55 TestUnwinder.inc_count()
56
57 try:
58 val = gdb.parse_and_eval("undefined_symbol")
59
60 except Exception as arg:
61 pass
62
63 self.recurse_level -= 1
64
65 return None
66
67 gdb.unwinder.register_unwinder(None, TestUnwinder(), True)
68 gdb.write("Python script imported\n")