Skip to content

Commit 1446e3c

Browse files
committed
Revert "Fix a bug with cancelling "attach -w" after you have run a process previously (#65822)"
This reverts commit 7265f79. The new test case is flaky on Linux AArch64 (https://lab.llvm.org/buildbot/#/builders/96) and more flaky on Windows on Arm (https://lab.llvm.org/buildbot/#/builders/219/builds/5735).
1 parent a2046ca commit 1446e3c

File tree

5 files changed

+22
-104
lines changed

5 files changed

+22
-104
lines changed

lldb/include/lldb/Interpreter/CommandInterpreter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ class CommandInterpreter : public Broadcaster,
447447

448448
Debugger &GetDebugger() { return m_debugger; }
449449

450-
ExecutionContext GetExecutionContext();
450+
ExecutionContext GetExecutionContext() const;
451451

452452
lldb::PlatformSP GetPlatform(bool prefer_target_platform);
453453

@@ -661,7 +661,7 @@ class CommandInterpreter : public Broadcaster,
661661

662662
void GetProcessOutput();
663663

664-
bool DidProcessStopAbnormally();
664+
bool DidProcessStopAbnormally() const;
665665

666666
void SetSynchronous(bool value);
667667

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,7 +2471,7 @@ PlatformSP CommandInterpreter::GetPlatform(bool prefer_target_platform) {
24712471
return platform_sp;
24722472
}
24732473

2474-
bool CommandInterpreter::DidProcessStopAbnormally() {
2474+
bool CommandInterpreter::DidProcessStopAbnormally() const {
24752475
auto exe_ctx = GetExecutionContext();
24762476
TargetSP target_sp = exe_ctx.GetTargetSP();
24772477
if (!target_sp)
@@ -2976,22 +2976,10 @@ void CommandInterpreter::FindCommandsForApropos(llvm::StringRef search_word,
29762976
m_alias_dict);
29772977
}
29782978

2979-
ExecutionContext CommandInterpreter::GetExecutionContext() {
2980-
ExecutionContext exe_ctx;
2981-
if (!m_overriden_exe_contexts.empty()) {
2982-
// During the course of a command, the target may have replaced the process
2983-
// coming in with another. I fix that here:
2984-
exe_ctx = m_overriden_exe_contexts.top();
2985-
// Don't use HasProcessScope, that returns false if there is a process but
2986-
// it's no longer valid, which is one of the cases we want to catch here.
2987-
if (exe_ctx.HasTargetScope() && exe_ctx.GetProcessPtr()) {
2988-
ProcessSP actual_proc_sp = exe_ctx.GetTargetSP()->GetProcessSP();
2989-
if (actual_proc_sp != exe_ctx.GetProcessSP())
2990-
m_overriden_exe_contexts.top().SetContext(actual_proc_sp);
2991-
}
2992-
return m_overriden_exe_contexts.top();
2993-
}
2994-
return m_debugger.GetSelectedExecutionContext();
2979+
ExecutionContext CommandInterpreter::GetExecutionContext() const {
2980+
return !m_overriden_exe_contexts.empty()
2981+
? m_overriden_exe_contexts.top()
2982+
: m_debugger.GetSelectedExecutionContext();
29952983
}
29962984

29972985
void CommandInterpreter::OverrideExecutionContext(
@@ -3184,17 +3172,12 @@ void CommandInterpreter::IOHandlerInputComplete(IOHandler &io_handler,
31843172
}
31853173

31863174
bool CommandInterpreter::IOHandlerInterrupt(IOHandler &io_handler) {
3187-
// InterruptCommand returns true if this is the first time
3188-
// we initiate an interrupt for this command. So we give the
3189-
// command a chance to handle the interrupt on the first
3190-
// interrupt, but if that didn't do anything, a second
3191-
// interrupt will do more work to halt the process/interpreter.
3192-
if (InterruptCommand())
3193-
return true;
3194-
31953175
ExecutionContext exe_ctx(GetExecutionContext());
31963176
Process *process = exe_ctx.GetProcessPtr();
31973177

3178+
if (InterruptCommand())
3179+
return true;
3180+
31983181
if (process) {
31993182
StateType state = process->GetState();
32003183
if (StateIsRunningState(state)) {

lldb/source/Target/Process.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3153,14 +3153,6 @@ Status Process::Halt(bool clear_thread_plans, bool use_run_lock) {
31533153
// case it was already set and some thread plan logic calls halt on its own.
31543154
m_clear_thread_plans_on_stop |= clear_thread_plans;
31553155

3156-
if (m_public_state.GetValue() == eStateAttaching) {
3157-
// Don't hijack and eat the eStateExited as the code that was doing the
3158-
// attach will be waiting for this event...
3159-
SetExitStatus(SIGKILL, "Cancelled async attach.");
3160-
Destroy(false);
3161-
return Status();
3162-
}
3163-
31643156
ListenerSP halt_listener_sp(
31653157
Listener::MakeListener("lldb.process.halt_listener"));
31663158
HijackProcessEvents(halt_listener_sp);
@@ -3169,6 +3161,15 @@ Status Process::Halt(bool clear_thread_plans, bool use_run_lock) {
31693161

31703162
SendAsyncInterrupt();
31713163

3164+
if (m_public_state.GetValue() == eStateAttaching) {
3165+
// Don't hijack and eat the eStateExited as the code that was doing the
3166+
// attach will be waiting for this event...
3167+
RestoreProcessEvents();
3168+
SetExitStatus(SIGKILL, "Cancelled async attach.");
3169+
Destroy(false);
3170+
return Status();
3171+
}
3172+
31723173
// Wait for the process halt timeout seconds for the process to stop.
31733174
// If we are going to use the run lock, that means we're stopping out to the
31743175
// user, so we should also select the most relevant frame.

lldb/test/API/commands/process/attach/TestProcessAttach.py

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55

66
import os
7-
import threading
87
import lldb
98
import shutil
109
from lldbsuite.test.decorators import *
@@ -129,65 +128,3 @@ def tearDown(self):
129128

130129
# Call super's tearDown().
131130
TestBase.tearDown(self)
132-
133-
def test_run_then_attach_wait_interrupt(self):
134-
# Test that having run one process doesn't cause us to be unable
135-
# to interrupt a subsequent attach attempt.
136-
self.build()
137-
exe = self.getBuildArtifact(exe_name)
138-
139-
target = lldbutil.run_to_breakpoint_make_target(self, exe_name, True)
140-
launch_info = target.GetLaunchInfo()
141-
launch_info.SetArguments(["q"], True)
142-
error = lldb.SBError()
143-
target.Launch(launch_info, error)
144-
self.assertSuccess(error, "Launched a process")
145-
self.assertState(target.process.state, lldb.eStateExited, "and it exited.")
146-
147-
# Okay now we've run a process, try to attach/wait to something
148-
# and make sure that we can interrupt that.
149-
150-
options = lldb.SBCommandInterpreterRunOptions()
151-
options.SetPrintResults(True)
152-
options.SetEchoCommands(False)
153-
154-
self.stdin_path = self.getBuildArtifact("stdin.txt")
155-
156-
with open(self.stdin_path, "w") as input_handle:
157-
input_handle.write("process attach -w -n noone_would_use_this_name\nquit")
158-
159-
# Python will close the file descriptor if all references
160-
# to the filehandle object lapse, so we need to keep one
161-
# around.
162-
self.filehandle = open(self.stdin_path, "r")
163-
self.dbg.SetInputFileHandle(self.filehandle, False)
164-
165-
# No need to track the output
166-
self.stdout_path = self.getBuildArtifact("stdout.txt")
167-
self.out_filehandle = open(self.stdout_path, "w")
168-
self.dbg.SetOutputFileHandle(self.out_filehandle, False)
169-
self.dbg.SetErrorFileHandle(self.out_filehandle, False)
170-
171-
n_errors, quit_req, crashed = self.dbg.RunCommandInterpreter(
172-
True, True, options, 0, False, False)
173-
174-
while 1:
175-
time.sleep(1)
176-
if target.process.state == lldb.eStateAttaching:
177-
break
178-
179-
self.dbg.DispatchInputInterrupt()
180-
self.dbg.DispatchInputInterrupt()
181-
182-
self.out_filehandle.flush()
183-
reader = open(self.stdout_path, "r")
184-
results = reader.readlines()
185-
found_result = False
186-
for line in results:
187-
if "Cancelled async attach" in line:
188-
found_result = True
189-
break
190-
self.assertTrue(found_result, "Found async error in results")
191-
# We shouldn't still have a process in the "attaching" state:
192-
state = self.dbg.GetSelectedTarget().process.state
193-
self.assertState(state, lldb.eStateExited, "Process not exited after attach cancellation")

lldb/test/API/commands/process/attach/main.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@ int main(int argc, char const *argv[]) {
1212
// Waiting to be attached by the debugger.
1313
temp = 0;
1414

15-
if (argc > 1 && argv[1][0] == 'q')
16-
return 0;
17-
1815
while (temp < 30) {
19-
std::this_thread::sleep_for(std::chrono::seconds(2)); // Waiting to be attached...
20-
temp++;
21-
}
16+
std::this_thread::sleep_for(std::chrono::seconds(2)); // Waiting to be attached...
17+
temp++;
18+
}
2219

2320
printf("Exiting now\n");
2421
}

0 commit comments

Comments
 (0)