-
Notifications
You must be signed in to change notification settings - Fork 74
UI option to turn on backtrace (RUST_BACKTRACE=1) --- off by default; (and also embed it in shared urls) #191
UI option to turn on backtrace (RUST_BACKTRACE=1) --- off by default; (and also embed it in shared urls) #191
Conversation
and does not set it when Stable build. This addresses rust-lang#119 although not entirely, as I imagine that a new UI button would be desirable instead of it currently depending on the Mode(Debug/Stable) one.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
by "Stable" I meant "Release"
This was proposed before, but I had some reservations because the spew isn't necessarily always wanted |
Oh I see. Since
spewed, as you've said. Here's what I propose:
What do you think? EDIT: Note that I explicitly didn't touch |
it was supposed to be inside that 'if'
backtrace is off by default! It has 3 options: on|off|auto The 'auto' is extraneous and can be removed in the future, it turn backtrace on only when Mode is Debug.
I did step 1 and 2 from my previous comment.
|
I think we can set it for ASM / IR / MIR as well, maybe even unconditionally, since it will only show a backtrace on ICEs, which is always useful. |
I wouldn't mind setting it(if @alexcrichton would agree) whether unconditionally or depending on the current setting. |
ie. http...&version=stable&backtrace=on|off|auto The effects of this are as follows: * the setting from the url overrides the setting from localStorage but it does not overwrite it. * the localStorage setting is kept as it was (eg. when opening new sessions in new tabs). * the localStorage setting will only be stored when user changes it from the Settings (by events: onkeyup, onchange)
Alright, I've made this now so that it's satisfactorily for me. Now, backtrace is a setting in Settings and it's off by default; it is also carried over in shared urls (playground URL and shortened). It is also stored in localStorage (just like
What's left to consider is:
Thoughts, ideas, feedback? |
This all sounds good to me, thanks @respeccing! I'd personally say that we should have this off by default even for the compiler because only compiler devs are really interested in the giant backtraces on ICEs, and I suspect most play users aren't compiler devs |
backtrace="--backtrace" | ||
if [ "${*#*$backtrace}" != "$*" ]; then | ||
export RUST_BACKTRACE=1 | ||
set -- ${*%$backtrace*}${*#*$backtrace} |
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.
Could the caller of this script just set the environment variable for the subprocess? This seems like crazy bash syntax that only one person in the world will ever understand :(
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 makes much more sense, I'll explore how to do just that. Thanks.
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.
Oh I forgot, looks like execute() is calling playpen.execute() which doesn't allow setting any env. vars ... and this is why I had to set RUST_BACKTRACE within evaluate.sh
depending on the incoming args (--backtrace
)
EDIT: that is, the playpen
executable(which is the one executing evaluate.sh
) isn't passing any outer env. vars that would be set by subprocess.Popen() and playpen
itself doesn't have a way to set any new vars, unless you'd want me to use the hostname (playpen --hostname=NAME
) as the state of the backtrace(?) though, that is hacky...
What do you think?
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.
tl;dr: I'll pass --backtrace
as first arg, and remove it with shift
, and also simplify the if
test (although I borrowed the code for if
from the below --test
and --color=always
code) which results in simpler code!
Don't read this, but I'll leave it here anyway :)
I used a simpler syntax in this commit: a147805
But that had the limitation that --backtrace
must always be the first passed arg! else it would break things badly(eg. delete another arg!) So, if someone would modify web.py not knowing --backtrace
must be first arg, then things would break so badly...
The ugly bash syntax(actually, it's running under the dash
shell - so there are no arrays for example) doesn't have the above limitation and it's making sure that when --backtrace
is specified wherever in the args list it will be safely removed, UNLESS it's specified more than once, then that will break. But I don't see why it would ever be specified more than once, unless a mistake in web.py but still not as easy of a mistake to make than in the above case with --backtrace
having to me first arg.
set -- ${*%$backtrace*}${*#*$backtrace}
This resets the $*
args (eg. it rewrites them) to have --backtrace
removed by concatenating the two halves of the current $*
, eg.
if $*
is initially somearg --test --backtrace --color=always "arg with space" moreargs here
and $#
is thus 7
The set
above will concat somearg --test
with --color=always "arg with space" moreargs here
and set the result as being the new $*
(the args passed to evaluate.sh
are thus modified/reset to this new value)
and still ensure the number of args is the same minus 1, even if args with spaces exist!
So it becomes: set -- somearg --test --color=always "arg with space" moreargs here
thus $*
is now somearg --test --color=always "arg with space" moreargs here
$#
is 6
Actually I forgot to test for args with spaces and it's clearly not working for that case($#
is 9
!)! eg. args with spaces are split into more than one arg. eg. the one argument "arg with space" becomes 3 args: "arg" "with" "space"
But I thought I did test it...
It doesn't seem to be a way to also remove --backtrace
AND keep the args with spaces intact, and I am unsure if it's necessary to keep them intact that way... they are only needed for this line, currently: TERM=xterm rustc - -o ./out "$@"
In other words, if rustc
currently(or in the future!) accepts any args with spaces(not counting the filename which is stdin here), then it's a MUST that I have to keep the args intact! I'll investigate more...
Worst case, we could revert to that that commit, it's the simpler syntax(as you'd want) AND it keeps the args intact! Hmm... I could even just check for $1
, expecting --backtrace
to be the first, and only then remove it, and if it's not first, then it will cause rustc to fail because it will get --backtrace
passed to it ... yes... this seems like a simpler way, an interestingly simple compromise between what I want and what you want:)
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.
Hmm, I just realized something... the caller(webpy
) can actually call playpen
with the shell(dash
, not bash) and pass it the script, but the best part is that, this way it could also set the env var, like so:
playpen ppargshere -- /usr/bin/dash -c 'export RUST_BACKTRACE=1; evaluate.sh eargshere'
or
playpen ppargshere -- /usr/bin/dash -c 'RUST_BACKTRACE=1 evaluate.sh eargshere'
(this I mentioned like 1 day ago in another issue and I forgot about it completely, see "EDIT3" here for the source of this)
So the question is, should I change this PR to do this?! it seems much better than having to pass(then remove) the --backtrace
arg!
EDIT: the answer to your question is thus yes
Could the caller of this script just set the environment variable for the subprocess?
EDIT2: I am doing it anyway haha... can't help it! (sorry? xD)
EDIT11: just realized I don't have to double quote! just have to make sure it's one arg!
EDIT3: the only problem seems to be that I might lose the wholeness of args-with-spaces, unless I would add doublequotes around each but that might be problematic if those args themselves contain such doublequotes already(which in our case is unlikely to be so, ever). I'll see what I can do... EDIT4: hmm, escaping the doublequotes from args is a great idea! :)) EDIT5: actually this is treading on dangerous territory lol... it seems safer to just not use dash -c
with all that escaping quotes/doublequotes just in case things might get away ... even though it's under playpen... Seems way safer as it currently is, with the scripts hmmm.... Because I have to escape both single quote and double quotes, and I'm unsure if it's as airtight as it seems... ok, let me think more, maybe I'm exaggerating it in my mind.
EDIT6: Hmm I can escape single quotes within singlequotes as '"'"'
=)) then this might actually work after all!! EDIT7: this would also work '\\''
. EDIT8: this would do? must read/test
EDIT9: ok, I can't sort out the quoting... whilst already within a quoting... that is, I have to escape some args and then escape the whole result... it's a like double escaping and I think it would leak... and yield a security-issue... or I'm missing something. In the above eargshere
are the ones that need to be escaped, but as you can see I'm already within single quotes... and those eargshere
could(in theory) contain args with spaces too and even backticks, and they cannot leak. (i'll think about it again)
EDIT10: nevermind, it works! it just didn't in my mind :))
Should I also change the internal values for Maybe this is desired to reduce the length of the url (since the code is limited to 5000 chars in url, apparently). And maybe while at it, I could change EDIT: Because once this is merged, changing it later, might imply the need to support the previous variants too, in case shared urls were created in the meantime (or just leave those urls with non-workable embeded backtrace setting) |
* this adds the limitation that --backtrace, if specified, must be the first arg! * got rid of the ugly syntax and as a side effect also fix the previous issue of splitting args with spaces into multiple args which would be bad(in theory anyway)
rather than moving code around
now backtrace affects all: Run/ASM/LLVM IR/MIR
from off|on|auto to 0|1|2
Should I keep the (url)variable name I notice that I would really like some feedback on this, whenever possible. Thx. (edit: otherwise, all is done, in theory) |
Ah yeah I wouldn't worry about the length of the URL option, we can always change it in the future if we need to and otherewise it's probably the least of our concerns in URL length :) |
if "1" == backtrace: | ||
args.insert(0, "--backtrace") | ||
#XXX: if exists, --backtrace must be the first arg passed to compile.sh | ||
if debug: |
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 wonder, can this and the above block share code for building up the arguments to the compiler?
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(and tested). Thanks for saying that! DRY is my friend ;-) (so to speak)
to reduce repetition/future maintenance (this diff _looks_ worse than it is, though)
A little summary of what has been done in this PR: (conciseness fail by the way, haha, sorry) The backtrace setting is
The backtrace setting does affect the following actions: |
Using extra shell syntax to specify the RUST_BACKTRACE env var actually seems pretty reasonable to me, could that be implemented here as well? |
This allows setting environment variables within playpen at the expense of having to run your command wrapped around the shell(which is dash(not to be confused with bash)) eg. dash -c 'cmd args' vs. cmd args Env.var values and args are properly escaped, supposedly. Invalid env.var names raise NameError exception.
No loger pass the arg. --backtrace which simplifies things a bit. A previous commit allows passing the shell env. var RUST_BACKTRACE directly!
The setting for Backtrace affects running 'rustfmt' via the Format button, just in case 'rustfmt' would ICE.
Really enjoyed this thus far. Don't hesitate to let me know if any changes are required or anything like that. EDIT: looks like I wrongly assumed this would set the variable $ (export ABC; set|grep ABC)
_=ABC
$ (export ABC=; set|grep ABC)
ABC=
_=ABC |
export A; vs export A=; the former didn't work, but I assumed it did.
backtrace="0" | ||
if "1" == backtrace: | ||
env_vars.append("RUST_BACKTRACE=1") | ||
if debug: |
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.
Perhaps this could just be if optimize == "0"
?
but still had to escapequote args when backtrace is on, to maintain the same logic with when backtrace is off - that each of the args are not split into multiple args when spaces(or other chars) are present in them.
Done as requested ;-) EDIT: under the hood: running: nightly /usr/bin/dash ('-c', 'export RUST_BACKTRACE=1; /usr/local/bin/evaluate.sh -C opt-level=0 -g --color=always') Backtrace off: running: nightly /usr/local/bin/evaluate.sh ('-C', 'opt-level=0', '-g', '--color=always')
|
Test, press Format button on this sample code to cause a rustfmt panic: https://play.rust-lang.org/?gist=8b133106dd19821a06ee68be3a922ebe&version=stable&backtrace=1 This is a fix for PR rust-lang#191
UPDATE: the following is old info, jump to
updatedupdated2updated3set RUST_BACKTRACE=1 when Debug build and does not set it when
StableRelease build.This addresses #119 although not entirely and I only say that because I imagine that a new UI
button would be desirable instead of it currently depending on the Mode(Debug/
StableRelease) one.Currently, if the Mode is set to Debug then the (dash)environmnet var
RUST_BACKTRACE=1
is set both for when runningrustc
(in case the compiler itself panics) and when running the output binary (./out
). But when Mode is set toStableRelease, it doesn't set this env. var.Unless I'm missing something, this should work! as I have tested it inside a virtualbox (Manjaro(based on Archlinux) VM)
In
web.js
I've setbacktrace
to2
which means that it will be set according toMode
(as explained above), but if an UI button would be added in the future, this button can directly setbacktrace
to1
to enable backtrace or to0
to disable it. (2 is the "auto" version, so to speak)Thank you.
EDIT: Just so it's visually clear what I meant by Mode(Debug/
StableRelease) see the red arrow in this screenshot:EDIT2: And by "Stable" I meant "Release"(in the UI there), for some reason in my mind Release mapped to Stable and I remembered it this way.