]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/bp-permanent.c
GDB copyright headers update after running GDB's copyright.py script.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / bp-permanent.c
CommitLineData
618f726f 1/* Copyright (C) 2014-2016 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")
29#else
af48d08f 30#define NOP asm("nop")
0d7b2549 31#endif
af48d08f
PA
32
33/* Buffer holding the breakpoint instruction. */
34unsigned char buffer[16];
35
36volatile unsigned char *addr_bp;
37volatile unsigned char *addr_after_bp;
38int counter = 0;
39
40void
41test (void)
42{
43 NOP;
44 NOP;
45 NOP;
46 NOP; /* write permanent bp here */
47 NOP; /* after permanent bp */
48 NOP;
49 NOP;
50 NOP;
51 NOP;
52 NOP;
53
54 counter++;
55}
56
57void
58setup (void)
59{
60 memcpy (buffer, (void *) addr_bp, addr_after_bp - addr_bp);
61}
62
63void
64test_basics (void)
65{
66 test (); /* for SIGTRAP */
67 test (); /* for breakpoint once */
68 test (); /* for breakpoint twice */
69 test (); /* for disabled bp SIGTRAP */
70 test (); /* for breakpoint thrice */
71}
72
73void
74test_next (void)
75{
76 test (); /* for next */
77 counter = 0; /* after next */
78}
79
80#ifdef SIGNALS
81
82static void
83test_signal_handler (int sig)
84{
85}
86
87void
88test_signal_with_handler (void)
89{
90 signal (SIGUSR1, test_signal_handler);
91 test ();
92}
93
94void
95test_signal_no_handler (void)
96{
97 signal (SIGUSR1, SIG_IGN);
98 test ();
99}
100
101static void
102test_signal_nested_handler ()
103{
104 test ();
105}
106
107void
108test_signal_nested_done (void)
109{
110}
111
112void
113test_signal_nested (void)
114{
115 counter = 0;
116 signal (SIGALRM, test_signal_nested_handler);
117 alarm (1);
118 test ();
119 test_signal_nested_done ();
120}
121
122#endif
123
124int
125main (void)
126{
127 setup ();
128 test_basics ();
129 test_next ();
130#ifdef SIGNALS
131 test_signal_nested ();
132 test_signal_with_handler ();
133 test_signal_no_handler ();
134#endif
135 return 0;
136}