-
Notifications
You must be signed in to change notification settings - Fork 5
Rethink debug strings. #118
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
Conversation
3e25ba4 to
5d3f222
Compare
|
I'm probably going to tweak this slightly as I noticed that (before this PR too, but still in here) we sometimes seem to give quirky debug strings to |
5d3f222 to
0e37fca
Compare
|
OK that wasn't too difficult. In essence, I just had to recognise that because we attach local x = 0
while x <= 6 do
io.stderr:write(tostring(x), "\n")
x = x + 1
end
io.stderr:write("exit\n")I can now get output such as: which really helps me work out what's been traced (and executed) and why. |
|
I see two new |
|
That's me being an idiot. Fixed in a4a142f. |
|
Sorry, I meant the direct calls to (side note: In the old design I was careful to only do stack allocation in C and to let Rust take its own copies of |
|
Fixed in 2c9d68f. FWIW, I moved away from stack allocation because of an (eventually probably unrelated) bug I hit where stack space was a possible issue. Maybe we can move back at some point. |
src/lparser.c
Outdated
| #ifdef YKLUA_DEBUG_STRS | ||
| free(dstr); | ||
| if (loc_dstr) | ||
| free(dstr); |
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.
potential double free here :) s/dstr/loc_dstr/
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.
Already fixed, but I've realised I can simplify this and solve a bigger issue too. Fix coming soon.
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.
Done in 309f58e.
|
Ah, the shadow stack stuff. Now it makes sense. |
|
Please squash. |
309f58e to
eeea398
Compare
|
Squashed. [For some reason, tryci doesn't work for me on this repo. I should investigate why. But it does mean that I have lower-than-normal confidence about a merge!] |
|
There is a genuine bug here, but whether it's caused by, or tickled by, this PR is not yet clear. |
|
Possibly related: in d8f1373 we removed the assignment to |
|
Please squash. |
This commit changes how yklua creates debug strings to help a yklua/yk
developer understand what's going on in traces. The major parts of this
commit are.
1. Move from printing source lines to printing opcodes.
2. Output yk "debug strings" in traces.
As will shortly become obvious, this commit extends debugging output
beyond `HotLocation`s, so the macro has become `YKLUA_DEBUG_STRS`. Since
in tests -- which will probably be the main use of this macro I suspect
-- full pathnames are a problem, defining this with a value of `2`
only outputs leaf names.
## Move from printing source lines to printing opcodes.
Previously debug strings contained Lua source code e.g.:
```
x.lua:41: if x < y
```
This caused two problems:
1. One source line can generate lots of IR so this gave poor
visibility into what was going on: often one source line would be
responsible for nearly all debug strings seen at runtime.
2. There is a bug where the `fgets` used to read source code sometimes
led (much later) to a segfault. Exactly why this happens is a bit
of a mystery to me. It doesn't seem to be `errno` related. Perhaps
it's shadowstack related? I spent a while on this, but eventually
gave up, because I realised that solving problem (1) means that
it's no longer really worth printing out source lines anyway.
The solution this commit alights upon is to print out opcodes. So the
example above might become something like:
```
x.lua:41: OP_LOADI
x.lua:41: OP_EQ
```
and so on. In other words, one source line is now decomposed into its
constituent opcodes. This makes much more fine-grained tests possible,
and has already given me a much greater insight into what tracing is
doing.
## Output yk "debug strings" in traces.
I have not found debug strings in `HotLocation`s to give me as much
insight as I expected. Instead, it's much more useful to know what
opcodes have been traced. So this commit leads to traces like this:
```
--- Begin jit-pre-opt ---
...
; debug_str: nested_loops.lua:33: ADDK
%63: i32 = and %45, 127i32
...
%139: ptr = load %138
; debug_str: nested_loops.lua:32: FORLOOP
%141: i32 = and %108, 127i32
...
--- End jit-pre-opt ---
```
This has already given me much greater insight into what's being traced
and thrown light onto factors I had either misunderstood or been unaware
of.
53c6915 to
421594f
Compare
|
Force pushed but ykjit/yk#1707 will need to go in before this one will merge. |
This commit changes how yklua creates debug strings to help a yklua/yk developer understand what's going on in traces. The major parts of this commit are.
As will shortly become obvious, this commit extends debugging output beyond
HotLocations, so the macro has becomeYKLUA_DEBUG_STRS. Since in tests -- which will probably be the main use of this macro I suspect -- full pathnames are a problem, defining this with a value of2only outputs leaf names.Move from printing source lines to printing opcodes.
Previously debug strings contained Lua source code e.g.:
This caused two problems:
fgetsused to read source code sometimes led (much later) to a segfault. Exactly why this happens is a bit of a mystery to me. It doesn't seem to beerrnorelated. Perhaps it's shadowstack related? I spent a while on this, but eventually gave up, because I realised that solving problem (1) means that it's no longer really worth printing out source lines anyway.The solution this commit alights upon is to print out opcodes. So the example above might become something like:
and so on. In other words, one source line is now decomposed into its constituent opcodes. This makes much more fine-grained tests possible, and has already given me a much greater insight into what tracing is doing.
Output yk "debug strings" in traces.
I have not found debug strings in
HotLocations to give me as much insight as I expected. Instead, it's much more useful to know what opcodes have been traced. So this commit leads to traces like this:This has already given me much greater insight into what's being traced and thrown light onto factors I had either misunderstood or been unaware of.