mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-01 15:17:25 +00:00
Make it easier to use DwarfContext with MCJIT
Summary: This supersedes http://reviews.llvm.org/D4010, hopefully properly dealing with the JIT case and also adds an actual test case. DwarfContext was basically already usable for the JIT (and back when we were overwriting ELF files it actually worked out of the box by accident), but in order to resolve relocations correctly it needs to know the load address of the section. Rather than trying to get this out of the ObjectFile or requiring the user to create a new ObjectFile just to get some debug info, this adds the capability to pass in that info directly. As part of this I separated out part of the LoadedObjectInfo struct from RuntimeDyld, since it is now required at a higher layer. Reviewers: lhames, echristo Reviewed By: echristo Subscribers: vtjnash, friss, rafael, llvm-commits Differential Revision: http://reviews.llvm.org/D6961 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237961 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user