Limit error filename capture to 64 chars, wrapping tests with right configs and astyle fixes.

pull/7214/head
Senthil Ramakrishnan 2018-06-18 11:26:48 -05:00
parent dcdd616e6d
commit baa44eb3f2
5 changed files with 59 additions and 54 deletions

View File

@ -261,7 +261,7 @@ void test_error_hook()
TEST_ASSERT(sem_status > 0);
}
#ifdef MBED_TEST_SIM_BLOCKDEVICE
#if MBED_CONF_PLATFORM_ERROR_HIST_ENABLED && defined(MBED_TEST_SIM_BLOCKDEVICE)
// test configuration
#ifndef MBED_TEST_FILESYSTEM
@ -356,7 +356,7 @@ Case cases[] = {
#if MBED_CONF_RTOS_PRESENT
Case("Test error handling multi-threaded", test_error_logging_multithread),
#endif //MBED_CONF_RTOS_PRESENT
#ifdef MBED_TEST_SIM_BLOCKDEVICE
#if MBED_CONF_PLATFORM_ERROR_HIST_ENABLED && defined(MBED_TEST_SIM_BLOCKDEVICE)
Case("Test error save log", test_save_error_log),
#endif //MBED_TEST_SIM_BLOCKDEVICE
#endif //MBED_CONF_ERROR_HIST_DISABLED

View File

@ -33,7 +33,7 @@
#define GET_CURRENT_SP(sp) \
{ \
/*If in Handler mode we are always using MSP*/ \
if( __get_IPSR() != 0U ) { \
if ( __get_IPSR() != 0U ) { \
sp = __get_MSP(); \
} else { \
/*Look into CONTROL.SPSEL value*/ \
@ -95,7 +95,7 @@ static mbed_error_status_t handle_error(mbed_error_status_t error_status, unsign
mbed_error_ctx current_error_ctx;
//Error status should always be < 0
if(error_status >= 0) {
if (error_status >= 0) {
//This is a weird situation, someone called mbed_error with invalid error code.
//We will still handle the situation but change the error code to ERROR_INVALID_ARGUMENT, atleast the context will have info on who called it
error_status = MBED_ERROR_INVALID_ARGUMENT;
@ -141,7 +141,7 @@ static mbed_error_status_t handle_error(mbed_error_status_t error_status, unsign
#endif
//Capture the fist system error and store it
if(error_count == 1) { //first error
if (error_count == 1) { //first error
memcpy(&first_error_ctx, &current_error_ctx, sizeof(mbed_error_ctx));
}
@ -154,7 +154,7 @@ static mbed_error_status_t handle_error(mbed_error_status_t error_status, unsign
#endif
//Call the error hook if available
if(error_hook != NULL) {
if (error_hook != NULL) {
error_hook(&last_error_ctx);
}
@ -194,7 +194,7 @@ mbed_error_status_t mbed_warning(mbed_error_status_t error_status, const char *e
WEAK mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
{
//set the error reported and then halt the system
if( MBED_SUCCESS != handle_error(error_status, error_value, filename, line_number) )
if ( MBED_SUCCESS != handle_error(error_status, error_value, filename, line_number))
return MBED_ERROR_FAILED_OPERATION;
//On fatal errors print the error context/report
@ -208,7 +208,7 @@ WEAK mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char
mbed_error_status_t mbed_set_error_hook(mbed_error_hook_t error_hook_in)
{
//register the new hook/callback
if( error_hook_in != NULL ) {
if ( error_hook_in != NULL ) {
error_hook = error_hook_in;
return MBED_SUCCESS;
}
@ -236,17 +236,17 @@ mbed_error_status_t mbed_make_error(mbed_error_type_t error_type, mbed_module_ty
switch(error_type)
{
case MBED_ERROR_TYPE_POSIX:
if(error_code >= MBED_POSIX_ERROR_BASE && error_code <= MBED_SYSTEM_ERROR_BASE)
if (error_code >= MBED_POSIX_ERROR_BASE && error_code <= MBED_SYSTEM_ERROR_BASE)
return -error_code;
break;
case MBED_ERROR_TYPE_SYSTEM:
if(error_code >= MBED_SYSTEM_ERROR_BASE && error_code <= MBED_CUSTOM_ERROR_BASE)
if (error_code >= MBED_SYSTEM_ERROR_BASE && error_code <= MBED_CUSTOM_ERROR_BASE)
return MAKE_MBED_ERROR(MBED_ERROR_TYPE_SYSTEM, entity, error_code);
break;
case MBED_ERROR_TYPE_CUSTOM:
if(error_code >= MBED_CUSTOM_ERROR_BASE)
if (error_code >= MBED_CUSTOM_ERROR_BASE)
return MAKE_MBED_ERROR(MBED_ERROR_TYPE_CUSTOM, entity, error_code);
break;
@ -291,7 +291,7 @@ static void print_thread(osRtxThread_t *thread)
/* Prints thread info from a list */
static void print_threads_info(osRtxThread_t *threads)
{
while(threads != NULL) {
while (threads != NULL) {
print_thread( threads );
threads = threads->thread_next;
}
@ -347,7 +347,7 @@ static void print_error_report(mbed_error_ctx *ctx, const char *error_msg)
mbed_error_printf("\nLocation: 0x%X", ctx->error_address);
#if MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED && !defined(NDEBUG)
if((NULL != ctx->error_filename[0]) && (ctx->error_line_number != 0)) {
if ((NULL != ctx->error_filename[0]) && (ctx->error_line_number != 0)) {
//for string, we must pass address of a ptr which has the address of the string
mbed_error_printf("\nFile:%s+%d", ctx->error_filename, ctx->error_line_number);
}
@ -404,19 +404,19 @@ mbed_error_status_t mbed_save_error_hist(const char *path)
FILE *error_log_file = NULL;
//Ensure path is valid
if(path==NULL) {
if (path==NULL) {
ret = MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_INVALID_ARGUMENT);
goto exit;
}
//Open the file for saving the error log info
if((error_log_file = fopen( path, "w" ) ) == NULL){
if ((error_log_file = fopen( path, "w" )) == NULL){
ret = MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_OPEN_FAILED);
goto exit;
}
//First store the first and last errors
if(fprintf(error_log_file, "\nFirst Error: Status:0x%x ThreadId:0x%x Address:0x%x Value:0x%x\n",
if (fprintf(error_log_file, "\nFirst Error: Status:0x%x ThreadId:0x%x Address:0x%x Value:0x%x\n",
(unsigned int)first_error_ctx.error_status,
(unsigned int)first_error_ctx.thread_id,
(unsigned int)first_error_ctx.error_address,
@ -425,7 +425,7 @@ mbed_error_status_t mbed_save_error_hist(const char *path)
goto exit;
}
if(fprintf(error_log_file, "\nLast Error: Status:0x%x ThreadId:0x%x Address:0x%x Value:0x%x\n",
if (fprintf(error_log_file, "\nLast Error: Status:0x%x ThreadId:0x%x Address:0x%x Value:0x%x\n",
(unsigned int)last_error_ctx.error_status,
(unsigned int)last_error_ctx.thread_id,
(unsigned int)last_error_ctx.error_address,
@ -435,10 +435,10 @@ mbed_error_status_t mbed_save_error_hist(const char *path)
}
//Update with error log info
while(--log_count >= 0) {
while (--log_count >= 0) {
mbed_error_hist_get(log_count, &ctx);
//first line of file will be error log count
if(fprintf(error_log_file, "\n%d: Status:0x%x ThreadId:0x%x Address:0x%x Value:0x%x\n",
if (fprintf(error_log_file, "\n%d: Status:0x%x ThreadId:0x%x Address:0x%x Value:0x%x\n",
log_count,
(unsigned int)ctx.error_status,
(unsigned int)ctx.thread_id,

View File

@ -39,6 +39,13 @@ extern "C" {
#ifndef MBED_CONF_PLATFORM_MAX_ERROR_FILENAME_LEN
#define MBED_CONF_PLATFORM_MAX_ERROR_FILENAME_LEN 16
#else //MBED_CONF_PLATFORM_MAX_ERROR_FILENAME_LEN
#if MBED_CONF_PLATFORM_MAX_ERROR_FILENAME_LEN > 64
//We have to limit this to 64 bytes since we use mbed_error_printf for error reporting
//and mbed_error_vfprintf uses 128bytes internal buffer which may not be sufficient for anything
//longer that 64 bytes with the current implementation.
#error "Unsupported error filename buffer length detected, max supported length is 64 chars. Please change MBED_CONF_PLATFORM_MAX_ERROR_FILENAME_LEN or max-error-filename-len in configuration."
#endif
#endif
#define MBED_ERROR_STATUS_CODE_MASK (0x0000FFFF)
@ -144,16 +151,16 @@ typedef int mbed_error_status_t;
*
*/
#ifdef NDEBUG
#define MBED_WARNING1( error_status, error_msg, error_value ) mbed_warning( error_status, (const char *)NULL, (uint32_t)error_value, NULL, 0 )
#define MBED_WARNING( error_status, error_msg ) mbed_warning( error_status, (const char *)NULL, (uint32_t)0, NULL, 0 )
#else
#if MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED
#define MBED_WARNING1( error_status, error_msg, error_value ) mbed_warning( error_status, (const char *)error_msg, (uint32_t)error_value, (const char *)MBED_FILENAME, __LINE__ )
#define MBED_WARNING( error_status, error_msg ) mbed_warning( error_status, (const char *)error_msg, (uint32_t)0 , (const char *)MBED_FILENAME, __LINE__ )
#else
#define MBED_WARNING1( error_status, error_msg, error_value ) mbed_warning( error_status, (const char *)error_msg, (uint32_t)error_value, NULL, 0 )
#define MBED_WARNING( error_status, error_msg ) mbed_warning( error_status, (const char *)error_msg, (uint32_t)0, NULL, 0 )
#endif
#define MBED_WARNING1( error_status, error_msg, error_value ) mbed_warning( error_status, (const char *)NULL, (uint32_t)error_value, NULL, 0 )
#define MBED_WARNING( error_status, error_msg ) mbed_warning( error_status, (const char *)NULL, (uint32_t)0, NULL, 0 )
#else //NDEBUG
#if MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED
#define MBED_WARNING1( error_status, error_msg, error_value ) mbed_warning( error_status, (const char *)error_msg, (uint32_t)error_value, (const char *)MBED_FILENAME, __LINE__ )
#define MBED_WARNING( error_status, error_msg ) mbed_warning( error_status, (const char *)error_msg, (uint32_t)0 , (const char *)MBED_FILENAME, __LINE__ )
#else //MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED
#define MBED_WARNING1( error_status, error_msg, error_value ) mbed_warning( error_status, (const char *)error_msg, (uint32_t)error_value, NULL, 0 )
#define MBED_WARNING( error_status, error_msg ) mbed_warning( error_status, (const char *)error_msg, (uint32_t)0, NULL, 0 )
#endif
#endif
/**
@ -176,16 +183,16 @@ typedef int mbed_error_status_t;
*
*/
#ifdef NDEBUG
#define MBED_ERROR1( error_status, error_msg, error_value ) mbed_error( error_status, (const char *)NULL, (uint32_t)error_value, NULL, 0 )
#define MBED_ERROR( error_status, error_msg ) mbed_error( error_status, (const char *)NULL, (uint32_t)0 , NULL, 0 )
#else
#if MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED
#define MBED_ERROR1( error_status, error_msg, error_value ) mbed_error( error_status, (const char *)error_msg, (uint32_t)error_value, (const char *)MBED_FILENAME, __LINE__ )
#define MBED_ERROR( error_status, error_msg ) mbed_error( error_status, (const char *)error_msg, (uint32_t)0 , (const char *)MBED_FILENAME, __LINE__ )
#else
#define MBED_ERROR1( error_status, error_msg, error_value ) mbed_error( error_status, (const char *)error_msg, (uint32_t)error_value, NULL, 0 )
#define MBED_ERROR( error_status, error_msg ) mbed_error( error_status, (const char *)error_msg, (uint32_t)0 , NULL, 0 )
#endif
#define MBED_ERROR1( error_status, error_msg, error_value ) mbed_error( error_status, (const char *)NULL, (uint32_t)error_value, NULL, 0 )
#define MBED_ERROR( error_status, error_msg ) mbed_error( error_status, (const char *)NULL, (uint32_t)0 , NULL, 0 )
#else //NDEBUG
#if MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED
#define MBED_ERROR1( error_status, error_msg, error_value ) mbed_error( error_status, (const char *)error_msg, (uint32_t)error_value, (const char *)MBED_FILENAME, __LINE__ )
#define MBED_ERROR( error_status, error_msg ) mbed_error( error_status, (const char *)error_msg, (uint32_t)0 , (const char *)MBED_FILENAME, __LINE__ )
#else //MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED
#define MBED_ERROR1( error_status, error_msg, error_value ) mbed_error( error_status, (const char *)error_msg, (uint32_t)error_value, NULL, 0 )
#define MBED_ERROR( error_status, error_msg ) mbed_error( error_status, (const char *)error_msg, (uint32_t)0 , NULL, 0 )
#endif
#endif
//Error Type definition
@ -253,8 +260,7 @@ typedef enum _mbed_error_type_t
\endverbatim
*
*/
typedef enum _mbed_module_type
{
typedef enum _mbed_module_type {
MBED_MODULE_APPLICATION = 0,
MBED_MODULE_PLATFORM,
MBED_MODULE_KERNEL,
@ -566,8 +572,7 @@ typedef enum _mbed_module_type
\endverbatim
*/
typedef enum _mbed_error_code
{
typedef enum _mbed_error_code {
//Below are POSIX ERROR CODE definitions, which starts at MBED_POSIX_ERROR_BASE(=0)
//POSIX ERROR CODE definitions starts at offset 0(MBED_POSIX_ERROR_BASE) to align them with actual Posix Error Code
//defintions in mbed_retarget.h

View File

@ -30,13 +30,13 @@ static int error_log_count = -1;
mbed_error_status_t mbed_error_hist_put(mbed_error_ctx *error_ctx)
{
//Return error if error_ctx is NULL
if(NULL == error_ctx) {
if (NULL == error_ctx) {
return MBED_ERROR_INVALID_ARGUMENT;
}
core_util_critical_section_enter();
error_log_count++;
memcpy(&mbed_error_ctx_log[error_log_count % MBED_CONF_PLATFORM_ERROR_HIST_SIZE], error_ctx, sizeof(mbed_error_ctx) );
memcpy(&mbed_error_ctx_log[error_log_count % MBED_CONF_PLATFORM_ERROR_HIST_SIZE], error_ctx, sizeof(mbed_error_ctx));
core_util_critical_section_exit();
return MBED_SUCCESS;
@ -45,17 +45,17 @@ mbed_error_status_t mbed_error_hist_put(mbed_error_ctx *error_ctx)
mbed_error_status_t mbed_error_hist_get(int index, mbed_error_ctx *error_ctx)
{
//Return error if index is more than max log size
if(index >= MBED_CONF_PLATFORM_ERROR_HIST_SIZE) {
if (index >= MBED_CONF_PLATFORM_ERROR_HIST_SIZE) {
return MBED_ERROR_INVALID_ARGUMENT;
}
core_util_critical_section_enter();
//calculate the index where we want to pick the ctx
if(error_log_count >= MBED_CONF_PLATFORM_ERROR_HIST_SIZE) {
if (error_log_count >= MBED_CONF_PLATFORM_ERROR_HIST_SIZE) {
index = (error_log_count + index + 1) % MBED_CONF_PLATFORM_ERROR_HIST_SIZE;
}
core_util_critical_section_exit();
memcpy(error_ctx, &mbed_error_ctx_log[index % MBED_CONF_PLATFORM_ERROR_HIST_SIZE], sizeof(mbed_error_ctx) );
memcpy(error_ctx, &mbed_error_ctx_log[index % MBED_CONF_PLATFORM_ERROR_HIST_SIZE], sizeof(mbed_error_ctx));
return MBED_SUCCESS;
}
@ -72,11 +72,11 @@ mbed_error_ctx *mbed_error_hist_get_entry(void)
mbed_error_status_t mbed_error_hist_get_last_error(mbed_error_ctx *error_ctx)
{
if(-1 == error_log_count) {
if (-1 == error_log_count) {
return MBED_ERROR_ITEM_NOT_FOUND;
}
core_util_critical_section_enter();
memcpy(error_ctx, &mbed_error_ctx_log[error_log_count % MBED_CONF_PLATFORM_ERROR_HIST_SIZE], sizeof(mbed_error_ctx) );
memcpy(error_ctx, &mbed_error_ctx_log[error_log_count % MBED_CONF_PLATFORM_ERROR_HIST_SIZE], sizeof(mbed_error_ctx));
core_util_critical_section_exit();
return MBED_SUCCESS;

View File

@ -99,17 +99,17 @@ MBED_NOINLINE void print_context_info(void)
,SCB->HFSR, (0xFF & SCB->CFSR), ((0xFF00 & SCB->CFSR) >> 8), ((0xFFFF0000 & SCB->CFSR) >> 16), SCB->DFSR, SCB->AFSR );
//Print MMFAR only if its valid as indicated by MMFSR
if((0xFF & SCB->CFSR) & 0x80) {
if ((0xFF & SCB->CFSR) & 0x80) {
mbed_error_printf("\nMMFAR: %08X",SCB->MMFAR);
}
//Print BFAR only if its valid as indicated by BFSR
if(((0xFF00 & SCB->CFSR) >> 8) & 0x80) {
if (((0xFF00 & SCB->CFSR) >> 8) & 0x80) {
mbed_error_printf("\nBFAR : %08X",SCB->BFAR);
}
#endif
//Print Mode
if(mbed_fault_context.EXC_RETURN & 0x8) {
if (mbed_fault_context.EXC_RETURN & 0x8) {
mbed_error_printf("\nMode : Thread");
//Print Priv level in Thread mode - We capture CONTROL reg which reflects the privilege.
//Note that the CONTROL register captured still reflects the privilege status of the
@ -124,7 +124,7 @@ MBED_NOINLINE void print_context_info(void)
mbed_error_printf("\nPriv : Privileged");
}
//Print Return Stack
if(mbed_fault_context.EXC_RETURN & 0x4) {
if (mbed_fault_context.EXC_RETURN & 0x4) {
mbed_error_printf("\nStack: PSP");
} else {
mbed_error_printf("\nStack: MSP");