[Lldb-commits] [PATCH] D125148: Add an example command that runs to one of a set of breakpoints
Jim Ingham via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Tue May 24 16:39:50 PDT 2022
jingham updated this revision to Diff 431837.
jingham added a comment.
Added support for breakpoint names as well as ID's.
Addressed other review comments.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D125148/new/
https://reviews.llvm.org/D125148
Files:
lldb/examples/python/cont_to_bkpt.py
Index: lldb/examples/python/cont_to_bkpt.py
===================================================================
--- /dev/null
+++ 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__))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125148.431837.patch
Type: text/x-patch
Size: 3132 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220524/58ca91fb/attachment-0001.bin>
More information about the lldb-commits
mailing list