diff options
author | Jason Molenda <jmolenda@apple.com> | 2011-11-09 08:03:56 +0000 |
---|---|---|
committer | Jason Molenda <jmolenda@apple.com> | 2011-11-09 08:03:56 +0000 |
commit | 3dc8583c96e249fba8884b9785ea02910f418f2b (patch) | |
tree | d9a80c29cd08a31e195243954dbbd0d1d023e958 /lldb/tools/debugserver/source/MacOSX | |
parent | 8c8a43105720bcc5eedd35efc490afc84c8fe668 (diff) | |
download | bcm5719-llvm-3dc8583c96e249fba8884b9785ea02910f418f2b.tar.gz bcm5719-llvm-3dc8583c96e249fba8884b9785ea02910f418f2b.zip |
Remove the QAddressIsExecutable packet I added last night.
Add a more general purpose qMemoryRegionInfo packet which can
describe various attributes about a memory region. Currently it
will return the start address, size, and permissions (read, write,
executable) for the memory region. It may be possible to add
additional attributes in the future such as whether the region is
designated as stack memory or jitted code a la vmmap.
I still haven't implemented the lldb side of the code to use this
packet yet so there may be unexpected behavior - but the basic implementation looks
about right. I'll hook it up to lldb soon and fix any problems that crop up.
llvm-svn: 144175
Diffstat (limited to 'lldb/tools/debugserver/source/MacOSX')
8 files changed, 45 insertions, 21 deletions
diff --git a/lldb/tools/debugserver/source/MacOSX/MachProcess.cpp b/lldb/tools/debugserver/source/MacOSX/MachProcess.cpp index 133f41e2df1..4cf8fd335da 100644 --- a/lldb/tools/debugserver/source/MacOSX/MachProcess.cpp +++ b/lldb/tools/debugserver/source/MacOSX/MachProcess.cpp @@ -603,10 +603,10 @@ MachProcess::WriteMemory (nub_addr_t addr, nub_size_t size, const void *buf) return bytes_written; } -bool -MachProcess::IsAddressExecutable(nub_addr_t address) +int +MachProcess::MemoryRegionInfo(nub_addr_t address, char *outbuf, nub_size_t outbufsize) { - return m_task.IsAddressExecutable (address); + return m_task.MemoryRegionInfo (address, outbuf, outbufsize); } void diff --git a/lldb/tools/debugserver/source/MacOSX/MachProcess.h b/lldb/tools/debugserver/source/MacOSX/MachProcess.h index b68fa7f49e2..732d50d69db 100644 --- a/lldb/tools/debugserver/source/MacOSX/MachProcess.h +++ b/lldb/tools/debugserver/source/MacOSX/MachProcess.h @@ -99,7 +99,7 @@ public: bool Detach (); nub_size_t ReadMemory (nub_addr_t addr, nub_size_t size, void *buf); nub_size_t WriteMemory (nub_addr_t addr, nub_size_t size, const void *buf); - bool IsAddressExecutable(nub_addr_t address); + int MemoryRegionInfo(nub_addr_t address, char *outbuf, nub_size_t outbufsize); //---------------------------------------------------------------------- // Path and arg accessors diff --git a/lldb/tools/debugserver/source/MacOSX/MachTask.cpp b/lldb/tools/debugserver/source/MacOSX/MachTask.cpp index 035198e4864..b6368fc8956 100644 --- a/lldb/tools/debugserver/source/MacOSX/MachTask.cpp +++ b/lldb/tools/debugserver/source/MacOSX/MachTask.cpp @@ -205,18 +205,17 @@ MachTask::WriteMemory (nub_addr_t addr, nub_size_t size, const void *buf) } //---------------------------------------------------------------------- -// MachTask::IsAddressExecutable +// MachTask::MemoryRegionInfo //---------------------------------------------------------------------- -bool -MachTask::IsAddressExecutable (nub_addr_t addr) +int +MachTask::MemoryRegionInfo (nub_addr_t addr, char *outbuf, nub_size_t outbufsize) { task_t task = TaskPort(); - bool ret = false; - if (task != TASK_NULL) - { - ret = m_vm_memory.IsExecutable(task, addr); - DNBLogThreadedIf(LOG_MEMORY, "MachTask::IsAddressExecutable ( addr = 0x%8.8llx ) => %s", (uint64_t)addr, (ret ? "true" : "false")); - } + if (task == TASK_NULL) + return -1; + + int ret = m_vm_memory.MemoryRegionInfo(task, addr, outbuf, outbufsize); + DNBLogThreadedIf(LOG_MEMORY, "MachTask::MemoryRegionInfo ( addr = 0x%8.8llx ) => %d", (uint64_t)addr, ret); return ret; } diff --git a/lldb/tools/debugserver/source/MacOSX/MachTask.h b/lldb/tools/debugserver/source/MacOSX/MachTask.h index da64ba6c997..f0cfd0e56e8 100644 --- a/lldb/tools/debugserver/source/MacOSX/MachTask.h +++ b/lldb/tools/debugserver/source/MacOSX/MachTask.h @@ -64,7 +64,7 @@ public: nub_size_t ReadMemory (nub_addr_t addr, nub_size_t size, void *buf); nub_size_t WriteMemory (nub_addr_t addr, nub_size_t size, const void *buf); - bool IsAddressExecutable (nub_addr_t addr) ; + int MemoryRegionInfo (nub_addr_t addr, char *outbuf, nub_size_t outbufsize); nub_addr_t AllocateMemory (nub_size_t size, uint32_t permissions); nub_bool_t DeallocateMemory (nub_addr_t addr); diff --git a/lldb/tools/debugserver/source/MacOSX/MachVMMemory.cpp b/lldb/tools/debugserver/source/MacOSX/MachVMMemory.cpp index 58789ed191a..69e50d546cf 100644 --- a/lldb/tools/debugserver/source/MacOSX/MachVMMemory.cpp +++ b/lldb/tools/debugserver/source/MacOSX/MachVMMemory.cpp @@ -52,15 +52,16 @@ MachVMMemory::MaxBytesLeftInPage(nub_addr_t addr, nub_size_t count) return count; } -bool -MachVMMemory::IsExecutable(task_t task, nub_addr_t address) +int +MachVMMemory::MemoryRegionInfo(task_t task, nub_addr_t address, char *outbuf, nub_size_t outbufsize) { MachVMRegion vmRegion(task); + outbuf[0] = '\0'; - if (vmRegion.GetRegionForAddress(address) && vmRegion.IsExecutable()) - return true; + if (vmRegion.GetRegionForAddress(address) && vmRegion.GetRegionDescription(outbuf, outbufsize)) + return 1; else - return false; + return 0; } nub_size_t diff --git a/lldb/tools/debugserver/source/MacOSX/MachVMMemory.h b/lldb/tools/debugserver/source/MacOSX/MachVMMemory.h index 421e4b4999c..fa5583383bf 100644 --- a/lldb/tools/debugserver/source/MacOSX/MachVMMemory.h +++ b/lldb/tools/debugserver/source/MacOSX/MachVMMemory.h @@ -27,7 +27,7 @@ public: nub_size_t Read(task_t task, nub_addr_t address, void *data, nub_size_t data_count); nub_size_t Write(task_t task, nub_addr_t address, const void *data, nub_size_t data_count); nub_size_t PageSize(); - bool IsExecutable(task_t task, nub_addr_t address); + int MemoryRegionInfo(task_t task, nub_addr_t address, char *outbuf, nub_size_t outbufsize); protected: nub_size_t MaxBytesLeftInPage(nub_addr_t addr, nub_size_t count); diff --git a/lldb/tools/debugserver/source/MacOSX/MachVMRegion.cpp b/lldb/tools/debugserver/source/MacOSX/MachVMRegion.cpp index 6299cf4179f..f12f2b92703 100644 --- a/lldb/tools/debugserver/source/MacOSX/MachVMRegion.cpp +++ b/lldb/tools/debugserver/source/MacOSX/MachVMRegion.cpp @@ -177,3 +177,27 @@ MachVMRegion::GetRegionForAddress(nub_addr_t addr) return true; } + +bool +MachVMRegion::GetRegionDescription (char *outbuf, nub_size_t outbufsize) +{ + if (m_addr == INVALID_NUB_ADDRESS || m_start == INVALID_NUB_ADDRESS || m_size == 0) + return false; + snprintf (outbuf, outbufsize, "start:%llx,size:%llx", m_start, m_size); + outbuf[outbufsize - 1] = '\0'; + + char tmpbuf[128]; + strcpy (tmpbuf, ",permissions:"); + if ((m_data.protection & VM_PROT_READ) == VM_PROT_READ) + strcat (tmpbuf, "r"); + if ((m_data.protection & VM_PROT_WRITE) == VM_PROT_WRITE) + strcat (tmpbuf, "w"); + if ((m_data.protection & VM_PROT_EXECUTE) == VM_PROT_EXECUTE) + strcat (tmpbuf, "x"); + strlcat (outbuf, tmpbuf, outbufsize); + + // It would be nice if we could figure out whether the memory region is stack memory or jitted code memory as well + + outbuf[outbufsize - 1] = '\0'; + return true; +} diff --git a/lldb/tools/debugserver/source/MacOSX/MachVMRegion.h b/lldb/tools/debugserver/source/MacOSX/MachVMRegion.h index bd1aaa0e2a2..7a3bd586600 100644 --- a/lldb/tools/debugserver/source/MacOSX/MachVMRegion.h +++ b/lldb/tools/debugserver/source/MacOSX/MachVMRegion.h @@ -43,7 +43,7 @@ public: bool RestoreProtections(); bool GetRegionForAddress(nub_addr_t addr); - bool IsExecutable() const { return (m_data.protection & VM_PROT_EXECUTE) == VM_PROT_EXECUTE; } + bool GetRegionDescription (char *outbuf, nub_size_t outbufsize); protected: #if defined (VM_REGION_SUBMAP_SHORT_INFO_COUNT_64) |