Update copyright year range in all GDB files.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / bp-permanent.c
CommitLineData
42a4f53d 1/* Copyright (C) 2014-2019 Free Software Foundation, Inc.
af48d08f
PA
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>
a267f3ad 21#include <unistd.h>
af48d08f
PA
22#endif
23
0d7b2549
AA
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")
c3d18620
SH
29#elif defined(__or1k__)
30#define NOP asm("l.nop")
0d7b2549 31#else
af48d08f 32#define NOP asm("nop")
0d7b2549 33#endif
af48d08f
PA
34
35/* Buffer holding the breakpoint instruction. */
36unsigned char buffer[16];
37
38volatile unsigned char *addr_bp;
39volatile unsigned char *addr_after_bp;
40int counter = 0;
41
42void
43test (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
59void
60setup (void)
61{
62 memcpy (buffer, (void *) addr_bp, addr_after_bp - addr_bp);
63}
64
65void
66test_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
75void
76test_next (void)
77{
78 test (); /* for next */
79 counter = 0; /* after next */
80}
81
82#ifdef SIGNALS
83
84static void
85test_signal_handler (int sig)
86{
87}
88
89void
90test_signal_with_handler (void)
91{
92 signal (SIGUSR1, test_signal_handler);
93 test ();
94}
95
96void
97test_signal_no_handler (void)
98{
99 signal (SIGUSR1, SIG_IGN);
100 test ();
101}
102
103static void
104test_signal_nested_handler ()
105{
106 test ();
107}
108
109void
110test_signal_nested_done (void)
111{
112}
113
114void
115test_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
126int
127main (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}
This page took 0.898678 seconds and 4 git commands to generate.