Skip to content

Comments

Print DFLAGS on -v to ease debugging#7865

Merged
dlang-bot merged 1 commit intodlang:masterfrom
wilzbach:v-debug
Feb 16, 2018
Merged

Print DFLAGS on -v to ease debugging#7865
dlang-bot merged 1 commit intodlang:masterfrom
wilzbach:v-debug

Conversation

@wilzbach
Copy link
Contributor

Motivation: it can be tricky to figure out what dflags DMD has read. This helps debugging at almost no cost (and -v is only used for debugging anyhow).

See also: #7845

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @wilzbach!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

# Force DMD to print the -v menu by passing an invalid object file
# It will fail with "no object files to link", but print the log
( ! "$DMD" -v foo.a 2> /dev/null ) | grep -q "dflags (none)"
( ! DFLAGS="-O -D" "$DMD" -v foo.a 2> /dev/null ) | grep -q "dflags -O -D"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imho it sucks that we have to workaround DMD so hard just to get it's config output. Shouldn't we make DMD's raw config settings easier to access? Most of this will be solved by the improved Json output, but there are still many cases where just looking what flags, args and precompiled versions DMD's as helps.
Ideas:

  • default for -v (instead of showing the help page)
  • --version=detailed

src/dmd/mars.d Outdated
message("binary %s", global.params.argv0);
message("version %s", global._version);
message("config %s", global.inifilename ? global.inifilename : "(none)");
OutBuffer buf;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend adding a header comment like "Print DFLAGS environment variable" for this block of code.

src/dmd/mars.d Outdated
foreach (flag; dflags.asDArray)
buf.printf("%s ", flag);
auto res = buf.peekSlice() ? buf.peekSlice()[0 .. $ - 1] : "(none)";
message("dflags %.*s", res.length, res.ptr);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use "DFLAGS" in all caps.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the existing convention of lower-casing everything - the entire output of -v starts with lower-cases tags.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Environment variables are case-sensitive (at least on Linux). Therefore, I think the case is important here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do other people think? (I don't mind changing it, but for now I focus on getting it to pass on auto-tester, so I won't change it immediately)

Copy link
Contributor

@marler8997 marler8997 Feb 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't matter to me, both have small pros/cons. Lower case is consistent with all other verbose output, CAPITAL makes it consistent with the actual variable name.

If it's helpful, rdmd's regex for verbose output is here:

auto pattern = ctRegex!(r"^(import|file|binary|config|library)\s+([^\(]+)\(?([^\)]*)\)?\s*$");

@wilzbach wilzbach force-pushed the v-debug branch 2 times, most recently from 9872cc7 to a158a35 Compare February 11, 2018 02:35
src/dmd/mars.d Outdated
message("version %s", global._version);
message("config %s", global.inifilename ? global.inifilename : "(none)");
// Print DFLAGS environment variable
OutBuffer buf;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should buf and res go in their own scope?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I didn't realize this was inside such a small if block...nevermind.

src/dmd/mars.d Outdated
// Print DFLAGS environment variable
OutBuffer buf;
foreach (flag; dflags.asDArray)
buf.printf("%s ", flag);
Copy link
Contributor

@marler8997 marler8997 Feb 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think individual dflags may contain spaces. If so, we may want to surround them with quotes when we see that they contain whitespace.

Maybe something similar to writeFilename in link.d.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you want me to detect whether there's a space in the flag and then use quotes for it?
Most flags don't use spaces and it would look pretty ugly if this is done by default.

Copy link
Contributor

@timotheecour timotheecour Feb 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would look pretty ugly if this is done by default

shouldn't be by default, just if there's space:

DFLAGS=-I"path to foo" -Ibar
=>
'-Ipath to foo' -Ibar
so only '' where needed;

also, using
-Ipath\ to\ foo -Ibar
is another option

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, a better solution might just be to print the original unprocessed value of DFLAGS because that one will already be quoted properly

@wilzbach
Copy link
Contributor Author

wilzbach commented Feb 11, 2018

Okay let's make a vote:

  • 👍 - dflags
  • 👎 - DFLAGS
  • ❤️ - I don't care, just get this merged
  • 😕 What are you talking about?

@timotheecour
Copy link
Contributor

why not add it to json output as well?

@wilzbach
Copy link
Contributor Author

Yes of course, but we are currently blocked on Walter for the JSON output: #7838

@wilzbach
Copy link
Contributor Author

Okay let's make a vote:

Looks like DFLAGS is more popular. Changed accordingly.

shouldn't be by default, just if there's space:

Okay done.

Actually, a better solution might just be to print the original unprocessed value of DFLAGS because that one will already be quoted properly

Not sure that's a good idea. There might potentially be some bugs or other problems with the processing of DFLAGS, so in my experience it's better to dump the actual value the program uses.

@wilzbach wilzbach mentioned this pull request Feb 15, 2018
@dlang-bot dlang-bot merged commit 998841a into dlang:master Feb 16, 2018
# On OSX DMD terminates with a successful exit code, so `|| true` is used.
( "$DMD" -v foo.d 2> /dev/null || true) | grep -q "DFLAGS (none)"
( DFLAGS="-O -D" "$DMD" -v foo.d 2> /dev/null || true) | grep -q "DFLAGS -O -D"
( DFLAGS="-O '-Ifoo bar' -c" "$DMD" -v foo.d 2> /dev/null || true) | grep -q "DFLAGS -O '-Ifoo bar' -c"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why this works on the auto tester. For me, this test fails without any helpful output and if I run it explicitly it seems DFLAGS is picked up as a test parameter and d_do_test complains:

object.Exception@d_do_test.d(584): The DFLAGS test argument must be empty: It is '   ="-O -D" "$DMD" -v foo.d 2> /dev/null || true) | grep -q "DFLAGS    -O -D" ="-O '-Ifoo bar' -c" "$DMD" -v foo.d 2> /dev/null || true) | grep -q "DFLAGS    -O '-Ifoo bar' -c"'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You running Windows?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but picking up DFLAGS should be OS platfrom-agnostic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something to do with the binutils or bash? What's the actual output of dmd for you?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not dmd complaining, but d_do_test because findTestParameter(envData, file, "DFLAGS", testArgs.dflags); results in the shown string.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch, totally missed that shell scripts are (no longer?) executed through d_do_test.
There is zero output from the script itself, will have to investigate further...

Copy link
Contributor

@marler8997 marler8997 Feb 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We just merged a change which adds sh_do_test.sh that automatically redirects output from all BASH tests to the test output file, i.e. test_results/compilable/mytest.sh.out

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found the issue: dmd still used an sc.ini which overrides DFLAGS. Better to pass -conf= to dmd in these tests, too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants