1 /* err.c --- handle errors for RX simulator.
3 Copyright (C) 2008-2024 Free Software Foundation, Inc.
4 Contributed by Red Hat, Inc.
6 This file is part of the GNU simulators.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 /* This must come before any other includes. */
29 static unsigned char ee_actions
[SIM_ERR_NUM_ERRORS
];
31 static enum execution_error last_error
;
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
;
45 execution_error_init_standalone (void)
49 for (i
= 0; i
< SIM_ERR_NUM_ERRORS
; i
++)
50 ee_actions
[i
] = SIM_ERRACTION_EXIT
;
56 execution_error_init_debugger (void)
60 for (i
= 0; i
< SIM_ERR_NUM_ERRORS
; i
++)
61 ee_actions
[i
] = SIM_ERRACTION_DEBUG
;
67 execution_error_warn_all (void)
71 for (i
= 0; i
< SIM_ERR_NUM_ERRORS
; i
++)
72 ee_actions
[i
] = SIM_ERRACTION_WARN
;
76 execution_error_ignore_all (void)
80 for (i
= 0; i
< SIM_ERR_NUM_ERRORS
; i
++)
81 ee_actions
[i
] = SIM_ERRACTION_IGNORE
;
85 execution_error (enum execution_error num
, unsigned long address
)
87 if (ee_actions
[num
] != SIM_ERRACTION_IGNORE
)
90 if (ee_actions
[num
] == SIM_ERRACTION_EXIT
91 || ee_actions
[num
] == SIM_ERRACTION_WARN
)
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
);
100 case SIM_ERR_NULL_POINTER_DEREFERENCE
:
101 printf ("NULL pointer dereference\n");
104 case SIM_ERR_CORRUPT_STACK
:
105 printf ("Stack corruption detected at 0x%lx\n", address
);
109 printf ("Unknown execution error %d\n", num
);
114 if (ee_actions
[num
] == SIM_ERRACTION_EXIT
)
119 execution_error_get_last_error (void)
125 execution_error_clear_last_error (void)
127 last_error
= SIM_ERR_NONE
;
131 execution_error_set_action (enum execution_error num
, enum execution_error_action act
)
133 ee_actions
[num
] = act
;