@@ -556,6 +556,49 @@ static void print_error_report(const mbed_error_ctx *ctx, const char *error_msg,
556
556
mbed_stats_sys_get (& sys_stats );
557
557
mbed_error_printf ("\nFor more info, visit: https://mbed.com/s/error?error=0x%08X&osver=%" PRId32 "&core=0x%08" PRIX32 "&comp=%d&ver=%" PRIu32 "&tgt=" GET_TARGET_NAME (TARGET_NAME ), ctx -> error_status , sys_stats .os_version , sys_stats .cpu_id , sys_stats .compiler_id , sys_stats .compiler_version );
558
558
#endif
559
+
560
+ #if MBED_STACK_DUMP_ENABLED && defined(MBED_CONF_RTOS_PRESENT )
561
+ /** The internal threshold to detect the end of the stack.
562
+ * The stack is filled with osRtxStackFillPattern at the end.
563
+ * However, it is possible that the call stack parameters can theoretically have consecutive osRtxStackFillPattern instances.
564
+ * For the best effort stack end detection, we will consider STACK_END_MARK_CNT consecutive osRtxStackFillPattern instances as the stack end. */
565
+ #define STACK_END_MARK_CNT 3
566
+ #define STACK_DUMP_WIDTH 8
567
+ mbed_error_printf ("\n\nStack Dump:" );
568
+ // Find the stack end.
569
+ int stack_end_cnt = 0 ;
570
+ uint32_t st_end = ctx -> thread_current_sp ;
571
+ for (; st_end >= ctx -> thread_stack_mem ; st_end -= sizeof (int )) {
572
+ uint32_t st_val = * ((uint32_t * )st_end );
573
+ if (st_val == osRtxStackFillPattern ) {
574
+ stack_end_cnt ++ ;
575
+ } else {
576
+ stack_end_cnt = 0 ;
577
+ }
578
+ if (stack_end_cnt >= STACK_END_MARK_CNT ) {
579
+ st_end += (STACK_END_MARK_CNT - 1 ) * sizeof (int );
580
+ break ;
581
+ }
582
+ }
583
+ for (uint32_t st = st_end ; st <= ctx -> thread_current_sp ; st += sizeof (int ) * STACK_DUMP_WIDTH ) {
584
+ mbed_error_printf ("\n0x%08" PRIX32 ":" , st );
585
+ for (int i = 0 ; i < STACK_DUMP_WIDTH ; i ++ ) {
586
+ uint32_t st_cur = st + i * sizeof (int );
587
+ if (st_cur > ctx -> thread_current_sp ) {
588
+ break ;
589
+ }
590
+ uint32_t st_val = * ((uint32_t * )st_cur );
591
+ mbed_error_printf ("0x%08" PRIX32 " " , st_val );
592
+ if (st_val == osRtxStackFillPattern ) {
593
+ stack_end_cnt ++ ;
594
+ } else {
595
+ stack_end_cnt = 0 ;
596
+ }
597
+ }
598
+ }
599
+ mbed_error_printf ("\n" );
600
+ #endif // MBED_STACK_DUMP_ENABLED
601
+
559
602
mbed_error_printf ("\n-- MbedOS Error Info --\n" );
560
603
}
561
604
#endif //ifndef NDEBUG
0 commit comments