diff options
| author | Aaron Smith <aaron.smith@microsoft.com> | 2019-08-13 23:50:54 +0000 |
|---|---|---|
| committer | Aaron Smith <aaron.smith@microsoft.com> | 2019-08-13 23:50:54 +0000 |
| commit | 216944ee035aa720cc94034f3aa68064eda80469 (patch) | |
| tree | 584ee74d8b8a9288a4660f8fe2cca4611011b634 | |
| parent | 0df9c8c57802b0b1c75380c904b3cce0b902e2c5 (diff) | |
| download | bcm5719-llvm-216944ee035aa720cc94034f3aa68064eda80469.tar.gz bcm5719-llvm-216944ee035aa720cc94034f3aa68064eda80469.zip | |
Enable lldb-server on Windows
Summary:
This commit contains three small changes to enable lldb-server on Windows.
- Add lldb-server for Windows to the build
- Disable pty redirection on Windows for the initial lldb-server bring up
- Add a support to get the parent pid for a process on Windows
- Ifdef some signals which aren't supported on Windows
Thanks to Hui Huang for the help with this patch!
Reviewers: labath
Reviewed By: labath
Subscribers: JDevlieghere, compnerd, Hui, amccarth, xiaobai, srhines, mgorny, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D61686
llvm-svn: 368774
6 files changed, 34 insertions, 4 deletions
diff --git a/lldb/cmake/modules/LLDBConfig.cmake b/lldb/cmake/modules/LLDBConfig.cmake index 270a46a9b25..ab15ebbdcc7 100644 --- a/lldb/cmake/modules/LLDBConfig.cmake +++ b/lldb/cmake/modules/LLDBConfig.cmake @@ -408,7 +408,7 @@ list(APPEND system_libs ${CMAKE_DL_LIBS}) # Figure out if lldb could use lldb-server. If so, then we'll # ensure we build lldb-server when an lldb target is being built. -if (CMAKE_SYSTEM_NAME MATCHES "Android|Darwin|FreeBSD|Linux|NetBSD") +if (CMAKE_SYSTEM_NAME MATCHES "Android|Darwin|FreeBSD|Linux|NetBSD|Windows") set(LLDB_CAN_USE_LLDB_SERVER ON) else() set(LLDB_CAN_USE_LLDB_SERVER OFF) diff --git a/lldb/source/Host/windows/Host.cpp b/lldb/source/Host/windows/Host.cpp index 413b1720e99..64642648734 100644 --- a/lldb/source/Host/windows/Host.cpp +++ b/lldb/source/Host/windows/Host.cpp @@ -169,7 +169,23 @@ bool Host::GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &process_info) { GetProcessExecutableAndTriple(handle, process_info); // Need to read the PEB to get parent process and command line arguments. - return true; + + AutoHandle snapshot(CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)); + if (!snapshot.IsValid()) + return false; + + PROCESSENTRY32W pe; + pe.dwSize = sizeof(PROCESSENTRY32W); + if (Process32FirstW(snapshot.get(), &pe)) { + do { + if (pe.th32ProcessID == pid) { + process_info.SetParentProcessID(pe.th32ParentProcessID); + return true; + } + } while (Process32NextW(snapshot.get(), &pe)); + } + + return false; } llvm::Expected<HostThread> Host::StartMonitoringChildProcess( diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index 24a099153be..b4472037b9b 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -39,6 +39,8 @@ #if defined(__APPLE__) #define DEBUGSERVER_BASENAME "debugserver" +#elif defined(_WIN32) +#define DEBUGSERVER_BASENAME "lldb-server.exe" #else #define DEBUGSERVER_BASENAME "lldb-server" #endif diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 6bdbbd24fdb..86ce4ea254b 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -217,8 +217,13 @@ Status GDBRemoteCommunicationServerLLGS::LaunchProcess() { m_process_launch_info.GetFlags().Set(eLaunchFlagDebug); if (should_forward_stdio) { + // Temporarily relax the following for Windows until we can take advantage + // of the recently added pty support. This doesn't really affect the use of + // lldb-server on Windows. +#if !defined(_WIN32) if (llvm::Error Err = m_process_launch_info.SetUpPtyRedirection()) return Status(std::move(Err)); +#endif } { diff --git a/lldb/tools/lldb-server/lldb-gdbserver.cpp b/lldb/tools/lldb-server/lldb-gdbserver.cpp index 1bc3b0b5562..5ef7b8fd5c1 100644 --- a/lldb/tools/lldb-server/lldb-gdbserver.cpp +++ b/lldb/tools/lldb-server/lldb-gdbserver.cpp @@ -514,7 +514,7 @@ int main_gdbserver(int argc, char *argv[]) { handle_launch(gdb_server, argc, argv); // Print version info. - printf("%s-%s", LLGS_PROGRAM_NAME, LLGS_VERSION_STR); + printf("%s-%s\n", LLGS_PROGRAM_NAME, LLGS_VERSION_STR); ConnectToRemote(mainloop, gdb_server, reverse_connect, host_and_port, progname, subcommand, named_pipe_path.c_str(), diff --git a/lldb/tools/lldb-server/lldb-platform.cpp b/lldb/tools/lldb-server/lldb-platform.cpp index af78f624073..ee438da07fe 100644 --- a/lldb/tools/lldb-server/lldb-platform.cpp +++ b/lldb/tools/lldb-server/lldb-platform.cpp @@ -15,8 +15,9 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#if !defined(_WIN32) #include <sys/wait.h> - +#endif #include <fstream> #include "llvm/Support/FileSystem.h" @@ -67,6 +68,7 @@ static struct option g_long_options[] = { #define HIGH_PORT (49151u) #endif +#if !defined(_WIN32) // Watch for signals static void signal_handler(int signo) { switch (signo) { @@ -81,6 +83,7 @@ static void signal_handler(int signo) { break; } } +#endif static void display_usage(const char *progname, const char *subcommand) { fprintf(stderr, "Usage:\n %s %s [--log-file log-file-name] [--log-channels " @@ -131,8 +134,10 @@ int main_platform(int argc, char *argv[]) { const char *subcommand = argv[1]; argc--; argv++; +#if !defined(_WIN32) signal(SIGPIPE, SIG_IGN); signal(SIGHUP, signal_handler); +#endif int long_option_index = 0; Status error; std::string listen_host_port; @@ -309,8 +314,10 @@ int main_platform(int argc, char *argv[]) { printf("Connection established.\n"); if (g_server) { // Collect child zombie processes. +#if !defined(_WIN32) while (waitpid(-1, nullptr, WNOHANG) > 0) ; +#endif if (fork()) { // Parent doesn't need a connection to the lldb client delete conn; |

