How to get rid of core dumps (or at least redirect them)

#1

Hi all,

During my investigation concerning ESP32 watchdog, I encountered the problem of the coredumps.
How can I suppress coredumps, or at least redirect them to an UART of my choice?

I have tried every combination with
CONFIG_ESP32_ENABLE_COREDUMP_TO_UART,
CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE and
CONFIG_ESP32_ENABLE_COREDUMP.
But either I could not compile anymore (version problem?) or it just did not work suppressing coredumps.
So, whatever I do, I get a coredump on UART0, which I must get rid of, because the module listening on this interface could be harmed.

Rolf

#2

Has anybody an idea??

#3

It might be useful to share your mos.yml file in case there is an error there somewhere causing the build vars not to be picked up

#4

The recommended approach is to use another UART for comms.
AFAIK you can redirect/suppress the log output with proper settings in your mos.yml, but that works once the system is up. A core dump is a response to an exception and the system may not be up, or even some logs may come from the IDF.
I’m not sure, I think I read 2.19.something redirects the IDF output (or something like that), so you might be lucky,
What I’ve seen done works for the regular logs, I don’t think it works for core dumps nor the first boot stages:

  - ["debug.stdout_uart", -1]
  - ["debug.stderr_uart", -1]
mgos_uart_set_dispatcher(0, your_serial_dispatcher, NULL /* arg */);

For control in a lower level, I can’t help.

#5

@klimbot:
Here my test sources. In mos.yml you can see the four blocks I have tested with comments.
(I tested it on a Olimex ESP-PoE hardware with a led at GPIO2)

@scaprile:
Unfortunately, your two lines do not help, the coredump is written anyway. I hoped so, too!

But as far as I have seen, the coredump is written by the ESP32 only, and not by the ESP8266. On the ESP32-System, I can take another Uart for the listening device, so it is no problem!

Thanks a lot for your inputs!
Rolf

mos.yml:

author: Rolf
description: FreeRTOS Watchdog Tests
version: 1.0

#platform: esp8266
platform: esp32

cxxflags: 
    #- "-DPLATFORM_ESP8266="
    - "-DPLATFORM_ESP32="

sources:
  - src

#######################################################################################
## Tests for suppress core dumps:
  
## Test 1: Not compilable: "undefined reference to 'mgos_freertos_extract_regs' ..." ???
#build_vars:
#  ESP_IDF_SDKCONFIG_OPTS: >
#    ${build_vars.ESP_IDF_SDKCONFIG_OPTS}
#    CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE=y  

## Test 2: Compilable but no effect, coredump is sent anyway:  
#build_vars:
#  ESP_IDF_SDKCONFIG_OPTS: >
#    ${build_vars.ESP_IDF_SDKCONFIG_OPTS}
#    CONFIG_ESP32_ENABLE_COREDUMP_TO_UART=
#    CONFIG_ESP32_ENABLE_COREDUMP=n  
  
## Test 3: Compilable but no effect, coredump is sent anyway:  
#build_vars:
#  ESP_IDF_SDKCONFIG_OPTS: >
#    ${build_vars.ESP_IDF_SDKCONFIG_OPTS}
#    CONFIG_ESP32_ENABLE_COREDUMP_TO_UART=1
#    CONFIG_ESP32_ENABLE_COREDUMP=n  
  
## Test 4: Compilable but no effect, coredump is sent anyway:  
#build_vars:
#  ESP_IDF_SDKCONFIG_OPTS: >
#    ${build_vars.ESP_IDF_SDKCONFIG_OPTS}
#    CONFIG_ESP32_ENABLE_COREDUMP_TO_UART=n
#    CONFIG_ESP32_ENABLE_COREDUMP=n  

#######################################################################################
  
config_schema:
  - ["debug.stdout_uart", -1]
  - ["debug.stderr_uart", -1]     
 #- ["sys.wdt_timeout", "i", 10, {title: "Watchdog timeout seconds (default value = 30 (?))"}]

manifest_version: 2017-05-18
libs_version: ${mos_version}
modules_version: ${mos_version}
mongoose_os_version: ${mos_version}

main.cpp:

#include "mgos.h"
#if defined(PLATFORM_ESP32)
	#include "FreeRTOS.h"
#endif

// ESP32-Olimex-PoE with led on Gpio2:
#if defined(PLATFORM_ESP32)
	#define LED_PIN 2
#endif
// ESP8266-NodeMcuV2 with led on Gpio16:
#if defined(PLATFORM_ESP8266)
	#define LED_PIN 16
#endif

#define WDT_CHECK_TIME_ms 1000

//---------------------------------------------------------
static void wdtFunction(void* pArg)
//---------------------------------------------------------
{
    #if defined(PLATFORM_ESP32)
		mgos_wdt_set_timeout(10); // Optional! (Overwrites the 'sys.wdt_timeout' in the yml-file, which has a default of 30 sec)
		mgos_wdt_enable();	      // Mandatory!
		//mgos_wdt_feed();        // Optional: No 'first feed' is necessary!

		TickType_t xLastWakeTime = xTaskGetTickCount();
		static int counter = 0;
		for(;;) {
			// Feed the watchdog for the first x loops (10 sec in this case!), stop afterwards to let watchdog bite:
			if ((counter++) < 10) {
				mgos_wdt_feed();
			}	
			// Delay:
			vTaskDelayUntil(&xLastWakeTime, WDT_CHECK_TIME_ms / portTICK_PERIOD_MS);
		}
	#endif
	#if defined(PLATFORM_ESP8266)
	static int counter = 0;
	// After the first x loops, stop the system (10 sec in this case!), to let watchdog bite:
	if ((counter++) > 10) {
		for (;;) {
		}
	}	
	#endif
}

//---------------------------------------------------------
void ledTimer_cb(void* arg)
//---------------------------------------------------------
{ 
	// Blink led:
	static bool bState = true;
	bState = !bState;
	mgos_gpio_write(LED_PIN, bState);
}

//---------------------------------------------------------
enum mgos_app_init_result mgos_app_init(void)
//---------------------------------------------------------
{
	#if defined(PLATFORM_ESP32)
		// Create extra watchdog task:
		xTaskCreate(wdtFunction, "WDT_TASK", 500, NULL, 1, NULL );
	#endif
	#if defined(PLATFORM_ESP8266)
		// Start timer for watchdog:
		mgos_set_timer(WDT_CHECK_TIME_ms, MGOS_TIMER_REPEAT, wdtFunction, NULL);
	#endif
	// Set led pin to output:
	mgos_gpio_set_mode(LED_PIN, MGOS_GPIO_MODE_OUTPUT);
	// Start timer to blink led:
	mgos_set_timer(100, MGOS_TIMER_REPEAT, ledTimer_cb, NULL);
	// Return success:
	return MGOS_APP_INIT_SUCCESS;
}
#6

I’m not an 8266 fan (or acquaintant), I believe it has a second UART but definitely it has a second pair of pins. You may connect to the second UART or to the second set of pins, and enable them when your application starts.

#7

Not sure why you are getting an error with “Test 1” but it compiles fine for me.
I did some mucking around a while back to add Espressif sources to my build path so maybe thats it?

ignore this, I was wrong

#8

Since 2.19.0 Mongoose OS uses esp-idf (4.2-r1) and mgos_freertos_extract_regs definition is protected by CONFIG_ESP32_ENABLE_COREDUMP_TO_UART.

In previous versions there was simply a #if 1.

#9

This means that ‘CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE=y’ is not possible anymore since version 2.19.0, if I understand your statement correctly, @nliviu?

As I mentionned, this is finally no problem for me, because on the ESP32 I can use another uart and on ESP8266 there is no coredump.

Thanks a lot for your inputs!
Rolf

#10

Yes, no

CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE=y