Index: include/lldb/Host/common/NativeBreakpointList.h =================================================================== --- include/lldb/Host/common/NativeBreakpointList.h +++ include/lldb/Host/common/NativeBreakpointList.h @@ -42,6 +42,9 @@ Error GetBreakpoint (lldb::addr_t addr, NativeBreakpointSP &breakpoint_sp); + Error + RemoveTrapsFromBuffer(lldb::addr_t addr, void *buf, size_t size) const; + private: typedef std::map BreakpointMap; Index: include/lldb/Host/common/NativeProcessProtocol.h =================================================================== --- include/lldb/Host/common/NativeProcessProtocol.h +++ include/lldb/Host/common/NativeProcessProtocol.h @@ -90,13 +90,16 @@ GetMemoryRegionInfo (lldb::addr_t load_addr, MemoryRegionInfo &range_info); virtual Error - ReadMemory (lldb::addr_t addr, void *buf, lldb::addr_t size, lldb::addr_t &bytes_read) = 0; + ReadMemory(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read) = 0; virtual Error - WriteMemory (lldb::addr_t addr, const void *buf, lldb::addr_t size, lldb::addr_t &bytes_written) = 0; + ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read) = 0; virtual Error - AllocateMemory (lldb::addr_t size, uint32_t permissions, lldb::addr_t &addr) = 0; + WriteMemory(lldb::addr_t addr, const void *buf, size_t size, size_t &bytes_written) = 0; + + virtual Error + AllocateMemory(size_t size, uint32_t permissions, lldb::addr_t &addr) = 0; virtual Error DeallocateMemory (lldb::addr_t addr) = 0; Index: include/lldb/Host/common/SoftwareBreakpoint.h =================================================================== --- include/lldb/Host/common/SoftwareBreakpoint.h +++ include/lldb/Host/common/SoftwareBreakpoint.h @@ -17,6 +17,8 @@ { class SoftwareBreakpoint : public NativeBreakpoint { + friend class NativeBreakpointList; + public: static Error CreateSoftwareBreakpoint (NativeProcessProtocol &process, lldb::addr_t addr, size_t size_hint, NativeBreakpointSP &breakpoint_spn); Index: source/Host/common/NativeBreakpointList.cpp =================================================================== --- source/Host/common/NativeBreakpointList.cpp +++ source/Host/common/NativeBreakpointList.cpp @@ -12,6 +12,7 @@ #include "lldb/Core/Log.h" #include "lldb/Host/common/NativeBreakpoint.h" +#include "lldb/Host/common/SoftwareBreakpoint.h" using namespace lldb; using namespace lldb_private; @@ -197,3 +198,24 @@ return Error (); } +Error +NativeBreakpointList::RemoveTrapsFromBuffer(lldb::addr_t addr, void *buf, size_t size) const +{ + for (const auto &map : m_breakpoints) + { + lldb::addr_t bp_addr = map.first; + // Breapoint not in range, ignore + if (bp_addr < addr || addr + size <= bp_addr) + continue; + const auto &bp_sp = map.second; + // Not software breakpoint, ignore + if (!bp_sp->IsSoftwareBreakpoint()) + continue; + auto software_bp_sp = std::static_pointer_cast(bp_sp); + auto opcode_addr = static_cast(buf) + bp_addr - addr; + auto saved_opcodes = software_bp_sp->m_saved_opcodes; + auto opcode_size = software_bp_sp->m_opcode_size; + ::memcpy(opcode_addr, saved_opcodes, opcode_size); + } + return Error(); +} Index: source/Plugins/Process/Linux/NativeProcessLinux.h =================================================================== --- source/Plugins/Process/Linux/NativeProcessLinux.h +++ source/Plugins/Process/Linux/NativeProcessLinux.h @@ -84,13 +84,16 @@ GetMemoryRegionInfo (lldb::addr_t load_addr, MemoryRegionInfo &range_info) override; Error - ReadMemory (lldb::addr_t addr, void *buf, lldb::addr_t size, lldb::addr_t &bytes_read) override; + ReadMemory(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read) override; Error - WriteMemory (lldb::addr_t addr, const void *buf, lldb::addr_t size, lldb::addr_t &bytes_written) override; + ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read) override; Error - AllocateMemory (lldb::addr_t size, uint32_t permissions, lldb::addr_t &addr) override; + WriteMemory(lldb::addr_t addr, const void *buf, size_t size, size_t &bytes_written) override; + + Error + AllocateMemory(size_t size, uint32_t permissions, lldb::addr_t &addr) override; Error DeallocateMemory (lldb::addr_t addr) override; Index: source/Plugins/Process/Linux/NativeProcessLinux.cpp =================================================================== --- source/Plugins/Process/Linux/NativeProcessLinux.cpp +++ source/Plugins/Process/Linux/NativeProcessLinux.cpp @@ -3405,10 +3405,7 @@ } Error -NativeProcessLinux::AllocateMemory ( - lldb::addr_t size, - uint32_t permissions, - lldb::addr_t &addr) +NativeProcessLinux::AllocateMemory(size_t size, uint32_t permissions, lldb::addr_t &addr) { // FIXME implementing this requires the equivalent of // InferiorCallPOSIX::InferiorCallMmap, which depends on @@ -3770,7 +3767,7 @@ #endif Error -NativeProcessLinux::ReadMemory (lldb::addr_t addr, void *buf, lldb::addr_t size, lldb::addr_t &bytes_read) +NativeProcessLinux::ReadMemory(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read) { ReadOperation op(addr, buf, size, bytes_read); m_monitor_up->DoOperation(&op); @@ -3778,7 +3775,15 @@ } Error -NativeProcessLinux::WriteMemory (lldb::addr_t addr, const void *buf, lldb::addr_t size, lldb::addr_t &bytes_written) +NativeProcessLinux::ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read) +{ + Error error = ReadMemory(addr, buf, size, bytes_read); + if (error.Fail()) return error; + return m_breakpoint_list.RemoveTrapsFromBuffer(addr, buf, size); +} + +Error +NativeProcessLinux::WriteMemory(lldb::addr_t addr, const void *buf, size_t size, size_t &bytes_written) { WriteOperation op(addr, buf, size, bytes_written); m_monitor_up->DoOperation(&op); Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp =================================================================== --- source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -1846,8 +1846,8 @@ // Retrieve the process memory. - lldb::addr_t bytes_read = 0; - Error error = m_debugged_process_sp->ReadMemory (read_addr, &buf[0], byte_count, bytes_read); + size_t bytes_read = 0; + Error error = m_debugged_process_sp->ReadMemoryWithoutTrap(read_addr, &buf[0], byte_count, bytes_read); if (error.Fail ()) { if (log)