From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by sourceware.org (Postfix) with ESMTPS id 95F7C38618A5 for ; Wed, 26 Aug 2020 15:47:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 95F7C38618A5 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=andrew.burgess@embecosm.com Received: by mail-wr1-x442.google.com with SMTP id h15so2274608wrt.12 for ; Wed, 26 Aug 2020 08:47:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Y63C/mBEtjKzRqlcCCsN4gE0STSGM/jskLe/9lFAOPE=; b=Aea1b/ubPq6Maop0FcgXXdK2cMXsmSGP3EEGfzWVzDkWEIoBoJsu9pmVEGfoEFenrz n/Y8hLz4ZcUYBc/rTFT0VX1XLrTAeIcM45DCxds67jWmWNJ2Q7r4p4GHOVnzVyFzZ5Wc KZG+UePQA1yYmy3a/94T7rrlx2RGcOwOKUNN00tk7Cv0qbc7hipqIxJnVeKvWMFvd63E TjUkbQOsYxUWB5NoatDLpRepUOkiY94NtUt0gpVSgifd6PlU55y5ihC44pmmsnNhCCQX Tty7en/+m/VODRgWupAg37z9kHguNgfdUvKZ3FfNQaiIqtERMHg613xI/Sz9CgiTlYvx /w8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Y63C/mBEtjKzRqlcCCsN4gE0STSGM/jskLe/9lFAOPE=; b=bXgZI4aLq9evV+4s4RjLmwIuVragizDmiEgtlxwbr3gFTioKBqca7cD1t6UIod7oTx OxPfI4nJlP/HCc9oGQOSVkB8Gs0CmCqJQcmfv/eAu5VBtTjGO+JhmzpZzHt70rwxxbHD u4vWXXHDlXHi5y1n4ubqc7/YJgYo2rua3WYmU/KfF0KhFVQW+KVTYQuajoQ4b9GTcxky 9XX8FdI8g3tnURnlr96TNrQs6lRG8WOTZAYr3E1fz7v6x8j51tvIUTKawW3D7ChpA6U7 MFL0O1cT2IKkwfuUT4KOfe1vbgjrSIer4MfiPfBii/4t6ItHCHaF6aA7mwoELvhIoJte qVVg== X-Gm-Message-State: AOAM530eaMMQQSJqCtDyD7l2URdhoVnF/tEAvp/94nQjS3kZ5p78D1tz AVQFRqDu0DDK3+bEhl1tyu4Xq67RRjDkHQ== X-Google-Smtp-Source: ABdhPJzLg4BDAkJOT2PUgjVTTCpKCFUjhfy9nTgBIKRYvEoKgrCIf38Xb57dakSKJ/+ikyfKUasrLQ== X-Received: by 2002:adf:ee83:: with SMTP id b3mr16096926wro.21.1598456825518; Wed, 26 Aug 2020 08:47:05 -0700 (PDT) Received: from localhost (host109-148-134-218.range109-148.btcentralplus.com. [109.148.134.218]) by smtp.gmail.com with ESMTPSA id u17sm8275949wrp.81.2020.08.26.08.47.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Aug 2020 08:47:04 -0700 (PDT) Date: Wed, 26 Aug 2020 16:47:03 +0100 From: Andrew Burgess To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [PATCH v2 5/7] Add early startup command file Message-ID: <20200826154703.GW853475@embecosm.com> References: <20200623132006.15863-1-tom@tromey.com> <20200623132006.15863-6-tom@tromey.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200623132006.15863-6-tom@tromey.com> X-Operating-System: Linux/5.6.15-200.fc31.x86_64 (x86_64) X-Uptime: 16:44:20 up 39 days, 58 min, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_ABUSEAT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Aug 2020 15:47:08 -0000 * Tom Tromey [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 > > * 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 > #include "arch-utils.h" > #include "observable.h" > +#include "gdbsupport/pathstuff.h" > +#include > > #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_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. */ > + } > + } > +} > + > + > /* 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 >