1 1.1 christos /* This testcase is part of GDB, the GNU debugger. 2 1.1 christos 3 1.1.1.6 christos Copyright 2015-2024 Free Software Foundation, Inc. 4 1.1 christos 5 1.1 christos This program is free software; you can redistribute it and/or modify 6 1.1 christos it under the terms of the GNU General Public License as published by 7 1.1 christos the Free Software Foundation; either version 3 of the License, or 8 1.1 christos (at your option) any later version. 9 1.1 christos 10 1.1 christos This program is distributed in the hope that it will be useful, 11 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 12 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 1.1 christos GNU General Public License for more details. 14 1.1 christos 15 1.1 christos You should have received a copy of the GNU General Public License 16 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 1.1 christos 18 1.1 christos #include <pthread.h> 19 1.1 christos #include <unistd.h> 20 1.1 christos #include "trace-common.h" 21 1.1 christos 22 1.1 christos /* Called if the testcase failed. */ 23 1.1 christos static void 24 1.1 christos fail (void) 25 1.1 christos { 26 1.1 christos } 27 1.1 christos 28 1.1 christos static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; 29 1.1 christos 30 1.1 christos /* This function overrides gdb_collect in the in-process agent library. 31 1.1 christos See gdbserver/tracepoint.c (gdb_collect). We want this function to 32 1.1 christos be ran instead of the one from the library to easily check that only 33 1.1 christos one thread is tracing at a time. 34 1.1 christos 35 1.1 christos This works as expected because GDBserver will ask GDB about symbols 36 1.1 christos present in the inferior with the 'qSymbol' packet. And GDB will 37 1.1 christos reply with the address of this function instead of the one from the 38 1.1 christos in-process agent library. */ 39 1.1 christos 40 1.1 christos void 41 1.1 christos gdb_agent_gdb_collect (void *tpoint, unsigned char *regs) 42 1.1 christos { 43 1.1 christos /* If we cannot acquire a lock, then this means another thread is 44 1.1 christos tracing and the lock implemented by the jump pad is not working! */ 45 1.1 christos if (pthread_mutex_trylock (&mutex) != 0) 46 1.1 christos { 47 1.1 christos fail (); 48 1.1 christos return; 49 1.1 christos } 50 1.1 christos 51 1.1 christos sleep (1); 52 1.1 christos 53 1.1 christos if (pthread_mutex_unlock (&mutex) != 0) 54 1.1 christos { 55 1.1 christos fail (); 56 1.1 christos return; 57 1.1 christos } 58 1.1 christos } 59 1.1 christos 60 1.1 christos static void * 61 1.1 christos thread_function (void *arg) 62 1.1 christos { 63 1.1 christos FAST_TRACEPOINT_LABEL(set_point); 64 1.1 christos } 65 1.1 christos 66 1.1 christos static void 67 1.1 christos end (void) 68 1.1 christos { 69 1.1 christos } 70 1.1 christos 71 1.1 christos int 72 1.1 christos main (int argc, char *argv[], char *envp[]) 73 1.1 christos { 74 1.1 christos pthread_t threads[NUM_THREADS]; 75 1.1 christos int i; 76 1.1 christos 77 1.1 christos for (i = 0; i < NUM_THREADS; i++) 78 1.1 christos pthread_create (&threads[i], NULL, thread_function, NULL); 79 1.1 christos 80 1.1 christos for (i = 0; i < NUM_THREADS; i++) 81 1.1 christos pthread_join (threads[i], NULL); 82 1.1 christos 83 1.1 christos end (); 84 1.1 christos 85 1.1 christos return 0; 86 1.1 christos } 87