2011-09-27 23:15:58 +00:00
|
|
|
"""
|
|
|
|
|
Test some SBModule and SBSection APIs.
|
|
|
|
|
"""
|
|
|
|
|
|
2015-10-23 17:04:29 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
|
2015-11-03 19:20:39 +00:00
|
|
|
|
2011-09-27 23:15:58 +00:00
|
|
|
import lldb
|
2016-02-04 18:03:01 +00:00
|
|
|
from lldbsuite.test.decorators import *
|
2015-11-03 02:06:18 +00:00
|
|
|
from lldbsuite.test.lldbtest import *
|
2016-02-04 18:03:01 +00:00
|
|
|
from lldbsuite.test import lldbutil
|
2015-11-03 02:06:18 +00:00
|
|
|
from lldbsuite.test.lldbutil import symbol_type_to_str
|
2011-09-27 23:15:58 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-09-27 23:15:58 +00:00
|
|
|
class ModuleAndSectionAPIsTestCase(TestBase):
|
|
|
|
|
|
2013-12-10 23:19:29 +00:00
|
|
|
mydir = TestBase.compute_mydir(__file__)
|
2011-09-27 23:15:58 +00:00
|
|
|
|
2016-01-08 21:08:24 +00:00
|
|
|
# Py3 asserts due to a bug in SWIG. A fix for this was upstreamed into
|
|
|
|
|
# SWIG 3.0.8.
|
|
|
|
|
@skipIf(py_version=['>=', (3, 0)], swig_version=['<', (3, 0, 8)])
|
2015-10-26 09:28:32 +00:00
|
|
|
@add_test_categories(['pyapi'])
|
2011-09-27 23:15:58 +00:00
|
|
|
def test_module_and_section(self):
|
|
|
|
|
"""Test module and section APIs."""
|
2015-09-30 10:12:40 +00:00
|
|
|
self.build()
|
2018-01-19 23:24:35 +00:00
|
|
|
exe = self.getBuildArtifact("a.out")
|
2011-09-27 23:15:58 +00:00
|
|
|
|
|
|
|
|
target = self.dbg.CreateTarget(exe)
|
|
|
|
|
self.assertTrue(target, VALID_TARGET)
|
|
|
|
|
self.assertTrue(target.GetNumModules() > 0)
|
|
|
|
|
|
|
|
|
|
# Hide stdout if not running with '-t' option.
|
|
|
|
|
if not self.TraceOn():
|
|
|
|
|
self.HideStdout()
|
|
|
|
|
|
2015-10-23 17:04:29 +00:00
|
|
|
print("Number of modules for the target: %d" % target.GetNumModules())
|
2011-09-27 23:15:58 +00:00
|
|
|
for module in target.module_iter():
|
2015-10-23 17:04:29 +00:00
|
|
|
print(module)
|
2011-09-27 23:15:58 +00:00
|
|
|
|
|
|
|
|
# Get the executable module at index 0.
|
|
|
|
|
exe_module = target.GetModuleAtIndex(0)
|
|
|
|
|
|
2015-10-23 17:04:29 +00:00
|
|
|
print("Exe module: %s" % str(exe_module))
|
|
|
|
|
print("Number of sections: %d" % exe_module.GetNumSections())
|
2019-04-04 10:13:59 +00:00
|
|
|
print("Number of symbols: %d" % len(exe_module))
|
2011-09-27 23:15:58 +00:00
|
|
|
INDENT = ' ' * 4
|
2011-09-28 00:51:00 +00:00
|
|
|
INDENT2 = INDENT * 2
|
2011-09-27 23:15:58 +00:00
|
|
|
for sec in exe_module.section_iter():
|
2015-10-23 17:04:29 +00:00
|
|
|
print(sec)
|
|
|
|
|
print(
|
|
|
|
|
INDENT +
|
|
|
|
|
"Number of subsections: %d" %
|
|
|
|
|
sec.GetNumSubSections())
|
2011-09-28 18:33:50 +00:00
|
|
|
if sec.GetNumSubSections() == 0:
|
2011-09-30 00:42:49 +00:00
|
|
|
for sym in exe_module.symbol_in_section_iter(sec):
|
2015-10-23 17:04:29 +00:00
|
|
|
print(INDENT + str(sym))
|
|
|
|
|
print(
|
|
|
|
|
INDENT +
|
|
|
|
|
"symbol type: %s" %
|
|
|
|
|
symbol_type_to_str(
|
|
|
|
|
sym.GetType()))
|
2011-09-28 18:33:50 +00:00
|
|
|
else:
|
2011-09-27 23:15:58 +00:00
|
|
|
for subsec in sec:
|
2015-10-23 17:04:29 +00:00
|
|
|
print(INDENT + str(subsec))
|
2011-09-28 00:51:00 +00:00
|
|
|
# Now print the symbols belonging to the subsection....
|
2011-09-30 00:42:49 +00:00
|
|
|
for sym in exe_module.symbol_in_section_iter(subsec):
|
2015-10-23 17:04:29 +00:00
|
|
|
print(INDENT2 + str(sym))
|
|
|
|
|
print(
|
|
|
|
|
INDENT2 +
|
|
|
|
|
"symbol type: %s" %
|
|
|
|
|
symbol_type_to_str(
|
|
|
|
|
sym.GetType()))
|
2011-09-27 23:15:58 +00:00
|
|
|
|
2015-10-26 09:28:32 +00:00
|
|
|
@add_test_categories(['pyapi'])
|
2015-09-30 10:12:40 +00:00
|
|
|
def test_module_and_section_boundary_condition(self):
|
|
|
|
|
"""Test module and section APIs by passing None when it expects a Python string."""
|
|
|
|
|
self.build()
|
2018-01-19 23:24:35 +00:00
|
|
|
exe = self.getBuildArtifact("a.out")
|
2011-12-19 20:16:22 +00:00
|
|
|
|
|
|
|
|
target = self.dbg.CreateTarget(exe)
|
|
|
|
|
self.assertTrue(target, VALID_TARGET)
|
|
|
|
|
self.assertTrue(target.GetNumModules() > 0)
|
|
|
|
|
|
|
|
|
|
# Hide stdout if not running with '-t' option.
|
|
|
|
|
if not self.TraceOn():
|
|
|
|
|
self.HideStdout()
|
|
|
|
|
|
2015-10-23 17:04:29 +00:00
|
|
|
print("Number of modules for the target: %d" % target.GetNumModules())
|
2011-12-19 20:16:22 +00:00
|
|
|
for module in target.module_iter():
|
2015-10-23 17:04:29 +00:00
|
|
|
print(module)
|
2011-12-19 20:16:22 +00:00
|
|
|
|
|
|
|
|
# Get the executable module at index 0.
|
|
|
|
|
exe_module = target.GetModuleAtIndex(0)
|
|
|
|
|
|
2015-10-23 17:04:29 +00:00
|
|
|
print("Exe module: %s" % str(exe_module))
|
|
|
|
|
print("Number of sections: %d" % exe_module.GetNumSections())
|
2011-12-19 20:16:22 +00:00
|
|
|
|
|
|
|
|
# Boundary condition testings. Should not crash lldb!
|
|
|
|
|
exe_module.FindFirstType(None)
|
|
|
|
|
exe_module.FindTypes(None)
|
|
|
|
|
exe_module.FindGlobalVariables(target, None, 1)
|
2012-02-06 01:44:54 +00:00
|
|
|
exe_module.FindFunctions(None, 0)
|
2011-12-19 20:16:22 +00:00
|
|
|
exe_module.FindSection(None)
|
|
|
|
|
|
|
|
|
|
# Get the section at index 1.
|
|
|
|
|
if exe_module.GetNumSections() > 1:
|
|
|
|
|
sec1 = exe_module.GetSectionAtIndex(1)
|
2015-10-23 17:04:29 +00:00
|
|
|
print(sec1)
|
2011-12-19 20:16:22 +00:00
|
|
|
else:
|
|
|
|
|
sec1 = None
|
|
|
|
|
|
|
|
|
|
if sec1:
|
|
|
|
|
sec1.FindSubSection(None)
|
2011-09-27 23:15:58 +00:00
|
|
|
|
2015-10-26 09:28:32 +00:00
|
|
|
@add_test_categories(['pyapi'])
|
2015-09-30 10:12:40 +00:00
|
|
|
def test_module_compile_unit_iter(self):
|
|
|
|
|
"""Test module's compile unit iterator APIs."""
|
|
|
|
|
self.build()
|
2018-01-19 23:24:35 +00:00
|
|
|
exe = self.getBuildArtifact("a.out")
|
2012-03-16 21:55:42 +00:00
|
|
|
|
|
|
|
|
target = self.dbg.CreateTarget(exe)
|
|
|
|
|
self.assertTrue(target, VALID_TARGET)
|
|
|
|
|
self.assertTrue(target.GetNumModules() > 0)
|
|
|
|
|
|
|
|
|
|
# Hide stdout if not running with '-t' option.
|
|
|
|
|
if not self.TraceOn():
|
|
|
|
|
self.HideStdout()
|
|
|
|
|
|
2015-10-23 17:04:29 +00:00
|
|
|
print("Number of modules for the target: %d" % target.GetNumModules())
|
2012-03-16 21:55:42 +00:00
|
|
|
for module in target.module_iter():
|
2015-10-23 17:04:29 +00:00
|
|
|
print(module)
|
2012-03-16 21:55:42 +00:00
|
|
|
|
|
|
|
|
# Get the executable module at index 0.
|
|
|
|
|
exe_module = target.GetModuleAtIndex(0)
|
|
|
|
|
|
2015-10-23 17:04:29 +00:00
|
|
|
print("Exe module: %s" % str(exe_module))
|
|
|
|
|
print("Number of compile units: %d" % exe_module.GetNumCompileUnits())
|
2012-03-16 21:55:42 +00:00
|
|
|
INDENT = ' ' * 4
|
|
|
|
|
INDENT2 = INDENT * 2
|
|
|
|
|
for cu in exe_module.compile_unit_iter():
|
2015-10-23 17:04:29 +00:00
|
|
|
print(cu)
|
2018-07-03 14:22:44 +00:00
|
|
|
|
|
|
|
|
@add_test_categories(['pyapi'])
|
|
|
|
|
def test_find_compile_units(self):
|
|
|
|
|
"""Exercise SBModule.FindCompileUnits() API."""
|
|
|
|
|
d = {'EXE': 'b.out'}
|
|
|
|
|
self.build(dictionary=d)
|
|
|
|
|
self.setTearDownCleanup(dictionary=d)
|
|
|
|
|
self.find_compile_units(self.getBuildArtifact('b.out'))
|
|
|
|
|
|
|
|
|
|
def find_compile_units(self, exe):
|
|
|
|
|
"""Exercise SBModule.FindCompileUnits() API."""
|
|
|
|
|
source_name_list = ["main.cpp", "b.cpp", "c.cpp"]
|
|
|
|
|
|
|
|
|
|
# Create a target by the debugger.
|
|
|
|
|
target = self.dbg.CreateTarget(exe)
|
|
|
|
|
self.assertTrue(target, VALID_TARGET)
|
|
|
|
|
|
|
|
|
|
num_modules = target.GetNumModules()
|
|
|
|
|
for i in range(num_modules):
|
|
|
|
|
module = target.GetModuleAtIndex(i)
|
|
|
|
|
for source_name in source_name_list:
|
|
|
|
|
list = module.FindCompileUnits(lldb.SBFileSpec(source_name, False))
|
|
|
|
|
for sc in list:
|
|
|
|
|
self.assertTrue(
|
|
|
|
|
sc.GetCompileUnit().GetFileSpec().GetFilename() ==
|
|
|
|
|
source_name)
|