Re: [PATCH v3 4/7] Per-inferior/Inferior-qualified thread IDs

2016-12-08 Thread Thomas Schwinge
Hi Simon!

On Wed, 7 Dec 2016 16:28:58 -0500, Simon Marchi  
wrote:
> On 16-12-07 04:09 PM, Thomas Schwinge wrote:
> > commit 14f6890677849172a4b13779acd9089c9baa3a81
> > Author: Thomas Schwinge 
> > Date:   Tue May 24 19:36:57 2016 +0200
> > 
> > Hurd: Adjust to "Per-inferior/Inferior-qualified thread IDs" changes
> > 
> > [...]/gdb/gnu-nat.c: In function 'set_sig_thread_cmd':
> > [...]/gdb/gnu-nat.c:2973:7: warning: implicit declaration of 
> > function 'thread_id_to_pid' [-Wimplicit-function-declaration]
> >ptid_t ptid = thread_id_to_pid (atoi (args));
> >^
> > [...]/gdb/gnu-nat.c:2973:7: error: invalid initializer
> > 
> > That's commit 5d5658a1d3c3eb2a09c03f2f0662a1c01963c869, which renamed
> > `thread_id_to_pid` to `global_thread_id_to_ptid`.

> > --- gdb/gnu-nat.c
> > +++ gdb/gnu-nat.c
> > @@ -2964,7 +2964,7 @@ set_sig_thread_cmd (char *args, int from_tty)
> >  inf->signal_thread = 0;
> >else
> >  {
> > -  ptid_t ptid = thread_id_to_pid (atoi (args));
> > +  ptid_t ptid = global_thread_id_to_ptid (atoi (args));
> 
> I think your patch is better than the status quo, since it fixes the build.
> However, global_thread_id_to_ptid expects global thread numbers, which are
> nowadays only used in MI, never presented to the user in the CLI.  Since this
> is a CLI command, it should accept the inferior-qualified format instead.

Thanks for the review!

> Something similar to this should do the trick (I can't test it though):

> --- a/gdb/gnu-nat.c
> +++ b/gdb/gnu-nat.c
> @@ -2964,13 +2964,13 @@ set_sig_thread_cmd (char *args, int from_tty)
>  inf->signal_thread = 0;
>else
>  {
> -  ptid_t ptid = thread_id_to_pid (atoi (args));
> +  struct thread_info *tp = parse_thread_id (args, NULL)
> 
> -  if (ptid_equal (ptid, minus_one_ptid))
> +  if (tp == nullptr)
> error (_("Thread ID %s not known.  "
>  "Use the \"info threads\" command to\n"
>"see the IDs of currently known threads."), args);
> -  inf->signal_thread = inf_tid_to_thread (inf, ptid_get_lwp (ptid));
> +  inf->signal_thread = inf_tid_to_thread (inf, ptid_get_lwp (tp->ptid));
>  }
>  }

Thanks for the patch!  Actually, parse_thread_id will never return NULL
("Either a valid thread is returned, or an error is thrown."), so that
can be made even simpler.  (As also the parse_thread_id usage in
gdb/thread.c doesn't use ENDPTR to check for "junk" after the thread ID,
I don't see a need to do that here.)  ;-)

> If there's a more efficient/concise way to go from a thread_info* to a proc*, 
> we
> should probably use it, but I couldn't find one.

Indeed that seems to be the standard pattern.

I pushed the following to master:

commit c3187fa5cc72734e6fc766a85d657018c0516bad
Author: Simon Marchi 
Date:   Thu Dec 8 09:45:59 2016 +0100

Hurd: In the CLI, use parse_thread_id instead of global_thread_id_to_ptid

Follow-up to commit 14f6890677849172a4b13779acd9089c9baa3a81.
global_thread_id_to_ptid expects global thread numbers, which are nowadays 
only
used in MI, never presented to the user in the CLI.  Since this is a CLI
command, it should accept the inferior-qualified format instead.

gdb/
* gnu-nat.c (set_sig_thread_cmd): Use parse_thread_id instead of
global_thread_id_to_ptid.
---
 gdb/ChangeLog |  6 ++
 gdb/gnu-nat.c | 12 
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git gdb/ChangeLog gdb/ChangeLog
index 171d03a..2bd99f1 100644
--- gdb/ChangeLog
+++ gdb/ChangeLog
@@ -1,3 +1,9 @@
+2016-12-08  Simon Marchi  
+   Thomas Schwinge  
+
+   * gnu-nat.c (set_sig_thread_cmd): Use parse_thread_id instead of
+   global_thread_id_to_ptid.
+
 2016-12-08  Thomas Schwinge  
 
* config/i386/i386gnu.mh (%_S.o %_U.o): Add "-x c" to
diff --git gdb/gnu-nat.c gdb/gnu-nat.c
index 5fd59a2..124574e 100644
--- gdb/gnu-nat.c
+++ gdb/gnu-nat.c
@@ -63,6 +63,7 @@ extern "C"
 #include "gdbcore.h"
 #include "gdbthread.h"
 #include "gdb_obstack.h"
+#include "tid-parse.h"
 
 #include "gnu-nat.h"
 #include "inf-child.h"
@@ -2975,19 +2976,14 @@ set_sig_thread_cmd (char *args, int from_tty)
 
   if (!args || (!isdigit (*args) && strcmp (args, "none") != 0))
 error (_("Illegal argument to \"set signal-thread\" command.\n"
-  "Should be an integer thread ID, or `none'."));
+"Should be a thread ID, or \"none\"."));
 
   if (strcmp (args, "none") == 0)
 inf->signal_thread = 0;
   else
 {
-  ptid_t ptid = global_thread_id_to_ptid (atoi (args));
-
-  if (ptid_equal (ptid, minus_one_ptid))
-   error (_("Thread ID %s not known.  "
-"Use the \"info threads\" command to\n"
-  "see the IDs of currently known threads."), args);
-  inf->signal_thread = inf_tid_to_thread (inf, ptid_get_lwp (ptid));
+  struct thread_info *tp = parse_thread_i

Re: [PATCH v3 4/7] Per-inferior/Inferior-qualified thread IDs

2016-12-07 Thread Simon Marchi
On 16-12-07 04:09 PM, Thomas Schwinge wrote:
> commit 14f6890677849172a4b13779acd9089c9baa3a81
> Author: Thomas Schwinge 
> Date:   Tue May 24 19:36:57 2016 +0200
> 
> Hurd: Adjust to "Per-inferior/Inferior-qualified thread IDs" changes
> 
> [...]/gdb/gnu-nat.c: In function 'set_sig_thread_cmd':
> [...]/gdb/gnu-nat.c:2973:7: warning: implicit declaration of function 
> 'thread_id_to_pid' [-Wimplicit-function-declaration]
>ptid_t ptid = thread_id_to_pid (atoi (args));
>^
> [...]/gdb/gnu-nat.c:2973:7: error: invalid initializer
> 
> That's commit 5d5658a1d3c3eb2a09c03f2f0662a1c01963c869, which renamed
> `thread_id_to_pid` to `global_thread_id_to_ptid`.
> 
> gdb/
> * gnu-nat.c (set_sig_thread_cmd): Call global_thread_id_to_ptid
> instead of thread_id_to_pid.
> ---
>  gdb/ChangeLog | 5 +
>  gdb/gnu-nat.c | 2 +-
>  2 files changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git gdb/ChangeLog gdb/ChangeLog
> index c251150..61d1205 100644
> --- gdb/ChangeLog
> +++ gdb/ChangeLog
> @@ -1,3 +1,8 @@
> +2016-12-07  Thomas Schwinge  
> +
> + * gnu-nat.c (set_sig_thread_cmd): Call global_thread_id_to_ptid
> + instead of thread_id_to_pid.
> +
>  2016-12-06  Simon Marchi  
>  
>   * inferior.c (inferior_command): Remove duplicate
> diff --git gdb/gnu-nat.c gdb/gnu-nat.c
> index 927ee5c..92b9292 100644
> --- gdb/gnu-nat.c
> +++ gdb/gnu-nat.c
> @@ -2964,7 +2964,7 @@ set_sig_thread_cmd (char *args, int from_tty)
>  inf->signal_thread = 0;
>else
>  {
> -  ptid_t ptid = thread_id_to_pid (atoi (args));
> +  ptid_t ptid = global_thread_id_to_ptid (atoi (args));

Hi Thomas,

I think your patch is better than the status quo, since it fixes the build.
However, global_thread_id_to_ptid expects global thread numbers, which are
nowadays only used in MI, never presented to the user in the CLI.  Since this
is a CLI command, it should accept the inferior-qualified format instead.

Something similar to this should do the trick (I can't test it though):

diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c
index 927ee5c6f1..6b4385d9c3 100644
--- a/gdb/gnu-nat.c
+++ b/gdb/gnu-nat.c
@@ -2964,13 +2964,13 @@ set_sig_thread_cmd (char *args, int from_tty)
 inf->signal_thread = 0;
   else
 {
-  ptid_t ptid = thread_id_to_pid (atoi (args));
+  struct thread_info *tp = parse_thread_id (args, NULL)

-  if (ptid_equal (ptid, minus_one_ptid))
+  if (tp == nullptr)
error (_("Thread ID %s not known.  "
 "Use the \"info threads\" command to\n"
   "see the IDs of currently known threads."), args);
-  inf->signal_thread = inf_tid_to_thread (inf, ptid_get_lwp (ptid));
+  inf->signal_thread = inf_tid_to_thread (inf, ptid_get_lwp (tp->ptid));
 }
 }

If there's a more efficient/concise way to go from a thread_info* to a proc*, we
should probably use it, but I couldn't find one.

Simon



Re: [PATCH v3 4/7] Per-inferior/Inferior-qualified thread IDs

2016-12-07 Thread Thomas Schwinge
Hi!

Better late than never...  ;-)

On Thu, 07 Jan 2016 23:37:38 +, Pedro Alves  wrote:
> --- a/gdb/gdbthread.h
> +++ b/gdb/gdbthread.h

> -/* Translate the integer thread id (GDB's homegrown id, not the system's)
> -   into a "pid" (which may be overloaded with extra thread information).  */
> -extern ptid_t thread_id_to_pid (int);
> +/* Translate the global integer thread id (GDB's homegrown id, not the
> +   system's) into a "pid" (which may be overloaded with extra thread
> +   information).  */
> +extern ptid_t global_thread_id_to_ptid (int num);

As obvious; pushed to master:

commit 14f6890677849172a4b13779acd9089c9baa3a81
Author: Thomas Schwinge 
Date:   Tue May 24 19:36:57 2016 +0200

Hurd: Adjust to "Per-inferior/Inferior-qualified thread IDs" changes

[...]/gdb/gnu-nat.c: In function 'set_sig_thread_cmd':
[...]/gdb/gnu-nat.c:2973:7: warning: implicit declaration of function 
'thread_id_to_pid' [-Wimplicit-function-declaration]
   ptid_t ptid = thread_id_to_pid (atoi (args));
   ^
[...]/gdb/gnu-nat.c:2973:7: error: invalid initializer

That's commit 5d5658a1d3c3eb2a09c03f2f0662a1c01963c869, which renamed
`thread_id_to_pid` to `global_thread_id_to_ptid`.

gdb/
* gnu-nat.c (set_sig_thread_cmd): Call global_thread_id_to_ptid
instead of thread_id_to_pid.
---
 gdb/ChangeLog | 5 +
 gdb/gnu-nat.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git gdb/ChangeLog gdb/ChangeLog
index c251150..61d1205 100644
--- gdb/ChangeLog
+++ gdb/ChangeLog
@@ -1,3 +1,8 @@
+2016-12-07  Thomas Schwinge  
+
+   * gnu-nat.c (set_sig_thread_cmd): Call global_thread_id_to_ptid
+   instead of thread_id_to_pid.
+
 2016-12-06  Simon Marchi  
 
* inferior.c (inferior_command): Remove duplicate
diff --git gdb/gnu-nat.c gdb/gnu-nat.c
index 927ee5c..92b9292 100644
--- gdb/gnu-nat.c
+++ gdb/gnu-nat.c
@@ -2964,7 +2964,7 @@ set_sig_thread_cmd (char *args, int from_tty)
 inf->signal_thread = 0;
   else
 {
-  ptid_t ptid = thread_id_to_pid (atoi (args));
+  ptid_t ptid = global_thread_id_to_ptid (atoi (args));
 
   if (ptid_equal (ptid, minus_one_ptid))
error (_("Thread ID %s not known.  "


Grüße
 Thomas