| 1 | # Copyright 1999-2022 Free Software Foundation, Inc. |
| 2 | |
| 3 | # This program is free software; you can redistribute it and/or modify |
| 4 | # it under the terms of the GNU General Public License as published by |
| 5 | # the Free Software Foundation; either version 3 of the License, or |
| 6 | # (at your option) any later version. |
| 7 | # |
| 8 | # This program is distributed in the hope that it will be useful, |
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | # GNU General Public License for more details. |
| 12 | # |
| 13 | # You should have received a copy of the GNU General Public License |
| 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | |
| 16 | load_lib mi-support.exp |
| 17 | set MIFLAGS "-i=mi" |
| 18 | |
| 19 | standard_testfile |
| 20 | |
| 21 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { |
| 22 | untested "failed to compile" |
| 23 | return -1 |
| 24 | } |
| 25 | |
| 26 | proc test_list_thread_groups { } { |
| 27 | global hex |
| 28 | global decimal |
| 29 | global binfile |
| 30 | |
| 31 | mi_clean_restart |
| 32 | |
| 33 | # Before any run, exit-code should not be present. |
| 34 | mi_gdb_test \ |
| 35 | "122-list-thread-groups" \ |
| 36 | "122\\^done,groups=\\\[\{id=\"i1\",type=\"process\"\}\]" \ |
| 37 | "-list-thread-groups before run shows no exit-code" |
| 38 | |
| 39 | mi_clean_restart $binfile |
| 40 | |
| 41 | with_test_prefix "first run" { |
| 42 | mi_runto_main |
| 43 | |
| 44 | # During the run, exit-code should not be present. |
| 45 | mi_gdb_test \ |
| 46 | "123-list-thread-groups" \ |
| 47 | "123\\^done,groups=\\\[\{id=\"i1\",type=\"process\",pid=\"$decimal\",executable=\".*\".*" \ |
| 48 | "-list-thread-groups during run shows no exit-code" |
| 49 | |
| 50 | # Exit the inferior. |
| 51 | mi_send_resuming_command "exec-continue" "continuing to inferior exit" |
| 52 | mi_expect_stop "exited-normally" "" "" "" "" "" "exit normally" |
| 53 | |
| 54 | # After the run, exit-code should be present. |
| 55 | mi_gdb_test \ |
| 56 | "124-list-thread-groups" \ |
| 57 | "124\\^done,groups=\\\[\{id=\"i1\",type=\"process\",exit-code=\"0\",executable=\".*\"\}\]" \ |
| 58 | "-list-thread-groups after exit shows exit-code" |
| 59 | } |
| 60 | |
| 61 | with_test_prefix "second run" { |
| 62 | mi_runto_main |
| 63 | |
| 64 | # Write the exit code we want in the global var |
| 65 | mi_gdb_test "set var exit_code = 8" ".*\\^done" "write exit code" |
| 66 | |
| 67 | # During the second run, exit-code should not be present. |
| 68 | mi_gdb_test \ |
| 69 | "125-list-thread-groups" \ |
| 70 | "125\\^done,groups=\\\[\{id=\"i1\",type=\"process\",pid=\"$decimal\",executable=\".*\".*" \ |
| 71 | "-list-thread-groups during run shows no exit-code" |
| 72 | |
| 73 | # Exit the inferior. |
| 74 | mi_send_resuming_command "exec-continue" "continuing to inferior exit" |
| 75 | mi_expect_stop "exited" "" "" "" "" "" "exit with code" |
| 76 | |
| 77 | # After the second run, exit-code should be present. |
| 78 | mi_gdb_test \ |
| 79 | "126-list-thread-groups" \ |
| 80 | "126\\^done,groups=\\\[\{id=\"i1\",type=\"process\",exit-code=\"010\",executable=\".*\"\}\]" \ |
| 81 | "-list-thread-groups after exit shows exit-code" |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | test_list_thread_groups |
| 86 | |
| 87 | mi_gdb_exit |
| 88 | return 0 |