From a2ecbe9fb7355698aad97841f9717cdfd7096d95 Mon Sep 17 00:00:00 2001 From: Kamil Rytarowski Date: Sun, 15 Mar 2020 00:12:53 +0100 Subject: [PATCH] Rewrite nbsd_nat_target::pid_to_exec_file to sysctl(3) procfs on NetBSD is optional and not recommended. * nbsd-nat.c: Include , and . * 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 3c9215060a9..cb2e91be8d0 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2020-03-17 Kamil Rytarowski + + * nbsd-nat.c: Include , and + . + * nbsd-nat.c (nbsd_nat_target::pid_to_exec_file): Rewrite. + 2020-03-17 Tom de Vries PR gdb/23710 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 +#include +#include + /* 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.30.2