From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22854 invoked by alias); 4 Aug 2011 18:31:58 -0000 Received: (qmail 22845 invoked by uid 22791); 4 Aug 2011 18:31:57 -0000 X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 04 Aug 2011 18:31:36 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p74IVana016653 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 4 Aug 2011 14:31:36 -0400 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p74IVYJk002672; Thu, 4 Aug 2011 14:31:35 -0400 From: Phil Muldoon To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [patch][python] Auto-load gdb.command and gdb.function modules References: Reply-to: pmuldoon@redhat.com X-URL: http://www.redhat.com Date: Thu, 04 Aug 2011 18:31:00 -0000 In-Reply-To: (Tom Tromey's message of "Thu, 04 Aug 2011 11:11:52 -0600") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-08/txt/msg00078.txt.bz2 Tom Tromey writes: > Phil> +module_dict = {\ > Phil> +'gdb.function': os.path.join(gdb.PYTHONDIR, 'gdb', 'function'),\ > Phil> +'gdb.command': os.path.join(gdb.PYTHONDIR, 'gdb', 'command')\ > Phil> +} > > You don't need the trailing "\"s, please remove them. > I think the lines in the dict should be indented, that looks better. OK, and to other format issues. > Phil> + print 'Error importing: ', py_file OK. Revised patch attached. ChangeLogs remain the same. -- diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 35fa075..9a0c8db 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -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. diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py index 43975c2..b7b4145 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: + py_file = py_file.rstrip('.py') + py_file = module + '.' + py_file + 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 86923d7..00aa390 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() diff --git a/gdb/python/python.c b/gdb/python/python.c index 16c0a6e..03edce9 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -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\