[Lldb-commits] [lldb] f362b05 - Add a "current" token to the ThreadID option to break set/modify.

Jim Ingham via lldb-commits lldb-commits at lists.llvm.org
Fri Aug 6 15:30:12 PDT 2021


Author: Jim Ingham
Date: 2021-08-06T15:29:55-07:00
New Revision: f362b05d0dcd176348f19a63f8b7f4d4c0498bba

URL: https://github.com/llvm/llvm-project/commit/f362b05d0dcd176348f19a63f8b7f4d4c0498bba
DIFF: https://github.com/llvm/llvm-project/commit/f362b05d0dcd176348f19a63f8b7f4d4c0498bba.diff

LOG: Add a "current" token to the ThreadID option to break set/modify.

This provides a convenient way to limit a breakpoint
to the current thread when setting it from the command line w/o
having to figure out what the current thread is.

Differential Revision: https://reviews.llvm.org/D107015

Added: 
    

Modified: 
    lldb/source/Commands/CommandObjectBreakpoint.cpp
    lldb/source/Commands/Options.td
    lldb/test/API/functionalities/thread/thread_specific_break/TestThreadSpecificBreakpoint.py

Removed: 
    


################################################################################
diff  --git a/lldb/source/Commands/CommandObjectBreakpoint.cpp b/lldb/source/Commands/CommandObjectBreakpoint.cpp
index 722d5c4d8f47..3f88a2fa6378 100644
--- a/lldb/source/Commands/CommandObjectBreakpoint.cpp
+++ b/lldb/source/Commands/CommandObjectBreakpoint.cpp
@@ -110,7 +110,19 @@ class lldb_private::BreakpointOptionGroup : public OptionGroup {
     case 't': {
       lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID;
       if (option_arg[0] != '\0') {
-        if (option_arg.getAsInteger(0, thread_id))
+        if (option_arg == "current") {
+          if (!execution_context) {
+            error.SetErrorStringWithFormat("No context to determine current "
+                                           "thread");
+          } else {
+            ThreadSP ctx_thread_sp = execution_context->GetThreadSP();
+            if (!ctx_thread_sp || !ctx_thread_sp->IsValid()) {
+              error.SetErrorStringWithFormat("No currently selected thread");
+            } else {
+              thread_id = ctx_thread_sp->GetID();
+            }
+          }
+        } else if (option_arg.getAsInteger(0, thread_id))
           error.SetErrorStringWithFormat("invalid thread id string '%s'",
                                          option_arg.str().c_str());
       }

diff  --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td
index 6abb4788bed0..b78fb37f56c4 100644
--- a/lldb/source/Commands/Options.td
+++ b/lldb/source/Commands/Options.td
@@ -73,7 +73,7 @@ let Command = "breakpoint modify" in {
     "index matches this argument.">;
   def breakpoint_modify_thread_id : Option<"thread-id", "t">, Group<1>,
     Arg<"ThreadID">, Desc<"The breakpoint stops only for the thread whose TID "
-    "matches this argument.">;
+    "matches this argument.  The token 'current' resolves to the current thread's ID.">;
   def breakpoint_modify_thread_name : Option<"thread-name", "T">, Group<1>,
     Arg<"ThreadName">, Desc<"The breakpoint stops only for the thread whose "
     "thread name matches this argument.">;

diff  --git a/lldb/test/API/functionalities/thread/thread_specific_break/TestThreadSpecificBreakpoint.py b/lldb/test/API/functionalities/thread/thread_specific_break/TestThreadSpecificBreakpoint.py
index e5505e1943ce..a8fa0a58e4d5 100644
--- a/lldb/test/API/functionalities/thread/thread_specific_break/TestThreadSpecificBreakpoint.py
+++ b/lldb/test/API/functionalities/thread/thread_specific_break/TestThreadSpecificBreakpoint.py
@@ -9,11 +9,15 @@
 from lldbsuite.test.lldbtest import *
 from lldbsuite.test import lldbutil
 
-def set_thread_id(thread, breakpoint):
+def using_current(test, thread, breakpoint):
+    bp_id = breakpoint.GetID()
+    test.runCmd("break modify -t current {0}".format(bp_id))
+    
+def set_thread_id(test, thread, breakpoint):
     id = thread.id
     breakpoint.SetThreadID(id)
 
-def set_thread_name(thread, breakpoint):
+def set_thread_name(test, thread, breakpoint):
     breakpoint.SetThreadName("main-thread")
 
 class ThreadSpecificBreakTestCase(TestBase):
@@ -32,6 +36,10 @@ def test_thread_id(self):
     def test_thread_name(self):
         self.do_test(set_thread_name)
 
+    @expectedFailureAll(oslist=['ios', 'watchos', 'tvos', 'bridgeos'], archs=['armv7', 'armv7k'], bugnumber='rdar://problem/34563920') # armv7 ios problem - breakpoint with tid qualifier isn't working
+    def test_current_token(self):
+        self.do_test(using_current)
+
     def do_test(self, setter_method):
         """Test that we obey thread conditioned breakpoints."""
         self.build()
@@ -51,7 +59,7 @@ def do_test(self, setter_method):
         # thread joins the secondary thread, and then the main thread will
         # execute the code at the breakpoint.  If the thread-specific
         # breakpoint works, the next stop will be on the main thread.
-        setter_method(main_thread, thread_breakpoint)
+        setter_method(self, main_thread, thread_breakpoint)
 
         process.Continue()
         next_stop_state = process.GetState()


        


More information about the lldb-commits mailing list