From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13937 invoked by alias); 24 Jun 2010 18:39:22 -0000 Received: (qmail 13926 invoked by uid 22791); 24 Jun 2010 18:39:21 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 24 Jun 2010 18:39:16 +0000 Received: from hpaq12.eem.corp.google.com (hpaq12.eem.corp.google.com [172.25.149.12]) by smtp-out.google.com with ESMTP id o5OIdEwE000478 for ; Thu, 24 Jun 2010 11:39:14 -0700 Received: from vws9 (vws9.prod.google.com [10.241.21.137]) by hpaq12.eem.corp.google.com with ESMTP id o5OIdCAx030839 for ; Thu, 24 Jun 2010 11:39:13 -0700 Received: by vws9 with SMTP id 9so2815507vws.5 for ; Thu, 24 Jun 2010 11:39:12 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.124.196 with SMTP id v4mr5317217vcr.175.1277404752227; Thu, 24 Jun 2010 11:39:12 -0700 (PDT) Received: by 10.220.201.66 with HTTP; Thu, 24 Jun 2010 11:39:11 -0700 (PDT) In-Reply-To: <1277403507-29213-1-git-send-email-brobecker@adacore.com> References: <1277403507-29213-1-git-send-email-brobecker@adacore.com> Date: Thu, 24 Jun 2010 18:39:00 -0000 Message-ID: Subject: Re: [PATCH] Add support for gdb.PYTHONDIR as $gdb_datadir/python. From: Doug Evans To: Joel Brobecker Cc: gdb-patches@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-System-Of-Record: true 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: 2010-06/txt/msg00548.txt.bz2 On Thu, Jun 24, 2010 at 11:18 AM, Joel Brobecker wr= ote: > Here is a new stab at implementing a "pythondir": > > 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. =A0For now, there is nothing there, but it can > now be added easily without further code changes. > > The difference with the previous patch is that this pythondir is no > longer changeable during configure - it's now hardcoded. > > Another tiny differnce is that I named the associated "variable" > in the gdb module as "PYTHONDIR", rather than "pythondir". =A0This is > because Python does not have constants and the usual convention to > name variables that are supposed to be constant is to use all-upper-case. > > > gdb/ChangeLog: > 2010-06-24 =A0Joel Brobecker =A0 > > =A0 =A0 =A0 =A0* python/python.c (_initialize_python): Add new "constant" > =A0 =A0 =A0 =A0PYTHONDIR in gdb module. =A0Insert this path at the head of > =A0 =A0 =A0 =A0sys.path. Set gdb.__path__ to gdb.PYTHONDIR + '/gdb' and > =A0 =A0 =A0 =A0exec its __init__.py script if it exists in that directory. > > Tested on x86_64-linux, no regression. =A0I also verified by hand that > sys.path has the expected path at the start of the list, and that an > import of a script in that directory works as expected. > > I guess documentation and NEWS will have to be written if this patch > goes in... > > --- > =A0gdb/python/python.c | =A0 14 ++++++++++++++ > =A01 files changed, 14 insertions(+), 0 deletions(-) > > diff --git a/gdb/python/python.c b/gdb/python/python.c > index 31880c1..0018816 100644 > --- a/gdb/python/python.c > +++ b/gdb/python/python.c > @@ -668,6 +668,13 @@ Enables or disables printing of Python stack traces.= "), > =A0 PyModule_AddStringConstant (gdb_module, "VERSION", (char*) version); > =A0 PyModule_AddStringConstant (gdb_module, "HOST_CONFIG", (char*) host_n= ame); > =A0 PyModule_AddStringConstant (gdb_module, "TARGET_CONFIG", (char*) targ= et_name); > + =A0{ > + =A0 =A0char *gdb_pythondir; > + > + =A0 =A0gdb_pythondir =3D concat (gdb_datadir, SLASH_STRING, "python", N= ULL); > + =A0 =A0PyModule_AddStringConstant (gdb_module, "PYTHONDIR", gdb_pythond= ir); > + =A0 =A0xfree (gdb_pythondir); > + =A0} > > =A0 gdbpy_gdberror_exc =3D PyErr_NewException ("gdb.GdbError", NULL, NULL= ); > =A0 PyModule_AddObject (gdb_module, "GdbError", gdbpy_gdberror_exc); > @@ -720,6 +727,13 @@ class GdbOutputFile:\n\ > =A0\n\ > =A0sys.stderr =3D GdbOutputFile()\n\ > =A0sys.stdout =3D GdbOutputFile()\n\ > +\n\ > +sys.path.insert(0, gdb.PYTHONDIR)\n\ > +gdb.__path__ =3D [gdb.PYTHONDIR + '/gdb']\n\ > +from os.path import exists\n\ > +ipy =3D gdb.PYTHONDIR + '/gdb/__init__.py'\n\ > +if exists (ipy):\n\ > + =A0execfile (ipy)\n\ > =A0"); > > =A0 /* Release the GIL while gdb runs. =A0*/ > -- > 1.7.1 > > Hi. Looks great to me with one nit. The execfile of __init__.py feels odd. I haven't seen it done elsewhere and I wonder if it's needed. [I know python has __init__.py, I just don't know if we have to *explicitly* exec it.]