[Lldb-commits] [lldb] r146704 - in /lldb/trunk/test/python_api/process: TestProcessAPI.py main.cpp
Johnny Chen
johnny.chen at apple.com
Thu Dec 15 15:30:06 PST 2011
Author: johnny
Date: Thu Dec 15 17:30:05 2011
New Revision: 146704
URL: http://llvm.org/viewvc/llvm-project?rev=146704&view=rev
Log:
Add test scenario for newly added SBProcess APIs: ReadCStringFromMemory() and ReadUnsignedFromMemory().
Modified:
lldb/trunk/test/python_api/process/TestProcessAPI.py
lldb/trunk/test/python_api/process/main.cpp
Modified: lldb/trunk/test/python_api/process/TestProcessAPI.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/process/TestProcessAPI.py?rev=146704&r1=146703&r2=146704&view=diff
==============================================================================
--- lldb/trunk/test/python_api/process/TestProcessAPI.py (original)
+++ lldb/trunk/test/python_api/process/TestProcessAPI.py Thu Dec 15 17:30:05 2011
@@ -105,6 +105,51 @@
exe=False,
startstr = 'x')
+ # Get the SBValue for the global variable 'my_cstring'.
+ val = frame.FindValue("my_cstring", lldb.eValueTypeVariableGlobal)
+ self.DebugSBValue(val)
+
+ # If the variable does not have a load address, there's no sense continuing.
+ if not val.GetLocation().startswith("0x"):
+ return
+
+ # OK, let's get the hex location of the variable.
+ location = int(val.GetLocation(), 16)
+
+ # Due to the typemap magic (see lldb.swig), we pass in 256 to read at most 256 bytes
+ # from the address, and expect to get a Python string as the result object!
+ cstring = process.ReadCStringFromMemory(location, 256, error)
+ if not error.Success():
+ self.fail("SBProcess.ReadCStringFromMemory() failed")
+ if self.TraceOn():
+ print "cstring read is:", cstring
+
+ self.expect(cstring, "Result from SBProcess.ReadCStringFromMemory() matches our expected output",
+ exe=False,
+ startstr = 'lldb.SBProcess.ReadCStringFromMemory() works!')
+
+ # Get the SBValue for the global variable 'my_uint32'.
+ val = frame.FindValue("my_uint32", lldb.eValueTypeVariableGlobal)
+ self.DebugSBValue(val)
+
+ # If the variable does not have a load address, there's no sense continuing.
+ if not val.GetLocation().startswith("0x"):
+ return
+
+ # OK, let's get the hex location of the variable.
+ location = int(val.GetLocation(), 16)
+
+ # Due to the typemap magic (see lldb.swig), we pass in 4 to read at 4 bytes
+ # from the address, and expect to get an int as the result!
+ my_uint32 = process.ReadUnsignedFromMemory(location, 4, error)
+ if not error.Success():
+ self.fail("SBProcess.ReadCStringFromMemory() failed")
+ if self.TraceOn():
+ print "uint32 read is:", my_uint32
+
+ if my_uint32 != 12345:
+ self.fail("Result from SBProcess.ReadUnsignedFromMemory() does not match our expected output")
+
def write_memory(self):
"""Test Python SBProcess.WriteMemory() API."""
exe = os.path.join(os.getcwd(), "a.out")
Modified: lldb/trunk/test/python_api/process/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/process/main.cpp?rev=146704&r1=146703&r2=146704&view=diff
==============================================================================
--- lldb/trunk/test/python_api/process/main.cpp (original)
+++ lldb/trunk/test/python_api/process/main.cpp Thu Dec 15 17:30:05 2011
@@ -7,10 +7,13 @@
//
//===----------------------------------------------------------------------===//
#include <stdio.h>
+#include <stdint.h>
// This simple program is to test the lldb Python API related to process.
char my_char = 'u';
+char my_cstring[] = "lldb.SBProcess.ReadCStringFromMemory() works!";
+uint32_t my_uint32 = 12345;
int my_int = 0;
int main (int argc, char const *argv[])
More information about the lldb-commits
mailing list