1# Copyright (C) 2018-2020 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# Following is for Python 3 compatibility... 21if sys.version_info[0] > 2: 22 long = int 23 24 25class 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 [ 42 ('atom', self._val['atom']) 43 ] 44 else: 45 return [ 46 ('car' , self._val["slots"][0]), 47 ('cdr' , self._val["slots"][1]), 48 ] 49 50def cons_pp_lookup(val): 51 if str(val.type) == 'struct cons *': 52 return cons_pp(val) 53 else: 54 return None 55 56del gdb.pretty_printers[1:] 57gdb.pretty_printers.append(cons_pp_lookup) 58