2 Test the SB API SBFrame::GuessLanguage.
5 from __future__ import print_function
12 import lldbsuite.test.lldbutil as lldbutil
13 from lldbsuite.test.decorators import *
14 from lldbsuite.test.lldbtest import *
17 class TestFrameGuessLanguage(TestBase):
19 mydir = TestBase.compute_mydir(__file__)
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
26 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr37658")
27 def test_guess_language(self):
28 """Test GuessLanguage for C and C++."""
33 # Call super's setUp().
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)
43 """Test GuessLanguage for C & C++."""
44 exe = self.getBuildArtifact("a.out")
46 # Create a target by the debugger.
47 target = self.dbg.CreateTarget(exe)
48 self.assertTrue(target, VALID_TARGET)
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,
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
63 launch_info = lldb.SBLaunchInfo(None)
64 process = target.Launch(launch_info, error)
65 self.assertTrue(process, PROCESS_IS_VALID)
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)
72 "There should be a thread stopped at our breakpoint")
74 # The hit count for the breakpoint should be 1.
75 self.assertTrue(breakpoint.GetHitCount() == 1)
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
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)