]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/python_api/lldbutil/frame/TestFrameUtils.py
Vendor import of lldb trunk r338150:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / python_api / lldbutil / frame / TestFrameUtils.py
1 """
2 Test utility functions for the frame object.
3 """
4
5 from __future__ import print_function
6
7
8 import os
9 import lldb
10 from lldbsuite.test.decorators import *
11 from lldbsuite.test.lldbtest import *
12 from lldbsuite.test import lldbutil
13
14
15 class FrameUtilsTestCase(TestBase):
16
17     mydir = TestBase.compute_mydir(__file__)
18
19     def setUp(self):
20         # Call super's setUp().
21         TestBase.setUp(self)
22         # Find the line number to break inside main().
23         self.line = line_number('main.c',
24                                 "// Find the line number here.")
25
26     @add_test_categories(['pyapi'])
27     def test_frame_utils(self):
28         """Test utility functions for the frame object."""
29         self.build()
30         exe = self.getBuildArtifact("a.out")
31
32         target = self.dbg.CreateTarget(exe)
33         self.assertTrue(target, VALID_TARGET)
34
35         breakpoint = target.BreakpointCreateByLocation("main.c", self.line)
36         self.assertTrue(breakpoint, VALID_BREAKPOINT)
37
38         # Now launch the process, and do not stop at entry point.
39         process = target.LaunchSimple(
40             None, None, self.get_process_working_directory())
41
42         if not process:
43             self.fail("SBTarget.LaunchProcess() failed")
44         self.assertTrue(process.GetState() == lldb.eStateStopped,
45                         PROCESS_STOPPED)
46
47         import lldbsuite.test.lldbutil as lldbutil
48         thread = lldbutil.get_stopped_thread(
49             process, lldb.eStopReasonBreakpoint)
50         self.assertTrue(thread)
51         frame0 = thread.GetFrameAtIndex(0)
52         self.assertTrue(frame0)
53         frame1 = thread.GetFrameAtIndex(1)
54         self.assertTrue(frame1)
55         parent = lldbutil.get_parent_frame(frame0)
56         self.assertTrue(parent and parent.GetFrameID() == frame1.GetFrameID())
57         frame0_args = lldbutil.get_args_as_string(frame0)
58         parent_args = lldbutil.get_args_as_string(parent)
59         self.assertTrue(
60             frame0_args and parent_args and "(int)val=1" in frame0_args)
61         if self.TraceOn():
62             lldbutil.print_stacktrace(thread)
63             print("Current frame: %s" % frame0_args)
64             print("Parent frame: %s" % parent_args)