So while coding a simple application via ESP-IDF on my ESP32-WROOM I encountered a problem with a stacktrace. The problem only reproduces when I remove a log from a specific area of code (but with at least one log everything it works). For the logging I use the dedicated macros ESP_LOGx (with a fflush(stdout) before and printfs the stacktrace still appears).
I can't figure it out why this happens. The message that is printed on the tty is the following one:
Code: Select all
Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x400d70d5 PS : 0x00060930 A0 : 0x800d6aba A1 : 0x3ffb9c90
A2 : 0x00000000 A3 : 0x00000001 A4 : 0x00000021 A5 : 0x00000022
A6 : 0x00000001 A7 : 0x00000021 A8 : 0x00fb9fb0 A9 : 0x3ffb9c40
A10 : 0x0000001f A11 : 0x3ffb9c90 A12 : 0x00000200 A13 : 0x3ffb9f58
A14 : 0x00ff0000 A15 : 0x0000000c SAR : 0x00000004 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00fb9fb4 LBEG : 0x4000c46c LEND : 0x4000c477 LCOUNT : 0x00000000
Backtrace: 0x400d70d2:0x3ffb9c90 0x400d6ab7:0x3ffb9fb0 0x40155cd7:0x3ffba0a0 0x40089c99:0x3ffba0d0
Source https://docs.espressif.com/projects/esp ... prohibited.If this address is something else (garbage value, not in 0x3fxxxxxx - 0x6xxxxxxx range), it likely means that the pointer used to access the data is either not initialized or has been corrupted.
The code:
Code: Select all
char buffer[BUFFER_SIZE];
esp_err_t result = ESP_FAIL;
int read_memory;
while ((read_memory = read(config->fd, buffer, 512)) > 0) { // needs to be greater then 0, because 0 means EOF
int current_char = 0;
int key_index = 0;
int value_index = 0;
char temp_key[KEY_MAX_LENGTH];
char temp_value[VALUE_MAX_LENGTH];
int compare_key_or_value = 0;
while (buffer[current_char] != WD_EOL && current_char < read_memory) { // we assume that the user will never add more than 19 chars in the key
if (compare_key_or_value == 0 && buffer[current_char] != WD_EQUAL_SIGN) {
ESP_LOGE(TAG, "HELLO1");
temp_key[key_index] = buffer[current_char];
current_char++; // it is more visible if done here, than in the array
key_index++;
continue;
}
if (buffer[current_char] == WD_EQUAL_SIGN) {
ESP_LOGE(TAG, "HELLO2");
temp_key[current_char] = '\0'; // nobody should write more then 19 char for the name of the key
if (strcmp(temp_key, key)) {
ESP_LOGE(TAG, "Here");
while (buffer[current_char++] != '\n' && current_char < read_memory);// consume until EOL, including EOL
memset(temp_key, 0, KEY_MAX_LENGTH);
memset(temp_value, 0, VALUE_MAX_LENGTH);
key_index = 0;
value_index = 0;
} else {
compare_key_or_value = 1;
current_char++;
}
continue;
}
if (compare_key_or_value == 1) {
ESP_LOGE(TAG, "HELLO3");
if (buffer[current_char + 1] == '\n') {
temp_value[value_index] = '\0';
ESP_LOGE(TAG, "HELLO4");
strncpy(value, temp_value, value_index);
result = ESP_OK;
memset(temp_key, 0, KEY_MAX_LENGTH);
memset(temp_value, 0, VALUE_MAX_LENGTH);
key_index = 0;
value_index = 0;
}
/* ***************************************
In this if I remove the logs the stacktrace occurs
**************************************** */
temp_value[value_index] = buffer[current_char];
//ESP_LOGE(TAG, "1.Cur char: %i, value index: %i", current_char, value_index);
current_char++;
//ESP_LOGE(TAG, "2.Cur char: %i, value index: %i", current_char, value_index);
value_index++;
//ESP_LOGE(TAG, "3.Cur char: %i, value index: %i", current_char, value_index);
/* ***************************************
End of section
**************************************** */
}
}
}
Thank you.