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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions include/swift/AST/IRGenOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,18 @@ enum class IRGenOutputKind : unsigned {
ObjectFile
};

enum class IRGenDebugInfoKind : unsigned {
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 IRGenDebugInfoLevel : unsigned {
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 IRGenDebugInfoFormat : unsigned {
None,
DWARF,
CodeView
};

enum class IRGenEmbedMode : unsigned {
Expand All @@ -72,8 +78,8 @@ class IRGenOptions {
/// The DWARF version of debug info.
unsigned DWARFVersion;

/// The command line string that is to be stored in the DWARF debug info.
std::string DWARFDebugFlags;
/// The command line string that is to be stored in the debug info.
std::string DebugFlags;

/// List of -Xcc -D macro definitions.
std::vector<std::string> ClangDefines;
Expand All @@ -97,8 +103,11 @@ class IRGenOptions {
/// Which sanitizer is turned on.
OptionSet<SanitizerKind> Sanitizers;

/// Whether we should emit debug info.
IRGenDebugInfoKind DebugInfoKind : 2;
/// What level of debug info to generate.
IRGenDebugInfoLevel DebugInfoLevel : 2;

/// What type of debug info to generate.
IRGenDebugInfoFormat DebugInfoFormat : 2;

/// \brief Whether we're generating IR for the JIT.
unsigned UseJIT : 1;
Expand Down Expand Up @@ -184,8 +193,9 @@ class IRGenOptions {
: DWARFVersion(2), OutputKind(IRGenOutputKind::LLVMAssembly),
Verify(true), OptMode(OptimizationMode::NotSet),
Sanitizers(OptionSet<SanitizerKind>()),
DebugInfoKind(IRGenDebugInfoKind::None), UseJIT(false),
IntegratedREPL(false),
DebugInfoLevel(IRGenDebugInfoLevel::None),
DebugInfoFormat(IRGenDebugInfoFormat::None),
UseJIT(false), IntegratedREPL(false),
DisableLLVMOptzns(false), DisableSwiftSpecificLLVMOptzns(false),
DisableLLVMSLPVectorizer(false), DisableFPElim(true), Playground(false),
EmitStackPromotionChecks(false), PrintInlineTree(false),
Expand Down
5 changes: 4 additions & 1 deletion include/swift/Driver/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ class OutputInfo {

/// Whether or not the output should contain debug info.
// FIXME: Eventually this should be replaced by dSYM generation.
IRGenDebugInfoKind DebugInfoKind = IRGenDebugInfoKind::None;
IRGenDebugInfoLevel DebugInfoLevel = IRGenDebugInfoLevel::None;

/// What kind of debug info to generate.
IRGenDebugInfoFormat DebugInfoFormat = IRGenDebugInfoFormat::None;

/// Whether or not the driver should generate a module.
bool ShouldGenerateModule = false;
Expand Down
10 changes: 5 additions & 5 deletions include/swift/Frontend/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ class CompilerInvocation {
serialization::Status loadFromSerializedAST(StringRef data);

/// Serialize the command line arguments for emitting them
/// to DWARF and inject SDKPath if necessary.
static void buildDWARFDebugFlags(std::string &Output,
const ArrayRef<const char*> &Args,
StringRef SDKPath,
StringRef ResourceDir);
/// to DWARF or CodeView and inject SDKPath if necessary.
static void buildDebugFlags(std::string &Output,
const ArrayRef<const char*> &Args,
StringRef SDKPath,
StringRef ResourceDir);

void setTargetTriple(StringRef Triple);

Expand Down
4 changes: 4 additions & 0 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,10 @@ def gdwarf_types : Flag<["-"], "gdwarf-types">,
Group<g_Group>, Flags<[FrontendOption]>,
HelpText<"Emit full DWARF type info.">;

def debug_info_format : Joined<["-"], "debug-info-format=">,
Flags<[FrontendOption]>,
HelpText<"Specify the debug info format type to either 'dwarf' or 'codeview'">;

// Verify debug info
def verify_debug_info : Flag<["-"], "verify-debug-info">,
Flags<[NoInteractiveOption, DoesNotAffectIncrementalBuild]>,
Expand Down
41 changes: 35 additions & 6 deletions lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1369,22 +1369,51 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args,

if (const Arg *A = Args.getLastArg(options::OPT_g_Group)) {
if (A->getOption().matches(options::OPT_g))
OI.DebugInfoKind = IRGenDebugInfoKind::Normal;
OI.DebugInfoLevel = IRGenDebugInfoLevel::Normal;
else if (A->getOption().matches(options::OPT_gline_tables_only))
OI.DebugInfoKind = IRGenDebugInfoKind::LineTables;
OI.DebugInfoLevel = IRGenDebugInfoLevel::LineTables;
else if (A->getOption().matches(options::OPT_gdwarf_types))
OI.DebugInfoKind = IRGenDebugInfoKind::DwarfTypes;
OI.DebugInfoLevel = IRGenDebugInfoLevel::DwarfTypes;
else
assert(A->getOption().matches(options::OPT_gnone) &&
"unknown -g<kind> option");
}

if (const Arg *A = Args.getLastArg(options::OPT_debug_info_format)) {
if (strcmp(A->getValue(), "dwarf") == 0)
OI.DebugInfoFormat = IRGenDebugInfoFormat::DWARF;
else if (strcmp(A->getValue(), "codeview") == 0)
OI.DebugInfoFormat = IRGenDebugInfoFormat::CodeView;
else
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
A->getAsString(Args), A->getValue());
} else if (OI.DebugInfoLevel > IRGenDebugInfoLevel::None) {
// If -g was specified but not -debug-info-format, DWARF is assumed.
OI.DebugInfoFormat = IRGenDebugInfoFormat::DWARF;
}
if (Args.hasArg(options::OPT_debug_info_format) &&
!Args.hasArg(options::OPT_g_Group)) {
const Arg *debugFormatArg = Args.getLastArg(options::OPT_debug_info_format);
Diags.diagnose(SourceLoc(), diag::error_option_missing_required_argument,
debugFormatArg->getAsString(Args), "-g");
}
if (OI.DebugInfoFormat == IRGenDebugInfoFormat::CodeView &&
(OI.DebugInfoLevel == IRGenDebugInfoLevel::LineTables ||
OI.DebugInfoLevel == IRGenDebugInfoLevel::DwarfTypes)) {
const Arg *debugFormatArg = Args.getLastArg(options::OPT_debug_info_format);
Diags.diagnose(SourceLoc(), diag::error_argument_not_allowed_with,
debugFormatArg->getAsString(Args),
OI.DebugInfoLevel == IRGenDebugInfoLevel::LineTables
? "-gline-tables-only"
: "-gdwarf_types");
}

if (Args.hasArg(options::OPT_emit_module, options::OPT_emit_module_path)) {
// The user has requested a module, so generate one and treat it as
// top-level output.
OI.ShouldGenerateModule = true;
OI.ShouldTreatModuleAsTopLevelOutput = true;
} else if ((OI.DebugInfoKind > IRGenDebugInfoKind::LineTables &&
} else if ((OI.DebugInfoLevel > IRGenDebugInfoLevel::LineTables &&
OI.shouldLink()) ||
Args.hasArg(options::OPT_emit_objc_header,
options::OPT_emit_objc_header_path)) {
Expand Down Expand Up @@ -1806,7 +1835,7 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
}

if (MergeModuleAction) {
if (OI.DebugInfoKind == IRGenDebugInfoKind::Normal) {
if (OI.DebugInfoLevel == IRGenDebugInfoLevel::Normal) {
if (TC.getTriple().getObjectFormat() == llvm::Triple::ELF) {
auto *ModuleWrapAction =
C.createAction<ModuleWrapJobAction>(MergeModuleAction);
Expand All @@ -1823,7 +1852,7 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
TopLevelActions.push_back(LinkAction);

if (TC.getTriple().isOSDarwin() &&
OI.DebugInfoKind > IRGenDebugInfoKind::None) {
OI.DebugInfoLevel > IRGenDebugInfoLevel::None) {
auto *dSYMAction = C.createAction<GenerateDSYMJobAction>(LinkAction);
TopLevelActions.push_back(dSYMAction);
if (Args.hasArg(options::OPT_verify_debug_info)) {
Expand Down
1 change: 1 addition & 0 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ static void addCommonFrontendArgs(const ToolChain &TC, const OutputInfo &OI,
inputArgs.AddLastArg(arguments, options::OPT_enable_app_extension);
inputArgs.AddLastArg(arguments, options::OPT_enable_testing);
inputArgs.AddLastArg(arguments, options::OPT_g_Group);
inputArgs.AddLastArg(arguments, options::OPT_debug_info_format);
inputArgs.AddLastArg(arguments, options::OPT_import_underlying_module);
inputArgs.AddLastArg(arguments, options::OPT_module_cache_path);
inputArgs.AddLastArg(arguments, options::OPT_module_link_name);
Expand Down
3 changes: 3 additions & 0 deletions lib/Driver/WindowsToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ toolchains::Windows::constructInvocation(const LinkJobAction &job,
if (!Linker.empty())
Arguments.push_back(context.Args.MakeArgString("-fuse-ld=" + Linker));

if (context.OI.DebugInfoFormat == IRGenDebugInfoFormat::CodeView)
Arguments.push_back("-Wl,/DEBUG");

// Configure the toolchain.
// By default, use the system clang++ to link.
const char *Clang = nullptr;
Expand Down
53 changes: 41 additions & 12 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,10 +711,10 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
return false;
}

void CompilerInvocation::buildDWARFDebugFlags(std::string &Output,
const ArrayRef<const char*> &Args,
StringRef SDKPath,
StringRef ResourceDir) {
void CompilerInvocation::buildDebugFlags(std::string &Output,
const ArrayRef<const char*> &Args,
StringRef SDKPath,
StringRef ResourceDir) {
// This isn't guaranteed to be the same temp directory as what the driver
// uses, but it's highly likely.
llvm::SmallString<128> TDir;
Expand Down Expand Up @@ -756,26 +756,26 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
using namespace options;

if (!SILOpts.SILOutputFileNameForDebugging.empty()) {
Opts.DebugInfoKind = IRGenDebugInfoKind::LineTables;
Opts.DebugInfoLevel = IRGenDebugInfoLevel::LineTables;
} else if (const Arg *A = Args.getLastArg(OPT_g_Group)) {
if (A->getOption().matches(OPT_g))
Opts.DebugInfoKind = IRGenDebugInfoKind::Normal;
Opts.DebugInfoLevel = IRGenDebugInfoLevel::Normal;
else if (A->getOption().matches(options::OPT_gline_tables_only))
Opts.DebugInfoKind = IRGenDebugInfoKind::LineTables;
Opts.DebugInfoLevel = IRGenDebugInfoLevel::LineTables;
else if (A->getOption().matches(options::OPT_gdwarf_types))
Opts.DebugInfoKind = IRGenDebugInfoKind::DwarfTypes;
Opts.DebugInfoLevel = IRGenDebugInfoLevel::DwarfTypes;
else
assert(A->getOption().matches(options::OPT_gnone) &&
"unknown -g<kind> option");

if (Opts.DebugInfoKind > IRGenDebugInfoKind::LineTables) {
if (Opts.DebugInfoLevel > IRGenDebugInfoLevel::LineTables) {
if (Args.hasArg(options::OPT_debug_info_store_invocation)) {
ArgStringList RenderedArgs;
for (auto A : Args)
A->render(Args, RenderedArgs);
CompilerInvocation::buildDWARFDebugFlags(Opts.DWARFDebugFlags,
RenderedArgs, SDKPath,
ResourceDir);
CompilerInvocation::buildDebugFlags(Opts.DebugFlags,
RenderedArgs, SDKPath,
ResourceDir);
}
// TODO: Should we support -fdebug-compilation-dir?
llvm::SmallString<256> cwd;
Expand All @@ -784,6 +784,35 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
}
}

if (const Arg *A = Args.getLastArg(options::OPT_debug_info_format)) {
if (A->containsValue("dwarf"))
Opts.DebugInfoFormat = IRGenDebugInfoFormat::DWARF;
else if (A->containsValue("codeview"))
Opts.DebugInfoFormat = IRGenDebugInfoFormat::CodeView;
else
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
A->getAsString(Args), A->getValue());
} else if (Opts.DebugInfoLevel > IRGenDebugInfoLevel::None) {
// If -g was specified but not -debug-info-format, DWARF is assumed.
Opts.DebugInfoFormat = IRGenDebugInfoFormat::DWARF;
}
if (Args.hasArg(options::OPT_debug_info_format) &&
!Args.hasArg(options::OPT_g_Group)) {
const Arg *debugFormatArg = Args.getLastArg(options::OPT_debug_info_format);
Diags.diagnose(SourceLoc(), diag::error_option_missing_required_argument,
debugFormatArg->getAsString(Args), "-g");
}
if (Opts.DebugInfoFormat == IRGenDebugInfoFormat::CodeView &&
(Opts.DebugInfoLevel == IRGenDebugInfoLevel::LineTables ||
Opts.DebugInfoLevel == IRGenDebugInfoLevel::DwarfTypes)) {
const Arg *debugFormatArg = Args.getLastArg(options::OPT_debug_info_format);
Diags.diagnose(SourceLoc(), diag::error_argument_not_allowed_with,
debugFormatArg->getAsString(Args),
Opts.DebugInfoLevel == IRGenDebugInfoLevel::LineTables
? "-gline-tables-only"
: "-gdwarf_types");
}

for (const Arg *A : Args.filtered(OPT_Xcc)) {
StringRef Opt = A->getValue();
if (Opt.startswith("-D") || Opt.startswith("-U"))
Expand Down
11 changes: 6 additions & 5 deletions lib/FrontendTool/FrontendTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,14 +1070,14 @@ static void performSILOptimizations(CompilerInvocation &Invocation,
/// the compile unit's flags.
static void setPrivateDiscriminatorIfNeeded(IRGenOptions &IRGenOpts,
ModuleOrSourceFile MSF) {
if (IRGenOpts.DebugInfoKind == IRGenDebugInfoKind::None ||
if (IRGenOpts.DebugInfoLevel == IRGenDebugInfoLevel::None ||
!MSF.is<SourceFile *>())
return;
Identifier PD = MSF.get<SourceFile *>()->getPrivateDiscriminator();
if (!PD.empty()) {
if (!IRGenOpts.DWARFDebugFlags.empty())
IRGenOpts.DWARFDebugFlags += " ";
IRGenOpts.DWARFDebugFlags += ("-private-discriminator " + PD.str()).str();
if (!IRGenOpts.DebugFlags.empty())
IRGenOpts.DebugFlags += " ";
IRGenOpts.DebugFlags += ("-private-discriminator " + PD.str()).str();
}
}

Expand Down Expand Up @@ -1125,7 +1125,8 @@ static bool processCommandLineAndRunImmediately(CompilerInvocation &Invocation,
assert(!MSF.is<SourceFile *>() && "-i doesn't work in -primary-file mode");
IRGenOptions &IRGenOpts = Invocation.getIRGenOptions();
IRGenOpts.UseJIT = true;
IRGenOpts.DebugInfoKind = IRGenDebugInfoKind::Normal;
IRGenOpts.DebugInfoLevel = IRGenDebugInfoLevel::Normal;
IRGenOpts.DebugInfoFormat = IRGenDebugInfoFormat::DWARF;
const ProcessCmdLine &CmdLine =
ProcessCmdLine(opts.ImmediateArgv.begin(), opts.ImmediateArgv.end());
Instance.setSILModule(std::move(SM));
Expand Down
Loading