1 """Test reading c-strings from memory via SB API."""
6 from lldbsuite.test.decorators import *
7 from lldbsuite.test.lldbtest import *
8 from lldbsuite.test import lldbutil
11 class TestReadMemCString(TestBase):
13 mydir = TestBase.compute_mydir(__file__)
14 NO_DEBUG_INFO_TESTCASE = True
16 def test_read_memory_c_string(self):
17 """Test corner case behavior of SBProcess::ReadCStringFromMemory"""
19 self.dbg.SetAsync(False)
21 self.main_source = "main.c"
22 self.main_source_path = os.path.join(self.getSourceDir(),
24 self.main_source_spec = lldb.SBFileSpec(self.main_source_path)
25 self.exe = self.getBuildArtifact("read-mem-cstring")
27 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
28 self, 'breakpoint here', self.main_source_spec, None, self.exe)
30 frame = thread.GetFrameAtIndex(0)
34 empty_str_addr = frame.FindVariable("empty_string").GetValueAsUnsigned(err)
35 self.assertTrue(err.Success())
36 self.assertTrue(empty_str_addr != lldb.LLDB_INVALID_ADDRESS)
38 one_letter_str_addr = frame.FindVariable("one_letter_string").GetValueAsUnsigned(err)
39 self.assertTrue(err.Success())
40 self.assertTrue(one_letter_str_addr != lldb.LLDB_INVALID_ADDRESS)
42 invalid_memory_str_addr = frame.FindVariable("invalid_memory_string").GetValueAsUnsigned(err)
43 self.assertTrue(err.Success())
44 self.assertTrue(invalid_memory_str_addr != lldb.LLDB_INVALID_ADDRESS)
46 # Important: An empty (0-length) c-string must come back as a Python string, not a
48 empty_str = process.ReadCStringFromMemory(empty_str_addr, 2048, err)
49 self.assertTrue(err.Success())
50 self.assertTrue(empty_str == "")
52 one_letter_string = process.ReadCStringFromMemory(one_letter_str_addr, 2048, err)
53 self.assertTrue(err.Success())
54 self.assertTrue(one_letter_string == "1")
56 invalid_memory_string = process.ReadCStringFromMemory(invalid_memory_str_addr, 2048, err)
57 self.assertTrue(err.Fail())
58 self.assertTrue(invalid_memory_string == "" or invalid_memory_string == None)