Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions trace.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/python
#!/usr/bin/env python3

import lldb
import commands
import optparse
import shlex
import threading
Expand Down Expand Up @@ -98,16 +97,16 @@ def instrument_calls_syscalls_and_jmps(self):
start_address = symbol.GetStartAddress().GetLoadAddress(self.target)
end_address = symbol.GetEndAddress().GetLoadAddress(self.target)
instruction_list = symbol.GetInstructions(self.target)
previous_breakpoint_address = 0L
previous_breakpoint_address = 0
for i in instruction_list:
address = i.GetAddress().GetLoadAddress(self.target)
#print >>self.result, '0x%x' % address
#print >>self.result, '{}, {}, {}'.format(i.GetMnemonic(self.target), i.GetOperands(self.target), i.GetComment(self.target))
if address in self.call_breakpoints or address in self.jmp_breakpoints:
continue
if previous_breakpoint_address != 0L:
if previous_breakpoint_address != 0:
self.subsequent_instruction[previous_breakpoint_address] = address
previous_breakpoint_address = 0L
previous_breakpoint_address = 0
mnemonic = i.GetMnemonic(self.target)
if mnemonic != None and mnemonic.startswith('call'):
log_v('Putting call breakpoint at 0x%lx' % address)
Expand All @@ -119,7 +118,7 @@ def instrument_calls_syscalls_and_jmps(self):
try:
jmp_destination = int(i.GetOperands(self.target), 16)
except:
jmp_destination = 0L;
jmp_destination = 0;

if jmp_destination < start_address or jmp_destination >= end_address:
log_v('Putting jmp breakpoint at 0x%lx' % address)
Expand All @@ -133,18 +132,18 @@ def instrument_calls_syscalls_and_jmps(self):
self.syscall_breakpoints[address] = breakpoint

def clear_calls_instrumentation(self):
for breakpoint in self.call_breakpoints.itervalues():
for breakpoint in self.call_breakpoints.values():
self.target.BreakpointDelete(breakpoint.GetID())
self.call_breakpoints = {}
self.subsequent_instruction = {}

def clear_syscall_instrumentation(self):
for breakpoint in self.syscall_breakpoints.itervalues():
for breakpoint in self.syscall_breakpoints.values():
self.target.BreakpointDelete(breakpoint.GetID())
self.syscall_breakpoints = {}

def clear_jmps_instrumentation(self):
for breakpoint in self.jmp_breakpoints.itervalues():
for breakpoint in self.jmp_breakpoints.values():
self.target.BreakpointDelete(breakpoint.GetID())
self.jmp_breakpoints = {}

Expand Down Expand Up @@ -224,8 +223,6 @@ def get_prog_name(self):
return "trace"

def exit(self, status=0, msg=None):
if msg != None:
print >>self.result, msg
self.exited = True

def parse_options(command, result):
Expand Down Expand Up @@ -416,7 +413,7 @@ def trace(debugger, command, result, internal_dict):
depth = depth + 1
log_v('Entered new frame at: 0x%lx' % frame.GetPC())
elif instrumented_frame.is_stopped_on_syscall(frame):
rax = -1L;
rax = -1;
register_sets = frame.GetRegisters()
for register_set in register_sets:
if register_set.GetName() == "General Purpose Registers":
Expand Down Expand Up @@ -460,4 +457,4 @@ def trace(debugger, command, result, internal_dict):
# And the initialization code to add your commands
def __lldb_init_module(debugger, internal_dict):
debugger.HandleCommand('command script add -f trace.trace trace')
print 'The "trace" python command has been installed and is ready for use.'
print('The "trace" python command has been installed and is ready for use.')