Hello!
We are trying to improve the in-production error handling for one of our products. In the past, we have always saved the LSB of the error code in the GPREGRET register, but that is not always enough information to characterize or solve complicated problems.
We have external eeprom and have confirmed that saving records to eeprom in our app_error_fault_handler function does not create any problems. The issue we are having is with getting the information that we need to effectively deal with the errors.
We know that when DEBUG=TRUE APP_ERROR_CHECK will call app_error_handler with the line number and filename magically obtained from the __LINE__ and __FILE__ macros, but when we build without DEBUG, these are not available. We would prefer to build without DEBUG=TRUE, both to keep the application size manageable and because we don't want most of the other effects of DEBUG=TRUE.
If we just change the definition of APP_ERROR_HANDLER so that it always calls app_error_handler instead of app_error_handler_bare it sort of gets us what we want, but the application still gets bloated with all the extra file paths.
#ifdef DEBUG #define APP_ERROR_HANDLER(ERR_CODE) \ do \ { \ app_error_handler((ERR_CODE), __LINE__, (uint8_t*) __FILE__); \ } while (0) #else #define APP_ERROR_HANDLER(ERR_CODE) \ do \ { \ app_error_handler((ERR_CODE), __LINE__, (uint8_t*) __FILE__); \ } while (0) #endif
What we would like to do is to save the address of the function containing the APP_ERROR_CHECK call so that we can look it up in the .map file when we get the log report.
I was hoping that we would be able to run __builtin_return_address(0) in app_error_handler_bare
void app_error_handler_bare(ret_code_t error_code)
{
error_info_t error_info =
{
.line_num = (uint32_t)__builtin_return_address(0),
.p_file_name = NULL,
.err_code = error_code,
};
app_error_fault_handler(NRF_FAULT_ID_SDK_ERROR, 0, (uint32_t)(&error_info));
UNUSED_VARIABLE(error_info);
}
to get the address of the thing that ran before it, but the address that I get doing that are all over the place. sometimes I get a different address for subsequent APP_ERROR_CHECK calls at the same location. Is there any way to reliably get the address of the function that called APP_ERROR_CHECK?
Relevant info: building with gcc using nrf5 sdk version 15.2
Thanks In advance