xref: /llvm-project/lldb/test/API/lang/objc/foundation/TestObjectDescriptionAPI.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1"""
2Test SBValue.GetObjectDescription() with the value from SBTarget.FindGlobalVariables().
3"""
4
5import lldb
6from lldbsuite.test.decorators import *
7from lldbsuite.test.lldbtest import *
8from lldbsuite.test import lldbutil
9
10
11class ObjectDescriptionAPITestCase(TestBase):
12    def setUp(self):
13        # Call super's setUp().
14        TestBase.setUp(self)
15        # Find the line number to break at.
16        self.source = "main.m"
17        self.line = line_number(self.source, "// Set break point at this line.")
18
19    # rdar://problem/10857337
20    @add_test_categories(["pyapi"])
21    def test_find_global_variables_then_object_description(self):
22        """Exercise SBTarget.FindGlobalVariables() API."""
23        d = {"EXE": "b.out"}
24        self.build(dictionary=d)
25        self.setTearDownCleanup(dictionary=d)
26        exe = self.getBuildArtifact("b.out")
27
28        # Create a target by the debugger.
29        target = self.dbg.CreateTarget(exe)
30        self.assertTrue(target, VALID_TARGET)
31
32        breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
33        self.assertTrue(breakpoint, VALID_BREAKPOINT)
34
35        # Now launch the process, and do not stop at entry point.
36        process = target.LaunchSimple(None, None, self.get_process_working_directory())
37        self.assertTrue(process, PROCESS_IS_VALID)
38        # Make sure we hit our breakpoint:
39        thread_list = lldbutil.get_threads_stopped_at_breakpoint(process, breakpoint)
40        self.assertEqual(len(thread_list), 1)
41
42        thread = thread_list[0]
43        frame0 = thread.GetFrameAtIndex(0)
44
45        # Note my_global_str's object description prints fine here.
46        value_list1 = frame0.GetVariables(True, True, True, True)
47        for v in value_list1:
48            self.DebugSBValue(v)
49            if self.TraceOn():
50                print("val:", v)
51                print("object description:", v.GetObjectDescription())
52            if v.GetName() == "my_global_str":
53                self.assertEqual(v.GetObjectDescription(), "This is a global string")
54
55        # But not here!
56        value_list2 = target.FindGlobalVariables("my_global_str", 3)
57        for v in value_list2:
58            self.DebugSBValue(v)
59            if self.TraceOn():
60                print("val:", v)
61                print("object description:", v.GetObjectDescription())
62            if v.GetName() == "my_global_str":
63                self.assertEqual(v.GetObjectDescription(), "This is a global string")
64