diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2020-01-17 20:45:01 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2020-01-17 20:45:01 +0000 |
commit | 706b4fc47bbc608932d3b491ae19a3b9cde9497b (patch) | |
tree | 4adf86a776049cbf7f69a1929c4babcbbef925eb /lldb/source/Host | |
parent | 7cc9cf2bf09f069cb2dd947ead05d0b54301fb71 (diff) |
Notes
Diffstat (limited to 'lldb/source/Host')
-rw-r--r-- | lldb/source/Host/common/Editline.cpp | 109 | ||||
-rw-r--r-- | lldb/source/Host/common/File.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Host/common/Host.cpp | 19 | ||||
-rw-r--r-- | lldb/source/Host/common/HostInfoBase.cpp | 95 | ||||
-rw-r--r-- | lldb/source/Host/common/MainLoop.cpp | 1 | ||||
-rw-r--r-- | lldb/source/Host/common/NativeProcessProtocol.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Host/common/PseudoTerminal.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Host/common/Socket.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Host/common/SocketAddress.cpp | 6 | ||||
-rw-r--r-- | lldb/source/Host/common/TCPSocket.cpp | 12 | ||||
-rw-r--r-- | lldb/source/Host/common/Terminal.cpp | 32 | ||||
-rw-r--r-- | lldb/source/Host/common/UDPSocket.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Host/common/XML.cpp | 59 | ||||
-rw-r--r-- | lldb/source/Host/netbsd/Host.cpp | 1 | ||||
-rw-r--r-- | lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Host/posix/FileSystemPosix.cpp (renamed from lldb/source/Host/posix/FileSystem.cpp) | 0 | ||||
-rw-r--r-- | lldb/source/Host/posix/PipePosix.cpp | 9 |
17 files changed, 212 insertions, 151 deletions
diff --git a/lldb/source/Host/common/Editline.cpp b/lldb/source/Host/common/Editline.cpp index 3e655244b107..5fd5a0cfc7fc 100644 --- a/lldb/source/Host/common/Editline.cpp +++ b/lldb/source/Host/common/Editline.cpp @@ -97,6 +97,33 @@ bool IsOnlySpaces(const EditLineStringType &content) { return true; } +static int GetOperation(HistoryOperation op) { + // The naming used by editline for the history operations is counter + // intuitive to how it's used here. + // + // - The H_PREV operation returns the previous element in the history, which + // is newer than the current one. + // + // - The H_NEXT operation returns the next element in the history, which is + // older than the current one. + // + // The naming of the enum entries match the semantic meaning. + switch(op) { + case HistoryOperation::Oldest: + return H_FIRST; + case HistoryOperation::Older: + return H_NEXT; + case HistoryOperation::Current: + return H_CURR; + case HistoryOperation::Newer: + return H_PREV; + case HistoryOperation::Newest: + return H_LAST; + } + llvm_unreachable("Fully covered switch!"); +} + + EditLineStringType CombineLines(const std::vector<EditLineStringType> &lines) { EditLineStringStreamType combined_stream; for (EditLineStringType line : lines) { @@ -423,7 +450,8 @@ StringList Editline::GetInputAsStringList(int line_count) { return lines; } -unsigned char Editline::RecallHistory(bool earlier) { +unsigned char Editline::RecallHistory(HistoryOperation op) { + assert(op == HistoryOperation::Older || op == HistoryOperation::Newer); if (!m_history_sp || !m_history_sp->IsValid()) return CC_ERROR; @@ -433,27 +461,38 @@ unsigned char Editline::RecallHistory(bool earlier) { // Treat moving from the "live" entry differently if (!m_in_history) { - if (!earlier) + switch (op) { + case HistoryOperation::Newer: return CC_ERROR; // Can't go newer than the "live" entry - if (history_w(pHistory, &history_event, H_FIRST) == -1) - return CC_ERROR; - - // Save any edits to the "live" entry in case we return by moving forward - // in history (it would be more bash-like to save over any current entry, - // but libedit doesn't offer the ability to add entries anywhere except the - // end.) - SaveEditedLine(); - m_live_history_lines = m_input_lines; - m_in_history = true; + case HistoryOperation::Older: { + if (history_w(pHistory, &history_event, + GetOperation(HistoryOperation::Newest)) == -1) + return CC_ERROR; + // Save any edits to the "live" entry in case we return by moving forward + // in history (it would be more bash-like to save over any current entry, + // but libedit doesn't offer the ability to add entries anywhere except + // the end.) + SaveEditedLine(); + m_live_history_lines = m_input_lines; + m_in_history = true; + } break; + default: + llvm_unreachable("unsupported history direction"); + } } else { - if (history_w(pHistory, &history_event, earlier ? H_PREV : H_NEXT) == -1) { - // Can't move earlier than the earliest entry - if (earlier) + if (history_w(pHistory, &history_event, GetOperation(op)) == -1) { + switch (op) { + case HistoryOperation::Older: + // Can't move earlier than the earliest entry. return CC_ERROR; - - // ... but moving to newer than the newest yields the "live" entry - new_input_lines = m_live_history_lines; - m_in_history = false; + case HistoryOperation::Newer: + // Moving to newer-than-the-newest entry yields the "live" entry. + new_input_lines = m_live_history_lines; + m_in_history = false; + break; + default: + llvm_unreachable("unsupported history direction"); + } } } @@ -468,8 +507,17 @@ unsigned char Editline::RecallHistory(bool earlier) { // Prepare to edit the last line when moving to previous entry, or the first // line when moving to next entry - SetCurrentLine(m_current_line_index = - earlier ? (int)m_input_lines.size() - 1 : 0); + switch (op) { + case HistoryOperation::Older: + m_current_line_index = (int)m_input_lines.size() - 1; + break; + case HistoryOperation::Newer: + m_current_line_index = 0; + break; + default: + llvm_unreachable("unsupported history direction"); + } + SetCurrentLine(m_current_line_index); MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingPrompt); return CC_NEWLINE; } @@ -721,7 +769,7 @@ unsigned char Editline::PreviousLineCommand(int ch) { SaveEditedLine(); if (m_current_line_index == 0) { - return RecallHistory(true); + return RecallHistory(HistoryOperation::Older); } // Start from a known location @@ -747,7 +795,7 @@ unsigned char Editline::NextLineCommand(int ch) { // Don't add an extra line if the existing last line is blank, move through // history instead if (IsOnlySpaces()) { - return RecallHistory(false); + return RecallHistory(HistoryOperation::Newer); } // Determine indentation for the new line @@ -779,13 +827,13 @@ unsigned char Editline::NextLineCommand(int ch) { unsigned char Editline::PreviousHistoryCommand(int ch) { SaveEditedLine(); - return RecallHistory(true); + return RecallHistory(HistoryOperation::Older); } unsigned char Editline::NextHistoryCommand(int ch) { SaveEditedLine(); - return RecallHistory(false); + return RecallHistory(HistoryOperation::Newer); } unsigned char Editline::FixIndentationCommand(int ch) { @@ -1105,6 +1153,15 @@ void Editline::ConfigureEditor(bool multiline) { el_set(m_editline, EL_BIND, "\t", "lldb-complete", NULL); // Bind TAB to auto complete + // Allow ctrl-left-arrow and ctrl-right-arrow for navigation, behave like + // bash in emacs mode. + el_set(m_editline, EL_BIND, ESCAPE "[1;5C", "em-next-word", NULL); + el_set(m_editline, EL_BIND, ESCAPE "[1;5D", "ed-prev-word", NULL); + el_set(m_editline, EL_BIND, ESCAPE "[5C", "em-next-word", NULL); + el_set(m_editline, EL_BIND, ESCAPE "[5D", "ed-prev-word", NULL); + el_set(m_editline, EL_BIND, ESCAPE ESCAPE "[C", "em-next-word", NULL); + el_set(m_editline, EL_BIND, ESCAPE ESCAPE "[D", "ed-prev-word", NULL); + // Allow user-specific customization prior to registering bindings we // absolutely require el_source(m_editline, nullptr); @@ -1427,7 +1484,7 @@ bool Editline::CompleteCharacter(char ch, EditLineGetCharType &out) { switch (cvt.in(state, input.begin(), input.end(), from_next, &out, &out + 1, to_next)) { case std::codecvt_base::ok: - return out != WEOF; + return out != (int)WEOF; case std::codecvt_base::error: case std::codecvt_base::noconv: diff --git a/lldb/source/Host/common/File.cpp b/lldb/source/Host/common/File.cpp index 9dae24d766f6..7850222376f7 100644 --- a/lldb/source/Host/common/File.cpp +++ b/lldb/source/Host/common/File.cpp @@ -310,7 +310,7 @@ Status NativeFile::Close() { if (m_own_stream) { if (::fclose(m_stream) == EOF) error.SetErrorToErrno(); - } else { + } else if (m_options & eOpenOptionWrite) { if (::fflush(m_stream) == EOF) error.SetErrorToErrno(); } diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp index 8e210c7e5fa5..5fbb655fc793 100644 --- a/lldb/source/Host/common/Host.cpp +++ b/lldb/source/Host/common/Host.cpp @@ -293,10 +293,21 @@ void Host::SystemLog(SystemLogType type, const char *format, va_list args) { #endif void Host::SystemLog(SystemLogType type, const char *format, ...) { - va_list args; - va_start(args, format); - SystemLog(type, format, args); - va_end(args); + { + va_list args; + va_start(args, format); + SystemLog(type, format, args); + va_end(args); + } + + Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST)); + if (log && log->GetVerbose()) { + // Log to log channel. This allows testcases to grep for log output. + va_list args; + va_start(args, format); + log->VAPrintf(format, args); + va_end(args); + } } lldb::pid_t Host::GetCurrentProcessID() { return ::getpid(); } diff --git a/lldb/source/Host/common/HostInfoBase.cpp b/lldb/source/Host/common/HostInfoBase.cpp index 3765f36fc79a..8f263e90d90f 100644 --- a/lldb/source/Host/common/HostInfoBase.cpp +++ b/lldb/source/Host/common/HostInfoBase.cpp @@ -47,18 +47,28 @@ struct HostInfoBaseFields { } } - std::string m_host_triple; + llvm::once_flag m_host_triple_once; + llvm::Triple m_host_triple; + llvm::once_flag m_host_arch_once; ArchSpec m_host_arch_32; ArchSpec m_host_arch_64; + llvm::once_flag m_lldb_so_dir_once; FileSpec m_lldb_so_dir; + llvm::once_flag m_lldb_support_exe_dir_once; FileSpec m_lldb_support_exe_dir; + llvm::once_flag m_lldb_headers_dir_once; FileSpec m_lldb_headers_dir; + llvm::once_flag m_lldb_clang_resource_dir_once; FileSpec m_lldb_clang_resource_dir; + llvm::once_flag m_lldb_system_plugin_dir_once; FileSpec m_lldb_system_plugin_dir; + llvm::once_flag m_lldb_user_plugin_dir_once; FileSpec m_lldb_user_plugin_dir; + llvm::once_flag m_lldb_process_tmp_dir_once; FileSpec m_lldb_process_tmp_dir; + llvm::once_flag m_lldb_global_tmp_dir_once; FileSpec m_lldb_global_tmp_dir; }; @@ -72,18 +82,16 @@ void HostInfoBase::Terminate() { g_fields = nullptr; } -llvm::StringRef HostInfoBase::GetTargetTriple() { - static llvm::once_flag g_once_flag; - llvm::call_once(g_once_flag, []() { +llvm::Triple HostInfoBase::GetTargetTriple() { + llvm::call_once(g_fields->m_host_triple_once, []() { g_fields->m_host_triple = - HostInfo::GetArchitecture().GetTriple().getTriple(); + HostInfo::GetArchitecture().GetTriple(); }); return g_fields->m_host_triple; } const ArchSpec &HostInfoBase::GetArchitecture(ArchitectureKind arch_kind) { - static llvm::once_flag g_once_flag; - llvm::call_once(g_once_flag, []() { + llvm::call_once(g_fields->m_host_arch_once, []() { HostInfo::ComputeHostArchitectureSupport(g_fields->m_host_arch_32, g_fields->m_host_arch_64); }); @@ -108,87 +116,76 @@ llvm::Optional<HostInfoBase::ArchitectureKind> HostInfoBase::ParseArchitectureKi } FileSpec HostInfoBase::GetShlibDir() { - static llvm::once_flag g_once_flag; - static bool success = false; - llvm::call_once(g_once_flag, []() { - success = HostInfo::ComputeSharedLibraryDirectory(g_fields->m_lldb_so_dir); + llvm::call_once(g_fields->m_lldb_so_dir_once, []() { + if (!HostInfo::ComputeSharedLibraryDirectory(g_fields->m_lldb_so_dir)) + g_fields->m_lldb_so_dir = FileSpec(); Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); LLDB_LOG(log, "shlib dir -> `{0}`", g_fields->m_lldb_so_dir); }); - return success ? g_fields->m_lldb_so_dir : FileSpec(); + return g_fields->m_lldb_so_dir; } FileSpec HostInfoBase::GetSupportExeDir() { - static llvm::once_flag g_once_flag; - static bool success = false; - llvm::call_once(g_once_flag, []() { - success = - HostInfo::ComputeSupportExeDirectory(g_fields->m_lldb_support_exe_dir); + llvm::call_once(g_fields->m_lldb_support_exe_dir_once, []() { + if (!HostInfo::ComputeSupportExeDirectory(g_fields->m_lldb_support_exe_dir)) + g_fields->m_lldb_support_exe_dir = FileSpec(); Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); LLDB_LOG(log, "support exe dir -> `{0}`", g_fields->m_lldb_support_exe_dir); }); - return success ? g_fields->m_lldb_support_exe_dir : FileSpec(); + return g_fields->m_lldb_support_exe_dir; } FileSpec HostInfoBase::GetHeaderDir() { - static llvm::once_flag g_once_flag; - static bool success = false; - llvm::call_once(g_once_flag, []() { - success = HostInfo::ComputeHeaderDirectory(g_fields->m_lldb_headers_dir); + llvm::call_once(g_fields->m_lldb_headers_dir_once, []() { + if (!HostInfo::ComputeHeaderDirectory(g_fields->m_lldb_headers_dir)) + g_fields->m_lldb_headers_dir = FileSpec(); Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); LLDB_LOG(log, "header dir -> `{0}`", g_fields->m_lldb_headers_dir); }); - return success ? g_fields->m_lldb_headers_dir : FileSpec(); + return g_fields->m_lldb_headers_dir; } FileSpec HostInfoBase::GetSystemPluginDir() { - static llvm::once_flag g_once_flag; - static bool success = false; - llvm::call_once(g_once_flag, []() { - success = HostInfo::ComputeSystemPluginsDirectory( - g_fields->m_lldb_system_plugin_dir); + llvm::call_once(g_fields->m_lldb_system_plugin_dir_once, []() { + if (!HostInfo::ComputeSystemPluginsDirectory(g_fields->m_lldb_system_plugin_dir)) + g_fields->m_lldb_system_plugin_dir = FileSpec(); Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); LLDB_LOG(log, "system plugin dir -> `{0}`", g_fields->m_lldb_system_plugin_dir); }); - return success ? g_fields->m_lldb_system_plugin_dir : FileSpec(); + return g_fields->m_lldb_system_plugin_dir; } FileSpec HostInfoBase::GetUserPluginDir() { - static llvm::once_flag g_once_flag; - static bool success = false; - llvm::call_once(g_once_flag, []() { - success = - HostInfo::ComputeUserPluginsDirectory(g_fields->m_lldb_user_plugin_dir); + llvm::call_once(g_fields->m_lldb_user_plugin_dir_once, []() { + if (!HostInfo::ComputeUserPluginsDirectory(g_fields->m_lldb_user_plugin_dir)) + g_fields->m_lldb_user_plugin_dir = FileSpec(); Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); LLDB_LOG(log, "user plugin dir -> `{0}`", g_fields->m_lldb_user_plugin_dir); }); - return success ? g_fields->m_lldb_user_plugin_dir : FileSpec(); + return g_fields->m_lldb_user_plugin_dir; } FileSpec HostInfoBase::GetProcessTempDir() { - static llvm::once_flag g_once_flag; - static bool success = false; - llvm::call_once(g_once_flag, []() { - success = HostInfo::ComputeProcessTempFileDirectory( - g_fields->m_lldb_process_tmp_dir); + llvm::call_once(g_fields->m_lldb_process_tmp_dir_once, []() { + if (!HostInfo::ComputeProcessTempFileDirectory( g_fields->m_lldb_process_tmp_dir)) + g_fields->m_lldb_process_tmp_dir = FileSpec(); Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); LLDB_LOG(log, "process temp dir -> `{0}`", g_fields->m_lldb_process_tmp_dir); }); - return success ? g_fields->m_lldb_process_tmp_dir : FileSpec(); + return g_fields->m_lldb_process_tmp_dir; } FileSpec HostInfoBase::GetGlobalTempDir() { - static llvm::once_flag g_once_flag; - static bool success = false; - llvm::call_once(g_once_flag, []() { - success = HostInfo::ComputeGlobalTempFileDirectory( - g_fields->m_lldb_global_tmp_dir); + llvm::call_once(g_fields->m_lldb_global_tmp_dir_once, []() { + if (!HostInfo::ComputeGlobalTempFileDirectory( g_fields->m_lldb_global_tmp_dir)) + g_fields->m_lldb_global_tmp_dir = FileSpec(); + Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); LLDB_LOG(log, "global temp dir -> `{0}`", g_fields->m_lldb_global_tmp_dir); }); - return success ? g_fields->m_lldb_global_tmp_dir : FileSpec(); + return g_fields->m_lldb_global_tmp_dir; } ArchSpec HostInfoBase::GetAugmentedArchSpec(llvm::StringRef triple) { @@ -249,8 +246,8 @@ bool HostInfoBase::ComputeSharedLibraryDirectory(FileSpec &file_spec) { // On other posix systems, we will get .../lib(64|32)?/liblldb.so. FileSpec lldb_file_spec(Host::GetModuleFileSpecForHostAddress( - reinterpret_cast<void *>(reinterpret_cast<intptr_t>( - HostInfoBase::ComputeSharedLibraryDirectory)))); + reinterpret_cast<void *>( + HostInfoBase::ComputeSharedLibraryDirectory))); // This is necessary because when running the testsuite the shlib might be a // symbolic link inside the Python resource dir. diff --git a/lldb/source/Host/common/MainLoop.cpp b/lldb/source/Host/common/MainLoop.cpp index 6f774451c8a4..240320f83242 100644 --- a/lldb/source/Host/common/MainLoop.cpp +++ b/lldb/source/Host/common/MainLoop.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Config/llvm-config.h" +#include "lldb/Host/Config.h" #include "lldb/Host/MainLoop.h" #include "lldb/Host/PosixApi.h" diff --git a/lldb/source/Host/common/NativeProcessProtocol.cpp b/lldb/source/Host/common/NativeProcessProtocol.cpp index fd349cc2915b..712c448dc2c1 100644 --- a/lldb/source/Host/common/NativeProcessProtocol.cpp +++ b/lldb/source/Host/common/NativeProcessProtocol.cpp @@ -682,7 +682,7 @@ NativeProcessProtocol::ReadCStringFromMemory(lldb::addr_t addr, char *buffer, addr_t cache_line_bytes_left = cache_line_size - (curr_addr % cache_line_size); addr_t bytes_to_read = std::min<addr_t>(bytes_left, cache_line_bytes_left); - status = ReadMemory(curr_addr, reinterpret_cast<void *>(curr_buffer), + status = ReadMemory(curr_addr, static_cast<void *>(curr_buffer), bytes_to_read, bytes_read); if (bytes_read == 0) @@ -691,7 +691,7 @@ NativeProcessProtocol::ReadCStringFromMemory(lldb::addr_t addr, char *buffer, void *str_end = std::memchr(curr_buffer, '\0', bytes_read); if (str_end != nullptr) { total_bytes_read = - (size_t)(reinterpret_cast<char *>(str_end) - buffer + 1); + static_cast<size_t>((static_cast<char *>(str_end) - buffer + 1)); status.Clear(); break; } diff --git a/lldb/source/Host/common/PseudoTerminal.cpp b/lldb/source/Host/common/PseudoTerminal.cpp index 85e54f4d3d6a..85828283e210 100644 --- a/lldb/source/Host/common/PseudoTerminal.cpp +++ b/lldb/source/Host/common/PseudoTerminal.cpp @@ -79,7 +79,7 @@ bool PseudoTerminal::OpenFirstAvailableMaster(int oflag, char *error_str, if (error_str) error_str[0] = '\0'; -#if !defined(LLDB_DISABLE_POSIX) +#if LLDB_ENABLE_POSIX // Open the master side of a pseudo terminal m_master_fd = ::posix_openpt(oflag); if (m_master_fd < 0) { @@ -193,7 +193,7 @@ lldb::pid_t PseudoTerminal::Fork(char *error_str, size_t error_len) { if (error_str) error_str[0] = '\0'; pid_t pid = LLDB_INVALID_PROCESS_ID; -#if !defined(LLDB_DISABLE_POSIX) +#if LLDB_ENABLE_POSIX int flags = O_RDWR; flags |= O_CLOEXEC; if (OpenFirstAvailableMaster(flags, error_str, error_len)) { diff --git a/lldb/source/Host/common/Socket.cpp b/lldb/source/Host/common/Socket.cpp index 6358ab8a8e77..7fba1daff75f 100644 --- a/lldb/source/Host/common/Socket.cpp +++ b/lldb/source/Host/common/Socket.cpp @@ -22,7 +22,7 @@ #include "llvm/Support/Error.h" #include "llvm/Support/WindowsError.h" -#ifndef LLDB_DISABLE_POSIX +#if LLDB_ENABLE_POSIX #include "lldb/Host/posix/DomainSocket.h" #include <arpa/inet.h> @@ -122,7 +122,7 @@ std::unique_ptr<Socket> Socket::Create(const SocketProtocol protocol, std::make_unique<UDPSocket>(true, child_processes_inherit); break; case ProtocolUnixDomain: -#ifndef LLDB_DISABLE_POSIX +#if LLDB_ENABLE_POSIX socket_up = std::make_unique<DomainSocket>(true, child_processes_inherit); #else diff --git a/lldb/source/Host/common/SocketAddress.cpp b/lldb/source/Host/common/SocketAddress.cpp index 882fd24558f7..960ed18dc768 100644 --- a/lldb/source/Host/common/SocketAddress.cpp +++ b/lldb/source/Host/common/SocketAddress.cpp @@ -174,12 +174,6 @@ bool SocketAddress::SetPort(uint16_t port) { } // SocketAddress assignment operator -const SocketAddress &SocketAddress::operator=(const SocketAddress &rhs) { - if (this != &rhs) - m_socket_addr = rhs.m_socket_addr; - return *this; -} - const SocketAddress &SocketAddress:: operator=(const struct addrinfo *addr_info) { Clear(); diff --git a/lldb/source/Host/common/TCPSocket.cpp b/lldb/source/Host/common/TCPSocket.cpp index e84054f3f581..b716935db6e6 100644 --- a/lldb/source/Host/common/TCPSocket.cpp +++ b/lldb/source/Host/common/TCPSocket.cpp @@ -20,7 +20,7 @@ #include "llvm/Support/Errno.h" #include "llvm/Support/raw_ostream.h" -#ifndef LLDB_DISABLE_POSIX +#if LLDB_ENABLE_POSIX #include <arpa/inet.h> #include <netinet/tcp.h> #include <sys/socket.h> @@ -149,9 +149,9 @@ Status TCPSocket::Connect(llvm::StringRef name) { if (!DecodeHostAndPort(name, host_str, port_str, port, &error)) return error; - auto addresses = lldb_private::SocketAddress::GetAddressInfo( + std::vector<SocketAddress> addresses = SocketAddress::GetAddressInfo( host_str.c_str(), nullptr, AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP); - for (auto address : addresses) { + for (SocketAddress &address : addresses) { error = CreateSocket(address.GetFamily()); if (error.Fail()) continue; @@ -187,9 +187,9 @@ Status TCPSocket::Listen(llvm::StringRef name, int backlog) { if (host_str == "*") host_str = "0.0.0.0"; - auto addresses = lldb_private::SocketAddress::GetAddressInfo( + std::vector<SocketAddress> addresses = SocketAddress::GetAddressInfo( host_str.c_str(), nullptr, AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP); - for (auto address : addresses) { + for (SocketAddress &address : addresses) { int fd = Socket::CreateSocket(address.GetFamily(), kType, IPPROTO_TCP, m_child_processes_inherit, error); if (error.Fail()) { @@ -273,7 +273,7 @@ Status TCPSocket::Accept(Socket *&conn_socket) { // Loop until we are happy with our connection while (!accept_connection) { accept_loop.Run(); - + if (error.Fail()) return error; diff --git a/lldb/source/Host/common/Terminal.cpp b/lldb/source/Host/common/Terminal.cpp index 4b536b03d852..e1aea26eeb90 100644 --- a/lldb/source/Host/common/Terminal.cpp +++ b/lldb/source/Host/common/Terminal.cpp @@ -15,7 +15,7 @@ #include <fcntl.h> #include <signal.h> -#ifdef LLDB_CONFIG_TERMIOS_SUPPORTED +#if LLDB_ENABLE_TERMIOS #include <termios.h> #endif @@ -25,7 +25,7 @@ bool Terminal::IsATerminal() const { return m_fd >= 0 && ::isatty(m_fd); } bool Terminal::SetEcho(bool enabled) { if (FileDescriptorIsValid()) { -#ifdef LLDB_CONFIG_TERMIOS_SUPPORTED +#if LLDB_ENABLE_TERMIOS if (IsATerminal()) { struct termios fd_termios; if (::tcgetattr(m_fd, &fd_termios) == 0) { @@ -47,14 +47,14 @@ bool Terminal::SetEcho(bool enabled) { return ::tcsetattr(m_fd, TCSANOW, &fd_termios) == 0; } } -#endif // #ifdef LLDB_CONFIG_TERMIOS_SUPPORTED +#endif // #if LLDB_ENABLE_TERMIOS } return false; } bool Terminal::SetCanonical(bool enabled) { if (FileDescriptorIsValid()) { -#ifdef LLDB_CONFIG_TERMIOS_SUPPORTED +#if LLDB_ENABLE_TERMIOS if (IsATerminal()) { struct termios fd_termios; if (::tcgetattr(m_fd, &fd_termios) == 0) { @@ -76,7 +76,7 @@ bool Terminal::SetCanonical(bool enabled) { return ::tcsetattr(m_fd, TCSANOW, &fd_termios) == 0; } } -#endif // #ifdef LLDB_CONFIG_TERMIOS_SUPPORTED +#endif // #if LLDB_ENABLE_TERMIOS } return false; } @@ -84,7 +84,7 @@ bool Terminal::SetCanonical(bool enabled) { // Default constructor TerminalState::TerminalState() : m_tty(), m_tflags(-1), -#ifdef LLDB_CONFIG_TERMIOS_SUPPORTED +#if LLDB_ENABLE_TERMIOS m_termios_up(), #endif m_process_group(-1) { @@ -96,7 +96,7 @@ TerminalState::~TerminalState() {} void TerminalState::Clear() { m_tty.Clear(); m_tflags = -1; -#ifdef LLDB_CONFIG_TERMIOS_SUPPORTED +#if LLDB_ENABLE_TERMIOS m_termios_up.reset(); #endif m_process_group = -1; @@ -108,17 +108,17 @@ void TerminalState::Clear() { bool TerminalState::Save(int fd, bool save_process_group) { m_tty.SetFileDescriptor(fd); if (m_tty.IsATerminal()) { -#ifndef LLDB_DISABLE_POSIX +#if LLDB_ENABLE_POSIX m_tflags = ::fcntl(fd, F_GETFL, 0); #endif -#ifdef LLDB_CONFIG_TERMIOS_SUPPORTED +#if LLDB_ENABLE_TERMIOS if (m_termios_up == nullptr) m_termios_up.reset(new struct termios); int err = ::tcgetattr(fd, m_termios_up.get()); if (err != 0) m_termios_up.reset(); -#endif // #ifdef LLDB_CONFIG_TERMIOS_SUPPORTED -#ifndef LLDB_DISABLE_POSIX +#endif // #if LLDB_ENABLE_TERMIOS +#if LLDB_ENABLE_POSIX if (save_process_group) m_process_group = ::tcgetpgrp(0); else @@ -127,7 +127,7 @@ bool TerminalState::Save(int fd, bool save_process_group) { } else { m_tty.Clear(); m_tflags = -1; -#ifdef LLDB_CONFIG_TERMIOS_SUPPORTED +#if LLDB_ENABLE_TERMIOS m_termios_up.reset(); #endif m_process_group = -1; @@ -138,16 +138,16 @@ bool TerminalState::Save(int fd, bool save_process_group) { // Restore the state of the TTY using the cached values from a previous call to // Save(). bool TerminalState::Restore() const { -#ifndef LLDB_DISABLE_POSIX +#if LLDB_ENABLE_POSIX if (IsValid()) { const int fd = m_tty.GetFileDescriptor(); if (TFlagsIsValid()) fcntl(fd, F_SETFL, m_tflags); -#ifdef LLDB_CONFIG_TERMIOS_SUPPORTED +#if LLDB_ENABLE_TERMIOS if (TTYStateIsValid()) tcsetattr(fd, TCSANOW, m_termios_up.get()); -#endif // #ifdef LLDB_CONFIG_TERMIOS_SUPPORTED +#endif // #if LLDB_ENABLE_TERMIOS if (ProcessGroupIsValid()) { // Save the original signal handler. @@ -176,7 +176,7 @@ bool TerminalState::TFlagsIsValid() const { return m_tflags != -1; } // Returns true if m_ttystate is valid bool TerminalState::TTYStateIsValid() const { -#ifdef LLDB_CONFIG_TERMIOS_SUPPORTED +#if LLDB_ENABLE_TERMIOS return m_termios_up != nullptr; #else return false; diff --git a/lldb/source/Host/common/UDPSocket.cpp b/lldb/source/Host/common/UDPSocket.cpp index 7accbb651ba9..0a991c33645b 100644 --- a/lldb/source/Host/common/UDPSocket.cpp +++ b/lldb/source/Host/common/UDPSocket.cpp @@ -11,7 +11,7 @@ #include "lldb/Host/Config.h" #include "lldb/Utility/Log.h" -#ifndef LLDB_DISABLE_POSIX +#if LLDB_ENABLE_POSIX #include <arpa/inet.h> #include <sys/socket.h> #endif diff --git a/lldb/source/Host/common/XML.cpp b/lldb/source/Host/common/XML.cpp index cb23ac17ef53..28d1f5a8eaf4 100644 --- a/lldb/source/Host/common/XML.cpp +++ b/lldb/source/Host/common/XML.cpp @@ -8,6 +8,7 @@ #include <stdlib.h> /* atof */ +#include "lldb/Host/Config.h" #include "lldb/Host/StringConvert.h" #include "lldb/Host/XML.h" @@ -21,7 +22,7 @@ XMLDocument::XMLDocument() : m_document(nullptr) {} XMLDocument::~XMLDocument() { Clear(); } void XMLDocument::Clear() { -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 if (m_document) { xmlDocPtr doc = m_document; m_document = nullptr; @@ -42,7 +43,7 @@ void XMLDocument::ErrorCallback(void *ctx, const char *format, ...) { } bool XMLDocument::ParseFile(const char *path) { -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 Clear(); xmlSetGenericErrorFunc((void *)this, XMLDocument::ErrorCallback); m_document = xmlParseFile(path); @@ -53,7 +54,7 @@ bool XMLDocument::ParseFile(const char *path) { bool XMLDocument::ParseMemory(const char *xml, size_t xml_length, const char *url) { -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 Clear(); xmlSetGenericErrorFunc((void *)this, XMLDocument::ErrorCallback); m_document = xmlReadMemory(xml, (int)xml_length, url, nullptr, 0); @@ -63,7 +64,7 @@ bool XMLDocument::ParseMemory(const char *xml, size_t xml_length, } XMLNode XMLDocument::GetRootElement(const char *required_name) { -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) { XMLNode root_node(xmlDocGetRootElement(m_document)); if (required_name) { @@ -81,7 +82,7 @@ XMLNode XMLDocument::GetRootElement(const char *required_name) { llvm::StringRef XMLDocument::GetErrors() const { return m_errors.GetString(); } bool XMLDocument::XMLEnabled() { -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 return true; #else return false; @@ -99,7 +100,7 @@ XMLNode::~XMLNode() {} void XMLNode::Clear() { m_node = nullptr; } XMLNode XMLNode::GetParent() const { -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) return XMLNode(m_node->parent); else @@ -110,7 +111,7 @@ XMLNode XMLNode::GetParent() const { } XMLNode XMLNode::GetSibling() const { -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) return XMLNode(m_node->next); else @@ -121,7 +122,7 @@ XMLNode XMLNode::GetSibling() const { } XMLNode XMLNode::GetChild() const { -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) return XMLNode(m_node->children); @@ -135,7 +136,7 @@ XMLNode XMLNode::GetChild() const { llvm::StringRef XMLNode::GetAttributeValue(const char *name, const char *fail_value) const { const char *attr_value = nullptr; -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) attr_value = (const char *)xmlGetProp(m_node, (const xmlChar *)name); @@ -152,7 +153,7 @@ llvm::StringRef XMLNode::GetAttributeValue(const char *name, bool XMLNode::GetAttributeValueAsUnsigned(const char *name, uint64_t &value, uint64_t fail_value, int base) const { -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 llvm::StringRef str_value = GetAttributeValue(name, ""); #else llvm::StringRef str_value; @@ -163,14 +164,14 @@ bool XMLNode::GetAttributeValueAsUnsigned(const char *name, uint64_t &value, } void XMLNode::ForEachChildNode(NodeCallback const &callback) const { -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) GetChild().ForEachSiblingNode(callback); #endif } void XMLNode::ForEachChildElement(NodeCallback const &callback) const { -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 XMLNode child = GetChild(); if (child) child.ForEachSiblingElement(callback); @@ -179,7 +180,7 @@ void XMLNode::ForEachChildElement(NodeCallback const &callback) const { void XMLNode::ForEachChildElementWithName(const char *name, NodeCallback const &callback) const { -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 XMLNode child = GetChild(); if (child) child.ForEachSiblingElementWithName(name, callback); @@ -187,7 +188,7 @@ void XMLNode::ForEachChildElementWithName(const char *name, } void XMLNode::ForEachAttribute(AttributeCallback const &callback) const { -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) { for (xmlAttrPtr attr = m_node->properties; attr != nullptr; @@ -210,7 +211,7 @@ void XMLNode::ForEachAttribute(AttributeCallback const &callback) const { } void XMLNode::ForEachSiblingNode(NodeCallback const &callback) const { -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) { // iterate through all siblings @@ -223,7 +224,7 @@ void XMLNode::ForEachSiblingNode(NodeCallback const &callback) const { } void XMLNode::ForEachSiblingElement(NodeCallback const &callback) const { -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) { // iterate through all siblings @@ -241,7 +242,7 @@ void XMLNode::ForEachSiblingElement(NodeCallback const &callback) const { void XMLNode::ForEachSiblingElementWithName( const char *name, NodeCallback const &callback) const { -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) { // iterate through all siblings @@ -269,7 +270,7 @@ void XMLNode::ForEachSiblingElementWithName( } llvm::StringRef XMLNode::GetName() const { -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) { if (m_node->name) return llvm::StringRef((const char *)m_node->name); @@ -280,7 +281,7 @@ llvm::StringRef XMLNode::GetName() const { bool XMLNode::GetElementText(std::string &text) const { text.clear(); -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) { bool success = false; if (m_node->type == XML_ELEMENT_NODE) { @@ -302,7 +303,7 @@ bool XMLNode::GetElementText(std::string &text) const { bool XMLNode::GetElementTextAsUnsigned(uint64_t &value, uint64_t fail_value, int base) const { bool success = false; -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) { std::string text; if (GetElementText(text)) @@ -316,7 +317,7 @@ bool XMLNode::GetElementTextAsUnsigned(uint64_t &value, uint64_t fail_value, bool XMLNode::GetElementTextAsFloat(double &value, double fail_value) const { bool success = false; -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) { std::string text; if (GetElementText(text)) { @@ -331,7 +332,7 @@ bool XMLNode::GetElementTextAsFloat(double &value, double fail_value) const { } bool XMLNode::NameIs(const char *name) const { -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) { // In case we are looking for a nullptr name or an exact pointer match @@ -347,7 +348,7 @@ bool XMLNode::NameIs(const char *name) const { XMLNode XMLNode::FindFirstChildElementWithName(const char *name) const { XMLNode result_node; -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 ForEachChildElementWithName( name, [&result_node](const XMLNode &node) -> bool { result_node = node; @@ -362,7 +363,7 @@ XMLNode XMLNode::FindFirstChildElementWithName(const char *name) const { bool XMLNode::IsValid() const { return m_node != nullptr; } bool XMLNode::IsElement() const { -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) return m_node->type == XML_ELEMENT_NODE; #endif @@ -370,7 +371,7 @@ bool XMLNode::IsElement() const { } XMLNode XMLNode::GetElementForPath(const NamePath &path) { -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) { if (path.empty()) @@ -430,7 +431,7 @@ bool ApplePropertyList::GetValueAsString(const char *key, XMLNode ApplePropertyList::GetValueNode(const char *key) const { XMLNode value_node; -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) { m_dict_node.ForEachChildElementWithName( @@ -454,7 +455,7 @@ XMLNode ApplePropertyList::GetValueNode(const char *key) const { bool ApplePropertyList::ExtractStringFromValueNode(const XMLNode &node, std::string &value) { value.clear(); -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 if (node.IsValid()) { llvm::StringRef element_name = node.GetName(); if (element_name == "true" || element_name == "false") { @@ -470,7 +471,7 @@ bool ApplePropertyList::ExtractStringFromValueNode(const XMLNode &node, return false; } -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 namespace { @@ -532,7 +533,7 @@ StructuredData::ObjectSP CreatePlistValue(XMLNode node) { StructuredData::ObjectSP ApplePropertyList::GetStructuredData() { StructuredData::ObjectSP root_sp; -#if defined(LIBXML2_DEFINED) +#if LLDB_ENABLE_LIBXML2 if (IsValid()) { return CreatePlistValue(m_dict_node); } diff --git a/lldb/source/Host/netbsd/Host.cpp b/lldb/source/Host/netbsd/Host.cpp index 08fec099bf49..20f3db3c22c1 100644 --- a/lldb/source/Host/netbsd/Host.cpp +++ b/lldb/source/Host/netbsd/Host.cpp @@ -78,6 +78,7 @@ static bool GetNetBSDProcessArgs(const ProcessInstanceInfoMatch *match_info_ptr, match_info_ptr->GetProcessInfo().GetName()))) return false; + process_info.SetArg0(cstr); Args &proc_args = process_info.GetArguments(); while (1) { const uint8_t *p = data.PeekData(offset, 1); diff --git a/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp b/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp index 325d854921e3..2223e1625b19 100644 --- a/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp +++ b/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp @@ -26,7 +26,7 @@ #include <string.h> #include <sys/types.h> -#ifndef LLDB_DISABLE_POSIX +#if LLDB_ENABLE_POSIX #include <termios.h> #include <unistd.h> #endif @@ -179,7 +179,7 @@ ConnectionStatus ConnectionFileDescriptor::Connect(llvm::StringRef path, // unix-abstract-connect://SOCKNAME return UnixAbstractSocketConnect(*addr, error_ptr); } -#ifndef LLDB_DISABLE_POSIX +#if LLDB_ENABLE_POSIX else if ((addr = GetURLAddress(path, FD_SCHEME))) { // Just passing a native file descriptor within this current process that // is already opened (possibly from a service or other source). diff --git a/lldb/source/Host/posix/FileSystem.cpp b/lldb/source/Host/posix/FileSystemPosix.cpp index 32fae68abb4d..32fae68abb4d 100644 --- a/lldb/source/Host/posix/FileSystem.cpp +++ b/lldb/source/Host/posix/FileSystemPosix.cpp diff --git a/lldb/source/Host/posix/PipePosix.cpp b/lldb/source/Host/posix/PipePosix.cpp index efdc151e3763..ce1baf3f12a3 100644 --- a/lldb/source/Host/posix/PipePosix.cpp +++ b/lldb/source/Host/posix/PipePosix.cpp @@ -270,8 +270,8 @@ Status PipePosix::ReadWithTimeout(void *buf, size_t size, while (error.Success()) { error = select_helper.Select(); if (error.Success()) { - auto result = ::read(fd, reinterpret_cast<char *>(buf) + bytes_read, - size - bytes_read); + auto result = + ::read(fd, static_cast<char *>(buf) + bytes_read, size - bytes_read); if (result != -1) { bytes_read += result; if (bytes_read == size || result == 0) @@ -301,9 +301,8 @@ Status PipePosix::Write(const void *buf, size_t size, size_t &bytes_written) { while (error.Success()) { error = select_helper.Select(); if (error.Success()) { - auto result = - ::write(fd, reinterpret_cast<const char *>(buf) + bytes_written, - size - bytes_written); + auto result = ::write(fd, static_cast<const char *>(buf) + bytes_written, + size - bytes_written); if (result != -1) { bytes_written += result; if (bytes_written == size) |