@@ -575,6 +575,44 @@ static void print_error_report(const mbed_error_ctx *ctx, const char *error_msg,
575
575
mbed_stats_sys_get (& sys_stats );
576
576
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 );
577
577
#endif
578
+
579
+ #if MBED_STACK_DUMP_ENABLED && defined(MBED_CONF_RTOS_PRESENT )
580
+ /** The internal threshold to detect the end of the stack.
581
+ * The stack is filled with osRtxStackFillPattern at the end.
582
+ * However, it is possible that the call stack parameters can theoretically have consecutive osRtxStackFillPattern instances.
583
+ * For the best effort stack end detection, we will consider STACK_END_MARK_CNT consecutive osRtxStackFillPattern instances as the stack end. */
584
+ #define STACK_END_MARK_CNT 3
585
+ #define STACK_DUMP_WIDTH 8
586
+ mbed_error_printf ("\n\nStack Dump:" );
587
+ // Find the stack end.
588
+ int stack_end_cnt = 0 ;
589
+ uint32_t st_end = ctx -> thread_current_sp ;
590
+ for (; st_end >= ctx -> thread_stack_mem ; st_end -= sizeof (int )) {
591
+ uint32_t st_val = * ((uint32_t * )st_end );
592
+ if (st_val == osRtxStackFillPattern ) {
593
+ stack_end_cnt ++ ;
594
+ } else {
595
+ stack_end_cnt = 0 ;
596
+ }
597
+ if (stack_end_cnt >= STACK_END_MARK_CNT ) {
598
+ st_end += (STACK_END_MARK_CNT - 1 ) * sizeof (int );
599
+ break ;
600
+ }
601
+ }
602
+ for (uint32_t st = st_end ; st <= ctx -> thread_current_sp ; st += sizeof (int ) * STACK_DUMP_WIDTH ) {
603
+ mbed_error_printf ("\n0x%08" PRIX32 ":" , st );
604
+ for (int i = 0 ; i < STACK_DUMP_WIDTH ; i ++ ) {
605
+ uint32_t st_cur = st + i * sizeof (int );
606
+ if (st_cur > ctx -> thread_current_sp ) {
607
+ break ;
608
+ }
609
+ uint32_t st_val = * ((uint32_t * )st_cur );
610
+ mbed_error_printf ("0x%08" PRIX32 " " , st_val );
611
+ }
612
+ }
613
+ mbed_error_printf ("\n" );
614
+ #endif // MBED_STACK_DUMP_ENABLED
615
+
578
616
mbed_error_printf ("\n-- MbedOS Error Info --\n" );
579
617
}
580
618
#endif //ifndef NDEBUG
0 commit comments