[Lldb-commits] [PATCH] D107015: Add "current" token for the -t option to "break set/modify"
Jim Ingham via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Wed Jul 28 17:08:47 PDT 2021
jingham created this revision.
jingham added reviewers: kastiglione, JDevlieghere.
Herald added a subscriber: dang.
jingham requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.
It's fairly common to want to set a breakpoint that is limited to the current thread. For instance, if you hit function A on thread 1, then you want to set a breakpoint on function B but only when this thread hits it. You can do this in Python, but it should be simple to do this just from the command line. With this patch you can do:
break set -t current -n foo
or something like that.
This actually uses the thread from the ExecutionContext passed to the CommandObjectBreakpointSet::DoExecute, not the currently selected thread, so it will work in breakpoint commands as well as from the command line. That's the right thing to do.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D107015
Files:
lldb/source/Commands/CommandObjectBreakpoint.cpp
lldb/source/Commands/Options.td
lldb/test/API/functionalities/thread/thread_specific_break/TestThreadSpecificBreakpoint.py
Index: lldb/test/API/functionalities/thread/thread_specific_break/TestThreadSpecificBreakpoint.py
===================================================================
--- lldb/test/API/functionalities/thread/thread_specific_break/TestThreadSpecificBreakpoint.py
+++ 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_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 @@
# 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()
Index: lldb/source/Commands/Options.td
===================================================================
--- lldb/source/Commands/Options.td
+++ lldb/source/Commands/Options.td
@@ -73,7 +73,7 @@
"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.">;
Index: lldb/source/Commands/CommandObjectBreakpoint.cpp
===================================================================
--- lldb/source/Commands/CommandObjectBreakpoint.cpp
+++ lldb/source/Commands/CommandObjectBreakpoint.cpp
@@ -110,7 +110,19 @@
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());
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107015.362586.patch
Type: text/x-patch
Size: 3725 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210729/f457deaf/attachment-0001.bin>
More information about the lldb-commits
mailing list