From 326bf95fb5b5b92145d6b2aa30fc30cb7fcd2171 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Wed, 11 Jun 2025 23:35:57 +0100 Subject: [PATCH] New gdb.threads/continue-break-command.exp testcase Change-Id: Ie57493bb5032f28619db418d9d8068aae2d40b09 --- .../gdb.threads/continue-break-command.c | 94 +++++++++++++++++++ .../gdb.threads/continue-break-command.exp | 76 +++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 gdb/testsuite/gdb.threads/continue-break-command.c create mode 100644 gdb/testsuite/gdb.threads/continue-break-command.exp diff --git a/gdb/testsuite/gdb.threads/continue-break-command.c b/gdb/testsuite/gdb.threads/continue-break-command.c new file mode 100644 index 00000000000..78fabdc5d33 --- /dev/null +++ b/gdb/testsuite/gdb.threads/continue-break-command.c @@ -0,0 +1,94 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2025 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 . */ + +#include +#include +#include + +#define NUM_THREADS 3 + +static pthread_barrier_t threads_started_barrier; + +static pthread_barrier_t may_exit_barrier; + +static void * +thread_func (void *arg) +{ + /* Wait until all threads have started. */ + pthread_barrier_wait (&threads_started_barrier); + + /* Wait until the main thread lets us exit. */ + pthread_barrier_wait (&may_exit_barrier); + + return NULL; +} + +static void +threads_started (void) +{ +} + +static void +foo () +{ +} + +static void +bar () +{ +} + +int +main (void) +{ + pthread_t thread[NUM_THREADS]; + int i; + + alarm (30); + + pthread_barrier_init (&threads_started_barrier, NULL, NUM_THREADS + 1); + pthread_barrier_init (&may_exit_barrier, NULL, NUM_THREADS + 1); + + for (i = 0; i < NUM_THREADS; i++) + { + int ret; + + ret = pthread_create (&thread[i], NULL, thread_func, NULL); + assert (ret == 0); + } + + pthread_barrier_wait (&threads_started_barrier); + + threads_started (); + + /* The testcase sets breakpoints on these two, that when hit, are + removed. */ + foo (); + bar (); + + /* Call them again to make sure the breakpoints are really + deleted. */ + foo (); + bar (); + + pthread_barrier_wait (&may_exit_barrier); + + for (i = 0; i < NUM_THREADS; i++) + pthread_join (thread[i], NULL); + + return 0; +} diff --git a/gdb/testsuite/gdb.threads/continue-break-command.exp b/gdb/testsuite/gdb.threads/continue-break-command.exp new file mode 100644 index 00000000000..5f020425419 --- /dev/null +++ b/gdb/testsuite/gdb.threads/continue-break-command.exp @@ -0,0 +1,76 @@ +# Copyright 2025 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 . + +# XXX, some meaninful explanation here. + +standard_testfile .c + +if { [build_executable "failed to prepare" $testfile $srcfile \ + {debug pthreads}] \ + == -1 } { + return +} + +proc test {} { + clean_restart $::binfile + + if ![runto threads_started] { + return + } + + # Disable "[Thread 14192.0x3618 exited with code 0]" messages. + gdb_test_no_output "set print thread-events off" + + gdb_breakpoint "foo" message + gdb_test_multiple "commands" "command for foo" { + -re "End with" { + gdb_test \ + [multi_line_input \ + {silent} \ + {printf "Breakpoint hit #1.\n"} \ + {clear foo} \ + {continue} \ + {end}] \ + "" \ + $gdb_test_name + } + } + + gdb_breakpoint "bar" message + gdb_test_multiple "commands" "commands for bar" { + -re "End with" { + gdb_test \ + [multi_line_input \ + {silent} \ + {printf "Breakpoint hit #2.\n"} \ + {clear bar} \ + {continue} \ + {end}] \ + "" \ + $gdb_test_name + } + } + + gdb_test "info breakpoints" ".*" + + gdb_test_sequence "continue" "" \ + [list \ + "Continuing\\." \ + "^\r\nBreakpoint hit #1\\." \ + "^\r\nBreakpoint hit #2\\." \ + "^\r\n$::inferior_exited_re normally"] +} + +test base-commit: eb6c9310ee4d6cbde509d251fafb54ae45f5a5bf -- 2.49.0