-
Notifications
You must be signed in to change notification settings - Fork 3k
Enable stack dump #10872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Enable stack dump #10872
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -556,6 +556,44 @@ static void print_error_report(const mbed_error_ctx *ctx, const char *error_msg, | |
mbed_stats_sys_get(&sys_stats); | ||
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); | ||
#endif | ||
|
||
#if MBED_STACK_DUMP_ENABLED && defined(MBED_CONF_RTOS_PRESENT) | ||
/** The internal threshold to detect the end of the stack. | ||
* The stack is filled with osRtxStackFillPattern at the end. | ||
* However, it is possible that the call stack parameters can theoretically have consecutive osRtxStackFillPattern instances. | ||
* For the best effort stack end detection, we will consider STACK_END_MARK_CNT consecutive osRtxStackFillPattern instances as the stack end. */ | ||
#define STACK_END_MARK_CNT 3 | ||
#define STACK_DUMP_WIDTH 8 | ||
mbed_error_printf("\n\nStack Dump:"); | ||
// Find the stack end. | ||
int stack_end_cnt = 0; | ||
uint32_t st_end = ctx->thread_current_sp; | ||
for (; st_end >= ctx->thread_stack_mem; st_end -= sizeof(int)) { | ||
uint32_t st_val = *((uint32_t *)st_end); | ||
if (st_val == osRtxStackFillPattern) { | ||
stack_end_cnt++; | ||
} else { | ||
stack_end_cnt = 0; | ||
} | ||
if (stack_end_cnt >= STACK_END_MARK_CNT) { | ||
st_end += (STACK_END_MARK_CNT - 1) * sizeof(int); | ||
break; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
for (uint32_t st = st_end; st <= ctx->thread_current_sp; st += sizeof(int) * STACK_DUMP_WIDTH) { | ||
mbed_error_printf("\n0x%08" PRIX32 ":", st); | ||
for (int i = 0; i < STACK_DUMP_WIDTH; i++) { | ||
uint32_t st_cur = st + i * sizeof(int); | ||
if (st_cur > ctx->thread_current_sp) { | ||
break; | ||
} | ||
uint32_t st_val = *((uint32_t *)st_cur); | ||
mbed_error_printf("0x%08" PRIX32 " ", st_val); | ||
} | ||
} | ||
mbed_error_printf("\n"); | ||
#endif // MBED_STACK_DUMP_ENABLED | ||
|
||
mbed_error_printf("\n-- MbedOS Error Info --\n"); | ||
} | ||
#endif //ifndef NDEBUG | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the current stack pointer verified somewhere before stored to context? It might be worth checking that it is within RAM at least to avoid faulting again here. Also the value should be checked for misalingment to avoid accessing data from non-32bit aligned addresses. A bit of caution on the data collected from crashed thread will not hurt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Good point. I will add this feature in the next candidate code for this PR.