Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Rewrite nbsd_nat_target::pid_to_exec_file to sysctl(3)
@ 2020-03-16 17:14 Kamil Rytarowski
  2020-03-16 17:35 ` Simon Marchi
  2020-03-16 18:27 ` [PATCH v2] " Kamil Rytarowski
  0 siblings, 2 replies; 4+ messages in thread
From: Kamil Rytarowski @ 2020-03-16 17:14 UTC (permalink / raw)
  To: gdb-patches

procfs on NetBSD is optional and not recommended.

	* nbsd-nat.c: Include <sys/types.h>, <sys/ptrace.h> and
	<sys/sysctl.h>.
	* nbsd-nat.c (nbsd_nat_target::pid_to_exec_file): Rewrite.
---
 gdb/ChangeLog  |  6 ++++++
 gdb/nbsd-nat.c | 22 ++++++++++------------
 2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index a0d97584189..358d49755bf 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2020-03-14  Kamil Rytarowski  <n54@gmx.com>
+
+	* nbsd-nat.c: Include <sys/types.h>, <sys/ptrace.h> and
+	<sys/sysctl.h>.
+	* nbsd-nat.c (nbsd_nat_target::pid_to_exec_file): Rewrite.
+
 2020-03-14  Tom Tromey  <tom@tromey.com>

 	* c-typeprint.c (cp_type_print_method_args): Print "__restrict__"
diff --git a/gdb/nbsd-nat.c b/gdb/nbsd-nat.c
index e7f91bebb0d..5e881883a1f 100644
--- a/gdb/nbsd-nat.c
+++ b/gdb/nbsd-nat.c
@@ -21,23 +21,21 @@

 #include "nbsd-nat.h"

+#include <sys/types.h>
+#include <sys/ptrace.h>
+#include <sys/sysctl.h>
+
 /* Return the name of a file that can be opened to get the symbols for
    the child process identified by PID.  */

 char *
 nbsd_nat_target::pid_to_exec_file (int pid)
 {
-  ssize_t len;
   static char buf[PATH_MAX];
-  char name[PATH_MAX];
-
-  xsnprintf (name, PATH_MAX, "/proc/%d/exe", pid);
-  len = readlink (name, buf, PATH_MAX - 1);
-  if (len != -1)
-    {
-      buf[len] = '\0';
-      return buf;
-    }
-
-  return NULL;
+  size_t buflen;
+  int mib[4] = {CTL_KERN, KERN_PROC_ARGS, pid, KERN_PROC_PATHNAME};
+  buflen = sizeof(buf);
+  if (sysctl (mib, ARRAY_SIZE (mib), buf, &buflen, NULL, 0))
+    return NULL;
+  return buf;
 }
--
2.25.0



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

* Re: [PATCH] Rewrite nbsd_nat_target::pid_to_exec_file to sysctl(3)
  2020-03-16 17:14 [PATCH] Rewrite nbsd_nat_target::pid_to_exec_file to sysctl(3) Kamil Rytarowski
@ 2020-03-16 17:35 ` Simon Marchi
  2020-03-16 18:27 ` [PATCH v2] " Kamil Rytarowski
  1 sibling, 0 replies; 4+ messages in thread
From: Simon Marchi @ 2020-03-16 17:35 UTC (permalink / raw)
  To: Kamil Rytarowski, gdb-patches

On 2020-03-16 1:14 p.m., Kamil Rytarowski wrote:
> procfs on NetBSD is optional and not recommended.
> 
> 	* nbsd-nat.c: Include <sys/types.h>, <sys/ptrace.h> and
> 	<sys/sysctl.h>.
> 	* nbsd-nat.c (nbsd_nat_target::pid_to_exec_file): Rewrite.
> ---
>  gdb/ChangeLog  |  6 ++++++
>  gdb/nbsd-nat.c | 22 ++++++++++------------
>  2 files changed, 16 insertions(+), 12 deletions(-)
> 
> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> index a0d97584189..358d49755bf 100644
> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,3 +1,9 @@
> +2020-03-14  Kamil Rytarowski  <n54@gmx.com>
> +
> +	* nbsd-nat.c: Include <sys/types.h>, <sys/ptrace.h> and
> +	<sys/sysctl.h>.
> +	* nbsd-nat.c (nbsd_nat_target::pid_to_exec_file): Rewrite.
> +
>  2020-03-14  Tom Tromey  <tom@tromey.com>
> 
>  	* c-typeprint.c (cp_type_print_method_args): Print "__restrict__"
> diff --git a/gdb/nbsd-nat.c b/gdb/nbsd-nat.c
> index e7f91bebb0d..5e881883a1f 100644
> --- a/gdb/nbsd-nat.c
> +++ b/gdb/nbsd-nat.c
> @@ -21,23 +21,21 @@
> 
>  #include "nbsd-nat.h"
> 
> +#include <sys/types.h>
> +#include <sys/ptrace.h>
> +#include <sys/sysctl.h>
> +
>  /* Return the name of a file that can be opened to get the symbols for
>     the child process identified by PID.  */
> 
>  char *
>  nbsd_nat_target::pid_to_exec_file (int pid)
>  {
> -  ssize_t len;
>    static char buf[PATH_MAX];
> -  char name[PATH_MAX];
> -
> -  xsnprintf (name, PATH_MAX, "/proc/%d/exe", pid);
> -  len = readlink (name, buf, PATH_MAX - 1);
> -  if (len != -1)
> -    {
> -      buf[len] = '\0';
> -      return buf;
> -    }
> -
> -  return NULL;
> +  size_t buflen;
> +  int mib[4] = {CTL_KERN, KERN_PROC_ARGS, pid, KERN_PROC_PATHNAME};
> +  buflen = sizeof(buf);

Space before parenthesis.

Otherwise, that LGTM.

Simon



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

* [PATCH v2] Rewrite nbsd_nat_target::pid_to_exec_file to sysctl(3)
  2020-03-16 17:14 [PATCH] Rewrite nbsd_nat_target::pid_to_exec_file to sysctl(3) Kamil Rytarowski
  2020-03-16 17:35 ` Simon Marchi
@ 2020-03-16 18:27 ` Kamil Rytarowski
  2020-03-16 19:12   ` Simon Marchi
  1 sibling, 1 reply; 4+ messages in thread
From: Kamil Rytarowski @ 2020-03-16 18:27 UTC (permalink / raw)
  To: gdb-patches; +Cc: simark, Kamil Rytarowski

procfs on NetBSD is optional and not recommended.

	* nbsd-nat.c: Include <sys/types.h>, <sys/ptrace.h> and
	<sys/sysctl.h>.
	* nbsd-nat.c (nbsd_nat_target::pid_to_exec_file): Rewrite.
---
 gdb/ChangeLog  |  6 ++++++
 gdb/nbsd-nat.c | 22 ++++++++++------------
 2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index a0d97584189..aeae2291612 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2020-03-16  Kamil Rytarowski  <n54@gmx.com>
+
+	* nbsd-nat.c: Include <sys/types.h>, <sys/ptrace.h> and
+	<sys/sysctl.h>.
+	* nbsd-nat.c (nbsd_nat_target::pid_to_exec_file): Rewrite.
+
 2020-03-14  Tom Tromey  <tom@tromey.com>

 	* c-typeprint.c (cp_type_print_method_args): Print "__restrict__"
diff --git a/gdb/nbsd-nat.c b/gdb/nbsd-nat.c
index e7f91bebb0d..326bbe3aec3 100644
--- a/gdb/nbsd-nat.c
+++ b/gdb/nbsd-nat.c
@@ -21,23 +21,21 @@

 #include "nbsd-nat.h"

+#include <sys/types.h>
+#include <sys/ptrace.h>
+#include <sys/sysctl.h>
+
 /* Return the name of a file that can be opened to get the symbols for
    the child process identified by PID.  */

 char *
 nbsd_nat_target::pid_to_exec_file (int pid)
 {
-  ssize_t len;
   static char buf[PATH_MAX];
-  char name[PATH_MAX];
-
-  xsnprintf (name, PATH_MAX, "/proc/%d/exe", pid);
-  len = readlink (name, buf, PATH_MAX - 1);
-  if (len != -1)
-    {
-      buf[len] = '\0';
-      return buf;
-    }
-
-  return NULL;
+  size_t buflen;
+  int mib[4] = {CTL_KERN, KERN_PROC_ARGS, pid, KERN_PROC_PATHNAME};
+  buflen = sizeof (buf);
+  if (sysctl (mib, ARRAY_SIZE (mib), buf, &buflen, NULL, 0))
+    return NULL;
+  return buf;
 }
--
2.25.0



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

* Re: [PATCH v2] Rewrite nbsd_nat_target::pid_to_exec_file to sysctl(3)
  2020-03-16 18:27 ` [PATCH v2] " Kamil Rytarowski
@ 2020-03-16 19:12   ` Simon Marchi
  0 siblings, 0 replies; 4+ messages in thread
From: Simon Marchi @ 2020-03-16 19:12 UTC (permalink / raw)
  To: Kamil Rytarowski, gdb-patches

On 2020-03-16 2:27 p.m., Kamil Rytarowski wrote:
> procfs on NetBSD is optional and not recommended.
> 
> 	* nbsd-nat.c: Include <sys/types.h>, <sys/ptrace.h> and
> 	<sys/sysctl.h>.
> 	* nbsd-nat.c (nbsd_nat_target::pid_to_exec_file): Rewrite.
> ---
>  gdb/ChangeLog  |  6 ++++++
>  gdb/nbsd-nat.c | 22 ++++++++++------------
>  2 files changed, 16 insertions(+), 12 deletions(-)

Sorry, I should have made it clear that it was fine to push with the small nit fixed.

This is ok to push :).

Simon



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

end of thread, other threads:[~2020-03-16 19:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-16 17:14 [PATCH] Rewrite nbsd_nat_target::pid_to_exec_file to sysctl(3) Kamil Rytarowski
2020-03-16 17:35 ` Simon Marchi
2020-03-16 18:27 ` [PATCH v2] " Kamil Rytarowski
2020-03-16 19:12   ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox