forked from evmar/retrowin32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lldb-trace.py
53 lines (42 loc) · 1.66 KB
/
lldb-trace.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
"""
export PYTHONPATH=`lldb -P`
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/Current/bin/python3 -u trace.py | tee log
"""
import lldb
import os
RETROWIN32 = './target/x86_64-apple-darwin/debug/retrowin32'
TARGET_TRIPLE = 'x86_64-apple-macosx13.0.0'
EXE = 'exe/demo/effect.exe'
trace_points = []
with open('tp') as f:
for line in f:
if line.startswith('@'):
trace_points.append(int(line.strip()[1:], 16))
debugger = lldb.SBDebugger.Create()
debugger.SetAsync(False)
target = debugger.CreateTargetWithFileAndTargetTriple(RETROWIN32, TARGET_TRIPLE)
bp = target.BreakpointCreateByName("jump_to_entry_point", target.GetExecutable().GetFilename())
err = lldb.SBError()
# Note target.LaunchSimple swallows stdout etc :(
process = target.Launch(
lldb.SBListener(), ['--win32-trace', '*', EXE], None,
'/dev/stdin', '/dev/stdout', '/dev/stderr', os.getcwd(),
0, False, err
)
while True:
bp.ClearAllBreakpointSites()
thread = process.GetThreadAtIndex(0)
frame = thread.GetFrameAtIndex(0)
vals = ' '.join(
'%s:%x' % ('e' + reg, frame.reg['r' + reg].unsigned & 0xFFFF_FFFF)
for reg in ['ax', 'bx', 'cx', 'dx', 'si', 'di', 'sp']
)
print('@%x' % frame.reg['rip'].unsigned)
print(' ' + vals)
# Note: FPU state in lldb is 80-bit floats, and for the life of me I could not
# get it to print those as anything other than arrays of bytes argh.
#print(' fpu: ' + ' '.join(('%f' % frame.reg['stmm%d' % d].data.double[0]) for d in range(0,8)))
next = trace_points.pop(0)
bp = target.BreakpointCreateByAddress(next)
process.Continue()