[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
Fri May 6 17:05:44 PDT 2022


jingham created this revision.
jingham added reviewers: JDevlieghere, kastiglione.
Herald added a project: All.
jingham requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

In a situation where you have a lot of breakpoints set, some enabled and some not, and you want to continue till you hit one breakpoint but don't want to hit any of the others in the course of doing that, you have to hand disable the other breakpoints, then continue, then re-enable the ones that were enabled when you started (but not the others).  That's tedious but easily done with scripting.  I wrote up this little example for somebody and it seems generally useful.


Repository:
  rG LLVM Github Monorepo

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,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__))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125148.427795.patch
Type: text/x-patch
Size: 2646 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220507/b4e98e92/attachment-0001.bin>


More information about the lldb-commits mailing list