[AMDGPU] Add True16 register classes.
[llvm-project.git] / lldb / test / API / python_api / process / read-mem-cstring / TestReadMemCString.py
blobf664a18ebfa3d6f6d8f2b680dbf2d04bdbc637d9
1 """Test reading c-strings from memory via SB API."""
4 import os
5 import lldb
6 from lldbsuite.test.decorators import *
7 from lldbsuite.test.lldbtest import *
8 from lldbsuite.test import lldbutil
11 class TestReadMemCString(TestBase):
12 NO_DEBUG_INFO_TESTCASE = True
14 def test_read_memory_c_string(self):
15 """Test corner case behavior of SBProcess::ReadCStringFromMemory"""
16 self.build()
17 self.dbg.SetAsync(False)
19 self.main_source = "main.c"
20 self.main_source_path = os.path.join(self.getSourceDir(), self.main_source)
21 self.main_source_spec = lldb.SBFileSpec(self.main_source_path)
22 self.exe = self.getBuildArtifact("read-mem-cstring")
24 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
25 self, "breakpoint here", self.main_source_spec, None, self.exe
28 frame = thread.GetFrameAtIndex(0)
30 err = lldb.SBError()
32 empty_str_addr = frame.FindVariable("empty_string").GetValueAsUnsigned(err)
33 self.assertSuccess(err)
34 self.assertNotEqual(empty_str_addr, lldb.LLDB_INVALID_ADDRESS)
36 one_letter_str_addr = frame.FindVariable(
37 "one_letter_string"
38 ).GetValueAsUnsigned(err)
39 self.assertSuccess(err)
40 self.assertNotEqual(one_letter_str_addr, lldb.LLDB_INVALID_ADDRESS)
42 invalid_memory_str_addr = frame.FindVariable(
43 "invalid_memory_string"
44 ).GetValueAsUnsigned(err)
45 self.assertSuccess(err)
46 self.assertNotEqual(invalid_memory_str_addr, lldb.LLDB_INVALID_ADDRESS)
48 # Important: An empty (0-length) c-string must come back as a Python string, not a
49 # None object.
50 empty_str = process.ReadCStringFromMemory(empty_str_addr, 2048, err)
51 self.assertSuccess(err)
52 self.assertEqual(empty_str, "")
54 one_letter_string = process.ReadCStringFromMemory(
55 one_letter_str_addr, 2048, err
57 self.assertSuccess(err)
58 self.assertEqual(one_letter_string, "1")
60 invalid_memory_string = process.ReadCStringFromMemory(
61 invalid_memory_str_addr, 2048, err
63 self.assertTrue(err.Fail())
64 self.assertTrue(invalid_memory_string == "" or invalid_memory_string == None)