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,78 @@ +import lldb + +class ContinueToBreakpoint: + def __init__(self, debugger, unused): + return + + def __call__(self, debugger, command, exe_ctx, result): + + target = exe_ctx.target + process = exe_ctx.process + + if not target.IsValid(): + result.SetError("Need a valid target") + return + if not process.IsValid(): + result.SetError("Need a valid process") + return + + bkpt_strs = command.split() + bkpt_ids = [] + for str in bkpt_strs: + is_a_number = True + bkpt_id = lldb.LLDB_INVALID_BREAK_ID + try: + bkpt_id = int(str) + except: + is_a_number = False + + if is_a_number: + bkpt = target.FindBreakpointByID(bkpt_id) + if not bkpt.IsValid(): + result.SetError("Input is a number, but not a known breakpoint ID: {0}".format(str)) + return + + bkpt_ids.append(bkpt_id) + else: + bkpts_for_name = lldb.SBBreakpointList(target) + if target.FindBreakpointsByName(str, bkpts_for_name): + for idx in range(0, bkpts_for_name.GetSize()): + bkpt_ids.append(bkpts_for_name.GetBreakpointAtIndex(idx).GetID()) + else: + result.SetError("Input must be breakpoint id's or breakpoint names: {0}".format(str)) + return + + if len(bkpt_ids) == 0: + result.SetError("No breakpoint to run to") + result.SetStatus(lldb.eReturnStatusFailed) + return + + disabled_bkpts = [] + for idx in range(0, target.num_breakpoints): + bkpt = target.GetBreakpointAtIndex(idx) + bkpt_id = bkpt.GetID() + if bkpt_id not in bkpt_ids: + if bkpt.enabled: + disabled_bkpts.append(bkpt) + bkpt.enabled = False + old_async = debugger.GetAsync() + debugger.SetAsync(False) + process.Continue() + strm = lldb.SBStream() + if process.state == lldb.eStateExited: + result.PutCString("process exited with state: {0}".format(process.exit_state)) + else: + thread = 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__))