* [PATCH] Implement "info proc exe" for NetBSD
@ 2020-04-12 15:36 Kamil Rytarowski
2020-04-12 17:13 ` Simon Marchi
0 siblings, 1 reply; 6+ messages in thread
From: Kamil Rytarowski @ 2020-04-12 15:36 UTC (permalink / raw)
To: gdb-patches
Use pid_to_exec_file() to query the program.
gdb/ChangeLog:
* nbsd-nat.c (nbsd_nat_target::info_proc): Add do_exe.
---
gdb/nbsd-nat.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/gdb/nbsd-nat.c b/gdb/nbsd-nat.c
index 2420153c7bc..828bbb57c82 100644
--- a/gdb/nbsd-nat.c
+++ b/gdb/nbsd-nat.c
@@ -299,6 +299,7 @@ bool
nbsd_nat_target::info_proc (const char *args, enum info_proc_what what)
{
pid_t pid;
+ bool do_exe = false;
bool do_mappings = false;
switch (what)
@@ -306,6 +307,9 @@ nbsd_nat_target::info_proc (const char *args, enum info_proc_what what)
case IP_MAPPINGS:
do_mappings = true;
break;
+ case IP_EXE:
+ do_exe = true;
+ break;
default:
error (_("Not supported on this target."));
}
@@ -345,6 +349,14 @@ nbsd_nat_target::info_proc (const char *args, enum info_proc_what what)
else
warning (_("unable to fetch virtual memory map"));
}
+ if (do_exe)
+ {
+ const char *exe = pid_to_exec_file (pid);
+ if (exe != nullptr)
+ printf_filtered ("exe = '%s'\n", exe);
+ else
+ warning (_("unable to fetch executable path name"));
+ }
return true;
}
--
2.25.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Implement "info proc exe" for NetBSD
2020-04-12 15:36 [PATCH] Implement "info proc exe" for NetBSD Kamil Rytarowski
@ 2020-04-12 17:13 ` Simon Marchi
2020-04-12 17:22 ` Kamil Rytarowski
0 siblings, 1 reply; 6+ messages in thread
From: Simon Marchi @ 2020-04-12 17:13 UTC (permalink / raw)
To: Kamil Rytarowski, gdb-patches
On 2020-04-12 11:36 a.m., Kamil Rytarowski wrote:
> Use pid_to_exec_file() to query the program.
>
> gdb/ChangeLog:
>
> * nbsd-nat.c (nbsd_nat_target::info_proc): Add do_exe.
Thanks, this is ok.
Simon
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Implement "info proc exe" for NetBSD
2020-04-12 17:13 ` Simon Marchi
@ 2020-04-12 17:22 ` Kamil Rytarowski
0 siblings, 0 replies; 6+ messages in thread
From: Kamil Rytarowski @ 2020-04-12 17:22 UTC (permalink / raw)
To: Simon Marchi, gdb-patches
On 12.04.2020 19:13, Simon Marchi wrote:
> On 2020-04-12 11:36 a.m., Kamil Rytarowski wrote:
>> Use pid_to_exec_file() to query the program.
>>
>> gdb/ChangeLog:
>>
>> * nbsd-nat.c (nbsd_nat_target::info_proc): Add do_exe.
>
> Thanks, this is ok.
>
> Simon
>
Thanks.
I will just reorder "if (do_exe)" and "if (do_mappings)" to follow the
FreeBSD order and push it.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Implement "info proc exe" for NetBSD
2020-04-12 17:53 Kamil Rytarowski
@ 2020-04-12 17:59 ` Simon Marchi
2020-04-12 17:58 ` Kamil Rytarowski
0 siblings, 1 reply; 6+ messages in thread
From: Simon Marchi @ 2020-04-12 17:59 UTC (permalink / raw)
To: Kamil Rytarowski, gdb-patches
On 2020-04-12 1:53 p.m., Kamil Rytarowski wrote:
> Add nbsd_pid_to_cwd() to query the program current directory.
>
> gdb/ChangeLog:
>
> * nbsd-nat.c (nbsd_pid_to_cwd): Add.
> (nbsd_nat_target::info_proc): Add do_cwd.
This was sent with the wrong title I suppose, so we should ignore this one?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Implement "info proc exe" for NetBSD
2020-04-12 17:59 ` Simon Marchi
@ 2020-04-12 17:58 ` Kamil Rytarowski
0 siblings, 0 replies; 6+ messages in thread
From: Kamil Rytarowski @ 2020-04-12 17:58 UTC (permalink / raw)
To: Simon Marchi, gdb-patches
On 12.04.2020 19:59, Simon Marchi wrote:
> On 2020-04-12 1:53 p.m., Kamil Rytarowski wrote:
>> Add nbsd_pid_to_cwd() to query the program current directory.
>>
>> gdb/ChangeLog:
>>
>> * nbsd-nat.c (nbsd_pid_to_cwd): Add.
>> (nbsd_nat_target::info_proc): Add do_cwd.
>
> This was sent with the wrong title I suppose, so we should ignore this one?
>
Yes. I resent it with a new title.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] Implement "info proc exe" for NetBSD
@ 2020-04-12 17:53 Kamil Rytarowski
2020-04-12 17:59 ` Simon Marchi
0 siblings, 1 reply; 6+ messages in thread
From: Kamil Rytarowski @ 2020-04-12 17:53 UTC (permalink / raw)
To: gdb-patches
Add nbsd_pid_to_cwd() to query the program current directory.
gdb/ChangeLog:
* nbsd-nat.c (nbsd_pid_to_cwd): Add.
(nbsd_nat_target::info_proc): Add do_cwd.
---
gdb/ChangeLog | 5 +++++
gdb/nbsd-nat.c | 27 +++++++++++++++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 3bbd5c3129d..9e49cf9cf97 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2020-04-12 Kamil Rytarowski <n54@gmx.com>
+
+ * nbsd-nat.c (nbsd_pid_to_cwd): Add.
+ (nbsd_nat_target::info_proc): Add do_cwd.
+
2020-04-12 Kamil Rytarowski <n54@gmx.com>
* nbsd-nat.c (nbsd_nat_target::info_proc): Add do_exe.
diff --git a/gdb/nbsd-nat.c b/gdb/nbsd-nat.c
index 05aedf8e3f1..628bf919a98 100644
--- a/gdb/nbsd-nat.c
+++ b/gdb/nbsd-nat.c
@@ -44,6 +44,21 @@ nbsd_nat_target::pid_to_exec_file (int pid)
return buf;
}
+/* Return the name of a file that can be opened to get the symbols for
+ the child process identified by PID. */
+
+static std::string
+nbsd_pid_to_cwd (int pid)
+{
+ char buf[PATH_MAX];
+ size_t buflen;
+ int mib[4] = {CTL_KERN, KERN_PROC_ARGS, pid, KERN_PROC_CWD};
+ buflen = sizeof (buf);
+ if (sysctl (mib, ARRAY_SIZE (mib), buf, &buflen, NULL, 0))
+ return "";
+ return buf;
+}
+
/* Generic thread (LWP) lister within a specified process. The callback
parameters is a C++ function that is called for each detected thread. */
@@ -299,6 +314,7 @@ bool
nbsd_nat_target::info_proc (const char *args, enum info_proc_what what)
{
pid_t pid;
+ bool do_cwd = false;
bool do_exe = false;
bool do_mappings = false;
@@ -310,6 +326,9 @@ nbsd_nat_target::info_proc (const char *args, enum info_proc_what what)
case IP_EXE:
do_exe = true;
break;
+ case IP_CWD:
+ do_cwd = true;
+ break;
default:
error (_("Not supported on this target."));
}
@@ -328,6 +347,14 @@ nbsd_nat_target::info_proc (const char *args, enum info_proc_what what)
printf_filtered (_("process %d\n"), pid);
+ if (do_cwd)
+ {
+ std::string cwd = nbsd_pid_to_cwd (pid);
+ if (cwd != "")
+ printf_filtered ("cwd = '%s'\n", cwd.c_str ());
+ else
+ warning (_("unable to fetch current working directory"));
+ }
if (do_exe)
{
const char *exe = pid_to_exec_file (pid);
--
2.25.0
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-04-12 17:59 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-12 15:36 [PATCH] Implement "info proc exe" for NetBSD Kamil Rytarowski
2020-04-12 17:13 ` Simon Marchi
2020-04-12 17:22 ` Kamil Rytarowski
2020-04-12 17:53 Kamil Rytarowski
2020-04-12 17:59 ` Simon Marchi
2020-04-12 17:58 ` Kamil Rytarowski
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).