Change CodeGen to use .loc directives. This produces a lot more readable output

and testing is easier.  A good example is the unknown-location.ll test that
now can just look for ".loc 1 0 0".  We also don't use a DW_LNE_set_address for
every address change anymore.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119613 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2010-11-18 02:04:25 +00:00
parent 5c71c7a137
commit 5c0556341e
7 changed files with 29 additions and 341 deletions

View File

@ -237,10 +237,6 @@ namespace llvm {
/// HasLEB128 - True if target asm supports leb128 directives.
bool HasLEB128; // Defaults to false.
/// hasDotLocAndDotFile - True if target asm supports .loc and .file
/// directives for emitting debugging information.
bool HasDotLocAndDotFile; // Defaults to false.
/// SupportsDebugInformation - True if target supports emission of debugging
/// information.
bool SupportsDebugInformation; // Defaults to false.
@ -410,9 +406,6 @@ namespace llvm {
bool hasLEB128() const {
return HasLEB128;
}
bool hasDotLocAndDotFile() const {
return HasDotLocAndDotFile;
}
bool doesSupportDebugInformation() const {
return SupportsDebugInformation;
}

View File

@ -514,8 +514,7 @@ void DwarfDebug::addSourceLine(DIE *Die, DIVariable V) {
unsigned Line = V.getLineNumber();
if (Line == 0)
return;
unsigned FileID = GetOrCreateSourceID(V.getContext().getDirectory(),
V.getContext().getFilename());
unsigned FileID = GetOrCreateSourceID(V.getContext().getFilename());
assert(FileID && "Invalid file id");
addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID);
addUInt(Die, dwarf::DW_AT_decl_line, 0, Line);
@ -531,8 +530,7 @@ void DwarfDebug::addSourceLine(DIE *Die, DIGlobalVariable G) {
unsigned Line = G.getLineNumber();
if (Line == 0)
return;
unsigned FileID = GetOrCreateSourceID(G.getContext().getDirectory(),
G.getContext().getFilename());
unsigned FileID = GetOrCreateSourceID(G.getContext().getFilename());
assert(FileID && "Invalid file id");
addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID);
addUInt(Die, dwarf::DW_AT_decl_line, 0, Line);
@ -551,8 +549,7 @@ void DwarfDebug::addSourceLine(DIE *Die, DISubprogram SP) {
unsigned Line = SP.getLineNumber();
if (!SP.getContext().Verify())
return;
unsigned FileID = GetOrCreateSourceID(SP.getDirectory(),
SP.getFilename());
unsigned FileID = GetOrCreateSourceID(SP.getFilename());
assert(FileID && "Invalid file id");
addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID);
addUInt(Die, dwarf::DW_AT_decl_line, 0, Line);
@ -568,8 +565,7 @@ void DwarfDebug::addSourceLine(DIE *Die, DIType Ty) {
unsigned Line = Ty.getLineNumber();
if (Line == 0 || !Ty.getContext().Verify())
return;
unsigned FileID = GetOrCreateSourceID(Ty.getDirectory(),
Ty.getFilename());
unsigned FileID = GetOrCreateSourceID(Ty.getFilename());
assert(FileID && "Invalid file id");
addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID);
addUInt(Die, dwarf::DW_AT_decl_line, 0, Line);
@ -586,9 +582,8 @@ void DwarfDebug::addSourceLine(DIE *Die, DINameSpace NS) {
if (Line == 0)
return;
StringRef FN = NS.getFilename();
StringRef Dir = NS.getDirectory();
unsigned FileID = GetOrCreateSourceID(Dir, FN);
unsigned FileID = GetOrCreateSourceID(FN);
assert(FileID && "Invalid file id");
addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID);
addUInt(Die, dwarf::DW_AT_decl_line, 0, Line);
@ -1772,41 +1767,21 @@ DIE *DwarfDebug::constructScopeDIE(DbgScope *Scope) {
/// source file names. If none currently exists, create a new id and insert it
/// in the SourceIds map. This can update DirectoryNames and SourceFileNames
/// maps as well.
unsigned DwarfDebug::GetOrCreateSourceID(StringRef DirName, StringRef FileName){
unsigned DId;
assert (DirName.empty() == false && "Invalid directory name!");
unsigned DwarfDebug::GetOrCreateSourceID(StringRef FileName){
// If FE did not provide a file name, then assume stdin.
if (FileName.empty())
return GetOrCreateSourceID(DirName, "<stdin>");
return GetOrCreateSourceID("<stdin>");
StringMap<unsigned>::iterator DI = DirectoryIdMap.find(DirName);
if (DI != DirectoryIdMap.end()) {
DId = DI->getValue();
} else {
DId = DirectoryNames.size() + 1;
DirectoryIdMap[DirName] = DId;
DirectoryNames.push_back(DirName);
}
StringMapEntry<unsigned> &Entry = SourceIdMap.GetOrCreateValue(FileName);
if (Entry.getValue())
return Entry.getValue();
unsigned FId;
StringMap<unsigned>::iterator FI = SourceFileIdMap.find(FileName);
if (FI != SourceFileIdMap.end()) {
FId = FI->getValue();
} else {
FId = SourceFileNames.size() + 1;
SourceFileIdMap[FileName] = FId;
SourceFileNames.push_back(FileName);
}
unsigned SrcId = SourceIdMap.size();
Entry.setValue(SrcId);
DenseMap<std::pair<unsigned, unsigned>, unsigned>::iterator SI =
SourceIdMap.find(std::make_pair(DId, FId));
if (SI != SourceIdMap.end())
return SI->second;
unsigned SrcId = SourceIds.size() + 1; // DW_AT_decl_file cannot be 0.
SourceIdMap[std::make_pair(DId, FId)] = SrcId;
SourceIds.push_back(std::make_pair(DId, FId));
// Print out a .file directive to specify files for .loc directives.
Asm->OutStreamer.EmitDwarfFileDirective(SrcId, FileName);
return SrcId;
}
@ -1832,7 +1807,7 @@ void DwarfDebug::constructCompileUnit(const MDNode *N) {
DICompileUnit DIUnit(N);
StringRef FN = DIUnit.getFilename();
StringRef Dir = DIUnit.getDirectory();
unsigned ID = GetOrCreateSourceID(Dir, FN);
unsigned ID = GetOrCreateSourceID(FN);
DIE *Die = new DIE(dwarf::DW_TAG_compile_unit);
addString(Die, dwarf::DW_AT_producer, dwarf::DW_FORM_string,
@ -2079,23 +2054,6 @@ void DwarfDebug::beginModule(Module *M) {
// Prime section data.
SectionMap.insert(Asm->getObjFileLowering().getTextSection());
// Print out .file directives to specify files for .loc directives. These are
// printed out early so that they precede any .loc directives.
if (Asm->MAI->hasDotLocAndDotFile()) {
for (unsigned i = 1, e = getNumSourceIds()+1; i != e; ++i) {
// Remember source id starts at 1.
std::pair<unsigned, unsigned> Id = getSourceDirectoryAndFileIds(i);
// FIXME: don't use sys::path for this! This should not depend on the
// host.
sys::Path FullPath(getSourceDirectoryName(Id.first));
bool AppendOk =
FullPath.appendComponent(getSourceFileName(Id.second));
assert(AppendOk && "Could not append filename to directory!");
AppendOk = false;
Asm->OutStreamer.EmitDwarfFileDirective(i, FullPath.str());
}
}
}
/// endModule - Emit all Dwarf sections that should come after the content.
@ -2185,9 +2143,6 @@ void DwarfDebug::endModule() {
// Corresponding abbreviations into a abbrev section.
emitAbbreviations();
// Emit source line correspondence into a debug line section.
emitDebugLines();
// Emit info into a debug pubnames section.
emitDebugPubNames();
@ -2873,17 +2828,6 @@ void DwarfDebug::endFunction(const MachineFunction *MF) {
SmallPtrSet<const MDNode *, 16> ProcessedVars;
collectVariableInfo(MF, ProcessedVars);
// Get function line info.
if (!Lines.empty()) {
// Get section line info.
unsigned ID = SectionMap.insert(Asm->getCurrentSection());
if (SectionSourceLines.size() < ID) SectionSourceLines.resize(ID);
std::vector<SrcLineInfo> &SectionLineInfos = SectionSourceLines[ID-1];
// Append the function info to section info.
SectionLineInfos.insert(SectionLineInfos.end(),
Lines.begin(), Lines.end());
}
// Construct abstract scopes.
for (SmallVector<DbgScope *, 4>::iterator AI = AbstractScopesList.begin(),
AE = AbstractScopesList.end(); AI != AE; ++AI) {
@ -2934,7 +2878,6 @@ void DwarfDebug::endFunction(const MachineFunction *MF) {
AbstractVariables.clear();
LabelsBeforeInsn.clear();
LabelsAfterInsn.clear();
Lines.clear();
PrevLabel = NULL;
}
@ -2981,7 +2924,6 @@ DbgScope *DwarfDebug::findDbgScope(const MachineInstr *MInsn) {
/// the source line list.
MCSymbol *DwarfDebug::recordSourceLine(unsigned Line, unsigned Col,
const MDNode *S) {
StringRef Dir;
StringRef Fn;
unsigned Src = 1;
@ -2990,29 +2932,26 @@ MCSymbol *DwarfDebug::recordSourceLine(unsigned Line, unsigned Col,
if (Scope.isCompileUnit()) {
DICompileUnit CU(S);
Dir = CU.getDirectory();
Fn = CU.getFilename();
} else if (Scope.isFile()) {
DIFile F(S);
Dir = F.getDirectory();
Fn = F.getFilename();
} else if (Scope.isSubprogram()) {
DISubprogram SP(S);
Dir = SP.getDirectory();
Fn = SP.getFilename();
} else if (Scope.isLexicalBlock()) {
DILexicalBlock DB(S);
Dir = DB.getDirectory();
Fn = DB.getFilename();
} else
assert(0 && "Unexpected scope info");
Src = GetOrCreateSourceID(Dir, Fn);
Src = GetOrCreateSourceID(Fn);
}
MCSymbol *Label = MMI->getContext().CreateTempSymbol();
Lines.push_back(SrcLineInfo(Line, Col, Src, Label));
Asm->OutStreamer.EmitDwarfLocDirective(Src, Line, Col, DWARF2_FLAG_IS_STMT,
0, 0);
MCSymbol *Label = MMI->getContext().CreateTempSymbol();
Asm->OutStreamer.EmitLabel(Label);
return Label;
}
@ -3323,185 +3262,6 @@ void DwarfDebug::emitEndOfLineMatrix(unsigned SectionEnd) {
Asm->EmitInt8(1);
}
/// emitDebugLines - Emit source line information.
///
void DwarfDebug::emitDebugLines() {
// If the target is using .loc/.file, the assembler will be emitting the
// .debug_line table automatically.
if (Asm->MAI->hasDotLocAndDotFile())
return;
// Minimum line delta, thus ranging from -10..(255-10).
const int MinLineDelta = -(dwarf::DW_LNS_fixed_advance_pc + 1);
// Maximum line delta, thus ranging from -10..(255-10).
const int MaxLineDelta = 255 + MinLineDelta;
// Start the dwarf line section.
Asm->OutStreamer.SwitchSection(
Asm->getObjFileLowering().getDwarfLineSection());
// Construct the section header.
Asm->OutStreamer.AddComment("Length of Source Line Info");
Asm->EmitLabelDifference(Asm->GetTempSymbol("line_end"),
Asm->GetTempSymbol("line_begin"), 4);
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("line_begin"));
Asm->OutStreamer.AddComment("DWARF version number");
Asm->EmitInt16(dwarf::DWARF_VERSION);
Asm->OutStreamer.AddComment("Prolog Length");
Asm->EmitLabelDifference(Asm->GetTempSymbol("line_prolog_end"),
Asm->GetTempSymbol("line_prolog_begin"), 4);
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("line_prolog_begin"));
Asm->OutStreamer.AddComment("Minimum Instruction Length");
Asm->EmitInt8(1);
Asm->OutStreamer.AddComment("Default is_stmt_start flag");
Asm->EmitInt8(1);
Asm->OutStreamer.AddComment("Line Base Value (Special Opcodes)");
Asm->EmitInt8(MinLineDelta);
Asm->OutStreamer.AddComment("Line Range Value (Special Opcodes)");
Asm->EmitInt8(MaxLineDelta);
Asm->OutStreamer.AddComment("Special Opcode Base");
Asm->EmitInt8(-MinLineDelta);
// Line number standard opcode encodings argument count
Asm->OutStreamer.AddComment("DW_LNS_copy arg count");
Asm->EmitInt8(0);
Asm->OutStreamer.AddComment("DW_LNS_advance_pc arg count");
Asm->EmitInt8(1);
Asm->OutStreamer.AddComment("DW_LNS_advance_line arg count");
Asm->EmitInt8(1);
Asm->OutStreamer.AddComment("DW_LNS_set_file arg count");
Asm->EmitInt8(1);
Asm->OutStreamer.AddComment("DW_LNS_set_column arg count");
Asm->EmitInt8(1);
Asm->OutStreamer.AddComment("DW_LNS_negate_stmt arg count");
Asm->EmitInt8(0);
Asm->OutStreamer.AddComment("DW_LNS_set_basic_block arg count");
Asm->EmitInt8(0);
Asm->OutStreamer.AddComment("DW_LNS_const_add_pc arg count");
Asm->EmitInt8(0);
Asm->OutStreamer.AddComment("DW_LNS_fixed_advance_pc arg count");
Asm->EmitInt8(1);
// Emit directories.
for (unsigned DI = 1, DE = getNumSourceDirectories()+1; DI != DE; ++DI) {
const std::string &Dir = getSourceDirectoryName(DI);
if (Asm->isVerbose()) Asm->OutStreamer.AddComment("Directory");
Asm->OutStreamer.EmitBytes(StringRef(Dir.c_str(), Dir.size()+1), 0);
}
Asm->OutStreamer.AddComment("End of directories");
Asm->EmitInt8(0);
// Emit files.
for (unsigned SI = 1, SE = getNumSourceIds()+1; SI != SE; ++SI) {
// Remember source id starts at 1.
std::pair<unsigned, unsigned> Id = getSourceDirectoryAndFileIds(SI);
const std::string &FN = getSourceFileName(Id.second);
if (Asm->isVerbose()) Asm->OutStreamer.AddComment("Source");
Asm->OutStreamer.EmitBytes(StringRef(FN.c_str(), FN.size()+1), 0);
Asm->EmitULEB128(Id.first, "Directory #");
Asm->EmitULEB128(0, "Mod date");
Asm->EmitULEB128(0, "File size");
}
Asm->OutStreamer.AddComment("End of files");
Asm->EmitInt8(0);
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("line_prolog_end"));
// A sequence for each text section.
unsigned SecSrcLinesSize = SectionSourceLines.size();
for (unsigned j = 0; j < SecSrcLinesSize; ++j) {
// Isolate current sections line info.
const std::vector<SrcLineInfo> &LineInfos = SectionSourceLines[j];
// Dwarf assumes we start with first line of first source file.
unsigned Source = 1;
unsigned Line = 1;
// Construct rows of the address, source, line, column matrix.
for (unsigned i = 0, N = LineInfos.size(); i < N; ++i) {
const SrcLineInfo &LineInfo = LineInfos[i];
MCSymbol *Label = LineInfo.getLabel();
if (!Label->isDefined()) continue; // Not emitted, in dead code.
if (Asm->isVerbose()) {
std::pair<unsigned, unsigned> SrcID =
getSourceDirectoryAndFileIds(LineInfo.getSourceID());
Asm->OutStreamer.AddComment(Twine(getSourceDirectoryName(SrcID.first)) +
"/" +
Twine(getSourceFileName(SrcID.second)) +
":" + Twine(LineInfo.getLine()));
}
// Define the line address.
Asm->OutStreamer.AddComment("Extended Op");
Asm->EmitInt8(0);
Asm->OutStreamer.AddComment("Op size");
Asm->EmitInt8(Asm->getTargetData().getPointerSize() + 1);
Asm->OutStreamer.AddComment("DW_LNE_set_address");
Asm->EmitInt8(dwarf::DW_LNE_set_address);
Asm->OutStreamer.AddComment("Location label");
Asm->OutStreamer.EmitSymbolValue(Label,
Asm->getTargetData().getPointerSize(),
0/*AddrSpace*/);
// If change of source, then switch to the new source.
if (Source != LineInfo.getSourceID()) {
Source = LineInfo.getSourceID();
Asm->OutStreamer.AddComment("DW_LNS_set_file");
Asm->EmitInt8(dwarf::DW_LNS_set_file);
Asm->EmitULEB128(Source, "New Source");
}
// If change of line.
if (Line != LineInfo.getLine()) {
// Determine offset.
int Offset = LineInfo.getLine() - Line;
int Delta = Offset - MinLineDelta;
// Update line.
Line = LineInfo.getLine();
// If delta is small enough and in range...
if (Delta >= 0 && Delta < (MaxLineDelta - 1)) {
// ... then use fast opcode.
Asm->OutStreamer.AddComment("Line Delta");
Asm->EmitInt8(Delta - MinLineDelta);
} else {
// ... otherwise use long hand.
Asm->OutStreamer.AddComment("DW_LNS_advance_line");
Asm->EmitInt8(dwarf::DW_LNS_advance_line);
Asm->EmitSLEB128(Offset, "Line Offset");
Asm->OutStreamer.AddComment("DW_LNS_copy");
Asm->EmitInt8(dwarf::DW_LNS_copy);
}
} else {
// Copy the previous row (different address or source)
Asm->OutStreamer.AddComment("DW_LNS_copy");
Asm->EmitInt8(dwarf::DW_LNS_copy);
}
}
emitEndOfLineMatrix(j + 1);
}
if (SecSrcLinesSize == 0)
// Because we're emitting a debug_line section, we still need a line
// table. The linker and friends expect it to exist. If there's nothing to
// put into it, emit an empty table.
emitEndOfLineMatrix(1);
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("line_end"));
}
/// emitCommonDebugFrame - Emit common frame info into a debug frame section.
///
void DwarfDebug::emitCommonDebugFrame() {

View File

@ -94,30 +94,9 @@ class DwarfDebug {
///
std::vector<DIEAbbrev *> Abbreviations;
/// DirectoryIdMap - Directory name to directory id map.
///
StringMap<unsigned> DirectoryIdMap;
/// DirectoryNames - A list of directory names.
SmallVector<std::string, 8> DirectoryNames;
/// SourceFileIdMap - Source file name to source file id map.
///
StringMap<unsigned> SourceFileIdMap;
/// SourceFileNames - A list of source file names.
SmallVector<std::string, 8> SourceFileNames;
/// SourceIdMap - Source id map, i.e. pair of directory id and source file
/// id mapped to a unique id.
DenseMap<std::pair<unsigned, unsigned>, unsigned> SourceIdMap;
/// SourceIds - Reverse map from source id to directory id + file id pair.
///
SmallVector<std::pair<unsigned, unsigned>, 8> SourceIds;
/// Lines - List of source line correspondence.
std::vector<SrcLineInfo> Lines;
StringMap<unsigned> SourceIdMap;
/// DIEBlocks - A list of all the DIEBlocks in use.
std::vector<DIEBlock *> DIEBlocks;
@ -136,10 +115,6 @@ class DwarfDebug {
///
UniqueVector<const MCSection*> SectionMap;
/// SectionSourceLines - Tracks line numbers per text section.
///
std::vector<std::vector<SrcLineInfo> > SectionSourceLines;
// CurrentFnDbgScope - Top level scope for the current function.
//
DbgScope *CurrentFnDbgScope;
@ -263,35 +238,10 @@ class DwarfDebug {
DIEInteger *DIEIntegerOne;
private:
/// getSourceDirectoryAndFileIds - Return the directory and file ids that
/// maps to the source id. Source id starts at 1.
std::pair<unsigned, unsigned>
getSourceDirectoryAndFileIds(unsigned SId) const {
return SourceIds[SId-1];
}
/// getNumSourceDirectories - Return the number of source directories in the
/// debug info.
unsigned getNumSourceDirectories() const {
return DirectoryNames.size();
}
/// getSourceDirectoryName - Return the name of the directory corresponding
/// to the id.
const std::string &getSourceDirectoryName(unsigned Id) const {
return DirectoryNames[Id - 1];
}
/// getSourceFileName - Return the name of the source file corresponding
/// to the id.
const std::string &getSourceFileName(unsigned Id) const {
return SourceFileNames[Id - 1];
}
/// getNumSourceIds - Return the number of unique source ids.
unsigned getNumSourceIds() const {
return SourceIds.size();
return SourceIdMap.size();
}
/// assignAbbrevNumber - Define a unique number for the abbreviation.
@ -479,10 +429,6 @@ private:
///
void emitEndOfLineMatrix(unsigned SectionEnd);
/// emitDebugLines - Emit source line information.
///
void emitDebugLines();
/// emitCommonDebugFrame - Emit common frame info into a debug frame section.
///
void emitCommonDebugFrame();
@ -541,9 +487,8 @@ private:
/// GetOrCreateSourceID - Look up the source id with the given directory and
/// source file names. If none currently exists, create a new id and insert it
/// in the SourceIds map. This can update DirectoryNames and SourceFileNames
/// maps as well.
unsigned GetOrCreateSourceID(StringRef DirName, StringRef FileName);
/// in the SourceIds map.
unsigned GetOrCreateSourceID(StringRef FullName);
/// constructCompileUnit - Create new CompileUnit for the given
/// metadata node with tag DW_TAG_compile_unit.
@ -563,12 +508,6 @@ private:
/// the source line list.
MCSymbol *recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope);
/// getSourceLineCount - Return the number of source lines in the debug
/// info.
unsigned getSourceLineCount() const {
return Lines.size();
}
/// recordVariableFrameIndex - Record a variable's index.
void recordVariableFrameIndex(const DbgVariable *V, int Index);

View File

@ -64,7 +64,6 @@ MCAsmInfo::MCAsmInfo() {
HiddenVisibilityAttr = MCSA_Hidden;
ProtectedVisibilityAttr = MCSA_Protected;
HasLEB128 = false;
HasDotLocAndDotFile = false;
SupportsDebugInformation = false;
ExceptionsType = ExceptionHandling::None;
DwarfRequiresFrameSection = true;

View File

@ -24,9 +24,8 @@ SPULinuxMCAsmInfo::SPULinuxMCAsmInfo(const Target &T, StringRef TT) {
GlobalPrefix = "";
PrivateGlobalPrefix = ".L";
// Has leb128, .loc and .file
// Has leb128
HasLEB128 = true;
HasDotLocAndDotFile = true;
SupportsDebugInformation = true;

View File

@ -1,15 +1,15 @@
; RUN: llc < %s -asm-verbose=false -march=x86-64 -use-unknown-locations | FileCheck %s
; The divide instruction does not have a debug location. CodeGen should
; represent this in the debug information. This is checked by a check
; for a label between the code for the add and the code for the divide,
; which indicates that the add's location doesn't spill over unto the
; divide.
; represent this in the debug information. This is done by setting line
; and column to 0
; CHECK: leal (%rdi,%rsi), %eax
; CHECK-NEXT: .loc 1 0 0
; CHECK-NEXT: Ltmp
; CHECK-NEXT: cltd
; CHECK-NEXT: idivl %r8d
; CHECK-NEXT: .loc 1 4 3
; CHECK-NEXT: Ltmp
; CHECK-NEXT: addl %ecx, %eax
; CHECK-NEXT: ret

View File

@ -1,8 +1,6 @@
; RUN: llc -O0 < %s - | FileCheck %s
; Radar 8286101
; CHECK: File size
; CHECK-NEXT: stdin
; CHECK-NEXT: Directory
; CHECK: .file 2 "<stdin>"
define i32 @foo() nounwind ssp {
entry: