summaryrefslogtreecommitdiffstats
path: root/lldb/test/python_api/module_section/TestModuleAndSection.py
diff options
context:
space:
mode:
authorJohnny Chen <johnny.chen@apple.com>2011-09-27 23:15:58 +0000
committerJohnny Chen <johnny.chen@apple.com>2011-09-27 23:15:58 +0000
commitb2c7825515ee54dc766cec70a725af265715e1ea (patch)
treefabf2df69315c89decbddba107f3c8b5cbae988d /lldb/test/python_api/module_section/TestModuleAndSection.py
parentf9b71a2e011fb36fa3112071c9cebd236055056d (diff)
downloadbcm5719-llvm-b2c7825515ee54dc766cec70a725af265715e1ea.tar.gz
bcm5719-llvm-b2c7825515ee54dc766cec70a725af265715e1ea.zip
Add a simple test TestModuleAndSection.py to exercise some module/section-related APIs.
In particular, it iterates through the executable module's SBSections, looking for the '__TEXT' section and further iterates on its subsections (of SBSection type, too). llvm-svn: 140654
Diffstat (limited to 'lldb/test/python_api/module_section/TestModuleAndSection.py')
-rw-r--r--lldb/test/python_api/module_section/TestModuleAndSection.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/lldb/test/python_api/module_section/TestModuleAndSection.py b/lldb/test/python_api/module_section/TestModuleAndSection.py
new file mode 100644
index 00000000000..98a8d08ef05
--- /dev/null
+++ b/lldb/test/python_api/module_section/TestModuleAndSection.py
@@ -0,0 +1,54 @@
+"""
+Test some SBModule and SBSection APIs.
+"""
+
+import os, time
+import re
+import unittest2
+import lldb
+from lldbtest import *
+
+class ModuleAndSectionAPIsTestCase(TestBase):
+
+ mydir = os.path.join("python_api", "module_section")
+
+ @python_api_test
+ def test_module_and_section(self):
+ """Test module and section APIs."""
+ self.buildDefault()
+ self.module_and_section()
+
+ def module_and_section(self):
+ exe = os.path.join(os.getcwd(), "a.out")
+
+ 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()
+
+ print "Number of modules for the target: %d" % target.GetNumModules()
+ for module in target.module_iter():
+ print module
+
+ # Get the executable module at index 0.
+ exe_module = target.GetModuleAtIndex(0)
+
+ print "Exe module: %s" % repr(exe_module)
+ print "Number of sections: %d" % exe_module.GetNumSections()
+ INDENT = ' ' * 4
+ for sec in exe_module.section_iter():
+ print sec
+ if sec.GetName() == "__TEXT":
+ print INDENT + "Number of subsections: %d" % sec.GetNumSubSections()
+ for subsec in sec:
+ print INDENT + repr(subsec)
+
+
+if __name__ == '__main__':
+ import atexit
+ lldb.SBDebugger.Initialize()
+ atexit.register(lambda: lldb.SBDebugger.Terminate())
+ unittest2.main()
OpenPOWER on IntegriCloud