Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions arch/arc/core/fatal.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <toolchain.h>
#include <arch/cpu.h>
#include <misc/printk.h>
#include <logging/log_ctrl.h>

/**
*
Expand All @@ -35,6 +36,8 @@
*/
void _NanoFatalErrorHandler(unsigned int reason, const NANO_ESF *pEsf)
{
LOG_PANIC();

switch (reason) {
case _NANO_ERR_HW_EXCEPTION:
break;
Expand Down Expand Up @@ -83,6 +86,7 @@ void _NanoFatalErrorHandler(unsigned int reason, const NANO_ESF *pEsf)

FUNC_NORETURN void _arch_syscall_oops(void *ssf_ptr)
{
LOG_PANIC();
_SysFatalErrorHandler(_NANO_ERR_KERNEL_OOPS, ssf_ptr);
CODE_UNREACHABLE;
}
3 changes: 3 additions & 0 deletions arch/arc/core/fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <kernel_structs.h>
#include <misc/printk.h>
#include <exc_handle.h>
#include <logging/log_ctrl.h>

#ifdef CONFIG_USERSPACE
Z_EXC_DECLARE(z_arch_user_string_nlen);
Expand All @@ -42,6 +43,8 @@ void _Fault(NANO_ESF *esf)
u32_t exc_addr = _arc_v2_aux_reg_read(_ARC_V2_EFA);
u32_t ecr = _arc_v2_aux_reg_read(_ARC_V2_ECR);

LOG_PANIC();

#ifdef CONFIG_USERSPACE
for (int i = 0; i < ARRAY_SIZE(exceptions); i++) {
u32_t start = (u32_t)exceptions[i].start;
Expand Down
6 changes: 5 additions & 1 deletion arch/arm/core/fatal.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <kernel.h>
#include <kernel_structs.h>
#include <misc/printk.h>

#include <logging/log_ctrl.h>

/**
*
Expand Down Expand Up @@ -47,6 +47,8 @@
void _NanoFatalErrorHandler(unsigned int reason,
const NANO_ESF *pEsf)
{
LOG_PANIC();

switch (reason) {
case _NANO_ERR_HW_EXCEPTION:
printk("***** Hardware exception *****\n");
Expand Down Expand Up @@ -98,6 +100,8 @@ FUNC_NORETURN void _arch_syscall_oops(void *ssf_ptr)
u32_t *ssf_contents = ssf_ptr;
NANO_ESF oops_esf = { 0 };

LOG_PANIC();

oops_esf.pc = ssf_contents[3];

_do_kernel_oops(&oops_esf);
Expand Down
3 changes: 3 additions & 0 deletions arch/arm/core/fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <kernel_structs.h>
#include <inttypes.h>
#include <exc_handle.h>
#include <logging/log_ctrl.h>

#ifdef CONFIG_PRINTK
#include <misc/printk.h>
Expand Down Expand Up @@ -670,6 +671,8 @@ void _Fault(NANO_ESF *esf, u32_t exc_return)
u32_t reason;
int fault = SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk;

LOG_PANIC();

#if defined(CONFIG_ARM_SECURE_FIRMWARE)
if ((exc_return & EXC_RETURN_INDICATOR_PREFIX) !=
EXC_RETURN_INDICATOR_PREFIX) {
Expand Down
3 changes: 3 additions & 0 deletions arch/nios2/core/fatal.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <kernel_structs.h>
#include <misc/printk.h>
#include <inttypes.h>
#include <logging/log_ctrl.h>

const NANO_ESF _default_esf = {
0xdeadbaad,
Expand Down Expand Up @@ -50,6 +51,8 @@ const NANO_ESF _default_esf = {
FUNC_NORETURN void _NanoFatalErrorHandler(unsigned int reason,
const NANO_ESF *esf)
{
LOG_PANIC();

#ifdef CONFIG_PRINTK
switch (reason) {
case _NANO_ERR_CPU_EXCEPTION:
Expand Down
3 changes: 3 additions & 0 deletions arch/posix/core/fatal.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <kernel_structs.h>
#include <misc/printk.h>
#include <inttypes.h>
#include <logging/log_ctrl.h>
#include "posix_soc_if.h"

const NANO_ESF _default_esf = {
Expand All @@ -34,6 +35,8 @@ const NANO_ESF _default_esf = {
FUNC_NORETURN void _NanoFatalErrorHandler(unsigned int reason,
const NANO_ESF *esf)
{
LOG_PANIC();

#ifdef CONFIG_PRINTK
switch (reason) {
case _NANO_ERR_CPU_EXCEPTION:
Expand Down
5 changes: 5 additions & 0 deletions arch/riscv32/core/fatal.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <kernel_structs.h>
#include <inttypes.h>
#include <misc/printk.h>
#include <logging/log_ctrl.h>

const NANO_ESF _default_esf = {
0xdeadbaad,
Expand Down Expand Up @@ -60,6 +61,8 @@ const NANO_ESF _default_esf = {
FUNC_NORETURN void _NanoFatalErrorHandler(unsigned int reason,
const NANO_ESF *esf)
{
LOG_PANIC();

switch (reason) {
case _NANO_ERR_CPU_EXCEPTION:
case _NANO_ERR_SPURIOUS_INT:
Expand Down Expand Up @@ -135,6 +138,8 @@ FUNC_NORETURN __weak void _SysFatalErrorHandler(unsigned int reason,
{
ARG_UNUSED(esf);

LOG_PANIC();

#if !defined(CONFIG_SIMPLE_FATAL_ERROR_HANDLER)
#ifdef CONFIG_STACK_SENTINEL
if (reason == _NANO_ERR_STACK_CHK_FAIL) {
Expand Down
3 changes: 3 additions & 0 deletions arch/x86/core/fatal.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <exception.h>
#include <inttypes.h>
#include <exc_handle.h>
#include <logging/log_ctrl.h>

__weak void _debug_fatal_hook(const NANO_ESF *esf) { ARG_UNUSED(esf); }

Expand Down Expand Up @@ -83,6 +84,8 @@ static void unwind_stack(u32_t base_ptr)
FUNC_NORETURN void _NanoFatalErrorHandler(unsigned int reason,
const NANO_ESF *pEsf)
{
LOG_PANIC();

_debug_fatal_hook(pEsf);

#ifdef CONFIG_PRINTK
Expand Down
3 changes: 3 additions & 0 deletions arch/x86/core/sys_fatal_error_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <linker/sections.h>
#include <kernel_structs.h>
#include <misc/printk.h>
#include <logging/log_ctrl.h>

/**
*
Expand All @@ -43,6 +44,8 @@ FUNC_NORETURN __weak void _SysFatalErrorHandler(unsigned int reason,
{
ARG_UNUSED(pEsf);

LOG_PANIC();

#if !defined(CONFIG_SIMPLE_FATAL_ERROR_HANDLER)
#ifdef CONFIG_STACK_SENTINEL
if (reason == _NANO_ERR_STACK_CHK_FAIL) {
Expand Down
3 changes: 3 additions & 0 deletions arch/xtensa/core/fatal.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <kernel_arch_data.h>
#include <misc/printk.h>
#include <xtensa/specreg.h>
#include <logging/log_ctrl.h>

#ifdef XT_SIMULATOR
#include <xtensa/simcall.h>
Expand Down Expand Up @@ -51,6 +52,8 @@ const NANO_ESF _default_esf = {
XTENSA_ERR_NORET void _NanoFatalErrorHandler(unsigned int reason,
const NANO_ESF *pEsf)
{
LOG_PANIC();

switch (reason) {
case _NANO_ERR_HW_EXCEPTION:
case _NANO_ERR_RESERVED_IRQ:
Expand Down
6 changes: 4 additions & 2 deletions include/logging/log_ctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ void log_thread_set(k_tid_t process_tid);
int log_set_timestamp_func(timestamp_get_t timestamp_getter, u32_t freq);

/**
* @brief Switch logger subsystem to panic mode.
* @brief Switch the logger subsystem to the panic mode.
*
* @details On panic logger subsystem informs all backends about panic mode.
* Returns immediately if the logger is already in the panic mode.
*
* @details On panic the logger subsystem informs all backends about panic mode.
* Backends must switch to blocking mode or halt. All pending logs
* are flushed after switching to panic mode. In panic mode, all log
* messages must be processed in the context of the call.
Expand Down
4 changes: 4 additions & 0 deletions subsys/logging/log_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ void log_panic(void)
{
struct log_backend const *backend;

if (panic_mode) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortuantely there are many paths in error handling. So i see scenarios where one fault function which called log_panic will call another one and i don't want to multiple panic calls to backends. Note that we want to enter panic mode as soon as possible to get as much logs as possible (flush as early as possible).

return;
}

for (int i = 0; i < log_backend_count_get(); i++) {
backend = log_backend_get(i);

Expand Down