public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix -list-thread-groups --available logic and add test
@ 2017-10-04 14:01 Simon Marchi
  2017-10-04 14:14 ` Pedro Alves
  0 siblings, 1 reply; 10+ messages in thread
From: Simon Marchi @ 2017-10-04 14:01 UTC (permalink / raw)
  To: gdb-patches; +Cc: tom, Simon Marchi

Commit

  Use std::set in mi-main.c
  52f9abe4c739f42cc5f80b2629276493ac6306f9

changed the logic of the "-list-thread-groups --available" by mistake
when a pid is passed.  It prints all the processes except the one
specified by the given pid.  The correct behavior is to only print the
process corresponding to that pid.  this patch fixes that and adds a test.

gdb/ChangeLog:

	* mi/mi-main.c (list_available_thread_groups): Reverse filter logic.

gdb/testsuite/ChangeLog:

	* gdb.mi/list-thread-groups-available.exp: New file.
	* gdb.mi/list-thread-groups-available.c: New file.
---
 gdb/mi/mi-main.c                                   |  2 +-
 .../gdb.mi/list-thread-groups-available.c          | 29 +++++++++++++
 .../gdb.mi/list-thread-groups-available.exp        | 48 ++++++++++++++++++++++
 3 files changed, 78 insertions(+), 1 deletion(-)
 create mode 100644 gdb/testsuite/gdb.mi/list-thread-groups-available.c
 create mode 100644 gdb/testsuite/gdb.mi/list-thread-groups-available.exp

diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 83b1fcf..289445f 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -801,7 +801,7 @@ list_available_thread_groups (const std::set<int> &ids, int recurse)
       /* At present, the target will return all available processes
 	 and if information about specific ones was required, we filter
 	 undesired processes here.  */
-      if (!ids.empty () && ids.find (pid_i) != ids.end ())
+      if (!ids.empty () && ids.find (pid_i) == ids.end ())
 	continue;
 
       ui_out_emit_tuple tuple_emitter (uiout, NULL);
diff --git a/gdb/testsuite/gdb.mi/list-thread-groups-available.c b/gdb/testsuite/gdb.mi/list-thread-groups-available.c
new file mode 100644
index 0000000..56daec9
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/list-thread-groups-available.c
@@ -0,0 +1,29 @@
+/* Copyright 2017 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <unistd.h>
+
+int
+main ()
+{
+  int i;
+
+  for (i = 0; i < 30; i++)
+    sleep (1);
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.mi/list-thread-groups-available.exp b/gdb/testsuite/gdb.mi/list-thread-groups-available.exp
new file mode 100644
index 0000000..d33d3a9
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/list-thread-groups-available.exp
@@ -0,0 +1,48 @@
+# Copyright 2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test that -list-thread-groups --available works.
+
+load_lib mi-support.exp
+set MIFLAGS "-i=mi"
+
+standard_testfile
+
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+    untested "failed to compile"
+    return -1
+}
+
+if [mi_gdb_start] {
+    continue
+}
+
+if [use_gdb_stub] {
+    continue
+}
+
+# List all available processes.
+mi_gdb_test \
+    "-list-thread-groups --available" \
+    "\\^done,groups=\\\[.*\\\]" \
+    "list available thread groups"
+
+# List a specific process.
+set spawn_id [remote_spawn target $binfile]
+set pid [spawn_id_get_pid $spawn_id]
+mi_gdb_test \
+    "-list-thread-groups --available i${pid}" \
+    "\\^done,groups=\\\[{id=\"${pid}\",type=\"process\",.*}\\\]" \
+    "list available thread groups with filter"
-- 
2.7.4

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

* Re: [PATCH] Fix -list-thread-groups --available logic and add test
  2017-10-04 14:01 [PATCH] Fix -list-thread-groups --available logic and add test Simon Marchi
@ 2017-10-04 14:14 ` Pedro Alves
  2017-10-04 14:32   ` Simon Marchi
  0 siblings, 1 reply; 10+ messages in thread
From: Pedro Alves @ 2017-10-04 14:14 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches; +Cc: tom

On 10/04/2017 03:00 PM, Simon Marchi wrote:

> +# List a specific process.
> +set spawn_id [remote_spawn target $binfile]
> +set pid [spawn_id_get_pid $spawn_id]
> +mi_gdb_test \
> +    "-list-thread-groups --available i${pid}" \
> +    "\\^done,groups=\\\[{id=\"${pid}\",type=\"process\",.*}\\\]" \
> +    "list available thread groups with filter"

Won't that ".*" above end up matching more than one process, if
GDB's filtering ends up a bit borked?  Can we be sure that
only one process comes out?

Thanks,
Pedro Alves

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

* Re: [PATCH] Fix -list-thread-groups --available logic and add test
  2017-10-04 14:14 ` Pedro Alves
@ 2017-10-04 14:32   ` Simon Marchi
  2017-10-04 14:42     ` Pedro Alves
  0 siblings, 1 reply; 10+ messages in thread
From: Simon Marchi @ 2017-10-04 14:32 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Simon Marchi, gdb-patches, tom

On 2017-10-04 10:14, Pedro Alves wrote:
> On 10/04/2017 03:00 PM, Simon Marchi wrote:
> 
>> +# List a specific process.
>> +set spawn_id [remote_spawn target $binfile]
>> +set pid [spawn_id_get_pid $spawn_id]
>> +mi_gdb_test \
>> +    "-list-thread-groups --available i${pid}" \
>> +    "\\^done,groups=\\\[{id=\"${pid}\",type=\"process\",.*}\\\]" \
>> +    "list available thread groups with filter"
> 
> Won't that ".*" above end up matching more than one process, if
> GDB's filtering ends up a bit borked?  Can we be sure that
> only one process comes out?

I tried designing it like that but found it was pretty difficult because 
of the description field:

  55 
^done,groups=[{id="499",type="process",description="/home/emaisin/build/binutils-gdb/gdb/testsuite/outputs/gdb.mi/list-thread-groups-available/list-thread-groups-available",user="emaisin",cores=["1"]}]^M

If we have something like this:

   groups=[{id="$decimal",type="process",description=".*",...}]

and there are two process entries, the .* in the description field could 
match from the beginning of the first description field to the end of 
the second description field.  So we wouldn't catch that there are two 
processes instead of one.  And we can't really restrict its content, 
because it could potentially include [,}"].

Do you have any idea on how to do this with a regex?  The only "real" 
solution I see is to have a proper MI parser that parses MI to a tcl 
data structure, and assert that the list of groups is of length 1.

Simon

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

* Re: [PATCH] Fix -list-thread-groups --available logic and add test
  2017-10-04 14:32   ` Simon Marchi
@ 2017-10-04 14:42     ` Pedro Alves
  2017-10-04 16:01       ` Simon Marchi
  0 siblings, 1 reply; 10+ messages in thread
From: Pedro Alves @ 2017-10-04 14:42 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Simon Marchi, gdb-patches, tom


On 10/04/2017 03:32 PM, Simon Marchi wrote:
> On 2017-10-04 10:14, Pedro Alves wrote:
>> On 10/04/2017 03:00 PM, Simon Marchi wrote:
>>
>>> +# List a specific process.
>>> +set spawn_id [remote_spawn target $binfile]
>>> +set pid [spawn_id_get_pid $spawn_id]
>>> +mi_gdb_test \
>>> +    "-list-thread-groups --available i${pid}" \
>>> +    "\\^done,groups=\\\[{id=\"${pid}\",type=\"process\",.*}\\\]" \
>>> +    "list available thread groups with filter"
>>
>> Won't that ".*" above end up matching more than one process, if
>> GDB's filtering ends up a bit borked?  Can we be sure that
>> only one process comes out?
> 
> I tried designing it like that but found it was pretty difficult because
> of the description field:
> 
>  55
> ^done,groups=[{id="499",type="process",description="/home/emaisin/build/binutils-gdb/gdb/testsuite/outputs/gdb.mi/list-thread-groups-available/list-thread-groups-available",user="emaisin",cores=["1"]}]^M
> 
> 
> If we have something like this:
> 
>   groups=[{id="$decimal",type="process",description=".*",...}]

Instead of .*, how about matching "all but unquoted/terminating
double-quote" ?

See http://wiki.tcl.tk/989 for example (Match a "quoted string").

(Maybe there's an easier way to write that regex, haven't
really thought about it.)

> 
> and there are two process entries, the .* in the description field could
> match from the beginning of the first description field to the end of
> the second description field.  So we wouldn't catch that there are two
> processes instead of one.  And we can't really restrict its content,
> because it could potentially include [,}"].
> 
> Do you have any idea on how to do this with a regex?  The only "real"
> solution I see is to have a proper MI parser that parses MI to a tcl
> data structure, and assert that the list of groups is of length 1.

A "real" parser would consume the "..." description string as a single
string by looking for an unescaped terminating double-quote.  :-)

Thanks,
Pedro Alves

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

* [PATCH] Fix -list-thread-groups --available logic and add test
  2017-10-04 14:42     ` Pedro Alves
@ 2017-10-04 16:01       ` Simon Marchi
  2017-10-04 16:13         ` Pedro Alves
  0 siblings, 1 reply; 10+ messages in thread
From: Simon Marchi @ 2017-10-04 16:01 UTC (permalink / raw)
  To: gdb-patches; +Cc: tom, palves, Simon Marchi

New in v2:

- Match more precisely process entry in output.  Actually, match two, to
  test that giving more than one pid works.

Commit

  Use std::set in mi-main.c
  52f9abe4c739f42cc5f80b2629276493ac6306f9

changed the logic of the "-list-thread-groups --available" by mistake
when a pid is passed.  It prints all the processes except the one
specified by the given pid.  The correct behavior is to only print the
process corresponding to that pid.  this patch fixes that and adds a test.

gdb/ChangeLog:

	* mi/mi-main.c (list_available_thread_groups): Reverse filter logic.

gdb/testsuite/ChangeLog:

	* gdb.mi/list-thread-groups-available.exp: New file.
	* gdb.mi/list-thread-groups-available.c: New file.
---
 gdb/mi/mi-main.c                                   |  2 +-
 .../gdb.mi/list-thread-groups-available.c          | 29 +++++++++
 .../gdb.mi/list-thread-groups-available.exp        | 69 ++++++++++++++++++++++
 3 files changed, 99 insertions(+), 1 deletion(-)
 create mode 100644 gdb/testsuite/gdb.mi/list-thread-groups-available.c
 create mode 100644 gdb/testsuite/gdb.mi/list-thread-groups-available.exp

diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 83b1fcf..289445f 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -801,7 +801,7 @@ list_available_thread_groups (const std::set<int> &ids, int recurse)
       /* At present, the target will return all available processes
 	 and if information about specific ones was required, we filter
 	 undesired processes here.  */
-      if (!ids.empty () && ids.find (pid_i) != ids.end ())
+      if (!ids.empty () && ids.find (pid_i) == ids.end ())
 	continue;
 
       ui_out_emit_tuple tuple_emitter (uiout, NULL);
diff --git a/gdb/testsuite/gdb.mi/list-thread-groups-available.c b/gdb/testsuite/gdb.mi/list-thread-groups-available.c
new file mode 100644
index 0000000..56daec9
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/list-thread-groups-available.c
@@ -0,0 +1,29 @@
+/* Copyright 2017 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <unistd.h>
+
+int
+main ()
+{
+  int i;
+
+  for (i = 0; i < 30; i++)
+    sleep (1);
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.mi/list-thread-groups-available.exp b/gdb/testsuite/gdb.mi/list-thread-groups-available.exp
new file mode 100644
index 0000000..b766b3a
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/list-thread-groups-available.exp
@@ -0,0 +1,69 @@
+# Copyright 2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test that -list-thread-groups --available works.
+
+load_lib mi-support.exp
+set MIFLAGS "-i=mi"
+
+standard_testfile
+
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+    untested "failed to compile"
+    return -1
+}
+
+if [mi_gdb_start] {
+    continue
+}
+
+if [use_gdb_stub] {
+    continue
+}
+
+set string_re {(?:[^\\"]|\\.)*}
+
+set id_re "id=\"$decimal\""
+set type_re "type=\"process\""
+set description_re "description=\"$string_re\""
+set user_re "user=\"$string_re\""
+set cores_re "cores=\[\"$decimal\"(,\"$decimal\")*\]"
+
+# List all available processes.
+set process_entry_re "{${id_re},${type_re}(,$description_re)?(,$user_re)?(,$cores_re)?}"
+
+mi_gdb_test \
+    "-list-thread-groups --available" \
+    "\\^done,groups=\\\[${process_entry_re}(,$process_entry_re)*\\\]" \
+    "list available thread groups"
+
+# List specific processes, make sure there are two entries.
+set spawn_id_1 [remote_spawn target $binfile]
+set pid_1 [spawn_id_get_pid $spawn_id_1]
+set id_re_1 "id=\"$pid_1\""
+
+set spawn_id_2 [remote_spawn target $binfile]
+set pid_2 [spawn_id_get_pid $spawn_id_2]
+set id_re_2 "id=\"$pid_2\""
+
+set process_entry_re_1 "{${id_re_1},${type_re}(,$description_re)?(,$user_re)?(,$cores_re)?}"
+set process_entry_re_2 "{${id_re_2},${type_re}(,$description_re)?(,$user_re)?(,$cores_re)?}"
+
+set process_list_re "(${process_entry_re_1},${process_entry_re_2}|${process_entry_re_2},${process_entry_re_1})"
+
+mi_gdb_test \
+    "-list-thread-groups --available i${pid_1} i${pid_2}" \
+    "\\^done,groups=\\\[${process_list_re}\\\]" \
+    "list available thread groups with filter"
-- 
2.7.4

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

* Re: [PATCH] Fix -list-thread-groups --available logic and add test
  2017-10-04 16:01       ` Simon Marchi
@ 2017-10-04 16:13         ` Pedro Alves
  2017-10-04 16:31           ` [PATCH v3] " Simon Marchi
  2017-10-04 16:31           ` [PATCH] " Simon Marchi
  0 siblings, 2 replies; 10+ messages in thread
From: Pedro Alves @ 2017-10-04 16:13 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches; +Cc: tom

On 10/04/2017 05:00 PM, Simon Marchi wrote:
> New in v2:
> 
> - Match more precisely process entry in output.  Actually, match two, to
>   test that giving more than one pid works.
> 

Great, thanks!

I noticed something else.  Don't we need to kill/reap
the spawned spawn_id's?

There's kill_wait_spawned_process for that, but it operators
on build, not on target.

Maybe it'd be OK to limit the test to local testing,
and so you'd use can_spawn_for_attach instead of
use_gdb_stub.

Hmm, actually, I do think that you should do that, given:

proc can_spawn_for_attach { } {
    # We use exp_pid to get the inferior's pid, assuming that gives
    # back the pid of the program.  On remote boards, that would give
    # us instead the PID of e.g., the ssh client, etc.
    if [is_remote target] then {
        return 0
    }

(the "we" above refers to spawn_id_get_pid.)

Thanks,
Pedro Alves

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

* Re: [PATCH] Fix -list-thread-groups --available logic and add test
  2017-10-04 16:13         ` Pedro Alves
  2017-10-04 16:31           ` [PATCH v3] " Simon Marchi
@ 2017-10-04 16:31           ` Simon Marchi
  1 sibling, 0 replies; 10+ messages in thread
From: Simon Marchi @ 2017-10-04 16:31 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches; +Cc: tom

On 2017-10-04 12:13 PM, Pedro Alves wrote:
> On 10/04/2017 05:00 PM, Simon Marchi wrote:
>> New in v2:
>>
>> - Match more precisely process entry in output.  Actually, match two, to
>>   test that giving more than one pid works.
>>
> 
> Great, thanks!
> 
> I noticed something else.  Don't we need to kill/reap
> the spawned spawn_id's?
> 
> There's kill_wait_spawned_process for that, but it operators
> on build, not on target.

I just assumed dejagnu/expect/tcl did that for us.  I looked at the process list just after
running the test and there are no leftover test processes.  I'll add some calls to
kill_wait_spawned_process anyhow.  If I replace use_gdb_stub with can_spawn_for_attach, as you
suggest, it should work since we know that build == target.

> Maybe it'd be OK to limit the test to local testing,
> and so you'd use can_spawn_for_attach instead of
> use_gdb_stub.
> 
> Hmm, actually, I do think that you should do that, given:
> 
> proc can_spawn_for_attach { } {
>     # We use exp_pid to get the inferior's pid, assuming that gives
>     # back the pid of the program.  On remote boards, that would give
>     # us instead the PID of e.g., the ssh client, etc.
>     if [is_remote target] then {
>         return 0
>     }
> 
> (the "we" above refers to spawn_id_get_pid.)

Good point, thanks.

Simon

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

* [PATCH v3] Fix -list-thread-groups --available logic and add test
  2017-10-04 16:13         ` Pedro Alves
@ 2017-10-04 16:31           ` Simon Marchi
  2017-10-04 16:38             ` Pedro Alves
  2017-10-04 16:31           ` [PATCH] " Simon Marchi
  1 sibling, 1 reply; 10+ messages in thread
From: Simon Marchi @ 2017-10-04 16:31 UTC (permalink / raw)
  To: gdb-patches; +Cc: tom, palves, Simon Marchi

New in v3:

- Replace use_gdb_stub with can_spawn_for_attach.
- Call kill_wait_spawned_process on spawn_ids.

Commit

  Use std::set in mi-main.c
  52f9abe4c739f42cc5f80b2629276493ac6306f9

changed the logic of the "-list-thread-groups --available" by mistake
when a pid is passed.  It prints all the processes except the one
specified by the given pid.  The correct behavior is to only print the
process corresponding to that pid.  this patch fixes that and adds a test.

gdb/ChangeLog:

	* mi/mi-main.c (list_available_thread_groups): Reverse filter logic.

gdb/testsuite/ChangeLog:

	* gdb.mi/list-thread-groups-available.exp: New file.
	* gdb.mi/list-thread-groups-available.c: New file.
---
 gdb/mi/mi-main.c                                   |  2 +-
 .../gdb.mi/list-thread-groups-available.c          | 29 +++++++++
 .../gdb.mi/list-thread-groups-available.exp        | 72 ++++++++++++++++++++++
 3 files changed, 102 insertions(+), 1 deletion(-)
 create mode 100644 gdb/testsuite/gdb.mi/list-thread-groups-available.c
 create mode 100644 gdb/testsuite/gdb.mi/list-thread-groups-available.exp

diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 83b1fcf..289445f 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -801,7 +801,7 @@ list_available_thread_groups (const std::set<int> &ids, int recurse)
       /* At present, the target will return all available processes
 	 and if information about specific ones was required, we filter
 	 undesired processes here.  */
-      if (!ids.empty () && ids.find (pid_i) != ids.end ())
+      if (!ids.empty () && ids.find (pid_i) == ids.end ())
 	continue;
 
       ui_out_emit_tuple tuple_emitter (uiout, NULL);
diff --git a/gdb/testsuite/gdb.mi/list-thread-groups-available.c b/gdb/testsuite/gdb.mi/list-thread-groups-available.c
new file mode 100644
index 0000000..56daec9
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/list-thread-groups-available.c
@@ -0,0 +1,29 @@
+/* Copyright 2017 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <unistd.h>
+
+int
+main ()
+{
+  int i;
+
+  for (i = 0; i < 30; i++)
+    sleep (1);
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.mi/list-thread-groups-available.exp b/gdb/testsuite/gdb.mi/list-thread-groups-available.exp
new file mode 100644
index 0000000..eea27b4
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/list-thread-groups-available.exp
@@ -0,0 +1,72 @@
+# Copyright 2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test that -list-thread-groups --available works.
+
+load_lib mi-support.exp
+set MIFLAGS "-i=mi"
+
+standard_testfile
+
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+    untested "failed to compile"
+    return -1
+}
+
+if [mi_gdb_start] {
+    continue
+}
+
+if ![can_spawn_for_attach] {
+    continue
+}
+
+set string_re {(?:[^\\"]|\\.)*}
+
+set id_re "id=\"$decimal\""
+set type_re "type=\"process\""
+set description_re "description=\"$string_re\""
+set user_re "user=\"$string_re\""
+set cores_re "cores=\[\"$decimal\"(,\"$decimal\")*\]"
+
+# List all available processes.
+set process_entry_re "{${id_re},${type_re}(,$description_re)?(,$user_re)?(,$cores_re)?}"
+
+mi_gdb_test \
+    "-list-thread-groups --available" \
+    "\\^done,groups=\\\[${process_entry_re}(,$process_entry_re)*\\\]" \
+    "list available thread groups"
+
+# List specific processes, make sure there are two entries.
+set spawn_id_1 [remote_spawn target $binfile]
+set pid_1 [spawn_id_get_pid $spawn_id_1]
+set id_re_1 "id=\"$pid_1\""
+
+set spawn_id_2 [remote_spawn target $binfile]
+set pid_2 [spawn_id_get_pid $spawn_id_2]
+set id_re_2 "id=\"$pid_2\""
+
+set process_entry_re_1 "{${id_re_1},${type_re}(,$description_re)?(,$user_re)?(,$cores_re)?}"
+set process_entry_re_2 "{${id_re_2},${type_re}(,$description_re)?(,$user_re)?(,$cores_re)?}"
+
+set process_list_re "(${process_entry_re_1},${process_entry_re_2}|${process_entry_re_2},${process_entry_re_1})"
+
+mi_gdb_test \
+    "-list-thread-groups --available i${pid_1} i${pid_2}" \
+    "\\^done,groups=\\\[${process_list_re}\\\]" \
+    "list available thread groups with filter"
+
+kill_wait_spawned_process $spawn_id_1
+kill_wait_spawned_process $spawn_id_2
-- 
2.7.4

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

* Re: [PATCH v3] Fix -list-thread-groups --available logic and add test
  2017-10-04 16:31           ` [PATCH v3] " Simon Marchi
@ 2017-10-04 16:38             ` Pedro Alves
  2017-10-04 16:45               ` Simon Marchi
  0 siblings, 1 reply; 10+ messages in thread
From: Pedro Alves @ 2017-10-04 16:38 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches; +Cc: tom

On 10/04/2017 05:31 PM, Simon Marchi wrote:
> New in v3:
> 
> - Replace use_gdb_stub with can_spawn_for_attach.
> - Call kill_wait_spawned_process on spawn_ids.
> 

LGTM.

Thanks,
Pedro Alves

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

* Re: [PATCH v3] Fix -list-thread-groups --available logic and add test
  2017-10-04 16:38             ` Pedro Alves
@ 2017-10-04 16:45               ` Simon Marchi
  0 siblings, 0 replies; 10+ messages in thread
From: Simon Marchi @ 2017-10-04 16:45 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Simon Marchi, gdb-patches, tom

On 2017-10-04 12:38, Pedro Alves wrote:
> On 10/04/2017 05:31 PM, Simon Marchi wrote:
>> New in v3:
>> 
>> - Replace use_gdb_stub with can_spawn_for_attach.
>> - Call kill_wait_spawned_process on spawn_ids.
>> 
> 
> LGTM.
> 
> Thanks,
> Pedro Alves

Thanks, pushed.

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

end of thread, other threads:[~2017-10-04 16:45 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-04 14:01 [PATCH] Fix -list-thread-groups --available logic and add test Simon Marchi
2017-10-04 14:14 ` Pedro Alves
2017-10-04 14:32   ` Simon Marchi
2017-10-04 14:42     ` Pedro Alves
2017-10-04 16:01       ` Simon Marchi
2017-10-04 16:13         ` Pedro Alves
2017-10-04 16:31           ` [PATCH v3] " Simon Marchi
2017-10-04 16:38             ` Pedro Alves
2017-10-04 16:45               ` Simon Marchi
2017-10-04 16:31           ` [PATCH] " Simon Marchi

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).