Skip to content
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

ST: Add support to save RBP register that allows stack backtrace #3987

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

winlinvip
Copy link
Member

@winlinvip winlinvip commented Mar 16, 2024

Duplicate the entire stack (backtrace) during coroutine creation, store the RBP in the jmpbuf, and replicate the parent RBP and stack home space containing local variables from the parent function.

Keep in mind that local variables might be freed after coroutine creation and should be freed while the coroutine is running. Please be caution with these variables; they only serve as backtrace hints and do not guarantee the validity of all local variables.

This Pull Request primarily serves as a helpful debugging tool for tracking the stack, with limited but valuable utility, particularly for identifying the creators of the current coroutine.

I have tested it in cygwin, before this patch, the backtrace is bellow:

(gdb) bt
#0  pfn (arg=0x0) at backtrace.cpp:9
#1  0x0000000100401cea in _st_thread_main () at sched.c:380
#2  0x000000010040265f in st_thread_create (start=0x7ffffcbc0, arg=0x100401b0d <st_thread_exit+588>, joinable=19616, stk_size=131072) at sched.c:666
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

After this patch, the backtrace is:

(gdb) bt
#0  pfn (arg=0x0) at backtrace.cpp:9
#1  0x0000000100401cea in _st_thread_main () at sched.c:380
#2  0x00000001004027f0 in st_thread_create (start=0x100401080 <pfn(void*)>, arg=0x0, joinable=0, stk_size=131072) at sched.c:698
#3  0x00000001004010d2 in bar (argc=0) at backtrace.cpp:16
#4  0x00000001004010f1 in foo (argc=0) at backtrace.cpp:21
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Because only save the parent RBP, so only trace some levels of backtrace.

@winlinvip winlinvip added the EnglishNative This issue is conveyed exclusively in English. label Mar 16, 2024
@winlinvip winlinvip marked this pull request as draft March 16, 2024 11:46
@winlinvip winlinvip self-assigned this Mar 16, 2024
@winlinvip winlinvip changed the title ST: Support save RBP and backtrace stack. ST: Add support for saving RBP register that allows stack backtrace Mar 16, 2024
@winlinvip winlinvip changed the title ST: Add support for saving RBP register that allows stack backtrace ST: Add support to save RBP register that allows stack backtrace Mar 16, 2024
st_init();
foo(argc);
st_thread_exit(NULL);
return 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

st_destroy() missing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
EnglishNative This issue is conveyed exclusively in English.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants