[Lldb-commits] [lldb] Make stop-hooks fire when lldb first gains control of a process. (PR #137410)
via lldb-commits
lldb-commits at lists.llvm.org
Fri Apr 25 16:57:49 PDT 2025
https://github.com/jimingham updated https://github.com/llvm/llvm-project/pull/137410
>From 8a5e25a6e850222fcbb94f685d46895d2666041f Mon Sep 17 00:00:00 2001
From: Jim Ingham <jingham at apple.com>
Date: Fri, 25 Apr 2025 15:35:12 -0700
Subject: [PATCH 1/2] Make stop-hooks fire when lldb first gains control of a
process.
---
lldb/include/lldb/Target/Target.h | 11 +-
lldb/source/Commands/CommandObjectTarget.cpp | 16 +
lldb/source/Commands/Options.td | 7 +-
lldb/source/Target/Process.cpp | 6 +
lldb/source/Target/Target.cpp | 37 +-
.../target/stop-hooks/TestStopHookScripted.py | 6 +-
.../target/stop-hooks/TestStopHooks.py | 3 +-
.../on-core-load/TestStopHookOnCoreLoad.py | 55 +
.../stop-hooks/on-core-load/linux-x86_64.core | Bin 0 -> 32768 bytes
.../stop-hooks/on-core-load/stop_hook.py | 28 +
.../stop-hooks/on-core-load/test.core.yaml | 1056 +++++++++++++++++
lldb/test/API/python_api/event/TestEvents.py | 3 +-
12 files changed, 1218 insertions(+), 10 deletions(-)
create mode 100644 lldb/test/API/commands/target/stop-hooks/on-core-load/TestStopHookOnCoreLoad.py
create mode 100644 lldb/test/API/commands/target/stop-hooks/on-core-load/linux-x86_64.core
create mode 100644 lldb/test/API/commands/target/stop-hooks/on-core-load/stop_hook.py
create mode 100644 lldb/test/API/commands/target/stop-hooks/on-core-load/test.core.yaml
diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h
index 29183cc267721..7aa1fd18233c2 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -1369,6 +1369,12 @@ class Target : public std::enable_shared_from_this<Target>,
}
bool GetAutoContinue() const { return m_auto_continue; }
+
+ void SetRunAtFirstStop(bool at_first_stop) {
+ m_at_first_stop = at_first_stop;
+ }
+
+ bool GetRunAtFirstStop() const { return m_at_first_stop; }
void GetDescription(Stream &s, lldb::DescriptionLevel level) const;
virtual void GetSubclassDescription(Stream &s,
@@ -1380,6 +1386,7 @@ class Target : public std::enable_shared_from_this<Target>,
std::unique_ptr<ThreadSpec> m_thread_spec_up;
bool m_active = true;
bool m_auto_continue = false;
+ bool m_at_first_stop = true;
StopHook(lldb::TargetSP target_sp, lldb::user_id_t uid);
};
@@ -1446,7 +1453,9 @@ class Target : public std::enable_shared_from_this<Target>,
// Runs the stop hooks that have been registered for this target.
// Returns true if the stop hooks cause the target to resume.
- bool RunStopHooks();
+ // Pass at_initial_stop if this is the stop where lldb gains
+ // control over the process for the first time.
+ bool RunStopHooks(bool at_initial_stop = false);
size_t GetStopHookSize();
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 3f7d3007ed168..3f73157155a02 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -4795,6 +4795,17 @@ class CommandObjectTargetStopHookAdd : public CommandObjectParsed,
m_use_one_liner = true;
m_one_liner.push_back(std::string(option_arg));
break;
+
+ case 'F': {
+ bool value, success;
+ value = OptionArgParser::ToBoolean(option_arg, false, &success);
+ if (success) {
+ m_at_first_stop = value;
+ } else
+ error = Status::FromErrorStringWithFormat(
+ "invalid boolean value '%s' passed for -F option",
+ option_arg.str().c_str());
+ } break;
default:
llvm_unreachable("Unimplemented option");
@@ -4822,6 +4833,7 @@ class CommandObjectTargetStopHookAdd : public CommandObjectParsed,
m_use_one_liner = false;
m_one_liner.clear();
m_auto_continue = false;
+ m_at_first_stop = true;
}
std::string m_class_name;
@@ -4842,6 +4854,7 @@ class CommandObjectTargetStopHookAdd : public CommandObjectParsed,
// Instance variables to hold the values for one_liner options.
bool m_use_one_liner = false;
std::vector<std::string> m_one_liner;
+ bool m_at_first_stop;
bool m_auto_continue = false;
};
@@ -5006,6 +5019,9 @@ Filter Options:
if (specifier_up)
new_hook_sp->SetSpecifier(specifier_up.release());
+
+ // Should we run at first stop:
+ new_hook_sp->SetRunAtFirstStop(m_options.m_at_first_stop);
// Next see if any of the thread options have been entered:
diff --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td
index 53864ff29327d..50313ac2cacbc 100644
--- a/lldb/source/Commands/Options.td
+++ b/lldb/source/Commands/Options.td
@@ -1050,8 +1050,13 @@ let Command = "target stop hook add" in {
Arg<"FunctionName">, Desc<"Set the function name within which the stop hook"
" will be run.">, Completion<"Symbol">;
def target_stop_hook_add_auto_continue : Option<"auto-continue", "G">,
- Arg<"Boolean">, Desc<"The breakpoint will auto-continue after running its"
+ Arg<"Boolean">, Desc<"The stop-hook will auto-continue after running its"
" commands.">;
+ def target_stop_hook_add_at_first_stop : Option<"at-first-stop", "F">,
+ Arg<"Boolean">, Desc<"Whether the stop-hook will trigger when lldb first "
+ "gains control of the process. For a process launch, this first stop "
+ "may happen very early on - before the loader has run. You might not want "
+ "some stop-hooks to run then. Defaults to true.">;
}
let Command = "thread backtrace" in {
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 73557eb767c72..f68bfa504f2c0 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -2830,6 +2830,9 @@ Status Process::LoadCore() {
"Did not get stopped event after loading the core file.");
}
RestoreProcessEvents();
+ // Since we hijacked the event stream, we will have we won't have run the
+ // stop hooks. Make sure we do that here:
+ GetTarget().RunStopHooks(true /* at_initial_stop */);
}
return error;
}
@@ -3200,6 +3203,9 @@ void Process::CompleteAttach() {
: "<none>");
}
}
+ // Since we hijacked the event stream, we will have we won't have run the
+ // stop hooks. Make sure we do that here:
+ GetTarget().RunStopHooks(true /* at_initial_stop */);
}
Status Process::ConnectRemote(llvm::StringRef remote_url) {
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 0fa61b20e19b9..3b31f6d0406a5 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -3038,7 +3038,7 @@ void Target::SetAllStopHooksActiveState(bool active_state) {
}
}
-bool Target::RunStopHooks() {
+bool Target::RunStopHooks(bool at_initial_stop) {
if (m_suppress_stop_hooks)
return false;
@@ -3047,14 +3047,18 @@ bool Target::RunStopHooks() {
// Somebody might have restarted the process:
// Still return false, the return value is about US restarting the target.
- if (m_process_sp->GetState() != eStateStopped)
+ lldb::StateType state = m_process_sp->GetState();
+ if (!(state == eStateStopped || state == eStateAttaching))
return false;
if (m_stop_hooks.empty())
return false;
bool no_active_hooks =
- llvm::none_of(m_stop_hooks, [](auto &p) { return p.second->IsActive(); });
+ llvm::none_of(m_stop_hooks, [at_initial_stop](auto &p) {
+ bool should_run_now = !at_initial_stop || p.second->GetRunAtFirstStop();
+ return p.second->IsActive() && should_run_now;
+ });
if (no_active_hooks)
return false;
@@ -3084,9 +3088,22 @@ bool Target::RunStopHooks() {
}
// If no threads stopped for a reason, don't run the stop-hooks.
+ // However, if this is the FIRST stop for this process, then we are in the
+ // state where an attach or a core file load was completed without designating
+ // a particular thread as responsible for the stop. In that case, we do
+ // want to run the stop hooks, but do so just on one thread.
size_t num_exe_ctx = exc_ctx_with_reasons.size();
- if (num_exe_ctx == 0)
- return false;
+ if (num_exe_ctx == 0) {
+ if (at_initial_stop && num_threads > 0) {
+ lldb::ThreadSP thread_to_use_sp = cur_threadlist.GetThreadAtIndex(0);
+ exc_ctx_with_reasons.emplace_back(m_process_sp.get(),
+ thread_to_use_sp.get(),
+ thread_to_use_sp->GetStackFrameAtIndex(0).get());
+ num_exe_ctx = 1;
+ } else
+ return false;
+ }
+
StreamSP output_sp = m_debugger.GetAsyncOutputStream();
auto on_exit = llvm::make_scope_exit([output_sp] { output_sp->Flush(); });
@@ -3100,6 +3117,8 @@ bool Target::RunStopHooks() {
StopHookSP cur_hook_sp = stop_entry.second;
if (!cur_hook_sp->IsActive())
continue;
+ if (at_initial_stop && !cur_hook_sp->GetRunAtFirstStop())
+ continue;
bool any_thread_matched = false;
for (auto exc_ctx : exc_ctx_with_reasons) {
@@ -3426,10 +3445,14 @@ Status Target::Launch(ProcessLaunchInfo &launch_info, Stream *stream) {
m_process_sp->RestoreProcessEvents();
if (rebroadcast_first_stop) {
+ // We don't need to run the stop hooks by hand here, they will get
+ // triggered when this rebroadcast event gets fetched.
assert(first_stop_event_sp);
m_process_sp->BroadcastEvent(first_stop_event_sp);
return error;
}
+ // Run the stop hooks that want to run at entry.
+ RunStopHooks(true /* at entry point */);
switch (state) {
case eStateStopped: {
@@ -3581,6 +3604,10 @@ Status Target::Attach(ProcessAttachInfo &attach_info, Stream *stream) {
std::nullopt, nullptr, false, attach_info.GetHijackListener(), stream,
true, SelectMostRelevantFrame);
process_sp->RestoreProcessEvents();
+
+ // Run the stop hooks here. Since we were hijacking the events, they
+ // wouldn't have gotten run as part of event delivery.
+ RunStopHooks(true /* at_initial_stop */);
if (state != eStateStopped) {
const char *exit_desc = process_sp->GetExitDescription();
diff --git a/lldb/test/API/commands/target/stop-hooks/TestStopHookScripted.py b/lldb/test/API/commands/target/stop-hooks/TestStopHookScripted.py
index 7c10669442b1c..38d8815e8ff50 100644
--- a/lldb/test/API/commands/target/stop-hooks/TestStopHookScripted.py
+++ b/lldb/test/API/commands/target/stop-hooks/TestStopHookScripted.py
@@ -50,7 +50,11 @@ def test_bad_handler(self):
def test_stop_hooks_scripted(self):
"""Test that a scripted stop hook works with no specifiers"""
- self.stop_hooks_scripted(5)
+ self.stop_hooks_scripted(5, "-F false")
+
+ def test_stop_hooks_scripted_no_entry(self):
+ """Test that a scripted stop hook works with no specifiers"""
+ self.stop_hooks_scripted(10)
def test_stop_hooks_scripted_right_func(self):
"""Test that a scripted stop hook fires when there is a function match"""
diff --git a/lldb/test/API/commands/target/stop-hooks/TestStopHooks.py b/lldb/test/API/commands/target/stop-hooks/TestStopHooks.py
index 7d52676121827..2d13b06d09c1a 100644
--- a/lldb/test/API/commands/target/stop-hooks/TestStopHooks.py
+++ b/lldb/test/API/commands/target/stop-hooks/TestStopHooks.py
@@ -55,7 +55,7 @@ def step_out_test(self):
def after_expr_test(self):
interp = self.dbg.GetCommandInterpreter()
result = lldb.SBCommandReturnObject()
- interp.HandleCommand("target stop-hook add -o 'expr g_var++'", result)
+ interp.HandleCommand("target stop-hook add -o 'expr g_var++' -F false", result)
self.assertTrue(result.Succeeded(), "Set the target stop hook")
(target, process, thread, first_bkpt) = lldbutil.run_to_source_breakpoint(
@@ -109,3 +109,4 @@ def before_and_after_target(self):
self.expect(
"target stop-hook list", substrs=["expr g_var++", "thread backtrace"]
)
+
diff --git a/lldb/test/API/commands/target/stop-hooks/on-core-load/TestStopHookOnCoreLoad.py b/lldb/test/API/commands/target/stop-hooks/on-core-load/TestStopHookOnCoreLoad.py
new file mode 100644
index 0000000000000..364a85fdd84ae
--- /dev/null
+++ b/lldb/test/API/commands/target/stop-hooks/on-core-load/TestStopHookOnCoreLoad.py
@@ -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")
+
diff --git a/lldb/test/API/commands/target/stop-hooks/on-core-load/linux-x86_64.core b/lldb/test/API/commands/target/stop-hooks/on-core-load/linux-x86_64.core
new file mode 100644
index 0000000000000000000000000000000000000000..fc27e5810ee589fc810bdda01d6c227c734f34a3
GIT binary patch
literal 32768
zcmeHP4RBP|6~3E40+MdD2C;%{3pz#0W)mO<qIFjSzOAXIU>rIUH_PsZq-3*k_bm`>
zB at hCxYn)8gR&-kJ_*18~K*!FMcBYsRM#aGzeyVn?N)aqSj;2zHg0em5y>pg*Z+B-A
zt%}~8d3)YD_ndpr{qDW*p8MwIuAEytFVA8ToC?JE#3 at b)CugKkr<f at w6JJ1d=ExL<
zl-u5mQ<#)ntfLTl2Me8iW2Bs4s*BN1tCQunMx#D+q%TtJiZGAu9F44Lq`B;d#^f0d
zh_mJEH!1ZQ+GiWSd+W*!mV+0i*=YjybLhN#GTI4Snw<fcp~}p5PTed!F4HpGQFU4E
z>ay5nsLy~)Zx*{w8igr%YMwJLr86 at 7nG2WF`pkAzPuBL?&d|=0#V!{v?OE&^bKo*~
zL+17kP0-*=ZJ%Mh^exM5mkXD{)3-D9``#>eom3$aYVE0c+qf>XpSjvs_nXXix!Tuw
z`gVr)wP&&GydbR~4C8ueOJ+ZFjq9P;GTS|*SC`uFhUZ}K>zVCrIqWuNv2&)|8E_fO
zVpm6x)s%iW_&Jow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-hooks/on-core-load/stop_hook.py b/lldb/test/API/commands/target/stop-hooks/on-core-load/stop_hook.py
new file mode 100644
index 0000000000000..ba8215e69dc42
--- /dev/null
+++ b/lldb/test/API/commands/target/stop-hooks/on-core-load/stop_hook.py
@@ -0,0 +1,28 @@
+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"
+)
+
diff --git a/lldb/test/API/commands/target/stop-hooks/on-core-load/test.core.yaml b/lldb/test/API/commands/target/stop-hooks/on-core-load/test.core.yaml
new file mode 100644
index 0000000000000..009c44aa1d1ad
--- /dev/null
+++ b/lldb/test/API/commands/target/stop-hooks/on-core-load/test.core.yaml
@@ -0,0 +1,1056 @@
+--- !mach-o
+FileHeader:
+ magic: 0xFEEDFACF
+ cputype: 0x01000007
+ cpusubtype: 0x00000003
+ filetype: 0x00000004
+ ncmds: 59
+ sizeofcmds: 4384
+ flags: 0x00000000
+ reserved: 0x00000000
+LoadCommands:
+ - cmd: LC_THREAD
+ cmdsize: 208
+ PayloadBytes:
+ - 0x04
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x2A
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x01
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0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- 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x2B
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x06
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x04
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x03
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x10
+ - 0x00
+ - 0x02
+ - 0xA7
+ - 0xFF
+ - 0x7F
+ - 0x00
+ - 0x00
+ - cmd: LC_THREAD
+ cmdsize: 208
+ PayloadBytes:
+ - 0x04
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x2A
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x01
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x80
+ - 0xF7
+ - 0xBF
+ - 0xEF
+ - 0xFE
+ - 0x7F
+ - 0x00
+ - 0x00
+ - 0x20
+ - 0xF6
+ - 0xBF
+ - 0xEF
+ - 0xFE
+ - 0x7F
+ - 0x00
+ - 0x00
+ - 0x01
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x10
+ - 0xF6
+ - 0xBF
+ - 0xEF
+ - 0xFE
+ - 0x7F
+ - 0x00
+ - 0x00
+ - 0xF0
+ - 0xF5
+ - 0xBF
+ - 0xEF
+ - 0xFE
+ - 0x7F
+ - 0x00
+ - 0x00
+ - 0xF0
+ - 0xF5
+ - 0xBF
+ - 0xEF
+ - 0xFE
+ - 0x7F
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0xFF
+ - 0xFF
+ - 0xFF
+ - 0xFF
+ - 0xC8
+ - 0xB0
+ - 0x70
+ - 0xA7
+ - 0xFF
+ - 0x7F
+ - 0x00
+ - 0x00
+ - 0xD0
+ - 0xB0
+ - 0x70
+ - 0xA7
+ - 0xFF
+ - 0x7F
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0xA0
+ - 0x0F
+ - 0x00
+ - 0x00
+ - 0x01
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x46
+ - 0x02
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x2B
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x06
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x04
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x03
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x00
+ - 0x10
+ - 0x00
+ - 0x02
+ - 0xA7
+ - 0xFF
+ - 0x7F
+ - 0x00
+ - 0x00
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 4294967296
+ vmsize: 4096
+ fileoff: 8192
+ filesize: 4096
+ maxprot: 5
+ initprot: 5
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 4294971392
+ vmsize: 4096
+ fileoff: 12288
+ filesize: 4096
+ maxprot: 1
+ initprot: 1
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 4294975488
+ vmsize: 307200
+ fileoff: 16384
+ filesize: 307200
+ maxprot: 5
+ initprot: 5
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 4295282688
+ vmsize: 12288
+ fileoff: 323584
+ filesize: 12288
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 4295294976
+ vmsize: 217088
+ fileoff: 335872
+ filesize: 217088
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 4295512064
+ vmsize: 110592
+ fileoff: 552960
+ filesize: 110592
+ maxprot: 1
+ initprot: 1
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 4295622656
+ vmsize: 8192
+ fileoff: 663552
+ filesize: 8192
+ maxprot: 1
+ initprot: 1
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 4295630848
+ vmsize: 8192
+ fileoff: 671744
+ filesize: 8192
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 4295639040
+ vmsize: 4096
+ fileoff: 679936
+ filesize: 4096
+ maxprot: 1
+ initprot: 1
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 4295643136
+ vmsize: 4096
+ fileoff: 684032
+ filesize: 4096
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 4295651328
+ vmsize: 24576
+ fileoff: 688128
+ filesize: 24576
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 4295684096
+ vmsize: 24576
+ fileoff: 712704
+ filesize: 24576
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 4295712768
+ vmsize: 4096
+ fileoff: 737280
+ filesize: 4096
+ maxprot: 1
+ initprot: 1
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 4295716864
+ vmsize: 8192
+ fileoff: 741376
+ filesize: 8192
+ maxprot: 1
+ initprot: 1
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 4296015872
+ vmsize: 1048576
+ fileoff: 749568
+ filesize: 1048576
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 4297064448
+ vmsize: 1048576
+ fileoff: 1798144
+ filesize: 1048576
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 4298113024
+ vmsize: 1048576
+ fileoff: 2846720
+ filesize: 1048576
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 4303355904
+ vmsize: 8388608
+ fileoff: 3895296
+ filesize: 8388608
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140732912369664
+ vmsize: 8388608
+ fileoff: 12283904
+ filesize: 8388608
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140734252867584
+ vmsize: 811999232
+ fileoff: 20672512
+ filesize: 811999232
+ maxprot: 5
+ initprot: 5
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735863480320
+ vmsize: 20553728
+ fileoff: 832671744
+ filesize: 20553728
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735884034048
+ vmsize: 2097152
+ fileoff: 853225472
+ filesize: 2097152
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735886131200
+ vmsize: 2097152
+ fileoff: 855322624
+ filesize: 2097152
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735888228352
+ vmsize: 2097152
+ fileoff: 857419776
+ filesize: 2097152
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735890325504
+ vmsize: 2097152
+ fileoff: 859516928
+ filesize: 2097152
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735892422656
+ vmsize: 2097152
+ fileoff: 861614080
+ filesize: 2097152
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735894519808
+ vmsize: 2097152
+ fileoff: 863711232
+ filesize: 2097152
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735896616960
+ vmsize: 2097152
+ fileoff: 865808384
+ filesize: 2097152
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735898714112
+ vmsize: 2097152
+ fileoff: 867905536
+ filesize: 2097152
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735900811264
+ vmsize: 2097152
+ fileoff: 870002688
+ filesize: 2097152
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735902908416
+ vmsize: 10485760
+ fileoff: 872099840
+ filesize: 10485760
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735913394176
+ vmsize: 4194304
+ fileoff: 882585600
+ filesize: 4194304
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735917588480
+ vmsize: 2097152
+ fileoff: 886779904
+ filesize: 2097152
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735919685632
+ vmsize: 2097152
+ fileoff: 888877056
+ filesize: 2097152
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735921782784
+ vmsize: 4194304
+ fileoff: 890974208
+ filesize: 4194304
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735925977088
+ vmsize: 4194304
+ fileoff: 895168512
+ filesize: 4194304
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735930171392
+ vmsize: 6291456
+ fileoff: 899362816
+ filesize: 6291456
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735936462848
+ vmsize: 2097152
+ fileoff: 905654272
+ filesize: 2097152
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735938560000
+ vmsize: 2097152
+ fileoff: 907751424
+ filesize: 2097152
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735940657152
+ vmsize: 2097152
+ fileoff: 909848576
+ filesize: 2097152
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735942754304
+ vmsize: 2097152
+ fileoff: 911945728
+ filesize: 2097152
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735944851456
+ vmsize: 6291456
+ fileoff: 914042880
+ filesize: 6291456
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735951142912
+ vmsize: 2097152
+ fileoff: 920334336
+ filesize: 2097152
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735953240064
+ vmsize: 4194304
+ fileoff: 922431488
+ filesize: 4194304
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735957434368
+ vmsize: 2097152
+ fileoff: 926625792
+ filesize: 2097152
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735959531520
+ vmsize: 2097152
+ fileoff: 928722944
+ filesize: 2097152
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735961628672
+ vmsize: 20971520
+ fileoff: 930820096
+ filesize: 20971520
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735982600192
+ vmsize: 6291456
+ fileoff: 951791616
+ filesize: 6291456
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735988891648
+ vmsize: 2097152
+ fileoff: 958083072
+ filesize: 2097152
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735990988800
+ vmsize: 2097152
+ fileoff: 960180224
+ filesize: 2097152
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735993085952
+ vmsize: 2097152
+ fileoff: 962277376
+ filesize: 2097152
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735995183104
+ vmsize: 2097152
+ fileoff: 964374528
+ filesize: 2097152
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735997280256
+ vmsize: 2097152
+ fileoff: 966471680
+ filesize: 2097152
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140735999377408
+ vmsize: 2097152
+ fileoff: 968568832
+ filesize: 2097152
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140736001474560
+ vmsize: 1302528
+ fileoff: 970665984
+ filesize: 1302528
+ maxprot: 3
+ initprot: 3
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140736937222144
+ vmsize: 219267072
+ fileoff: 971968512
+ filesize: 219267072
+ maxprot: 1
+ initprot: 1
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140737486258176
+ vmsize: 4096
+ fileoff: 1191235584
+ filesize: 4096
+ maxprot: 1
+ initprot: 1
+ nsects: 0
+ flags: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 72
+ segname: ''
+ vmaddr: 140737487028224
+ vmsize: 4096
+ fileoff: 1191239680
+ filesize: 4096
+ maxprot: 5
+ initprot: 5
+ nsects: 0
+ flags: 0
+...
diff --git a/lldb/test/API/python_api/event/TestEvents.py b/lldb/test/API/python_api/event/TestEvents.py
index fb1a7e3bc6d3a..9b73a0e2e1e04 100644
--- a/lldb/test/API/python_api/event/TestEvents.py
+++ b/lldb/test/API/python_api/event/TestEvents.py
@@ -411,8 +411,9 @@ def test_shadow_listener(self):
self.runCmd(f"command script import {stop_hook_path}")
import stop_hook
+ # Add our stop hook here, don't report on the initial attach:
self.runCmd(
- f"target stop-hook add -P stop_hook.StopHook -k instance -v {self.instance}"
+ f"target stop-hook add -P stop_hook.StopHook -k instance -v {self.instance} -F false"
)
self.stop_counter = 0
>From 3ba6a55a2821313db5554aee7fedd0bafb4d3bde Mon Sep 17 00:00:00 2001
From: Jim Ingham <jingham at apple.com>
Date: Fri, 25 Apr 2025 16:57:25 -0700
Subject: [PATCH 2/2] reformatting
---
lldb/include/lldb/Target/Target.h | 4 ++--
lldb/source/Commands/CommandObjectTarget.cpp | 4 ++--
lldb/source/Target/Target.cpp | 17 ++++++++---------
.../commands/target/stop-hooks/TestStopHooks.py | 1 -
.../on-core-load/TestStopHookOnCoreLoad.py | 16 ++++++++--------
.../target/stop-hooks/on-core-load/stop_hook.py | 10 ++++++----
6 files changed, 26 insertions(+), 26 deletions(-)
diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h
index 7aa1fd18233c2..7e89d31761aa7 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -1369,11 +1369,11 @@ class Target : public std::enable_shared_from_this<Target>,
}
bool GetAutoContinue() const { return m_auto_continue; }
-
+
void SetRunAtFirstStop(bool at_first_stop) {
m_at_first_stop = at_first_stop;
}
-
+
bool GetRunAtFirstStop() const { return m_at_first_stop; }
void GetDescription(Stream &s, lldb::DescriptionLevel level) const;
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 3f73157155a02..d162846bad8d8 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -4795,7 +4795,7 @@ class CommandObjectTargetStopHookAdd : public CommandObjectParsed,
m_use_one_liner = true;
m_one_liner.push_back(std::string(option_arg));
break;
-
+
case 'F': {
bool value, success;
value = OptionArgParser::ToBoolean(option_arg, false, &success);
@@ -5019,7 +5019,7 @@ Filter Options:
if (specifier_up)
new_hook_sp->SetSpecifier(specifier_up.release());
-
+
// Should we run at first stop:
new_hook_sp->SetRunAtFirstStop(m_options.m_at_first_stop);
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 3b31f6d0406a5..473cd3afc0d0c 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -3056,9 +3056,9 @@ bool Target::RunStopHooks(bool at_initial_stop) {
bool no_active_hooks =
llvm::none_of(m_stop_hooks, [at_initial_stop](auto &p) {
- bool should_run_now = !at_initial_stop || p.second->GetRunAtFirstStop();
- return p.second->IsActive() && should_run_now;
- });
+ bool should_run_now = !at_initial_stop || p.second->GetRunAtFirstStop();
+ return p.second->IsActive() && should_run_now;
+ });
if (no_active_hooks)
return false;
@@ -3096,14 +3096,13 @@ bool Target::RunStopHooks(bool at_initial_stop) {
if (num_exe_ctx == 0) {
if (at_initial_stop && num_threads > 0) {
lldb::ThreadSP thread_to_use_sp = cur_threadlist.GetThreadAtIndex(0);
- exc_ctx_with_reasons.emplace_back(m_process_sp.get(),
- thread_to_use_sp.get(),
- thread_to_use_sp->GetStackFrameAtIndex(0).get());
+ exc_ctx_with_reasons.emplace_back(
+ m_process_sp.get(), thread_to_use_sp.get(),
+ thread_to_use_sp->GetStackFrameAtIndex(0).get());
num_exe_ctx = 1;
} else
return false;
}
-
StreamSP output_sp = m_debugger.GetAsyncOutputStream();
auto on_exit = llvm::make_scope_exit([output_sp] { output_sp->Flush(); });
@@ -3604,8 +3603,8 @@ Status Target::Attach(ProcessAttachInfo &attach_info, Stream *stream) {
std::nullopt, nullptr, false, attach_info.GetHijackListener(), stream,
true, SelectMostRelevantFrame);
process_sp->RestoreProcessEvents();
-
- // Run the stop hooks here. Since we were hijacking the events, they
+
+ // Run the stop hooks here. Since we were hijacking the events, they
// wouldn't have gotten run as part of event delivery.
RunStopHooks(true /* at_initial_stop */);
diff --git a/lldb/test/API/commands/target/stop-hooks/TestStopHooks.py b/lldb/test/API/commands/target/stop-hooks/TestStopHooks.py
index 2d13b06d09c1a..7a206486bf63e 100644
--- a/lldb/test/API/commands/target/stop-hooks/TestStopHooks.py
+++ b/lldb/test/API/commands/target/stop-hooks/TestStopHooks.py
@@ -109,4 +109,3 @@ def before_and_after_target(self):
self.expect(
"target stop-hook list", substrs=["expr g_var++", "thread backtrace"]
)
-
diff --git a/lldb/test/API/commands/target/stop-hooks/on-core-load/TestStopHookOnCoreLoad.py b/lldb/test/API/commands/target/stop-hooks/on-core-load/TestStopHookOnCoreLoad.py
index 364a85fdd84ae..fa142de949057 100644
--- a/lldb/test/API/commands/target/stop-hooks/on-core-load/TestStopHookOnCoreLoad.py
+++ b/lldb/test/API/commands/target/stop-hooks/on-core-load/TestStopHookOnCoreLoad.py
@@ -22,15 +22,14 @@ def test_hook_runs_no_threads(self):
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:
+ # 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)
@@ -42,14 +41,15 @@ def do_test(self, core_path, stop_thread):
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.
-
+ # 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")
-
+ self.assertIn(
+ f"Stop Threads: {stop_thread}", result.GetOutput(), "Ran the stop hook"
+ )
diff --git a/lldb/test/API/commands/target/stop-hooks/on-core-load/stop_hook.py b/lldb/test/API/commands/target/stop-hooks/on-core-load/stop_hook.py
index ba8215e69dc42..d976d2e093ff1 100644
--- a/lldb/test/API/commands/target/stop-hooks/on-core-load/stop_hook.py
+++ b/lldb/test/API/commands/target/stop-hooks/on-core-load/stop_hook.py
@@ -1,5 +1,6 @@
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}")
@@ -7,7 +8,8 @@ def report_command(debugger, command, exe_ctx, result, internal_dict):
result.AppendMessage(mssg)
result.SetStatus(lldb.eReturnStatusSuccessFinishResult)
-
+
+
class stop_handler:
def __init__(self, target, extra_args, dict):
global stop_thread
@@ -19,10 +21,10 @@ def handle_stop(self, exe_ctx, stream):
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"
-)
-
+ f"command script add -o -f '{__name__}.report_command' report_command"
+ )
More information about the lldb-commits
mailing list