2 Test the lldb disassemble command on lib stdc++.
5 from __future__ import print_function
12 from lldbsuite.test.lldbtest import *
13 import lldbsuite.test.lldbutil as lldbutil
15 class StdCXXDisassembleTestCase(TestBase):
17 mydir = TestBase.compute_mydir(__file__)
20 # Call super's setUp().
22 # Find the line number to break inside main().
23 self.line = line_number('main.cpp', '// Set break point at this line.')
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."""
31 exe = os.path.join(os.getcwd(), "a.out")
32 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
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?
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)
41 self.runCmd("run", RUN_SUCCEEDED)
43 # Now let's get the target as well as the process objects.
44 target = self.dbg.GetSelectedTarget()
45 process = target.GetProcess()
47 # The process should be in a 'stopped' state.
48 self.expect(str(process), STOPPED_DUE_TO_BREAKPOINT, exe=False,
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())
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++")):
71 # At this point, lib_stdcxx is the full path to the stdc++ library and
72 # module is the corresponding SBModule.
74 self.expect(lib_stdcxx, "Libraray StdC++ is located", exe=False,
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
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
90 (0x[0-9a-f]{16}) # the load address column, and
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.
97 for line in raw_output.split(os.linesep):
98 match = codeRE.search(line)
103 print("load address:", LA)
106 if int(LA, 16) > int(SA, 16):
107 self.runCmd("disassemble -s %s -e %s" % (SA, LA))
110 # This entry is not a Code entry. Reset SA = None.