2 Test lldb-mi -symbol-xxx commands.
5 from __future__ import print_function
10 from lldbsuite.test.decorators import *
11 from lldbsuite.test.lldbtest import *
12 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
20 @expectedFailureAll(oslist=["linux"], bugnumber="new failure after r256863")
21 def test_lldbmi_symbol_list_lines_file(self):
22 """Test that 'lldb-mi --interpreter' works for -symbol-list-lines when file exists."""
24 self.spawnLldbMi(args = None)
27 self.runCmd("-file-exec-and-symbols %s" % self.myexe)
31 self.runCmd("-break-insert -f main")
32 self.expect("\^done,bkpt={number=\"1\"")
33 self.runCmd("-exec-run")
34 self.expect("\^running")
35 self.expect("\*stopped,reason=\"breakpoint-hit\"")
37 # Get address of main and its line
38 self.runCmd("-data-evaluate-expression main")
39 self.expect("\^done,value=\"0x[0-9a-f]+ \(a.out`main at main.cpp:[0-9]+\)\"")
40 addr = int(self.child.after.split("\"")[1].split(" ")[0], 16)
41 line = line_number('main.cpp', '// FUNC_main')
43 # Test that -symbol-list-lines works on valid data
44 self.runCmd("-symbol-list-lines main.cpp")
45 self.expect("\^done,lines=\[\{pc=\"0x0*%x\",line=\"%d\"\}(,\{pc=\"0x[0-9a-f]+\",line=\"\d+\"\})+\]" % (addr, line))
47 # Test that -symbol-list-lines doesn't include lines from other sources
48 # by checking the first and last line, and making sure the other lines
49 # are between 30 and 39.
50 sline = line_number('symbol_list_lines_inline_test2.cpp', '// FUNC_gfunc2')
51 eline = line_number('symbol_list_lines_inline_test2.cpp', '// END_gfunc2')
52 self.runCmd("-symbol-list-lines symbol_list_lines_inline_test2.cpp")
53 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\"\}(,\{pc=\"0x[0-9a-f]+\",line=\"3\d\"\})*\]" % (sline, eline))
54 ##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)
55 ##sline = line_number('symbol_list_lines_inline_test.cpp', '// FUNC_gfunc')
56 ##eline = line_number('symbol_list_lines_inline_test.cpp', '// STRUCT_s')
57 ##self.runCmd("-symbol-list-lines symbol_list_lines_inline_test.cpp")
58 ##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))
60 # Test that -symbol-list-lines works on header files by checking the first
61 # and last line, and making sure the other lines are under 29.
62 sline = line_number('symbol_list_lines_inline_test.h', '// FUNC_ifunc')
63 eline = line_number('symbol_list_lines_inline_test.h', '// FUNC_mfunc')
64 self.runCmd("-symbol-list-lines symbol_list_lines_inline_test.h")
65 self.expect("\^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\"\})*\]" % (sline, eline))
67 # Test that -symbol-list-lines fails when file doesn't exist
68 self.runCmd("-symbol-list-lines unknown_file")
69 self.expect("\^error,message=\"error: No source filenames matched 'unknown_file'\. \"")
71 # Test that -symbol-list-lines fails when file is specified using relative path
72 self.runCmd("-symbol-list-lines ./main.cpp")
73 self.expect("\^error,message=\"error: No source filenames matched '\./main\.cpp'\. \"")
75 # Test that -symbol-list-lines works when file is specified using absolute path
77 path = os.path.join(os.getcwd(), "main.cpp")
78 self.runCmd("-symbol-list-lines \"%s\"" % path)
79 self.expect("\^done,lines=\[\{pc=\"0x0*%x\",line=\"%d\"\}(,\{pc=\"0x[0-9a-f]+\",line=\"\d+\"\})+\]" % (addr, line))
81 # Test that -symbol-list-lines fails when file doesn't exist
82 self.runCmd("-symbol-list-lines unknown_dir/main.cpp")
83 self.expect("\^error,message=\"error: No source filenames matched 'unknown_dir/main\.cpp'\. \"")