Created
February 1, 2016 22:09
-
-
Save charles-l/b4745f6ae14ddea4148d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import gdb | |
class ListPrintCommand(gdb.Command): | |
"""print atoms""" | |
def __init__(self): | |
super(ListPrintCommand, self).__init__("print-atom", | |
gdb.COMMAND_DATA, gdb.COMPLETE_SYMBOL) | |
def print_atom(self, a): | |
if a == 0x0: | |
print("null", end='') | |
return | |
if str(a['type']) == 'ATOM': | |
print('%s' % (a['sym'].string()), end='') | |
elif str(a['type']) == 'CONS': | |
print("(", end='') | |
self.print_atom(a['car']) | |
print(" ", end='') | |
self.print_atom(a['cdr']) | |
print(")", end='') | |
elif str(a['type']) == 'LAMBDA': | |
print("<lambda>", end='') | |
elif str(a['type']) == 'FFI': | |
print("<cffi>", end='') | |
def invoke(self, argument, from_tty): | |
args = gdb.string_to_argv(argument) | |
if len(args) == 0: | |
print("Argument required (list to iterate)") | |
return | |
expr = args[0] | |
a = gdb.parse_and_eval(expr) | |
self.print_atom(a) | |
print("") | |
ListPrintCommand() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment