29
29
#include <stdio.h>
30
30
#endif
31
31
32
- //Helper macro to get the current SP
33
- #define GET_CURRENT_SP (sp ) \
34
- { \
35
- /*If in Handler mode we are always using MSP*/ \
36
- if ( __get_IPSR () != 0U ) { \
37
- sp = __get_MSP (); \
38
- } else { \
39
- /*Look into CONTROL.SPSEL value*/ \
40
- if ((__get_CONTROL () & 2U ) == 0U ) { \
41
- sp = __get_MSP ();/*Read MSP*/ \
42
- } else { \
43
- sp = __get_PSP ();/*Read PSP*/ \
44
- } \
45
- } \
46
- }
47
-
48
32
#ifndef NDEBUG
49
- #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 );
50
35
#else
51
- #define ERROR_REPORT (ctx , error_msg ) ((void) 0)
36
+ #define ERROR_REPORT (ctx , error_msg , error_filename , error_line ) ((void) 0)
52
37
#endif
53
38
54
39
static uint8_t error_in_progress = 0 ;
55
40
static int error_count = 0 ;
56
41
static mbed_error_ctx first_error_ctx = {0 };
57
42
static mbed_error_ctx last_error_ctx = {0 };
58
43
static mbed_error_hook_t error_hook = NULL ;
59
- static void print_error_report (mbed_error_ctx * ctx , const char * );
60
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 );
61
45
62
46
//Helper function to halt the system
@@ -83,7 +67,7 @@ WEAK void error(const char *format, ...)
83
67
84
68
//Call handle_error/print_error_report permanently setting error_in_progress flag
85
69
handle_error (MBED_ERROR_UNKNOWN , 0 , NULL , 0 , MBED_CALLER_ADDR ());
86
- ERROR_REPORT (& last_error_ctx , "Fatal Run-time error" );
70
+ ERROR_REPORT (& last_error_ctx , "Fatal Run-time error" , NULL , 0 );
87
71
error_in_progress = 1 ;
88
72
89
73
#ifndef NDEBUG
@@ -132,16 +116,12 @@ static mbed_error_status_t handle_error(mbed_error_status_t error_status, unsign
132
116
current_error_ctx .thread_entry_address = (uint32_t )current_thread -> thread_addr ;
133
117
current_error_ctx .thread_stack_size = current_thread -> stack_size ;
134
118
current_error_ctx .thread_stack_mem = (uint32_t )current_thread -> stack_mem ;
135
- #ifdef TARGET_CORTEX_M
136
- GET_CURRENT_SP (current_error_ctx .thread_current_sp );
137
- #endif //TARGET_CORTEX_M
138
-
119
+ current_error_ctx .thread_current_sp = (uint32_t )& current_error_ctx ; // Address local variable to get a stack pointer
139
120
#endif //MBED_CONF_RTOS_PRESENT
140
121
141
122
#if MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED
142
123
//Capture filename/linenumber if provided
143
124
//Index for tracking error_filename
144
- memset (& current_error_ctx .error_filename , 0 , MBED_CONF_PLATFORM_MAX_ERROR_FILENAME_LEN );
145
125
strncpy (current_error_ctx .error_filename , filename , MBED_CONF_PLATFORM_MAX_ERROR_FILENAME_LEN );
146
126
current_error_ctx .error_line_number = line_number ;
147
127
#endif
@@ -205,7 +185,7 @@ WEAK mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char
205
185
}
206
186
207
187
//On fatal errors print the error context/report
208
- ERROR_REPORT (& last_error_ctx , error_msg );
188
+ ERROR_REPORT (& last_error_ctx , error_msg , filename , line_number );
209
189
mbed_halt_system ();
210
190
211
191
return MBED_ERROR_FAILED_OPERATION ;
@@ -290,15 +270,20 @@ mbed_error_status_t mbed_clear_all_errors(void)
290
270
return status ;
291
271
}
292
272
273
+ static const char * name_or_unnamed (const char * name )
274
+ {
275
+ return name ? name : "<unnamed>" ;
276
+ }
277
+
293
278
#if MBED_CONF_PLATFORM_ERROR_ALL_THREADS_INFO && defined(MBED_CONF_RTOS_PRESENT )
294
279
/* Prints info of a thread(using osRtxThread_t struct)*/
295
- static void print_thread (osRtxThread_t * thread )
280
+ static void print_thread (const osRtxThread_t * thread )
296
281
{
297
- mbed_error_printf ("\nState : 0x%08X Entry: 0x%08X Stack Size: 0x%08X Mem: 0x%08X SP: 0x%08X" , thread -> state , thread -> thread_addr , thread -> stack_size , (uint32_t )thread -> stack_mem , thread -> sp );
282
+ mbed_error_printf ("\n%s State : 0x%X Entry: 0x%08X Stack Size: 0x%08X Mem: 0x%08X SP: 0x%08X" , name_or_unnamed ( thread -> name ) , thread -> state , thread -> thread_addr , thread -> stack_size , (uint32_t )thread -> stack_mem , thread -> sp );
298
283
}
299
284
300
285
/* Prints thread info from a list */
301
- static void print_threads_info (osRtxThread_t * threads )
286
+ static void print_threads_info (const osRtxThread_t * threads )
302
287
{
303
288
while (threads != NULL ) {
304
289
print_thread (threads );
@@ -308,7 +293,7 @@ static void print_threads_info(osRtxThread_t *threads)
308
293
#endif
309
294
310
295
#ifndef NDEBUG
311
- 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 )
312
297
{
313
298
uint32_t error_code = MBED_GET_ERROR_CODE (ctx -> error_status );
314
299
uint32_t error_module = MBED_GET_ERROR_MODULE (ctx -> error_status );
@@ -357,41 +342,41 @@ static void print_error_report(mbed_error_ctx *ctx, const char *error_msg)
357
342
//Nothing to do here, just print the error info down
358
343
break ;
359
344
}
360
- mbed_error_printf (error_msg );
345
+ mbed_error_puts (error_msg );
361
346
mbed_error_printf ("\nLocation: 0x%X" , ctx -> error_address );
362
347
363
- #if MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED && !defined(NDEBUG )
364
- if ((NULL != ctx -> error_filename [0 ]) && (ctx -> error_line_number != 0 )) {
365
- //for string, we must pass address of a ptr which has the address of the string
366
- 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 );
367
359
}
368
- #endif
369
360
370
361
mbed_error_printf ("\nError Value: 0x%X" , ctx -> error_value );
371
- #ifdef TARGET_CORTEX_M
372
- mbed_error_printf ("\nCurrent Thread: Id: 0x%X Entry: 0x%X StackSize: 0x%X StackMem: 0x%X SP: 0x%X " ,
362
+ #ifdef MBED_CONF_RTOS_PRESENT
363
+ mbed_error_printf ("\nCurrent Thread: %s Id: 0x%X Entry: 0x%X StackSize: 0x%X StackMem: 0x%X SP: 0x%X " ,
364
+ name_or_unnamed (((osRtxThread_t * )ctx -> thread_id )-> name ),
373
365
ctx -> thread_id , ctx -> thread_entry_address , ctx -> thread_stack_size , ctx -> thread_stack_mem , ctx -> thread_current_sp );
374
- #else
375
- //For Cortex-A targets we dont have support to capture the current SP
376
- mbed_error_printf ("\nCurrent Thread: Id: 0x%X Entry: 0x%X StackSize: 0x%X StackMem: 0x%X " ,
377
- ctx -> thread_id , ctx -> thread_entry_address , ctx -> thread_stack_size , ctx -> thread_stack_mem );
378
- #endif //TARGET_CORTEX_M
366
+ #endif
379
367
380
368
#if MBED_CONF_PLATFORM_ERROR_ALL_THREADS_INFO && defined(MBED_CONF_RTOS_PRESENT )
381
369
mbed_error_printf ("\nNext:" );
382
370
print_thread (osRtxInfo .thread .run .next );
383
371
372
+ mbed_error_printf ("\nReady:" );
373
+ print_threads_info (osRtxInfo .thread .ready .thread_list );
374
+
384
375
mbed_error_printf ("\nWait:" );
385
- osRtxThread_t * threads = (osRtxThread_t * )& osRtxInfo .thread .wait_list ;
386
- print_threads_info (threads );
376
+ print_threads_info (osRtxInfo .thread .wait_list );
387
377
388
378
mbed_error_printf ("\nDelay:" );
389
- threads = (osRtxThread_t * )& osRtxInfo .thread .delay_list ;
390
- print_threads_info (threads );
391
-
392
- mbed_error_printf ("\nIdle:" );
393
- threads = (osRtxThread_t * )& osRtxInfo .thread .idle ;
394
- print_threads_info (threads );
379
+ print_threads_info (osRtxInfo .thread .delay_list );
395
380
#endif
396
381
mbed_error_printf (MBED_CONF_PLATFORM_ERROR_DECODE_HTTP_URL_STR , ctx -> error_status );
397
382
mbed_error_printf ("\n-- MbedOS Error Info --\n" );
0 commit comments