30
30
#endif
31
31
32
32
#ifndef NDEBUG
33
- #define ERROR_REPORT (ctx , error_msg ) print_error_report(ctx, error_msg)
33
+ #define ERROR_REPORT (ctx , error_msg , error_filename , error_line ) print_error_report(ctx, error_msg, error_filename, error_line)
34
+ static void print_error_report (const mbed_error_ctx * ctx , const char * , const char * error_filename , int error_line );
34
35
#else
35
- #define ERROR_REPORT (ctx , error_msg ) ((void) 0)
36
+ #define ERROR_REPORT (ctx , error_msg , error_filename , error_line ) ((void) 0)
36
37
#endif
37
38
38
39
static uint8_t error_in_progress = 0 ;
39
40
static int error_count = 0 ;
40
41
static mbed_error_ctx first_error_ctx = {0 };
41
42
static mbed_error_ctx last_error_ctx = {0 };
42
43
static mbed_error_hook_t error_hook = NULL ;
43
- static void print_error_report (mbed_error_ctx * ctx , const char * );
44
44
static mbed_error_status_t handle_error (mbed_error_status_t error_status , unsigned int error_value , const char * filename , int line_number , void * caller );
45
45
46
46
//Helper function to halt the system
@@ -67,7 +67,7 @@ WEAK void error(const char *format, ...)
67
67
68
68
//Call handle_error/print_error_report permanently setting error_in_progress flag
69
69
handle_error (MBED_ERROR_UNKNOWN , 0 , NULL , 0 , MBED_CALLER_ADDR ());
70
- ERROR_REPORT (& last_error_ctx , "Fatal Run-time error" );
70
+ ERROR_REPORT (& last_error_ctx , "Fatal Run-time error" , NULL , 0 );
71
71
error_in_progress = 1 ;
72
72
73
73
#ifndef NDEBUG
@@ -185,7 +185,7 @@ WEAK mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char
185
185
}
186
186
187
187
//On fatal errors print the error context/report
188
- ERROR_REPORT (& last_error_ctx , error_msg );
188
+ ERROR_REPORT (& last_error_ctx , error_msg , filename , line_number );
189
189
mbed_halt_system ();
190
190
191
191
return MBED_ERROR_FAILED_OPERATION ;
@@ -293,7 +293,7 @@ static void print_threads_info(const osRtxThread_t *threads)
293
293
#endif
294
294
295
295
#ifndef NDEBUG
296
- static void print_error_report (mbed_error_ctx * ctx , const char * error_msg )
296
+ static void print_error_report (const mbed_error_ctx * ctx , const char * error_msg , const char * error_filename , int error_line )
297
297
{
298
298
uint32_t error_code = MBED_GET_ERROR_CODE (ctx -> error_status );
299
299
uint32_t error_module = MBED_GET_ERROR_MODULE (ctx -> error_status );
@@ -342,15 +342,21 @@ static void print_error_report(mbed_error_ctx *ctx, const char *error_msg)
342
342
//Nothing to do here, just print the error info down
343
343
break ;
344
344
}
345
- mbed_error_printf (error_msg );
345
+ mbed_error_puts (error_msg );
346
346
mbed_error_printf ("\nLocation: 0x%X" , ctx -> error_address );
347
347
348
- #if MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED && !defined(NDEBUG )
349
- if ((NULL != ctx -> error_filename [0 ]) && (ctx -> error_line_number != 0 )) {
350
- //for string, we must pass address of a ptr which has the address of the string
351
- mbed_error_printf ("\nFile:%s+%d" , ctx -> error_filename , ctx -> error_line_number );
348
+ /* We print the filename passed in, not any filename in the context. This
349
+ * avoids the console print for mbed_error being limited to the presence
350
+ * and length of the filename storage. Note that although the MBED_ERROR
351
+ * macro compiles out filenames unless platform.error-filename-capture-enabled
352
+ * is turned on, MBED_ASSERT always passes filenames, and other direct
353
+ * users of mbed_error() may also choose to.
354
+ */
355
+ if (error_filename ) {
356
+ mbed_error_puts ("\nFile: " );
357
+ mbed_error_puts (error_filename );
358
+ mbed_error_printf ("+%d" , error_line );
352
359
}
353
- #endif
354
360
355
361
mbed_error_printf ("\nError Value: 0x%X" , ctx -> error_value );
356
362
#ifdef MBED_CONF_RTOS_PRESENT
0 commit comments