DwarfUnit: Refactor DW_AT_file creation into a common function.

This is preliminary work to fix type unit file strings so they appear in
their originating CU's line table - but it's also just good/simple
cleanup, so I'm committing it ahead of time.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201195 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Blaikie 2014-02-12 00:11:25 +00:00
parent 19cfb96184
commit a22a1bb8c1
2 changed files with 20 additions and 51 deletions

View File

@ -355,33 +355,31 @@ void DwarfUnit::addBlock(DIE *Die, dwarf::Attribute Attribute,
/// addSourceLine - Add location information to specified debug information
/// entry.
void DwarfUnit::addSourceLine(DIE *Die, DIVariable V) {
assert(V.isVariable());
unsigned Line = V.getLineNumber();
void DwarfUnit::addSourceLine(DIE *Die, unsigned Line, StringRef File,
StringRef Directory) {
if (Line == 0)
return;
unsigned FileID =
DD->getOrCreateSourceID(V.getContext().getFilename(),
V.getContext().getDirectory(), getUniqueID());
unsigned FileID = DD->getOrCreateSourceID(File, Directory, getUniqueID());
assert(FileID && "Invalid file id");
addUInt(Die, dwarf::DW_AT_decl_file, None, FileID);
addUInt(Die, dwarf::DW_AT_decl_line, None, Line);
}
/// addSourceLine - Add location information to specified debug information
/// entry.
void DwarfUnit::addSourceLine(DIE *Die, DIVariable V) {
assert(V.isVariable());
addSourceLine(Die, V.getLineNumber(), V.getContext().getFilename(), V.getContext().getDirectory());
}
/// addSourceLine - Add location information to specified debug information
/// entry.
void DwarfUnit::addSourceLine(DIE *Die, DIGlobalVariable G) {
assert(G.isGlobalVariable());
unsigned Line = G.getLineNumber();
if (Line == 0)
return;
unsigned FileID =
DD->getOrCreateSourceID(G.getFilename(), G.getDirectory(), getUniqueID());
assert(FileID && "Invalid file id");
addUInt(Die, dwarf::DW_AT_decl_file, None, FileID);
addUInt(Die, dwarf::DW_AT_decl_line, None, Line);
addSourceLine(Die, G.getLineNumber(), G.getFilename(), G.getDirectory());
}
/// addSourceLine - Add location information to specified debug information
@ -389,16 +387,7 @@ void DwarfUnit::addSourceLine(DIE *Die, DIGlobalVariable G) {
void DwarfUnit::addSourceLine(DIE *Die, DISubprogram SP) {
assert(SP.isSubprogram());
// If the line number is 0, don't add it.
unsigned Line = SP.getLineNumber();
if (Line == 0)
return;
unsigned FileID = DD->getOrCreateSourceID(SP.getFilename(), SP.getDirectory(),
getUniqueID());
assert(FileID && "Invalid file id");
addUInt(Die, dwarf::DW_AT_decl_file, None, FileID);
addUInt(Die, dwarf::DW_AT_decl_line, None, Line);
addSourceLine(Die, SP.getLineNumber(), SP.getFilename(), SP.getDirectory());
}
/// addSourceLine - Add location information to specified debug information
@ -406,14 +395,7 @@ void DwarfUnit::addSourceLine(DIE *Die, DISubprogram SP) {
void DwarfUnit::addSourceLine(DIE *Die, DIType Ty) {
assert(Ty.isType());
unsigned Line = Ty.getLineNumber();
if (Line == 0)
return;
unsigned FileID = DD->getOrCreateSourceID(Ty.getFilename(), Ty.getDirectory(),
getUniqueID());
assert(FileID && "Invalid file id");
addUInt(Die, dwarf::DW_AT_decl_file, None, FileID);
addUInt(Die, dwarf::DW_AT_decl_line, None, Line);
addSourceLine(Die, Ty.getLineNumber(), Ty.getFilename(), Ty.getDirectory());
}
/// addSourceLine - Add location information to specified debug information
@ -421,15 +403,9 @@ void DwarfUnit::addSourceLine(DIE *Die, DIType Ty) {
void DwarfUnit::addSourceLine(DIE *Die, DIObjCProperty Ty) {
assert(Ty.isObjCProperty());
unsigned Line = Ty.getLineNumber();
if (Line == 0)
return;
DIFile File = Ty.getFile();
unsigned FileID = DD->getOrCreateSourceID(File.getFilename(),
File.getDirectory(), getUniqueID());
assert(FileID && "Invalid file id");
addUInt(Die, dwarf::DW_AT_decl_file, None, FileID);
addUInt(Die, dwarf::DW_AT_decl_line, None, Line);
addSourceLine(Die, Ty.getLineNumber(), File.getFilename(),
File.getDirectory());
}
/// addSourceLine - Add location information to specified debug information
@ -437,16 +413,7 @@ void DwarfUnit::addSourceLine(DIE *Die, DIObjCProperty Ty) {
void DwarfUnit::addSourceLine(DIE *Die, DINameSpace NS) {
assert(NS.Verify());
unsigned Line = NS.getLineNumber();
if (Line == 0)
return;
StringRef FN = NS.getFilename();
unsigned FileID =
DD->getOrCreateSourceID(FN, NS.getDirectory(), getUniqueID());
assert(FileID && "Invalid file id");
addUInt(Die, dwarf::DW_AT_decl_file, None, FileID);
addUInt(Die, dwarf::DW_AT_decl_line, None, Line);
addSourceLine(Die, NS.getLineNumber(), NS.getFilename(), NS.getDirectory());
}
/// addVariableAddress - Add DW_AT_location attribute for a

View File

@ -361,6 +361,8 @@ public:
/// addSourceLine - Add location information to specified debug information
/// entry.
void addSourceLine(DIE *Die, unsigned Line, StringRef File,
StringRef Directory);
void addSourceLine(DIE *Die, DIVariable V);
void addSourceLine(DIE *Die, DIGlobalVariable G);
void addSourceLine(DIE *Die, DISubprogram SP);