public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/7] Adding startup files to GDB
@ 2020-10-07 20:05 Andrew Burgess
  2020-10-07 20:05 ` [PATCH 1/7] Add get_standard_config_dir function Andrew Burgess
                   ` (8 more replies)
  0 siblings, 9 replies; 24+ messages in thread
From: Andrew Burgess @ 2020-10-07 20:05 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey, Andrew Burgess

This series borrows heavily from some work that Tom submitted here:

  https://sourceware.org/pipermail/gdb-patches/2020-June/169821.html

This work replaces patches 4 -> 7 of Tom's original series.  Patches
1->3 of the original work are unrelated and are not impacted by this
series.

Looking at what I'm submitting here, my patches #1, #6 and #7 are
taken directly from Tom's original series with only very minor tweaks.

Patches #2, #3, #4, and #5 are significantly different than Tom's
original work though.

First, the motivation for this series - there are some parts of GDB
that can't currently be controlled with normal settings, as the point
at which the action is performed in GDB is earlier than the current
config files and command line options are processed.

This series introduces a new set of command line options and config
files that can be read very early during the startup process, these
files/command line flags can then be used to control the very early
actions that would otherwise not be user controllable.

Right now there are just two such settings added in this series, but
it is hoped that over time we might be able to add more.

Next I'll describe what the patches I wrote do, and the significant
differences to the series Tom put forward:

Patch #2 makes GDB look for .gdbinit in the standard config directory,
this makes this consistent between the standard init file and the new
startup file.  This is new work in this series.

Patch #3 is just a small refactor in preparation for later patches.

Patch #4 adds the startup file support.  Compared to Tom's original work:
   (a) there's no auto saving of startup options,
   
   (b) there's command line flag support for passing startup options
       to GDB.
   
   (c) there's support for a home directory and current working
       directory startup file (only because this is basically free
       given the restructuring of the code).

Patch #5 adds back the auto-save feature from Tom's series, however, I
have this off by default.  I (personally) dislike the auto-save
feature, though I can see why some users might want it.  I hope the
proposal I have here is might be a good middle ground.

There's some pretty extensive documentation changes in this series,
which I'm sure will need some serious polish before this is ready to
commit.

---

Andrew Burgess (4):
  gdb: use get_standard_config_dir when looking for .gdbinit
  gdb: new function to wrap up executing command line scripts/commands
  gdb: process startup files and startup command line options
  gdb: add mechanism to auto-save startup options

Tom Tromey (3):
  Add get_standard_config_dir function
  Let the user control the startup style
  Add "set startup-quietly"

 gdb/ChangeLog                      |  72 ++++++
 gdb/NEWS                           |  31 +++
 gdb/auto-load.c                    |  27 ++-
 gdb/cli/cli-setshow.c              | 122 +++++++++-
 gdb/cli/cli-setshow.h              |  23 ++
 gdb/cli/cli-style.c                |  36 ++-
 gdb/cli/cli-style.h                |   9 +-
 gdb/config.in                      |   3 +
 gdb/configure                      |   6 +
 gdb/configure.ac                   |   3 +
 gdb/doc/ChangeLog                  |  31 +++
 gdb/doc/gdb.texinfo                | 364 +++++++++++++++++++++-------
 gdb/main.c                         | 370 ++++++++++++++++++++---------
 gdb/main.h                         |   5 +
 gdb/testsuite/ChangeLog            |   8 +
 gdb/testsuite/gdb.base/persist.exp |  68 ++++++
 gdb/top.c                          |  45 +++-
 gdb/top.h                          |   5 +
 gdbsupport/ChangeLog               |   5 +
 gdbsupport/pathstuff.cc            |  81 +++++++
 gdbsupport/pathstuff.h             |  37 +++
 21 files changed, 1148 insertions(+), 203 deletions(-)
 create mode 100644 gdb/testsuite/gdb.base/persist.exp

-- 
2.25.4


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 1/7] Add get_standard_config_dir function
  2020-10-07 20:05 [PATCH 0/7] Adding startup files to GDB Andrew Burgess
@ 2020-10-07 20:05 ` Andrew Burgess
  2020-10-07 20:05 ` [PATCH 2/7] gdb: use get_standard_config_dir when looking for .gdbinit Andrew Burgess
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 24+ messages in thread
From: Andrew Burgess @ 2020-10-07 20:05 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

From: Tom Tromey <tom@tromey.com>

This adds a new get_standard_config_dir, which returns the name of the
configuration directory.  In XDG, this is ~/.config/gdb/.  Future
patches will make use of this.

2020-07-05  Tom Tromey  <tom@tromey.com>

	* pathstuff.h (get_standard_config_dir): Declare.
	* pathstuff.cc (get_standard_config_dir): New function.
---
 gdbsupport/ChangeLog    |  5 +++++
 gdbsupport/pathstuff.cc | 32 ++++++++++++++++++++++++++++++++
 gdbsupport/pathstuff.h  | 14 ++++++++++++++
 3 files changed, 51 insertions(+)

diff --git a/gdbsupport/pathstuff.cc b/gdbsupport/pathstuff.cc
index 1f60fd0c986..9fb5e5cf614 100644
--- a/gdbsupport/pathstuff.cc
+++ b/gdbsupport/pathstuff.cc
@@ -266,6 +266,38 @@ get_standard_temp_dir ()
 #endif
 }
 
+/* See pathstuff.h.  */
+
+std::string
+get_standard_config_dir ()
+{
+#ifdef __APPLE__
+#define HOME_CONFIG_DIR "Library/Preferences"
+#else
+#define HOME_CONFIG_DIR ".config"
+#endif
+
+#ifndef __APPLE__
+  const char *xdg_config_home = getenv ("XDG_CONFIG_HOME");
+  if (xdg_config_home != NULL)
+    {
+      /* Make sure the path is absolute and tilde-expanded.  */
+      gdb::unique_xmalloc_ptr<char> abs (gdb_abspath (xdg_config_home));
+      return string_printf ("%s/gdb", abs.get ());
+    }
+#endif
+
+  const char *home = getenv ("HOME");
+  if (home != NULL)
+    {
+      /* Make sure the path is absolute and tilde-expanded.  */
+      gdb::unique_xmalloc_ptr<char> abs (gdb_abspath (home));
+      return string_printf ("%s/" HOME_CONFIG_DIR "/gdb", abs.get ());
+    }
+
+  return {};
+}
+
 /* See gdbsupport/pathstuff.h.  */
 
 const char *
diff --git a/gdbsupport/pathstuff.h b/gdbsupport/pathstuff.h
index 4bc0d892119..85241bc8c7c 100644
--- a/gdbsupport/pathstuff.h
+++ b/gdbsupport/pathstuff.h
@@ -85,6 +85,20 @@ extern std::string get_standard_cache_dir ();
 
 extern std::string get_standard_temp_dir ();
 
+/* Get the usual user config directory for the current platform.
+
+   On Linux, it follows the XDG Base Directory specification: use
+   $XDG_CONFIG_HOME/gdb if the XDG_CONFIG_HOME environment variable is
+   defined, otherwise $HOME/.config.
+
+   On macOS, it follows the local convention and uses
+   ~/Library/Preferences/gdb.
+
+  The return value is absolute and tilde-expanded.  Return an empty
+  string if neither XDG_CONFIG_HOME (on Linux) or HOME are defined.  */
+
+extern std::string get_standard_config_dir ();
+
 /* Return the file name of the user's shell.  Normally this comes from
    the SHELL environment variable.  */
 
-- 
2.25.4


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 2/7] gdb: use get_standard_config_dir when looking for .gdbinit
  2020-10-07 20:05 [PATCH 0/7] Adding startup files to GDB Andrew Burgess
  2020-10-07 20:05 ` [PATCH 1/7] Add get_standard_config_dir function Andrew Burgess
@ 2020-10-07 20:05 ` Andrew Burgess
  2020-10-08  6:52   ` Eli Zaretskii
                     ` (2 more replies)
  2020-10-07 20:05 ` [PATCH 3/7] gdb: new function to wrap up executing command line scripts/commands Andrew Burgess
                   ` (6 subsequent siblings)
  8 siblings, 3 replies; 24+ messages in thread
From: Andrew Burgess @ 2020-10-07 20:05 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey, Andrew Burgess

This commit effectively changes the default location of the .gdbinit
file, while maintaining backward compatibility.

For non Apple hosts the .gdbinit file will now be looked for in the
following locations:

  $XDG_CONFIG_HOME/gdb/gdbinit
  $HOME/.config/gdb/gdbinit
  $HOME/.gdbinit

On Apple hosts the search order is instead:

  $HOME/Library/Preferences/gdb/gdbinit
  $HOME/.gdbinit

I've performed an extensive rewrite of the documentation, moving all
information about initialization files and where to find them into a
new @node, text from other areas has been moved into this one
location, and other areas cross-reference to this new @node as much as
possible.

gdb/ChangeLog:

	* NEWS: Mention changes to config file search path.
	* main.c

gdb/doc/ChangeLog:

	* gdb.texinfo (Mode Options): Descriptions of initialization files
	has been moved to 'Initialization Files'.
	(Startup): Likewise.
	(Initialization Files): New node.
	(gdb man): Update to mention alternative file paths.
	(gdbinit man): Likewise.
---
 gdb/ChangeLog           |   5 +
 gdb/NEWS                |   6 ++
 gdb/auto-load.c         |  27 ++++--
 gdb/doc/ChangeLog       |   9 ++
 gdb/doc/gdb.texinfo     | 207 +++++++++++++++++++++++++---------------
 gdb/main.c              |  13 +--
 gdbsupport/pathstuff.cc |  49 ++++++++++
 gdbsupport/pathstuff.h  |  23 +++++
 8 files changed, 246 insertions(+), 93 deletions(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index d230b1c3228..c64dda7bbcb 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -15,6 +15,12 @@
 
 * GDB now supports core file debugging for x86_64 Cygwin programs.
 
+* GDB will now look for the .gdbinit file in a config directory before
+  looking for ~/.gdbinit.  The file is searched for in the following
+  locations: $XDG_CONFIG_HOME/gdb/gdbinit, $HOME/.config/gdb/gdbinit,
+  $HOME/.gdbinit.  On Apple hosts the search order is instead:
+  $HOME/Library/Preferences/gdb/gdbinit, $HOME/.gdbinit.
+
 * New commands
 
 set debug event-loop
diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index 43d007ca5b0..837d2219bb5 100644
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -498,11 +498,26 @@ file_is_auto_load_safe (const char *filename, const char *debug_fmt, ...)
 
   if (!advice_printed)
     {
-      const char *homedir = getenv ("HOME");
-
-      if (homedir == NULL)
-	homedir = "$HOME";
-      std::string homeinit = string_printf ("%s/%s", homedir, GDBINIT);
+      /* Find the existing home directory config file.  */
+      struct stat buf;
+      std::string home_config = find_gdb_home_config_file (GDBINIT, &buf);
+      if (home_config.empty ())
+	{
+	  /* The user doesn't have an existing home directory config file,
+	     so we should suggest a suitable path for them to use.  */
+	  std::string config_dir_file
+	    = get_standard_config_filename (GDBINIT);
+	  if (!config_dir_file.empty ())
+	    home_config = config_dir_file;
+	  else
+	    {
+	      const char *homedir = getenv ("HOME");
+	      if (homedir == nullptr)
+		homedir = "$HOME";
+	      home_config = (std::string (homedir) + SLASH_STRING
+			     + std::string (GDBINIT));
+	    }
+	}
 
       printf_filtered (_("\
 To enable execution of this file add\n\
@@ -515,7 +530,7 @@ For more information about this security protection see the\n\
 \"Auto-loading safe path\" section in the GDB manual.  E.g., run from the shell:\n\
 \tinfo \"(gdb)Auto-loading safe path\"\n"),
 		       filename_real.get (),
-		       homeinit.c_str (), homeinit.c_str ());
+		       home_config.c_str (), home_config.c_str ());
       advice_printed = 1;
     }
 
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 2636b6f9903..af5f27f8a8a 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -937,6 +937,7 @@
 * File Options::                Choosing files
 * Mode Options::                Choosing modes
 * Startup::                     What @value{GDBN} does during startup
+* Initialization Files::        Initialization Files
 @end menu
 
 @node File Options
@@ -1077,47 +1078,16 @@
 @itemx -n
 @cindex @code{--nx}
 @cindex @code{-n}
-Do not execute commands found in any initialization file.
-There are three init files, loaded in the following order:
-
-@table @code
-@item @file{system.gdbinit}
-This is the system-wide init file.
-Its location is specified with the @code{--with-system-gdbinit}
-configure option (@pxref{System-wide configuration}).
-It is loaded first when @value{GDBN} starts, before command line options
-have been processed.
-@item @file{system.gdbinit.d}
-This is the system-wide init directory.
-Its location is specified with the @code{--with-system-gdbinit-dir}
-configure option (@pxref{System-wide configuration}).
-Files in this directory are loaded in alphabetical order immediately after
-system.gdbinit (if enabled) when @value{GDBN} starts, before command line
-options have been processed.  Files need to have a recognized scripting
-language extension (@file{.py}/@file{.scm}) or be named with a @file{.gdb}
-extension to be interpreted as regular @value{GDBN} commands.  @value{GDBN}
-will not recurse into any subdirectories of this directory.
-@item @file{~/.gdbinit}
-This is the init file in your home directory.
-It is loaded next, after @file{system.gdbinit}, and before
-command options have been processed.
-@item @file{./.gdbinit}
-This is the init file in the current directory.
-It is loaded last, after command line options other than @code{-x} and
-@code{-ex} have been processed.  Command line options @code{-x} and
-@code{-ex} are processed last, after @file{./.gdbinit} has been loaded.
-@end table
-
-For further documentation on startup processing, @xref{Startup}.
-For documentation on how to write command files,
-@xref{Command Files,,Command Files}.
+Do not execute commands found in any initialization file
+(@pxref{Initialization Files}).
 
 @anchor{-nh}
 @item -nh
 @cindex @code{--nh}
-Do not execute commands found in @file{~/.gdbinit}, the init file
-in your home directory.
-@xref{Startup}.
+Do not execute commands found in any home directory initialization
+file (@pxref{Initialization Files,,Home directory initialization
+file}).  The system wide and current directory initialization files
+are still loaded.
 
 @item -quiet
 @itemx -silent
@@ -1327,20 +1297,13 @@
 
 @item
 @cindex init file
-Reads the system-wide @dfn{init file} (if @option{--with-system-gdbinit} was
-used when building @value{GDBN}; @pxref{System-wide configuration,
- ,System-wide configuration and settings}) and the files in the system-wide
-gdbinit directory (if @option{--with-system-gdbinit-dir} was used) and executes
-all the commands in those files.  The files need to be named with a @file{.gdb}
-extension to be interpreted as @value{GDBN} commands, or they can be written
-in a supported scripting language with an appropriate file extension.
+Reads the system wide initialization file and the files from the
+system wide initialization directory, @pxref{System Wide Init Files}.
 
-@anchor{Home Directory Init File}
 @item
-Reads the 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
-that file.
+Reads the initialization file (if any) in your home directory and
+executes all the commands in that file, @pxref{Home Directory Init
+File}.
 
 @anchor{Option -init-eval-command}
 @item
@@ -1353,16 +1316,16 @@
 @item
 Processes command line options and operands.
 
-@anchor{Init File in the Current Directory during Startup}
 @item
-Reads and executes the commands from init file (if any) in the current
-working directory as long as @samp{set auto-load local-gdbinit} is set to
-@samp{on} (@pxref{Init File in the Current Directory}).
-This is only done if the current directory is
-different from your home directory.  Thus, you can have more than one
-init file, one generic in your home directory, and another, specific
-to the program you are debugging, in the directory where you invoke
-@value{GDBN}.
+Reads and executes the commands from the initialization file (if any)
+in the current working directory as long as @samp{set auto-load
+local-gdbinit} is set to @samp{on} (@pxref{Init File in the Current
+Directory}).  This is only done if the current directory is different
+from your home directory.  Thus, you can have more than one init file,
+one generic in your home directory, and another, specific to the
+program you are debugging, in the directory where you invoke
+@value{GDBN}. @xref{Init File in the Current Directory during
+Startup}.
 
 @item
 If the command line specified a program to debug, or a process to
@@ -1391,26 +1354,115 @@
 files where @value{GDBN} records it.
 @end enumerate
 
-Init files use the same syntax as @dfn{command files} (@pxref{Command
-Files}) and are processed by @value{GDBN} in the same way.  The init
-file in your home directory can set options (such as @samp{set
-complaints}) that affect subsequent processing of command line options
-and operands.  Init files are not executed if you use the @samp{-nx}
-option (@pxref{Mode Options, ,Choosing Modes}).
+@node Initialization Files
+@subsection Initialization Files
+@cindex init file name
 
-To display the list of init files loaded by gdb at startup, you
-can use @kbd{gdb --help}.
+During startup (@pxref{Startup}) @value{GDBN} will execute commands
+from several initialization files.  These initialization files use the
+same syntax as @dfn{command files} (@pxref{Command Files}) and are
+processed by @value{GDBN} in the same way.
 
-@cindex init file name
+To display the list of initialization files loaded by @value{GDBN} at
+startup, in the order they will be loaded, you can use @kbd{gdb
+--help}.
+
+As the system wide and home directory initialization files are
+processed before most command line options, changes to settings
+(e.g. @samp{set complaints}) can affect subsequent processing of
+command line options and operands.
+
+The following sections describe where @value{GDBN} looks for the
+initialization and the order that the files are searched for.
+
+@anchor{System Wide Init Files}
+@subsubsection System wide initialization files
+
+There are two locations that are searched for system wide
+initialization files.  Both of these locations are always checked:
+
+@table @code
+
+@item @file{system.gdbinit}
+This is a single system-wide initialization file.  Its location is
+specified with the @code{--with-system-gdbinit} configure option
+(@pxref{System-wide configuration}).  It is loaded first when
+@value{GDBN} starts, before command line options have been processed.
+
+@item @file{system.gdbinit.d}
+This is the system-wide initialization directory.  Its location is
+specified with the @code{--with-system-gdbinit-dir} configure option
+(@pxref{System-wide configuration}).  Files in this directory are
+loaded in alphabetical order immediately after @file{system.gdbinit}
+(if enabled) when @value{GDBN} starts, before command line options
+have been processed.  Files need to have a recognized scripting
+language extension (@file{.py}/@file{.scm}) or be named with a
+@file{.gdb} extension to be interpreted as regular @value{GDBN}
+commands.  @value{GDBN} will not recurse into any subdirectories of
+this directory.
+
+@end table
+
+It is possible to prevent the system wide initialization files from
+being loaded using the @samp{-nx} command line option, @pxref{Mode
+Options,,Choosing Modes}.
+
+@anchor{Home Directory Init File}
+@subsubsection Home directory initialization file
+@cindex @file{gdbinit}
 @cindex @file{.gdbinit}
 @cindex @file{gdb.ini}
-The @value{GDBN} init files are normally called @file{.gdbinit}.
-The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
-the limitations of file names imposed by DOS filesystems.  The Windows
-port of @value{GDBN} uses the standard name, but if it finds a
-@file{gdb.ini} file in your home directory, it warns you about that
-and suggests to rename the file to the standard name.
 
+After loading the system wide initialization files @value{GDBN} will
+look for an initialization file in the users home
+directory@footnote{On DOS/Windows systems, the home directory is the
+one pointed to by the @code{HOME} environment variable.}.  There are a
+number of locations that @value{GDBN} will search in the home
+directory, these locations are searched in order and @value{GDBN} will
+load the first file that it finds, and subsequent locations will not
+be checked.
+
+On non-Apple hosts the locations searched are:
+@table @file
+@item $XDG_CONFIG_HOME/gdb/gdbinit
+@item $HOME/.config/gdb/gdbinit
+@item $HOME/.gdbinit
+@end table
+
+While on Apple hosts the locations searched are:
+@table @file
+@item $HOME/Library/Preferences/gdb/gdbinit
+@item $HOME/.gdbinit
+@end table
+
+It is possible to prevent the home directory initialization file from
+being loaded using the @samp{-nx} or @samp{-nh} command line options,
+@pxref{Mode Options,,Choosing Modes}.
+
+The DJGPP port of @value{GDBN} uses the name @file{gdb.ini} instead of
+@file{.gdbinit} or @file{gdbinit}, due to the limitations of file
+names imposed by DOS filesystems.  The Windows port of @value{GDBN}
+uses the standard name, but if it finds a @file{gdb.ini} file in your
+home directory, it warns you about that and suggests to rename the
+file to the standard name.
+
+@anchor{Init File in the Current Directory during Startup}
+@subsubsection Local directory initialization file
+
+@value{GDBN} will check the current directory for a file called
+@file{./.gdbinit}.  It is loaded last, after command line options
+other than @samp{-x} and @samp{-ex} have been processed.  The command
+line options @samp{-x} and @samp{-ex} are processed last, after
+@file{./.gdbinit} has been loaded, @pxref{File Options,,Choosing
+Files}.
+
+If the file in the current directory was already loaded as the home
+directory initialization file then it will not be loaded a second
+time.
+
+It is possible to prevent the local directory initialization file from
+being loaded using the @samp{-nx} command line option, @pxref{Mode
+Options,,Choosing Modes}.
 
 @node Quitting GDB
 @section Quitting @value{GDBN}
@@ -46400,7 +46452,8 @@
 Add @var{directory} to the path to search for source files.
 
 @item -nh
-Do not execute commands from @file{~/.gdbinit}.
+Do not execute commands from @file{~/.config/gdb/gdbinit} or
+@file{~/.gdbinit}.
 
 @item -nx
 @itemx -n
@@ -46825,6 +46878,8 @@
 @value{SYSTEM_GDBINIT_DIR}/*
 @end ifset
 
+~/.config/gdb/gdbinit
+
 ~/.gdbinit
 
 ./.gdbinit
@@ -46884,11 +46939,11 @@
 @ref{System-wide configuration}.
 @end ifclear
 
-@item ~/.gdbinit
+@item @file{~/.config/gdb/gdbinit} or @file{~/.gdbinit}
 User initialization file.  It is executed unless user specified
 @value{GDBN} options @code{-nx}, @code{-n} or @code{-nh}.
 
-@item ./.gdbinit
+@item @file{./.gdbinit}
 Initialization file for current directory.  It may need to be enabled with
 @value{GDBN} security command @code{set auto-load local-gdbinit}.
 See more in
diff --git a/gdb/main.c b/gdb/main.c
index 19bbb923889..f6377f2df28 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -301,8 +301,6 @@ get_init_files (std::vector<std::string> *system_gdbinit,
 	  }
 	}
 
-      const char *homedir = getenv ("HOME");
-
       /* If the .gdbinit file in the current directory is the same as
 	 the $HOME/.gdbinit file, it should not be sourced.  homebuf
 	 and cwdbuf are used in that purpose.  Make sure that the stats
@@ -312,14 +310,7 @@ get_init_files (std::vector<std::string> *system_gdbinit,
       memset (&homebuf, 0, sizeof (struct stat));
       memset (&cwdbuf, 0, sizeof (struct stat));
 
-      if (homedir)
-	{
-	  homeinit = std::string (homedir) + SLASH_STRING + GDBINIT;
-	  if (stat (homeinit.c_str (), &homebuf) != 0)
-	    {
-	      homeinit = "";
-	    }
-	}
+      homeinit = find_gdb_home_config_file (GDBINIT, &homebuf);
 
       if (stat (GDBINIT, &cwdbuf) == 0)
 	{
@@ -328,7 +319,7 @@ get_init_files (std::vector<std::string> *system_gdbinit,
 			 sizeof (struct stat)))
 	    localinit = GDBINIT;
 	}
-      
+
       initialized = 1;
     }
 
diff --git a/gdbsupport/pathstuff.cc b/gdbsupport/pathstuff.cc
index 9fb5e5cf614..a52e53b8671 100644
--- a/gdbsupport/pathstuff.cc
+++ b/gdbsupport/pathstuff.cc
@@ -23,6 +23,10 @@
 #include "filenames.h"
 #include "gdb_tilde_expand.h"
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
 #ifdef USE_WIN32API
 #include <windows.h>
 #endif
@@ -298,6 +302,51 @@ get_standard_config_dir ()
   return {};
 }
 
+/* See pathstuff.h. */
+
+std::string
+get_standard_config_filename (const char *filename)
+{
+  std::string config_dir = get_standard_config_dir ();
+  if (config_dir != "")
+    {
+      const char *tmp = (*filename == '.') ? (filename + 1) : filename;
+      std::string path = config_dir + SLASH_STRING + std::string (tmp);
+      return path;
+    }
+
+  return {};
+}
+
+/* See pathstuff.h.  */
+
+std::string
+find_gdb_home_config_file (const char *name, struct stat *buf)
+{
+  gdb_assert (name != nullptr);
+  gdb_assert (*name != '\0');
+
+  std::string config_dir_file = get_standard_config_filename (name);
+  if (!config_dir_file.empty ())
+    {
+      if (stat (config_dir_file.c_str (), buf) == 0)
+	return config_dir_file;
+    }
+
+  const char *homedir = getenv ("HOME");
+  if (homedir != nullptr)
+    {
+      /* Make sure the path is absolute and tilde-expanded.  */
+      gdb::unique_xmalloc_ptr<char> abs (gdb_abspath (homedir));
+      std::string path = (std::string (abs.get ()) + SLASH_STRING
+			  + std::string (name));
+      if (stat (path.c_str (), buf) == 0)
+	return path;
+    }
+
+  return {};
+}
+
 /* See gdbsupport/pathstuff.h.  */
 
 const char *
diff --git a/gdbsupport/pathstuff.h b/gdbsupport/pathstuff.h
index 85241bc8c7c..996c8f2bbf6 100644
--- a/gdbsupport/pathstuff.h
+++ b/gdbsupport/pathstuff.h
@@ -99,6 +99,29 @@ extern std::string get_standard_temp_dir ();
 
 extern std::string get_standard_config_dir ();
 
+/* Look for FILENAME in the standard configuration directory as returned by
+   GET_STANDARD_CONFIG_DIR and return the path to the file.  No check is
+   performed that the file actually exists or not.
+
+   If FILENAME begins with a '.' then the path returned will remove the
+   leading '.' character, for example passing '.gdbinit' could return the
+   path '/home/username/.config/gdb/gdbinit'.  */
+
+extern std::string get_standard_config_filename (const char *filename);
+
+/* Look for a file called NAME in either the standard config directory or
+   in the users home directory.  If a suitable file is found then *BUF will
+   be filled with the contents of a call to 'stat' on the found file,
+   otherwise *BUF is undefined after this call.
+
+   If NAME starts with a '.' character then, when looking in the standard
+   config directory the file searched for has the '.' removed.  For
+   example, if NAME is '.gdbinit' then on a Linux target GDB might look for
+   '~/.config/gdb/gdbinit' and then '~/.gdbinit'.  */
+
+extern std::string find_gdb_home_config_file (const char *name,
+					      struct stat *buf);
+
 /* Return the file name of the user's shell.  Normally this comes from
    the SHELL environment variable.  */
 
-- 
2.25.4


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 3/7] gdb: new function to wrap up executing command line scripts/commands
  2020-10-07 20:05 [PATCH 0/7] Adding startup files to GDB Andrew Burgess
  2020-10-07 20:05 ` [PATCH 1/7] Add get_standard_config_dir function Andrew Burgess
  2020-10-07 20:05 ` [PATCH 2/7] gdb: use get_standard_config_dir when looking for .gdbinit Andrew Burgess
@ 2020-10-07 20:05 ` Andrew Burgess
  2020-10-08 15:25   ` Aktemur, Tankut Baris
  2020-10-22 19:08   ` Tom Tromey
  2020-10-07 20:05 ` [PATCH 4/7] gdb: process startup files and startup command line options Andrew Burgess
                   ` (5 subsequent siblings)
  8 siblings, 2 replies; 24+ messages in thread
From: Andrew Burgess @ 2020-10-07 20:05 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey, Andrew Burgess

Small refactor to wrap up executing the scripts and commands passed
using the -x, -ex, -ix, -iex command line flags.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* main.c (execute_cmdargs): New function.
	(captured_main_1): Make use of execute_cmdargs.
---
 gdb/ChangeLog |  5 +++++
 gdb/main.c    | 53 ++++++++++++++++++++-------------------------------
 2 files changed, 26 insertions(+), 32 deletions(-)

diff --git a/gdb/main.c b/gdb/main.c
index f6377f2df28..f85b7dbfdaa 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -515,6 +515,25 @@ struct cmdarg
   char *string;
 };
 
+/* From CMDARG_VEC execute command files (matching FILE_TYPE) or commands
+   (matching CMD_TYPE).  Update the value in *RET.  */
+
+static void
+execute_cmdargs (const std::vector<struct cmdarg> *cmdarg_vec,
+		 cmdarg_kind file_type, cmdarg_kind cmd_type,
+		 int *ret)
+{
+  for (const auto &cmdarg_p : *cmdarg_vec)
+    {
+      if (cmdarg_p.type == file_type)
+	*ret = catch_command_errors (source_script, cmdarg_p.string,
+				     !batch_flag);
+      else if (cmdarg_p.type == cmd_type)
+	*ret = catch_command_errors (execute_command, cmdarg_p.string,
+				     !batch_flag);
+    }
+}
+
 static void
 captured_main_1 (struct captured_main_args *context)
 {
@@ -1069,22 +1088,7 @@ captured_main_1 (struct captured_main_args *context)
     ret = catch_command_errors (source_script, home_gdbinit.c_str (), 0);
 
   /* Process '-ix' and '-iex' options early.  */
-  for (i = 0; i < cmdarg_vec.size (); i++)
-    {
-      const struct cmdarg &cmdarg_p = cmdarg_vec[i];
-
-      switch (cmdarg_p.type)
-	{
-	case CMDARG_INIT_FILE:
-	  ret = catch_command_errors (source_script, cmdarg_p.string,
-				      !batch_flag);
-	  break;
-	case CMDARG_INIT_COMMAND:
-	  ret = catch_command_errors (execute_command, cmdarg_p.string,
-				      !batch_flag);
-	  break;
-	}
-    }
+  execute_cmdargs (&cmdarg_vec, CMDARG_INIT_FILE, CMDARG_INIT_COMMAND, &ret);
 
   /* Now perform all the actions indicated by the arguments.  */
   if (cdarg != NULL)
@@ -1195,22 +1199,7 @@ captured_main_1 (struct captured_main_args *context)
     load_auto_scripts_for_objfile (objfile);
 
   /* Process '-x' and '-ex' options.  */
-  for (i = 0; i < cmdarg_vec.size (); i++)
-    {
-      const struct cmdarg &cmdarg_p = cmdarg_vec[i];
-
-      switch (cmdarg_p.type)
-	{
-	case CMDARG_FILE:
-	  ret = catch_command_errors (source_script, cmdarg_p.string,
-				      !batch_flag);
-	  break;
-	case CMDARG_COMMAND:
-	  ret = catch_command_errors (execute_command, cmdarg_p.string,
-				      !batch_flag);
-	  break;
-	}
-    }
+  execute_cmdargs (&cmdarg_vec, CMDARG_FILE, CMDARG_COMMAND, &ret);
 
   /* Read in the old history after all the command files have been
      read.  */
-- 
2.25.4


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 4/7] gdb: process startup files and startup command line options
  2020-10-07 20:05 [PATCH 0/7] Adding startup files to GDB Andrew Burgess
                   ` (2 preceding siblings ...)
  2020-10-07 20:05 ` [PATCH 3/7] gdb: new function to wrap up executing command line scripts/commands Andrew Burgess
@ 2020-10-07 20:05 ` Andrew Burgess
  2020-10-08  6:28   ` Eli Zaretskii
  2020-10-07 20:05 ` [PATCH 5/7] gdb: add mechanism to auto-save startup options Andrew Burgess
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 24+ messages in thread
From: Andrew Burgess @ 2020-10-07 20:05 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey, Andrew Burgess

Adds the ability to process commands at a new phase during GDB's
startup.  This phase is earlier than the current initialisation file
processing, before GDB has produced any output.

The number of commands that can be processed at this early stage will
be limited, and it is expected that the only commands that would be
processed at this stage will relate to some of the fundamentals of how
GDB starts up.

This commit adds a mechanism to find these startup files as well as
some corresponding command line flags.  Later commits will add
commands that require this functionality in order to do what the user
might want.

The startup files that GDB will currently check for are
~/.config/gdb/gdbstartup (on Linux like systems) or ~/.gdbstartup if
the former is not found.  GDB will also look for ./.gdbstartup, a
local startup file, with the usual auto-loading restrictions.

The output of 'gdb --help' has been extended to include a list of the
startup files being processed, as well as better handling the case
where no startup files are found, so you might now see:

  At startup, GDB reads the following startup files and executes their commands:
     None found.

The printing of 'None found.' has also been applied to .gdbinit files
too.

There are no tests yet for this functionality, as there are no options
that really make use of it, but later commits will add some tests.

gdb/ChangeLog:

	* NEWS: Mention new startup files and command line options.
	* config.in: Regenerate.
	* configure: Regenerate.
	* configure.ac: Define GDBSTARTUP.
	* main.c (relocate_gdbinit_path_maybe_in_datadir): Rename to...
	(relocate_file_path_maybe_in_datadir): ...this.
	(class gdb_initfile_finder): New class.
	(get_init_files): New uses gdb_initfile_finder.
	(get_startup_files): New function.
	(enum cmdarg_kind): Add CMDARG_STARTUP_FILE and
	CMDARG_STARTUP_COMMAND.
	(captured_main_1): Add support for new command line flags, and for
	processing startup files.
	(print_gdb_help): Include startup files in the output, print 'None
	found' when there are no startup files, or no init files.

gdb/doc/ChangeLog:

	* gdb.texinfo (File Options): Mention new command line options.
	(Startup): Discuss when startup files are processed.
	(Initialization Files): Add description of startup files.
	(Auto-loading): Mention startup files.
	(gdb man): Likewise.
---
 gdb/ChangeLog       |  18 +++
 gdb/NEWS            |  11 ++
 gdb/config.in       |   3 +
 gdb/configure       |   6 +
 gdb/configure.ac    |   3 +
 gdb/doc/ChangeLog   |   8 ++
 gdb/doc/gdb.texinfo | 104 ++++++++++++++--
 gdb/main.c          | 289 ++++++++++++++++++++++++++++++++++----------
 8 files changed, 369 insertions(+), 73 deletions(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index c64dda7bbcb..bd3aca84d51 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -21,6 +21,17 @@
   $HOME/.gdbinit.  On Apple hosts the search order is instead:
   $HOME/Library/Preferences/gdb/gdbinit, $HOME/.gdbinit.
 
+* GDB will now load and process commands from
+  ~/.config/gdb/gdbstartup, ~/.gdbstartup, or a local file
+  ./.gdbstartup if these files are present.  These files are processed
+  earlier than any of the previous initialization files and can effect
+  parts of GDB's startup that previously had already been completed
+  before the initialization files were read.
+
+* GDB now has two new options "--startup-command" and
+  "--startup-eval-command" with corresponding short options "-sx" and
+  "-sex" that allow startup options to be passed on the command line.
+
 * New commands
 
 set debug event-loop
diff --git a/gdb/config.in b/gdb/config.in
index 3e741c6ee71..a345125dd35 100644
--- a/gdb/config.in
+++ b/gdb/config.in
@@ -46,6 +46,9 @@
 /* The .gdbinit filename. */
 #undef GDBINIT
 
+/* The .gdbstartup filename. */
+#undef GDBSTARTUP
+
 /* look for global separate data files in this path [DATADIR/gdb] */
 #undef GDB_DATADIR
 
diff --git a/gdb/configure b/gdb/configure
index a8942ecbd5d..0f426fcf52b 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -16315,6 +16315,12 @@ _ACEOF
 
 
 
+cat >>confdefs.h <<_ACEOF
+#define GDBSTARTUP ".gdbstartup"
+_ACEOF
+
+
+
 # Support for --with-sysroot is a copy of GDB_AC_WITH_DIR,
 # except that the argument to --with-sysroot is optional.
 # --with-sysroot (or --with-sysroot=yes) sets the default sysroot path.
diff --git a/gdb/configure.ac b/gdb/configure.ac
index 6b4b0fa8510..6a357cbfa30 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -1701,6 +1701,9 @@ case $host_os in
 esac
 AC_DEFINE_UNQUOTED(GDBINIT,"$gdbinit",[The .gdbinit filename.])
 
+dnl Set the host's .gdbstartup filename
+AC_DEFINE_UNQUOTED(GDBSTARTUP,".gdbstartup",[The .gdbstartup filename.])
+
 dnl Handle optional features that can be enabled.
 
 # Support for --with-sysroot is a copy of GDB_AC_WITH_DIR,
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index af5f27f8a8a..f141616bea1 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -1040,6 +1040,22 @@
 after loading gdbinit files).
 @xref{Startup}.
 
+@item -startup-command @var{file}
+@itemx -sx @var{file}
+@cindex @code{--startup-command}
+@cindex @code{-sx}
+Execute commands from file @var{file} as early as possible during the
+initialization process, before any output is produced.
+@xref{Startup}.
+
+@item -startup-eval-command @var{command}
+@itemx -sex @var{command}
+@cindex @code{--startup-eval-command}
+@cindex @code{-sex}
+Execute a single @value{GDBN} command as early as possible during the
+initialization process, before any output is produced.
+@xref{Startup}.
+
 @item -directory @var{directory}
 @itemx -d @var{directory}
 @cindex @code{--directory}
@@ -1291,6 +1307,22 @@
 Here's the description of what @value{GDBN} does during session startup:
 
 @enumerate
+
+@item
+Performs minimal setup required to initialise basic internal state.
+
+@item
+@cindex startup file
+Reads startup options from the startup file (if any) in your home
+directory, followed by any startup options contained in a startup file
+(if any) in the local directory as long as @samp{set auto-load
+local-gdbinit} is set to @samp{on} (@pxref{Init File in the Current
+Directory}), @pxref{Local directory startup file}.
+
+@item
+Any startup command line options (@samp{startup-command} and
+@samp{startup-eval-command}) are processed.
+
 @item
 Sets up the command interpreter as specified by the command line
 (@pxref{Mode Options, interpreter}).
@@ -1367,13 +1399,63 @@
 startup, in the order they will be loaded, you can use @kbd{gdb
 --help}.
 
+The files processed are split into two categories @dfn{startup files}
+and @dfn{initialization files}.  The startup files are loaded as
+early as possible during @value{GDBN}'s startup and allow a limited
+set of settings to be configured that can affect how the rest of
+@value{GDBN} starts up.  The more general initialization files are
+processed later after @value{GDBN} has finished its own internal
+startup process, any commands can be used in these files.
+
 As the system wide and home directory initialization files are
 processed before most command line options, changes to settings
 (e.g. @samp{set complaints}) can affect subsequent processing of
 command line options and operands.
 
 The following sections describe where @value{GDBN} looks for the
-initialization and the order that the files are searched for.
+startup and initialization files, and the order that the files are
+searched for.
+
+@subsubsection Home directory startup files
+
+@value{GDBN} initially looks for startup files in the users home
+directory@footnote{On DOS/Windows systems, the home directory is the
+one pointed to by the @code{HOME} environment variable.}.  There are a
+number of locations that @value{GDBN} will search in the home
+directory, these locations are searched in order and @value{GDBN} will
+load the first file that it finds, and subsequent locations will not
+be checked.
+
+On non-Apple hosts the locations searched are:
+@table @file
+@item $XDG_CONFIG_HOME/gdb/gdbstartup
+@item $HOME/.config/gdb/gdbstartup
+@item $HOME/.gdbstartup
+@end table
+
+While on Apple hosts the locations searched are:
+@table @file
+@item $HOME/Library/Preferences/gdb/gdbstartup
+@item $HOME/.gdbstartup
+@end table
+
+It is possible to prevent the home directory startup file from
+being loaded using the @samp{-nx} or @samp{-nh} command line options,
+@pxref{Mode Options,,Choosing Modes}.
+
+@anchor{Local directory startup file}
+@subsubsection Local directory startup file
+
+@value{GDBN} will check the current directory for a file called
+@file{./.gdbstartup}.  It is loaded after the home directory startup
+file.
+
+If the file in the current directory was already loaded as the home
+directory startup file then it will not be loaded a second time.
+
+It is possible to prevent the local directory startup file from being
+loaded using the @samp{-nx} command line option, @pxref{Mode
+Options,,Choosing Modes}.
 
 @anchor{System Wide Init Files}
 @subsubsection System wide initialization files
@@ -25975,9 +26057,10 @@
 In addition to these files, @value{GDBN} supports auto-loading code written
 in various extension languages.  @xref{Auto-loading extensions}.
 
-Note that loading of these associated files (including the local @file{.gdbinit}
-file) requires accordingly configured @code{auto-load safe-path}
-(@pxref{Auto-loading safe path}).
+Note that loading of these associated files (including the local
+@file{.gdbinit} and @file{.gdbstartup} files) requires accordingly
+configured @code{auto-load safe-path} (@pxref{Auto-loading safe
+path}).
 
 For these reasons, @value{GDBN} includes commands and options to let you
 control when to auto-load files and which files should be auto-loaded.
@@ -26100,8 +26183,9 @@
 from init file (if any) in the current working directory,
 see @ref{Init File in the Current Directory during Startup}.
 
-Note that loading of this local @file{.gdbinit} file also requires accordingly
-configured @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
+Note that loading of this local @file{.gdbinit} (and likewise of
+@file{.gdbstartup}) file also requires accordingly configured
+@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
 
 @table @code
 @anchor{set auto-load local-gdbinit}
@@ -46452,12 +46536,14 @@
 Add @var{directory} to the path to search for source files.
 
 @item -nh
-Do not execute commands from @file{~/.config/gdb/gdbinit} or
-@file{~/.gdbinit}.
+Do not execute commands from @file{~/.config/gdb/gdbinit},
+@file{~/.gdbinit}, @file{~/.config/gdb/gdbstartup}, or
+@file{~/.gdbstartup}
 
 @item -nx
 @itemx -n
-Do not execute commands from any @file{.gdbinit} initialization files.
+Do not execute commands from any @file{.gdbinit} or @file{.gdbstartup}
+initialization files.
 
 @item -quiet
 @itemx -q
diff --git a/gdb/main.c b/gdb/main.c
index f85b7dbfdaa..8c2240085f7 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -202,8 +202,8 @@ relocate_gdb_directory (const char *initial, bool relocatable)
    otherwise.  */
 
 static std::string
-relocate_gdbinit_path_maybe_in_datadir (const std::string &file,
-					bool relocatable)
+relocate_file_path_maybe_in_datadir (const std::string &file,
+				     bool relocatable)
 {
   size_t datadir_len = strlen (GDB_DATADIR);
 
@@ -232,45 +232,51 @@ relocate_gdbinit_path_maybe_in_datadir (const std::string &file,
     return relocated_path;
 }
 
-/* Compute the locations of init files that GDB should source and
-   return them in SYSTEM_GDBINIT, HOME_GDBINIT, LOCAL_GDBINIT.  If
-   there is no system gdbinit (resp. home gdbinit and local gdbinit)
-   to be loaded, then SYSTEM_GDBINIT (resp. HOME_GDBINIT and
-   LOCAL_GDBINIT) is set to the empty string.  */
-static void
-get_init_files (std::vector<std::string> *system_gdbinit,
-		std::string *home_gdbinit,
-		std::string *local_gdbinit)
+/* A class to wrap up the logic for finding the three different types of
+   initialisation files GDB uses, system wide, home directory, and current
+   working directory.  */
+
+class gdb_initfile_finder
 {
-  static std::vector<std::string> sysgdbinit;
-  static std::string homeinit;
-  static std::string localinit;
-  static int initialized = 0;
+public:
+  /* Constructor.  Finds initialisation files named FILENAME in the home
+     directory or local (current working) directory.  System initialisation
+     files are found in both SYSTEM_FILENAME and SYSTEM_DIRNAME if these
+     are not nullptr (either or both can be).  The matching *_RELOCATABLE
+     flag is passed through to RELOCATE_FILE_PATH_MAYBE_IN_DATADIR.
+
+     If FILENAME starts with a '.' then when looking in the home directory
+     this first '.' can be ignored in some cases.  */
+  explicit gdb_initfile_finder (const char *filename,
+				const char *system_filename,
+				bool system_filename_relocatable,
+				const char *system_dirname,
+				bool system_dirname_relocatable)
+  {
+    struct stat s;
 
-  if (!initialized)
-    {
-      struct stat homebuf, cwdbuf, s;
+    if (system_filename != nullptr && system_filename[0] != '\0')
+      {
+	std::string relocated_filename
+	  = relocate_file_path_maybe_in_datadir (system_filename,
+						 system_filename_relocatable);
+	if (!relocated_filename.empty ()
+	    && stat (relocated_filename.c_str (), &s) == 0)
+	  m_system_files.push_back (relocated_filename);
+      }
 
-      if (SYSTEM_GDBINIT[0])
-	{
-	  std::string relocated_sysgdbinit
-	    = relocate_gdbinit_path_maybe_in_datadir
-		(SYSTEM_GDBINIT, SYSTEM_GDBINIT_RELOCATABLE);
-	  if (!relocated_sysgdbinit.empty ()
-	      && stat (relocated_sysgdbinit.c_str (), &s) == 0)
-	    sysgdbinit.push_back (relocated_sysgdbinit);
-	}
-      if (SYSTEM_GDBINIT_DIR[0])
-	{
-	  std::string relocated_gdbinit_dir
-	    = relocate_gdbinit_path_maybe_in_datadir
-		(SYSTEM_GDBINIT_DIR, SYSTEM_GDBINIT_DIR_RELOCATABLE);
-	  if (!relocated_gdbinit_dir.empty ()) {
-	    gdb_dir_up dir (opendir (relocated_gdbinit_dir.c_str ()));
+    if (system_dirname != nullptr && system_dirname[0] != '\0')
+      {
+	std::string relocated_dirname
+	  = relocate_file_path_maybe_in_datadir (system_dirname,
+						 system_dirname_relocatable);
+	if (!relocated_dirname.empty ())
+	  {
+	    gdb_dir_up dir (opendir (relocated_dirname.c_str ()));
 	    if (dir != nullptr)
 	      {
 		std::vector<std::string> files;
-		for (;;)
+		while (true)
 		  {
 		    struct dirent *ent = readdir (dir.get ());
 		    if (ent == nullptr)
@@ -278,28 +284,28 @@ get_init_files (std::vector<std::string> *system_gdbinit,
 		    std::string name (ent->d_name);
 		    if (name == "." || name == "..")
 		      continue;
-		    /* ent->d_type is not available on all systems (e.g. mingw,
-		       Solaris), so we have to call stat().  */
-		    std::string filename
-		      = relocated_gdbinit_dir + SLASH_STRING + name;
-		    if (stat (filename.c_str (), &s) != 0
+		    /* ent->d_type is not available on all systems
+		       (e.g. mingw, Solaris), so we have to call stat().  */
+		    std::string tmp_filename
+		      = relocated_dirname + SLASH_STRING + name;
+		    if (stat (tmp_filename.c_str (), &s) != 0
 			|| !S_ISREG (s.st_mode))
 		      continue;
 		    const struct extension_language_defn *extlang
-		      = get_ext_lang_of_file (filename.c_str ());
+		      = get_ext_lang_of_file (tmp_filename.c_str ());
 		    /* We effectively don't support "set script-extension
-		       off/soft", because we are loading system init files here,
-		       so it does not really make sense to depend on a
-		       setting.  */
+		       off/soft", because we are loading system init files
+		       here, so it does not really make sense to depend on
+		       a setting.  */
 		    if (extlang != nullptr && ext_lang_present_p (extlang))
-		      files.push_back (std::move (filename));
+		      files.push_back (std::move (tmp_filename));
 		  }
 		std::sort (files.begin (), files.end ());
-		sysgdbinit.insert (sysgdbinit.end (),
-				   files.begin (), files.end ());
+		m_system_files.insert (m_system_files.end (),
+				       files.begin (), files.end ());
 	      }
 	  }
-	}
+      }
 
       /* If the .gdbinit file in the current directory is the same as
 	 the $HOME/.gdbinit file, it should not be sourced.  homebuf
@@ -307,25 +313,98 @@ get_init_files (std::vector<std::string> *system_gdbinit,
 	 are zero in case one of them fails (this guarantees that they
 	 won't match if either exists).  */
 
-      memset (&homebuf, 0, sizeof (struct stat));
-      memset (&cwdbuf, 0, sizeof (struct stat));
+    struct stat homebuf, cwdbuf;
+    memset (&homebuf, 0, sizeof (struct stat));
+    memset (&cwdbuf, 0, sizeof (struct stat));
 
-      homeinit = find_gdb_home_config_file (GDBINIT, &homebuf);
+    m_home_file = find_gdb_home_config_file (filename, &homebuf);
 
-      if (stat (GDBINIT, &cwdbuf) == 0)
-	{
-	  if (homeinit.empty ()
-	      || memcmp ((char *) &homebuf, (char *) &cwdbuf,
-			 sizeof (struct stat)))
-	    localinit = GDBINIT;
-	}
+    if (stat (filename, &cwdbuf) == 0)
+      {
+	if (m_home_file.empty ()
+	    || memcmp ((char *) &homebuf, (char *) &cwdbuf,
+		       sizeof (struct stat)))
+	  m_local_file = filename;
+      }
+  }
 
-      initialized = 1;
-    }
+  DISABLE_COPY_AND_ASSIGN (gdb_initfile_finder);
+
+  /* Return a list of system initialisation files.  The list could be
+     empty.  */
+  const std::vector<std::string> &system_files () const
+  { return m_system_files; }
+
+  /* Return the path to the home initialisation file.  The string can be
+     empty if there is no such file.  */
+  const std::string &home_file () const
+  { return m_home_file; }
+
+  /* Return the path to the local initialisation file.  The string can be
+     empty if there is no such file.  */
+  const std::string &local_file () const
+  { return m_local_file; }
 
-  *system_gdbinit = sysgdbinit;
-  *home_gdbinit = homeinit;
-  *local_gdbinit = localinit;
+private:
+
+  /* Vector of all system init files in the order they should be processed.
+     Could be empty.  */
+  std::vector<std::string> m_system_files;
+
+  /* Initialization file from the home directory.  Could be the empty
+     string if there is no such file found.  */
+  std::string m_home_file;
+
+  /* Initialization file from the current working directory.  Could be the
+     empty string if there is no such file found.  */
+  std::string m_local_file;
+};
+
+/* Compute the locations of init files that GDB should source and return
+   them in SYSTEM_GDBINIT, HOME_GDBINIT, LOCAL_GDBINIT.  The SYSTEM_GDBINIT
+   can be returned as an empty vector, and HOME_GDBINIT and LOCAL_GDBINIT
+   can be returned as empty strings if there is no init file of that
+   type.  */
+
+static void
+get_init_files (std::vector<std::string> *system_gdbinit,
+		std::string *home_gdbinit,
+		std::string *local_gdbinit)
+{
+  static std::unique_ptr<gdb_initfile_finder> init_files;
+  if (init_files == nullptr)
+    init_files = std::unique_ptr<gdb_initfile_finder>
+      (new gdb_initfile_finder (GDBINIT,
+				SYSTEM_GDBINIT,
+				SYSTEM_GDBINIT_RELOCATABLE,
+				SYSTEM_GDBINIT_DIR,
+				SYSTEM_GDBINIT_DIR_RELOCATABLE));
+
+  *system_gdbinit = init_files->system_files ();
+  *home_gdbinit = init_files->home_file ();
+  *local_gdbinit = init_files->local_file ();
+}
+
+/* Compute the locations of startup files that GDB should source and return
+   them in SYSTEM_GDBSTARTUP, HOME_GDBSTARTUP, LOCAL_GDBSTARTUP.  The
+   SYSTEM_GDBSTARTUP can be returned as an empty vector, and
+   HOME_GDBSTARTUP and LOCAL_GDBSTARTUP can be returned as empty strings if
+   there is no startup file of that type.  */
+
+static void
+get_startup_files (std::vector<std::string> *system_gdbstartup,
+		   std::string *home_gdbstartup,
+		   std::string *local_gdbstartup)
+{
+  static std::unique_ptr<gdb_initfile_finder> init_files;
+  if (init_files == nullptr)
+    init_files = std::unique_ptr<gdb_initfile_finder>
+      (new gdb_initfile_finder (GDBSTARTUP,
+				nullptr, false, nullptr, false));
+
+  *system_gdbstartup = init_files->system_files ();
+  *home_gdbstartup = init_files->home_file ();
+  *local_gdbstartup = init_files->local_file ();
 }
 
 /* Start up the event loop.  This is the entry point to the event loop
@@ -497,7 +576,13 @@ enum cmdarg_kind
   CMDARG_INIT_FILE,
     
   /* Option type -iex.  */
-  CMDARG_INIT_COMMAND
+  CMDARG_INIT_COMMAND,
+
+  /* Option type -sx.  */
+  CMDARG_STARTUP_FILE,
+
+  /* Option type -sex.  */
+  CMDARG_STARTUP_COMMAND
 };
 
 /* Arguments of --command option and its counterpart.  */
@@ -674,6 +759,8 @@ captured_main_1 (struct captured_main_args *context)
       OPT_WINDOWS,
       OPT_IX,
       OPT_IEX,
+      OPT_SX,
+      OPT_SEX,
       OPT_READNOW,
       OPT_READNEVER
     };
@@ -723,6 +810,10 @@ captured_main_1 (struct captured_main_args *context)
       {"init-eval-command", required_argument, 0, OPT_IEX},
       {"ix", required_argument, 0, OPT_IX},
       {"iex", required_argument, 0, OPT_IEX},
+      {"startup-command", required_argument, 0, OPT_SX},
+      {"startup-eval-command", required_argument, 0, OPT_SEX},
+      {"sx", required_argument, 0, OPT_SX},
+      {"sex", required_argument, 0, OPT_SEX},
 #ifdef GDBTK
       {"tclcommand", required_argument, 0, 'z'},
       {"enable-external-editor", no_argument, 0, 'y'},
@@ -835,6 +926,12 @@ captured_main_1 (struct captured_main_args *context)
 	  case OPT_IEX:
 	    cmdarg_vec.emplace_back (CMDARG_INIT_COMMAND, optarg);
 	    break;
+	  case OPT_SX:
+	    cmdarg_vec.emplace_back (CMDARG_STARTUP_FILE, optarg);
+	    break;
+	  case OPT_SEX:
+	    cmdarg_vec.emplace_back (CMDARG_STARTUP_COMMAND, optarg);
+	    break;
 	  case 'B':
 	    batch_flag = batch_silent = 1;
 	    gdb_stdout = new null_file ();
@@ -943,6 +1040,34 @@ captured_main_1 (struct captured_main_args *context)
   /* Initialize all files.  */
   gdb_init (gdb_program_name);
 
+  /* Process startup files and startup options from the command line.  */
+  if (!inhibit_gdbinit)
+    {
+      std::vector<std::string> system_gdbstartup;
+      std::string home_gdbstartup;
+      std::string local_gdbstartup;
+      get_startup_files (&system_gdbstartup, &home_gdbstartup,
+			 &local_gdbstartup);
+      if (!system_gdbstartup.empty () && !inhibit_gdbinit)
+	{
+	  for (const std::string &file : system_gdbstartup)
+	    ret = catch_command_errors (source_script, file.c_str (), 0);
+	}
+      if (!home_gdbstartup.empty () && !inhibit_home_gdbinit)
+	ret = catch_command_errors (source_script,
+				    home_gdbstartup.c_str (), 0);
+      if (!local_gdbstartup.empty ()
+	  && file_is_auto_load_safe (local_gdbstartup.c_str (),
+				     _("auto-load: Loading %s "
+				       "file \"%s\".\n"),
+				     GDBSTARTUP,
+				     local_gdbstartup.c_str ()))
+	ret = catch_command_errors (source_script,
+				    local_gdbstartup.c_str (), 0);
+    }
+  execute_cmdargs (&cmdarg_vec, CMDARG_STARTUP_FILE,
+		   CMDARG_STARTUP_COMMAND, &ret);
+
   /* Now that gdb_init has created the initial inferior, we're in
      position to set args for that inferior.  */
   if (set_args)
@@ -1268,8 +1393,12 @@ print_gdb_help (struct ui_file *stream)
   std::vector<std::string> system_gdbinit;
   std::string home_gdbinit;
   std::string local_gdbinit;
+  std::vector<std::string> system_gdbstartup;
+  std::string home_gdbstartup;
+  std::string local_gdbstartup;
 
   get_init_files (&system_gdbinit, &home_gdbinit, &local_gdbinit);
+  get_startup_files (&system_gdbstartup, &home_gdbstartup, &local_gdbstartup);
 
   /* Note: The options in the list below are only approximately sorted
      in the alphabetical order, so as to group closely related options
@@ -1343,6 +1472,34 @@ Other options:\n\n\
                      Set GDB's data-directory to DIR.\n\
 "), stream);
   fputs_unfiltered (_("\n\
+At startup, GDB reads the following startup files and executes their commands:\n\
+"), stream);
+  if (!system_gdbstartup.empty ())
+    {
+      std::string output;
+      for (size_t idx = 0; idx < system_gdbstartup.size (); ++idx)
+        {
+	  output += system_gdbstartup[idx];
+	  if (idx < system_gdbstartup.size () - 1)
+	    output += ", ";
+	}
+      fprintf_unfiltered (stream, _("\
+   * system-wide startup files: %s\n\
+"), output.c_str ());
+    }
+  if (!home_gdbstartup.empty ())
+    fprintf_unfiltered (stream, _("\
+   * user-specific startup file: %s\n\
+"), home_gdbstartup.c_str ());
+  if (!local_gdbstartup.empty ())
+    fprintf_unfiltered (stream, _("\
+   * local startup file (see also 'set auto-load local-gdbinit'): ./%s\n\
+"), local_gdbstartup.c_str ());
+  if (system_gdbstartup.empty () && home_gdbstartup.empty ()
+      && local_gdbstartup.empty ())
+    fprintf_unfiltered (stream, _("\
+   None found.\n"));
+  fputs_unfiltered (_("\n\
 At startup, GDB reads the following init files and executes their commands:\n\
 "), stream);
   if (!system_gdbinit.empty ())
@@ -1366,6 +1523,10 @@ At startup, GDB reads the following init files and executes their commands:\n\
     fprintf_unfiltered (stream, _("\
    * local init file (see also 'set auto-load local-gdbinit'): ./%s\n\
 "), local_gdbinit.c_str ());
+  if (system_gdbinit.empty () && home_gdbinit.empty ()
+      && local_gdbinit.empty ())
+    fprintf_unfiltered (stream, _("\
+   None found.\n"));
   fputs_unfiltered (_("\n\
 For more information, type \"help\" from within GDB, or consult the\n\
 GDB manual (available as on-line info or a printed manual).\n\
-- 
2.25.4


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 5/7] gdb: add mechanism to auto-save startup options
  2020-10-07 20:05 [PATCH 0/7] Adding startup files to GDB Andrew Burgess
                   ` (3 preceding siblings ...)
  2020-10-07 20:05 ` [PATCH 4/7] gdb: process startup files and startup command line options Andrew Burgess
@ 2020-10-07 20:05 ` Andrew Burgess
  2020-10-08  6:36   ` Eli Zaretskii
  2020-10-07 20:05 ` [PATCH 6/7] Let the user control the startup style Andrew Burgess
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 24+ messages in thread
From: Andrew Burgess @ 2020-10-07 20:05 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey, Andrew Burgess

As we add settings to GDB (in the following patches) that effect GDB's
startup behaviour a user might desire a mechanism to automatically
save these options into a file.

The reason that this could be important is that, unlike other,
non-startup options, the startup options will only effect GDB's
startup process.  As a result setting the option within a GDB session
will not change how the user experiences that session, but could only
effect the following sessions.

We could take the position that it is entirely the users
responsibility to add these options to a startup file and maintain
them, however, this commit provides a mechanism to automate that
management.

If a user adds the following lines to ~/.config/gdb/gdbstartup:

  set startup-save-filename ~/.config/gdb/auto-save
  source ~/.config/gdb/auto-save

Then GDB will write all startup options to the file auto-save file any
time one of the options is modified.  The source ensures that the
options are reloaded correctly.

This auto saving feature is currently off by default.

There are currently no options that can be auto-saved in this way, but
later commits will add some.

gdb/ChangeLog:

	* cli/cli-setshow.c: Add 'main.h' and 'cli/cli-style.h' include.
	(startup_save_filename): New static global.
	(show_startup_save_filename): New function.
	(write_startup_functions): New static global.
	(write_startup_file): New function.
	(default_startup_writer_callback): New function.
	(add_startup_writer): New function.
	(add_default_startup_writer): New function.
	(_initialize_cli_setshow): New function.
	* cli/cli-setshow.h (write_startup_file): Declare.
	(write_startup_setting_ftype): New typedef.
	(add_startup_writer): Declare.
	(add_default_startup_writer): Declare.
	* main.c (startup_file_read): New static global.
	(gdb_startup_file_read_p): New function.
	(captured_main_1): Set startup_file_read.
	* main.h (gdb_startup_file_read_p): Declare.

gdb/doc/ChangeLog:

	* gdb.texinfo (Commands): Add link to new section.
	(Automatically saving startup options): New section.
---
 gdb/ChangeLog         |  20 +++++++
 gdb/cli/cli-setshow.c | 122 +++++++++++++++++++++++++++++++++++++++++-
 gdb/cli/cli-setshow.h |  23 ++++++++
 gdb/doc/ChangeLog     |   5 ++
 gdb/doc/gdb.texinfo   |  29 ++++++++++
 gdb/main.c            |  12 +++++
 gdb/main.h            |   5 ++
 7 files changed, 215 insertions(+), 1 deletion(-)

diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c
index 19a5565bfe0..cdbb99f8a2d 100644
--- a/gdb/cli/cli-setshow.c
+++ b/gdb/cli/cli-setshow.c
@@ -21,6 +21,7 @@
 #include <ctype.h>
 #include "arch-utils.h"
 #include "observable.h"
+#include "main.h"
 
 #include "ui-out.h"
 
@@ -28,6 +29,110 @@
 #include "cli/cli-cmds.h"
 #include "cli/cli-setshow.h"
 #include "cli/cli-utils.h"
+#include "cli/cli-style.h"
+
+/* Filename where startup options are written to when modified.  If this
+   is NULL or the empty string then startup options are not automatically
+   saved when set.  */
+
+static char *startup_save_filename;
+
+/* Implement 'show startup-save-filename'.  */
+
+static void
+show_startup_save_filename (struct ui_file *file, int from_tty,
+                            struct cmd_list_element *c, const char *value)
+{
+  if (startup_save_filename == NULL
+      || *startup_save_filename == '\0')
+    fprintf_filtered (file,
+                      _("Startup options will not be written to and file.\n"));
+  else
+    fprintf_filtered (file, _("Startup options will be written to \"%ps\".\n"),
+                      styled_string (file_name_style.style (), value));
+}
+
+/* Callbacks that will be called to write out startup settings.  */
+
+static std::vector<std::pair<write_startup_setting_ftype *,
+                             const cmd_list_element *>> write_startup_functions;
+
+/* See cli-setshow.h.  */
+
+void
+write_startup_file ()
+{
+  if (!gdb_startup_file_read_p ())
+    return;
+
+  /* Saving of these options is disabled.  */
+  if (startup_save_filename == NULL
+      || *startup_save_filename == '\0')
+    {
+      static bool warned = false;
+      if (!warned)
+        {
+          warning (_("auto-save of startup options is disabled.  Use `set "
+                     "startup-save-filename FILENAME` to save startup "
+                     "options."));
+          warned = true;
+        }
+      return;
+    }
+
+  stdio_file outfile;
+
+  if (!outfile.open (startup_save_filename, FOPEN_WT))
+    perror_with_name (startup_save_filename);
+
+  fprintf_unfiltered (&outfile, "\
+# This file is written by gdb whenever the relevant settings are changed.\n\
+# Any edits you make here will be overwritten by gdb.\n");
+
+  for (auto &callback_and_cmd : write_startup_functions)
+    callback_and_cmd.first (&outfile, callback_and_cmd.second);
+}
+
+/* A default callback that can be used to write the value of CMD into the
+   startup configuration file.  All the required information is extracted
+   from CMD and the result written to OUTFILE.  */
+
+static void
+default_startup_writer_callback (ui_file *outfile,
+                                 const cmd_list_element *cmd)
+{
+  std::string str;
+  std::function<void(const cmd_list_element *)> build_cmd;
+  build_cmd = [&] (const cmd_list_element *c) -> void
+    {
+      if (c->prefix != nullptr)
+        build_cmd (c->prefix);
+      (str += c->name) += " ";
+    };
+
+  build_cmd (cmd);
+  str += get_setshow_command_value_string (cmd);
+  str += "\n";
+  fputs_unfiltered (str.c_str (), outfile);
+}
+
+/* See cli-setshow.h.  */
+
+void
+add_startup_writer (write_startup_setting_ftype *callback,
+                    const cmd_list_element *cmd)
+{
+  write_startup_functions.emplace_back (callback, cmd);
+}
+
+/* See cli-setshow.h.  */
+
+void
+add_default_startup_writer (const cmd_list_element *cmd)
+{
+  gdb_assert (cmd != nullptr);
+  add_startup_writer (default_startup_writer_callback, cmd);
+}
 
 /* Return true if the change of command parameter should be notified.  */
 
@@ -774,4 +879,19 @@ cmd_show_list (struct cmd_list_element *list, int from_tty)
     }
 }
 
-
+extern void _initialize_cli_setshow ();
+void
+_initialize_cli_setshow ()
+{
+  add_setshow_filename_cmd ("startup-save-filename", class_support,
+                            &startup_save_filename, _("\
+Set the filename to which startup options should be written."), _("\
+Show the filename to which startup options are written."), _("\
+Some options only effect the startup of GDB.  When these options are\n\
+modified GDB can arrange to write the values of all of these options\n\
+to a file which can then be sourced during startup to reapply these\n\
+options."),
+                            NULL,
+                            show_startup_save_filename,
+                            &setlist, &showlist);
+}
diff --git a/gdb/cli/cli-setshow.h b/gdb/cli/cli-setshow.h
index 83e4984ed6c..3bc856a3b84 100644
--- a/gdb/cli/cli-setshow.h
+++ b/gdb/cli/cli-setshow.h
@@ -62,4 +62,27 @@ extern std::string get_setshow_command_value_string (const cmd_list_element *c);
 
 extern void cmd_show_list (struct cmd_list_element *list, int from_tty);
 
+/* Write the file of gdb "set" commands that is read early in the
+   startup sequence.  */
+
+extern void write_startup_file ();
+
+/* The type of a callback function that is used when writing the
+   startup file.  */
+
+class ui_file;
+typedef void write_startup_setting_ftype (ui_file *, const cmd_list_element *);
+
+/* Add a callback function that will be called when writing the
+   startup sequence.  */
+
+extern void add_startup_writer (write_startup_setting_ftype *callback,
+                                const cmd_list_element *cmd = nullptr);
+
+/* Add the default callback function that will be called when writing the
+   startup sequence.  The default callback builds a string to set the
+   option from CMD.  */
+
+extern void add_default_startup_writer (const cmd_list_element *cmd);
+
 #endif /* CLI_CLI_SETSHOW_H */
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index f141616bea1..66b87608b89 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -1717,6 +1717,7 @@
 * Completion::                  Command completion
 * Command Options::             Command options
 * Command aliases default args::        Automatically prepend default arguments to user-defined aliases
+* Automatically saving startup settings::      Automatically saving startup settings
 * Help::                        How to ask @value{GDBN} for help
 @end menu
 
@@ -2220,6 +2221,34 @@
 For more information about the @code{with} command usage,
 see @ref{Command Settings}.
 
+@node Automatically saving startup settings
+@section Automatically saving startup settings
+@table @code
+@kindex show startup-save-filename
+@kindex set startup-save-filename filename
+@cindex @value{GDBN} startup settings
+@item show startup-save-filename
+@itemx set startup-save-filename @var{filename}
+Some settings only effect the early startup behaviour of @value{GDBN}.
+In order to make use of these settings they will need to be added to a
+startup file, for example @file{~/.config/gdb/gdbstartup}
+(@pxref{Startup}).
+
+When @samp{startup-save-filename} is set to a valid path @value{GDBN}
+will automatically save all startup settings to this file whenever they
+are modified in a @value{GDBN} session.  The save file can then be
+loaded using @samp{source} (@pxref{Command Files}).
+
+For example, these commands could be placed into
+@file{~/.config/gdb/gdbstartup} in order to have GDB automatically
+save and restore startup settings:
+
+@smallexample
+set startup-save-filename ~/.config/gdb/autosave
+source ~/.config/gdb/autosave
+@end smallexample
+@end table
+
 @node Help
 @section Getting Help
 @cindex online documentation
diff --git a/gdb/main.c b/gdb/main.c
index 8c2240085f7..850b6b6708d 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -95,6 +95,17 @@ int batch_silent = 0;
 int return_child_result = 0;
 int return_child_result_value = -1;
 
+/* True after gdb has read the startup files, and processed any startup
+   command line options.  */
+static bool startup_file_read = false;
+
+/* See main.h.  */
+
+bool
+gdb_startup_file_read_p ()
+{
+  return startup_file_read;
+}
 
 /* GDB as it has been invoked from the command line (i.e. argv[0]).  */
 static char *gdb_program_name;
@@ -1067,6 +1078,7 @@ captured_main_1 (struct captured_main_args *context)
     }
   execute_cmdargs (&cmdarg_vec, CMDARG_STARTUP_FILE,
 		   CMDARG_STARTUP_COMMAND, &ret);
+  startup_file_read = true;
 
   /* Now that gdb_init has created the initial inferior, we're in
      position to set args for that inferior.  */
diff --git a/gdb/main.h b/gdb/main.h
index 78be7c5c4e0..eb4e6958272 100644
--- a/gdb/main.h
+++ b/gdb/main.h
@@ -52,4 +52,9 @@ extern const char *get_gdb_program_name (void);
 
 extern void set_gdb_data_directory (const char *new_data_dir);
 
+/* Return true once GDB has finished reading in the startup files, and
+   finished processing any startup command line options.  */
+
+extern bool gdb_startup_file_read_p ();
+
 #endif
-- 
2.25.4


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 6/7] Let the user control the startup style
  2020-10-07 20:05 [PATCH 0/7] Adding startup files to GDB Andrew Burgess
                   ` (4 preceding siblings ...)
  2020-10-07 20:05 ` [PATCH 5/7] gdb: add mechanism to auto-save startup options Andrew Burgess
@ 2020-10-07 20:05 ` Andrew Burgess
  2020-10-08  6:40   ` Eli Zaretskii
  2020-10-07 20:05 ` [PATCH 7/7] Add "set startup-quietly" Andrew Burgess
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 24+ messages in thread
From: Andrew Burgess @ 2020-10-07 20:05 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

From: Tom Tromey <tom@tromey.com>

Some users find the startup text highlighting to be distracting.  This
patch provides a way to change this, building on the startup file
infrastructure that was added earlier.

2020-07-05  Tom Tromey  <tom@tromey.com>

	* NEWS: Add entry.
	* top.c (startup_style): Remove.
	(print_gdb_version): Update.
	* cli/cli-style.h (class cli_style_option) <cli_style_option>: Add
	intensity parameter.
	<write>: Declare new method.
	(startup_style): Declare.
	* cli/cli-style.c (startup_style): New global.
	(cli_style_option): Add intensity parameter.
	(cli_style_option::write): New method.
	(_initialize_cli_style): Register new style and callbacks.

gdb/doc/ChangeLog
2020-07-05  Tom Tromey  <tom@tromey.com>

	* gdb.texinfo (Output Styling): Document "set style startup"
	commands.

gdb/testsuite/ChangeLog
2020-07-05  Tom Tromey  <tom@tromey.com>

	* gdb.base/persist.exp: New file.
---
 gdb/ChangeLog                      | 14 +++++++
 gdb/NEWS                           |  7 ++++
 gdb/cli/cli-style.c                | 36 +++++++++++++++-
 gdb/cli/cli-style.h                |  9 +++-
 gdb/doc/ChangeLog                  |  5 +++
 gdb/doc/gdb.texinfo                | 15 +++++++
 gdb/testsuite/ChangeLog            |  4 ++
 gdb/testsuite/gdb.base/persist.exp | 67 ++++++++++++++++++++++++++++++
 gdb/top.c                          |  6 +--
 9 files changed, 155 insertions(+), 8 deletions(-)
 create mode 100644 gdb/testsuite/gdb.base/persist.exp

diff --git a/gdb/NEWS b/gdb/NEWS
index bd3aca84d51..d72d51b18b6 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -132,6 +132,13 @@ show exec-file-mismatch -- Show exec-file-mismatch handling (ask|warn|off).
   executable file; if 'warn', just display a warning; if 'off', don't
   attempt to detect a mismatch.
 
+set style startup foreground COLOR
+set style startup background COLOR
+set style startup intensity VALUE
+  Control the styling of startup text.  This saves the setting into
+  a special configuration file, so that it can be read during startup
+  and applied.
+
 tui new-layout NAME WINDOW WEIGHT [WINDOW WEIGHT]...
   Define a new TUI layout, specifying its name and the windows that
   will be displayed.
diff --git a/gdb/cli/cli-style.c b/gdb/cli/cli-style.c
index a0c3cc51801..c5842023223 100644
--- a/gdb/cli/cli-style.c
+++ b/gdb/cli/cli-style.c
@@ -19,6 +19,7 @@
 
 #include "defs.h"
 #include "cli/cli-cmds.h"
+#include "cli/cli-setshow.h"
 #include "cli/cli-style.h"
 #include "source-cache.h"
 #include "observable.h"
@@ -98,13 +99,19 @@ cli_style_option metadata_style ("metadata", ui_file_style::DIM);
 
 /* See cli-style.h.  */
 
+cli_style_option startup_style ("startup", ui_file_style::MAGENTA,
+				ui_file_style::BOLD);
+
+/* See cli-style.h.  */
+
 cli_style_option::cli_style_option (const char *name,
-				    ui_file_style::basic_color fg)
+				    ui_file_style::basic_color fg,
+				    ui_file_style::intensity intensity)
   : changed (name),
     m_name (name),
     m_foreground (cli_colors[fg - ui_file_style::NONE]),
     m_background (cli_colors[0]),
-    m_intensity (cli_intensities[ui_file_style::NORMAL])
+    m_intensity (cli_intensities[intensity])
 {
 }
 
@@ -253,6 +260,17 @@ cli_style_option::add_setshow_commands (enum command_class theclass,
 			  &m_set_list, &m_show_list, (void *) this);
 }
 
+void
+cli_style_option::write (ui_file *outfile)
+{
+  fprintf_unfiltered (outfile, "set style %s background %s\n",
+		      m_name, m_background);
+  fprintf_unfiltered (outfile, "set style %s foreground %s\n",
+		      m_name, m_foreground);
+  fprintf_unfiltered (outfile, "set style %s intensity %s\n",
+		      m_name, m_intensity);
+}
+
 static cmd_list_element *style_set_list;
 static cmd_list_element *style_show_list;
 
@@ -382,4 +400,18 @@ TUI window that does have the focus."),
 						&style_set_list,
 						&style_show_list,
 						true);
+
+  startup_style.add_setshow_commands (no_class, _("\
+Startup display styling.\n\
+Configure colors used in some startup text."),
+				      &style_set_list, &style_show_list,
+				      false);
+  /* Ensure that the startup style is written to the startup file.  */
+  add_startup_writer ([] (ui_file *outfile, const cmd_list_element *cmd)
+    {
+      startup_style.write (outfile);
+    });
+  /* Arrange to write the startup file whenever a startup style
+     setting changes.  */
+  startup_style.changed.attach (write_startup_file);
 }
diff --git a/gdb/cli/cli-style.h b/gdb/cli/cli-style.h
index 6422e5296a3..28859f88560 100644
--- a/gdb/cli/cli-style.h
+++ b/gdb/cli/cli-style.h
@@ -30,7 +30,8 @@ class cli_style_option
 public:
 
   /* Construct a CLI style option with a foreground color.  */
-  cli_style_option (const char *name, ui_file_style::basic_color fg);
+  cli_style_option (const char *name, ui_file_style::basic_color fg,
+		    ui_file_style::intensity = ui_file_style::NORMAL);
 
   /* Construct a CLI style option with an intensity.  */
   cli_style_option (const char *name, ui_file_style::intensity i);
@@ -56,6 +57,9 @@ class cli_style_option
   /* Same as SET_LIST but for the show command list.  */
   struct cmd_list_element *show_list () { return m_show_list; };
 
+  /* Write this style to FILE.  */
+  void write (ui_file *outfile);
+
   /* This style can be observed for any changes.  */
   gdb::observers::observable<> changed;
 
@@ -124,6 +128,9 @@ extern cli_style_option tui_border_style;
 /* The border style of a TUI window that does have the focus.  */
 extern cli_style_option tui_active_border_style;
 
+/* The style to use for (some) startup text.  */
+extern cli_style_option startup_style;
+
 /* True if source styling is enabled.  */
 extern bool source_styling;
 
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 66b87608b89..f11948e8c4f 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -25880,6 +25880,21 @@
 @code{set style address} family of commands.  By default, this style's
 foreground color is blue.
 
+@item startup
+Control the styling of some text that is printed at startup.  These
+are managed with the @code{set style startup} family of commands.  By
+default, this style's foreground color is magenta and it has bold
+intensity.  Changing these settings will cause them to automatically
+be saved in a special configuration file, which is read by
+@value{GDBN} early in its startup.
+
+The directory in which this file appears depends on the host platform.
+On most systems, the file is in the @file{gdb} subdirectory of the
+directory pointed to by the @env{XDG_CONFIG_HOME} environment
+variable, if it is defined, else in the @file{.config/gdb}
+subdirectory of your home directory.  However, on some systems, the
+default may differ according to local convention.
+
 @item title
 Control the styling of titles.  These are managed with the
 @code{set style title} family of commands.  By default, this style's
diff --git a/gdb/testsuite/gdb.base/persist.exp b/gdb/testsuite/gdb.base/persist.exp
new file mode 100644
index 00000000000..e0525786feb
--- /dev/null
+++ b/gdb/testsuite/gdb.base/persist.exp
@@ -0,0 +1,67 @@
+# Copyright 2020 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+# This test relies on XDG_CONFIG_HOME, which does not work on all
+# platforms; so limit it to Linux native.
+if {![istarget "*-*-linux*"]} then {
+    continue
+}
+if { [target_info gdb_protocol] != "" } {
+    continue
+}
+
+# Check that the contents of FILENAME changed and that the contents
+# now contain the given command.  CONTENTS is the old contents.
+# COMMAND is the command to run, and also used to name the test.
+# Returns the new contents.
+proc require_changed {command filename contents} {
+    gdb_test_no_output $command
+
+    set fd [open $filename r]
+    set new [read $fd]
+    close $fd
+
+    set testname "$command check"
+    if {$contents == $new || [string first $command $new] == -1} {
+	fail $testname
+    } else {
+	pass $testname
+    }
+
+    return $new
+}
+
+save_vars { env(XDG_CONFIG_HOME) } {
+    set dirname [standard_output_file .]
+    file mkdir $dirname/gdb
+    set filename $dirname/gdb/gdbstartup
+
+    # Create the file as empty.
+    set fd [open $filename w]
+    close $fd
+
+    # Current contents.
+    set contents ""
+
+    setenv XDG_CONFIG_HOME $dirname
+    clean_restart
+
+    gdb_test_no_output "set startup-save-filename $filename" \
+	"arrange to auto-save startup settings"
+
+    set contents [require_changed "set style startup foreground green" $filename $contents]
+    set contents [require_changed "set style startup background green" $filename $contents]
+    set contents [require_changed "set style startup intensity dim" $filename $contents]
+}
diff --git a/gdb/top.c b/gdb/top.c
index 6233575eed6..e4c80c6dadb 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1399,11 +1399,7 @@ print_gdb_version (struct ui_file *stream, bool interactive)
 
   ui_file_style style;
   if (interactive)
-    {
-      ui_file_style nstyle = { ui_file_style::MAGENTA, ui_file_style::NONE,
-			       ui_file_style::BOLD };
-      style = nstyle;
-    }
+    style = startup_style.style ();
   fprintf_styled (stream, style, "GNU gdb %s%s\n", PKGVERSION, version);
 
   /* Second line is a copyright notice.  */
-- 
2.25.4


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 7/7] Add "set startup-quietly"
  2020-10-07 20:05 [PATCH 0/7] Adding startup files to GDB Andrew Burgess
                   ` (5 preceding siblings ...)
  2020-10-07 20:05 ` [PATCH 6/7] Let the user control the startup style Andrew Burgess
@ 2020-10-07 20:05 ` Andrew Burgess
  2020-10-08  6:44   ` Eli Zaretskii
  2020-10-08  6:56 ` [PATCH 0/7] Adding startup files to GDB Eli Zaretskii
  2020-10-22 19:02 ` Tom Tromey
  8 siblings, 1 reply; 24+ messages in thread
From: Andrew Burgess @ 2020-10-07 20:05 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

From: Tom Tromey <tom@tromey.com>

This adds a new command to change gdb to behave as though "-quiet"
were always given.  This is done by using the early startup file
infrastructure.

2020-07-05  Tom Tromey  <tom@tromey.com>

	* NEWS: Add entry.
	* top.h (check_quiet_mode): Declare.
	* top.c (startup_quiet): New global.
	(check_quiet_mode, set_startup_quiet, show_startup_quiet)
	(write_startup_quietly): New functions.
	(init_main): Register new command and callback.
	* main.c (captured_main_1): Call check_quiet_mode.

gdb/doc/ChangeLog
2020-07-05  Tom Tromey  <tom@tromey.com>

	* gdb.texinfo (Mode Options): Mention "set startup-quietly".

gdb/testsuite/ChangeLog
2020-07-05  Tom Tromey  <tom@tromey.com>

	* gdb.base/persist.exp: Add startup-quietly test.
---
 gdb/ChangeLog                      | 10 ++++++++
 gdb/NEWS                           |  7 ++++++
 gdb/doc/ChangeLog                  |  4 +++
 gdb/doc/gdb.texinfo                | 15 ++++++++++++
 gdb/main.c                         |  5 ++++
 gdb/testsuite/ChangeLog            |  4 +++
 gdb/testsuite/gdb.base/persist.exp |  1 +
 gdb/top.c                          | 39 ++++++++++++++++++++++++++++++
 gdb/top.h                          |  5 ++++
 9 files changed, 90 insertions(+)

diff --git a/gdb/NEWS b/gdb/NEWS
index d72d51b18b6..9b69ea70c11 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -139,6 +139,13 @@ set style startup intensity VALUE
   a special configuration file, so that it can be read during startup
   and applied.
 
+set startup-quietly on|off
+show startup-quietly
+  When enabled, this causes GDB to act as if "-silent" were always
+  passed on the command line.  This saves the setting into a special
+  configuration file, so that it can be read during startup and
+  applied.
+
 tui new-layout NAME WINDOW WEIGHT [WINDOW WEIGHT]...
   Define a new TUI layout, specifying its name and the windows that
   will be displayed.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index f11948e8c4f..1162f0d46ac 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -1114,6 +1114,21 @@
 ``Quiet''.  Do not print the introductory and copyright messages.  These
 messages are also suppressed in batch mode.
 
+@kindex set startup-quietly
+@kindex show startup-quietly
+This can also be enabled using @code{set startup-quietly on}.  The
+default is @code{off}.  Use @code{show startup-quietly} to see the
+current setting.  Changing this setting will cause it to automatically
+be saved in a special configuration file, which is read by
+@value{GDBN} early in its startup.
+
+The directory in which this file appears depends on the host platform.
+On most systems, the file is in the @file{gdb} subdirectory of the
+directory pointed to by the @env{XDG_CONFIG_HOME} environment
+variable, if it is defined, else in the @file{.config/gdb}
+subdirectory of your home directory.  However, on some systems, the
+default may differ according to local convention.
+
 @item -batch
 @cindex @code{--batch}
 Run in batch mode.  Exit with status @code{0} after processing all the
diff --git a/gdb/main.c b/gdb/main.c
index 850b6b6708d..e067158d4e3 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -1080,6 +1080,11 @@ captured_main_1 (struct captured_main_args *context)
 		   CMDARG_STARTUP_COMMAND, &ret);
   startup_file_read = true;
 
+  /* Recheck if we're starting up quietly after processing the startup
+     scripts and commands.  */
+  if (!quiet)
+    quiet = check_quiet_mode ();
+
   /* Now that gdb_init has created the initial inferior, we're in
      position to set args for that inferior.  */
   if (set_args)
diff --git a/gdb/testsuite/gdb.base/persist.exp b/gdb/testsuite/gdb.base/persist.exp
index e0525786feb..3e7791f2ad0 100644
--- a/gdb/testsuite/gdb.base/persist.exp
+++ b/gdb/testsuite/gdb.base/persist.exp
@@ -64,4 +64,5 @@ save_vars { env(XDG_CONFIG_HOME) } {
     set contents [require_changed "set style startup foreground green" $filename $contents]
     set contents [require_changed "set style startup background green" $filename $contents]
     set contents [require_changed "set style startup intensity dim" $filename $contents]
+    set contents [require_changed "set startup-quietly on" $filename $contents]
 }
diff --git a/gdb/top.c b/gdb/top.c
index e4c80c6dadb..c05b5506ef2 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -2153,6 +2153,34 @@ set_history_filename (const char *args,
     }
 }
 
+/* Whether we're in quiet startup mode.  */
+
+static bool startup_quiet;
+
+/* See top.h.  */
+
+bool
+check_quiet_mode ()
+{
+  return startup_quiet;
+}
+
+/* Set the startup-quiet flag.  */
+
+static void
+set_startup_quiet (const char *args, int from_tty, struct cmd_list_element *c)
+{
+  write_startup_file ();
+}
+
+static void
+show_startup_quiet (struct ui_file *file, int from_tty,
+	      struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("Whether to start up quietly is %s.\n"),
+		    value);
+}
+
 static void
 init_gdb_version_vars (void)
 {
@@ -2307,6 +2335,17 @@ input settings."),
                         show_interactive_mode,
                         &setlist, &showlist);
 
+  c = add_setshow_boolean_cmd ("startup-quietly", class_support,
+			       &startup_quiet, _("\
+Set whether GDB should start up quietly."), _("		\
+Show whether GDB should start up quietly."), NULL,
+			       set_startup_quiet,
+			       show_startup_quiet,
+			       &setlist, &showlist);
+  /* Arrange to write "set startup-quietly" to the early startup
+     file.  */
+  add_default_startup_writer (c);
+
   c = add_cmd ("new-ui", class_support, new_ui_command, _("\
 Create a new UI.\n\
 Usage: new-ui INTERPRETER TTY\n\
diff --git a/gdb/top.h b/gdb/top.h
index fd992977155..85e178c527a 100644
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -298,4 +298,9 @@ extern char *handle_line_of_input (struct buffer *cmd_line_buffer,
 				   const char *rl, int repeat,
 				   const char *annotation_suffix);
 
+/* Call at startup to see if the user has requested that gdb start up
+   quietly.  */
+
+extern bool check_quiet_mode ();
+
 #endif
-- 
2.25.4


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 4/7] gdb: process startup files and startup command line options
  2020-10-07 20:05 ` [PATCH 4/7] gdb: process startup files and startup command line options Andrew Burgess
@ 2020-10-08  6:28   ` Eli Zaretskii
  0 siblings, 0 replies; 24+ messages in thread
From: Eli Zaretskii @ 2020-10-08  6:28 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches, tom

> From: Andrew Burgess <andrew.burgess@embecosm.com>
> Date: Wed,  7 Oct 2020 21:05:08 +0100
> Cc: Tom Tromey <tom@tromey.com>
> 
> Adds the ability to process commands at a new phase during GDB's
> startup.  This phase is earlier than the current initialisation file
> processing, before GDB has produced any output.

Thanks.  Some comments about the documentation parts below.

> diff --git a/gdb/NEWS b/gdb/NEWS
> index c64dda7bbcb..bd3aca84d51 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -21,6 +21,17 @@
>    $HOME/.gdbinit.  On Apple hosts the search order is instead:
>    $HOME/Library/Preferences/gdb/gdbinit, $HOME/.gdbinit.
>  
> +* GDB will now load and process commands from
> +  ~/.config/gdb/gdbstartup, ~/.gdbstartup, or a local file
> +  ./.gdbstartup if these files are present.  These files are processed
> +  earlier than any of the previous initialization files and can effect
                                                                   ^^^^^^
"affect"

> +  parts of GDB's startup that previously had already been completed
> +  before the initialization files were read.

This begs the question: such as?...  Can we at least say something
about that here?

> +* GDB now has two new options "--startup-command" and
> +  "--startup-eval-command" with corresponding short options "-sx" and
> +  "-sex" that allow startup options to be passed on the command line.

What are "startup options" for this matter?  Perhaps an example will
be enough to explain that.

> +@item
> +@cindex startup file
> +Reads startup options from the startup file (if any) in your home
> +directory, followed by any startup options contained in a startup file
> +(if any) in the local directory as long as @samp{set auto-load
> +local-gdbinit} is set to @samp{on} (@pxref{Init File in the Current
> +Directory}), @pxref{Local directory startup file}.
> +
> +@item
> +Any startup command line options (@samp{startup-command} and
> +@samp{startup-eval-command}) are processed.

The previous @item uses the style of others in the list ("Reads ..."),
but this item suddenly switches to a different style.  Suggest to
reword:

  Processes any startup command-line options ...

> +The files processed are split into two categories @dfn{startup files}
> +and @dfn{initialization files}.  The startup files are loaded as
> +early as possible during @value{GDBN}'s startup and allow a limited
> +set of settings to be configured that can affect how the rest of
> +@value{GDBN} starts up.  The more general initialization files are
> +processed later after @value{GDBN} has finished its own internal
> +startup process, any commands can be used in these files.

This again leaves unexplained the practical difference between these
two classes.  I as a reader am left wondering what kind of commands
and settings would I need to put in the startup files, and why.

Please add some text that explains this, preferably with a couple of
examples.

> +On non-Apple hosts the locations searched are:
> +@table @file
> +@item $XDG_CONFIG_HOME/gdb/gdbstartup
> +@item $HOME/.config/gdb/gdbstartup
> +@item $HOME/.gdbstartup
> +@end table

This should be @itemize, not @table.  Also, I wonder whether it is
wise to use the $FOO notation here, as that is a Posix shell-ism.  How
about something like this instead:

  @item
  The @file{gdb/gdbstartup} subdirectory of the directory pointed to
  by the environment variable @env{XDG_CONFIG_HOME}, if it is defined.

> +While on Apple hosts the locations searched are:
> +@table @file
> +@item $HOME/Library/Preferences/gdb/gdbstartup
> +@item $HOME/.gdbstartup
> +@end table

I wonder why we make special case for Apple system, but not for
MS-Windows (which also has its own conventions for user-private
settings directories).

> +@anchor{Local directory startup file}
> +@subsubsection Local directory startup file

Instead of @anchor, how about using @node (here and elsewhere)?

> +@value{GDBN} will check the current directory for a file called
> +@file{./.gdbstartup}.

I think the "./" part is redundant here, you already say that the file
is looked up in the current directory.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 5/7] gdb: add mechanism to auto-save startup options
  2020-10-07 20:05 ` [PATCH 5/7] gdb: add mechanism to auto-save startup options Andrew Burgess
@ 2020-10-08  6:36   ` Eli Zaretskii
  0 siblings, 0 replies; 24+ messages in thread
From: Eli Zaretskii @ 2020-10-08  6:36 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches, tom

> From: Andrew Burgess <andrew.burgess@embecosm.com>
> Date: Wed,  7 Oct 2020 21:05:09 +0100
> Cc: Tom Tromey <tom@tromey.com>
> 
> As we add settings to GDB (in the following patches) that effect GDB's
> startup behaviour a user might desire a mechanism to automatically
> save these options into a file.
> 
> The reason that this could be important is that, unlike other,
> non-startup options, the startup options will only effect GDB's
> startup process.  As a result setting the option within a GDB session
> will not change how the user experiences that session, but could only
> effect the following sessions.
> 
> We could take the position that it is entirely the users
> responsibility to add these options to a startup file and maintain
> them, however, this commit provides a mechanism to automate that
> management.
> 
> If a user adds the following lines to ~/.config/gdb/gdbstartup:
> 
>   set startup-save-filename ~/.config/gdb/auto-save
>   source ~/.config/gdb/auto-save
> 
> Then GDB will write all startup options to the file auto-save file any
> time one of the options is modified.  The source ensures that the
> options are reloaded correctly.

Sorry, I don't think I understand the use case you describe.  Since
the startup options only affect the behavior during the startup
process, and will not change anything if set during the session
itself, why would the user want to change one of those settings
during the session?  AFAIU, such a change will not affect GDB's
behavior in any way.

> +extern void _initialize_cli_setshow ();
> +void
> +_initialize_cli_setshow ()
> +{
> +  add_setshow_filename_cmd ("startup-save-filename", class_support,
> +                            &startup_save_filename, _("\
> +Set the filename to which startup options should be written."), _("\
> +Show the filename to which startup options are written."), _("\
> +Some options only effect the startup of GDB.  When these options are\n\
> +modified GDB can arrange to write the values of all of these options\n\
> +to a file which can then be sourced during startup to reapply these\n\
> +options."),

This doesn't mention that merely setting the variable has the effect
of turning on the auto-saving (as far as I understand).

> +@node Automatically saving startup settings
> +@section Automatically saving startup settings
> +@table @code
> +@kindex show startup-save-filename
> +@kindex set startup-save-filename filename
> +@cindex @value{GDBN} startup settings
> +@item show startup-save-filename
> +@itemx set startup-save-filename @var{filename}
> +Some settings only effect the early startup behaviour of @value{GDBN}.
                      ^^^^^^
"affect"

Also, I don't think "early startup behavior" is a term we explain
anywhere, so it presents a small puzzle to the reader.  Can we explain
it somewhere?

> +In order to make use of these settings they will need to be added to a
> +startup file, for example @file{~/.config/gdb/gdbstartup}
> +(@pxref{Startup}).
> +
> +When @samp{startup-save-filename} is set to a valid path @value{GDBN}
> +will automatically save all startup settings to this file whenever they
> +are modified in a @value{GDBN} session.  The save file can then be
> +loaded using @samp{source} (@pxref{Command Files}).
> +
> +For example, these commands could be placed into
> +@file{~/.config/gdb/gdbstartup} in order to have GDB automatically
> +save and restore startup settings:
> +
> +@smallexample
> +set startup-save-filename ~/.config/gdb/autosave
> +source ~/.config/gdb/autosave
> +@end smallexample
> +@end table

I think this should explain the use case when this is useful, see
above.  Upon reading this description, I don't think I understand the
use case.

Thanks.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 6/7] Let the user control the startup style
  2020-10-07 20:05 ` [PATCH 6/7] Let the user control the startup style Andrew Burgess
@ 2020-10-08  6:40   ` Eli Zaretskii
  0 siblings, 0 replies; 24+ messages in thread
From: Eli Zaretskii @ 2020-10-08  6:40 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches, tom

> From: Andrew Burgess <andrew.burgess@embecosm.com>
> Date: Wed,  7 Oct 2020 21:05:10 +0100
> Cc: Tom Tromey <tom@tromey.com>
> 
> diff --git a/gdb/NEWS b/gdb/NEWS
> index bd3aca84d51..d72d51b18b6 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -132,6 +132,13 @@ show exec-file-mismatch -- Show exec-file-mismatch handling (ask|warn|off).
>    executable file; if 'warn', just display a warning; if 'off', don't
>    attempt to detect a mismatch.
>  
> +set style startup foreground COLOR
> +set style startup background COLOR
> +set style startup intensity VALUE
> +  Control the styling of startup text.  This saves the setting into
> +  a special configuration file, so that it can be read during startup
> +  and applied.

The second sentence is unclear: do you mean that setting the style
saves the setting into a file?  Isn't that true only if such saving
was enabled by specifying the name of that file?

> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 66b87608b89..f11948e8c4f 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -25880,6 +25880,21 @@
>  @code{set style address} family of commands.  By default, this style's
>  foreground color is blue.
>  
> +@item startup
> +Control the styling of some text that is printed at startup.  These
> +are managed with the @code{set style startup} family of commands.  By
> +default, this style's foreground color is magenta and it has bold
> +intensity.  Changing these settings will cause them to automatically
> +be saved in a special configuration file, which is read by
> +@value{GDBN} early in its startup.

Same comment here.

> +The directory in which this file appears depends on the host platform.
> +On most systems, the file is in the @file{gdb} subdirectory of the
> +directory pointed to by the @env{XDG_CONFIG_HOME} environment
> +variable, if it is defined, else in the @file{.config/gdb}
> +subdirectory of your home directory.  However, on some systems, the
> +default may differ according to local convention.

This seems to describe (in less detail) what was already described in
another place in the manual.  Please replace this text (sans the first
sentence) with a cross-reference to that other place.

Thanks.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 7/7] Add "set startup-quietly"
  2020-10-07 20:05 ` [PATCH 7/7] Add "set startup-quietly" Andrew Burgess
@ 2020-10-08  6:44   ` Eli Zaretskii
  0 siblings, 0 replies; 24+ messages in thread
From: Eli Zaretskii @ 2020-10-08  6:44 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches, tom

> From: Andrew Burgess <andrew.burgess@embecosm.com>
> Date: Wed,  7 Oct 2020 21:05:11 +0100
> Cc: Tom Tromey <tom@tromey.com>
> 
> +set startup-quietly on|off
> +show startup-quietly
> +  When enabled, this causes GDB to act as if "-silent" were always
> +  passed on the command line.  This saves the setting into a special
> +  configuration file, so that it can be read during startup and
> +  applied.

As I wrote earlier, the second sentence is inaccurate/incomplete.

> +@kindex set startup-quietly
> +@kindex show startup-quietly
> +This can also be enabled using @code{set startup-quietly on}.  The
> +default is @code{off}.  Use @code{show startup-quietly} to see the
> +current setting.  Changing this setting will cause it to automatically
> +be saved in a special configuration file, which is read by
> +@value{GDBN} early in its startup.

Likewise.  Also, the text should say explicitly that the setting will
not affect any aspect of GDB behavior during the current session.

> +The directory in which this file appears depends on the host platform.
> +On most systems, the file is in the @file{gdb} subdirectory of the
> +directory pointed to by the @env{XDG_CONFIG_HOME} environment
> +variable, if it is defined, else in the @file{.config/gdb}
> +subdirectory of your home directory.  However, on some systems, the
> +default may differ according to local convention.

Once again, this has been already documented elsewhere in the manual,
and in more detail.  Please leave here just the cross-reference to
that place, and please call that file "startup file", for consistency
with the terminology there.
> +  c = add_setshow_boolean_cmd ("startup-quietly", class_support,
> +			       &startup_quiet, _("\
> +Set whether GDB should start up quietly."), _("		\
> +Show whether GDB should start up quietly."), NULL,

I think the doc string should mention that the setting has no effect
in this session.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 2/7] gdb: use get_standard_config_dir when looking for .gdbinit
  2020-10-07 20:05 ` [PATCH 2/7] gdb: use get_standard_config_dir when looking for .gdbinit Andrew Burgess
@ 2020-10-08  6:52   ` Eli Zaretskii
  2020-11-02 10:20     ` Andrew Burgess
  2020-10-22 19:07   ` Tom Tromey
  2020-11-09 13:52   ` Tom Tromey
  2 siblings, 1 reply; 24+ messages in thread
From: Eli Zaretskii @ 2020-10-08  6:52 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches, tom

> From: Andrew Burgess <andrew.burgess@embecosm.com>
> Date: Wed,  7 Oct 2020 21:05:06 +0100
> Cc: Tom Tromey <tom@tromey.com>
> 
> This commit effectively changes the default location of the .gdbinit
> file, while maintaining backward compatibility.
> 
> For non Apple hosts the .gdbinit file will now be looked for in the
> following locations:
> 
>   $XDG_CONFIG_HOME/gdb/gdbinit
>   $HOME/.config/gdb/gdbinit
>   $HOME/.gdbinit
> 
> On Apple hosts the search order is instead:
> 
>   $HOME/Library/Preferences/gdb/gdbinit
>   $HOME/.gdbinit

Thanks.

I still wonder why we treat Apple specially here.

> +Do not execute commands found in any initialization file

"files"

Also, I think this should say "in any startup or initialization
files", as startup file loading is also prevented, right?

> +(@pxref{Initialization Files}).

There should be a cross-reference to where startup files are described
as well.

> +As the system wide and home directory initialization files are
> +@value{GDBN} will check the current directory for a file called
> +@file{./.gdbinit}.  It is loaded last, after command line options
         ^^^^^^^^^^
The "./" part is redundant here.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 0/7] Adding startup files to GDB
  2020-10-07 20:05 [PATCH 0/7] Adding startup files to GDB Andrew Burgess
                   ` (6 preceding siblings ...)
  2020-10-07 20:05 ` [PATCH 7/7] Add "set startup-quietly" Andrew Burgess
@ 2020-10-08  6:56 ` Eli Zaretskii
  2020-10-22 19:02 ` Tom Tromey
  8 siblings, 0 replies; 24+ messages in thread
From: Eli Zaretskii @ 2020-10-08  6:56 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches, tom

> From: Andrew Burgess <andrew.burgess@embecosm.com>
> Date: Wed,  7 Oct 2020 21:05:04 +0100
> Cc: Tom Tromey <tom@tromey.com>
> 
> This series introduces a new set of command line options and config
> files that can be read very early during the startup process, these
> files/command line flags can then be used to control the very early
> actions that would otherwise not be user controllable.

Even after I've read the documentation parts of the entire series
(which was confusing due to the docs being dispersed between the
messages, and the basic issue with email that you cannot ensure the
order in which the messages wind up in the addressee's inbox), I must
say that I don't understand why we need to expose the startup settings
as normal user options changeable during a session.  Since changing
those settings during a session is useless, why have them as options
at all?  We could simply honor them as "options" only in the startup
files, and do away with the auto-saving feature.  After all, how hard
is it for a developer who uses GDB to debug his/her programs to start
up an editor and edit the startup file?  It sounds like much ado about
nothing to me.  FWIW.

Thanks.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* RE: [PATCH 3/7] gdb: new function to wrap up executing command line scripts/commands
  2020-10-07 20:05 ` [PATCH 3/7] gdb: new function to wrap up executing command line scripts/commands Andrew Burgess
@ 2020-10-08 15:25   ` Aktemur, Tankut Baris
  2020-11-02  9:48     ` Andrew Burgess
  2020-10-22 19:08   ` Tom Tromey
  1 sibling, 1 reply; 24+ messages in thread
From: Aktemur, Tankut Baris @ 2020-10-08 15:25 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches; +Cc: Tom Tromey

On Wednesday, October 7, 2020 10:05 PM, Andrew Burgess wrote:
> Small refactor to wrap up executing the scripts and commands passed
> using the -x, -ex, -ix, -iex command line flags.
> 
> There should be no user visible changes after this commit.
> 
> gdb/ChangeLog:
> 
> 	* main.c (execute_cmdargs): New function.
> 	(captured_main_1): Make use of execute_cmdargs.
> ---
>  gdb/ChangeLog |  5 +++++
>  gdb/main.c    | 53 ++++++++++++++++++++-------------------------------
>  2 files changed, 26 insertions(+), 32 deletions(-)
> 
> diff --git a/gdb/main.c b/gdb/main.c
> index f6377f2df28..f85b7dbfdaa 100644
> --- a/gdb/main.c
> +++ b/gdb/main.c
> @@ -515,6 +515,25 @@ struct cmdarg
>    char *string;
>  };
> 
> +/* From CMDARG_VEC execute command files (matching FILE_TYPE) or commands
> +   (matching CMD_TYPE).  Update the value in *RET.  */

Is there any particular reason to have the output parameter?  The function could have 
returned its result instead of writing it to *ret, right?

> +static void
> +execute_cmdargs (const std::vector<struct cmdarg> *cmdarg_vec,
> +		 cmdarg_kind file_type, cmdarg_kind cmd_type,
> +		 int *ret)
> +{
> +  for (const auto &cmdarg_p : *cmdarg_vec)
> +    {
> +      if (cmdarg_p.type == file_type)
> +	*ret = catch_command_errors (source_script, cmdarg_p.string,
> +				     !batch_flag);
> +      else if (cmdarg_p.type == cmd_type)
> +	*ret = catch_command_errors (execute_command, cmdarg_p.string,
> +				     !batch_flag);
> +    }

Well, it's the original code that was doing it, but I found it a bit odd that
ret is being overwritten without checking the value until almost the very end
of captured_main_1.

-Baris


Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Gary Kershaw
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 0/7] Adding startup files to GDB
  2020-10-07 20:05 [PATCH 0/7] Adding startup files to GDB Andrew Burgess
                   ` (7 preceding siblings ...)
  2020-10-08  6:56 ` [PATCH 0/7] Adding startup files to GDB Eli Zaretskii
@ 2020-10-22 19:02 ` Tom Tromey
  2020-10-28 15:29   ` Andrew Burgess
  2021-01-11 16:45   ` Andrew Burgess
  8 siblings, 2 replies; 24+ messages in thread
From: Tom Tromey @ 2020-10-22 19:02 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches, Tom Tromey

Andrew> Patch #4 adds the startup file support.  Compared to Tom's original work:
Andrew>    (a) there's no auto saving of startup options,
   
Andrew>    (b) there's command line flag support for passing startup options
Andrew>        to GDB.
   
Andrew>    (c) there's support for a home directory and current working
Andrew>        directory startup file (only because this is basically free
Andrew>        given the restructuring of the code).

Andrew> Patch #5 adds back the auto-save feature from Tom's series, however, I
Andrew> have this off by default.  I (personally) dislike the auto-save
Andrew> feature, though I can see why some users might want it.  I hope the
Andrew> proposal I have here is might be a good middle ground.

Could you say why you dislike it?

The reason I did it the way I did is that I thought it was strange to
have a command like "set startup-blah-blah off" that would be useless to
use in a running gdb.  It seemed to me that the name & intended use of
the command implied auto-saving.

Regardless of the choice here, I don't think it makes sense to have
another option to control whether the first options are auto-saved.
This is "feature to enable a feature" territory for me.

Tom

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 2/7] gdb: use get_standard_config_dir when looking for .gdbinit
  2020-10-07 20:05 ` [PATCH 2/7] gdb: use get_standard_config_dir when looking for .gdbinit Andrew Burgess
  2020-10-08  6:52   ` Eli Zaretskii
@ 2020-10-22 19:07   ` Tom Tromey
  2020-11-09 13:52   ` Tom Tromey
  2 siblings, 0 replies; 24+ messages in thread
From: Tom Tromey @ 2020-10-22 19:07 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches, Tom Tromey

>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:

Andrew> gdb/ChangeLog:

Andrew> 	* NEWS: Mention changes to config file search path.
Andrew> 	* main.c

Incomplete changelog entry here.
The patch itself looks good.

Tom

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 3/7] gdb: new function to wrap up executing command line scripts/commands
  2020-10-07 20:05 ` [PATCH 3/7] gdb: new function to wrap up executing command line scripts/commands Andrew Burgess
  2020-10-08 15:25   ` Aktemur, Tankut Baris
@ 2020-10-22 19:08   ` Tom Tromey
  1 sibling, 0 replies; 24+ messages in thread
From: Tom Tromey @ 2020-10-22 19:08 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches, Tom Tromey

>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:

Andrew> gdb/ChangeLog:

Andrew> 	* main.c (execute_cmdargs): New function.
Andrew> 	(captured_main_1): Make use of execute_cmdargs.

Looks fine.  Thank you.

Tom

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 0/7] Adding startup files to GDB
  2020-10-22 19:02 ` Tom Tromey
@ 2020-10-28 15:29   ` Andrew Burgess
  2021-01-11 16:45   ` Andrew Burgess
  1 sibling, 0 replies; 24+ messages in thread
From: Andrew Burgess @ 2020-10-28 15:29 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

* Tom Tromey <tom@tromey.com> [2020-10-22 13:02:07 -0600]:

> Andrew> Patch #4 adds the startup file support.  Compared to Tom's original work:
> Andrew>    (a) there's no auto saving of startup options,
>    
> Andrew>    (b) there's command line flag support for passing startup options
> Andrew>        to GDB.
>    
> Andrew>    (c) there's support for a home directory and current working
> Andrew>        directory startup file (only because this is basically free
> Andrew>        given the restructuring of the code).
> 
> Andrew> Patch #5 adds back the auto-save feature from Tom's series, however, I
> Andrew> have this off by default.  I (personally) dislike the auto-save
> Andrew> feature, though I can see why some users might want it.  I hope the
> Andrew> proposal I have here is might be a good middle ground.
> 
> Could you say why you dislike it?

Sure.  I just have a general dislike of tools that auto-write config
files.  I prefer to be able to modify these files myself.

I guess the counter position is that a user should never be touching
these files by hand, they should be considered more of an internal
cache.

Another area where auto-saving might cause problems might be if a user
runs multiple versions of GDB (e.g. a desktop version, and several
different versions built to debug different remote targets), if these
versions have different sets of features that they auto-save then a
user will end up "loosing" settings in some cases I think.
> 
> The reason I did it the way I did is that I thought it was strange to
> have a command like "set startup-blah-blah off" that would be useless to
> use in a running gdb.  It seemed to me that the name & intended use of
> the command implied auto-saving.

Understood.

> 
> Regardless of the choice here, I don't think it makes sense to have
> another option to control whether the first options are auto-saved.
> This is "feature to enable a feature" territory for me.

I don't really understand what "feature to enable a feature" means.
Does this mean you don't see any way that having a flag to control
auto-saving could be acceptable?  What if it was just simple that I
proposed here, say 'set auto-save-startup-options on|off', which could
then be placed in to the startup file to disable auto-save?

Thanks,
Andrew

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 3/7] gdb: new function to wrap up executing command line scripts/commands
  2020-10-08 15:25   ` Aktemur, Tankut Baris
@ 2020-11-02  9:48     ` Andrew Burgess
  0 siblings, 0 replies; 24+ messages in thread
From: Andrew Burgess @ 2020-11-02  9:48 UTC (permalink / raw)
  To: Aktemur, Tankut Baris; +Cc: gdb-patches, Tom Tromey

* Aktemur, Tankut Baris <tankut.baris.aktemur@intel.com> [2020-10-08 15:25:25 +0000]:

> On Wednesday, October 7, 2020 10:05 PM, Andrew Burgess wrote:
> > Small refactor to wrap up executing the scripts and commands passed
> > using the -x, -ex, -ix, -iex command line flags.
> > 
> > There should be no user visible changes after this commit.
> > 
> > gdb/ChangeLog:
> > 
> > 	* main.c (execute_cmdargs): New function.
> > 	(captured_main_1): Make use of execute_cmdargs.
> > ---
> >  gdb/ChangeLog |  5 +++++
> >  gdb/main.c    | 53 ++++++++++++++++++++-------------------------------
> >  2 files changed, 26 insertions(+), 32 deletions(-)
> > 
> > diff --git a/gdb/main.c b/gdb/main.c
> > index f6377f2df28..f85b7dbfdaa 100644
> > --- a/gdb/main.c
> > +++ b/gdb/main.c
> > @@ -515,6 +515,25 @@ struct cmdarg
> >    char *string;
> >  };
> > 
> > +/* From CMDARG_VEC execute command files (matching FILE_TYPE) or commands
> > +   (matching CMD_TYPE).  Update the value in *RET.  */
> 
> Is there any particular reason to have the output parameter?  The function could have 
> returned its result instead of writing it to *ret, right?
> 
> > +static void
> > +execute_cmdargs (const std::vector<struct cmdarg> *cmdarg_vec,
> > +		 cmdarg_kind file_type, cmdarg_kind cmd_type,
> > +		 int *ret)
> > +{
> > +  for (const auto &cmdarg_p : *cmdarg_vec)
> > +    {
> > +      if (cmdarg_p.type == file_type)
> > +	*ret = catch_command_errors (source_script, cmdarg_p.string,
> > +				     !batch_flag);
> > +      else if (cmdarg_p.type == cmd_type)
> > +	*ret = catch_command_errors (execute_command, cmdarg_p.string,
> > +				     !batch_flag);
> > +    }
> 
> Well, it's the original code that was doing it, but I found it a bit odd that
> ret is being overwritten without checking the value until almost the very end
> of captured_main_1.

I find this odd too, but the last thing I wanted to do was combine a
change in behaviour with a restructuring, so I left things as they
were.

I'll update the comment on the function to (hopefully) document the
existing (odd) behaviour a little better.

Thanks,
Andrew

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 2/7] gdb: use get_standard_config_dir when looking for .gdbinit
  2020-10-08  6:52   ` Eli Zaretskii
@ 2020-11-02 10:20     ` Andrew Burgess
  0 siblings, 0 replies; 24+ messages in thread
From: Andrew Burgess @ 2020-11-02 10:20 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches, tom

* Eli Zaretskii <eliz@gnu.org> [2020-10-08 09:52:14 +0300]:

> > From: Andrew Burgess <andrew.burgess@embecosm.com>
> > Date: Wed,  7 Oct 2020 21:05:06 +0100
> > Cc: Tom Tromey <tom@tromey.com>
> > 
> > This commit effectively changes the default location of the .gdbinit
> > file, while maintaining backward compatibility.
> > 
> > For non Apple hosts the .gdbinit file will now be looked for in the
> > following locations:
> > 
> >   $XDG_CONFIG_HOME/gdb/gdbinit
> >   $HOME/.config/gdb/gdbinit
> >   $HOME/.gdbinit
> > 
> > On Apple hosts the search order is instead:
> > 
> >   $HOME/Library/Preferences/gdb/gdbinit
> >   $HOME/.gdbinit
> 
> Thanks.
> 
> I still wonder why we treat Apple specially here.
> 
> > +Do not execute commands found in any initialization file
> 
> "files"
> 
> Also, I think this should say "in any startup or initialization
> files", as startup file loading is also prevented, right?
> 
> > +(@pxref{Initialization Files}).
> 
> There should be a cross-reference to where startup files are described
> as well.

Eli,

Thanks for the review.

I'm going to push the first 3 patches in this series as they have had
positive feedback, and can be considered separate from the other 4
patches.

As these first 3 don't introduce startup files (they were just setup
for that) then I'll not make the startup file related changes you
suggest here, instead I'll make these changes in the later patches as
I rebase them.

The other fixes you have suggested I have of course made.

Thanks,
Andrew


> 
> > +As the system wide and home directory initialization files are
> > +@value{GDBN} will check the current directory for a file called
> > +@file{./.gdbinit}.  It is loaded last, after command line options
>          ^^^^^^^^^^
> The "./" part is redundant here.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 2/7] gdb: use get_standard_config_dir when looking for .gdbinit
  2020-10-07 20:05 ` [PATCH 2/7] gdb: use get_standard_config_dir when looking for .gdbinit Andrew Burgess
  2020-10-08  6:52   ` Eli Zaretskii
  2020-10-22 19:07   ` Tom Tromey
@ 2020-11-09 13:52   ` Tom Tromey
  2020-11-09 13:55     ` Tom Tromey
  2 siblings, 1 reply; 24+ messages in thread
From: Tom Tromey @ 2020-11-09 13:52 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches, Tom Tromey

>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:

Andrew> This commit effectively changes the default location of the .gdbinit
Andrew> file, while maintaining backward compatibility.

Andrew> diff --git a/gdbsupport/pathstuff.cc b/gdbsupport/pathstuff.cc
Andrew> index 9fb5e5cf614..a52e53b8671 100644
Andrew> --- a/gdbsupport/pathstuff.cc
Andrew> +++ b/gdbsupport/pathstuff.cc
Andrew> @@ -23,6 +23,10 @@
Andrew>  #include "filenames.h"
Andrew>  #include "gdb_tilde_expand.h"
 
Andrew> +#include <sys/types.h>
Andrew> +#include <sys/stat.h>
Andrew> +#include <unistd.h>
Andrew> +
Andrew>  #ifdef USE_WIN32API
Andrew>  #include <windows.h>
Andrew>  #endif
Andrew> @@ -298,6 +302,51 @@ get_standard_config_dir ()
Andrew>    return {};
Andrew>  }
 
Andrew> +std::string
Andrew> +find_gdb_home_config_file (const char *name, struct stat *buf)
Andrew> +{

For my mingw build, this fails with:

  CXX      pathstuff.o
../../binutils-gdb/gdbsupport/pathstuff.cc:324:1: error: no previous declaration for 'std::string find_gdb_home_config_file(const char*, _stati64*)' [-Werror=missing-declarations]
  324 | find_gdb_home_config_file (const char *name, struct stat *buf)
      | ^~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors

I suppose the definition of "stat" changes between the header and the
.cc file, probably due to the new includes somehow.

I configure like this:

../binutils-gdb/configure '--host=i686-w64-mingw32' '--target=i686-w64-mingw32' '--disable-binutils' '--disable-gas' '--disable-gold' '--disable-gprof' '--disable-ld' '--disable-guile' '--disable-source-highlight' 'host_alias=i686-w64-mingw32' 'target_alias=i686-w64-mingw32' '--without-debuginfod'

This build is done on x86-64 Fedora 32.

Tom

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 2/7] gdb: use get_standard_config_dir when looking for .gdbinit
  2020-11-09 13:52   ` Tom Tromey
@ 2020-11-09 13:55     ` Tom Tromey
  0 siblings, 0 replies; 24+ messages in thread
From: Tom Tromey @ 2020-11-09 13:55 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Andrew Burgess, gdb-patches

Andrew> +#include <sys/types.h>
Andrew> +#include <sys/stat.h>
Andrew> +#include <unistd.h>

Moving this block to pathstuff.h seems to work though.

Tom

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 0/7] Adding startup files to GDB
  2020-10-22 19:02 ` Tom Tromey
  2020-10-28 15:29   ` Andrew Burgess
@ 2021-01-11 16:45   ` Andrew Burgess
  1 sibling, 0 replies; 24+ messages in thread
From: Andrew Burgess @ 2021-01-11 16:45 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

* Tom Tromey <tom@tromey.com> [2020-10-22 13:02:07 -0600]:

> Andrew> Patch #4 adds the startup file support.  Compared to Tom's original work:
> Andrew>    (a) there's no auto saving of startup options,
>    
> Andrew>    (b) there's command line flag support for passing startup options
> Andrew>        to GDB.
>    
> Andrew>    (c) there's support for a home directory and current working
> Andrew>        directory startup file (only because this is basically free
> Andrew>        given the restructuring of the code).
> 
> Andrew> Patch #5 adds back the auto-save feature from Tom's series, however, I
> Andrew> have this off by default.  I (personally) dislike the auto-save
> Andrew> feature, though I can see why some users might want it.  I hope the
> Andrew> proposal I have here is might be a good middle ground.
> 
> Could you say why you dislike it?
> 
> The reason I did it the way I did is that I thought it was strange to
> have a command like "set startup-blah-blah off" that would be useless to
> use in a running gdb.  It seemed to me that the name & intended use of
> the command implied auto-saving.
> 
> Regardless of the choice here, I don't think it makes sense to have
> another option to control whether the first options are auto-saved.
> This is "feature to enable a feature" territory for me.

Tom,

I don't really understand how "feature to enable a feature" is
different from lots of the other features in GDB that have a feature
(setting) to enable them.

Are you just suggesting that auto-save should be on by default?  If it
was on by default, but could be turned off with a setting, would this
be more acceptable to you?

Thanks,
Andrew

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2021-01-11 16:45 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-07 20:05 [PATCH 0/7] Adding startup files to GDB Andrew Burgess
2020-10-07 20:05 ` [PATCH 1/7] Add get_standard_config_dir function Andrew Burgess
2020-10-07 20:05 ` [PATCH 2/7] gdb: use get_standard_config_dir when looking for .gdbinit Andrew Burgess
2020-10-08  6:52   ` Eli Zaretskii
2020-11-02 10:20     ` Andrew Burgess
2020-10-22 19:07   ` Tom Tromey
2020-11-09 13:52   ` Tom Tromey
2020-11-09 13:55     ` Tom Tromey
2020-10-07 20:05 ` [PATCH 3/7] gdb: new function to wrap up executing command line scripts/commands Andrew Burgess
2020-10-08 15:25   ` Aktemur, Tankut Baris
2020-11-02  9:48     ` Andrew Burgess
2020-10-22 19:08   ` Tom Tromey
2020-10-07 20:05 ` [PATCH 4/7] gdb: process startup files and startup command line options Andrew Burgess
2020-10-08  6:28   ` Eli Zaretskii
2020-10-07 20:05 ` [PATCH 5/7] gdb: add mechanism to auto-save startup options Andrew Burgess
2020-10-08  6:36   ` Eli Zaretskii
2020-10-07 20:05 ` [PATCH 6/7] Let the user control the startup style Andrew Burgess
2020-10-08  6:40   ` Eli Zaretskii
2020-10-07 20:05 ` [PATCH 7/7] Add "set startup-quietly" Andrew Burgess
2020-10-08  6:44   ` Eli Zaretskii
2020-10-08  6:56 ` [PATCH 0/7] Adding startup files to GDB Eli Zaretskii
2020-10-22 19:02 ` Tom Tromey
2020-10-28 15:29   ` Andrew Burgess
2021-01-11 16:45   ` Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).