]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/rx/err.c
sim: switch config.h usage to defs.h
[thirdparty/binutils-gdb.git] / sim / rx / err.c
CommitLineData
4f8d4a38
DD
1/* err.c --- handle errors for RX simulator.
2
3666a048 3Copyright (C) 2008-2021 Free Software Foundation, Inc.
4f8d4a38
DD
4Contributed by Red Hat, Inc.
5
6This file is part of the GNU simulators.
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 3 of the License, or
11(at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
6df01ab8
MF
21/* This must come before any other includes. */
22#include "defs.h"
23
4f8d4a38
DD
24#include <stdio.h>
25#include <stdlib.h>
26
27#include "err.h"
28
29static unsigned char ee_actions[SIM_ERR_NUM_ERRORS];
30
31static enum execution_error last_error;
32
33static void
1c3e93a4 34ee_overrides (void)
4f8d4a38
DD
35{
36 /* GCC may initialize a bitfield by reading the uninitialized byte,
37 masking in the bitfield, and writing the byte back out. */
38 ee_actions[SIM_ERR_READ_UNWRITTEN_BYTES] = SIM_ERRACTION_IGNORE;
39 /* This breaks stack unwinding for exceptions because it leaves
40 MC_PUSHED_PC tags in the unwound stack frames. */
41 ee_actions[SIM_ERR_CORRUPT_STACK] = SIM_ERRACTION_IGNORE;
42}
43
44void
45execution_error_init_standalone (void)
46{
47 int i;
48
49 for (i = 0; i < SIM_ERR_NUM_ERRORS; i++)
50 ee_actions[i] = SIM_ERRACTION_EXIT;
51
52 ee_overrides ();
53}
54
55void
56execution_error_init_debugger (void)
57{
58 int i;
59
60 for (i = 0; i < SIM_ERR_NUM_ERRORS; i++)
61 ee_actions[i] = SIM_ERRACTION_DEBUG;
62
63 ee_overrides ();
64}
65
4f8d4a38
DD
66void
67execution_error_warn_all (void)
68{
69 int i;
70
71 for (i = 0; i < SIM_ERR_NUM_ERRORS; i++)
72 ee_actions[i] = SIM_ERRACTION_WARN;
73}
74
75void
76execution_error_ignore_all (void)
77{
78 int i;
79
80 for (i = 0; i < SIM_ERR_NUM_ERRORS; i++)
81 ee_actions[i] = SIM_ERRACTION_IGNORE;
82}
83
84void
85execution_error (enum execution_error num, unsigned long address)
86{
87 if (ee_actions[num] != SIM_ERRACTION_IGNORE)
88 last_error = num;
89
90 if (ee_actions[num] == SIM_ERRACTION_EXIT
91 || ee_actions[num] == SIM_ERRACTION_WARN)
92 {
93 switch (num)
94 {
95 case SIM_ERR_READ_UNWRITTEN_PAGES:
96 case SIM_ERR_READ_UNWRITTEN_BYTES:
97 printf("Read from unwritten memory at 0x%lx\n", address);
98 break;
99
100 case SIM_ERR_NULL_POINTER_DEREFERENCE:
101 printf ("NULL pointer dereference\n");
102 break;
103
104 case SIM_ERR_CORRUPT_STACK:
105 printf ("Stack corruption detected at 0x%lx\n", address);
106 break;
107
108 default:
109 printf ("Unknown execution error %d\n", num);
110 exit (1);
111 }
112 }
113
114 if (ee_actions[num] == SIM_ERRACTION_EXIT)
115 exit (1);
116}
117
118enum execution_error
119execution_error_get_last_error (void)
120{
121 return last_error;
122}
123
124void
125execution_error_clear_last_error (void)
126{
127 last_error = SIM_ERR_NONE;
128}
129
130void
131execution_error_set_action (enum execution_error num, enum execution_error_action act)
132{
133 ee_actions[num] = act;
134}