Skip to content

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

Merged
merged 1 commit into from
Jun 20, 2018
Merged

Add option gcodeview #16888

merged 1 commit into from
Jun 20, 2018

Conversation

ellishg
Copy link
Contributor

@ellishg ellishg commented May 29, 2018

Replace this paragraph with a description of your changes and rationale. Provide links to external references/discussions if appropriate.

Resolves SR-NNNN.

@ellishg
Copy link
Contributor Author

ellishg commented May 29, 2018

CC @compnerd @jrose-apple @dcci

Copy link
Contributor

@jrose-apple jrose-apple left a 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.

@adrian-prantl
Copy link
Contributor

The debug info levels sort by amount of debug info are

-gnone (no debug info)
-gline-tables-only (line tables)
-g (line tables + variables, only type names, type definitions are in .swiftmodules)
-gdwarf-types (line tables + variables + types represented in dwarf)

Note that -g is the default and -gdwarf-types is an experimental and incomplete mode were the actual type definitions are encoded in the debug info.

@adrian-prantl
Copy link
Contributor

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?

@ellishg
Copy link
Contributor Author

ellishg commented May 29, 2018

Yes, lldb on WIndows with CodeView is the goal.

@jrose-apple
Copy link
Contributor

Ah, the line tables mode would need to be CodeView-compatible too, right? I think that means this should be an orthogonal option, -codeview-debug-info or -debug-info-format=codeview or something.

Copy link
Member

@compnerd compnerd left a 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.

@@ -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
Copy link
Member

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.

@adrian-prantl
Copy link
Contributor

In clang cc1 we have orthogonal options -gcodeview -debug-info-kind=line-tables-only for this, too.

@jrose-apple
Copy link
Contributor

I really don't want to carry over Clang's idea that all debug options need to start with -g. Let's spell things out, please.

@adrian-prantl
Copy link
Contributor

Internally, the codeview mode should be a flag that is orthogonal to the debug info level.
For the driver, I think we could have -gcodeview that only switches from DWARF to codeview and specify that in addition to whatever other -g options are present (e.g., -gcode-view -gline-tables-only, -gcode-view -g).

@adrian-prantl
Copy link
Contributor

I really don't want to carry over Clang's idea that all debug options need to start with -g. Let's spell things out, please.

I'm fine with a -debug-info-format=codeview option for this, but generally I'd rather keep -g and -gline-tables-only for consistency with many, many other compilers.

@jrose-apple
Copy link
Contributor

Yeah, the various -g options as mutually-exclusive modes bothers me less.

@ellishg
Copy link
Contributor Author

ellishg commented May 29, 2018

So, we want to use -debug-info-format=codeview rather than -gcodeview?

@adrian-prantl
Copy link
Contributor

-debug-info-format=[codeview|dwarf] with the default either being dwarf or depending on the host os seems reasonable to me. Let me know if anyone has a better idea for naming.

@ellishg
Copy link
Contributor Author

ellishg commented May 29, 2018

Should -debug-info-format=codeview imply -g? Or is it reasonable to assume they will be used together?

@adrian-prantl
Copy link
Contributor

I think it's cleaner for it not to imply -g.

Copy link
Member

@compnerd compnerd left a 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.

else {
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
A->getAsString(Args), A->getValue());
return;
Copy link
Member

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.

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 don't think I can use StringSwitch after moving CodeViewTypes out of IRGenDwarfDebugInfoKind.

@@ -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"))
Copy link
Member

Choose a reason for hiding this comment

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

Same.

@@ -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.
Copy link
Member

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.

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 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?

Copy link
Contributor

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.

@ellishg ellishg force-pushed the gcodeview branch 3 times, most recently from f79c4b8 to d7985d4 Compare May 30, 2018 22:26
@compnerd
Copy link
Member

@adrian-prantl @jrose-apple - do we really want the driver level option to be -debug-info-format? I think that having -gdwarf and -gcodeview is kinda nice to bring over those who have familiarity with gcc/clang.

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
Copy link
Member

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.

@compnerd compnerd dismissed their stale review May 31, 2018 18:31

out of date

@adrian-prantl
Copy link
Contributor

do we really want the driver level option to be -debug-info-format? I think that having -gdwarf and -gcodeview is kinda nice to bring over those who have familiarity with gcc/clang.

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.

IRGenDwarfDebugInfoKind DwarfInfoKind : 2;

/// Whether we should emit codeview debug info.
IRGenCodeViewDebugInfo CodeViewInfo : 1;
Copy link
Contributor

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?

Copy link
Member

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.

Copy link
Contributor

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.)

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"))
Copy link
Contributor

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.

else {
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
A->getAsString(Args), A->getValue());
return;
Copy link
Contributor

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.)

@ellishg
Copy link
Contributor Author

ellishg commented Jun 14, 2018

@jrose-apple Any other changes you would like to see?

Copy link
Contributor

@jrose-apple jrose-apple left a 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?

Diags.diagnose(SourceLoc(), diag::error_option_missing_required_argument,
debugFormatArg->getAsString(Args), "-g");
} else if (OI.DebugInfoFormat == IRGenDebugInfoFormat::CodeView &&
OI.DebugInfoLevel != IRGenDebugInfoLevel::Normal) {
Copy link
Contributor

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.)

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 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.

Copy link
Contributor Author

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?

Copy link
Contributor

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".

Copy link
Contributor

@adrian-prantl adrian-prantl left a 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).

// If -g was specified but not -debug-info-format, DWARF is assumed.
Opts.DebugInfoFormat = IRGenDebugInfoFormat::DWARF;
}
if (Opts.DebugInfoFormat > IRGenDebugInfoFormat::None &&
Copy link
Contributor

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.

@@ -47,14 +47,20 @@ enum class IRGenOutputKind : unsigned {
ObjectFile
};

enum class IRGenDebugInfoKind : unsigned {
enum class IRGenDebugInfoLevel : unsigned {
None, /// No debug info.
Copy link
Contributor

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.

@ellishg ellishg force-pushed the gcodeview branch 4 times, most recently from 0294524 to 4c3920e Compare June 14, 2018 17:56
@ellishg
Copy link
Contributor Author

ellishg commented Jun 14, 2018

Any final nitpicks?

@jrose-apple
Copy link
Contributor

Ah, there's conflicts now, so you'll have to rebase to resolve those.

@jrose-apple
Copy link
Contributor

Or that, I guess.

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 64bf3393b2f03608ad454dc477d6621ad705227c

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 4cbdf4bb4a509143e0e1cbf5338df33f16aacbe4

@jrose-apple jrose-apple self-assigned this Jun 14, 2018
@jrose-apple
Copy link
Contributor

Looks like you'll need to do an update to LLDB too. We can then test and land them together.

@ellishg
Copy link
Contributor Author

ellishg commented Jun 16, 2018

What do you mean do an update to LLDB?

@jrose-apple
Copy link
Contributor

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).

@ellishg
Copy link
Contributor Author

ellishg commented Jun 19, 2018

@jrose-apple Can we test LLDB (apple/swift-lldb#697) and swift together?

@adrian-prantl
Copy link
Contributor

test with apple/swift-lldb#697
@swift-ci test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 59a7406f2e8097968052c42aee8e50f5544c8c43

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 59a7406f2e8097968052c42aee8e50f5544c8c43

@jrose-apple jrose-apple merged commit c93a5a5 into swiftlang:master Jun 20, 2018
@jrose-apple
Copy link
Contributor

Thanks, Ellis!

@ellishg
Copy link
Contributor Author

ellishg commented Jun 20, 2018

Thank you for all your help!

@ellishg ellishg deleted the gcodeview branch June 22, 2018 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants