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.

llvm-svn: 146636
This commit is contained in:
Greg Clayton
2011-12-15 03:14:23 +00:00
parent 2c74eedbba
commit e91b7957b2
9 changed files with 146 additions and 17 deletions

View File

@@ -765,6 +765,60 @@ SBProcess::ReadMemory (addr_t addr, void *dst, size_t dst_len, SBError &sb_error
return bytes_read;
}
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)
{