From: Andrew Burgess <andrew.burgess@embecosm.com>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH v2 5/7] Add early startup command file
Date: Wed, 26 Aug 2020 16:47:03 +0100 [thread overview]
Message-ID: <20200826154703.GW853475@embecosm.com> (raw)
In-Reply-To: <20200623132006.15863-6-tom@tromey.com>
* Tom Tromey <tom@tromey.com> [2020-06-23 07:20:04 -0600]:
> This adds support for a gdb command file to be read early in startup.
> Code that wants to save an early setting can register a callback to be
> called to write to this file. This code is not yet used, but will be
> in subsequent patches.
>
> 2020-06-22 Tom Tromey <tom@tromey.com>
>
> * main.c (captured_main_1): Call read_startup_file.
> * cli/cli-setshow.h (write_startup_functions, add_startup_writer)
> (read_startup_file): Declare.
> (write_startup_setting_ftype): New typedef.
> * cli/cli-setshow.c (STARTUP_FILE): New define.
> (write_startup_functions, startup_file_read): New globals.
> (write_startup_file, add_startup_writer, read_startup_file): New
> functions.
I think that this patch needs some documentation in, at least, the
'@node Startup' section of the manual.
Also I think that if this config file is going to be generated as
~/.config/gdb/... then we should allow the gdbinit file to be moved
into that directory too, though obviously this would be a follow up
patch.
Thanks,
Andrew
> ---
> gdb/ChangeLog | 11 +++++++
> gdb/cli/cli-setshow.c | 76 +++++++++++++++++++++++++++++++++++++++++++
> gdb/cli/cli-setshow.h | 21 ++++++++++++
> gdb/main.c | 5 +++
> 4 files changed, 113 insertions(+)
>
> diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c
> index 19a5565bfe0..32e867160cb 100644
> --- a/gdb/cli/cli-setshow.c
> +++ b/gdb/cli/cli-setshow.c
> @@ -21,6 +21,8 @@
> #include <ctype.h>
> #include "arch-utils.h"
> #include "observable.h"
> +#include "gdbsupport/pathstuff.h"
> +#include <vector>
>
> #include "ui-out.h"
>
> @@ -29,6 +31,80 @@
> #include "cli/cli-setshow.h"
> #include "cli/cli-utils.h"
>
> +/* File name for startup style. */
> +
> +#define STARTUP_FILE "startup-commands"
> +
> +/* Callbacks that will be called to write out startup settings. */
> +static std::vector<write_startup_setting_ftype *> write_startup_functions;
> +
> +/* True after gdb has read the startup file. */
> +static bool startup_file_read;
> +
> +/* See cli-setshow.h. */
> +
> +void
> +write_startup_file ()
> +{
> + std::string config_dir = get_standard_config_dir ();
> +
> + if (config_dir.empty ())
> + {
> + warning (_("Couldn't determine a path for the startup settings."));
> + return;
> + }
> +
> + if (!mkdir_recursive (config_dir.c_str ()))
> + {
> + warning (_("Could not make config directory: %s"),
> + safe_strerror (errno));
> + return;
> + }
> +
> + std::string fullname = config_dir + "/" + STARTUP_FILE;
> + stdio_file outfile;
> +
> + if (!outfile.open (fullname.c_str (), FOPEN_WT))
> + perror_with_name (fullname.c_str ());
> +
> + for (auto &callback : write_startup_functions)
> + callback (&outfile);
> +}
> +
> +/* See cli-setshow.h. */
> +
> +void
> +add_startup_writer (write_startup_setting_ftype *callback)
> +{
> + write_startup_functions.push_back (callback);
> +}
> +
> +/* See cli-setshow.h. */
> +
> +void
> +read_startup_file ()
> +{
> + std::string config_dir = get_standard_config_dir ();
> +
> + if (!config_dir.empty ())
> + {
> + std::string filename = config_dir + "/" + STARTUP_FILE;
> + try
> + {
> + source_script (filename.c_str (), 1);
> + /* If reading fails, we don't want to write the file -- it
> + might overwrite something. So, we set this flag after
> + reading. */
> + startup_file_read = true;
> + }
> + catch (const gdb_exception &)
> + {
> + /* Ignore errors. */
> + }
> + }
> +}
> +
> +\f
> /* Return true if the change of command parameter should be notified. */
>
> static int
> diff --git a/gdb/cli/cli-setshow.h b/gdb/cli/cli-setshow.h
> index 83e4984ed6c..35e229022ff 100644
> --- a/gdb/cli/cli-setshow.h
> +++ b/gdb/cli/cli-setshow.h
> @@ -62,4 +62,25 @@ 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 *);
> +
> +/* Add a callback function that will be called when writing the
> + startup sequence. */
> +
> +extern void add_startup_writer (write_startup_setting_ftype *callback);
> +
> +/* Read the startup file. This should only be called by the gdb
> + startup sequence. */
> +
> +extern void read_startup_file ();
> +
> #endif /* CLI_CLI_SETSHOW_H */
> diff --git a/gdb/main.c b/gdb/main.c
> index 3649e4a2201..bd1f6d6b2c5 100644
> --- a/gdb/main.c
> +++ b/gdb/main.c
> @@ -35,6 +35,7 @@
> #include "main.h"
> #include "source.h"
> #include "cli/cli-cmds.h"
> +#include "cli/cli-setshow.h"
> #include "objfiles.h"
> #include "auto-load.h"
> #include "maint.h"
> @@ -933,6 +934,10 @@ captured_main_1 (struct captured_main_args *context)
> /* Initialize all files. */
> gdb_init (gdb_program_name);
>
> + /* Set the startup style. */
> + if (!inhibit_gdbinit && !inhibit_home_gdbinit)
> + read_startup_file ();
> +
> /* Now that gdb_init has created the initial inferior, we're in
> position to set args for that inferior. */
> if (set_args)
> --
> 2.17.2
>
next prev parent reply other threads:[~2020-08-26 15:47 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-23 13:19 [PATCH v2 0/7] Some user-friendliness changes Tom Tromey
2020-06-23 13:20 ` [PATCH v2 1/7] Introduce read_entire_file Tom Tromey
2020-07-06 13:47 ` Simon Marchi
2020-10-02 10:24 ` Andrew Burgess
2020-06-23 13:20 ` [PATCH v2 2/7] Add "help news" Tom Tromey
2020-06-23 14:35 ` Eli Zaretskii
2020-06-23 18:18 ` Christian Biesinger
2020-07-05 15:59 ` Tom Tromey
2020-07-06 14:14 ` Simon Marchi
2020-07-11 15:30 ` Tom Tromey
2020-07-06 14:06 ` Simon Marchi
2020-07-06 14:18 ` Simon Marchi
2020-07-11 15:56 ` Tom Tromey
2020-07-06 14:22 ` Simon Marchi
2020-07-11 15:31 ` Tom Tromey
2020-06-23 13:20 ` [PATCH v2 3/7] Add "tips" file to gdb Tom Tromey
2020-06-23 14:36 ` Eli Zaretskii
2020-07-06 14:27 ` Simon Marchi
2020-06-23 13:20 ` [PATCH v2 4/7] Add get_standard_config_dir function Tom Tromey
2020-06-23 13:20 ` [PATCH v2 5/7] Add early startup command file Tom Tromey
2020-07-05 18:51 ` Tom Tromey
2020-08-26 15:47 ` Andrew Burgess [this message]
2020-08-27 16:32 ` Andrew Burgess
2020-06-23 13:20 ` [PATCH v2 6/7] Let the user control the startup style Tom Tromey
2020-06-23 14:41 ` Eli Zaretskii
2020-07-05 18:50 ` Tom Tromey
2020-07-05 19:02 ` Eli Zaretskii
2020-06-23 13:20 ` [PATCH v2 7/7] Add "set startup-quietly" Tom Tromey
2020-06-23 14:45 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200826154703.GW853475@embecosm.com \
--to=andrew.burgess@embecosm.com \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox