Skip to content

Commit

Permalink
Fix SBData::SetData() so that it always sets the address byte size co…
Browse files Browse the repository at this point in the history
…rrectly and added a test.

llvm-svn: 293102
  • Loading branch information
Greg Clayton committed Jan 25, 2017
1 parent 7b5b7c7 commit 896b451
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Expand Up @@ -21,6 +21,26 @@ def setUp(self):
# Find the line number to break on inside main.cpp.
self.line = line_number('main.cpp', '// set breakpoint here')

@add_test_categories(['pyapi'])
def test_byte_order_and_address_byte_size(self):
"""Test the SBData::SetData() to ensure the byte order and address
byte size are obeyed"""
addr_data = '\x11\x22\x33\x44\x55\x66\x77\x88'
error = lldb.SBError()
data = lldb.SBData()
data.SetData(error, addr_data, lldb.eByteOrderBig, 4)
addr = data.GetAddress(error, 0)
self.assertTrue(addr == 0x11223344);
data.SetData(error, addr_data, lldb.eByteOrderBig, 8)
addr = data.GetAddress(error, 0)
self.assertTrue(addr == 0x1122334455667788);
data.SetData(error, addr_data, lldb.eByteOrderLittle, 4)
addr = data.GetAddress(error, 0)
self.assertTrue(addr == 0x44332211);
data.SetData(error, addr_data, lldb.eByteOrderLittle, 8)
addr = data.GetAddress(error, 0)
self.assertTrue(addr == 0x8877665544332211);

@add_test_categories(['pyapi'])
def test_with_run_command(self):
"""Test the SBData APIs."""
Expand Down
4 changes: 4 additions & 0 deletions lldb/source/API/SBData.cpp
Expand Up @@ -383,7 +383,11 @@ void SBData::SetData(lldb::SBError &error, const void *buf, size_t size,
if (!m_opaque_sp.get())
m_opaque_sp.reset(new DataExtractor(buf, size, endian, addr_size));
else
{
m_opaque_sp->SetData(buf, size, endian);
m_opaque_sp->SetAddressByteSize(addr_size);
}

if (log)
log->Printf("SBData::SetData (error=%p,buf=%p,size=%" PRIu64
",endian=%d,addr_size=%c) => "
Expand Down

0 comments on commit 896b451

Please sign in to comment.