-
Notifications
You must be signed in to change notification settings - Fork 7
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
Implement debug strings #1540
Merged
Merged
Implement debug strings #1540
Conversation
This file contains 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
Force pushed the renaming and fixed conflicts. |
That last push syncs with master and adds the missing outlining logic (and a test for it). |
If you are OK with the deubgging logic, OK to squash this? |
Please squash. |
vext01
force-pushed
the
debug-anchors
branch
2 times, most recently
from
January 22, 2025 16:27
6a91f73
to
617f1e9
Compare
That last force push syncs ykllvm and this is now ready to merge. |
github-merge-queue
bot
removed this pull request from the merge queue due to failed status checks
Jan 22, 2025
This allows the interpreter author to insert special comments into the trace IR for helping with debugging. In the interpreter source code you can add a call like `yk_debug_str(debug_string)` and when it is traced, a special `DebugStr` bytecode is inserted into the JIT IR, which when printed, displays the dynamic value of `debug_string` at the time the instruction was traced. Under the hood, this works a lot like promotion. Calls to `yk_debug_str` (when tracing is enabled) causes `debug_string` to be copied into a vector which is passed down the pipeline. Here's an example for yklua: ```diff --- a/src/lvm.c +++ b/src/lvm.c @@ -27,6 +27,7 @@ #include "lgc.h" #include "lobject.h" #include "lopcodes.h" +#include "lopnames.h" #include "lstate.h" #include "lstring.h" #include "ltable.h" @@ -1234,6 +1235,10 @@ void luaV_execute (lua_State *L, CallInfo *ci) { lua_assert(base <= L->top.p && L->top.p <= L->stack_last.p); /* invalidate top for instructions not expecting it */ lua_assert(isIT(i) || (cast_void(L->top.p = base), 1)); + char dbgmsg[128]; + snprintf(dbgmsg, 128, "%s", opnames[GET_OPCODE(i)]); + yk_debug_str(dbgmsg); + vmdispatch (GET_OPCODE(i)) { vmcase(OP_MOVE) { StkId ra = RA(i); ``` Will give a trace with debug strings inside like: ``` ... %408: ptr = ptr_add %361, 152 %409: ptr = load %408 %410: i32 = call @snprintf(%320, 128i64, %364, %409) ; debug_str: NEWTABLE %412: ptr = ptr_add %351, 592 %413: i32 = shl 1i32, 4294967295i32 ... ``` The strings are formatted as a comment. (Obviously you'd probably want to guard the debug string logic in the interpreter somehow so the overhead doesn't arise in production) For this facility to be useful, the `DebugStr` bytecode must never be optimised out. We tell the trace optimiser that this bytecode is an "internal" bytecode, which stops DCE from killing it. When adding the code to outline the contents of `yk_debug_str()` I needed to copy logic from `handle_promote()` and found several other copies of that same code in other places in the trace builder. Thic change also de-duplicates the copies into a function `outline_until_after_call()`.
Force pushed to fix clippy warnings. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
[This requires a compiler change and a llvm sync]
@vext01
Implement debug strings.
6fb181e
This allows the interpreter author to insert special comments into the
trace IR for helping with debugging.
In the interpreter source code you can add a call like
yk_debug_str(debug_string)
and when it is traced, a specialDebugStr
bytecode is inserted into the JIT IR, which when printed, displays the
dynamic value of
debug_string
at the time the instruction was traced.Under the hood, this works a lot like promotion. Calls to
yk_debug_str
(when tracing is enabled) causes
debug_string
to be copied into avector which is passed down the pipeline.
Here's an example for yklua:
Will give a trace with debug strings inside like:
The strings are formatted as a comment.
(Obviously you'd probably want to guard the debug string logic in the
interpreter somehow so the overhead doesn't arise in production)
For this facility to be useful, the
DebugStr
bytecode must never beoptimised out. We tell the trace optimiser that this bytecode is an
"internal" bytecode, which stops DCE from killing it.
When adding the code to outline the contents of
yk_debug_str()
Ineeded to copy logic from
handle_promote()
and found several othercopies of that same code in other places in the trace builder. Thic
change also de-duplicates the copies into a function
outline_until_after_call()
.