From 5e239b84ac58a9edfc0d942ef751a78aac4c007b Mon Sep 17 00:00:00 2001 From: Phil Muldoon Date: Tue, 9 Aug 2011 12:45:40 +0000 Subject: 2011-08-09 Phil Muldoon * python/lib/gdb/__init__.py: Auto-load files in command and function directories. * python/python.c (finish_python_initialization): Use os.path.join. * python/lib/gdb/command/pretty_printers.py: Self register command. * NEWS: Document auto-loading. 2011-08-09 Phil Muldoon * gdb.texinfo (Python): Document command and function auto-loading. --- gdb/python/lib/gdb/__init__.py | 27 +++++++++++++++++++++++++-- gdb/python/lib/gdb/command/pretty_printers.py | 2 ++ 2 files changed, 27 insertions(+), 2 deletions(-) (limited to 'gdb/python/lib') diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py index 43975c2819a..190213274c1 100644 --- a/gdb/python/lib/gdb/__init__.py +++ b/gdb/python/lib/gdb/__init__.py @@ -13,6 +13,29 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import gdb.command.pretty_printers +import traceback -gdb.command.pretty_printers.register_pretty_printer_commands() +# Auto-load all functions/commands. + +# Modules to auto-load, and the paths where those modules exist. + +module_dict = { + 'gdb.function': os.path.join(gdb.PYTHONDIR, 'gdb', 'function'), + 'gdb.command': os.path.join(gdb.PYTHONDIR, 'gdb', 'command') +} + +# Iterate the dictionary, collating the Python files in each module +# path. Construct the module name, and import. + +for module, location in module_dict.iteritems(): + if os.path.exists(location): + py_files = filter(lambda x: x.endswith('.py') and x != '__init__.py', + os.listdir(location)) + + for py_file in py_files: + # Construct from foo.py, gdb.module.foo + py_file = module + '.' + py_file[:-3] + try: + exec('import ' + py_file) + except: + print >> sys.stderr, traceback.format_exc() diff --git a/gdb/python/lib/gdb/command/pretty_printers.py b/gdb/python/lib/gdb/command/pretty_printers.py index 86923d7cf85..00aa390528c 100644 --- a/gdb/python/lib/gdb/command/pretty_printers.py +++ b/gdb/python/lib/gdb/command/pretty_printers.py @@ -368,3 +368,5 @@ def register_pretty_printer_commands(): InfoPrettyPrinter() EnablePrettyPrinter() DisablePrettyPrinter() + +register_pretty_printer_commands() -- cgit v1.2.1