1 /* Copyright (C) 2014-2019 Free Software Foundation, Inc. 2 3 This file is part of GDB. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 3 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 18 #include <string.h> 19 #ifdef SIGNALS 20 #include <signal.h> 21 #include <unistd.h> 22 #endif 23 24 /* NOP instruction: must have the same size as the breakpoint 25 instruction. */ 26 27 #if defined(__s390__) || defined(__s390x__) 28 #define NOP asm("nopr 0") 29 #elif defined(__or1k__) 30 #define NOP asm("l.nop") 31 #else 32 #define NOP asm("nop") 33 #endif 34 35 /* Buffer holding the breakpoint instruction. */ 36 unsigned char buffer[16]; 37 38 volatile unsigned char *addr_bp; 39 volatile unsigned char *addr_after_bp; 40 int counter = 0; 41 42 void 43 test (void) 44 { 45 NOP; 46 NOP; 47 NOP; 48 NOP; /* write permanent bp here */ 49 NOP; /* after permanent bp */ 50 NOP; 51 NOP; 52 NOP; 53 NOP; 54 NOP; 55 56 counter++; 57 } 58 59 void 60 setup (void) 61 { 62 memcpy (buffer, (void *) addr_bp, addr_after_bp - addr_bp); 63 } 64 65 void 66 test_basics (void) 67 { 68 test (); /* for SIGTRAP */ 69 test (); /* for breakpoint once */ 70 test (); /* for breakpoint twice */ 71 test (); /* for disabled bp SIGTRAP */ 72 test (); /* for breakpoint thrice */ 73 } 74 75 void 76 test_next (void) 77 { 78 test (); /* for next */ 79 counter = 0; /* after next */ 80 } 81 82 #ifdef SIGNALS 83 84 static void 85 test_signal_handler (int sig) 86 { 87 } 88 89 void 90 test_signal_with_handler (void) 91 { 92 signal (SIGUSR1, test_signal_handler); 93 test (); 94 } 95 96 void 97 test_signal_no_handler (void) 98 { 99 signal (SIGUSR1, SIG_IGN); 100 test (); 101 } 102 103 static void 104 test_signal_nested_handler () 105 { 106 test (); 107 } 108 109 void 110 test_signal_nested_done (void) 111 { 112 } 113 114 void 115 test_signal_nested (void) 116 { 117 counter = 0; 118 signal (SIGALRM, test_signal_nested_handler); 119 alarm (1); 120 test (); 121 test_signal_nested_done (); 122 } 123 124 #endif 125 126 int 127 main (void) 128 { 129 setup (); 130 test_basics (); 131 test_next (); 132 #ifdef SIGNALS 133 test_signal_nested (); 134 test_signal_with_handler (); 135 test_signal_no_handler (); 136 #endif 137 return 0; 138 } 139