]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/lang/cpp/stl/TestStdCXXDisassembly.py
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / lang / cpp / stl / TestStdCXXDisassembly.py
1 """
2 Test the lldb disassemble command on lib stdc++.
3 """
4
5 from __future__ import print_function
6
7
8
9 import unittest2
10 import os, time
11 import lldb
12 from lldbsuite.test.lldbtest import *
13 import lldbsuite.test.lldbutil as lldbutil
14
15 class StdCXXDisassembleTestCase(TestBase):
16
17     mydir = TestBase.compute_mydir(__file__)
18
19     def setUp(self):
20         # Call super's setUp().
21         TestBase.setUp(self)
22         # Find the line number to break inside main().
23         self.line = line_number('main.cpp', '// Set break point at this line.')
24
25     # rdar://problem/8504895
26     # Crash while doing 'disassemble -n "-[NSNumber descriptionWithLocale:]"
27     @unittest2.skipIf(TestBase.skipLongRunningTest(), "Skip this long running test")
28     def test_stdcxx_disasm(self):
29         """Do 'disassemble' on each and every 'Code' symbol entry from the std c++ lib."""
30         self.build()
31         exe = os.path.join(os.getcwd(), "a.out")
32         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
33
34         # rdar://problem/8543077
35         # test/stl: clang built binaries results in the breakpoint locations = 3,
36         # is this a problem with clang generated debug info?
37         #
38         # Break on line 13 of main.cpp.
39         lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
40
41         self.runCmd("run", RUN_SUCCEEDED)
42
43         # Now let's get the target as well as the process objects.
44         target = self.dbg.GetSelectedTarget()
45         process = target.GetProcess()
46
47         # The process should be in a 'stopped' state.
48         self.expect(str(process), STOPPED_DUE_TO_BREAKPOINT, exe=False,
49             substrs = ["a.out",
50                        "stopped"])
51
52         # Disassemble the functions on the call stack.
53         self.runCmd("thread backtrace")
54         thread = process.GetThreadAtIndex(0)
55         depth = thread.GetNumFrames()
56         for i in range(depth - 1):
57             frame = thread.GetFrameAtIndex(i)
58             function = frame.GetFunction()
59             if function.GetName():
60                 self.runCmd("disassemble -n '%s'" % function.GetName())
61
62         lib_stdcxx = "FAILHORRIBLYHERE"
63         # Iterate through the available modules, looking for stdc++ library...
64         for i in range(target.GetNumModules()):
65             module = target.GetModuleAtIndex(i)
66             fs = module.GetFileSpec()
67             if (fs.GetFilename().startswith("libstdc++") or fs.GetFilename().startswith("libc++")):
68                 lib_stdcxx = str(fs)
69                 break
70
71         # At this point, lib_stdcxx is the full path to the stdc++ library and
72         # module is the corresponding SBModule.
73
74         self.expect(lib_stdcxx, "Libraray StdC++ is located", exe=False,
75             substrs = ["lib"])
76
77         self.runCmd("image dump symtab '%s'" % lib_stdcxx)
78         raw_output = self.res.GetOutput()
79         # Now, look for every 'Code' symbol and feed its load address into the
80         # command: 'disassemble -s load_address -e end_address', where the
81         # end_address is taken from the next consecutive 'Code' symbol entry's
82         # load address.
83         #
84         # The load address column comes after the file address column, with both
85         # looks like '0xhhhhhhhh', i.e., 8 hexadecimal digits.
86         codeRE = re.compile(r"""
87                              \ Code\ {9}      # ' Code' followed by 9 SPCs,
88                              0x[0-9a-f]{16}   # the file address column, and
89                              \                # a SPC, and
90                              (0x[0-9a-f]{16}) # the load address column, and
91                              .*               # the rest.
92                              """, re.VERBOSE)
93         # Maintain a start address variable; if we arrive at a consecutive Code
94         # entry, then the load address of the that entry is fed as the end
95         # address to the 'disassemble -s SA -e LA' command.
96         SA = None
97         for line in raw_output.split(os.linesep):
98             match = codeRE.search(line)
99             if match:
100                 LA = match.group(1)
101                 if self.TraceOn():
102                     print("line:", line)
103                     print("load address:", LA)
104                     print("SA:", SA)
105                 if SA and LA:
106                     if int(LA, 16) > int(SA, 16):
107                         self.runCmd("disassemble -s %s -e %s" % (SA, LA))
108                 SA = LA
109             else:
110                 # This entry is not a Code entry.  Reset SA = None.
111                 SA = None