From: Tom de Vries <tdevries@suse.de>
To: simon.marchi@polymtl.ca, gdb-patches@sourceware.org
Subject: Re: [PATCH 1/2] gdb, gdbserver, gdbsupport: use [[maybe_unused]] instead of ATTRIBUTE_UNUSED
Date: Fri, 19 Jun 2026 14:49:10 +0200 [thread overview]
Message-ID: <56913a13-2ca4-4c0b-be00-5f1c479122a7@suse.de> (raw)
In-Reply-To: <20260618175118.3758778-1-simon.marchi@polymtl.ca>
On 6/18/26 7:50 PM, simon.marchi@polymtl.ca wrote:
> From: Simon Marchi <simon.marchi@polymtl.ca>
>
> Since we require C++17, replace the uses of the ATTRIBUTE_UNUSED macro
> (which expands to __attribute__ ((__unused__))) with the standard
> [[maybe_unused]] attribute.
>
> I think that some of these attribute uses are not necessary, but I did
> not make an attempt to remove them, that would be for another patch.
>
Hi,
these both look fine to me.
Reviewed-By: Tom de Vries <tdevries@suse.de>
Thanks,
- Tom
> Change-Id: I62529d94153c65e2b3c49ff5330292e60c8a0f9e
> ---
> gdb/inferior.c | 4 ++--
> gdb/inflow.c | 2 +-
> gdb/linux-fork.c | 2 +-
> gdb/mi/mi-interp.c | 2 +-
> gdb/python/py-utils.c | 2 +-
> gdb/remote.c | 2 +-
> gdb/source-cache.c | 6 +++---
> gdb/thread.c | 4 ++--
> gdb/typeprint.c | 4 ++--
> gdb/unittests/enum-flags-selftests.c | 4 ++--
> gdb/valprint.c | 4 ++--
> gdbserver/linux-aarch64-low.cc | 6 +++---
> gdbserver/x86-tdesc.h | 4 ++--
> gdbsupport/safe-strerror.cc | 4 ++--
> gdbsupport/thread-pool.cc | 6 +++---
> 15 files changed, 28 insertions(+), 28 deletions(-)
>
> diff --git a/gdb/inferior.c b/gdb/inferior.c
> index 1481f46cdd18..7d54845f28ac 100644
> --- a/gdb/inferior.c
> +++ b/gdb/inferior.c
> @@ -432,7 +432,7 @@ find_inferior_for_program_space (struct program_space *pspace)
> int
> have_inferiors (void)
> {
> - for (inferior *inf ATTRIBUTE_UNUSED : all_non_exited_inferiors ())
> + for ([[maybe_unused]] inferior *inf : all_non_exited_inferiors ())
> return 1;
>
> return 0;
> @@ -449,7 +449,7 @@ number_of_live_inferiors (process_stratum_target *proc_target)
>
> for (inferior *inf : all_non_exited_inferiors (proc_target))
> if (inf->has_execution ())
> - for (thread_info &tp ATTRIBUTE_UNUSED : inf->non_exited_threads ())
> + for ([[maybe_unused]] thread_info &tp : inf->non_exited_threads ())
> {
> /* Found a live thread in this inferior, go to the next
> inferior. */
> diff --git a/gdb/inflow.c b/gdb/inflow.c
> index c40ad2cf5294..e3a080dbd657 100644
> --- a/gdb/inflow.c
> +++ b/gdb/inflow.c
> @@ -493,7 +493,7 @@ child_terminal_ours_1 (target_terminal_state desired_state)
>
> if (gdb_tty_state != desired_state)
> {
> - int result ATTRIBUTE_UNUSED;
> + [[maybe_unused]] int result;
>
> /* Ignore SIGTTOU since it will happen when we try to set the
> terminal's pgrp. */
> diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c
> index 92afa4dde6db..fac35e13afb8 100644
> --- a/gdb/linux-fork.c
> +++ b/gdb/linux-fork.c
> @@ -963,7 +963,7 @@ inf_has_multiple_threads ()
>
> /* Return true as soon as we see the second thread of the current
> inferior. */
> - for (thread_info &tp ATTRIBUTE_UNUSED : current_inferior ()->threads ())
> + for ([[maybe_unused]] thread_info &tp : current_inferior ()->threads ())
> if (++count > 1)
> return true;
>
> diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c
> index 1a0d34106ed1..998409563e97 100644
> --- a/gdb/mi/mi-interp.c
> +++ b/gdb/mi/mi-interp.c
> @@ -637,7 +637,7 @@ static bool
> multiple_inferiors_p ()
> {
> int count = 0;
> - for (inferior *inf ATTRIBUTE_UNUSED : all_non_exited_inferiors ())
> + for ([[maybe_unused]] inferior *inf : all_non_exited_inferiors ())
> {
> count++;
> if (count > 1)
> diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
> index a831b96eb387..3979343acde9 100644
> --- a/gdb/python/py-utils.c
> +++ b/gdb/python/py-utils.c
> @@ -314,7 +314,7 @@ gdb_py_int_as_long (PyObject *obj, long *result)
>
> PyObject *
> gdb_py_generic_dict_getter (PyObject *self,
> - void *closure ATTRIBUTE_UNUSED)
> + [[maybe_unused]] void *closure)
> {
> PyObject **py_dict_ptr = gdbpy_dict_wrapper::compute_addr (self);
> PyObject *py_dict = *py_dict_ptr;
> diff --git a/gdb/remote.c b/gdb/remote.c
> index f8c7383cb037..43df087b83b3 100644
> --- a/gdb/remote.c
> +++ b/gdb/remote.c
> @@ -4546,7 +4546,7 @@ static bool
> has_single_non_exited_thread (inferior *inf)
> {
> int count = 0;
> - for (thread_info &tp ATTRIBUTE_UNUSED : inf->non_exited_threads ())
> + for ([[maybe_unused]] thread_info &tp : inf->non_exited_threads ())
> if (++count > 1)
> break;
> return count == 1;
> diff --git a/gdb/source-cache.c b/gdb/source-cache.c
> index 6e8acab35044..0a64745ee585 100644
> --- a/gdb/source-cache.c
> +++ b/gdb/source-cache.c
> @@ -199,9 +199,9 @@ get_language_name (enum language lang)
> succeeded. */
>
> static bool
> -try_source_highlight (std::string &contents ATTRIBUTE_UNUSED,
> - enum language lang ATTRIBUTE_UNUSED,
> - const std::string &fullname ATTRIBUTE_UNUSED)
> +try_source_highlight ([[maybe_unused]] std::string &contents,
> + [[maybe_unused]] enum language lang,
> + [[maybe_unused]] const std::string &fullname)
> {
> #ifdef HAVE_SOURCE_HIGHLIGHT
> if (!use_gnu_source_highlight)
> diff --git a/gdb/thread.c b/gdb/thread.c
> index 96c733e0629b..ffb980546b93 100644
> --- a/gdb/thread.c
> +++ b/gdb/thread.c
> @@ -476,7 +476,7 @@ thread_step_over_chain_length (const thread_step_over_list &l)
> {
> int num = 0;
>
> - for (const thread_info &thread ATTRIBUTE_UNUSED : l)
> + for ([[maybe_unused]] const thread_info &thread : l)
> ++num;
>
> return num;
> @@ -626,7 +626,7 @@ find_thread (find_thread_callback_ftype callback)
> bool
> any_thread_p ()
> {
> - for (thread_info &tp ATTRIBUTE_UNUSED : all_threads ())
> + for ([[maybe_unused]] thread_info &tp : all_threads ())
> return true;
> return false;
> }
> diff --git a/gdb/typeprint.c b/gdb/typeprint.c
> index 31a9c1814a31..01c6c218a5d5 100644
> --- a/gdb/typeprint.c
> +++ b/gdb/typeprint.c
> @@ -516,11 +516,11 @@ ptype_command (const char *type_name, int from_tty)
> }
>
> /* Meant to be used in debug sessions, so don't export it in a header file. */
> -extern void ATTRIBUTE_UNUSED debug_type (struct type *type);
> +[[maybe_unused]] extern void debug_type (struct type *type);
>
> /* Print TYPE. */
>
> -void ATTRIBUTE_UNUSED
> +[[maybe_unused]] void
> debug_type (struct type *type)
> {
> type_print (type, "", gdb_stdlog, 1);
> diff --git a/gdb/unittests/enum-flags-selftests.c b/gdb/unittests/enum-flags-selftests.c
> index bf748e873035..ca404bfa3ebe 100644
> --- a/gdb/unittests/enum-flags-selftests.c
> +++ b/gdb/unittests/enum-flags-selftests.c
> @@ -70,8 +70,8 @@ static_assert (std::is_trivially_copyable<EnumFlag>::value);
> below. Their names (and types) match the uppercase type names
> exposed by CHECK_VALID just to make the expressions easier to
> follow. */
> -static RawEnum re ATTRIBUTE_UNUSED;
> -static EnumFlag ef ATTRIBUTE_UNUSED;
> +[[maybe_unused]] static RawEnum re;
> +[[maybe_unused]] static EnumFlag ef;
>
> /* First, compile-time tests that:
>
> diff --git a/gdb/valprint.c b/gdb/valprint.c
> index 50a4663ca3b5..67bfbf589301 100644
> --- a/gdb/valprint.c
> +++ b/gdb/valprint.c
> @@ -1232,11 +1232,11 @@ value_print (struct value *val, struct ui_file *stream,
> }
>
> /* Meant to be used in debug sessions, so don't export it in a header file. */
> -extern void ATTRIBUTE_UNUSED debug_val (struct value *val);
> +[[maybe_unused]] extern void debug_val (struct value *val);
>
> /* Print VAL. */
>
> -void ATTRIBUTE_UNUSED
> +[[maybe_unused]] void
> debug_val (struct value *val)
> {
> value_print (val, gdb_stdlog, &user_print_options);
> diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc
> index a2588a6e2a9c..b68d39e1b803 100644
> --- a/gdbserver/linux-aarch64-low.cc
> +++ b/gdbserver/linux-aarch64-low.cc
> @@ -741,7 +741,7 @@ aarch64_target::low_new_fork (process_info *parent,
>
> static void
> aarch64_sve_regs_copy_to_regcache (struct regcache *regcache,
> - ATTRIBUTE_UNUSED const void *buf)
> + [[maybe_unused]] const void *buf)
> {
> /* BUF is unused here since we collect the data straight from a ptrace
> request in aarch64_sve_regs_copy_to_reg_buf, therefore bypassing
> @@ -776,7 +776,7 @@ aarch64_sve_regs_copy_from_regcache (struct regcache *regcache, void *buf)
>
> static void
> aarch64_za_regs_copy_to_regcache (struct regcache *regcache,
> - ATTRIBUTE_UNUSED const void *buf)
> + [[maybe_unused]] const void *buf)
> {
> /* BUF is unused here since we collect the data straight from a ptrace
> request, therefore bypassing gdbserver's own call to ptrace. */
> @@ -822,7 +822,7 @@ aarch64_za_regs_copy_from_regcache (struct regcache *regcache, void *buf)
>
> static void
> aarch64_zt_regs_copy_to_regcache (struct regcache *regcache,
> - ATTRIBUTE_UNUSED const void *buf)
> + [[maybe_unused]] const void *buf)
> {
> /* BUF is unused here since we collect the data straight from a ptrace
> request, therefore bypassing gdbserver's own call to ptrace. */
> diff --git a/gdbserver/x86-tdesc.h b/gdbserver/x86-tdesc.h
> index 4ed6d6635bbb..ce0c6c1be90d 100644
> --- a/gdbserver/x86-tdesc.h
> +++ b/gdbserver/x86-tdesc.h
> @@ -20,8 +20,8 @@
>
> /* The "expedite" registers for x86 targets. Since whether the
> variable is used depends on host/configuration, we mark it
> - ATTRIBUTE_UNUSED to keep it simple here. */
> -static const char *i386_expedite_regs[] ATTRIBUTE_UNUSED
> + [[maybe_unused]] to keep it simple here. */
> +[[maybe_unused]] static const char *i386_expedite_regs[]
> = {"ebp", "esp", "eip", NULL};
>
> #ifdef __x86_64__
> diff --git a/gdbsupport/safe-strerror.cc b/gdbsupport/safe-strerror.cc
> index d53cf84511fd..ad25cfc3d765 100644
> --- a/gdbsupport/safe-strerror.cc
> +++ b/gdbsupport/safe-strerror.cc
> @@ -26,14 +26,14 @@
> function. */
>
> /* Called if we have a XSI-compliant strerror_r. */
> -ATTRIBUTE_UNUSED static char *
> +[[maybe_unused]] static char *
> select_strerror_r (int res, char *buf)
> {
> return res == 0 ? buf : nullptr;
> }
>
> /* Called if we have a GNU strerror_r. */
> -ATTRIBUTE_UNUSED static char *
> +[[maybe_unused]] static char *
> select_strerror_r (char *res, char *)
> {
> return res;
> diff --git a/gdbsupport/thread-pool.cc b/gdbsupport/thread-pool.cc
> index 4dc72e566428..12329ea98831 100644
> --- a/gdbsupport/thread-pool.cc
> +++ b/gdbsupport/thread-pool.cc
> @@ -44,14 +44,14 @@
> takes a printf-style format and an argument. This wrapper handles the
> difference. */
>
> -ATTRIBUTE_UNUSED static void
> +[[maybe_unused]] static void
> do_set_thread_name (int (*set_name) (pthread_t, const char *, void *),
> const char *name)
> {
> set_name (pthread_self (), "%s", const_cast<char *> (name));
> }
>
> -ATTRIBUTE_UNUSED static void
> +[[maybe_unused]] static void
> do_set_thread_name (int (*set_name) (pthread_t, const char *),
> const char *name)
> {
> @@ -60,7 +60,7 @@ do_set_thread_name (int (*set_name) (pthread_t, const char *),
>
> /* The macOS man page says that pthread_setname_np returns "void", but
> the headers actually declare it returning "int". */
> -ATTRIBUTE_UNUSED static void
> +[[maybe_unused]] static void
> do_set_thread_name (int (*set_name) (const char *), const char *name)
> {
> set_name (name);
>
> base-commit: cdfda31c0d6b85cfff7fddeabffa570176161548
next prev parent reply other threads:[~2026-06-19 12:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-18 17:50 simon.marchi
2026-06-18 17:51 ` [PATCH 2/2] gdb, gdbsupport: use [[nodiscard]] instead of ATTRIBUTE_UNUSED_RESULT simon.marchi
2026-06-19 12:49 ` Tom de Vries [this message]
2026-06-26 15:20 ` [PATCH 1/2] gdb, gdbserver, gdbsupport: use [[maybe_unused]] instead of ATTRIBUTE_UNUSED 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=56913a13-2ca4-4c0b-be00-5f1c479122a7@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@polymtl.ca \
/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