[PATCH] Fix gdb.base/attach-twice.c build on NetBSD

Simon Marchi simark@simark.ca
Fri Apr 17 20:18:36 GMT 2020


On 2020-04-17 12:49 p.m., Kamil Rytarowski wrote:
> Add a fallback definition of PTRACE_ATTACH that is an alias of
> PT_ATTACH. Change the 4th argument of ptrace(2) to 0 as it is
> compatible with void * (Linux) and int (NetBSD) arguments.
> 
> Include <sys/types.h> for <sys/ptrace.h>.
> 
> gdb/testsuite/ChangeLog:
> 
> 	* gdb.base/attach-twice.c: Include "sys/types.h".
> 	(PTRACE_ATTACH): Add fallback definition.
> 	(main): Pass `0' to the 4th argument of `ptrace'.
> ---
>  gdb/testsuite/ChangeLog               | 6 ++++++
>  gdb/testsuite/gdb.base/attach-twice.c | 7 ++++++-
>  2 files changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
> index eaa96b06e76..81c555834ae 100644
> --- a/gdb/testsuite/ChangeLog
> +++ b/gdb/testsuite/ChangeLog
> @@ -1,3 +1,9 @@
> +2020-04-17  Kamil Rytarowski  <n54@gmx.com>
> +
> +	* gdb.base/attach-twice.c: Include "sys/types.h".
> +	(PTRACE_ATTACH): Add fallback definition.
> +	(main): Pass `0' to the 4th argument of `ptrace'.
> +
>  2020-04-16  Tom de Vries  <tdevries@suse.de>
> 
>  	PR symtab/25791
> diff --git a/gdb/testsuite/gdb.base/attach-twice.c b/gdb/testsuite/gdb.base/attach-twice.c
> index 9299b3abf81..cdefc53c9d8 100644
> --- a/gdb/testsuite/gdb.base/attach-twice.c
> +++ b/gdb/testsuite/gdb.base/attach-twice.c
> @@ -18,9 +18,14 @@
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <unistd.h>
> +#include <sys/types.h>
>  #include <sys/ptrace.h>
>  #include <errno.h>
> 
> +#ifndef PTRACE_ATTACH
> +#define PTRACE_ATTACH PT_ATTACH
> +#endif
> +
>  int
>  main (void)
>  {
> @@ -33,7 +38,7 @@ main (void)
>        exit (1);
>      case 0:
>        errno = 0;
> -      ptrace (PTRACE_ATTACH, getppid (), NULL, NULL);
> +      ptrace (PTRACE_ATTACH, getppid (), NULL, 0);

I don't really mind to take this shortcut, since this is some test
code.  However, if you want to avoid somebody "cleaning" it and
putting back NULL, you should put a comment.

Simon



More information about the Gdb-patches mailing list