Index: lldb/trunk/include/lldb/Host/Host.h =================================================================== --- lldb/trunk/include/lldb/Host/Host.h +++ lldb/trunk/include/lldb/Host/Host.h @@ -238,10 +238,6 @@ uint32_t timeout_sec, bool run_in_default_shell = true); - static lldb::DataBufferSP GetAuxvData(lldb_private::Process *process); - - static lldb::DataBufferSP GetAuxvData(lldb::pid_t pid); - static bool OpenFileInExternalEditor(const FileSpec &file_spec, uint32_t line_no); Index: lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h =================================================================== --- lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h +++ lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h @@ -10,9 +10,6 @@ #ifndef liblldb_NativeProcessProtocol_h_ #define liblldb_NativeProcessProtocol_h_ -#include -#include - #include "lldb/Host/MainLoop.h" #include "lldb/Utility/Error.h" #include "lldb/lldb-private-forward.h" @@ -20,6 +17,8 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/MemoryBuffer.h" +#include #include "NativeBreakpointList.h" #include "NativeWatchpointList.h" @@ -152,6 +151,9 @@ bool GetByteOrder(lldb::ByteOrder &byte_order) const; + virtual llvm::ErrorOr> + GetAuxvData() const = 0; + //---------------------------------------------------------------------- // Exit Status //---------------------------------------------------------------------- Index: lldb/trunk/source/Host/CMakeLists.txt =================================================================== --- lldb/trunk/source/Host/CMakeLists.txt +++ lldb/trunk/source/Host/CMakeLists.txt @@ -122,7 +122,6 @@ linux/LibcGlue.cpp linux/Support.cpp ) - list(APPEND LLDB_PLUGINS lldbPluginProcessLinux) if (CMAKE_SYSTEM_NAME MATCHES "Android") add_host_subdirectory(android android/HostInfoAndroid.cpp Index: lldb/trunk/source/Host/freebsd/Host.cpp =================================================================== --- lldb/trunk/source/Host/freebsd/Host.cpp +++ lldb/trunk/source/Host/freebsd/Host.cpp @@ -243,23 +243,6 @@ return false; } -lldb::DataBufferSP Host::GetAuxvData(lldb_private::Process *process) { - int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_AUXV, 0}; - size_t auxv_size = AT_COUNT * sizeof(Elf_Auxinfo); - DataBufferSP buf_sp; - - std::unique_ptr buf_ap(new DataBufferHeap(auxv_size, 0)); - - mib[3] = process->GetID(); - if (::sysctl(mib, 4, buf_ap->GetBytes(), &auxv_size, NULL, 0) == 0) { - buf_sp.reset(buf_ap.release()); - } else { - perror("sysctl failed on auxv"); - } - - return buf_sp; -} - Error Host::ShellExpandArguments(ProcessLaunchInfo &launch_info) { return Error("unimplemented"); } Index: lldb/trunk/source/Host/linux/Host.cpp =================================================================== --- lldb/trunk/source/Host/linux/Host.cpp +++ lldb/trunk/source/Host/linux/Host.cpp @@ -31,7 +31,6 @@ #include "lldb/Utility/DataBufferHeap.h" #include "lldb/Utility/DataExtractor.h" -#include "Plugins/Process/Linux/ProcFileReader.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Symbol/ObjectFile.h" @@ -115,15 +114,6 @@ return true; } -lldb::DataBufferSP Host::GetAuxvData(lldb_private::Process *process) { - return process_linux::ProcFileReader::ReadIntoDataBuffer(process->GetID(), - "auxv"); -} - -lldb::DataBufferSP Host::GetAuxvData(lldb::pid_t pid) { - return process_linux::ProcFileReader::ReadIntoDataBuffer(pid, "auxv"); -} - static bool IsDirNumeric(const char *dname) { for (; *dname; dname++) { if (!isdigit(*dname)) Index: lldb/trunk/source/Host/macosx/Host.mm =================================================================== --- lldb/trunk/source/Host/macosx/Host.mm +++ lldb/trunk/source/Host/macosx/Host.mm @@ -1448,7 +1448,3 @@ ::asl_vlog(NULL, g_aslmsg, asl_level, format, args); } } - -lldb::DataBufferSP Host::GetAuxvData(lldb_private::Process *process) { - return lldb::DataBufferSP(); -} Index: lldb/trunk/source/Host/netbsd/Host.cpp =================================================================== --- lldb/trunk/source/Host/netbsd/Host.cpp +++ lldb/trunk/source/Host/netbsd/Host.cpp @@ -259,10 +259,6 @@ return false; } -lldb::DataBufferSP Host::GetAuxvData(lldb_private::Process *process) { - return lldb::DataBufferSP(); -} - Error Host::ShellExpandArguments(ProcessLaunchInfo &launch_info) { return Error("unimplemented"); } Index: lldb/trunk/source/Host/windows/Host.cpp =================================================================== --- lldb/trunk/source/Host/windows/Host.cpp +++ lldb/trunk/source/Host/windows/Host.cpp @@ -97,10 +97,6 @@ } } -lldb::DataBufferSP Host::GetAuxvData(lldb_private::Process *process) { - return 0; -} - lldb::thread_t Host::GetCurrentThread() { return lldb::thread_t(::GetCurrentThread()); } Index: lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp =================================================================== --- lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp +++ lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp @@ -10,6 +10,12 @@ // C Includes #include +#include +#include +#include +#include +#include +#include // C++ Includes #include @@ -904,15 +910,18 @@ const DataBufferSP ProcessFreeBSD::GetAuxvData() { // If we're the local platform, we can ask the host for auxv data. PlatformSP platform_sp = GetTarget().GetPlatform(); - if (platform_sp && platform_sp->IsHost()) - return lldb_private::Host::GetAuxvData(this); + assert(platform_sp && platform_sp->IsHost()); - // Somewhat unexpected - the process is not running locally or we don't have a - // platform. - assert( - false && - "no platform or not the host - how did we get here with ProcessFreeBSD?"); - return DataBufferSP(); + int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_AUXV, process->GetID()}; + size_t auxv_size = AT_COUNT * sizeof(Elf_Auxinfo); + DataBufferSP buf_sp(new DataBufferHeap(auxv_size, 0)); + + if (::sysctl(mib, 4, buf_ap->GetBytes(), &auxv_size, NULL, 0) != 0) { + perror("sysctl failed on auxv"); + buf_sp.reset(); + } + + return buf_sp; } struct EmulatorBaton { Index: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h =================================================================== --- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h +++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h @@ -18,6 +18,7 @@ #include "lldb/Host/Debug.h" #include "lldb/Host/FileSpec.h" #include "lldb/Host/HostThread.h" +#include "lldb/Host/linux/Support.h" #include "lldb/Target/MemoryRegionInfo.h" #include "lldb/lldb-types.h" @@ -98,6 +99,11 @@ NativeThreadLinuxSP GetThreadByID(lldb::tid_t id); + llvm::ErrorOr> + GetAuxvData() const override { + return getProcFile(GetID(), "auxv"); + } + // --------------------------------------------------------------------- // Interface used by NativeRegisterContext-derived classes. // --------------------------------------------------------------------- Index: lldb/trunk/source/Plugins/Process/gdb-remote/CMakeLists.txt =================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/CMakeLists.txt +++ lldb/trunk/source/Plugins/Process/gdb-remote/CMakeLists.txt @@ -2,6 +2,15 @@ include_directories(${LIBXML2_INCLUDE_DIR}) endif() +set(LLDB_PLUGINS + lldbPluginProcessUtility + lldbPluginPlatformMacOSX +) + +if(CMAKE_SYSTEM_NAME MATCHES "Linux|Android") + list(APPEND LLDB_PLUGINS lldbPluginProcessLinux) +endif() + add_lldb_library(lldbPluginProcessGDBRemote PLUGIN GDBRemoteClientBase.cpp GDBRemoteCommunication.cpp @@ -24,8 +33,7 @@ lldbSymbol lldbTarget lldbUtility - lldbPluginProcessUtility - lldbPluginPlatformMacOSX + ${LLDB_PLUGINS} LINK_COMPONENTS Support ) Index: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h =================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h +++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h @@ -117,7 +117,7 @@ MainLoop::ReadHandleUP m_stdio_handle_up; lldb::StateType m_inferior_prev_state; - lldb::DataBufferSP m_active_auxv_buffer_sp; + std::unique_ptr m_active_auxv_buffer_up; std::mutex m_saved_registers_mutex; std::unordered_map m_saved_registers_map; uint32_t m_next_saved_registers_id; Index: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp =================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -81,7 +81,6 @@ m_continue_tid(LLDB_INVALID_THREAD_ID), m_debugged_process_mutex(), m_debugged_process_sp(), m_stdio_communication("process.stdio"), m_inferior_prev_state(StateType::eStateInvalid), - m_active_auxv_buffer_sp(), m_saved_registers_mutex(), m_saved_registers_map(), m_next_saved_registers_id(1), m_handshake_completed(false) { RegisterPacketHandlers(); @@ -2694,7 +2693,7 @@ "qXfer:auxv:read:: packet missing length"); // Grab the auxv data if we need it. - if (!m_active_auxv_buffer_sp) { + if (!m_active_auxv_buffer_up) { // Make sure we have a valid process. if (!m_debugged_process_sp || (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) { @@ -2706,55 +2705,45 @@ } // Grab the auxv data. - m_active_auxv_buffer_sp = Host::GetAuxvData(m_debugged_process_sp->GetID()); - if (!m_active_auxv_buffer_sp || - m_active_auxv_buffer_sp->GetByteSize() == 0) { - // Hmm, no auxv data, call that an error. - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, no auxv data " - "retrieved", - __FUNCTION__); - m_active_auxv_buffer_sp.reset(); - return SendErrorResponse(0x11); + auto buffer_or_error = m_debugged_process_sp->GetAuxvData(); + if (!buffer_or_error) { + std::error_code ec = buffer_or_error.getError(); + LLDB_LOG(log, "no auxv data retrieved: {0}", ec.message()); + return SendErrorResponse(ec.value()); } + m_active_auxv_buffer_up = std::move(*buffer_or_error); } - // FIXME find out if/how I lock the stream here. - StreamGDBRemote response; bool done_with_buffer = false; - if (auxv_offset >= m_active_auxv_buffer_sp->GetByteSize()) { + llvm::StringRef buffer = m_active_auxv_buffer_up->getBuffer(); + if (auxv_offset >= buffer.size()) { // We have nothing left to send. Mark the buffer as complete. response.PutChar('l'); done_with_buffer = true; } else { // Figure out how many bytes are available starting at the given offset. - const uint64_t bytes_remaining = - m_active_auxv_buffer_sp->GetByteSize() - auxv_offset; - - // Figure out how many bytes we're going to read. - const uint64_t bytes_to_read = - (auxv_length > bytes_remaining) ? bytes_remaining : auxv_length; + buffer = buffer.drop_front(auxv_offset); // Mark the response type according to whether we're reading the remainder // of the auxv data. - if (bytes_to_read >= bytes_remaining) { + if (auxv_length >= buffer.size()) { // There will be nothing left to read after this response.PutChar('l'); done_with_buffer = true; } else { // There will still be bytes to read after this request. response.PutChar('m'); + buffer = buffer.take_front(auxv_length); } // Now write the data in encoded binary form. - response.PutEscapedBytes(m_active_auxv_buffer_sp->GetBytes() + auxv_offset, - bytes_to_read); + response.PutEscapedBytes(buffer.data(), buffer.size()); } if (done_with_buffer) - m_active_auxv_buffer_sp.reset(); + m_active_auxv_buffer_up.reset(); return SendPacketNoLock(response.GetString()); #else @@ -3216,20 +3205,10 @@ } void GDBRemoteCommunicationServerLLGS::ClearProcessSpecificData() { - Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | GDBR_LOG_PROCESS)); - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s()", __FUNCTION__); + Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); -// Clear any auxv cached data. -// *BSD impls should be able to do this too. -#if defined(__linux__) - if (log) - log->Printf("GDBRemoteCommunicationServerLLGS::%s clearing auxv buffer " - "(previously %s)", - __FUNCTION__, - m_active_auxv_buffer_sp ? "was set" : "was not set"); - m_active_auxv_buffer_sp.reset(); -#endif + LLDB_LOG(log, "clearing auxv buffer: {0}", m_active_auxv_buffer_up.get()); + m_active_auxv_buffer_up.reset(); } FileSpec