From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7348 invoked by alias); 14 Jan 2009 13:56:57 -0000 Received: (qmail 7340 invoked by uid 22791); 14 Jan 2009 13:56:56 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL,BAYES_00,HK_OBFDOM,J_CHICKENPOX_37,J_CHICKENPOX_92 X-Spam-Check-By: sourceware.org Received: from NaN.false.org (HELO nan.false.org) (208.75.86.248) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 14 Jan 2009 13:56:24 +0000 Received: from nan.false.org (localhost [127.0.0.1]) by nan.false.org (Postfix) with ESMTP id ABCBB10729; Wed, 14 Jan 2009 13:56:20 +0000 (GMT) Received: from caradoc.them.org (209.195.188.212.nauticom.net [209.195.188.212]) by nan.false.org (Postfix) with ESMTP id 3F7EB1053D; Wed, 14 Jan 2009 13:56:20 +0000 (GMT) Received: from drow by caradoc.them.org with local (Exim 4.69) (envelope-from ) id 1LN6EF-0006T5-Jg; Wed, 14 Jan 2009 08:56:19 -0500 Date: Wed, 14 Jan 2009 13:56:00 -0000 From: Daniel Jacobowitz To: gdb-patches@sourceware.org Cc: Jerome Guitton , Eli Zaretskii Subject: Add support for --with-system-gdbinit Message-ID: <20090114135619.GA24456@caradoc.them.org> Mail-Followup-To: gdb-patches@sourceware.org, Jerome Guitton , Eli Zaretskii MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.17 (2008-05-11) 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: 2009-01/txt/msg00313.txt.bz2 As described on gdb@ last month, this patch adds support for a system-wide gdbinit file. The path will be automatically relocated if the GDB binary is moved, so it can be used for a system-wide directory like /etc or a prefixed directory like /opt/vendor/share. Eli, is the doc patch OK? -- Daniel Jacobowitz CodeSourcery 2008-12-15 Daniel Jacobowitz * configure, config.in: Regenerated. * configure.ac: Add --with-system-gdbinit. * main.c (system_gdbinit): New. (captured_main): Relocate system_gdbinit. Load it before $HOME/.gdbinit. 2008-12-15 Daniel Jacobowitz * gdb.texinfo (Startup): Document --with-system-gdbinit. Index: config.in =================================================================== RCS file: /cvs/src/src/gdb/config.in,v retrieving revision 1.103 diff -u -p -r1.103 config.in --- config.in 6 Aug 2008 19:41:31 -0000 1.103 +++ config.in 15 Dec 2008 15:40:34 -0000 @@ -646,6 +646,13 @@ /* Define to 1 if you have the ANSI C header files. */ #undef STDC_HEADERS +/* System-wide gdbinit file. */ +#undef SYSTEM_GDBINIT + +/* Define if the system-wide gdbinit file should be relocated when GDB is + moved. */ +#undef SYSTEM_GDBINIT_RELOCATABLE + /* Define if has the TD_NOTALLOC error code. */ #undef THREAD_DB_HAS_TD_NOTALLOC Index: configure =================================================================== RCS file: /cvs/src/src/gdb/configure,v retrieving revision 1.262 diff -u -p -r1.262 configure --- configure 21 Nov 2008 22:35:57 -0000 1.262 +++ configure 15 Dec 2008 15:40:36 -0000 @@ -895,6 +895,7 @@ Optional Packages: on systems with version 2 of the GNU C library (use with caution on other system) --with-sysroot=DIR Search for usr/lib et al within DIR. + --with-system-gdbinit=file Automatically load a system-wide gdbinit file --with-tcl directory containing tcl configuration (tclConfig.sh) --with-tk directory containing tk configuration (tkConfig.sh) --with-x use the X Window System @@ -19417,6 +19418,49 @@ fi; +system_gdbinit= + +# Check whether --with-system-gdbinit or --without-system-gdbinit was given. +if test "${with_system_gdbinit+set}" = set; then + withval="$with_system_gdbinit" + system_gdbinit=${withval} +fi; + + + test "x$prefix" = xNONE && prefix="$ac_default_prefix" + test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' + ac_define_dir=`eval echo $system_gdbinit` + ac_define_dir=`eval echo $ac_define_dir` + +cat >>confdefs.h <<_ACEOF +#define SYSTEM_GDBINIT "$ac_define_dir" +_ACEOF + + + +if test "x$prefix" = xNONE; then + test_prefix=$ac_default_prefix +else + test_prefix=$prefix +fi +if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then + test_exec_prefix=$test_prefix +else + test_exec_prefix=$exec_prefix +fi +case ${system_gdbinit} in + "${test_prefix}"|"${test_prefix}/"*|\ + "${test_exec_prefix}"|"${test_exec_prefix}/"*|\ + '${prefix}'|'${prefix}/'*|\ + '${exec_prefix}'|'${exec_prefix}/'*) + +cat >>confdefs.h <<\_ACEOF +#define SYSTEM_GDBINIT_RELOCATABLE 1 +_ACEOF + + ;; +esac + # Check whether --enable-werror or --disable-werror was given. if test "${enable_werror+set}" = set; then enableval="$enable_werror" Index: configure.ac =================================================================== RCS file: /cvs/src/src/gdb/configure.ac,v retrieving revision 1.82 diff -u -p -r1.82 configure.ac --- configure.ac 21 Nov 2008 22:35:58 -0000 1.82 +++ configure.ac 15 Dec 2008 15:40:36 -0000 @@ -1488,6 +1488,34 @@ AC_ARG_WITH(sysroot, AC_SUBST(TARGET_SYSTEM_ROOT) AC_SUBST(TARGET_SYSTEM_ROOT_DEFINE) +system_gdbinit= +AC_ARG_WITH(system-gdbinit, +[ --with-system-gdbinit=file Automatically load a system-wide gdbinit file], +[system_gdbinit=${withval}]) + +AC_DEFINE_DIR(SYSTEM_GDBINIT, system_gdbinit, + [System-wide gdbinit file.]) + +if test "x$prefix" = xNONE; then + test_prefix=$ac_default_prefix +else + test_prefix=$prefix +fi +if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then + test_exec_prefix=$test_prefix +else + test_exec_prefix=$exec_prefix +fi +case ${system_gdbinit} in + "${test_prefix}"|"${test_prefix}/"*|\ + "${test_exec_prefix}"|"${test_exec_prefix}/"*|\ + '${prefix}'|'${prefix}/'*|\ + '${exec_prefix}'|'${exec_prefix}/'*) + AC_DEFINE(SYSTEM_GDBINIT_RELOCATABLE, 1, + [Define if the system-wide gdbinit file should be relocated when GDB is moved.]) + ;; +esac + AC_ARG_ENABLE(werror, [ --enable-werror treat compile warnings as errors], [case "${enableval}" in Index: main.c =================================================================== RCS file: /cvs/src/src/gdb/main.c,v retrieving revision 1.70 diff -u -p -r1.70 main.c --- main.c 29 Jul 2008 14:16:15 -0000 1.70 +++ main.c 15 Dec 2008 15:40:36 -0000 @@ -83,6 +83,9 @@ int return_child_result_value = -1; /* Whether to enable writing into executable and core files */ extern int write_files; +/* The system-wide gdbinit file. */ +static char *system_gdbinit = SYSTEM_GDBINIT; + static void print_gdb_help (struct ui_file *); /* These two are used to set the external editor commands when gdb is farming @@ -268,6 +271,24 @@ captured_main (void *data) } } +#ifdef SYSTEM_GDBINIT_RELOCATABLE + system_gdbinit = make_relative_prefix (argv[0], BINDIR, SYSTEM_GDBINIT); + if (system_gdbinit) + { + struct stat s; + int res = 0; + + if (stat (system_gdbinit, &s) == 0) + res = 1; + + if (res == 0) + { + xfree (system_gdbinit); + system_gdbinit = SYSTEM_GDBINIT; + } + } +#endif + /* There will always be an interpreter. Either the one passed into this captured main, or one specified by the user at start up, or the console. Initialize the interpreter to the one requested by @@ -679,6 +700,13 @@ Excess command line arguments ignored. ( quit_pre_print = error_pre_print; warning_pre_print = _("\nwarning: "); + /* Read and execute the system-wide gdbinit file, if it exists. + This is done *before* all the command line arguments are + processed; it sets global parameters, which are independent of + what file you are debugging or what directory you are in. */ + if (system_gdbinit[0] && !inhibit_gdbinit) + catch_command_errors (source_script, system_gdbinit, 0, RETURN_MASK_ALL); + /* Read and execute $HOME/.gdbinit file, if it exists. This is done *before* all the command line arguments are processed; it sets global parameters, which are independent of what file you are Index: doc/gdb.texinfo =================================================================== RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v retrieving revision 1.537 diff -u -p -r1.537 gdb.texinfo --- doc/gdb.texinfo 27 Nov 2008 09:23:01 -0000 1.537 +++ doc/gdb.texinfo 15 Dec 2008 15:40:42 -0000 @@ -1219,6 +1219,10 @@ Sets up the command interpreter as speci @item @cindex init file +Reads the system-wide @dfn{init file} (if @option{--with-system-gdbinit} was +used when building @value{GDBN}) and executes all the commands in that file. + +@item Reads the @dfn{init file} (if any) in your home directory@footnote{On DOS/Windows systems, the home directory is the one pointed to by the @code{HOME} environment variable.} and executes all the commands in