From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16880 invoked by alias); 24 Jun 2010 22:53:52 -0000 Received: (qmail 16871 invoked by uid 22791); 24 Jun 2010 22:53:52 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 24 Jun 2010 22:53:47 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id DBD962BACCD; Thu, 24 Jun 2010 18:53:45 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id IWVAu0nLbnlR; Thu, 24 Jun 2010 18:53:45 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id A38522BACC1; Thu, 24 Jun 2010 18:53:45 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id 0D443F5894; Thu, 24 Jun 2010 15:53:30 -0700 (PDT) Date: Thu, 24 Jun 2010 22:53:00 -0000 From: Joel Brobecker To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] Add support for gdb.PYTHONDIR as $gdb_datadir/python. Message-ID: <20100624225329.GL2595@adacore.com> References: <1277403507-29213-1-git-send-email-brobecker@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="liOOAslEiF7prFVr" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) 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: 2010-06/txt/msg00565.txt.bz2 --liOOAslEiF7prFVr Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 494 > Joel> 2010-06-24 Joel Brobecker > Joel> * python/python.c (_initialize_python): Add new "constant" > Joel> PYTHONDIR in gdb module. Insert this path at the head of > Joel> sys.path. Set gdb.__path__ to gdb.PYTHONDIR + '/gdb' and > Joel> exec its __init__.py script if it exists in that directory. > > This is fine with me. Thanks! Following Doug's comments, here is the patch that I just checked in. NEWS and docs next. -- Joel --liOOAslEiF7prFVr Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="pythondir-commented.diff" Content-length: 2502 commit 2de53ec24130ae79b8f5eb138185173f900ccb29 Author: Joel Brobecker Date: Thu Jun 24 10:59:55 2010 -0700 Add support for gdb.PYTHONDIR as $gdb_datadir/python. Python scripts to be used by GDB can be stored in that directory, and will be automatically found by the interpreter when importing them. This patch also sets up /gdb as the directory where gdb submodules can be stored. For now, there is nothing there, but it can now be added easily without further code changes. gdb/ChangeLog: 2010-06-24 Joel Brobecker * python/python.c (_initialize_python): Add new "constant" PYTHONDIR in gdb module. Insert this path at the head of sys.path. Set gdb.__path__ to gdb.PYTHONDIR + '/gdb' and exec its __init__.py script if it exists in that directory. diff --git a/gdb/python/python.c b/gdb/python/python.c index 31880c1..18b2cdc 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -668,6 +668,13 @@ Enables or disables printing of Python stack traces."), PyModule_AddStringConstant (gdb_module, "VERSION", (char*) version); PyModule_AddStringConstant (gdb_module, "HOST_CONFIG", (char*) host_name); PyModule_AddStringConstant (gdb_module, "TARGET_CONFIG", (char*) target_name); + { + char *gdb_pythondir; + + gdb_pythondir = concat (gdb_datadir, SLASH_STRING, "python", NULL); + PyModule_AddStringConstant (gdb_module, "PYTHONDIR", gdb_pythondir); + xfree (gdb_pythondir); + } gdbpy_gdberror_exc = PyErr_NewException ("gdb.GdbError", NULL, NULL); PyModule_AddObject (gdb_module, "GdbError", gdbpy_gdberror_exc); @@ -720,6 +727,20 @@ class GdbOutputFile:\n\ \n\ sys.stderr = GdbOutputFile()\n\ sys.stdout = GdbOutputFile()\n\ +\n\ +# GDB's python scripts are stored inside gdb.PYTHONDIR. So insert\n\ +# that directory name at the start of sys.path to allow the Python\n\ +# interpreter to find them.\n\ +sys.path.insert(0, gdb.PYTHONDIR)\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 exists.\n\ +gdb.__path__ = [gdb.PYTHONDIR + '/gdb']\n\ +from os.path import exists\n\ +ipy = gdb.PYTHONDIR + '/gdb/__init__.py'\n\ +if exists (ipy):\n\ + execfile (ipy)\n\ "); /* Release the GIL while gdb runs. */ --liOOAslEiF7prFVr--