diff --git a/lldb/examples/python/cont_to_bkpt.py b/lldb/examples/python/cont_to_bkpt.py new file mode 100644 --- /dev/null +++ b/lldb/examples/python/cont_to_bkpt.py @@ -0,0 +1,63 @@ +import lldb + +class ContinueToBreakpoint: + def __init__(self, debugger, unused): + self.dbg = debugger + self.interp = debugger.GetCommandInterpreter() + + def __call__(self, debugger, command, exe_ctx, result): + bkpt_strs = command.split() + bkpt_ids = [] + for str in bkpt_strs: + try: + int_val = int(str) + except: + result.SetError("Input must be breakpoint id's: {0}".format(str)) + result.SetStatus(lldb.eReturnStatusFailed) + return + + bkpt_ids.append(int(str)) + + if len(bkpt_ids) == 0: + result.SetError("No breakpoint to run to") + result.SetStatus(lldb.eReturnStatusFailed) + return + target = exe_ctx.target + if not exe_ctx.target.IsValid(): + result.SetError("Need a valid target") + result.SetStatus(lldb.eReturnStatusFailed) + return + if not exe_ctx.process.IsValid(): + result.SetError("Need a valid process") + result.SetStatus(lldb.eReturnStatusFailed) + return + + disabled_bkpts = [] + for idx in range(0, exe_ctx.target.num_breakpoints): + bkpt = target.GetBreakpointAtIndex(idx) + bkpt_id = bkpt.GetID() + if not bkpt_id in bkpt_ids: + if bkpt.enabled: + disabled_bkpts.append(bkpt) + bkpt.enabled = False + old_async = debugger.GetAsync() + debugger.SetAsync(False) + exe_ctx.process.Continue() + strm = lldb.SBStream() + if exe_ctx.process.state == lldb.eStateExited: + result.PutCString("process exited with state: {0}".format(exe_ctx.process.exit_state)) + else: + thread = exe_ctx.process.GetSelectedThread() + thread.GetStatus(strm) + result.PutCString(strm.GetData()) + + result.SetStatus(lldb.eReturnStatusSuccessFinishResult) + for bkpt in disabled_bkpts: + bkpt.enabled = True; + debugger.SetAsync(old_async) + + def get_short_help(self): + return "takes a list of breakpoint ID's and continues the process until one of the breakpoint IDs passed in is hit" + +def __lldb_init_module(debugger, unused): + debugger.HandleCommand("command script add -c {0}.ContinueToBreakpoint continue_to_bkpts".format(__name__))