-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Make DWARF debug flag behavior match Clang. #17087
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
Make DWARF debug flag behavior match Clang. #17087
Conversation
Only write the compilation flags to debug info for Mach-O targets, and only if the RC_DEBUG_OPTIONS environment variable is set.
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.
This is going into the right direction, I added a suggestion for an alternate wording. Let's also hear if @jrose-apple has any opinions.
@@ -486,4 +486,7 @@ def disable_verify_exclusivity : Flag<["-"], "disable-verify-exclusivity">, | |||
def enable_key_path_resilience : Flag<["-"], "enable-key-path-resilience">, | |||
HelpText<"Enable key path resilience.">; | |||
|
|||
def use_dwarf_debug_flags : Flag<["-"], "use-dwarf-debug-flags">, | |||
HelpText<"Write the compilation flags into the DWARF debug info.">; |
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: -emit-debug-options: Emit the compiler invocation in the debug info.
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 alternative seems fine; my only concern would be whether it would be easily confused with -serialize-debugging-options
. Or do you think the symmetry between "serialize" and "emit" would intentionally work well and make it clear which one goes where?
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 don't love either name; it's not the "debug flags" or "debug options" that are being written. (It also doesn't seem DWARF-specific.) I'll toss another contribution in, -enable-invocation-in-debug-info
, but that's getting fairly wordy.
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 think it would be nice if the debug-info part came first for grouping and sorting.
-debug-info-(emit|store)-invocation
, -debug-info-invocation=yes
?
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.
If we're making it a driver flag based on the conversation below, should we prefix it with -g
then (but not add it to the g_Group
)? How do any of these sound:
-gcompiler-flags
-gcompiler-options
-gcompiler-invocation
-grecord-compiler-flags
-grecord-compiler-options
-grecord-compiler-invocation
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.
Sorry, I'm fine with -debug-info
; it's grouping a bunch of things under single letters that I don't like. To compare with GCC/Clang flags:
- -f* - something to do with the language? Why -f?
- -m* - something to do with code generation? Why -m?
- -d* - something to do with dependencies? Or "defines"?
- -i* - "includes", okay…but it led us to the horrible
-iframework
, meaning "system framework include path"
-g is at least consistently used for debugging things, but there's still no obvious link between "-g" and "debug info"; you just have to memorize it. -O, -W, and -X are pretty much the only flag families that stayed consistent, and -W is still weird around the edges.
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.
Also we do have a man page! It just tells you to use -help
. :-)
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.
Alright, given the feedback so far, if we exclude prefixed flags, I think -debug-info-store-invocation
is the one that best balances conciseness while still getting across what the flag actually does. -enable-invocation-in-debug-info
came close, but I agree that it's a bit verbose.
If that sounds good, I'll go ahead and update the PR to use that.
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.
@jrose-apple the prefixes actually have some level of consistency
-f
: feature flags
-m
: machine flags
-d
: dump flags (used for the C Preprocessor)
-i
: includes
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.
Except that "feature flag" vs. "machine flag" doesn't make any sense to a normal user, and "-i", while consistent, has led to badness elsewhere.
Please don't limit this to Darwin. This is a spelling issue. |
@compnerd This PR only changes the default behavior of the driver to match that of Clang, where on non-Darwin platforms it never emits the flags, and on Darwin it only emits them if that environment variable is set. The user can still force the frontend to emit them on other platforms by passing Is that sufficient, or do you think we need a driver-level flag for this? |
Definitely in favor of this direction! I've been after Adrian to remove/disable this feature for a while. :-) I'm inclined to make this a driver-level flag too; if it's useful on Darwin it could easily be useful elsewhere, and no one's supposed to use -Xfrontend options in production code (they're not supported or stable). And environment variables are terrible for controlling things like this. |
The environment variable is (good design or not) necessary for uniformity with clang on Apple platforms. I just wanted to point out that the intent of this feature is to help debugging build systems. |
@allevato - I think as @jrose-apple points out, |
I've updated the PR to use |
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.
Looks reasonable to me! Adrian?
// Check that the sdk and resource dirs end up in the debug info if we build for | ||
// a Darwin target and set the RC_DEBUG_OPTIONS environment variable. This | ||
// matches the behavior found in Clang. | ||
// RUN: %target-swiftc_driver %s -emit-ir -g -target x86_64-apple-macosx10.10 -o - | %FileCheck %s |
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.
These can just be %swiftc_driver
, since you're overriding the target anyway.
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.
@swift-ci Please test |
Build failed |
lib/FrontendTool/FrontendTool.cpp
Outdated
if (!PD.empty()) | ||
IRGenOpts.DWARFDebugFlags += (" -private-discriminator " + PD.str()).str(); | ||
if (!PD.empty()) { | ||
if (!IRGenOpts.DWARFDebugFlags.empty()) IRGenOpts.DWARFDebugFlags += " "; |
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.
clang-format would format this as:
if (!IRGenOpts.DWARFDebugFlags.empty())
IRGenOpts.DWARFDebugFlags += " ";
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.
Build failed |
Thanks all! Latest requested changes are pushed. |
@swift-ci test |
Build failed |
Build failed |
Oops, of course. By default, we can't compile for macOS on a non-macOS platform. Adding |
Ah-ha, thanks for the tip! Updated. |
@swift-ci Please test |
Build failed |
Build failed |
Hmm, I'm not sure why the test is crashing when emitting the debug info on Linux after the change adding |
And to be sure nothing's changed since a few days ago. @swift-ci Please smoke test macOS |
Excellent! Thanks for the related fix on the side. |
Only write the compilation flags to debug info for Mach-O targets, and only
if the RC_DEBUG_OPTIONS environment variable is set.
This change improves hermeticity/reproducibility of Swift binaries/dSYMs by not encoding command line flags that might contain file system paths, since LLDB no longer needs them (except for
-private-discriminator
, which I've left in; it's invariant because it's computed only from the basename anyway).@adrian-prantl