1# Copyright (C) 2018-2023 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 16import sys 17import gdb 18import gdb.types 19 20 21class cons_pp(object): 22 def __init__(self, val): 23 self._val = val 24 25 def to_string(self): 26 if int(self._val) == 0: 27 return "nil" 28 elif int(self._val["type"]) == 0: 29 return "( . )" 30 else: 31 return "%d" % self._val["atom"]["ival"] 32 33 def children(self): 34 if int(self._val) == 0: 35 return [] 36 elif int(self._val["type"]) == 0: 37 return [("atom", self._val["atom"])] 38 else: 39 return [ 40 ("car", self._val["slots"][0]), 41 ("cdr", self._val["slots"][1]), 42 ] 43 44 45def cons_pp_lookup(val): 46 if str(val.type) == "struct cons *": 47 return cons_pp(val) 48 else: 49 return None 50 51 52del gdb.pretty_printers[1:] 53gdb.pretty_printers.append(cons_pp_lookup) 54