-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
8332287: When printing arguments in error logs, quote arguments with whitespaces #19248
base: master
Are you sure you want to change the base?
8332287: When printing arguments in error logs, quote arguments with whitespaces #19248
Conversation
👋 Welcome back stuefe! A progress list of the required criteria for merging this PR into |
@tstuefe This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 168 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
Webrevs
|
const char* const s = _jvm_args_array[i]; | ||
bool ws = false; | ||
for (const char* p = s; *p && !ws; p++) { | ||
ws = isspace(*p); |
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.
Based on a recommendation from CPPReference, the argument of isspace
should be casted to unsigned char
.
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.
ok, done.
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.
Are we saying we actually ran with, e.g. -Dtest.vm.opts="1 2 3"
and we curently report in e.g. VM.info or hs_err as:
Command Line: -Dtest.vm.opts=1 2 3 AppName
and:
jvm_args: -Dtest.vm.opts=1 2 3
But do we really want to report it with -Dtest.vm.opts itself inside the quotes - to make the copy/paste usable, we need to recognise -Dname=value args containing spaces, and add the first quote after the = sign?
The scheme here would work for args to the app, e.g. java -Dtest.vm.opts="1 2 3" MyApp "one arg with spaces"
Currently reported as:
Command Line: -Dtest.vm.opts=1 2 3 MyApp one arg with spaces
..where the args to the Java app are misleading. However, if the arg to the Java app is:
java MyApp arg="arg with spaces"
..then if we simply quote that one argument it may be clearer to humans, but may not be directly usable in a copy/paste.
Hi Kevin,
yes
No, its usable in its current form. When copy-pasted into a terminal running bash,
I don't like the hs-err file to be too smart about this :) I would like to see the real argument vector, not some interpreted form of it. If something is given as a single argument containing spaces, that argument should be quoted. For that it does not matter if the arguments itself is later interpreted by the JVM or one of its daughter processes as a variable assignment. |
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 and feature seems reasonable.
// quote any argument containing whitespaces | ||
const char* const s = _jvm_args_array[i]; | ||
bool ws = false; | ||
for (const char* p = s; *p && !ws; p++) { |
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.
Please expand the check for *p
to *p != '\0'
.
OK, yes I can expect for the JVM arguments, it doesn't matter if the JVM sees -Dfoo="1 2 3 " or "-Dfoo=1 2 3 " I just thought that if we report the quotes in a different place to the original, that we should at least acknowledge that difference somewhere in the change/bug report. I was exactly noticing that this is an interpreted form of the arg. (But yes it should be harmless, and no I don't want to suggest we should do anything much more clever here right now.) I think -XX args work this way too, they don't mind the quotes moving. |
But how would I know the original? The JVM does not know if you called |
I don't think you can. 8-) That may be why it's currently done as it is, if the quote placement is lost we just can't put it back and know it was correct. This next one may be a bit artificial, but we should also at least acknowledge the case where an argument has an embedded quote character, e.g. escaped with a backslash before I type it. There might be an XX or other option where that could apply at some point. You don't get a String you can paste, unless we escape quotes when printing in print_jvm_args_on(). And we don't want to make that much more complicated. We can either print the escape \ before any quotes, or just note in the bug that this is not always a trivial problem, although it is trivial for many cases. |
How deep down the rabbit hole do we go? Escape both single- and double-quotes? What if they are already escaped? Tbh, I would have liked this to be a small patch without burning too much time on it. I think what you describe is a rare outlier case (arguments that contain both whitespaces and quotes). Wheras the spaces-in-arguments is something that regularly occurs during many jtreg tests. |
Hey @tstuefe Thomas -- I don't mean to stop this happening, and I don't want you or anybody to burn time on it too much, just wanted to note that quoting and trivial are not words that usually go together, and we have winners and losers. 8-) We want to simply copy paste all the JVM arguments to rerun the same arguments and reproduce an issue. With this change: don't worry if an option has embedded spaces, but look carefully if an option contains a quote. e.g. With mixed feelings about deepening the rabbit hole, if this is triggered by reproducing failures from jtreg tests, then the result .jtr file contains "rerun:" information, with single-quoted args like: ...so while I realise somebody may only send you an hs_err file, the full script to rerun should be available somewhere. If you're reproducing a crash, is it the process that had the -Dtest.vm.opts... that crashed and gave you an hs_err file, or is it the thing which that launched? Running with -Dtest.vm.opts suggests you might be looking at the com.sun.javatest.regtest.agent.MainWrapper process and that sounds unusual. I really want to leave this alone and let you and others decide if this is a net benefit. I think the JBS bug should contain some note on the trade-off. |
Trivial fix to a simple issue.
In hs-err files, when printing the arguments of the crashed JVM process, print arguments with whitespaces in them with quotes. Makes it easier to copy-paste them to terminals.
Before:
Now (notice the gigantic -Dtest.vm.opts and -Dtest.tool.vm.opts that are actually just one large argument each)
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/19248/head:pull/19248
$ git checkout pull/19248
Update a local copy of the PR:
$ git checkout pull/19248
$ git pull https://git.openjdk.org/jdk.git pull/19248/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 19248
View PR using the GUI difftool:
$ git pr show -t 19248
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/19248.diff
Webrev
Link to Webrev Comment