From patchwork Tue Aug 20 22:17:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Terekhov, Mikhail via Gdb-patches" X-Patchwork-Id: 34203 Received: (qmail 46159 invoked by alias); 20 Aug 2019 22:18:04 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 46095 invoked by uid 89); 20 Aug 2019 22:18:03 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=silent, sk:with-li, 16186, sk:withli X-HELO: mail-qk1-f202.google.com Received: from mail-qk1-f202.google.com (HELO mail-qk1-f202.google.com) (209.85.222.202) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 20 Aug 2019 22:18:00 +0000 Received: by mail-qk1-f202.google.com with SMTP id m198so43661qke.22 for ; Tue, 20 Aug 2019 15:18:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=eHpREXlV4NbxUKze27AKAn2j+C55WED8bb2KzfmwNls=; b=ppcutMRaKUB9JtHXHRId68NJezvU8+Au53Y41243zY+TozifxN3HOAAc2ZKEs8F7Qv L0ITwXT5h20M0Y4I6Zgny57ODnRP340zcVtx/XsFBCv7phkNRbzk2O6+X+5Vsu29UcQx tJ1UJchhK9rPmwU+47So4HlIdsRd4iChwM35LmhVFUDAsan/8b/oRjibXWCGa1U6MreW RrK501ZJmu3xtIG3Tv3wUNHvoTt4WL0Y4uCBChtfqO3lLezHLP+vaPKTAI5nohfWe43x DwMPrizx5OBB4e3B5cJVvYQLwIiKMHqDX9MnS+D0A3y+pZbQpVAJlIt2bNk8FESm/wVC zF/g== Date: Tue, 20 Aug 2019 17:17:45 -0500 In-Reply-To: <20190820221745.147370-1-cbiesinger@google.com> Message-Id: <20190820221745.147370-4-cbiesinger@google.com> Mime-Version: 1.0 References: <20190820221745.147370-1-cbiesinger@google.com> Subject: [PATCH 3/3] Load system gdbinit files from a directory X-Patchwork-Original-From: "Christian Biesinger via gdb-patches" From: "Terekhov, Mikhail via Gdb-patches" Reply-To: Christian Biesinger To: gdb-patches@sourceware.org Cc: Christian Biesinger X-IsSubscribed: yes gdb/ChangeLog: 2019-08-20 Christian Biesinger * config.in: Add SYSTEM_GDBINIT_DIR. * configure: Regenerate. * configure.ac: Add new option --with-system-gdbinit-dir. * main.c (get_init_files): Change system_gdbinit argument to a vector and return the files in SYSTEM_GDBINIT_DIR in addition to SYSTEM_GDBINIT. (captured_main_1): Update. (print_gdb_help): Update. --- gdb/config.in | 3 ++ gdb/configure | 77 ++++++++++++++++++++++++++++++++++++++++++++---- gdb/configure.ac | 3 ++ gdb/main.c | 53 +++++++++++++++++++++++++++------ 4 files changed, 121 insertions(+), 15 deletions(-) diff --git a/gdb/config.in b/gdb/config.in index 26ca02f6a3..ca523fe4ab 100644 --- a/gdb/config.in +++ b/gdb/config.in @@ -684,6 +684,9 @@ /* automatically load a system-wide gdbinit file */ #undef SYSTEM_GDBINIT +/* automatically load system-wide gdbinit files from this dir */ +#undef SYSTEM_GDBINIT_DIR + /* Define if the system-gdbinit directory should be relocated when GDB is moved. */ #undef SYSTEM_GDBINIT_RELOCATABLE diff --git a/gdb/configure b/gdb/configure index cb71bbf057..e5aa2e6b3b 100755 --- a/gdb/configure +++ b/gdb/configure @@ -693,6 +693,7 @@ WIN32LIBS SER_HARDWIRE WERROR_CFLAGS WARN_CFLAGS +SYSTEM_GDBINIT_DIR SYSTEM_GDBINIT TARGET_SYSTEM_ROOT CONFIG_LDFLAGS @@ -824,6 +825,7 @@ infodir docdir oldincludedir includedir +runstatedir localstatedir sharedstatedir sysconfdir @@ -884,6 +886,7 @@ with_libipt_prefix with_included_regex with_sysroot with_system_gdbinit +with_system_gdbinit_dir enable_werror enable_build_warnings enable_gdb_build_warnings @@ -956,6 +959,7 @@ datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' +runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE}' @@ -1208,6 +1212,15 @@ do | -silent | --silent | --silen | --sile | --sil) silent=yes ;; + -runstatedir | --runstatedir | --runstatedi | --runstated \ + | --runstate | --runstat | --runsta | --runst | --runs \ + | --run | --ru | --r) + ac_prev=runstatedir ;; + -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ + | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ + | --run=* | --ru=* | --r=*) + runstatedir=$ac_optarg ;; + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ @@ -1345,7 +1358,7 @@ fi for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir + libdir localedir mandir runstatedir do eval ac_val=\$$ac_var # Remove trailing slashes. @@ -1498,6 +1511,7 @@ Fine tuning of the installation directories: --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] @@ -1618,6 +1632,9 @@ Optional Packages: --with-sysroot[=DIR] search for usr/lib et al within DIR --with-system-gdbinit=PATH automatically load a system-wide gdbinit file + --with-system-gdbinit-dir=PATH + automatically load system-wide gdbinit files from + this directory --with-lzma support lzma compression (auto/yes/no) --with-liblzma-prefix[=DIR] search for liblzma in DIR/include and DIR/lib --without-liblzma-prefix don't search for liblzma in includedir and libdir @@ -4683,7 +4700,7 @@ else We can't simply define LARGE_OFF_T to be 9223372036854775807, since some C++ compilers masquerading as C compilers incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) +#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; @@ -4729,7 +4746,7 @@ else We can't simply define LARGE_OFF_T to be 9223372036854775807, since some C++ compilers masquerading as C compilers incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) +#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; @@ -4753,7 +4770,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext We can't simply define LARGE_OFF_T to be 9223372036854775807, since some C++ compilers masquerading as C compilers incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) +#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; @@ -4798,7 +4815,7 @@ else We can't simply define LARGE_OFF_T to be 9223372036854775807, since some C++ compilers masquerading as C compilers incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) +#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; @@ -4822,7 +4839,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext We can't simply define LARGE_OFF_T to be 9223372036854775807, since some C++ compilers masquerading as C compilers incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) +#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; @@ -12872,6 +12889,8 @@ main () if (*(data + i) != *(data3 + i)) return 14; close (fd); + free (data); + free (data3); return 0; } _ACEOF @@ -15239,6 +15258,52 @@ _ACEOF +# Check whether --with-system-gdbinit-dir was given. +if test "${with_system_gdbinit_dir+set}" = set; then : + withval=$with_system_gdbinit_dir; + SYSTEM_GDBINIT_DIR=$withval +else + SYSTEM_GDBINIT_DIR= +fi + + + test "x$prefix" = xNONE && prefix="$ac_default_prefix" + test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' + ac_define_dir=`eval echo $SYSTEM_GDBINIT_DIR` + ac_define_dir=`eval echo $ac_define_dir` + +cat >>confdefs.h <<_ACEOF +#define SYSTEM_GDBINIT_DIR "$ac_define_dir" +_ACEOF + + + + + if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then + if test "x$prefix" = xNONE; then + test_prefix=/usr/local + else + test_prefix=$prefix + fi + else + test_prefix=$exec_prefix + fi + value=0 + case ${ac_define_dir} in + "${test_prefix}"|"${test_prefix}/"*|\ + '${exec_prefix}'|'${exec_prefix}/'*) + value=1 + ;; + esac + +cat >>confdefs.h <<_ACEOF +#define SYSTEM_GDBINIT_DIR_RELOCATABLE $value +_ACEOF + + + + + # Check whether --enable-werror was given. if test "${enable_werror+set}" = set; then : enableval=$enable_werror; case "${enableval}" in diff --git a/gdb/configure.ac b/gdb/configure.ac index 5a18c16405..27d67ead3e 100644 --- a/gdb/configure.ac +++ b/gdb/configure.ac @@ -1844,6 +1844,9 @@ GDB_AC_DEFINE_RELOCATABLE(TARGET_SYSTEM_ROOT, sysroot, ${ac_define_dir}) GDB_AC_WITH_DIR(SYSTEM_GDBINIT, system-gdbinit, [automatically load a system-wide gdbinit file], []) +GDB_AC_WITH_DIR(SYSTEM_GDBINIT_DIR, system-gdbinit-dir, + [automatically load system-wide gdbinit files from this directory], + []) AM_GDB_WARNINGS AM_GDB_UBSAN diff --git a/gdb/main.c b/gdb/main.c index a1d1904c9b..39957db4bd 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -45,6 +45,7 @@ #include "event-top.h" #include "infrun.h" #include "gdbsupport/signals-state-save-restore.h" +#include #include #include "gdbsupport/pathstuff.h" #include "cli/cli-style.h" @@ -232,11 +233,11 @@ static std::string relocate_gdbinit_path_maybe_in_datadir (std::string file) to be loaded, then SYSTEM_GDBINIT (resp. HOME_GDBINIT and LOCAL_GDBINIT) is set to the empty string. */ static void -get_init_files (std::string *system_gdbinit, +get_init_files (std::vector *system_gdbinit, std::string *home_gdbinit, std::string *local_gdbinit) { - static std::string sysgdbinit; + static std::vector sysgdbinit; static std::string homeinit; static std::string localinit; static int initialized = 0; @@ -251,7 +252,28 @@ get_init_files (std::string *system_gdbinit, relocate_gdbinit_path_maybe_in_datadir (SYSTEM_GDBINIT); if (!relocated_sysgdbinit.empty () && stat (relocated_sysgdbinit.c_str (), &s) == 0) - sysgdbinit = relocated_sysgdbinit; + sysgdbinit.push_back(relocated_sysgdbinit); + } + if (SYSTEM_GDBINIT_DIR[0]) + { + std::string relocated_gdbinit_dir = + relocate_gdbinit_path_maybe_in_datadir (SYSTEM_GDBINIT_DIR); + DIR* dir; + if (!relocated_gdbinit_dir.empty () && + (dir = opendir (relocated_gdbinit_dir.c_str ())) != nullptr) + { + std::vector files; + struct dirent* ent; + while ((ent = readdir (dir)) != nullptr) + { + if (ent->d_name[0] != '.') + files.push_back (relocated_gdbinit_dir + SLASH_STRING + + ent->d_name); + } + closedir (dir); + std::sort (files.begin (), files.end ()); + sysgdbinit.insert (sysgdbinit.end (), files.begin (), files.end ()); + } } const char *homedir = getenv ("HOME"); @@ -909,7 +931,8 @@ captured_main_1 (struct captured_main_args *context) /* Lookup gdbinit files. Note that the gdbinit file name may be overriden during file initialization, so get_init_files should be called after gdb_init. */ - std::string system_gdbinit, home_gdbinit, local_gdbinit; + std::vector system_gdbinit; + std::string home_gdbinit, local_gdbinit; get_init_files (&system_gdbinit, &home_gdbinit, &local_gdbinit); /* Do these (and anything which might call wrap_here or *_filtered) @@ -987,7 +1010,10 @@ captured_main_1 (struct captured_main_args *context) processed; it sets global parameters, which are independent of what file you are debugging or what directory you are in. */ if (!system_gdbinit.empty () && !inhibit_gdbinit) - ret = catch_command_errors (source_script, system_gdbinit.c_str (), 0); + { + for (const std::string& file : system_gdbinit) + ret = catch_command_errors (source_script, file.c_str (), 0); + } /* Read and execute $HOME/.gdbinit file, if it exists. This is done *before* all the command line arguments are processed; it sets @@ -1205,7 +1231,7 @@ gdb_main (struct captured_main_args *args) static void print_gdb_help (struct ui_file *stream) { - std::string system_gdbinit; + std::vector system_gdbinit; std::string home_gdbinit; std::string local_gdbinit; @@ -1286,9 +1312,18 @@ Other options:\n\n\ At startup, GDB reads the following init files and executes their commands:\n\ "), stream); if (!system_gdbinit.empty ()) - fprintf_unfiltered (stream, _("\ - * system-wide init file: %s\n\ -"), system_gdbinit.c_str ()); + { + std::string output; + for (size_t idx = 0; idx < system_gdbinit.size(); ++idx) + { + output += system_gdbinit[idx]; + if (idx < system_gdbinit.size() - 1) + output += ", "; + } + fprintf_unfiltered (stream, _("\ + * system-wide init files: %s\n\ +"), output.c_str ()); + } if (!home_gdbinit.empty ()) fprintf_unfiltered (stream, _("\ * user-specific init file: %s\n\