aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@gnat.com>2010-06-24 22:52:04 +0000
committerJoel Brobecker <brobecker@gnat.com>2010-06-24 22:52:04 +0000
commitb14285f60edd8d072778b3d6d07d0e1dd0fb52c0 (patch)
tree457d04e36b0c817e18602761a5af9b7f90e37881
parentfd60dc691fb51f108b1e74025e4a2751dced8d32 (diff)
downloadfsf-binutils-gdb-b14285f60edd8d072778b3d6d07d0e1dd0fb52c0.zip
fsf-binutils-gdb-b14285f60edd8d072778b3d6d07d0e1dd0fb52c0.tar.gz
fsf-binutils-gdb-b14285f60edd8d072778b3d6d07d0e1dd0fb52c0.tar.bz2
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_pythondir>/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 <brobecker@adacore.com> * 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.
-rw-r--r--gdb/ChangeLog7
-rw-r--r--gdb/python/python.c21
2 files changed, 28 insertions, 0 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index c94b08c..009c16a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2010-06-24 Joel Brobecker <brobecker@adacore.com>
+
+ * 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.
+
2010-06-24 Kevin Buettner <kevinb@redhat.com>
* rx-tdep.c (RX_ACC_REGNUM): Define.
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. */