From 4c71c1059f876fcca9809f7b6372b721ddb83635 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 4 Oct 2017 12:44:01 -0400 Subject: [PATCH] Fix -list-thread-groups --available logic and add test 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/ChangeLog | 4 ++ gdb/mi/mi-main.c | 2 +- gdb/testsuite/ChangeLog | 5 ++ .../gdb.mi/list-thread-groups-available.c | 29 ++++++++ .../gdb.mi/list-thread-groups-available.exp | 72 +++++++++++++++++++ 5 files changed, 111 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/ChangeLog b/gdb/ChangeLog index 87f84ca3120..37d86aee9e6 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2017-10-04 Simon Marchi + + * mi/mi-main.c (list_available_thread_groups): Reverse filter logic. + 2017-10-04 Pedro Alves * guile/scm-breakpoint.c (gdbscm_breakpoint_commands): Move code diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index 83b1fcf5322..289445f8324 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -801,7 +801,7 @@ list_available_thread_groups (const std::set &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/ChangeLog b/gdb/testsuite/ChangeLog index 2a580f4cb11..ddae8e015a4 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-10-04 Simon Marchi + + * gdb.mi/list-thread-groups-available.exp: New file. + * gdb.mi/list-thread-groups-available.c: New file. + 2017-10-04 Sergio Durigan Junior * gdb.base/set-cwd.exp: Make it available on 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 00000000000..56daec9663e --- /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 . */ + +#include + +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 00000000000..eea27b447ba --- /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 . + +# 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.30.2