public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] fbsd-nat: Pacify gcc with no functional changes
@ 2023-09-09 13:50 Enze Li
  2023-09-09 16:49 ` John Baldwin
  0 siblings, 1 reply; 5+ messages in thread
From: Enze Li @ 2023-09-09 13:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: jhb, enze.li

I see these errors on FreeBSD/aarch64 when using gcc 12 without passing
--disable-werror.

=====================================================================
  CXX    fbsd-nat.o
fbsd-nat.c: In member function 'void fbsd_nat_target::resume_one_process(ptid_t, int, gdb_signal)':
fbsd-nat.c:1208:11: error: unused variable 'request' [-Werror=unused-variable]
 1208 |       int request;
      |           ^~~~~~~
fbsd-nat.c: In member function 'virtual ptid_t fbsd_nat_target::wait(ptid_t, target_waitstatus*, target_wait_flags)':
fbsd-nat.c:1726:22: error: declaration of 'inf' shadows a previous local [-Werror=shadow=compatible-local]
 1726 |       for (inferior *inf : all_non_exited_inferiors (this))
      |                      ^~~
fbsd-nat.c:1697:17: note: shadowed declaration is here
 1697 |       inferior *inf = find_inferior_ptid (this, wptid);
      |                 ^~~
fbsd-nat.c: In member function 'virtual void fbsd_nat_target::detach(inferior*, int)':
fbsd-nat.c:2044:18: error: variable 'wptid' set but not used [-Werror=unused-but-set-variable]
 2044 |           ptid_t wptid = wait_1 (ptid, &ws, 0);
      |                  ^~~~~
cc1plus: all warnings being treated as errors
=====================================================================

This patch includes the following non-functional changes,

1. Remove unused variable "request".
2. Rename inf to inf_p to avoid shadowed declaration warnings.
3. Set wptid to null_ptid when USE_SIGTRAP_SIGINFO is not defined.

Tested on FreeBSD/aarch64 by rebuilding.
---
 gdb/fbsd-nat.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c
index 0ee3bccb5ef..af416557504 100644
--- a/gdb/fbsd-nat.c
+++ b/gdb/fbsd-nat.c
@@ -1205,8 +1205,6 @@ fbsd_nat_target::resume_one_process (ptid_t ptid, int step,
 
   for (thread_info *tp : inf->non_exited_threads ())
     {
-      int request;
-
       /* If ptid is a specific LWP, suspend all other LWPs in the
 	 process, otherwise resume all LWPs in the process..  */
       if (!ptid.lwp_p() || tp->ptid.lwp () == ptid.lwp ())
@@ -1694,9 +1692,9 @@ fbsd_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
 	  || ourstatus->kind () == TARGET_WAITKIND_NO_RESUMED)
 	break;
 
-      inferior *inf = find_inferior_ptid (this, wptid);
-      gdb_assert (inf != nullptr);
-      fbsd_inferior *fbsd_inf = get_fbsd_inferior (inf);
+      inferior *inf_p = find_inferior_ptid (this, wptid);
+      gdb_assert (inf_p != nullptr);
+      fbsd_inferior *fbsd_inf = get_fbsd_inferior (inf_p);
       gdb_assert (fbsd_inf != nullptr);
       gdb_assert (fbsd_inf->resumed_lwps != null_ptid);
       gdb_assert (fbsd_inf->running_lwps > 0);
@@ -2094,6 +2092,9 @@ fbsd_nat_target::detach (inferior *inf, int from_tty)
 			  }
 		      }
 		  }
+#else
+		  /* pacify gcc  */
+		  wptid = null_ptid;
 #endif
 		  sig = 0;
 		  break;

base-commit: 38a984fa440c7686c741b7804eae06a528849aa7
-- 
2.42.0


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

* Re: [PATCH] fbsd-nat: Pacify gcc with no functional changes
  2023-09-09 13:50 [PATCH] fbsd-nat: Pacify gcc with no functional changes Enze Li
@ 2023-09-09 16:49 ` John Baldwin
  2023-09-11 14:20   ` Enze Li
  2023-09-11 14:40   ` [PATCH v2] " Enze Li
  0 siblings, 2 replies; 5+ messages in thread
From: John Baldwin @ 2023-09-09 16:49 UTC (permalink / raw)
  To: Enze Li, gdb-patches; +Cc: enze.li

On 9/9/23 6:50 AM, Enze Li wrote:
> I see these errors on FreeBSD/aarch64 when using gcc 12 without passing
> --disable-werror.
> 
> =====================================================================
>    CXX    fbsd-nat.o
> fbsd-nat.c: In member function 'void fbsd_nat_target::resume_one_process(ptid_t, int, gdb_signal)':
> fbsd-nat.c:1208:11: error: unused variable 'request' [-Werror=unused-variable]
>   1208 |       int request;
>        |           ^~~~~~~
> fbsd-nat.c: In member function 'virtual ptid_t fbsd_nat_target::wait(ptid_t, target_waitstatus*, target_wait_flags)':
> fbsd-nat.c:1726:22: error: declaration of 'inf' shadows a previous local [-Werror=shadow=compatible-local]
>   1726 |       for (inferior *inf : all_non_exited_inferiors (this))
>        |                      ^~~
> fbsd-nat.c:1697:17: note: shadowed declaration is here
>   1697 |       inferior *inf = find_inferior_ptid (this, wptid);
>        |                 ^~~
> fbsd-nat.c: In member function 'virtual void fbsd_nat_target::detach(inferior*, int)':
> fbsd-nat.c:2044:18: error: variable 'wptid' set but not used [-Werror=unused-but-set-variable]
>   2044 |           ptid_t wptid = wait_1 (ptid, &ws, 0);
>        |                  ^~~~~
> cc1plus: all warnings being treated as errors
> =====================================================================
> 
> This patch includes the following non-functional changes,
> 
> 1. Remove unused variable "request".
> 2. Rename inf to inf_p to avoid shadowed declaration warnings.
> 3. Set wptid to null_ptid when USE_SIGTRAP_SIGINFO is not defined.

I'm surprised you see this third warning.  USE_SIGTRAP_SIGINFO should
be on for all modern versions of FreeBSD.  In particular, fbsd-nat.h
enables it on 11.3 and later.  What version of FreeBSD are you building on?

 From fbsd-nat.h:

/* FreeBSD kernels 11.3 and later report valid si_code values for
    SIGTRAP on all architectures.  Older FreeBSD kernels that supported
    TRAP_BRKPT did not report valid values for MIPS and sparc64.  Even
    older kernels without TRAP_BRKPT support did not report valid
    values on any architecture.  */
#if (__FreeBSD_kernel_version >= 1102502) || (__FreeBSD_version >= 1102502)
# define USE_SIGTRAP_SIGINFO


> Tested on FreeBSD/aarch64 by rebuilding.
> ---
>   gdb/fbsd-nat.c | 11 ++++++-----
>   1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c
> index 0ee3bccb5ef..af416557504 100644
> --- a/gdb/fbsd-nat.c
> +++ b/gdb/fbsd-nat.c
> @@ -1205,8 +1205,6 @@ fbsd_nat_target::resume_one_process (ptid_t ptid, int step,
>   
>     for (thread_info *tp : inf->non_exited_threads ())
>       {
> -      int request;
> -
>         /* If ptid is a specific LWP, suspend all other LWPs in the
>   	 process, otherwise resume all LWPs in the process..  */
>         if (!ptid.lwp_p() || tp->ptid.lwp () == ptid.lwp ())

Thanks.  This a leftover from my recent patches, not sure why clang didn't notice.

> @@ -1694,9 +1692,9 @@ fbsd_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
>   	  || ourstatus->kind () == TARGET_WAITKIND_NO_RESUMED)
>   	break;
>   
> -      inferior *inf = find_inferior_ptid (this, wptid);
> -      gdb_assert (inf != nullptr);
> -      fbsd_inferior *fbsd_inf = get_fbsd_inferior (inf);
> +      inferior *inf_p = find_inferior_ptid (this, wptid);
> +      gdb_assert (inf_p != nullptr);
> +      fbsd_inferior *fbsd_inf = get_fbsd_inferior (inf_p);
>         gdb_assert (fbsd_inf != nullptr);
>         gdb_assert (fbsd_inf->resumed_lwps != null_ptid);
>         gdb_assert (fbsd_inf->running_lwps > 0);

I might call this variable `winf` to match the `wptid` vs `ptid` pattern.

> @@ -2094,6 +2092,9 @@ fbsd_nat_target::detach (inferior *inf, int from_tty)
>   			  }
>   		      }
>   		  }
> +#else
> +		  /* pacify gcc  */
> +		  wptid = null_ptid;

Probably the better way to pacify this is to use a (void) cast to mark it
as used, e.g. `(void)null_ptid;`

>   #endif
>   		  sig = 0;
>   		  break;
> 
> base-commit: 38a984fa440c7686c741b7804eae06a528849aa7

-- 
John Baldwin


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

* Re: [PATCH] fbsd-nat: Pacify gcc with no functional changes
  2023-09-09 16:49 ` John Baldwin
@ 2023-09-11 14:20   ` Enze Li
  2023-09-11 14:40   ` [PATCH v2] " Enze Li
  1 sibling, 0 replies; 5+ messages in thread
From: Enze Li @ 2023-09-11 14:20 UTC (permalink / raw)
  To: John Baldwin; +Cc: gdb-patches, enze.li

On Sat, Sep 09 2023 at 09:49:40 AM -0700, John Baldwin wrote:

> On 9/9/23 6:50 AM, Enze Li wrote:
>> I see these errors on FreeBSD/aarch64 when using gcc 12 without passing
>> --disable-werror.
>> =====================================================================
>>    CXX    fbsd-nat.o
>> fbsd-nat.c: In member function 'void fbsd_nat_target::resume_one_process(ptid_t, int, gdb_signal)':
>> fbsd-nat.c:1208:11: error: unused variable 'request' [-Werror=unused-variable]
>>   1208 |       int request;
>>        |           ^~~~~~~
>> fbsd-nat.c: In member function 'virtual ptid_t
>> fbsd_nat_target::wait(ptid_t, target_waitstatus*,
>> target_wait_flags)':
>> fbsd-nat.c:1726:22: error: declaration of 'inf' shadows a previous
>> local [-Werror=shadow=compatible-local]
>>   1726 |       for (inferior *inf : all_non_exited_inferiors (this))
>>        |                      ^~~
>> fbsd-nat.c:1697:17: note: shadowed declaration is here
>>   1697 |       inferior *inf = find_inferior_ptid (this, wptid);
>>        |                 ^~~
>> fbsd-nat.c: In member function 'virtual void
>> fbsd_nat_target::detach(inferior*, int)':
>> fbsd-nat.c:2044:18: error: variable 'wptid' set but not used
>> [-Werror=unused-but-set-variable]
>>   2044 |           ptid_t wptid = wait_1 (ptid, &ws, 0);
>>        |                  ^~~~~
>> cc1plus: all warnings being treated as errors
>> =====================================================================
>> This patch includes the following non-functional changes,
>> 1. Remove unused variable "request".
>> 2. Rename inf to inf_p to avoid shadowed declaration warnings.
>> 3. Set wptid to null_ptid when USE_SIGTRAP_SIGINFO is not defined.

Hi John,

Thanks for your review.

>
> I'm surprised you see this third warning.  USE_SIGTRAP_SIGINFO should
> be on for all modern versions of FreeBSD.  In particular, fbsd-nat.h
> enables it on 11.3 and later.  What version of FreeBSD are you
> building on?

I just realized that the third description is incorrect and should be:

  "3. Set wptid to null_ptid when USE_SIGTRAP_SIGINFO is defined."

BTW, I'm using FreeBSD/aarch64 13.2-RELEASE.

>
> From fbsd-nat.h:
>
> /* FreeBSD kernels 11.3 and later report valid si_code values for
>    SIGTRAP on all architectures.  Older FreeBSD kernels that supported
>    TRAP_BRKPT did not report valid values for MIPS and sparc64.  Even
>    older kernels without TRAP_BRKPT support did not report valid
>    values on any architecture.  */
> #if (__FreeBSD_kernel_version >= 1102502) || (__FreeBSD_version >= 1102502)
> # define USE_SIGTRAP_SIGINFO
>
>
>> Tested on FreeBSD/aarch64 by rebuilding.
>> ---
>>   gdb/fbsd-nat.c | 11 ++++++-----
>>   1 file changed, 6 insertions(+), 5 deletions(-)
>> diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c
>> index 0ee3bccb5ef..af416557504 100644
>> --- a/gdb/fbsd-nat.c
>> +++ b/gdb/fbsd-nat.c
>> @@ -1205,8 +1205,6 @@ fbsd_nat_target::resume_one_process (ptid_t ptid, int step,
>>       for (thread_info *tp : inf->non_exited_threads ())
>>       {
>> -      int request;
>> -
>>         /* If ptid is a specific LWP, suspend all other LWPs in the
>>   	 process, otherwise resume all LWPs in the process..  */
>>         if (!ptid.lwp_p() || tp->ptid.lwp () == ptid.lwp ())
>
> Thanks.  This a leftover from my recent patches, not sure why clang
> didn't notice.
>
>> @@ -1694,9 +1692,9 @@ fbsd_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
>>   	  || ourstatus->kind () == TARGET_WAITKIND_NO_RESUMED)
>>   	break;
>>   -      inferior *inf = find_inferior_ptid (this, wptid);
>> -      gdb_assert (inf != nullptr);
>> -      fbsd_inferior *fbsd_inf = get_fbsd_inferior (inf);
>> +      inferior *inf_p = find_inferior_ptid (this, wptid);
>> +      gdb_assert (inf_p != nullptr);
>> +      fbsd_inferior *fbsd_inf = get_fbsd_inferior (inf_p);
>>         gdb_assert (fbsd_inf != nullptr);
>>         gdb_assert (fbsd_inf->resumed_lwps != null_ptid);
>>         gdb_assert (fbsd_inf->running_lwps > 0);
>
> I might call this variable `winf` to match the `wptid` vs `ptid` pattern.
>

Fixed.

>> @@ -2094,6 +2092,9 @@ fbsd_nat_target::detach (inferior *inf, int from_tty)
>>   			  }
>>   		      }
>>   		  }
>> +#else
>> +		  /* pacify gcc  */
>> +		  wptid = null_ptid;
>
> Probably the better way to pacify this is to use a (void) cast to mark it
> as used, e.g. `(void)null_ptid;`
>

Okey, fixed.  I'll send v2 to the list soon.

Best Regards,
Enze

>>   #endif
>>   		  sig = 0;
>>   		  break;
>> base-commit: 38a984fa440c7686c741b7804eae06a528849aa7

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

* [PATCH v2] fbsd-nat: Pacify gcc with no functional changes
  2023-09-09 16:49 ` John Baldwin
  2023-09-11 14:20   ` Enze Li
@ 2023-09-11 14:40   ` Enze Li
  2023-09-22 19:24     ` John Baldwin
  1 sibling, 1 reply; 5+ messages in thread
From: Enze Li @ 2023-09-11 14:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: jhb, enze.li

I see these errors on FreeBSD/aarch64 when using gcc 12 without passing
--disable-werror.

=====================================================================
  CXX    fbsd-nat.o
fbsd-nat.c: In member function 'void fbsd_nat_target::resume_one_process(ptid_t, int, gdb_signal)':
fbsd-nat.c:1208:11: error: unused variable 'request' [-Werror=unused-variable]
 1208 |       int request;
      |           ^~~~~~~
fbsd-nat.c: In member function 'virtual ptid_t fbsd_nat_target::wait(ptid_t, target_waitstatus*, target_wait_flags)':
fbsd-nat.c:1726:22: error: declaration of 'inf' shadows a previous local [-Werror=shadow=compatible-local]
 1726 |       for (inferior *inf : all_non_exited_inferiors (this))
      |                      ^~~
fbsd-nat.c:1697:17: note: shadowed declaration is here
 1697 |       inferior *inf = find_inferior_ptid (this, wptid);
      |                 ^~~
fbsd-nat.c: In member function 'virtual void fbsd_nat_target::detach(inferior*, int)':
fbsd-nat.c:2044:18: error: variable 'wptid' set but not used [-Werror=unused-but-set-variable]
 2044 |           ptid_t wptid = wait_1 (ptid, &ws, 0);
      |                  ^~~~~
cc1plus: all warnings being treated as errors
=====================================================================

This patch includes the following non-functional changes,

1. Remove unused variable "request".
2. Rename inf to inf_p to avoid shadowed declaration warnings.
3. Set wptid to null_ptid when USE_SIGTRAP_SIGINFO is defined.

Tested on FreeBSD/aarch64 by rebuilding.
---
 gdb/fbsd-nat.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c
index 0ee3bccb5ef..81a77b3a60f 100644
--- a/gdb/fbsd-nat.c
+++ b/gdb/fbsd-nat.c
@@ -1205,8 +1205,6 @@ fbsd_nat_target::resume_one_process (ptid_t ptid, int step,
 
   for (thread_info *tp : inf->non_exited_threads ())
     {
-      int request;
-
       /* If ptid is a specific LWP, suspend all other LWPs in the
 	 process, otherwise resume all LWPs in the process..  */
       if (!ptid.lwp_p() || tp->ptid.lwp () == ptid.lwp ())
@@ -1694,9 +1692,9 @@ fbsd_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
 	  || ourstatus->kind () == TARGET_WAITKIND_NO_RESUMED)
 	break;
 
-      inferior *inf = find_inferior_ptid (this, wptid);
-      gdb_assert (inf != nullptr);
-      fbsd_inferior *fbsd_inf = get_fbsd_inferior (inf);
+      inferior *winf = find_inferior_ptid (this, wptid);
+      gdb_assert (winf != nullptr);
+      fbsd_inferior *fbsd_inf = get_fbsd_inferior (winf);
       gdb_assert (fbsd_inf != nullptr);
       gdb_assert (fbsd_inf->resumed_lwps != null_ptid);
       gdb_assert (fbsd_inf->running_lwps > 0);
@@ -2094,6 +2092,9 @@ fbsd_nat_target::detach (inferior *inf, int from_tty)
 			  }
 		      }
 		  }
+#else
+		  /* pacify gcc  */
+		  wptid = (void) null_ptid;
 #endif
 		  sig = 0;
 		  break;

base-commit: cdda72c2fa1e47c566c7b5768f3831a1cc11d263
-- 
2.42.0


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

* Re: [PATCH v2] fbsd-nat: Pacify gcc with no functional changes
  2023-09-11 14:40   ` [PATCH v2] " Enze Li
@ 2023-09-22 19:24     ` John Baldwin
  0 siblings, 0 replies; 5+ messages in thread
From: John Baldwin @ 2023-09-22 19:24 UTC (permalink / raw)
  To: Enze Li, gdb-patches; +Cc: enze.li

On 9/11/23 3:40 PM, Enze Li wrote:
> I see these errors on FreeBSD/aarch64 when using gcc 12 without passing
> --disable-werror.
> 
> =====================================================================
>    CXX    fbsd-nat.o
> fbsd-nat.c: In member function 'void fbsd_nat_target::resume_one_process(ptid_t, int, gdb_signal)':
> fbsd-nat.c:1208:11: error: unused variable 'request' [-Werror=unused-variable]
>   1208 |       int request;
>        |           ^~~~~~~
> fbsd-nat.c: In member function 'virtual ptid_t fbsd_nat_target::wait(ptid_t, target_waitstatus*, target_wait_flags)':
> fbsd-nat.c:1726:22: error: declaration of 'inf' shadows a previous local [-Werror=shadow=compatible-local]
>   1726 |       for (inferior *inf : all_non_exited_inferiors (this))
>        |                      ^~~
> fbsd-nat.c:1697:17: note: shadowed declaration is here
>   1697 |       inferior *inf = find_inferior_ptid (this, wptid);
>        |                 ^~~
> fbsd-nat.c: In member function 'virtual void fbsd_nat_target::detach(inferior*, int)':
> fbsd-nat.c:2044:18: error: variable 'wptid' set but not used [-Werror=unused-but-set-variable]
>   2044 |           ptid_t wptid = wait_1 (ptid, &ws, 0);
>        |                  ^~~~~
> cc1plus: all warnings being treated as errors
> =====================================================================
> 
> This patch includes the following non-functional changes,
> 
> 1. Remove unused variable "request".
> 2. Rename inf to inf_p to avoid shadowed declaration warnings.
> 3. Set wptid to null_ptid when USE_SIGTRAP_SIGINFO is defined.

Ah, I had misread the code at first and yes, the variable is unused
when this is defined.

> Tested on FreeBSD/aarch64 by rebuilding.
> ---
>   gdb/fbsd-nat.c | 11 ++++++-----
>   1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c
> index 0ee3bccb5ef..81a77b3a60f 100644
> --- a/gdb/fbsd-nat.c
> +++ b/gdb/fbsd-nat.c
> @@ -1205,8 +1205,6 @@ fbsd_nat_target::resume_one_process (ptid_t ptid, int step,
>   
>     for (thread_info *tp : inf->non_exited_threads ())
>       {
> -      int request;
> -
>         /* If ptid is a specific LWP, suspend all other LWPs in the
>   	 process, otherwise resume all LWPs in the process..  */
>         if (!ptid.lwp_p() || tp->ptid.lwp () == ptid.lwp ())
> @@ -1694,9 +1692,9 @@ fbsd_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
>   	  || ourstatus->kind () == TARGET_WAITKIND_NO_RESUMED)
>   	break;
>   
> -      inferior *inf = find_inferior_ptid (this, wptid);
> -      gdb_assert (inf != nullptr);
> -      fbsd_inferior *fbsd_inf = get_fbsd_inferior (inf);
> +      inferior *winf = find_inferior_ptid (this, wptid);
> +      gdb_assert (winf != nullptr);
> +      fbsd_inferior *fbsd_inf = get_fbsd_inferior (winf);
>         gdb_assert (fbsd_inf != nullptr);
>         gdb_assert (fbsd_inf->resumed_lwps != null_ptid);
>         gdb_assert (fbsd_inf->running_lwps > 0);
> @@ -2094,6 +2092,9 @@ fbsd_nat_target::detach (inferior *inf, int from_tty)
>   			  }
>   		      }
>   		  }
> +#else
> +		  /* pacify gcc  */
> +		  wptid = (void) null_ptid;
>   #endif

Hmm, what I meant was:

	(void) wptid;

This is a way to tell the compiler that the variable should be considered
"used".  I was able to reproduce the warnings on FreeBSD/amd64 as well using
GCC 12 and verified that your patch (with the above fix) fixes the warnings
for me as well, thanks.  I've pushed it.

-- 
John Baldwin


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

end of thread, other threads:[~2023-09-22 19:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-09 13:50 [PATCH] fbsd-nat: Pacify gcc with no functional changes Enze Li
2023-09-09 16:49 ` John Baldwin
2023-09-11 14:20   ` Enze Li
2023-09-11 14:40   ` [PATCH v2] " Enze Li
2023-09-22 19:24     ` John Baldwin

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).