mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
esp_system: share abort panic with port layer
This commit is contained in:
parent
2855bb6f0a
commit
af9b1131a3
@ -2,7 +2,7 @@ SOC_NAME := $(IDF_TARGET)
|
||||
|
||||
COMPONENT_SRCDIRS := .
|
||||
COMPONENT_ADD_INCLUDEDIRS := include
|
||||
COMPONENT_PRIV_INCLUDEDIRS := private_include
|
||||
COMPONENT_PRIV_INCLUDEDIRS := private_include port/include
|
||||
COMPONENT_ADD_LDFRAGMENTS += linker.lf
|
||||
|
||||
-include $(COMPONENT_PATH)/port/$(SOC_NAME)/component.mk
|
@ -41,6 +41,7 @@
|
||||
#endif
|
||||
|
||||
#include "panic_internal.h"
|
||||
#include "port/panic_funcs.h"
|
||||
|
||||
#include "sdkconfig.h"
|
||||
|
||||
@ -50,8 +51,8 @@
|
||||
#define APPTRACE_ONPANIC_HOST_FLUSH_TMO (1000*CONFIG_APPTRACE_ONPANIC_HOST_FLUSH_TMO)
|
||||
#endif
|
||||
|
||||
static bool s_abort = false;
|
||||
static char *s_abort_details = NULL;
|
||||
bool g_panic_abort = false;
|
||||
static char *s_panic_abort_details = NULL;
|
||||
|
||||
#if !CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT
|
||||
|
||||
@ -144,7 +145,7 @@ static inline void disable_all_wdts(void)
|
||||
|
||||
static void print_abort_details(const void *f)
|
||||
{
|
||||
panic_print_str(s_abort_details);
|
||||
panic_print_str(s_panic_abort_details);
|
||||
}
|
||||
|
||||
// Control arrives from chip-specific panic handler, environment prepared for
|
||||
@ -153,10 +154,9 @@ static void print_abort_details(const void *f)
|
||||
void esp_panic_handler(panic_info_t *info)
|
||||
{
|
||||
// If the exception was due to an abort, override some of the panic info
|
||||
if (s_abort) {
|
||||
if (g_panic_abort) {
|
||||
info->description = NULL;
|
||||
info->details = s_abort_details ? print_abort_details : NULL;
|
||||
info->state = NULL; // do not display state, since it is not a 'real' crash
|
||||
info->details = s_panic_abort_details ? print_abort_details : NULL;
|
||||
info->reason = "SoftwareAbort";
|
||||
info->exception = PANIC_EXCEPTION_ABORT;
|
||||
}
|
||||
@ -304,7 +304,7 @@ void esp_panic_handler(panic_info_t *info)
|
||||
}
|
||||
|
||||
panic_print_str("Rebooting...\r\n");
|
||||
esp_restart_noos();
|
||||
panic_restart();
|
||||
#else
|
||||
disable_all_wdts();
|
||||
panic_print_str("CPU halted.\r\n");
|
||||
@ -315,8 +315,8 @@ void esp_panic_handler(panic_info_t *info)
|
||||
|
||||
void __attribute__((noreturn)) panic_abort(const char *details)
|
||||
{
|
||||
s_abort = true;
|
||||
s_abort_details = (char*) details;
|
||||
g_panic_abort = true;
|
||||
s_panic_abort_details = (char*) details;
|
||||
|
||||
#if CONFIG_APPTRACE_ENABLE
|
||||
#if CONFIG_SYSVIEW_ENABLE
|
||||
|
@ -12,4 +12,6 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
void __attribute__((noreturn)) panic_restart(void);
|
@ -233,6 +233,15 @@ static void print_registers(const void *f, int core)
|
||||
}
|
||||
}
|
||||
|
||||
static void print_state_for_core(const void *f, int core)
|
||||
{
|
||||
if (!g_panic_abort) {
|
||||
print_registers(f, core);
|
||||
panic_print_str("\r\n");
|
||||
}
|
||||
print_backtrace(f, core);
|
||||
}
|
||||
|
||||
static void print_state(const void* f)
|
||||
{
|
||||
#if !CONFIG_FREERTOS_UNICORE
|
||||
@ -241,9 +250,8 @@ static void print_state(const void* f)
|
||||
int err_core = 0;
|
||||
#endif
|
||||
|
||||
print_registers(f, err_core);
|
||||
panic_print_str("\r\n");
|
||||
print_backtrace(f, err_core);
|
||||
print_state_for_core(f, err_core);
|
||||
|
||||
panic_print_str("\r\n");
|
||||
|
||||
#if !CONFIG_FREERTOS_UNICORE
|
||||
@ -251,10 +259,8 @@ static void print_state(const void* f)
|
||||
for (int i = 0; i < SOC_CPU_CORES_NUM; i++) {
|
||||
// `f` is the frame for the offending core, see note above.
|
||||
if (err_core != i && xt_exc_frames[i] != NULL) {
|
||||
print_state_for_core(xt_exc_frames[i], i);
|
||||
panic_print_str("\r\n");
|
||||
print_registers(xt_exc_frames[i], i);
|
||||
panic_print_str("\r\n");
|
||||
print_backtrace(xt_exc_frames[i], i);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -16,8 +16,12 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "port/panic_funcs.h"
|
||||
|
||||
#include "sdkconfig.h"
|
||||
|
||||
extern bool g_panic_abort;
|
||||
|
||||
// Function to print longer amounts of information such as the details
|
||||
// and backtrace field of panic_info_t. These functions should limit themselves
|
||||
// to printing to the console and should do other more involved processing,
|
||||
|
@ -21,25 +21,26 @@
|
||||
|
||||
void __attribute__((noreturn)) abort(void)
|
||||
{
|
||||
#define ERR_STR1 "abort() was called at PC 0x"
|
||||
#define ERR_STR2 " on core "
|
||||
|
||||
#define ERR_STR1 "abort() was called at PC 0x"
|
||||
#define ERR_STR2 " on core "
|
||||
|
||||
_Static_assert(UINTPTR_MAX == 0xffffffff, "abort() assumes 32-bit addresses");
|
||||
_Static_assert(SOC_CPU_CORES_NUM < 10, "abort() assumes number of cores is 1 to 9");
|
||||
|
||||
|
||||
char addr_buf[9] = { 0 };
|
||||
char core_buf[2] = { 0 };
|
||||
|
||||
|
||||
char buf[sizeof(ERR_STR1) + sizeof(addr_buf) + sizeof(core_buf) + sizeof(ERR_STR2) + 1 /* null char */] = { 0 };
|
||||
|
||||
|
||||
itoa((uint32_t)(__builtin_return_address(0) - 3), addr_buf, 16);
|
||||
itoa(cpu_ll_get_core_id(), core_buf, 10);
|
||||
|
||||
|
||||
const char *str[] = { ERR_STR1, addr_buf, ERR_STR2, core_buf };
|
||||
|
||||
char *dest = buf;
|
||||
|
||||
char *dest = buf;
|
||||
for (int i = 0; i < sizeof(str) / sizeof(str[0]); i++) {
|
||||
strcat(dest, str[i]);
|
||||
strcat(dest, str[i]);
|
||||
}
|
||||
|
||||
esp_system_abort(buf);
|
||||
|
Loading…
x
Reference in New Issue
Block a user