-
Notifications
You must be signed in to change notification settings - Fork 161
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
Add WhereWithVars - a more verbose Where #3564
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3564 +/- ##
==========================================
+ Coverage 83.73% 84.52% +0.79%
==========================================
Files 695 696 +1
Lines 344884 345125 +241
==========================================
+ Hits 288789 291727 +2938
+ Misses 56095 53398 -2697
|
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.
Overall, I like this! Some minor questions, though
tst/testspecial/backtrace.g.out
Outdated
od; at *stdin*:24 | ||
with local state: | ||
-Arguments: | ||
-Locals: |
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.
Why is there a minus sign in front of these strings? Or is that supposed to be a list? Then I'd suggest to add a space after the -
.
(For the following, please keep in mind that I am German: these are optional suggestions, not concealed demands :-)
Perhaps this should be indented by a space or two (the "called from" is also indented, after all); and perhaps replace "Arguments" by "arguments" and "Locals" by "locals", which seems to me to better match with the surrounding text?
And perhaps when there are no arguments, one could print - arguments: <none>
? Same for locals, I guess?
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.
I played around a little with the formatting, I'm happy for other suggestions, and couldn't come up with anything I loved.
A nicer handling of 'none' definitely seems like a nice idea.
lib/error.g
Outdated
BIND_GLOBAL("PRETTY_PRINT_VARS", function(context) | ||
local vars, i; | ||
vars := ContentsLVars(context); | ||
if IsRecord(vars) then |
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.
A matter of taste, but there'd be less need for indentation if you used if not IsRecord(vars) then return; fi;
.
doc/ref/mloop.xml
Outdated
<Description> | ||
<Index Subkey="GAP3 name for Where">Backtrace</Index> | ||
<Index>Stack trace</Index> | ||
shows the last <A>nr</A> commands on the execution stack during whose execution | ||
the error occurred. If not given, <A>nr</A> defaults to 5. (Assume, for the | ||
following example, that after the last example <Ref Func="OnBreak"/> | ||
has been set back to its default value.) | ||
has been set back to its default value.). <Ref Func="WhereWithVars"/> also | ||
shows the function arguments and local variables in each stack frame |
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.
shows the function arguments and local variables in each stack frame | |
shows the function arguments and local variables in each stack frame. |
The term "stack frame" is not actually defined in the manual, is it? In that case, it might be better to either define it, or avoid it here.
f307260
to
b777a6b
Compare
i've tried overhauling the output based on printing records. it looks a bit awkward as PrintTo(ERROR_OUTPUT,...) doesn't preserve the indentation level. |
b777a6b
to
e8e9dde
Compare
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.
The output looks great to me now, thanks! This is a very useful feature.
However, there is something I don't understand about the line break hints in the implementation.
lib/error.g
Outdated
vars := ContentsLVars(context); | ||
if IsRecord(vars) then | ||
argcount := ABS_RAT(NumberArgumentsFunction(vars.func)); | ||
PrintTo(ERROR_OUTPUT, "\>\>\n\<\<arguments:"); |
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.
That doesn't make sense to me. Why would you decrease the hint level with \>\>
at the start, and then after the newline increase it again? Is that to counteract some line break hints in the caller? But that would seem rather fragile, and at least should be documented.
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.
So, \>\>
increases the hint level (at least, it causes an indent). The reason I write this strangely is because (as I mention below, but I should pull the comment up) there is a long-standing bug in PrintTo(ERROR_OUTPUT,
(and a related places in printing) where the indentation level gets reset on each print call.
Therefore I'm making sure I do all the indentation I want in a single call to PrintTo is balanced (which I believe I've achieved, unless I'm missing something), so that at the moment I end up with the output I want, and if PrintTo is ever fixed, the output won't change.
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.
I'll write a longer comment pointing this out at the top of the function
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.
Thanks for the explanation, I mixed up the meaning of \<
and \>
.
And: Ah yeah, I remember that bug: the problem is that for each such PrintTo
call, we "open" stderr, print to it, and close it -- but the output state for the stdout and stderr stream are not shared, but arguably should be, at least if both are known to map to the same device. We probably should have an issue for that (perhaps we already do, I didn't check).
1f7a92f
to
3432010
Compare
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.
LGTM, thank you!
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.
Actually, I think there is still a typo in the manual -- at least I can't find a function Break
anywhere?
1c3871e
to
a70e933
Compare
Description
This adds an extended version of
Where
, calledWhereWithVars
, which adds the values of all arguments and locals to the backtrace given in a breakloop. This is a tidied up version of some code I've had use privately for a while.I didn't just add an argument to 'Where', as in some places 'Where' is replaced.
Text for release notes
Add 'WhereWithVars', an extended version of
Where
which prints the values of all arguments and locals.