From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 4/4] [gdb] Use make_scoped_restore in captured_main_1
Date: Sun, 20 Sep 2026 15:02:54 +0200 [thread overview]
Message-ID: <20260920130254.604592-5-tdevries@suse.de> (raw)
In-Reply-To: <20260920130254.604592-1-tdevries@suse.de>
Use make_scoped_restore in captured_main_1 to protect a cleanup against
exceptions.
I don't think this is strictly necessary: exceptions that escape out of
captured_main_1 are printed, after which gdb exits, so the state of the
global_auto_load doesn't matter much at that point.
But using make_scoped_restore probably captures the intent better.
I used std::optional to avoid indenting the code in between the save and
restore.
---
gdb/main.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/gdb/main.c b/gdb/main.c
index f49d5f48c9d..ea7ecc468e6 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -652,7 +652,6 @@ captured_main_1 (struct captured_main_args *context)
std::vector<char *> dirarg;
int i;
- int save_auto_load;
int ret = 1;
/* Check for environment variables which might cause GDB to start with
@@ -1238,8 +1237,8 @@ captured_main_1 (struct captured_main_args *context)
/* Skip auto-loading section-specified scripts until we've sourced
local_gdbinit (which is often used to augment the source search
path). */
- save_auto_load = global_auto_load;
- global_auto_load = 0;
+ std::optional<scoped_restore_tmpl<bool>>
+ auto_load_restore (make_scoped_restore (&global_auto_load, false));
if (execarg != nullptr && symarg != nullptr && streq (execarg, symarg))
{
@@ -1333,7 +1332,7 @@ captured_main_1 (struct captured_main_args *context)
processed, we can read any scripts mentioned in SYMARG.
We wait until now because it is common to add to the source search
path in local_gdbinit. */
- global_auto_load = save_auto_load;
+ auto_load_restore.reset ();
for (objfile &objfile : current_program_space->objfiles ())
load_auto_scripts_for_objfile (objfile);
--
2.51.0
next prev parent reply other threads:[~2026-09-20 13:04 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-20 13:02 [PATCH 0/4] [gdb] Use c++-style cleanups a bit more Tom de Vries
2026-09-20 13:02 ` [PATCH 1/4] [gdb] Use make_scoped_restore in z80_read_overlay_region_table Tom de Vries
2026-09-20 13:02 ` [PATCH 2/4] [gdb] Use SCOPE_EXIT in tfile_get_traceframe_address Tom de Vries
2026-09-20 13:02 ` [PATCH 3/4] [gdb] Use make_scoped_restore in linespec_lexer_peek_token Tom de Vries
2026-09-20 13:02 ` Tom de Vries [this message]
2026-09-22 19:37 ` [PATCH 0/4] [gdb] Use c++-style cleanups a bit more Tom Tromey
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=20260920130254.604592-5-tdevries@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
/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