Expose new read memory fucntion through python in SBProcess:
size_t
SBProcess::ReadCStringFromMemory (addr_t addr, void *buf, size_t size, lldb::SBError &error);
uint64_t
SBProcess::ReadUnsignedFromMemory (addr_t addr, uint32_t byte_size, lldb::SBError &error);
lldb::addr_t
SBProcess::ReadPointerFromMemory (addr_t addr, lldb::SBError &error);
These ReadCStringFromMemory() has some SWIG type magic that makes it return the
python string directly and the "buf" is not needed:
error = SBError()
max_cstr_len = 256
cstr = lldb.process.ReadCStringFromMemory (0x1000, max_cstr_len, error)
if error.Success():
....
The other two functions behave as expteced. This will make it easier to get integer values
from the inferior process that are correctly byte swapped. Also for pointers, the correct
pointer byte size will be used.
Also cleaned up a few printf style warnings for the 32 bit lldb build on darwin.
git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@146636 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/API/SBProcess.cpp b/source/API/SBProcess.cpp
index ce8109f..89932a3 100644
--- a/source/API/SBProcess.cpp
+++ b/source/API/SBProcess.cpp
@@ -766,6 +766,60 @@
}
size_t
+SBProcess::ReadCStringFromMemory (addr_t addr, void *buf, size_t size, lldb::SBError &sb_error)
+{
+ size_t bytes_read = 0;
+ if (m_opaque_sp)
+ {
+ Error error;
+ Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
+ bytes_read = m_opaque_sp->ReadCStringFromMemory (addr, (char *)buf, size, error);
+ sb_error.SetError (error);
+ }
+ else
+ {
+ sb_error.SetErrorString ("SBProcess is invalid");
+ }
+ return bytes_read;
+}
+
+uint64_t
+SBProcess::ReadUnsignedFromMemory (addr_t addr, uint32_t byte_size, lldb::SBError &sb_error)
+{
+ if (m_opaque_sp)
+ {
+ Error error;
+ Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
+ uint64_t value = m_opaque_sp->ReadUnsignedIntegerFromMemory (addr, byte_size, 0, error);
+ sb_error.SetError (error);
+ return value;
+ }
+ else
+ {
+ sb_error.SetErrorString ("SBProcess is invalid");
+ }
+ return 0;
+}
+
+lldb::addr_t
+SBProcess::ReadPointerFromMemory (addr_t addr, lldb::SBError &sb_error)
+{
+ lldb::addr_t ptr = LLDB_INVALID_ADDRESS;
+ if (m_opaque_sp)
+ {
+ Error error;
+ Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex());
+ ptr = m_opaque_sp->ReadPointerFromMemory (addr, error);
+ sb_error.SetError (error);
+ }
+ else
+ {
+ sb_error.SetErrorString ("SBProcess is invalid");
+ }
+ return ptr;
+}
+
+size_t
SBProcess::WriteMemory (addr_t addr, const void *src, size_t src_len, SBError &sb_error)
{
size_t bytes_written = 0;
diff --git a/source/Host/macosx/Host.mm b/source/Host/macosx/Host.mm
index de6929d..ac036e4 100644
--- a/source/Host/macosx/Host.mm
+++ b/source/Host/macosx/Host.mm
@@ -657,7 +657,7 @@
if (log)
log->Printf("Sending source file: \"%s\" and line: %d to external editor.\n", file_path, line_no);
- OSStatus error;
+ long error;
BabelAESelInfo file_and_line_info =
{
0, // reserved0
@@ -678,7 +678,7 @@
if (error != noErr)
{
if (log)
- log->Printf("Error creating AEDesc: %d.\n", error);
+ log->Printf("Error creating AEDesc: %ld.\n", error);
return false;
}
@@ -713,7 +713,7 @@
if (error != noErr)
{
if (log)
- log->Printf("Could not find External Editor application, error: %d.\n", error);
+ log->Printf("Could not find External Editor application, error: %ld.\n", error);
return false;
}
@@ -735,7 +735,7 @@
if (error != noErr)
{
if (log)
- log->Printf("LSOpenURLsWithRole failed, error: %d.\n", error);
+ log->Printf("LSOpenURLsWithRole failed, error: %ld.\n", error);
return false;
}
@@ -750,7 +750,7 @@
if (error != noErr)
{
if (log)
- log->Printf("GetProcessInformation failed, error: %d.\n", error);
+ log->Printf("GetProcessInformation failed, error: %ld.\n", error);
using_xcode = false;
}
else
@@ -807,7 +807,7 @@
if (error != noErr)
{
if (log)
- log->Printf("Failed to create AEDesc for Xcode AppleEvent: %d.\n", error);
+ log->Printf("Failed to create AEDesc for Xcode AppleEvent: %ld.\n", error);
return false;
}
@@ -825,7 +825,7 @@
if (error != noErr)
{
if (log)
- log->Printf("Sending AppleEvent to Xcode failed, error: %d.\n", error);
+ log->Printf("Sending AppleEvent to Xcode failed, error: %ld.\n", error);
return false;
}
}
diff --git a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
index b2b40c9..2b5efab 100644
--- a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
+++ b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
@@ -918,10 +918,13 @@
image_infos[i].mod_date = info_data_ref.GetPointer(&info_data_offset);
char raw_path[PATH_MAX];
- m_process->ReadCStringFromMemory (path_addr, raw_path, sizeof(raw_path));
+ m_process->ReadCStringFromMemory (path_addr, raw_path, sizeof(raw_path), error);
// don't resolve the path
- const bool resolve_path = false;
- image_infos[i].file_spec.SetFile(raw_path, resolve_path);
+ if (error.Success())
+ {
+ const bool resolve_path = false;
+ image_infos[i].file_spec.SetFile(raw_path, resolve_path);
+ }
}
return true;
}
diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
index e614edf..d584cb2 100644
--- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
+++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
@@ -145,7 +145,8 @@
size_t curr_len = full_buffer_len;
while (curr_len == full_buffer_len)
{
- curr_len = process->ReadCStringFromMemory(result_ptr + cstr_len, buf, sizeof(buf));
+ Error error;
+ curr_len = process->ReadCStringFromMemory(result_ptr + cstr_len, buf, sizeof(buf), error);
strm.Write (buf, curr_len);
cstr_len += curr_len;
}
diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
index 5442acd..ae64668 100644
--- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -220,10 +220,11 @@
}
addr_t result_ptr = void_ptr_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
- size_t chars_read = m_process->ReadCStringFromMemory (result_ptr, name_dst, max_name_len);
+ Error error;
+ size_t chars_read = m_process->ReadCStringFromMemory (result_ptr, name_dst, max_name_len, error);
// If we exhausted our buffer before finding a NULL we're probably off in the weeds somewhere...
- if (chars_read == max_name_len)
+ if (error.Fail() || chars_read == max_name_len)
return false;
else
return true;
@@ -686,8 +687,8 @@
return g_unknown;
//printf("name_pointer: %llx\n", name_pointer);
- char* cstr = new char[512];
- if (m_process->ReadCStringFromMemory(name_pointer, cstr, 512) > 0)
+ char cstr[512];
+ if (m_process->ReadCStringFromMemory(name_pointer, cstr, sizeof(cstr), error) > 0)
{
if (::strstr(cstr, "NSKVONotify") == cstr)
{
diff --git a/source/Target/Process.cpp b/source/Target/Process.cpp
index a138f59..fdd6b17 100644
--- a/source/Target/Process.cpp
+++ b/source/Target/Process.cpp
@@ -1856,11 +1856,12 @@
size_t
-Process::ReadCStringFromMemory (addr_t addr, char *dst, size_t dst_max_len)
+Process::ReadCStringFromMemory (addr_t addr, char *dst, size_t dst_max_len, Error &result_error)
{
size_t total_cstr_len = 0;
if (dst && dst_max_len)
{
+ result_error.Clear();
// NULL out everything just to be safe
memset (dst, 0, dst_max_len);
Error error;
@@ -1877,6 +1878,7 @@
if (bytes_read == 0)
{
+ result_error = error;
dst[total_cstr_len] = '\0';
break;
}
@@ -1892,6 +1894,13 @@
bytes_left -= bytes_read;
}
}
+ else
+ {
+ if (dst == NULL)
+ result_error.SetErrorString("invalid arguments");
+ else
+ result_error.Clear();
+ }
return total_cstr_len;
}