Skip to content

Commit dffe3df

Browse files
charles-zablitc-rhodes
authored andcommitted
[lldb-dap][windows] allow STDIN to be a console (#178642)
(cherry picked from commit e17374a)
1 parent 51460c3 commit dffe3df

2 files changed

Lines changed: 63 additions & 1 deletion

File tree

lldb/source/Host/windows/MainLoopWindows.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ MainLoopWindows::RegisterReadObject(const IOObjectSP &object_sp,
247247
callback};
248248
} else {
249249
DWORD file_type = GetFileType(waitable_handle);
250-
if (file_type != FILE_TYPE_PIPE) {
250+
if (file_type != FILE_TYPE_CHAR && file_type != FILE_TYPE_PIPE) {
251251
error = Status::FromErrorStringWithFormat("Unsupported file type %ld",
252252
file_type);
253253
return nullptr;
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# REQUIRES: python, system-windows
2+
# RUN: %python %s %lldb-dap > %t.out 2>&1
3+
# RUN: FileCheck %s --check-prefix=ERROR --allow-empty < %t.out
4+
5+
# ERROR-NOT: DAP session error:
6+
7+
# Test that we can successfully start the dap server from the console on Windows.
8+
9+
import sys
10+
import subprocess
11+
import os
12+
13+
lldb_dap_path = sys.argv[1]
14+
if lldb_dap_path.startswith('%'):
15+
lldb_dap_path = lldb_dap_path[1:]
16+
lldb_dap_path = os.path.normpath(lldb_dap_path)
17+
18+
import ctypes
19+
from ctypes import wintypes
20+
import msvcrt
21+
22+
GENERIC_READ = 0x80000000
23+
GENERIC_WRITE = 0x40000000
24+
OPEN_EXISTING = 3
25+
FILE_SHARE_READ = 0x00000001
26+
FILE_SHARE_WRITE = 0x00000002
27+
28+
kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
29+
30+
conin_handle = kernel32.CreateFileW(
31+
"CONIN$",
32+
GENERIC_READ | GENERIC_WRITE,
33+
FILE_SHARE_READ | FILE_SHARE_WRITE,
34+
None,
35+
OPEN_EXISTING,
36+
0,
37+
None
38+
)
39+
40+
if conin_handle == -1:
41+
print("Failed to open CONIN$", file=sys.stderr)
42+
sys.exit(1)
43+
44+
conin_fd = msvcrt.open_osfhandle(conin_handle, os.O_RDONLY)
45+
46+
proc = subprocess.Popen(
47+
[lldb_dap_path],
48+
stdin=conin_fd,
49+
stdout=subprocess.PIPE,
50+
stderr=subprocess.STDOUT
51+
)
52+
53+
os.close(conin_fd)
54+
55+
try:
56+
output, _ = proc.communicate(timeout=2)
57+
except subprocess.TimeoutExpired:
58+
proc.kill()
59+
output, _ = proc.communicate()
60+
61+
sys.stdout.buffer.write(output)
62+
sys.stdout.flush()

0 commit comments

Comments
 (0)