public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [pushed] Fix aarch64-linux-hw-point.c build problem
@ 2021-02-24 19:59 Kevin Buettner
  2021-02-24 20:52 ` Tom Tromey
  0 siblings, 1 reply; 5+ messages in thread
From: Kevin Buettner @ 2021-02-24 19:59 UTC (permalink / raw)
  To: gdb-patches

Due to a recent glibc header file change, the file
nat/aarch64-linux-hw-point.c no longer builds on Fedora rawhide.

An enum for PTRACE_SYSEMU is now provided by <sys/ptrace.h>.  In the
past, PTRACE_SYSEMU was defined only in <asm/ptrace.h>.  This is
what it looks like...

In <asm/ptrace.h>:

 #define PTRACE_SYSEMU		  31

In <sys/ptrace.h>:

enum __ptrace_request
{
  ...
  PTRACE_SYSEMU = 31,
 #define PT_SYSEMU PTRACE_SYSEMU

  ...
}

When <asm/ptrace.h> and <sys/ptrace.h> are both included in a source
file, we run into the following build problem when the former is
included before the latter:

In file included from nat/aarch64-linux-hw-point.c:26:
/usr/include/sys/ptrace.h:86:3: error: expected identifier before numeric constant
   86 |   PTRACE_SYSEMU = 31,
      |   ^~~~~~~~~~~~~

(There are more errors after this one too.)

The file builds without error when <asm/ptrace.h> is included after
<sys/ptrace.h>.  I found that this is already done in
nat/aarch64-sve-linux-ptrace.h (which is included by
nat/aarch64-linux-ptrace.c).

I've tested this change on Fedora rawhide and Fedora 33, both
running on an aarch64 machine.

gdb/ChangeLog:

	* nat/aarch64-linux-hw-point.c: Include <asm/ptrace.h> after
	<sys/ptrace.h>.
---
 gdb/ChangeLog                    | 5 +++++
 gdb/nat/aarch64-linux-hw-point.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 00a71fe9025..f7052421935 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2021-02-24  Kevin Buettner  <kevinb@redhat.com>
+
+	* nat/aarch64-linux-hw-point.c: Include <asm/ptrace.h> after
+	<sys/ptrace.h>.
+
 2021-02-24  Andrew Burgess  <andrew.burgess@embecosm.com>
 
 	* exec.c (set_section_command): Move variable declarations into
diff --git a/gdb/nat/aarch64-linux-hw-point.c b/gdb/nat/aarch64-linux-hw-point.c
index 73e4edd68cb..0278ac2bb28 100644
--- a/gdb/nat/aarch64-linux-hw-point.c
+++ b/gdb/nat/aarch64-linux-hw-point.c
@@ -23,8 +23,8 @@
 #include "aarch64-linux-hw-point.h"
 
 #include <sys/uio.h>
-#include <asm/ptrace.h>
 #include <sys/ptrace.h>
+#include <asm/ptrace.h>
 #include <elf.h>
 
 /* Number of hardware breakpoints/watchpoints the target supports.
-- 
2.29.2


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

* Re: [pushed] Fix aarch64-linux-hw-point.c build problem
  2021-02-24 19:59 [pushed] Fix aarch64-linux-hw-point.c build problem Kevin Buettner
@ 2021-02-24 20:52 ` Tom Tromey
  2021-02-24 21:52   ` Kevin Buettner
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2021-02-24 20:52 UTC (permalink / raw)
  To: Kevin Buettner via Gdb-patches

>>>>> "Kevin" == Kevin Buettner via Gdb-patches <gdb-patches@sourceware.org> writes:

Kevin> gdb/ChangeLog:

Kevin> 	* nat/aarch64-linux-hw-point.c: Include <asm/ptrace.h> after
Kevin> 	<sys/ptrace.h>.

This seems reasonable, but a comment saying that the order matters might
be helpful later on.

Tom

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

* Re: [pushed] Fix aarch64-linux-hw-point.c build problem
  2021-02-24 20:52 ` Tom Tromey
@ 2021-02-24 21:52   ` Kevin Buettner
  2021-02-24 23:22     ` Christian Biesinger
  0 siblings, 1 reply; 5+ messages in thread
From: Kevin Buettner @ 2021-02-24 21:52 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

On Wed, 24 Feb 2021 13:52:00 -0700
Tom Tromey <tom@tromey.com> wrote:

> >>>>> "Kevin" == Kevin Buettner via Gdb-patches <gdb-patches@sourceware.org> writes:  
> 
> Kevin> gdb/ChangeLog:  
> 
> Kevin> 	* nat/aarch64-linux-hw-point.c: Include <asm/ptrace.h> after
> Kevin> 	<sys/ptrace.h>.  
> 
> This seems reasonable, but a comment saying that the order matters might
> be helpful later on.

Agreed.

I've pushed the following (along with a suitable ChangeLog entry)...

diff --git a/gdb/nat/aarch64-linux-hw-point.c b/gdb/nat/aarch64-linux-hw-point.c
index 0278ac2bb28..af2cc4254e2 100644
--- a/gdb/nat/aarch64-linux-hw-point.c
+++ b/gdb/nat/aarch64-linux-hw-point.c
@@ -23,8 +23,15 @@
 #include "aarch64-linux-hw-point.h"
 
 #include <sys/uio.h>
+
+/* The order in which <sys/ptrace.h> and <asm/ptrace.h> are included
+   can be important.  <sys/ptrace.h> often declares various PTRACE_*
+   enums.  <asm/ptrace.h> often defines preprocessor constants for
+   these very same symbols.  When that's the case, build errors will
+   result when <asm/ptrace.h> is included before <sys/ptrace.h>.  */
 #include <sys/ptrace.h>
 #include <asm/ptrace.h>
+
 #include <elf.h>
 
 /* Number of hardware breakpoints/watchpoints the target supports.


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

* Re: [pushed] Fix aarch64-linux-hw-point.c build problem
  2021-02-24 21:52   ` Kevin Buettner
@ 2021-02-24 23:22     ` Christian Biesinger
  2021-02-25 22:49       ` Kevin Buettner
  0 siblings, 1 reply; 5+ messages in thread
From: Christian Biesinger @ 2021-02-24 23:22 UTC (permalink / raw)
  To: Kevin Buettner; +Cc: gdb-patches, Tom Tromey

On Wed, Feb 24, 2021, 22:52 Kevin Buettner via Gdb-patches <
gdb-patches@sourceware.org> wrote:

> On Wed, 24 Feb 2021 13:52:00 -0700
> Tom Tromey <tom@tromey.com> wrote:
>
> > >>>>> "Kevin" == Kevin Buettner via Gdb-patches <
> gdb-patches@sourceware.org> writes:
> >
> > Kevin> gdb/ChangeLog:
> >
> > Kevin>        * nat/aarch64-linux-hw-point.c: Include <asm/ptrace.h>
> after
> > Kevin>        <sys/ptrace.h>.
> >
> > This seems reasonable, but a comment saying that the order matters might
> > be helpful later on.
>
> Agreed.
>
> I've pushed the following (along with a suitable ChangeLog entry)...
>

Since you said nat/aarch64-sve-linux-ptrace.h also includes these headers,
maybe add the comment there as well?



> diff --git a/gdb/nat/aarch64-linux-hw-point.c
> b/gdb/nat/aarch64-linux-hw-point.c
> index 0278ac2bb28..af2cc4254e2 100644
> --- a/gdb/nat/aarch64-linux-hw-point.c
> +++ b/gdb/nat/aarch64-linux-hw-point.c
> @@ -23,8 +23,15 @@
>  #include "aarch64-linux-hw-point.h"
>
>  #include <sys/uio.h>
> +
> +/* The order in which <sys/ptrace.h> and <asm/ptrace.h> are included
> +   can be important.  <sys/ptrace.h> often declares various PTRACE_*
> +   enums.  <asm/ptrace.h> often defines preprocessor constants for
> +   these very same symbols.  When that's the case, build errors will
> +   result when <asm/ptrace.h> is included before <sys/ptrace.h>.  */
>  #include <sys/ptrace.h>
>  #include <asm/ptrace.h>
> +
>  #include <elf.h>
>
>  /* Number of hardware breakpoints/watchpoints the target supports.
>
>

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

* Re: [pushed] Fix aarch64-linux-hw-point.c build problem
  2021-02-24 23:22     ` Christian Biesinger
@ 2021-02-25 22:49       ` Kevin Buettner
  0 siblings, 0 replies; 5+ messages in thread
From: Kevin Buettner @ 2021-02-25 22:49 UTC (permalink / raw)
  To: gdb-patches; +Cc: Christian Biesinger, Tom Tromey

On Thu, 25 Feb 2021 00:22:52 +0100
Christian Biesinger <cbiesinger@google.com> wrote:

> Since you said nat/aarch64-sve-linux-ptrace.h also includes these headers,
> maybe add the comment there as well?

Done...

Add comment regarding include order of <sys/ptrace.h> and <asm/ptrace.h>

I added the same comment for nat/aarch64-linux-hw-point.c yesterday.
Christian suggested adding the comment for the other file that I had
identified as including both <sys/ptrace.h> and <asm/ptrace.h>.

I searched the sources in gdb/, but found no other files which include
both of these headers.

If possible, I would prefer to see us use <sys/ptrace.h> when possible,
however, from past experience, I've found that this file does not always
contain all of the constants, etc. required by the particular source
file.

gdb/ChangeLog:

	* nat/aarch64-sve-linux-ptrace.h: Add comment regarding include
	order for <sys/ptrace.h> and <asm/ptrace.h>.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 842dc0a1374..7e0b00cc7c6 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2021-02-24  Kevin Buettner  <kevinb@redhat.com>
+
+	* nat/aarch64-sve-linux-ptrace.h: Add comment regarding
+	include order for <sys/ptrace.h> and <asm/ptrace.h>.
+
 2021-02-25  Simon Marchi  <simon.marchi@polymtl.ca>
 
 	PR gdb/26861
diff --git a/gdb/nat/aarch64-sve-linux-ptrace.h b/gdb/nat/aarch64-sve-linux-ptrace.h
index 06684023f5d..be00f306137 100644
--- a/gdb/nat/aarch64-sve-linux-ptrace.h
+++ b/gdb/nat/aarch64-sve-linux-ptrace.h
@@ -22,6 +22,12 @@
 
 #include <signal.h>
 #include <sys/utsname.h>
+
+/* The order in which <sys/ptrace.h> and <asm/ptrace.h> are included
+   can be important.  <sys/ptrace.h> often declares various PTRACE_*
+   enums.  <asm/ptrace.h> often defines preprocessor constants for
+   these very same symbols.  When that's the case, build errors will
+   result when <asm/ptrace.h> is included before <sys/ptrace.h>.  */
 #include <sys/ptrace.h>
 #include <asm/ptrace.h>
 


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

end of thread, other threads:[~2021-02-25 22:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-24 19:59 [pushed] Fix aarch64-linux-hw-point.c build problem Kevin Buettner
2021-02-24 20:52 ` Tom Tromey
2021-02-24 21:52   ` Kevin Buettner
2021-02-24 23:22     ` Christian Biesinger
2021-02-25 22:49       ` Kevin Buettner

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