-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Make stop-hooks fire when lldb first gains control of a process. #137410
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
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
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
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
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
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/commands/target/stop-hooks/on-core-load/TestStopHookOnCoreLoad.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 @@ | ||
""" | ||
Test that stop hooks fire on core load (first stop) | ||
""" | ||
|
||
|
||
import lldb | ||
import os | ||
from lldbsuite.test.decorators import * | ||
from lldbsuite.test.lldbtest import * | ||
from lldbsuite.test import lldbutil | ||
|
||
|
||
class TestStopOnCoreLoad(TestBase): | ||
NO_DEBUG_INFO_TESTCASE = True | ||
|
||
# This was originally marked as expected failure on Windows, but it has | ||
# started timing out instead, so the expectedFailure attribute no longer | ||
# correctly tracks it: llvm.org/pr37371 | ||
@skipIfWindows | ||
def test_hook_runs_no_threads(self): | ||
# Create core form YAML. | ||
core_path = self.getBuildArtifact("test.core") | ||
self.yaml2obj("test.core.yaml", core_path) | ||
|
||
# Since mach core files don't have stop reasons, we should choose | ||
# the first thread: | ||
self.do_test(core_path, 1) | ||
|
||
def test_hook_one_thread(self): | ||
core_path = os.path.join(self.getSourceDir(), "linux-x86_64.core") | ||
self.do_test(core_path, 3) | ||
|
||
def do_test(self, core_path, stop_thread): | ||
# Set debugger into synchronous mode | ||
self.dbg.SetAsync(False) | ||
|
||
# Create a target by the debugger. | ||
target = self.dbg.CreateTarget("") | ||
|
||
# load the stop hook module and add the stop hook: | ||
stop_hook_path = os.path.join(self.getSourceDir(), "stop_hook.py") | ||
self.runCmd(f"command script import {stop_hook_path}") | ||
self.runCmd("target stop-hook add -P stop_hook.stop_handler") | ||
|
||
# Load core. | ||
process = target.LoadCore(core_path) | ||
self.assertTrue(process, PROCESS_IS_VALID) | ||
# Now run our report command and make sure we get the right answer. | ||
|
||
result = lldb.SBCommandReturnObject() | ||
self.dbg.GetCommandInterpreter().HandleCommand("report_command", result) | ||
print(f"Command Output: '{result.GetOutput}'") | ||
self.assertIn( | ||
f"Stop Threads: {stop_thread}", result.GetOutput(), "Ran the stop hook" | ||
) |
Binary file added
BIN
+32 KB
lldb/test/API/commands/target/stop-hooks/on-core-load/linux-x86_64.core
Binary file not shown.
30 changes: 30 additions & 0 deletions
30
lldb/test/API/commands/target/stop-hooks/on-core-load/stop_hook.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,30 @@ | ||
import lldb | ||
|
||
|
||
def report_command(debugger, command, exe_ctx, result, internal_dict): | ||
global stop_thread | ||
print(f"About to report out stop_thread: {stop_thread}") | ||
mssg = f"Stop Threads: {stop_thread}" | ||
result.AppendMessage(mssg) | ||
|
||
result.SetStatus(lldb.eReturnStatusSuccessFinishResult) | ||
|
||
|
||
class stop_handler: | ||
def __init__(self, target, extra_args, dict): | ||
global stop_thread | ||
stop_thead = 0 | ||
self.target = target | ||
|
||
def handle_stop(self, exe_ctx, stream): | ||
global stop_thread | ||
thread = exe_ctx.thread | ||
stop_thread = thread.idx | ||
|
||
|
||
def __lldb_init_module(debugger, internal_dict): | ||
global stop_thread | ||
stop_thread = 0 | ||
debugger.HandleCommand( | ||
f"command script add -o -f '{__name__}.report_command' report_command" | ||
) |
Oops, something went wrong.
Oops, something went wrong.
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.
Should this be
at_first_stop
for consistency with the target setting?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 thought about this a bit, and I like
initial
better thanfirst
. I want to make sure this isn't confused with "the first user stop", andinitial
sounds more like something that always happens. So I switched everything over to initial.