Skip to content

Commit 403cd57

Browse files
committed
[LLDB] [Windows] Fix Windows-specific race condition in LLDB for session lifetime
This can e.g. happen if the debugged executable exits before the initial stop, e.g. if it fails to load dependent DLLs. Add a virtual destructor to ProcessDebugger and let it clean up the session, and make ProcessWindows::OnExitProcess call ProcessDebugger::OnExitProcess for shared parts. Fix suggestion by Adrian McCarthy. Differential Revision: https://reviews.llvm.org/D69503
1 parent 3db1d13 commit 403cd57

File tree

4 files changed

+95
-10
lines changed

4 files changed

+95
-10
lines changed

lldb/source/Plugins/Process/Windows/Common/ProcessDebugger.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ static bool IsPageExecutable(uint32_t protect) {
6363

6464
namespace lldb_private {
6565

66+
ProcessDebugger::~ProcessDebugger() {}
67+
6668
lldb::pid_t ProcessDebugger::GetDebuggedProcessId() const {
6769
if (m_session_data)
6870
return m_session_data->m_debugger->GetProcess().GetProcessId();

lldb/source/Plugins/Process/Windows/Common/ProcessDebugger.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class ProcessWindowsData {
4848
class ProcessDebugger {
4949

5050
public:
51+
virtual ~ProcessDebugger();
52+
5153
virtual void OnExitProcess(uint32_t exit_code);
5254
virtual void OnDebuggerConnected(lldb::addr_t image_base);
5355
virtual ExceptionResult OnDebugException(bool first_chance,

lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -625,16 +625,7 @@ void ProcessWindows::OnExitProcess(uint32_t exit_code) {
625625
SetProcessExitStatus(GetID(), true, 0, exit_code);
626626
SetPrivateState(eStateExited);
627627

628-
// If the process exits before any initial stop then notify the debugger
629-
// of the error otherwise WaitForDebuggerConnection() will be blocked.
630-
// An example of this issue is when a process fails to load a dependent DLL.
631-
if (m_session_data && !m_session_data->m_initial_stop_received) {
632-
Status error(exit_code, eErrorTypeWin32);
633-
OnDebuggerError(error, 0);
634-
}
635-
636-
// Reset the session.
637-
m_session_data.reset();
628+
ProcessDebugger::OnExitProcess(exit_code);
638629
}
639630

640631
void ProcessWindows::OnDebuggerConnected(lldb::addr_t image_base) {
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
## Test that we don't crash when the process fails to launch before reaching
2+
## the initial stop. This test exe has a dependency on NonExistent.dll.
3+
4+
# REQUIRES: system-windows
5+
# REQUIRES: native && target-x86_64
6+
7+
# RUN: yaml2obj %s > %t.exe
8+
# RUN: %lldb %t.exe -o run 2>&1 | FileCheck %s
9+
10+
# CHECK: error: process launch failed: unknown error
11+
12+
--- !COFF
13+
OptionalHeader:
14+
AddressOfEntryPoint: 4096
15+
ImageBase: 1073741824
16+
SectionAlignment: 4096
17+
FileAlignment: 512
18+
MajorOperatingSystemVersion: 6
19+
MinorOperatingSystemVersion: 0
20+
MajorImageVersion: 0
21+
MinorImageVersion: 0
22+
MajorSubsystemVersion: 6
23+
MinorSubsystemVersion: 0
24+
Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI
25+
DLLCharacteristics: [ IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA, IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE, IMAGE_DLL_CHARACTERISTICS_NX_COMPAT, IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE ]
26+
SizeOfStackReserve: 1048576
27+
SizeOfStackCommit: 4096
28+
SizeOfHeapReserve: 1048576
29+
SizeOfHeapCommit: 4096
30+
ExportTable:
31+
RelativeVirtualAddress: 0
32+
Size: 0
33+
ImportTable:
34+
RelativeVirtualAddress: 8192
35+
Size: 40
36+
ResourceTable:
37+
RelativeVirtualAddress: 0
38+
Size: 0
39+
ExceptionTable:
40+
RelativeVirtualAddress: 0
41+
Size: 0
42+
CertificateTable:
43+
RelativeVirtualAddress: 0
44+
Size: 0
45+
BaseRelocationTable:
46+
RelativeVirtualAddress: 0
47+
Size: 0
48+
Debug:
49+
RelativeVirtualAddress: 0
50+
Size: 0
51+
Architecture:
52+
RelativeVirtualAddress: 0
53+
Size: 0
54+
GlobalPtr:
55+
RelativeVirtualAddress: 0
56+
Size: 0
57+
TlsTable:
58+
RelativeVirtualAddress: 0
59+
Size: 0
60+
LoadConfigTable:
61+
RelativeVirtualAddress: 0
62+
Size: 0
63+
BoundImport:
64+
RelativeVirtualAddress: 0
65+
Size: 0
66+
IAT:
67+
RelativeVirtualAddress: 8248
68+
Size: 16
69+
DelayImportDescriptor:
70+
RelativeVirtualAddress: 0
71+
Size: 0
72+
ClrRuntimeHeader:
73+
RelativeVirtualAddress: 0
74+
Size: 0
75+
header:
76+
Machine: IMAGE_FILE_MACHINE_AMD64
77+
Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LARGE_ADDRESS_AWARE ]
78+
sections:
79+
- Name: .text
80+
Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
81+
VirtualAddress: 4096
82+
VirtualSize: 7
83+
SectionData: 48FF2531100000
84+
- Name: .rdata
85+
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
86+
VirtualAddress: 8192
87+
VirtualSize: 96
88+
SectionData: 282000000000000000000000502000003820000000000000000000000000000000000000000000004820000000000000000000000000000048200000000000000000000000000000000066756E6300004E6F6E4578697374656E742E646C6C00
89+
symbols: []
90+
...

0 commit comments

Comments
 (0)