Fixed SBTarget::ReadMemory() to work correctly and the TestTargetAPI.py test case...
authorGreg Clayton <gclayton@apple.com>
Tue, 4 Nov 2014 00:56:30 +0000 (00:56 +0000)
committerGreg Clayton <gclayton@apple.com>
Tue, 4 Nov 2014 00:56:30 +0000 (00:56 +0000)
commit8691dc5b754f32c4262236481ca29770c3219353
tree613d3d18580522b287e56b6e81af9ac40a9d24bf
parent4eb0a3fd2536cae6bd08b7c7f632ab2343902cd5
Fixed SBTarget::ReadMemory() to work correctly and the TestTargetAPI.py test case that was reading target memory in TargetAPITestCase.test_read_memory_with_dsym and TargetAPITestCase.test_read_memory_with_dwarf.

The problem was that SBTarget::ReadMemory() was making a new section offset lldb_private::Address by doing:

size_t
SBTarget::ReadMemory (const SBAddress addr,
                      void *buf,
                      size_t size,
                      lldb::SBError &error)
{
        ...
        lldb_private::Address addr_priv(addr.GetFileAddress(), NULL);
        bytes_read = target_sp->ReadMemory(addr_priv, false, buf, size, err_priv);

This is wrong. If you get the file addresss from the "addr" argument and try to read memory using that, it will think the file address is a load address and it will try to resolve it accordingly. This will work fine if your executable is loaded at the same address (no slide), but it won't work if there is a slide.

The fix is to just pass along the "addr.ref()" instead of making a new addr_priv as this will pass along the lldb_private::Address that is inside the SBAddress (which is what we want), and not always change it into something that becomes a load address (if we are running), or abmigious file address (think address zero when you have 150 shared libraries that have sections that start at zero, which one would you pick). The main reason for passing a section offset address to SBTarget::ReadMemory() is so you _can_ read from the actual section + offset that is specified in the SBAddress.

llvm-svn: 221213
lldb/source/API/SBTarget.cpp
lldb/test/python_api/target/TestTargetAPI.py