@@ -51,6 +51,7 @@ static mbed_error_ctx first_error_ctx = {0};
51
51
static mbed_error_ctx last_error_ctx = {0 };
52
52
static mbed_error_hook_t error_hook = NULL ;
53
53
static void print_error_report (mbed_error_ctx * ctx , const char * );
54
+ static mbed_error_status_t handle_error (mbed_error_status_t error_status , unsigned int error_value , const char * filename , int line_number );
54
55
55
56
//Helper function to halt the system
56
57
static void mbed_halt_system (void )
@@ -72,20 +73,23 @@ WEAK void error(const char* format, ...) {
72
73
if (error_in_progress ) {
73
74
return ;
74
75
}
76
+
77
+ //Call handle_error/print_error_report permanently setting error_in_progress flag
78
+ handle_error (MBED_ERROR_UNKNOWN , 0 , NULL , 0 );
79
+ print_error_report (& last_error_ctx , "Fatal Run-time error" );
75
80
error_in_progress = 1 ;
76
81
77
82
#ifndef NDEBUG
78
83
va_list arg ;
79
84
va_start (arg , format );
80
85
mbed_error_vfprintf (format , arg );
81
- MBED_ERROR (MBED_ERROR_UNKNOWN , "Fatal Run-time Error" );
82
86
va_end (arg );
83
87
#endif
84
88
exit (1 );
85
89
}
86
90
87
91
//Set an error status with the error handling system
88
- mbed_error_status_t handle_error (mbed_error_status_t error_status , const char * error_msg , unsigned int error_value , const char * filename , int line_number )
92
+ static mbed_error_status_t handle_error (mbed_error_status_t error_status , unsigned int error_value , const char * filename , int line_number )
89
93
{
90
94
mbed_error_ctx current_error_ctx ;
91
95
@@ -129,16 +133,10 @@ mbed_error_status_t handle_error(mbed_error_status_t error_status, const char *e
129
133
130
134
#ifdef MBED_CONF_ERROR_FILENAME_CAPTURE_ENABLED
131
135
//Capture filename/linenumber if provided
132
- //Index for tracking error_filename
133
- int idx = 0 ;
134
-
135
- if (NULL != filename ) {
136
- while (idx < MBED_CONF_MAX_ERROR_FILENAME_LEN && (filename [idx ] != '\0' )) {
137
- current_error_ctx .error_filename [idx ] = filename [idx ];
138
- idx ++ ;
139
- }
140
- current_error_ctx .error_line_number = line_number ;
141
- }
136
+ //Index for tracking error_filename
137
+ memset (& current_error_ctx .error_filename , 0 , MBED_CONF_MAX_ERROR_FILENAME_LEN );
138
+ strncpy (current_error_ctx .error_filename , filename , MBED_CONF_MAX_ERROR_FILENAME_LEN );
139
+ current_error_ctx .error_line_number = line_number ;
142
140
#endif
143
141
144
142
//Capture the fist system error and store it
@@ -188,14 +186,14 @@ int mbed_get_error_count(void)
188
186
//Sets a fatal error
189
187
mbed_error_status_t mbed_warning (mbed_error_status_t error_status , const char * error_msg , unsigned int error_value , const char * filename , int line_number )
190
188
{
191
- return handle_error (error_status , error_msg , error_value , filename , line_number );
189
+ return handle_error (error_status , error_value , filename , line_number );
192
190
}
193
191
194
192
//Sets a fatal error
195
193
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 )
196
194
{
197
195
//set the error reported and then halt the system
198
- if ( MBED_SUCCESS != handle_error (error_status , error_msg , error_value , filename , line_number ) )
196
+ if ( MBED_SUCCESS != handle_error (error_status , error_value , filename , line_number ) )
199
197
return MBED_ERROR_FAILED_OPERATION ;
200
198
201
199
//On fatal errors print the error context/report
@@ -359,7 +357,7 @@ static void print_error_report(mbed_error_ctx *ctx, const char *error_msg)
359
357
uint32_t error_code = MBED_GET_ERROR_CODE (ctx -> error_status );
360
358
uint32_t error_module = MBED_GET_ERROR_MODULE (ctx -> error_status );
361
359
362
- mbed_error_printf ("\n\n++ MbedOS Error Info ++\nError Status: 0x%x Code: %d Entity : %d\nError Message: " , ctx -> error_status , error_code , error_module );
360
+ mbed_error_printf ("\n\n++ MbedOS Error Info ++\nError Status: 0x%x Code: %d Module : %d\nError Message: " , ctx -> error_status , error_code , error_module );
363
361
364
362
//Report error info based on error code, some errors require different
365
363
//error_vals[1] contains the error code
@@ -410,12 +408,10 @@ static void print_error_report(mbed_error_ctx *ctx, const char *error_msg)
410
408
}
411
409
mbed_error_printf (error_msg , NULL );
412
410
mbed_error_printf ("\nLocation: 0x%x" , ctx -> error_address );
413
- #ifdef MBED_CONF_ERROR_FILENAME_CAPTURE_ENABLED
414
- if (NULL != error_ctx -> error_filename ) {
411
+ #if defined( MBED_CONF_ERROR_FILENAME_CAPTURE_ENABLED ) && !defined( NDEBUG )
412
+ if (NULL != ctx -> error_filename ) {
415
413
//for string, we must pass address of a ptr which has the address of the string
416
- uint32_t * file_name = (uint32_t * )& error_ctx -> error_filename [0 ];
417
- mbed_error_printf ("\nFile:%s" , & file_name );
418
- mbed_error_printf ("+0x%x" , ctx -> error_line_number );
414
+ mbed_error_printf ("\nFile:%s+%d" , ctx -> error_filename , ctx -> error_line_number );
419
415
}
420
416
#endif
421
417
@@ -429,7 +425,7 @@ static void print_error_report(mbed_error_ctx *ctx, const char *error_msg)
429
425
#endif //TARGET_CORTEX_M
430
426
}
431
427
432
- mbed_error_printf ("\n-- MbedOS Error Info --" );
428
+ mbed_error_printf ("\n-- MbedOS Error Info --\n " );
433
429
}
434
430
435
431
0 commit comments