Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / test / API / lang / objc / foundation / TestObjectDescriptionAPI.py
blobe2f78139ae66b8a33122b6680e43b3c045ebd487
1 """
2 Test SBValue.GetObjectDescription() with the value from SBTarget.FindGlobalVariables().
3 """
5 import lldb
6 from lldbsuite.test.decorators import *
7 from lldbsuite.test.lldbtest import *
8 from lldbsuite.test import lldbutil
11 class 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.")
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")
28 # Create a target by the debugger.
29 target = self.dbg.CreateTarget(exe)
30 self.assertTrue(target, VALID_TARGET)
32 breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
33 self.assertTrue(breakpoint, VALID_BREAKPOINT)
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)
42 thread = thread_list[0]
43 frame0 = thread.GetFrameAtIndex(0)
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")
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")