}
static void DiagHandler(const SMDiagnostic &Diag, void *Context);
+ /// Should we emit DWARF describing this assembler source? (Returns false if
+ /// the source has .file directives, which means we don't want to generate
+ /// info describing the assembler source itself.)
+ bool enabledGenDwarfForAssembly();
+
/// \brief Enter the specified file. This returns true on failure.
bool enterIncludeFile(const std::string &Filename);
return *tok;
}
+bool AsmParser::enabledGenDwarfForAssembly() {
+ // Check whether the user specified -g.
+ if (!getContext().getGenDwarfForAssembly())
+ return false;
+ // If we haven't encountered any .file directives (which would imply that
+ // the assembler source was produced with debug info already) then emit one
+ // describing the assembler source file itself.
+ if (getContext().getGenDwarfFileNumber() == 0)
+ getContext().setGenDwarfFileNumber(getStreamer().EmitDwarfFileDirective(
+ 0, StringRef(), getContext().getMainFileName()));
+ return true;
+}
+
bool AsmParser::Run(bool NoInitialTextSection, bool NoFinalize) {
// Create the initial section, if requested.
if (!NoInitialTextSection)
SmallVector<AsmRewrite, 4> AsmStrRewrites;
// If we are generating dwarf for assembly source files save the initial text
- // section and generate a .file directive.
+ // section. (Don't use enabledGenDwarfForAssembly() here, as we aren't
+ // emitting any actual debug info yet and haven't had a chance to parse any
+ // embedded .file directives.)
if (getContext().getGenDwarfForAssembly()) {
MCSection *Sec = getStreamer().getCurrentSectionOnly();
if (!Sec->getBeginSymbol()) {
bool InsertResult = getContext().addGenDwarfSection(Sec);
assert(InsertResult && ".text section should not have debug info yet");
(void)InsertResult;
- getContext().setGenDwarfFileNumber(getStreamer().EmitDwarfFileDirective(
- 0, StringRef(), getContext().getMainFileName()));
}
// While we have input, parse each statement.
// If we are generating dwarf for assembly source files then gather the
// info to make a dwarf label entry for this label if needed.
- if (getContext().getGenDwarfForAssembly())
+ if (enabledGenDwarfForAssembly())
MCGenDwarfLabelEntry::Make(Sym, &getStreamer(), getSourceManager(),
IDLoc);
// If we are generating dwarf for the current section then generate a .loc
// directive for the instruction.
- if (!ParseHadError && getContext().getGenDwarfForAssembly() &&
+ if (!ParseHadError && enabledGenDwarfForAssembly() &&
getContext().getGenDwarfSectionSyms().count(
getStreamer().getCurrentSectionOnly())) {
unsigned Line;
}
}
+ // In case there is a -g option as well as debug info from directive .file,
+ // we turn off the -g option, directly use the existing debug info instead.
+ getContext().setGenDwarfForAssembly(false);
+
if (FileNumber == -1)
getStreamer().EmitFileDirective(Filename);
else {
memcpy(SourceBuf, SourceString.data(), SourceString.size());
Source = StringRef(SourceBuf, SourceString.size());
}
- // If there is -g option as well as debug info from directive file,
- // we turn off -g option, directly use the existing debug info instead.
- if (getContext().getGenDwarfForAssembly())
- getContext().setGenDwarfForAssembly(false);
- else {
- Expected<unsigned> FileNumOrErr = getStreamer().tryEmitDwarfFileDirective(
- FileNumber, Directory, Filename, CKMem, Source);
- if (!FileNumOrErr)
- return Error(DirectiveLoc, toString(FileNumOrErr.takeError()));
- FileNumber = FileNumOrErr.get();
- }
+ Expected<unsigned> FileNumOrErr = getStreamer().tryEmitDwarfFileDirective(
+ FileNumber, Directory, Filename, CKMem, Source);
+ if (!FileNumOrErr)
+ return Error(DirectiveLoc, toString(FileNumOrErr.takeError()));
+ FileNumber = FileNumOrErr.get();
}
return false;