Commit f362b05d authored by Jim Ingham's avatar Jim Ingham
Browse files

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
parent 3229c971
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -110,7 +110,19 @@ public:
    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());
      }
+1 −1
Original line number Diff line number Diff line
@@ -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.">;
+11 −3
Original line number Diff line number Diff line
@@ -9,11 +9,15 @@ from lldbsuite.test.decorators import *
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 @@ class ThreadSpecificBreakTestCase(TestBase):
    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 @@ class ThreadSpecificBreakTestCase(TestBase):
        # 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()