-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add option gcodeview #16888
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 option gcodeview #16888
Conversation
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 feel a little weird mixing the kind of debug info with the amount of debug info. Why is -gdwarf-types
different from -g
again?
Also, please undo all the whitespace changes that aren't near the code you're changing.
The debug info levels sort by amount of debug info are
Note that |
What's your vision for how this is supposed to work in the end? Are you planning to hook up lldb on Windows with dwarf replaced by codeview or do you have something else in mind? |
Yes, lldb on WIndows with CodeView is the goal. |
Ah, the line tables mode would need to be CodeView-compatible too, right? I think that means this should be an orthogonal option, |
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 - another option would be to support something like -g -gcodeview
to specify that you want debug info and you want codeview style information rather than DWARF. -g
would be equivalent to -g -gdwarf
in that case. That does mean that you could specify something like -gnone -gdwarf
. There is precedent for this in clang, it does make it easier to target different versions of DWARF as well. -gdwarf
is the default DWARF level, while say -gdwarf-2
would generate DWARF 2.
lib/Frontend/CompilerInvocation.cpp
Outdated
@@ -764,6 +764,8 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args, | |||
Opts.DebugInfoKind = IRGenDebugInfoKind::LineTables; | |||
else if (A->getOption().matches(options::OPT_gdwarf_types)) | |||
Opts.DebugInfoKind = IRGenDebugInfoKind::DwarfTypes; | |||
else if (A->getOption().matches(options::OPT_gcodeview)) | |||
Opts.DebugInfoKind = IRGenDebugInfoKind::CodeViewTypes; | |||
else |
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.
Might be nice to have some sort of validation that -gdwarf-types
and -gcodeview
is not specified together.
In clang cc1 we have orthogonal options |
I really don't want to carry over Clang's idea that all debug options need to start with |
Internally, the codeview mode should be a flag that is orthogonal to the debug info level. |
I'm fine with a |
Yeah, the various |
So, we want to use |
|
Should |
I think it's cleaner for it not to imply -g. |
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 that you should extract the debug info kind parameter handling into a small utility function to avoid having to maintain the same list in multiple places.
lib/Driver/Driver.cpp
Outdated
else { | ||
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value, | ||
A->getAsString(Args), A->getValue()); | ||
return; |
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 that this would be nicer as a StringSwitch
.
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 think I can use StringSwitch
after moving CodeViewTypes
out of IRGenDwarfDebugInfoKind
.
lib/Frontend/CompilerInvocation.cpp
Outdated
@@ -768,6 +768,18 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args, | |||
assert(A->getOption().matches(options::OPT_gnone) && | |||
"unknown -g<kind> option"); | |||
|
|||
if (const Arg *A = Args.getLastArg(options::OPT_debug_info_format)) { | |||
if (A->containsValue("dwarf")) |
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.
Same.
include/swift/AST/IRGenOptions.h
Outdated
@@ -52,6 +52,7 @@ enum class IRGenDebugInfoKind : unsigned { | |||
LineTables, /// Line tables only. | |||
ASTTypes, /// Line tables + AST type references. | |||
DwarfTypes, /// Line tables + AST type references + DWARF types. | |||
CodeViewTypes, /// Line tables + AST type references + CodeView types. |
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.
Thinking more about what @adrian-prantl said, I think it makes sense to split this out and crease IRGenDWARFDebugInfoKind
and IRGenCodeViewDebugInfoKind
and a separate switch between the two formats.
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 can make these changes, but rather than IRGenCodeViewDebugInfoKind
I was thinking of making it IRGenCodeViewDebugInfo
with only values None
and Yes
. Would it make more sense to make this a bool?
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.
Nah, err on the side of enums when it's not obvious which one would be the default in the long term. It makes it easier at call sites too.
f79c4b8
to
d7985d4
Compare
@adrian-prantl @jrose-apple - do we really want the driver level option to be |
include/swift/AST/IRGenOptions.h
Outdated
None, /// No debug info. | ||
LineTables, /// Line tables only. | ||
ASTTypes, /// Line tables + AST type references. | ||
DwarfTypes, /// Line tables + AST type references + DWARF types. | ||
Normal = ASTTypes /// The setting LLDB prefers. | ||
}; | ||
|
||
enum class IRGenCodeViewDebugInfo : bool { | ||
None, | ||
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.
I think Normal
would be nicer than Yes
.
My expectation is that a normal user would never need to specify this option anyway since the driver would default to whatever format makes most sense for the specified target, and then we might as well use an unambiguous option. |
include/swift/AST/IRGenOptions.h
Outdated
IRGenDwarfDebugInfoKind DwarfInfoKind : 2; | ||
|
||
/// Whether we should emit codeview debug info. | ||
IRGenCodeViewDebugInfo CodeViewInfo : 1; |
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'm still not happy with this. Can't CodeView do line tables?
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.
No, unfortunately, CodeView really has no concept of "levels". You generate full fidelity debug info. The generated information is coalesced into a PDB, which can be post-processed to reduce the amount of information.
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 this representation is causing problems elsewhere. We really do want a "level of debug info" setting and a "debug format" setting, not two different "level" settings. (And then probably a separate error saying that CodeView can't do line tables or full type info—the experimental "DWARF types" option.)
lib/Driver/Driver.cpp
Outdated
else | ||
assert(A->getOption().matches(options::OPT_gnone) && | ||
"unknown -g<kind> option"); | ||
} | ||
|
||
if (const Arg *A = Args.getLastArg(options::OPT_debug_info_format)) { | ||
if (A->containsValue("dwarf")) |
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.
Nitpick: Since this isn't a multi-valued option, comparing against getValue
is probably clearer.
lib/Driver/Driver.cpp
Outdated
else { | ||
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value, | ||
A->getAsString(Args), A->getValue()); | ||
return; |
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.
No need to early-exit here. There's already an error; we might as well diagnose any other errors that come up. (I realize we're not consistent about this.)
@jrose-apple Any other changes you would like to see? |
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.
Thank you, I like this version a lot better! @adrian-prantl, any remaining concerns?
lib/Driver/Driver.cpp
Outdated
Diags.diagnose(SourceLoc(), diag::error_option_missing_required_argument, | ||
debugFormatArg->getAsString(Args), "-g"); | ||
} else if (OI.DebugInfoFormat == IRGenDebugInfoFormat::CodeView && | ||
OI.DebugInfoLevel != IRGenDebugInfoLevel::Normal) { |
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.
Ah, strictly speaking -gnone -debug-info-format=codeview
should be allowed, right? (Could be useful for autogenerated command lines.)
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 can specifically allow -g -debug-info-format=codeview
and -gnone -debug-info-format=codeview
, but as the code is written that would also allow just -dwarf-info-format=codeview
.
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.
Do we want any kind of warning in case someone forgets -g
?
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 what you had earlier is reasonable as long as it checks for the presence of a -g*
flag rather than just "oh, the debug level is None".
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 looks good now (minor nitpicks inside).
lib/Frontend/CompilerInvocation.cpp
Outdated
// If -g was specified but not -debug-info-format, DWARF is assumed. | ||
Opts.DebugInfoFormat = IRGenDebugInfoFormat::DWARF; | ||
} | ||
if (Opts.DebugInfoFormat > IRGenDebugInfoFormat::None && |
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 personally would use !=
here, since these values aren't ordered like the DebugInfoLevel.
include/swift/AST/IRGenOptions.h
Outdated
@@ -47,14 +47,20 @@ enum class IRGenOutputKind : unsigned { | |||
ObjectFile | |||
}; | |||
|
|||
enum class IRGenDebugInfoKind : unsigned { | |||
enum class IRGenDebugInfoLevel : unsigned { | |||
None, /// No 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.
Not your code, but: These should be ///<
comments.
0294524
to
4c3920e
Compare
Any final nitpicks? |
Ah, there's conflicts now, so you'll have to rebase to resolve those. |
Or that, I guess. @swift-ci Please test |
Build failed |
Build failed |
Looks like you'll need to do an update to LLDB too. We can then test and land them together. |
What do you mean do an update to LLDB? |
Since LLDB (https://github.com/apple/swift-lldb) also refers to some of the IRGenOptions fields you're changing, you'll need to submit a pull request there as well (probably just a find/replace of those names). |
@jrose-apple Can we test LLDB (apple/swift-lldb#697) and swift together? |
test with apple/swift-lldb#697 |
Build failed |
Build failed |
Thanks, Ellis! |
Thank you for all your help! |
Replace this paragraph with a description of your changes and rationale. Provide links to external references/discussions if appropriate.
Resolves SR-NNNN.