From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15548 invoked by alias); 2 Apr 2009 20:54:12 -0000 Received: (qmail 15539 invoked by uid 22791); 2 Apr 2009 20:54:11 -0000 X-SWARE-Spam-Status: No, hits=0.5 required=5.0 tests=AWL,BAYES_50,J_CHICKENPOX_24,J_CHICKENPOX_34,J_CHICKENPOX_36,J_CHICKENPOX_37,J_CHICKENPOX_39,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx2.redhat.com (HELO mx2.redhat.com) (66.187.237.31) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 02 Apr 2009 20:54:06 +0000 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n32Ks4sp027018 for ; Thu, 2 Apr 2009 16:54:04 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n32Ks5os008954; Thu, 2 Apr 2009 16:54:05 -0400 Received: from opsy.redhat.com (vpn-12-111.rdu.redhat.com [10.11.12.111]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n32Ks31N032116; Thu, 2 Apr 2009 16:54:04 -0400 Received: by opsy.redhat.com (Postfix, from userid 500) id 3BAC33784C0; Thu, 2 Apr 2009 14:54:02 -0600 (MDT) To: gdb-patches@sourceware.org Subject: Python pretty-printing [1/6] From: Tom Tromey Reply-To: tromey@redhat.com Date: Thu, 02 Apr 2009 20:54:00 -0000 Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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: 2009-04/txt/msg00045.txt.bz2 This is the first in a series of patches which implement the long-discussed Python pretty-printing feature. This patch imports --with-gdb-data from S=C3=A9rgio's syscall patch. It also adds --with-pythondir and arranges for some Python variables to be set appropriately. This code is needed as the basis of the auto-loading patch. Tom 2009-01-25 Sergio Durigan Junior Tom Tromey * configure, config.in: Regenerate. * configure.ac: Support for relocatable GDB datadir. Add --with-pythondir. * python/python.c (_initialize_python): Set pythondir or datadir as needed. Update sys.path. * maint.c (_initialize_maint_cmds): Add "maint set gdb_datadir". * defs.h (gdb_datadir): Declare. * main.c (gdb_datadir): New global. (captured_main): Initialize gdb_datadir. gdb/ChangeLog | 13 ++++++++ gdb/config.in | 9 ++++++ gdb/configure | 77 +++++++++++++++++++++++++++++++++++++++++++++++= +++- gdb/configure.ac | 45 +++++++++++++++++++++++++++++ gdb/defs.h | 3 ++ gdb/main.c | 37 ++++++++++++++++++++++++ gdb/maint.c | 8 +++++ gdb/python/python.c | 15 ++++++++++ 8 files changed, 206 insertions(+), 1 deletions(-) diff --git a/gdb/configure.ac b/gdb/configure.ac index 821dffe..9bca6c6 100644 --- a/gdb/configure.ac +++ b/gdb/configure.ac @@ -118,6 +118,51 @@ case ${debugdir} in ;; esac =20 +# GDB's datadir relocation + +gdbdatadir=3D${datadir}/gdb + +AC_ARG_WITH([gdb-datadir], + [AS_HELP_STRING([--with-gdb-datadir], + [look for global separate data files in this path [DATAD= IR/gdb]])], [gdbdatadir=3D"${withval}"]) + +AC_DEFINE_DIR(GDB_DATADIR, gdbdatadir, + [Global directory for GDB data files. ]) + +if test "x$exec_prefix" =3D xNONE || test "x$exec_prefix" =3D 'x${prefix}'= ; then + if test "x$prefix" =3D xNONE; then + test_prefix=3D/usr/local + else + test_prefix=3D$prefix + fi +else + test_prefix=3D$exec_prefix +fi + +case ${gdbdatadir} in + "${test_prefix}"|"${test_prefix}/"*|\ + '${exec_prefix}'|'${exec_prefix}/'*) + AC_DEFINE(GDB_DATADIR_RELOCATABLE, 1, [Define if GDB datadir should be= relocated when GDB is moved.]) + ;; +esac +GDB_DATADIR_PATH=3D${gdbdatadir} +AC_SUBST(GDB_DATADIR_PATH) + +AC_ARG_WITH([pythondir], + [AS_HELP_STRING([--with-pythondir], + [install Python data files in this path [DATADIR/gdb/pyt= hon]])], [pythondir=3D"${withval}"], [pythondir=3Dno]) + +# If the user passed in a path, define it. Otherwise, compute it at +# runtime based on the possibly-relocatable datadir. +if test "$pythondir" =3D "no"; then + pythondir=3D'$(GDB_DATADIR_PATH)/python' +else + AC_DEFINE_UNQUOTED(PYTHONDIR, "$pythondir", + [Define to install path for Python sources]) +fi +AC_SUBST(pythondir) + + AC_CONFIG_SUBDIRS(doc testsuite) =20 # Check whether to support alternative target configurations diff --git a/gdb/defs.h b/gdb/defs.h index 882a844..ee80659 100644 --- a/gdb/defs.h +++ b/gdb/defs.h @@ -153,6 +153,9 @@ extern int dbx_commands; /* System root path, used to find libraries etc. */ extern char *gdb_sysroot; =20 +/* GDB datadir, used to store data files. */ +extern char *gdb_datadir; + /* Search path for separate debug files. */ extern char *debug_file_directory; =20 diff --git a/gdb/main.c b/gdb/main.c index 5d4640b..fe65dc5 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -62,6 +62,9 @@ int dbx_commands =3D 0; /* System root path, used to find libraries etc. */ char *gdb_sysroot =3D 0; =20 +/* GDB datadir, used to store data files. */ +char *gdb_datadir =3D 0; + struct ui_file *gdb_stdout; struct ui_file *gdb_stderr; struct ui_file *gdb_stdlog; @@ -357,6 +360,40 @@ captured_main (void *data) } } =20 +#ifdef GDB_DATADIR_RELOCATABLE + gdb_datadir =3D make_relative_prefix (argv[0], BINDIR, GDB_DATADIR); + if (gdb_datadir) + { + struct stat s; + int res =3D 0; + + if (stat (gdb_datadir, &s) =3D=3D 0) + if (S_ISDIR (s.st_mode)) + res =3D 1; + + if (res =3D=3D 0) + { + xfree (gdb_datadir); + gdb_datadir =3D xstrdup (GDB_DATADIR); + } + } + else + gdb_datadir =3D xstrdup (GDB_DATADIR); +#else + gdb_datadir =3D xstrdup (GDB_DATADIR); +#endif /* GDB_DATADIR_RELOCATABLE */ + + /* Canonicalize the GDB's datadir path. */ + if (*gdb_datadir) + { + char *canon_debug =3D lrealpath (gdb_datadir); + if (canon_debug) + { + xfree (gdb_datadir); + gdb_datadir =3D canon_debug; + } + } + get_init_files (&system_gdbinit, &home_gdbinit, &local_gdbinit); =20 /* There will always be an interpreter. Either the one passed into diff --git a/gdb/maint.c b/gdb/maint.c index 56cafe9..1b57ff5 100644 --- a/gdb/maint.c +++ b/gdb/maint.c @@ -906,4 +906,12 @@ When enabled GDB is profiled."), show_maintenance_profile_p, &maintenance_set_cmdlist, &maintenance_show_cmdlist); + add_setshow_filename_cmd ("gdb_datadir", class_maintenance, + &gdb_datadir, _("Set GDB's datadir path."), + _("Show GDB's datadir path."), + _("\ +When set, GDB uses the specified path to search for data files."), + NULL, NULL, + &maintenance_set_cmdlist, + &maintenance_show_cmdlist); } diff --git a/gdb/python/python.c b/gdb/python/python.c index b48cf05..1762c46 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -409,6 +409,12 @@ 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); +#ifdef PYTHONDIR + PyModule_AddStringConstant (gdb_module, "pythondir", PYTHONDIR); +#else + if (gdb_datadir) + PyModule_AddStringConstant (gdb_module, "datadir", gdb_datadir); +#endif =20 gdbpy_initialize_values (); gdbpy_initialize_commands (); @@ -442,6 +448,15 @@ class GdbOutputFile:\n\ \n\ sys.stderr =3D GdbOutputFile()\n\ sys.stdout =3D GdbOutputFile()\n\ +if hasattr (gdb, 'datadir'):\n\ + gdb.pythondir =3D gdb.datadir + '/python'\n\ +if hasattr (gdb, 'pythondir'):\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\ + execfile (ipy)\n\ "); =20 /* Release the GIL while gdb runs. */ --=20 1.6.0.6