Index: lldb/trunk/include/lldb/Symbol/Function.h =================================================================== --- lldb/trunk/include/lldb/Symbol/Function.h +++ lldb/trunk/include/lldb/Symbol/Function.h @@ -324,7 +324,8 @@ /// made the call. lldb::addr_t GetReturnPCAddress(Function &caller, Target &target) const; - /// Like \ref GetReturnPCAddress, but returns an unresolved file address. + /// Like \ref GetReturnPCAddress, but returns an unslid function-local PC + /// offset. lldb::addr_t GetUnresolvedReturnPCAddress() const { return return_pc; } private: @@ -337,8 +338,9 @@ Function *def; } lazy_callee; - /// An invalid address if this is a tail call. Otherwise, the return PC for - /// the call. Note that this is a file address which must be resolved. + /// An invalid address if this is a tail call. Otherwise, the function-local + /// PC offset. Adding this PC offset to the function's base load address + /// gives the return PC for the call. lldb::addr_t return_pc; /// Whether or not an attempt was made to find the callee's definition. Index: lldb/trunk/source/Symbol/Function.cpp =================================================================== --- lldb/trunk/source/Symbol/Function.cpp +++ lldb/trunk/source/Symbol/Function.cpp @@ -180,8 +180,7 @@ lldb::addr_t CallEdge::GetReturnPCAddress(Function &caller, Target &target) const { const Address &base = caller.GetAddressRange().GetBaseAddress(); - Address return_pc_addr{base.GetSection(), return_pc}; - return return_pc_addr.GetLoadAddress(&target); + return base.GetLoadAddress(&target) + return_pc; } //---------------------------------------------------------------------- Index: llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.h =================================================================== --- llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.h +++ llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.h @@ -125,6 +125,10 @@ /// Return Label immediately following the instruction. MCSymbol *getLabelAfterInsn(const MachineInstr *MI); + /// Return the function-local offset of an instruction. A label for the + /// instruction \p MI should exist (\ref getLabelAfterInsn). + const MCExpr *getFunctionLocalOffsetAfterInsn(const MachineInstr *MI); + /// If this type is derived from a base type then return base type size. static uint64_t getBaseTypeSize(const DITypeRef TyRef); }; Index: llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp =================================================================== --- llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp +++ llvm/trunk/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp @@ -125,6 +125,21 @@ return LabelsAfterInsn.lookup(MI); } +// Return the function-local offset of an instruction. +const MCExpr * +DebugHandlerBase::getFunctionLocalOffsetAfterInsn(const MachineInstr *MI) { + MCContext &MC = Asm->OutContext; + + MCSymbol *Start = Asm->getFunctionBegin(); + const auto *StartRef = MCSymbolRefExpr::create(Start, MC); + + MCSymbol *AfterInsn = getLabelAfterInsn(MI); + assert(AfterInsn && "Expected label after instruction"); + const auto *AfterRef = MCSymbolRefExpr::create(AfterInsn, MC); + + return MCBinaryExpr::createSub(AfterRef, StartRef, MC); +} + /// If this type is derived from a base type then return base type size. uint64_t DebugHandlerBase::getBaseTypeSize(const DITypeRef TyRef) { DIType *Ty = TyRef.resolve(); Index: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h =================================================================== --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h @@ -210,10 +210,10 @@ /// Construct a call site entry DIE describing a call within \p Scope to a /// callee described by \p CalleeSP. \p IsTail specifies whether the call is - /// a tail call. \p ReturnPC must be non-null for non-tail calls and point - /// to the PC value after the call returns. + /// a tail call. \p PCOffset must be non-zero for non-tail calls or be the + /// function-local offset to PC value after the call instruction. DIE &constructCallSiteEntryDIE(DIE &ScopeDIE, const DISubprogram &CalleeSP, - bool IsTail, const MCSymbol *ReturnPC); + bool IsTail, const MCExpr *PCOffset); /// Construct import_module DIE. DIE *constructImportedEntityDIE(const DIImportedEntity *Module); @@ -292,6 +292,9 @@ /// Add a Dwarf expression attribute data and value. void addExpr(DIELoc &Die, dwarf::Form Form, const MCExpr *Expr); + /// Add an attribute containing an address expression to \p Die. + void addAddressExpr(DIE &Die, dwarf::Attribute Attribute, const MCExpr *Expr); + void applySubprogramAttributesToDefinition(const DISubprogram *SP, DIE &SPDie); Index: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp =================================================================== --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -821,7 +821,7 @@ DIE &DwarfCompileUnit::constructCallSiteEntryDIE(DIE &ScopeDIE, const DISubprogram &CalleeSP, bool IsTail, - const MCSymbol *ReturnPC) { + const MCExpr *PCOffset) { // Insert a call site entry DIE within ScopeDIE. DIE &CallSiteDIE = createAndAddDIE(dwarf::DW_TAG_call_site, ScopeDIE, nullptr); @@ -838,8 +838,8 @@ } else { // Attach the return PC to allow the debugger to disambiguate call paths // from one function to another. - assert(ReturnPC && "Missing return PC information for a call"); - addLabelAddress(CallSiteDIE, dwarf::DW_AT_call_return_pc, ReturnPC); + assert(PCOffset && "Missing return PC information for a call"); + addAddressExpr(CallSiteDIE, dwarf::DW_AT_call_return_pc, PCOffset); } return CallSiteDIE; } @@ -1103,6 +1103,12 @@ Die.addValue(DIEValueAllocator, (dwarf::Attribute)0, Form, DIEExpr(Expr)); } +void DwarfCompileUnit::addAddressExpr(DIE &Die, dwarf::Attribute Attribute, + const MCExpr *Expr) { + Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_addr, + DIEExpr(Expr)); +} + void DwarfCompileUnit::applySubprogramAttributesToDefinition( const DISubprogram *SP, DIE &SPDie) { auto *SPDecl = SP->getDeclaration(); Index: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp =================================================================== --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -548,14 +548,15 @@ // For tail calls, no return PC information is needed. For regular calls, // the return PC is needed to disambiguate paths in the call graph which // could lead to some target function. - const MCSymbol *ReturnPC = IsTail ? nullptr : getLabelAfterInsn(&MI); + const MCExpr *PCOffset = + IsTail ? nullptr : getFunctionLocalOffsetAfterInsn(&MI); - assert((IsTail || ReturnPC) && "Call without return PC information"); + assert((IsTail || PCOffset) && "Call without return PC information"); LLVM_DEBUG(dbgs() << "CallSiteEntry: " << MF.getName() << " -> " << CalleeDecl->getName() << (IsTail ? " [tail]" : "") << "\n"); CU.constructCallSiteEntryDIE(ScopeDIE, *CalleeDecl->getSubprogram(), - IsTail, ReturnPC); + IsTail, PCOffset); } } }