]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
2011-08-09 Phil Muldoon <pmuldoon@redhat.com>
authorPhil Muldoon <pmuldoon@redhat.com>
Tue, 9 Aug 2011 12:45:40 +0000 (12:45 +0000)
committerPhil Muldoon <pmuldoon@redhat.com>
Tue, 9 Aug 2011 12:45:40 +0000 (12:45 +0000)
* 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  <pmuldoon@redhat.com>

* gdb.texinfo (Python): Document command and function
auto-loading.

gdb/ChangeLog
gdb/NEWS
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/python/lib/gdb/__init__.py
gdb/python/lib/gdb/command/pretty_printers.py
gdb/python/python.c

index ab1e2f823e759e93bfbe80b7f5e41d753c903493..ac421f1782a527002c138b2603b6b945a3215bac 100644 (file)
@@ -1,3 +1,13 @@
+2011-08-09  Phil Muldoon  <pmuldoon@redhat.com>
+
+       * 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-08  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
        * dwarf2loc.c (dwarf2_evaluate_loc_desc_full) <DWARF_VALUE_STACK>
index b0da564c36bde288a7d8c1887275bcdeb097867c..da558508151ffe75972aa280410d8f2695ac094d 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
   ** A prompt subsitution hook (prompt_hook) is now available to the
      Python API.
 
+  ** Python commands and convenience-functions located in
+    'data-directory'/python/gdb/command and
+    'data-directory'/python/gdb/function are now automatically loaded
+     on GDB start-up.
+
 * libthread-db-search-path now supports two special values: $sdir and $pdir.
   $sdir specifies the default system locations of shared libraries.
   $pdir specifies the directory where the libpthread used by the application
index ea27a62b5c74826d4a3d71099abf2428b9298b51..dbef2b11b20d20a6372cfe031d9dffc2ab4601e4 100644 (file)
@@ -1,3 +1,8 @@
+2011-08-09  Phil Muldoon  <pmuldoon@redhat.com>
+
+       * gdb.texinfo (Python): Document command and function
+       auto-loading.
+
 2011-07-26  Jan Kratochvil  <jan.kratochvil@redhat.com>
            Eli Zaretskii  <eliz@gnu.org>
 
index 35fa075d775880d9fb3cba6c88390b7e914e7781..9a0c8dbb11bf6b66a6fc936c5568f57d04e6eda6 100644 (file)
@@ -20845,6 +20845,12 @@ This directory, known as the @dfn{python directory},
 is automatically added to the Python Search Path in order to allow
 the Python interpreter to locate all scripts installed at this location.
 
+Additionally, @value{GDBN} commands and convenience functions which
+are written in Python and are located in the
+@file{@var{data-directory}/python/gdb/command} or
+@file{@var{data-directory}/python/gdb/function} directories are
+automatically imported when @value{GDBN} starts.
+
 @menu
 * Python Commands::             Accessing Python from @value{GDBN}.
 * Python API::                  Accessing @value{GDBN} from Python.
index 43975c2819a2d9c7f675f703d498b0d39172957a..190213274c124b304820e2901567020bc798c3fb 100644 (file)
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-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()
index 86923d7cf85992ae61007acbad9d3c24e0473e16..00aa390528c27a3753ca813712f3b3b205d00f48 100644 (file)
@@ -368,3 +368,5 @@ def register_pretty_printer_commands():
     InfoPrettyPrinter()
     EnablePrettyPrinter()
     DisablePrettyPrinter()
+
+register_pretty_printer_commands()
index 16c0a6e27b4fec6360e8416aa9d0942a90e56fc3..03edce9e9a2858bc920ead2f7beccdd57d842c13 100644 (file)
@@ -1302,13 +1302,13 @@ def GdbSetPythonDirectory (dir):\n\
   sys.path.insert (0, gdb.PYTHONDIR)\n\
 \n\
   # Tell python where to find submodules of gdb.\n\
-  gdb.__path__ = [gdb.PYTHONDIR + '/gdb']\n\
+  gdb.__path__ = [os.path.join (gdb.PYTHONDIR, 'gdb')]\n\
 \n\
   # The gdb module is implemented in C rather than in Python.  As a result,\n\
   # the associated __init.py__ script is not not executed by default when\n\
   # the gdb module gets imported.  Execute that script manually if it\n\
   # exists.\n\
-  ipy = gdb.PYTHONDIR + '/gdb/__init__.py'\n\
+  ipy = os.path.join (gdb.PYTHONDIR, 'gdb', '__init__.py')\n\
   if os.path.exists (ipy):\n\
     execfile (ipy)\n\
 \n\