Skip to content

Instantly share code, notes, and snippets.

@jvns
Created May 25, 2023 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jvns/7f1eff7cdda26412cc8df280a1641fd4 to your computer and use it in GitHub Desktop.
Save jvns/7f1eff7cdda26412cc8df280a1641fd4 to your computer and use it in GitHub Desktop.
import lldb
import os
import json
def format_variable(variable):
data = variable.GetData()
as_bytes = list(data.uint8)
return {
"name": variable.name,
"address": variable.address_of.value,
"size": variable.size,
"data": as_bytes,
"type": variable.GetType().GetName(),
"value": variable.value,
}
def format_variables(frame):
variables = frame.GetVariables(True, True, True, True)
return [format_variable(v) for v in variables]
def run(filename):
debugger = lldb.SBDebugger.Create()
debugger.SetAsync(False)
target = debugger.CreateTarget(filename)
target.BreakpointCreateByName("main")
process = target.LaunchSimple(None, None, os.getcwd())
while process.GetState() == lldb.eStateStopped:
thread = process.GetSelectedThread()
frame = thread.GetSelectedFrame()
line_number = frame.GetLineEntry().GetLine()
if line_number > 100000:
break
yield {
"line_number": line_number,
"variables": format_variables(frame),
}
thread.StepOver()
process.Kill()
def main():
filename = os.environ["BINARY_NAME"]
lines = list(run(filename))
print(json.dumps(lines))
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment