]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/tools/lldb-mi/symbol/TestMiSymbol.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / tools / lldb-mi / symbol / TestMiSymbol.py
1 """
2 Test lldb-mi -symbol-xxx commands.
3 """
4
5 from __future__ import print_function
6
7
8 import lldbmi_testcase
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
12
13
14 class MiSymbolTestCase(lldbmi_testcase.MiTestCaseBase):
15
16     mydir = TestBase.compute_mydir(__file__)
17
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(
21         oslist=["linux"],
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."""
25
26         self.spawnLldbMi(args=None)
27
28         # Load executable
29         self.runCmd("-file-exec-and-symbols %s" % self.myexe)
30         self.expect("\^done")
31
32         # Run to main
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\"")
38
39         # Get address of main and its line
40         self.runCmd("-data-evaluate-expression main")
41         self.expect(
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')
45
46         # Test that -symbol-list-lines works on valid data
47         self.runCmd("-symbol-list-lines main.cpp")
48         self.expect(
49             "\^done,lines=\[\{pc=\"0x0*%x\",line=\"%d\"\}(,\{pc=\"0x[0-9a-f]+\",line=\"\d+\"\})+\]" %
50             (addr, line))
51
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.
55         sline = line_number(
56             'symbol_list_lines_inline_test2.cpp',
57             '// FUNC_gfunc2')
58         eline = line_number(
59             'symbol_list_lines_inline_test2.cpp',
60             '// END_gfunc2')
61         self.runCmd("-symbol-list-lines symbol_list_lines_inline_test2.cpp")
62         self.expect(
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\"\})*\]" %
64             (sline, eline))
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))
70
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")
76         self.expect(
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\"\})*\]" %
78             (sline, eline))
79
80         # Test that -symbol-list-lines fails when file doesn't exist
81         self.runCmd("-symbol-list-lines unknown_file")
82         self.expect(
83             "\^error,message=\"error: No source filenames matched 'unknown_file'\. \"")
84
85         # Test that -symbol-list-lines fails when file is specified using
86         # relative path
87         self.runCmd("-symbol-list-lines ./main.cpp")
88         self.expect(
89             "\^error,message=\"error: No source filenames matched '\./main\.cpp'\. \"")
90
91         # Test that -symbol-list-lines works when file is specified using
92         # absolute path
93         import os
94         path = os.path.join(os.getcwd(), "main.cpp")
95         self.runCmd("-symbol-list-lines \"%s\"" % path)
96         self.expect(
97             "\^done,lines=\[\{pc=\"0x0*%x\",line=\"%d\"\}(,\{pc=\"0x[0-9a-f]+\",line=\"\d+\"\})+\]" %
98             (addr, line))
99
100         # Test that -symbol-list-lines fails when file doesn't exist
101         self.runCmd("-symbol-list-lines unknown_dir/main.cpp")
102         self.expect(
103             "\^error,message=\"error: No source filenames matched 'unknown_dir/main\.cpp'\. \"")