]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/frame-language/TestGuessLanguage.py
Vendor import of lldb trunk r338536:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / frame-language / TestGuessLanguage.py
1 """
2 Test the SB API SBFrame::GuessLanguage.
3 """
4
5 from __future__ import print_function
6
7
8 import os
9 import time
10 import re
11 import lldb
12 import lldbsuite.test.lldbutil as lldbutil
13 from lldbsuite.test.decorators import *
14 from lldbsuite.test.lldbtest import *
15
16
17 class TestFrameGuessLanguage(TestBase):
18
19     mydir = TestBase.compute_mydir(__file__)
20
21     # If your test case doesn't stress debug info, the
22     # set this to true.  That way it won't be run once for
23     # each debug info format.
24     NO_DEBUG_INFO_TESTCASE = True
25
26     @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr37658")
27     def test_guess_language(self):
28         """Test GuessLanguage for C and C++."""
29         self.build()
30         self.do_test()
31
32     def setUp(self):
33         # Call super's setUp().
34         TestBase.setUp(self)
35
36     def check_language(self, thread, frame_no, test_lang):
37         frame = thread.frames[frame_no]
38         self.assertTrue(frame.IsValid(), "Frame %d was not valid."%(frame_no))
39         lang = frame.GuessLanguage()
40         self.assertEqual(lang, test_lang)
41
42     def do_test(self):
43         """Test GuessLanguage for C & C++."""
44         exe = self.getBuildArtifact("a.out")
45
46         # Create a target by the debugger.
47         target = self.dbg.CreateTarget(exe)
48         self.assertTrue(target, VALID_TARGET)
49
50         # Now create a breakpoint in main.c at the source matching
51         # "Set a breakpoint here"
52         breakpoint = target.BreakpointCreateBySourceRegex(
53             "Set breakpoint here", lldb.SBFileSpec("somefunc.c"))
54         self.assertTrue(breakpoint and
55                         breakpoint.GetNumLocations() >= 1,
56                         VALID_BREAKPOINT)
57
58         error = lldb.SBError()
59         # This is the launch info.  If you want to launch with arguments or
60         # environment variables, add them using SetArguments or
61         # SetEnvironmentEntries
62
63         launch_info = lldb.SBLaunchInfo(None)
64         process = target.Launch(launch_info, error)
65         self.assertTrue(process, PROCESS_IS_VALID)
66
67         # Did we hit our breakpoint?
68         from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint
69         threads = get_threads_stopped_at_breakpoint(process, breakpoint)
70         self.assertTrue(
71             len(threads) == 1,
72             "There should be a thread stopped at our breakpoint")
73
74         # The hit count for the breakpoint should be 1.
75         self.assertTrue(breakpoint.GetHitCount() == 1)
76
77         thread = threads[0]
78
79         c_frame_language = lldb.eLanguageTypeC99
80         # gcc emits DW_LANG_C89 even if -std=c99 was specified
81         if "gcc" in self.getCompiler():
82             c_frame_language = lldb.eLanguageTypeC89
83
84         self.check_language(thread, 0, c_frame_language)
85         self.check_language(thread, 1, lldb.eLanguageTypeC_plus_plus)
86         self.check_language(thread, 2, lldb.eLanguageTypeC_plus_plus)
87
88
89