diff options
Diffstat (limited to 'tools/lldb-server')
-rw-r--r-- | tools/lldb-server/LLDBServerUtilities.cpp | 2 | ||||
-rw-r--r-- | tools/lldb-server/lldb-gdbserver.cpp | 17 | ||||
-rw-r--r-- | tools/lldb-server/lldb-platform.cpp | 61 | ||||
-rw-r--r-- | tools/lldb-server/lldb-server.cpp | 4 |
4 files changed, 52 insertions, 32 deletions
diff --git a/tools/lldb-server/LLDBServerUtilities.cpp b/tools/lldb-server/LLDBServerUtilities.cpp index 095d281e9208..7f9271e36b68 100644 --- a/tools/lldb-server/LLDBServerUtilities.cpp +++ b/tools/lldb-server/LLDBServerUtilities.cpp @@ -24,7 +24,7 @@ static std::shared_ptr<raw_ostream> GetLogStream(StringRef log_file) { if (!log_file.empty()) { std::error_code EC; std::shared_ptr<raw_ostream> stream_sp = std::make_shared<raw_fd_ostream>( - log_file, EC, sys::fs::F_Text | sys::fs::F_Append); + log_file, EC, sys::fs::OF_Text | sys::fs::OF_Append); if (!EC) return stream_sp; errs() << llvm::formatv( diff --git a/tools/lldb-server/lldb-gdbserver.cpp b/tools/lldb-server/lldb-gdbserver.cpp index b479c2197bff..204c67bc470f 100644 --- a/tools/lldb-server/lldb-gdbserver.cpp +++ b/tools/lldb-server/lldb-gdbserver.cpp @@ -39,6 +39,8 @@ #include "Plugins/Process/Linux/NativeProcessLinux.h" #elif defined(__NetBSD__) #include "Plugins/Process/NetBSD/NativeProcessNetBSD.h" +#elif defined(_WIN32) +#include "Plugins/Process/Windows/Common/NativeProcessWindows.h" #endif #ifndef LLGS_PROGRAM_NAME @@ -60,6 +62,8 @@ namespace { typedef process_linux::NativeProcessLinux::Factory NativeProcessFactory; #elif defined(__NetBSD__) typedef process_netbsd::NativeProcessNetBSD::Factory NativeProcessFactory; +#elif defined(_WIN32) +typedef NativeProcessWindows::Factory NativeProcessFactory; #else // Dummy implementation to make sure the code compiles class NativeProcessFactory : public NativeProcessProtocol::Factory { @@ -104,17 +108,16 @@ static struct option g_long_options[] = { {"fd", required_argument, nullptr, 'F'}, {nullptr, 0, nullptr, 0}}; +#ifndef _WIN32 // Watch for signals static int g_sighup_received_count = 0; -#ifndef _WIN32 static void sighup_handler(MainLoopBase &mainloop) { ++g_sighup_received_count; Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); - if (log) - log->Printf("lldb-server:%s swallowing SIGHUP (receive count=%d)", - __FUNCTION__, g_sighup_received_count); + LLDB_LOGF(log, "lldb-server:%s swallowing SIGHUP (receive count=%d)", + __FUNCTION__, g_sighup_received_count); if (g_sighup_received_count >= 2) mainloop.RequestTermination(); @@ -479,9 +482,9 @@ int main_gdbserver(int argc, char *argv[]) { Log *log(lldb_private::GetLogIfAnyCategoriesSet(GDBR_LOG_PROCESS)); if (log) { - log->Printf("lldb-server launch"); + LLDB_LOGF(log, "lldb-server launch"); for (int i = 0; i < argc; i++) { - log->Printf("argv[%i] = '%s'", i, argv[i]); + LLDB_LOGF(log, "argv[%i] = '%s'", i, argv[i]); } } @@ -515,7 +518,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/tools/lldb-server/lldb-platform.cpp b/tools/lldb-server/lldb-platform.cpp index af78f624073e..a6fb5639d642 100644 --- a/tools/lldb-server/lldb-platform.cpp +++ b/tools/lldb-server/lldb-platform.cpp @@ -15,12 +15,14 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#if !defined(_WIN32) #include <sys/wait.h> - +#endif #include <fstream> #include "llvm/Support/FileSystem.h" #include "llvm/Support/FileUtilities.h" +#include "llvm/Support/raw_ostream.h" #include "Acceptor.h" #include "LLDBServerUtilities.h" @@ -67,6 +69,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 +84,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 " @@ -100,29 +104,36 @@ static Status save_socket_id_to_file(const std::string &socket_id, llvm::SmallString<64> temp_file_path; temp_file_spec.AppendPathComponent("port-file.%%%%%%"); - int FD; - auto err_code = llvm::sys::fs::createUniqueFile(temp_file_spec.GetPath(), FD, - temp_file_path); - if (err_code) - return Status("Failed to create temp file: %s", err_code.message().c_str()); - - llvm::FileRemover tmp_file_remover(temp_file_path); - - { - llvm::raw_fd_ostream temp_file(FD, true); - temp_file << socket_id; - temp_file.close(); - if (temp_file.has_error()) - return Status("Failed to write to port file."); - } - err_code = llvm::sys::fs::rename(temp_file_path, file_spec.GetPath()); - if (err_code) - return Status("Failed to rename file %s to %s: %s", temp_file_path.c_str(), - file_spec.GetPath().c_str(), err_code.message().c_str()); - - tmp_file_remover.releaseFile(); - return Status(); + Status status; + if (auto Err = + handleErrors(llvm::writeFileAtomically( + temp_file_path, temp_file_spec.GetPath(), socket_id), + [&status, &file_spec](const AtomicFileWriteError &E) { + std::string ErrorMsgBuffer; + llvm::raw_string_ostream S(ErrorMsgBuffer); + E.log(S); + + switch (E.Error) { + case atomic_write_error::failed_to_create_uniq_file: + status = Status("Failed to create temp file: %s", + ErrorMsgBuffer.c_str()); + break; + case atomic_write_error::output_stream_error: + status = Status("Failed to write to port file."); + break; + case atomic_write_error::failed_to_rename_temp_file: + status = Status("Failed to rename file %s to %s: %s", + ErrorMsgBuffer.c_str(), + file_spec.GetPath().c_str(), + ErrorMsgBuffer.c_str()); + break; + } + })) { + return Status("Failed to atomically write file %s", + file_spec.GetPath().c_str()); + } + return status; } // main @@ -131,8 +142,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 +322,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; diff --git a/tools/lldb-server/lldb-server.cpp b/tools/lldb-server/lldb-server.cpp index 690aa6277bce..ab32eefb518e 100644 --- a/tools/lldb-server/lldb-server.cpp +++ b/tools/lldb-server/lldb-server.cpp @@ -12,6 +12,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/InitLLVM.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/Signals.h" @@ -39,7 +40,7 @@ int main_platform(int argc, char *argv[]); namespace llgs { static void initialize() { if (auto e = g_debugger_lifetime->Initialize( - llvm::make_unique<SystemInitializerLLGS>(), nullptr)) + std::make_unique<SystemInitializerLLGS>(), nullptr)) llvm::consumeError(std::move(e)); } @@ -48,6 +49,7 @@ static void terminate_debugger() { g_debugger_lifetime->Terminate(); } // main int main(int argc, char *argv[]) { + llvm::InitLLVM IL(argc, argv); llvm::StringRef ToolName = argv[0]; llvm::sys::PrintStackTraceOnErrorSignal(ToolName); llvm::PrettyStackTraceProgram X(argc, argv); |