arch: posix: break debugger on fatal error
Add option to raise a SIGTRAP on fatal error, making the debugger break instead of exiting. Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
This commit is contained in:
parent
05a335dcba
commit
05cc2f37a3
4 changed files with 32 additions and 0 deletions
|
@ -57,4 +57,10 @@ config ARCH_POSIX_FUZZ_TICKS
|
|||
|
||||
endif # CONFIG_ARCH_POSIX_LIBFUZZER
|
||||
|
||||
config ARCH_POSIX_TRAP_ON_FATAL
|
||||
bool "Raise a SIGTRAP on fatal error"
|
||||
help
|
||||
Raise a SIGTRAP signal on fatal error before exiting.
|
||||
This automatically suspends the target if a debugger is attached.
|
||||
|
||||
endmenu
|
||||
|
|
|
@ -10,6 +10,14 @@ zephyr_library_sources(
|
|||
thread.c
|
||||
)
|
||||
|
||||
if(CONFIG_ARCH_POSIX_TRAP_ON_FATAL)
|
||||
if(CONFIG_NATIVE_LIBRARY)
|
||||
target_sources(native_simulator INTERFACE fatal_trap.c)
|
||||
else()
|
||||
zephyr_library_sources(fatal_trap.c)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CONFIG_NATIVE_APPLICATION)
|
||||
zephyr_include_directories(
|
||||
nsi_compat/
|
||||
|
|
|
@ -13,10 +13,16 @@
|
|||
#include <zephyr/logging/log_ctrl.h>
|
||||
#include <zephyr/arch/posix/posix_soc_if.h>
|
||||
|
||||
extern void nsi_raise_sigtrap(void);
|
||||
|
||||
FUNC_NORETURN void arch_system_halt(unsigned int reason)
|
||||
{
|
||||
ARG_UNUSED(reason);
|
||||
|
||||
if (IS_ENABLED(CONFIG_ARCH_POSIX_TRAP_ON_FATAL)) {
|
||||
nsi_raise_sigtrap();
|
||||
}
|
||||
|
||||
posix_print_error_and_exit("Exiting due to fatal error\n");
|
||||
CODE_UNREACHABLE; /* LCOV_EXCL_LINE */
|
||||
}
|
||||
|
|
12
arch/posix/core/fatal_trap.c
Normal file
12
arch/posix/core/fatal_trap.c
Normal file
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
void nsi_raise_sigtrap(void)
|
||||
{
|
||||
raise(SIGTRAP);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue