Created
July 10, 2015 18:33
-
-
Save alejandro-isaza/96ec9b3c5df60a07b216 to your computer and use it in GitHub Desktop.
lldb command to print an array to a file in disk
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/python | |
import lldb | |
import os | |
import re | |
import subprocess | |
import fblldbbase as fb | |
def lldbcommands(): | |
return [ PrintToFile() ] | |
class PrintToFile(fb.FBCommand): | |
def name(self): | |
return 'pfile' | |
def description(self): | |
return 'Print an array to a file.' | |
def args(self): | |
return [ fb.FBCommandArgument(arg='pointer', type='void *', help='The pointer to the first element in the array.') ] | |
def options(self): | |
return [ | |
fb.FBCommandArgument(short='-t', long='--type', arg='type', type='string', default='int', help='The type of values contained in the array'), | |
fb.FBCommandArgument(short='-c', long='--size', arg='size', type='int', default=100, help='The number of elements to print'), | |
fb.FBCommandArgument(short='-f', long='--file', arg='file', type='string', default='/tmp/lldb_out.txt', help='The file to write the results to') | |
] | |
def run(self, args, options): | |
res = lldb.SBCommandReturnObject() | |
interpreter = lldb.debugger.GetCommandInterpreter() | |
command = 'memory read --force -t %s -c %s %s' % (options.type, options.size, args[0]) | |
interpreter.HandleCommand(command, res) | |
if not res.Succeeded(): | |
return | |
output = res.GetOutput() | |
print 'Printing to \'%s\'' % options.file | |
f = open(options.file, "w") | |
for line in output.splitlines(): | |
match = re.search('.*\s=\s(.*)', line) | |
if match: | |
f.write(match.group(1) + '\n') | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Depends on https://github.com/facebook/chisel. To install save somewhere (eg.
'/Users/you/.lldb/
) and addscript fblldb.loadCommandsInDirectory('/Users/you/.lldb')
to~/.lldbinit