diff options
author | Johnny Chen <johnny.chen@apple.com> | 2011-03-02 01:36:45 +0000 |
---|---|---|
committer | Johnny Chen <johnny.chen@apple.com> | 2011-03-02 01:36:45 +0000 |
commit | 43766d6f1274decc804b3f3a32e1bb2b127d2f7a (patch) | |
tree | a452b4f7fcc76b06979511c293a073f938711ddd /lldb/test/python_api/process/TestProcessAPI.py | |
parent | 7290868a1ba52b5b82b4c30807301b63b2b14cf1 (diff) | |
download | bcm5719-llvm-43766d6f1274decc804b3f3a32e1bb2b127d2f7a.tar.gz bcm5719-llvm-43766d6f1274decc804b3f3a32e1bb2b127d2f7a.zip |
Add two utility functions to lldbutil.py:
o int_to_bytearray()
o bytearray_to_int()
They return/interpret the bytearray in the little endian format.
For big endian, simply perform ba.reverse() on the bytearray object.
And modify TestProcessAPI.py to take advantage of the functions.
llvm-svn: 126813
Diffstat (limited to 'lldb/test/python_api/process/TestProcessAPI.py')
-rw-r--r-- | lldb/test/python_api/process/TestProcessAPI.py | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/lldb/test/python_api/process/TestProcessAPI.py b/lldb/test/python_api/process/TestProcessAPI.py index 1e92fa309d3..615668b115e 100644 --- a/lldb/test/python_api/process/TestProcessAPI.py +++ b/lldb/test/python_api/process/TestProcessAPI.py @@ -174,20 +174,18 @@ class ProcessAPITestCase(TestBase): # OK, let's get the hex location of the variable. location = int(val.GetLocation(frame), 16) + from lldbutil import int_to_bytearray, bytearray_to_int byteSize = val.GetByteSize() - byteOrder = self.process.GetByteOrder() - bytes = bytearray(byteSize) + bytes = int_to_bytearray(256, byteSize) + byteOrder = self.process.GetByteOrder() if byteOrder == lldb.eByteOrderBig: - # 256 in big endian => 0x00000100 - # the second byte counted from the end is to be 0b00000001 - bytes[-2] = 0b00000001 + bytes.reverse() elif byteOrder == lldb.eByteOrderLittle: - # 256 in little endian => 0x00010000 - # the second byte counted from the start is to be 0b00000001 - bytes[1] = 0b00000001 + pass else: # Neither big endian nor little endian? Return for now. + # Add more logic here if we want to handle other types. return # The program logic makes the 'my_int' variable to have int type and value of 0. @@ -211,12 +209,14 @@ class ProcessAPITestCase(TestBase): if not error.Success(): self.fail("SBProcess.ReadMemory() failed") new_bytes = bytearray(content, "ascii") + + # The bytearray_to_int utility function expects a little endian bytearray. if byteOrder == lldb.eByteOrderBig: - if new_bytes[-2] != 0b00000001: - self.fail("Memory content read from 'my_int' does not match (int)256") - elif byteOrder == lldb.eByteOrderLittle: - if new_bytes[1] != 0b00000001: - self.fail("Memory content read from 'my_int' does not match (int)256") + new_bytes.reverse() + + new_value = bytearray_to_int(new_bytes, byteSize) + if new_value != 256: + self.fail("Memory content read from 'my_int' does not match (int)256") # Dump the memory content.... for i in new_bytes: |