forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 342
[lldb] Introduce command to select task "threads" #9840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kastiglione
merged 6 commits into
stable/20240723
from
dl/lldb-Introduce-command-to-select-task-threads
Jan 23, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d32d287
[lldb] Introduce command to select task "threads"
kastiglione 9e8c614
Reduce tid expectation in test
kastiglione d7f10b9
Change test to use platform agnostic library name
kastiglione 554406f
Fix logic mistake in test
kastiglione 1f1c08a
Use SBAPI to test selected thread/frame
kastiglione 277bba4
Remove temporary comment
kastiglione File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
lldb/test/API/lang/swift/async/tasks/TestSwiftTaskSelect.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import lldb | ||
from lldbsuite.test.decorators import * | ||
from lldbsuite.test.lldbtest import TestBase | ||
import lldbsuite.test.lldbutil as lldbutil | ||
|
||
|
||
class TestCase(TestBase): | ||
|
||
def test_backtrace_selected_task(self): | ||
self.build() | ||
lldbutil.run_to_source_breakpoint( | ||
self, "break here", lldb.SBFileSpec("main.swift") | ||
) | ||
self.runCmd("language swift task select task") | ||
self.expect( | ||
"thread backtrace", | ||
substrs=[ | ||
".sleep(", | ||
"`second() at main.swift:6:", | ||
"`first() at main.swift:2:", | ||
"`closure #1 in static Main.main() at main.swift:12:", | ||
], | ||
) | ||
|
||
def test_navigate_selected_task_stack(self): | ||
self.build() | ||
_, process, _, _ = lldbutil.run_to_source_breakpoint( | ||
self, "break here", lldb.SBFileSpec("main.swift") | ||
) | ||
self.runCmd("language swift task select task") | ||
|
||
thread = process.selected_thread | ||
self.assertEqual(thread.id, 2) | ||
self.assertEqual(thread.idx, 0xFFFFFFFF) | ||
self.assertIn( | ||
"libswift_Concurrency.", thread.GetSelectedFrame().module.file.basename | ||
) | ||
|
||
frame_idx = -1 | ||
for frame in thread: | ||
if "`second()" in str(frame): | ||
frame_idx = frame.idx | ||
self.assertNotEqual(frame_idx, -1) | ||
|
||
self.expect(f"frame select {frame_idx}", substrs=[f"frame #{frame_idx}:"]) | ||
frame = thread.GetSelectedFrame() | ||
self.assertIn(".second()", frame.function.name) | ||
|
||
self.expect("up", substrs=[f"frame #{frame_idx + 1}:"]) | ||
frame = thread.GetSelectedFrame() | ||
self.assertIn(".first()", frame.function.name) | ||
|
||
self.expect("up", substrs=[f"frame #{frame_idx + 2}:"]) | ||
frame = thread.GetSelectedFrame() | ||
self.assertIn(".Main.main()", frame.function.name) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Process class has a mutex to protect its thread list; should we lock it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. The ThreadList references the processes lock. The lock is taken inside
AddThread
, I would say there's no need to take the lock here explicitly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I wasn't aware that these methods were already thread-safe.
I guess the only argument for locking outside would be if these two operations need to be atomic:
If they don't, then no locking is needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these being non-atomic is ok. If another thread is attempting to remove the
thread_task
(which strikes me as unlikely), then I'm not sure it matters whether the removal happens before or afterSetSelectedThreadByID
.