2 Test lldb-mi -symbol-xxx commands.
5 from __future__ import print_function
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
14 class MiSymbolTestCase(lldbmi_testcase.MiTestCaseBase):
16 mydir = TestBase.compute_mydir(__file__)
18 @skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
19 @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
22 bugnumber="new failure after r256863")
23 def test_lldbmi_symbol_list_lines_file(self):
24 """Test that 'lldb-mi --interpreter' works for -symbol-list-lines when file exists."""
26 self.spawnLldbMi(args=None)
29 self.runCmd("-file-exec-and-symbols %s" % self.myexe)
33 self.runCmd("-break-insert -f main")
34 self.expect("\^done,bkpt={number=\"1\"")
35 self.runCmd("-exec-run")
36 self.expect("\^running")
37 self.expect("\*stopped,reason=\"breakpoint-hit\"")
39 # Get address of main and its line
40 self.runCmd("-data-evaluate-expression main")
42 "\^done,value=\"0x[0-9a-f]+ \(a.out`main at main.cpp:[0-9]+\)\"")
43 addr = int(self.child.after.split("\"")[1].split(" ")[0], 16)
44 line = line_number('main.cpp', '// FUNC_main')
46 # Test that -symbol-list-lines works on valid data
47 self.runCmd("-symbol-list-lines main.cpp")
49 "\^done,lines=\[\{pc=\"0x0*%x\",line=\"%d\"\}(,\{pc=\"0x[0-9a-f]+\",line=\"\d+\"\})+\]" %
52 # Test that -symbol-list-lines doesn't include lines from other sources
53 # by checking the first and last line, and making sure the other lines
54 # are between 30 and 39.
56 'symbol_list_lines_inline_test2.cpp',
59 'symbol_list_lines_inline_test2.cpp',
61 self.runCmd("-symbol-list-lines symbol_list_lines_inline_test2.cpp")
63 "\^done,lines=\[\{pc=\"0x[0-9a-f]+\",line=\"%d\"\}(,\{pc=\"0x[0-9a-f]+\",line=\"3\d\"\})*,\{pc=\"0x[0-9a-f]+\",line=\"%d\"\}(,\{pc=\"0x[0-9a-f]+\",line=\"3\d\"\})*\]" %
65 # FIXME: This doesn't work for symbol_list_lines_inline_test.cpp due to clang bug llvm.org/pr24716 (fixed in newer versions of clang)
66 ##sline = line_number('symbol_list_lines_inline_test.cpp', '// FUNC_gfunc')
67 ##eline = line_number('symbol_list_lines_inline_test.cpp', '// STRUCT_s')
68 ##self.runCmd("-symbol-list-lines symbol_list_lines_inline_test.cpp")
69 ##self.expect("\^done,lines=\[\{pc=\"0x[0-9a-f]+\",line=\"%d\"\}(,\{pc=\"0x[0-9a-f]+\",line=\"3\d\"\})*,\{pc=\"0x[0-9a-f]+\",line=\"%d\"\}\]" % (sline, eline))
71 # Test that -symbol-list-lines works on header files by checking the first
72 # and last line, and making sure the other lines are under 29.
73 sline = line_number('symbol_list_lines_inline_test.h', '// FUNC_ifunc')
74 eline = line_number('symbol_list_lines_inline_test.h', '// FUNC_mfunc')
75 self.runCmd("-symbol-list-lines symbol_list_lines_inline_test.h")
77 "\^done,lines=\[\{pc=\"0x[0-9a-f]+\",line=\"%d\"\}(,\{pc=\"0x[0-9a-f]+\",line=\"\d\"\})*(,\{pc=\"0x[0-9a-f]+\",line=\"1\d\"\})*,\{pc=\"0x[0-9a-f]+\",line=\"%d\"\}(,\{pc=\"0x[0-9a-f]+\",line=\"2\d\"\})*\]" %
80 # Test that -symbol-list-lines fails when file doesn't exist
81 self.runCmd("-symbol-list-lines unknown_file")
83 "\^error,message=\"error: No source filenames matched 'unknown_file'\. \"")
85 # Test that -symbol-list-lines fails when file is specified using
87 self.runCmd("-symbol-list-lines ./main.cpp")
89 "\^error,message=\"error: No source filenames matched '\./main\.cpp'\. \"")
91 # Test that -symbol-list-lines works when file is specified using
94 path = os.path.join(os.getcwd(), "main.cpp")
95 self.runCmd("-symbol-list-lines \"%s\"" % path)
97 "\^done,lines=\[\{pc=\"0x0*%x\",line=\"%d\"\}(,\{pc=\"0x[0-9a-f]+\",line=\"\d+\"\})+\]" %
100 # Test that -symbol-list-lines fails when file doesn't exist
101 self.runCmd("-symbol-list-lines unknown_dir/main.cpp")
103 "\^error,message=\"error: No source filenames matched 'unknown_dir/main\.cpp'\. \"")