Exemple #1
0
bool esp_core_dump_process_stack(core_dump_task_header_t* task_snaphort, uint32_t *length)
{
    uint32_t len = 0;
    bool task_is_valid = false;
    len = (uint32_t)task_snaphort->stack_end - (uint32_t)task_snaphort->stack_start;
    // Check task's stack
    if (!esp_stack_ptr_is_sane(task_snaphort->stack_start) ||
        !esp_task_stack_start_is_sane((uint32_t)task_snaphort->stack_end) ||
        (len > COREDUMP_MAX_TASK_STACK_SIZE)) {
        // Check if current task stack corrupted
        if (task_snaphort->tcb_addr == xTaskGetCurrentTaskHandleForCPU(xPortGetCoreID())) {
            ESP_COREDUMP_LOG_PROCESS("Crashed task will be skipped!");
        }
        ESP_COREDUMP_LOG_PROCESS("Corrupted TCB %x: stack len %lu, top %x, end %x!",
            task_snaphort->tcb_addr, len, task_snaphort->stack_start, task_snaphort->stack_end);
        task_snaphort->tcb_addr = 0; // make TCB addr invalid to skip it in dump
        task_is_valid = false;
    } else {
        ESP_COREDUMP_LOG_PROCESS("Stack len = %lu (%x %x)", len,
                task_snaphort->stack_start, task_snaphort->stack_end);
        // Take stack padding into account
        *length = (len + sizeof(uint32_t) - 1) & ~(sizeof(uint32_t) - 1);
        task_is_valid = true;
    }
    return task_is_valid;
}
Exemple #2
0
bool esp_core_dump_process_tcb(void *frame, core_dump_task_header_t *task_snaphort, uint32_t tcb_sz)
{
    XtExcFrame *exc_frame = (XtExcFrame*)frame;

    if (!esp_tcb_addr_is_sane((uint32_t)task_snaphort->tcb_addr, tcb_sz)) {
        ESP_COREDUMP_LOG_PROCESS("Bad TCB addr %x!", task_snaphort->tcb_addr);
        return false;
    }
    if (task_snaphort->tcb_addr == xTaskGetCurrentTaskHandleForCPU(xPortGetCoreID())) {
        // Set correct stack top for current task
        task_snaphort->stack_start = (uint32_t)exc_frame;
        // This field is not initialized for crashed task, but stack frame has the structure of interrupt one,
        // so make workaround to allow espcoredump to parse it properly.
        if (exc_frame->exit == 0)
            exc_frame->exit = -1;
        ESP_COREDUMP_LOG_PROCESS("Current task %x EXIT/PC/PS/A0/SP %x %x %x %x %x",
                task_snaphort->tcb_addr, exc_frame->exit, exc_frame->pc, exc_frame->ps, exc_frame->a0, exc_frame->a1);
    }
    else {
        XtSolFrame *task_frame = (XtSolFrame *)task_snaphort->stack_start;
        if (task_frame->exit == 0) {
                ESP_COREDUMP_LOG_PROCESS("Task %x EXIT/PC/PS/A0/SP %x %x %x %x %x",
                        task_snaphort->tcb_addr, task_frame->exit, task_frame->pc, task_frame->ps, task_frame->a0, task_frame->a1);
        }
        else {
#if CONFIG_ESP32_ENABLE_COREDUMP_TO_FLASH
                XtExcFrame *task_frame2 = (XtExcFrame *)task_snaphort->stack_start;
                ESP_COREDUMP_LOG_PROCESS("Task %x EXIT/PC/PS/A0/SP %x %x %x %x %x",
                        task_snaphort->tcb_addr, task_frame2->exit, task_frame2->pc, task_frame2->ps, task_frame2->a0, task_frame2->a1);
#endif
        }
    }
    return true;
}
Exemple #3
0
static void task_wdt_isr(void *arg) {
    wdt_task_t *wdttask;
    const char *cpu;
    //Feed the watchdog so we do not reset
    TIMERG0.wdt_wprotect=TIMG_WDT_WKEY_VALUE;
    TIMERG0.wdt_feed=1;
    TIMERG0.wdt_wprotect=0;
    //Ack interrupt
    TIMERG0.int_clr_timers.wdt=1;
    //We are taking a spinlock while doing I/O (ets_printf) here. Normally, that is a pretty
    //bad thing, possibly (temporarily) hanging up the 2nd core and stopping FreeRTOS. In this case,
    //something bad already happened and reporting this is considered more important
    //than the badness caused by a spinlock here.
    portENTER_CRITICAL(&taskwdt_spinlock);
    if (!wdt_task_list) {
        //No task on list. Maybe none registered yet.
        portEXIT_CRITICAL(&taskwdt_spinlock);
        return;
    }
    //Watchdog got triggered because at least one task did not report in.
    ets_printf("Task watchdog got triggered. The following tasks did not feed the watchdog in time:\n");
    for (wdttask=wdt_task_list; wdttask!=NULL; wdttask=wdttask->next) {
        if (!wdttask->fed_watchdog) {
            cpu=xTaskGetAffinity(wdttask->task_handle)==0?DRAM_STR("CPU 0"):DRAM_STR("CPU 1");
            if (xTaskGetAffinity(wdttask->task_handle)==tskNO_AFFINITY) cpu=DRAM_STR("CPU 0/1");
            ets_printf(" - %s (%s)\n", pcTaskGetTaskName(wdttask->task_handle), cpu);
        }
    }
    ets_printf(DRAM_STR("Tasks currently running:\n"));
    for (int x=0; x<portNUM_PROCESSORS; x++) {
        ets_printf("CPU %d: %s\n", x, pcTaskGetTaskName(xTaskGetCurrentTaskHandleForCPU(x)));
    }

#if CONFIG_TASK_WDT_PANIC
    ets_printf("Aborting.\n");
    abort();
#endif
    portEXIT_CRITICAL(&taskwdt_spinlock);
}