DebugInfo: Add (initially no-op) -gsimple-template-names={simple,mangled}

This is to build the foundation of a new debug info feature to use only
the base name of template as its debug info name (eg: "t1" instead of
the full "t1<int>"). The intent being that a consumer can still retrieve
all that information from the DW_TAG_template_*_parameters.

So gno-simple-template-names is business as usual/previously ("t1<int>")
   =simple is the simplified name ("t1")
   =mangled is a special mode to communicate the full information, but
   also indicate that the name should be able to be simplified. The data
   is encoded as "_STNt1|<int>" which will be matched with an
   llvm-dwarfdump --verify feature to deconstruct this name, rebuild the
   original name, and then try to rebuild the simple name via the DWARF
   tags - then compare the latter and the former to ensure that all the
   data necessary to fully rebuild the name is present.
This commit is contained in:
David Blaikie
2021-09-21 20:25:13 -07:00
parent 4355265131
commit 38c09ea2d2
6 changed files with 71 additions and 1 deletions

View File

@@ -320,6 +320,12 @@ CODEGENOPT(DebugFwdTemplateParams, 1, 0) ///< Whether to emit complete
///< template parameter descriptions in
///< forward declarations (versus just
///< including them in the name).
ENUM_CODEGENOPT(DebugSimpleTemplateNames, codegenoptions::DebugTemplateNamesKind, 2, codegenoptions::DebugTemplateNamesKind::Full) ///< Whether to emit template parameters
///< in the textual names of template
///< specializations.
///< Implies DebugFwdTemplateNames to
///< allow decorated names to be
///< reconstructed when needed.
CODEGENOPT(EmitLLVMUseLists, 1, 0) ///< Control whether to serialize use-lists.
CODEGENOPT(WholeProgramVTables, 1, 0) ///< Whether to apply whole-program

View File

@@ -54,6 +54,12 @@ enum DebugInfoKind {
UnusedTypeInfo,
};
enum class DebugTemplateNamesKind {
Full,
Simple,
Mangled
};
} // end namespace codegenoptions
} // end namespace clang

View File

@@ -2967,6 +2967,15 @@ def gsplit_dwarf_EQ : Joined<["-"], "gsplit-dwarf=">, Group<g_flags_Group>,
HelpText<"Set DWARF fission mode to either 'split' or 'single'">,
Values<"split,single">;
def gno_split_dwarf : Flag<["-"], "gno-split-dwarf">, Group<g_flags_Group>;
def gsimple_template_names : Flag<["-"], "gsimple-template-names">, Group<g_flags_Group>;
def gsimple_template_names_EQ
: Joined<["-"], "gsimple-template-names=">,
Group<g_flags_Group>,
HelpText<"Use simple template names in DWARF, or include the full "
"template name with a modified prefix for validation">,
Values<"simple,mangled">, Flags<[CC1Option]>;
def gno_simple_template_names : Flag<["-"], "gno-simple-template-names">,
Group<g_flags_Group>;
def ggnu_pubnames : Flag<["-"], "ggnu-pubnames">, Group<g_flags_Group>, Flags<[CC1Option]>;
def gno_gnu_pubnames : Flag<["-"], "gno-gnu-pubnames">, Group<g_flags_Group>;
def gpubnames : Flag<["-"], "gpubnames">, Group<g_flags_Group>, Flags<[CC1Option]>;

View File

@@ -4128,6 +4128,29 @@ static void renderDebugOptions(const ToolChain &TC, const Driver &D,
options::OPT_gpubnames)
? "-gpubnames"
: "-ggnu-pubnames");
const auto *SimpleTemplateNamesArg =
Args.getLastArg(options::OPT_gsimple_template_names, options::OPT_gno_simple_template_names,
options::OPT_gsimple_template_names_EQ);
bool ForwardTemplateParams = DebuggerTuning == llvm::DebuggerKind::SCE;
if (SimpleTemplateNamesArg &&
checkDebugInfoOption(SimpleTemplateNamesArg, Args, D, TC)) {
const auto &Opt = SimpleTemplateNamesArg->getOption();
if (Opt.matches(options::OPT_gsimple_template_names)) {
ForwardTemplateParams = true;
CmdArgs.push_back("-gsimple-template-names=simple");
} else if (Opt.matches(options::OPT_gsimple_template_names_EQ)) {
ForwardTemplateParams = true;
StringRef Value = SimpleTemplateNamesArg->getValue();
if (Value == "simple") {
CmdArgs.push_back("-gsimple-template-names=simple");
} else if (Value == "mangled") {
CmdArgs.push_back("-gsimple-template-names=mangled");
} else {
D.Diag(diag::err_drv_unsupported_option_argument)
<< Opt.getName() << SimpleTemplateNamesArg->getValue();
}
}
}
if (Args.hasFlag(options::OPT_fdebug_ranges_base_address,
options::OPT_fno_debug_ranges_base_address, false)) {
@@ -4174,7 +4197,7 @@ static void renderDebugOptions(const ToolChain &TC, const Driver &D,
// Decide how to render forward declarations of template instantiations.
// SCE wants full descriptions, others just get them in the name.
if (DebuggerTuning == llvm::DebuggerKind::SCE)
if (ForwardTemplateParams)
CmdArgs.push_back("-debug-forward-template-params");
// Do we need to explicitly import anonymous namespaces into the parent

View File

@@ -1411,6 +1411,14 @@ void CompilerInvocation::GenerateCodeGenArgs(
llvm::DICompileUnit::DebugNameTableKind::Default))
GenerateArg(Args, OPT_gpubnames, SA);
auto TNK = Opts.getDebugSimpleTemplateNames();
if (TNK != codegenoptions::DebugTemplateNamesKind::Full) {
if (TNK == codegenoptions::DebugTemplateNamesKind::Simple)
GenerateArg(Args, OPT_gsimple_template_names_EQ, "simple", SA);
if (TNK == codegenoptions::DebugTemplateNamesKind::Mangled)
GenerateArg(Args, OPT_gsimple_template_names_EQ, "mangled", SA);
}
// ProfileInstrumentUsePath is marshalled automatically, no need to generate
// it or PGOUseInstrumentor.
@@ -1685,6 +1693,12 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
: Args.hasArg(OPT_gpubnames)
? llvm::DICompileUnit::DebugNameTableKind::Default
: llvm::DICompileUnit::DebugNameTableKind::None);
if (const Arg *A = Args.getLastArg(OPT_gsimple_template_names_EQ)) {
Opts.setDebugSimpleTemplateNames(
StringRef(A->getValue()) == "simple"
? codegenoptions::DebugTemplateNamesKind::Simple
: codegenoptions::DebugTemplateNamesKind::Mangled);
}
if (!Opts.ProfileInstrumentUsePath.empty())
setPGOUseInstrumentor(Opts, Opts.ProfileInstrumentUsePath);

View File

@@ -435,3 +435,15 @@
// DIRECTORY-NOT: "-fno-dwarf-directory-asm"
// NODIRECTORY: "-fno-dwarf-directory-asm"
// RUN: %clang -### -target x86_64 -c -g -gsimple-template-names %s 2>&1 | FileCheck --check-prefix=SIMPLE_TEMP_NAMES %s
// RUN: %clang -### -target x86_64 -c -g -gsimple-template-names=simple %s 2>&1 | FileCheck --check-prefix=SIMPLE_TEMP_NAMES %s
// SIMPLE_TEMP_NAMES: -gsimple-template-names=simple
// SIMPLE_TEMP_NAMES: -debug-forward-template-params
// RUN: %clang -### -target x86_64 -c -g -gsimple-template-names=mangled %s 2>&1 | FileCheck --check-prefix=MANGLED_TEMP_NAMES %s
// MANGLED_TEMP_NAMES: -gsimple-template-names=mangled
// MANGLED_TEMP_NAMES: -debug-forward-template-params
// RUN: %clang -### -target x86_64 -c -g %s 2>&1 | FileCheck --check-prefix=FULL_TEMP_NAMES --implicit-check-not=debug-forward-template-params %s
// FULL_TEMP_NAMES-NOT: -gsimple-template-names
// RUN: %clang -### -target x86_64 -c -g -gsimple-template-names=other %s 2>&1 | FileCheck --check-prefix=SIMPLE_TEMP_OTHER %s
// SIMPLE_TEMP_OTHER: error: unsupported argument 'other' to option 'gsimple-template-names='