Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-mi-var-info-path-expression.py
1 # Copyright (C) 2018-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 import sys
17 import gdb
18 import gdb.types
19
20 # Following is for Python 3 compatibility...
21 if sys.version_info[0] > 2:
22 long = int
23
24
25 class cons_pp(object):
26 def __init__(self, val):
27 self._val = val
28
29 def to_string(self):
30 if long(self._val) == 0:
31 return "nil"
32 elif long(self._val["type"]) == 0:
33 return "( . )"
34 else:
35 return "%d" % self._val["atom"]["ival"]
36
37 def children(self):
38 if long(self._val) == 0:
39 return []
40 elif long(self._val["type"]) == 0:
41 return [("atom", self._val["atom"])]
42 else:
43 return [
44 ("car", self._val["slots"][0]),
45 ("cdr", self._val["slots"][1]),
46 ]
47
48
49 def cons_pp_lookup(val):
50 if str(val.type) == "struct cons *":
51 return cons_pp(val)
52 else:
53 return None
54
55
56 del gdb.pretty_printers[1:]
57 gdb.pretty_printers.append(cons_pp_lookup)
This page took 0.043773 seconds and 4 git commands to generate.