]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/rx/err.c
sim: set up build-time compiler settings
[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
21#include <stdio.h>
22#include <stdlib.h>
23
24#include "err.h"
25
26static unsigned char ee_actions[SIM_ERR_NUM_ERRORS];
27
28static enum execution_error last_error;
29
30static void
1c3e93a4 31ee_overrides (void)
4f8d4a38
DD
32{
33 /* GCC may initialize a bitfield by reading the uninitialized byte,
34 masking in the bitfield, and writing the byte back out. */
35 ee_actions[SIM_ERR_READ_UNWRITTEN_BYTES] = SIM_ERRACTION_IGNORE;
36 /* This breaks stack unwinding for exceptions because it leaves
37 MC_PUSHED_PC tags in the unwound stack frames. */
38 ee_actions[SIM_ERR_CORRUPT_STACK] = SIM_ERRACTION_IGNORE;
39}
40
41void
42execution_error_init_standalone (void)
43{
44 int i;
45
46 for (i = 0; i < SIM_ERR_NUM_ERRORS; i++)
47 ee_actions[i] = SIM_ERRACTION_EXIT;
48
49 ee_overrides ();
50}
51
52void
53execution_error_init_debugger (void)
54{
55 int i;
56
57 for (i = 0; i < SIM_ERR_NUM_ERRORS; i++)
58 ee_actions[i] = SIM_ERRACTION_DEBUG;
59
60 ee_overrides ();
61}
62
4f8d4a38
DD
63void
64execution_error_warn_all (void)
65{
66 int i;
67
68 for (i = 0; i < SIM_ERR_NUM_ERRORS; i++)
69 ee_actions[i] = SIM_ERRACTION_WARN;
70}
71
72void
73execution_error_ignore_all (void)
74{
75 int i;
76
77 for (i = 0; i < SIM_ERR_NUM_ERRORS; i++)
78 ee_actions[i] = SIM_ERRACTION_IGNORE;
79}
80
81void
82execution_error (enum execution_error num, unsigned long address)
83{
84 if (ee_actions[num] != SIM_ERRACTION_IGNORE)
85 last_error = num;
86
87 if (ee_actions[num] == SIM_ERRACTION_EXIT
88 || ee_actions[num] == SIM_ERRACTION_WARN)
89 {
90 switch (num)
91 {
92 case SIM_ERR_READ_UNWRITTEN_PAGES:
93 case SIM_ERR_READ_UNWRITTEN_BYTES:
94 printf("Read from unwritten memory at 0x%lx\n", address);
95 break;
96
97 case SIM_ERR_NULL_POINTER_DEREFERENCE:
98 printf ("NULL pointer dereference\n");
99 break;
100
101 case SIM_ERR_CORRUPT_STACK:
102 printf ("Stack corruption detected at 0x%lx\n", address);
103 break;
104
105 default:
106 printf ("Unknown execution error %d\n", num);
107 exit (1);
108 }
109 }
110
111 if (ee_actions[num] == SIM_ERRACTION_EXIT)
112 exit (1);
113}
114
115enum execution_error
116execution_error_get_last_error (void)
117{
118 return last_error;
119}
120
121void
122execution_error_clear_last_error (void)
123{
124 last_error = SIM_ERR_NONE;
125}
126
127void
128execution_error_set_action (enum execution_error num, enum execution_error_action act)
129{
130 ee_actions[num] = act;
131}