From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2955 invoked by alias); 24 Jun 2010 18:19:52 -0000 Received: (qmail 2942 invoked by uid 22791); 24 Jun 2010 18:19:50 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD 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 18:19:44 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id BAFCD2BAB98; Thu, 24 Jun 2010 14:19:42 -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 fPAVeYoJJs-j; Thu, 24 Jun 2010 14:19:42 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 856B52BAB93; Thu, 24 Jun 2010 14:19:42 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id 5A961F5894; Thu, 24 Jun 2010 11:19:27 -0700 (PDT) From: Joel Brobecker To: gdb-patches@sourceware.org Cc: Joel Brobecker Subject: [PATCH] Add support for gdb.PYTHONDIR as $gdb_datadir/python. Date: Thu, 24 Jun 2010 18:19:00 -0000 Message-Id: <1277403507-29213-1-git-send-email-brobecker@adacore.com> 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/msg00544.txt.bz2 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. For 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". This 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 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. Tested on x86_64-linux, no regression. I 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... --- gdb/python/python.c | 14 ++++++++++++++ 1 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."), 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,13 @@ class GdbOutputFile:\n\ \n\ sys.stderr = GdbOutputFile()\n\ sys.stdout = GdbOutputFile()\n\ +\n\ +sys.path.insert(0, gdb.PYTHONDIR)\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. */ -- 1.7.1