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