Skip to content

Commit

Permalink
Deal with spurious breakpoints due to recursion.
Browse files Browse the repository at this point in the history
  • Loading branch information
gm281 committed Aug 6, 2014
1 parent 69e3ef8 commit 2604471
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
14 changes: 14 additions & 0 deletions SimpleTraceTarget/SimpleTraceTarget/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,23 @@ void a(void)
printf("Cycle\n");
}

void c(int i);
void d(int i)
{
c(i-1);
}

void c(int i)
{
if (i > 0) {
d(i);
}
}

void breakpoint(void)
{
a();
c(1);
}

int main(int argc, const char * argv[])
Expand Down
20 changes: 14 additions & 6 deletions trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def __init__(self, target, thread, frame, result):
def update_frame(self, frame):
self.frame = frame

def is_frame_valid(self):
return self.frame.IsValid()

def instrument_calls_syscalls_and_jmps(self):
# TODO: symbols vs functions
print >>self.result, self.frame.GetFunction()
Expand Down Expand Up @@ -136,31 +139,31 @@ def clear_return_breakpoint(self):
self.return_breakpoint == None

def is_stopped_on_call(self, frame):
if frame.GetFrameID() != self.frame.GetFrameID():
if not self.frame.IsValid() or frame.GetFrameID() != self.frame.GetFrameID():
print >>self.result, "A Frames don't match, ours: {}, valid: {}, submitted: {}".format(self.frame.GetFrameID(), self.frame.IsValid(), frame.GetFrameID())
return False

stop_address = frame.GetPC()
return stop_address in self.call_breakpoints

def is_stopped_on_syscall(self, frame):
if frame.GetFrameID() != self.frame.GetFrameID():
if not self.frame.IsValid() or frame.GetFrameID() != self.frame.GetFrameID():
print >>self.result, "D Frames don't match, ours: {}, valid: {}, submitted: {}".format(self.frame.GetFrameID(), self.frame.IsValid(), frame.GetFrameID())
return False

stop_address = frame.GetPC()
return stop_address in self.syscall_breakpoints

def is_stopped_on_jmp(self, frame, validate_saved_frame):
if validate_saved_frame and frame.GetFrameID() != self.frame.GetFrameID():
if validate_saved_frame and (not self.frame.IsValid() or frame.GetFrameID() != self.frame.GetFrameID()):
print >>self.result, "B Frames don't match, ours: {}, valid: {}, submitted: {}".format(self.frame.GetFrameID(), self.frame.IsValid(), frame.GetFrameID())
return False

stop_address = frame.GetPC()
return stop_address in self.jmp_breakpoints

def is_stopped_on_return(self, frame):
if frame.GetFrameID() != self.frame.GetFrameID():
if not self.frame.IsValid() or frame.GetFrameID() != self.frame.GetFrameID():
print >>self.result, "C Frames don't match, ours: {}, valid: {}, submitted: {}".format(self.frame.GetFrameID(), self.frame.IsValid(), frame.GetFrameID())
return False

Expand Down Expand Up @@ -362,8 +365,13 @@ def trace(debugger, command, result, internal_dict):
instrumented_frame.update_frame(frame)
instrumented_frame.instrument_calls_syscalls_and_jmps()
else:
print >>result, "Failed to detect return, call or jmp. Error exit"
break
top_instrumented_frame = instrumented_frame
if top_instrumented_frame == None:
top_instrumented_frame = parent_instrumented_frame
if top_instrumented_frame == None or not top_instrumented_frame.is_frame_valid():
print >>result, "Failed to detect return, call or jmp. Error exit"
break
print >>result, "Unexpected breakpoint but top frame still valid, continuing"

# TODO: clear instrumented frames, on errors there
# may be breakpoints left, what needs to be worked out
Expand Down

0 comments on commit 2604471

Please sign in to comment.