TestStdCXXDisassembly.py [plain text]
"""
Test the lldb disassemble command on lib stdc++.
"""
import os, time
import unittest2
import lldb
from lldbtest import *
class StdCXXDisassembleTestCase(TestBase):
mydir = os.path.join("lang", "cpp", "stl")
def setUp(self):
TestBase.setUp(self)
self.line = line_number('main.cpp', '// Set break point at this line.')
@unittest2.skipIf(TestBase.skipLongRunningTest(), "Skip this long running test")
def test_stdcxx_disasm(self):
"""Do 'disassemble' on each and every 'Code' symbol entry from the std c++ lib."""
self.buildDefault()
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
self.expect("breakpoint set -f main.cpp -l %d" % self.line,
BREAKPOINT_CREATED,
startstr = "Breakpoint created: 1: file ='main.cpp', line = %d" %
self.line)
self.runCmd("run", RUN_SUCCEEDED)
target = self.dbg.GetSelectedTarget()
process = target.GetProcess()
self.expect(str(process), STOPPED_DUE_TO_BREAKPOINT, exe=False,
substrs = ["a.out",
"stopped"])
self.runCmd("thread backtrace")
thread = process.GetThreadAtIndex(0)
depth = thread.GetNumFrames()
for i in range(depth - 1):
frame = thread.GetFrameAtIndex(i)
function = frame.GetFunction()
self.runCmd("disassemble -n '%s'" % function.GetName())
for i in range(target.GetNumModules()):
module = target.GetModuleAtIndex(i)
fs = module.GetFileSpec()
if (fs.GetFilename().startswith("libstdc++")):
lib_stdcxx = str(fs)
break
self.expect(fs.GetFilename(), "Libraray StdC++ is located", exe=False,
substrs = ["libstdc++"])
self.runCmd("image dump symtab %s" % str(fs))
raw_output = self.res.GetOutput()
codeRE = re.compile(r"""
\ Code\ {9} # ' Code' followed by 9 SPCs,
0x[0-9a-f]{16} # the file address column, and
\ # a SPC, and
(0x[0-9a-f]{16}) # the load address column, and
.* # the rest.
""", re.VERBOSE)
SA = None
for line in raw_output.split(os.linesep):
match = codeRE.search(line)
if match:
LA = match.group(1)
if self.TraceOn():
print "line:", line
print "load address:", LA
print "SA:", SA
if SA and LA:
if int(LA, 16) > int(SA, 16):
self.runCmd("disassemble -s %s -e %s" % (SA, LA))
SA = LA
else:
SA = None
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
atexit.register(lambda: lldb.SBDebugger.Terminate())
unittest2.main()