* [PATCH] Implement nbsd_nat_target::thread_alive
@ 2020-03-25 19:36 Kamil Rytarowski
2020-03-25 20:42 ` John Baldwin
0 siblings, 1 reply; 5+ messages in thread
From: Kamil Rytarowski @ 2020-03-25 19:36 UTC (permalink / raw)
To: gdb-patches
gdb/ChangeLog:
* nbsd-nat.h (nbsd_nat_target::thread_alive): Add.
* nbsd-nat.c (nbsd_nat_target::thread_alive): Add.
---
gdb/ChangeLog | 5 +++++
gdb/nbsd-nat.c | 30 ++++++++++++++++++++++++++++++
gdb/nbsd-nat.h | 1 +
3 files changed, 36 insertions(+)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 1ee58a541cb..d6789f4d7ca 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2020-03-25 Kamil Rytarowski <n54@gmx.com>
+
+ * nbsd-nat.h (nbsd_nat_target::thread_alive): Add.
+ * nbsd-nat.c (nbsd_nat_target::thread_alive): Add.
+
2020-03-25 Tom Tromey <tom@tromey.com>
* compile/compile-object-load.c (get_out_value_type): Mention
diff --git a/gdb/nbsd-nat.c b/gdb/nbsd-nat.c
index 326bbe3aec3..aa0353309df 100644
--- a/gdb/nbsd-nat.c
+++ b/gdb/nbsd-nat.c
@@ -39,3 +39,33 @@ nbsd_nat_target::pid_to_exec_file (int pid)
return NULL;
return buf;
}
+
+bool
+thread_alive (ptid_t ptid)
+{
+ pid_t pid = ptid.pid ();
+ int lwp = ptid.lwp ();
+ int mib[5] = {CTL_KERN, KERN_LWP, pid, sizeof (struct kinfo_lwp), 0};
+ size_t size;
+
+ if (sysctl (mib, 5, NULL, &size, NULL, 0) == -1 || size == 0)
+ perror_with_name (("sysctl"));
+
+ mib[4] = size / sizeof (size_t);
+
+ gdb::unique_xmalloc_ptr<struct kinfo_lwp> kl
+ ((struct kinfo_lwp *) xcalloc (size, 1));
+ if (kl == NULL)
+ perror_with_name (("calloc"));
+
+ if (sysctl (mib, 5, kl.get (), &size, NULL, 0) == -1 || size == 0)
+ perror_with_name (("sysctl"));
+
+ for (size_t i = 0; i < size / sizeof (struct kinfo_lwp); i++)
+ {
+ if (kl.get ()[i].l_lid == lwp)
+ return true;
+ }
+
+ return false;
+}
diff --git a/gdb/nbsd-nat.h b/gdb/nbsd-nat.h
index a752fbe572d..11b49427a44 100644
--- a/gdb/nbsd-nat.h
+++ b/gdb/nbsd-nat.h
@@ -27,6 +27,7 @@
struct nbsd_nat_target : public inf_ptrace_target
{
char *pid_to_exec_file (int pid) override;
+ bool thread_alive (ptid_t ptid) override;
};
#endif /* nbsd-nat.h */
--
2.25.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Implement nbsd_nat_target::thread_alive
2020-03-25 19:36 [PATCH] Implement nbsd_nat_target::thread_alive Kamil Rytarowski
@ 2020-03-25 20:42 ` John Baldwin
2020-03-25 21:01 ` Kamil Rytarowski
0 siblings, 1 reply; 5+ messages in thread
From: John Baldwin @ 2020-03-25 20:42 UTC (permalink / raw)
To: Kamil Rytarowski, gdb-patches
On 3/25/20 12:36 PM, Kamil Rytarowski wrote:
> gdb/ChangeLog:
>
> * nbsd-nat.h (nbsd_nat_target::thread_alive): Add.
> * nbsd-nat.c (nbsd_nat_target::thread_alive): Add.
> ---
> gdb/ChangeLog | 5 +++++
> gdb/nbsd-nat.c | 30 ++++++++++++++++++++++++++++++
> gdb/nbsd-nat.h | 1 +
> 3 files changed, 36 insertions(+)
>
> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> index 1ee58a541cb..d6789f4d7ca 100644
> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,3 +1,8 @@
> +2020-03-25 Kamil Rytarowski <n54@gmx.com>
> +
> + * nbsd-nat.h (nbsd_nat_target::thread_alive): Add.
> + * nbsd-nat.c (nbsd_nat_target::thread_alive): Add.
> +
> 2020-03-25 Tom Tromey <tom@tromey.com>
>
> * compile/compile-object-load.c (get_out_value_type): Mention
> diff --git a/gdb/nbsd-nat.c b/gdb/nbsd-nat.c
> index 326bbe3aec3..aa0353309df 100644
> --- a/gdb/nbsd-nat.c
> +++ b/gdb/nbsd-nat.c
> @@ -39,3 +39,33 @@ nbsd_nat_target::pid_to_exec_file (int pid)
> return NULL;
> return buf;
> }
> +
> +bool
> +thread_alive (ptid_t ptid)
> +{
> + pid_t pid = ptid.pid ();
> + int lwp = ptid.lwp ();
> + int mib[5] = {CTL_KERN, KERN_LWP, pid, sizeof (struct kinfo_lwp), 0};
> + size_t size;
> +
> + if (sysctl (mib, 5, NULL, &size, NULL, 0) == -1 || size == 0)
> + perror_with_name (("sysctl"));
> +
> + mib[4] = size / sizeof (size_t);
> +
> + gdb::unique_xmalloc_ptr<struct kinfo_lwp> kl
> + ((struct kinfo_lwp *) xcalloc (size, 1));
> + if (kl == NULL)
> + perror_with_name (("calloc"));
> +
> + if (sysctl (mib, 5, kl.get (), &size, NULL, 0) == -1 || size == 0)
> + perror_with_name (("sysctl"));
> +
> + for (size_t i = 0; i < size / sizeof (struct kinfo_lwp); i++)
> + {
> + if (kl.get ()[i].l_lid == lwp)
> + return true;
> + }
> +
> + return false;
Given that you have nearly identical code both here and in the thread_name
method in your other patch, perhaps it makes sense to have a single
"gdb::unique_xmalloc_ptr <struct kinfo_lwp> fetch_kinfo_lwp(ptid_t ptid)"
helper function that the other routines could share? Perhaps instead of
just returning the pointer to the array of structures it could take a lamda
function that is invoked on the matching 'kl' instance with the correct lwp?
--
John Baldwin
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Implement nbsd_nat_target::thread_alive
2020-03-25 20:42 ` John Baldwin
@ 2020-03-25 21:01 ` Kamil Rytarowski
2020-03-25 21:08 ` Simon Marchi
0 siblings, 1 reply; 5+ messages in thread
From: Kamil Rytarowski @ 2020-03-25 21:01 UTC (permalink / raw)
To: John Baldwin, gdb-patches
On 25.03.2020 21:42, John Baldwin wrote:
> On 3/25/20 12:36 PM, Kamil Rytarowski wrote:
>> gdb/ChangeLog:
>>
>> * nbsd-nat.h (nbsd_nat_target::thread_alive): Add.
>> * nbsd-nat.c (nbsd_nat_target::thread_alive): Add.
>> ---
>> gdb/ChangeLog | 5 +++++
>> gdb/nbsd-nat.c | 30 ++++++++++++++++++++++++++++++
>> gdb/nbsd-nat.h | 1 +
>> 3 files changed, 36 insertions(+)
>>
>> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
>> index 1ee58a541cb..d6789f4d7ca 100644
>> --- a/gdb/ChangeLog
>> +++ b/gdb/ChangeLog
>> @@ -1,3 +1,8 @@
>> +2020-03-25 Kamil Rytarowski <n54@gmx.com>
>> +
>> + * nbsd-nat.h (nbsd_nat_target::thread_alive): Add.
>> + * nbsd-nat.c (nbsd_nat_target::thread_alive): Add.
>> +
>> 2020-03-25 Tom Tromey <tom@tromey.com>
>>
>> * compile/compile-object-load.c (get_out_value_type): Mention
>> diff --git a/gdb/nbsd-nat.c b/gdb/nbsd-nat.c
>> index 326bbe3aec3..aa0353309df 100644
>> --- a/gdb/nbsd-nat.c
>> +++ b/gdb/nbsd-nat.c
>> @@ -39,3 +39,33 @@ nbsd_nat_target::pid_to_exec_file (int pid)
>> return NULL;
>> return buf;
>> }
>> +
>> +bool
>> +thread_alive (ptid_t ptid)
>> +{
>> + pid_t pid = ptid.pid ();
>> + int lwp = ptid.lwp ();
>> + int mib[5] = {CTL_KERN, KERN_LWP, pid, sizeof (struct kinfo_lwp), 0};
>> + size_t size;
>> +
>> + if (sysctl (mib, 5, NULL, &size, NULL, 0) == -1 || size == 0)
>> + perror_with_name (("sysctl"));
>> +
>> + mib[4] = size / sizeof (size_t);
>> +
>> + gdb::unique_xmalloc_ptr<struct kinfo_lwp> kl
>> + ((struct kinfo_lwp *) xcalloc (size, 1));
>> + if (kl == NULL)
>> + perror_with_name (("calloc"));
>> +
>> + if (sysctl (mib, 5, kl.get (), &size, NULL, 0) == -1 || size == 0)
>> + perror_with_name (("sysctl"));
>> +
>> + for (size_t i = 0; i < size / sizeof (struct kinfo_lwp); i++)
>> + {
>> + if (kl.get ()[i].l_lid == lwp)
>> + return true;
>> + }
>> +
>> + return false;
>
> Given that you have nearly identical code both here and in the thread_name
> method in your other patch, perhaps it makes sense to have a single
> "gdb::unique_xmalloc_ptr <struct kinfo_lwp> fetch_kinfo_lwp(ptid_t ptid)"
> helper function that the other routines could share? Perhaps instead of
> just returning the pointer to the array of structures it could take a lamda
> function that is invoked on the matching 'kl' instance with the correct lwp?
>
I can do it. I will submit these two patches in one go. I will also add
a third similar function to list threads within a process.
Normally, I would go for PT_LWPSTATUS, but it is available since NetBSD
>10 and for the time being sysctl(3) is more portable.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Implement nbsd_nat_target::thread_alive
2020-03-25 21:01 ` Kamil Rytarowski
@ 2020-03-25 21:08 ` Simon Marchi
2020-03-26 4:00 ` Kamil Rytarowski
0 siblings, 1 reply; 5+ messages in thread
From: Simon Marchi @ 2020-03-25 21:08 UTC (permalink / raw)
To: Kamil Rytarowski, John Baldwin, gdb-patches
On 2020-03-25 5:01 p.m., Kamil Rytarowski wrote:
> On 25.03.2020 21:42, John Baldwin wrote:
>> Given that you have nearly identical code both here and in the thread_name
>> method in your other patch, perhaps it makes sense to have a single
>> "gdb::unique_xmalloc_ptr <struct kinfo_lwp> fetch_kinfo_lwp(ptid_t ptid)"
>> helper function that the other routines could share? Perhaps instead of
>> just returning the pointer to the array of structures it could take a lamda
>> function that is invoked on the matching 'kl' instance with the correct lwp?
>>
>
> I can do it. I will submit these two patches in one go. I will also add
> a third similar function to list threads within a process.
>
> Normally, I would go for PT_LWPSTATUS, but it is available since NetBSD
>> 10 and for the time being sysctl(3) is more portable.
And let me mention the same thing I've told John :). Please add a meaningful
commit message, explaining why you do this change. It's easy to see _what_
it does, but not _why_ you needed to do it. Does it enable some feature, does
it fix some test case, something else? What impact does it have?
Simon
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Implement nbsd_nat_target::thread_alive
2020-03-25 21:08 ` Simon Marchi
@ 2020-03-26 4:00 ` Kamil Rytarowski
0 siblings, 0 replies; 5+ messages in thread
From: Kamil Rytarowski @ 2020-03-26 4:00 UTC (permalink / raw)
To: Simon Marchi, John Baldwin, gdb-patches
On 25.03.2020 22:08, Simon Marchi wrote:
> On 2020-03-25 5:01 p.m., Kamil Rytarowski wrote:
>> On 25.03.2020 21:42, John Baldwin wrote:
>>> Given that you have nearly identical code both here and in the thread_name
>>> method in your other patch, perhaps it makes sense to have a single
>>> "gdb::unique_xmalloc_ptr <struct kinfo_lwp> fetch_kinfo_lwp(ptid_t ptid)"
>>> helper function that the other routines could share? Perhaps instead of
>>> just returning the pointer to the array of structures it could take a lamda
>>> function that is invoked on the matching 'kl' instance with the correct lwp?
>>>
>>
>> I can do it. I will submit these two patches in one go. I will also add
>> a third similar function to list threads within a process.
>>
>> Normally, I would go for PT_LWPSTATUS, but it is available since NetBSD
>>> 10 and for the time being sysctl(3) is more portable.
>
> And let me mention the same thing I've told John :). Please add a meaningful
> commit message, explaining why you do this change. It's easy to see _what_
> it does, but not _why_ you needed to do it. Does it enable some feature, does
> it fix some test case, something else? What impact does it have?
>
> Simon
>
Done in [PATCH v2] Implement basic threading support in the NetBSD target.
Please review.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-03-26 4:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-25 19:36 [PATCH] Implement nbsd_nat_target::thread_alive Kamil Rytarowski
2020-03-25 20:42 ` John Baldwin
2020-03-25 21:01 ` Kamil Rytarowski
2020-03-25 21:08 ` Simon Marchi
2020-03-26 4:00 ` 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).