Skip to content

Commit 875e1c0

Browse files
committed
Revert "Make stop-hooks fire when lldb first gains control of a process. (#137410)"
This reverts commit 4fdb8cb.
1 parent bac4aa4 commit 875e1c0

File tree

12 files changed

+10
-1221
lines changed

12 files changed

+10
-1221
lines changed

lldb/include/lldb/Target/Target.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,12 +1375,6 @@ class Target : public std::enable_shared_from_this<Target>,
13751375

13761376
bool GetAutoContinue() const { return m_auto_continue; }
13771377

1378-
void SetRunAtInitialStop(bool at_initial_stop) {
1379-
m_at_initial_stop = at_initial_stop;
1380-
}
1381-
1382-
bool GetRunAtInitialStop() const { return m_at_initial_stop; }
1383-
13841378
void GetDescription(Stream &s, lldb::DescriptionLevel level) const;
13851379
virtual void GetSubclassDescription(Stream &s,
13861380
lldb::DescriptionLevel level) const = 0;
@@ -1391,7 +1385,6 @@ class Target : public std::enable_shared_from_this<Target>,
13911385
std::unique_ptr<ThreadSpec> m_thread_spec_up;
13921386
bool m_active = true;
13931387
bool m_auto_continue = false;
1394-
bool m_at_initial_stop = true;
13951388

13961389
StopHook(lldb::TargetSP target_sp, lldb::user_id_t uid);
13971390
};
@@ -1458,9 +1451,7 @@ class Target : public std::enable_shared_from_this<Target>,
14581451

14591452
// Runs the stop hooks that have been registered for this target.
14601453
// Returns true if the stop hooks cause the target to resume.
1461-
// Pass at_initial_stop if this is the stop where lldb gains
1462-
// control over the process for the first time.
1463-
bool RunStopHooks(bool at_initial_stop = false);
1454+
bool RunStopHooks();
14641455

14651456
size_t GetStopHookSize();
14661457

lldb/source/Commands/CommandObjectTarget.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4806,17 +4806,6 @@ class CommandObjectTargetStopHookAdd : public CommandObjectParsed,
48064806
m_one_liner.push_back(std::string(option_arg));
48074807
break;
48084808

4809-
case 'I': {
4810-
bool value, success;
4811-
value = OptionArgParser::ToBoolean(option_arg, false, &success);
4812-
if (success)
4813-
m_at_initial_stop = value;
4814-
else
4815-
error = Status::FromErrorStringWithFormat(
4816-
"invalid boolean value '%s' passed for -F option",
4817-
option_arg.str().c_str());
4818-
} break;
4819-
48204809
default:
48214810
llvm_unreachable("Unimplemented option");
48224811
}
@@ -4843,7 +4832,6 @@ class CommandObjectTargetStopHookAdd : public CommandObjectParsed,
48434832
m_use_one_liner = false;
48444833
m_one_liner.clear();
48454834
m_auto_continue = false;
4846-
m_at_initial_stop = true;
48474835
}
48484836

48494837
std::string m_class_name;
@@ -4864,7 +4852,6 @@ class CommandObjectTargetStopHookAdd : public CommandObjectParsed,
48644852
// Instance variables to hold the values for one_liner options.
48654853
bool m_use_one_liner = false;
48664854
std::vector<std::string> m_one_liner;
4867-
bool m_at_initial_stop;
48684855

48694856
bool m_auto_continue = false;
48704857
};
@@ -5030,9 +5017,6 @@ Filter Options:
50305017
if (specifier_up)
50315018
new_hook_sp->SetSpecifier(specifier_up.release());
50325019

5033-
// Should we run at the initial stop:
5034-
new_hook_sp->SetRunAtInitialStop(m_options.m_at_initial_stop);
5035-
50365020
// Next see if any of the thread options have been entered:
50375021

50385022
if (m_options.m_thread_specified) {

lldb/source/Commands/Options.td

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,14 +1052,8 @@ let Command = "target stop hook add" in {
10521052
Arg<"FunctionName">, Desc<"Set the function name within which the stop hook"
10531053
" will be run.">, Completion<"Symbol">;
10541054
def target_stop_hook_add_auto_continue : Option<"auto-continue", "G">,
1055-
Arg<"Boolean">, Desc<"The stop-hook will auto-continue after running its"
1055+
Arg<"Boolean">, Desc<"The breakpoint will auto-continue after running its"
10561056
" commands.">;
1057-
def target_stop_hook_add_at_initial_stop : Option<"at-initial-stop", "I">,
1058-
Arg<"Boolean">, Desc<"Whether the stop-hook will trigger when lldb "
1059-
"initially gains control of the process. For a process launch, this "
1060-
"initial stop may happen very early on - before the loader has run. You "
1061-
"can use this option if you do not want some stop-hooks to run then. "
1062-
"Defaults to true.">;
10631057
}
10641058

10651059
let Command = "thread backtrace" in {

lldb/source/Target/Process.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2802,9 +2802,6 @@ Status Process::LoadCore() {
28022802
"Did not get stopped event after loading the core file.");
28032803
}
28042804
RestoreProcessEvents();
2805-
// Since we hijacked the event stream, we will have we won't have run the
2806-
// stop hooks. Make sure we do that here:
2807-
GetTarget().RunStopHooks(/* at_initial_stop= */ true);
28082805
}
28092806
return error;
28102807
}
@@ -3176,9 +3173,6 @@ void Process::CompleteAttach() {
31763173
: "<none>");
31773174
}
31783175
}
3179-
// Since we hijacked the event stream, we will have we won't have run the
3180-
// stop hooks. Make sure we do that here:
3181-
GetTarget().RunStopHooks(/* at_initial_stop= */ true);
31823176
}
31833177

31843178
Status Process::ConnectRemote(llvm::StringRef remote_url) {

lldb/source/Target/Target.cpp

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3048,7 +3048,7 @@ void Target::SetAllStopHooksActiveState(bool active_state) {
30483048
}
30493049
}
30503050

3051-
bool Target::RunStopHooks(bool at_initial_stop) {
3051+
bool Target::RunStopHooks() {
30523052
if (m_suppress_stop_hooks)
30533053
return false;
30543054

@@ -3057,19 +3057,14 @@ bool Target::RunStopHooks(bool at_initial_stop) {
30573057

30583058
// Somebody might have restarted the process:
30593059
// Still return false, the return value is about US restarting the target.
3060-
lldb::StateType state = m_process_sp->GetState();
3061-
if (!(state == eStateStopped || state == eStateAttaching))
3060+
if (m_process_sp->GetState() != eStateStopped)
30623061
return false;
30633062

30643063
if (m_stop_hooks.empty())
30653064
return false;
30663065

30673066
bool no_active_hooks =
3068-
llvm::none_of(m_stop_hooks, [at_initial_stop](auto &p) {
3069-
bool should_run_now =
3070-
!at_initial_stop || p.second->GetRunAtInitialStop();
3071-
return p.second->IsActive() && should_run_now;
3072-
});
3067+
llvm::none_of(m_stop_hooks, [](auto &p) { return p.second->IsActive(); });
30733068
if (no_active_hooks)
30743069
return false;
30753070

@@ -3099,22 +3094,9 @@ bool Target::RunStopHooks(bool at_initial_stop) {
30993094
}
31003095

31013096
// If no threads stopped for a reason, don't run the stop-hooks.
3102-
// However, if this is the FIRST stop for this process, then we are in the
3103-
// state where an attach or a core file load was completed without designating
3104-
// a particular thread as responsible for the stop. In that case, we do
3105-
// want to run the stop hooks, but do so just on one thread.
31063097
size_t num_exe_ctx = exc_ctx_with_reasons.size();
3107-
if (num_exe_ctx == 0) {
3108-
if (at_initial_stop && num_threads > 0) {
3109-
lldb::ThreadSP thread_to_use_sp = cur_threadlist.GetThreadAtIndex(0);
3110-
exc_ctx_with_reasons.emplace_back(
3111-
m_process_sp.get(), thread_to_use_sp.get(),
3112-
thread_to_use_sp->GetStackFrameAtIndex(0).get());
3113-
num_exe_ctx = 1;
3114-
} else {
3115-
return false;
3116-
}
3117-
}
3098+
if (num_exe_ctx == 0)
3099+
return false;
31183100

31193101
StreamSP output_sp = m_debugger.GetAsyncOutputStream();
31203102
auto on_exit = llvm::make_scope_exit([output_sp] { output_sp->Flush(); });
@@ -3128,8 +3110,6 @@ bool Target::RunStopHooks(bool at_initial_stop) {
31283110
StopHookSP cur_hook_sp = stop_entry.second;
31293111
if (!cur_hook_sp->IsActive())
31303112
continue;
3131-
if (at_initial_stop && !cur_hook_sp->GetRunAtInitialStop())
3132-
continue;
31333113

31343114
bool any_thread_matched = false;
31353115
for (auto exc_ctx : exc_ctx_with_reasons) {
@@ -3456,14 +3436,10 @@ Status Target::Launch(ProcessLaunchInfo &launch_info, Stream *stream) {
34563436
m_process_sp->RestoreProcessEvents();
34573437

34583438
if (rebroadcast_first_stop) {
3459-
// We don't need to run the stop hooks by hand here, they will get
3460-
// triggered when this rebroadcast event gets fetched.
34613439
assert(first_stop_event_sp);
34623440
m_process_sp->BroadcastEvent(first_stop_event_sp);
34633441
return error;
34643442
}
3465-
// Run the stop hooks that want to run at entry.
3466-
RunStopHooks(true /* at entry point */);
34673443

34683444
switch (state) {
34693445
case eStateStopped: {
@@ -3616,10 +3592,6 @@ Status Target::Attach(ProcessAttachInfo &attach_info, Stream *stream) {
36163592
true, SelectMostRelevantFrame);
36173593
process_sp->RestoreProcessEvents();
36183594

3619-
// Run the stop hooks here. Since we were hijacking the events, they
3620-
// wouldn't have gotten run as part of event delivery.
3621-
RunStopHooks(/* at_initial_stop= */ true);
3622-
36233595
if (state != eStateStopped) {
36243596
const char *exit_desc = process_sp->GetExitDescription();
36253597
if (exit_desc)

lldb/test/API/commands/target/stop-hooks/TestStopHookScripted.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ def test_bad_handler(self):
5050

5151
def test_stop_hooks_scripted(self):
5252
"""Test that a scripted stop hook works with no specifiers"""
53-
self.stop_hooks_scripted(5, "-I false")
54-
55-
def test_stop_hooks_scripted_no_entry(self):
56-
"""Test that a scripted stop hook works with no specifiers"""
57-
self.stop_hooks_scripted(10)
53+
self.stop_hooks_scripted(5)
5854

5955
def test_stop_hooks_scripted_right_func(self):
6056
"""Test that a scripted stop hook fires when there is a function match"""

lldb/test/API/commands/target/stop-hooks/TestStopHooks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def step_out_test(self):
5555
def after_expr_test(self):
5656
interp = self.dbg.GetCommandInterpreter()
5757
result = lldb.SBCommandReturnObject()
58-
interp.HandleCommand("target stop-hook add -o 'expr g_var++' -I false", result)
58+
interp.HandleCommand("target stop-hook add -o 'expr g_var++'", result)
5959
self.assertTrue(result.Succeeded(), "Set the target stop hook")
6060

6161
(target, process, thread, first_bkpt) = lldbutil.run_to_source_breakpoint(

lldb/test/API/commands/target/stop-hooks/on-core-load/TestStopHookOnCoreLoad.py

Lines changed: 0 additions & 55 deletions
This file was deleted.
Binary file not shown.

lldb/test/API/commands/target/stop-hooks/on-core-load/stop_hook.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)