This test causes several timeouts for Clang, taking too long time to finish. The reason is, for an infinite loop of the form while(1); /* suppose this is line 30. */ Clang generates code that looks like 0x00000000004004d4 <+4>: jmp 0x4004d9 <loop+9> 0x00000000004004d9 <+9>: jmp 0x4004d9 <loop+9> So, the real loop is the instruction at address 0x4004d9. But a breakpoint that's defined at the loop line (assume line 30 in this case) is inserted at address 0x4004d4. (gdb) break 30 Breakpoint 1 at 0x4004d4: file test.c, line 30. Therefore, continuing a thread that was spinning on the loop does not hit the breakpoint. The bug is reported at https://bugs.llvm.org/show_bug.cgi?id=49614 Tweak the infinite loop to spin on a variable to avoid this bug. The test is unrelated to the bug. gdb/testsuite/ChangeLog: 2021-03-29 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> * gdb.mi/user-selected-context-sync.exp: Spin on a variable in the infinite loop to avoid a Clang bug.
70 lines
1.8 KiB
C
70 lines
1.8 KiB
C
/* This testcase is part of GDB, the GNU debugger.
|
|
|
|
Copyright 2016-2021 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/>.
|
|
|
|
*/
|
|
|
|
#include <pthread.h>
|
|
#include <unistd.h>
|
|
|
|
#define NUM_THREADS 2
|
|
|
|
static pthread_barrier_t barrier;
|
|
|
|
static void
|
|
child_sub_function (void)
|
|
{
|
|
/* Deliberately spin on a variable instead of plain 'while (1)' to
|
|
avoid the Clang bug https://bugs.llvm.org/show_bug.cgi?id=49614. */
|
|
int spin = 1;
|
|
while (spin); /* thread loop line */
|
|
}
|
|
|
|
static void *
|
|
child_function (void *args)
|
|
{
|
|
pthread_barrier_wait (&barrier);
|
|
|
|
child_sub_function (); /* thread caller line */
|
|
|
|
return NULL;
|
|
}
|
|
|
|
int
|
|
main (void)
|
|
{
|
|
int i = 0;
|
|
pthread_t threads[NUM_THREADS];
|
|
|
|
/* Make the test exit eventually. */
|
|
alarm (20);
|
|
|
|
/* Initialize the barrier, NUM_THREADS plus the main thread. */
|
|
pthread_barrier_init (&barrier, NULL, NUM_THREADS + 1);
|
|
|
|
for (i = 0; i < NUM_THREADS; i++)
|
|
pthread_create (&threads[i], NULL, child_function, NULL);
|
|
|
|
pthread_barrier_wait (&barrier);
|
|
|
|
/* Deliberately spin on a variable instead of plain 'while (1)' to
|
|
avoid the Clang bug https://bugs.llvm.org/show_bug.cgi?id=49614. */
|
|
int spin = 1;
|
|
while (spin); /* main break line */
|
|
|
|
return 0;
|
|
}
|