blob: 0632779b12d2e4a690211664dcc6f2766aea0374 [file] [log] [blame]
Johnny Chen7ea9aee2010-10-07 21:38:28 +00001"""
Johnny Chen0b8fd432011-04-19 22:44:20 +00002Test SBprocess and SBThread APIs with printing of the stack traces using lldbutil.
Johnny Chen7ea9aee2010-10-07 21:38:28 +00003"""
4
Zachary Turner35d017f2015-10-23 17:04:29 +00005from __future__ import print_function
6
Zachary Turner0a0490b2015-10-27 20:12:05 +00007import use_lldb_suite
Zachary Turner77db4a82015-10-22 20:06:20 +00008
Johnny Chen7ea9aee2010-10-07 21:38:28 +00009import os, time
10import re
Johnny Chen7ea9aee2010-10-07 21:38:28 +000011import lldb
12from lldbtest import *
13
14class ThreadsStackTracesTestCase(TestBase):
15
Greg Clayton4570d3e2013-12-10 23:19:29 +000016 mydir = TestBase.compute_mydir(__file__)
Johnny Chen7ea9aee2010-10-07 21:38:28 +000017
Johnny Chenc043de12010-11-11 20:18:36 +000018 def setUp(self):
19 # Call super's setUp().
20 TestBase.setUp(self)
21 # Find the line number to break inside main().
22 self.line = line_number('main.cpp', '// Set break point at this line.')
23
Pavel Labathecc728b2015-06-25 15:25:30 +000024 @expectedFailureAll("llvm.org/pr23043", ["linux"], archs=["i386"]) # We are unable to produce a backtrace of the main thread when the thread is blocked in fgets
Zachary Turner9c7b08e2015-09-11 20:01:24 +000025 @expectedFailureWindows("llvm.org/pr24778")
Pavel Labathdc8b2d32015-10-26 09:28:32 +000026 @add_test_categories(['pyapi'])
Johnny Chen7ea9aee2010-10-07 21:38:28 +000027 def test_stack_traces(self):
28 """Test SBprocess and SBThread APIs with printing of the stack traces."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000029 self.build()
Johnny Chen7ea9aee2010-10-07 21:38:28 +000030 exe = os.path.join(os.getcwd(), "a.out")
31
32 target = self.dbg.CreateTarget(exe)
Johnny Chen112f5692011-05-17 22:14:39 +000033 self.assertTrue(target, VALID_TARGET)
Johnny Chen7ea9aee2010-10-07 21:38:28 +000034
Johnny Chenc043de12010-11-11 20:18:36 +000035 breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line)
Johnny Chen112f5692011-05-17 22:14:39 +000036 self.assertTrue(breakpoint, VALID_BREAKPOINT)
Johnny Chen7ea9aee2010-10-07 21:38:28 +000037
38 # Now launch the process, and do not stop at entry point.
Greg Claytonc6947512013-12-13 19:18:59 +000039 process = target.LaunchSimple (["abc", "xyz"], None, self.get_process_working_directory())
Johnny Chen7ea9aee2010-10-07 21:38:28 +000040
Johnny Chen1d3e8802011-07-11 23:38:23 +000041 if not process:
Johnny Chen7ea9aee2010-10-07 21:38:28 +000042 self.fail("SBTarget.LaunchProcess() failed")
43
Johnny Chen109941b2011-01-25 17:17:45 +000044 import lldbutil
Johnny Chen5a0bee72011-06-15 22:14:12 +000045 if process.GetState() != lldb.eStateStopped:
Johnny Chen0c724ef2010-10-18 15:44:42 +000046 self.fail("Process should be in the 'stopped' state, "
Johnny Chen7ea9aee2010-10-07 21:38:28 +000047 "instead the actual state is: '%s'" %
Johnny Chen5a0bee72011-06-15 22:14:12 +000048 lldbutil.state_type_to_str(process.GetState()))
Johnny Chen7ea9aee2010-10-07 21:38:28 +000049
Johnny Chen0d4f6dd2011-06-16 22:07:48 +000050 stacktraces = lldbutil.print_stacktraces(process, string_buffer=True)
51 self.expect(stacktraces, exe=False,
52 substrs = ['(int)argc=3'])