summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp')
-rw-r--r--llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp57
1 files changed, 43 insertions, 14 deletions
diff --git a/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp b/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
index c9877c27283..e87f1e2d4c1 100644
--- a/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
+++ b/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
@@ -48,6 +48,7 @@ InputFileList(cl::Positional, cl::ZeroOrMore,
enum ActionType {
AC_Execute,
AC_PrintLineInfo,
+ AC_PrintDebugLineInfo,
AC_Verify
};
@@ -58,6 +59,8 @@ Action(cl::desc("Action to perform:"),
"Load, link, and execute the inputs."),
clEnumValN(AC_PrintLineInfo, "printline",
"Load, link, and print line information for each function."),
+ clEnumValN(AC_PrintDebugLineInfo, "printdebugline",
+ "Load, link, and print line information for each function using the debug object"),
clEnumValN(AC_Verify, "verify",
"Load, link and verify the resulting memory image."),
clEnumValEnd));
@@ -189,7 +192,9 @@ static void loadDylibs() {
/* *** */
-static int printLineInfoForInput() {
+static int printLineInfoForInput(bool LoadObjects, bool UseDebugObj) {
+ assert(LoadObjects || !UseDebugObj);
+
// Load any dylibs requested on the command line.
loadDylibs();
@@ -216,24 +221,32 @@ static int printLineInfoForInput() {
ObjectFile &Obj = **MaybeObj;
- // Load the object file
- std::unique_ptr<RuntimeDyld::LoadedObjectInfo> LoadedObjInfo =
- Dyld.loadObject(Obj);
+ OwningBinary<ObjectFile> DebugObj;
+ std::unique_ptr<RuntimeDyld::LoadedObjectInfo> LoadedObjInfo = nullptr;
+ ObjectFile *SymbolObj = &Obj;
+ if (LoadObjects) {
+ // Load the object file
+ LoadedObjInfo =
+ Dyld.loadObject(Obj);
- if (Dyld.hasError())
- return Error(Dyld.getErrorString());
+ if (Dyld.hasError())
+ return Error(Dyld.getErrorString());
- // Resolve all the relocations we can.
- Dyld.resolveRelocations();
+ // Resolve all the relocations we can.
+ Dyld.resolveRelocations();
- OwningBinary<ObjectFile> DebugObj = LoadedObjInfo->getObjectForDebug(Obj);
+ if (UseDebugObj) {
+ DebugObj = LoadedObjInfo->getObjectForDebug(Obj);
+ SymbolObj = DebugObj.getBinary();
+ }
+ }
std::unique_ptr<DIContext> Context(
- new DWARFContextInMemory(*DebugObj.getBinary()));
+ new DWARFContextInMemory(*SymbolObj,LoadedObjInfo.get()));
// Use symbol info to iterate functions in the object.
- for (object::symbol_iterator I = DebugObj.getBinary()->symbol_begin(),
- E = DebugObj.getBinary()->symbol_end();
+ for (object::symbol_iterator I = SymbolObj->symbol_begin(),
+ E = SymbolObj->symbol_end();
I != E; ++I) {
object::SymbolRef::Type SymType;
if (I->getType(SymType)) continue;
@@ -245,7 +258,21 @@ static int printLineInfoForInput() {
if (I->getAddress(Addr)) continue;
if (I->getSize(Size)) continue;
- outs() << "Function: " << Name << ", Size = " << Size << "\n";
+ // If we're not using the debug object, compute the address of the
+ // symbol in memory (rather than that in the unrelocated object file)
+ // and use that to query the DWARFContext.
+ if (!UseDebugObj && LoadObjects) {
+ object::section_iterator Sec(SymbolObj->section_end());
+ I->getSection(Sec);
+ StringRef SecName;
+ Sec->getName(SecName);
+ uint64_t SectionLoadAddress =
+ LoadedObjInfo->getSectionLoadAddress(SecName);
+ if (SectionLoadAddress != 0)
+ Addr += SectionLoadAddress - Sec->getAddress();
+ }
+
+ outs() << "Function: " << Name << ", Size = " << Size << ", Addr = " << Addr << "\n";
DILineInfoTable Lines = Context->getLineInfoForAddressRange(Addr, Size);
DILineInfoTable::iterator Begin = Lines.begin();
@@ -594,8 +621,10 @@ int main(int argc, char **argv) {
switch (Action) {
case AC_Execute:
return executeInput();
+ case AC_PrintDebugLineInfo:
+ return printLineInfoForInput(true,true);
case AC_PrintLineInfo:
- return printLineInfoForInput();
+ return printLineInfoForInput(true,false);
case AC_Verify:
return linkAndVerify();
}
OpenPOWER on IntegriCloud