2009-05-15 17:23:25 +08:00
|
|
|
//===-- llvm/CodeGen/DwarfDebug.cpp - Dwarf Debug Framework ---------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains support for writing dwarf debug info into asm files.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2010-03-09 08:39:24 +08:00
|
|
|
|
2009-08-29 07:24:31 +08:00
|
|
|
#define DEBUG_TYPE "dwarfdebug"
|
2009-05-15 17:23:25 +08:00
|
|
|
#include "DwarfDebug.h"
|
2010-04-05 13:24:55 +08:00
|
|
|
#include "DIE.h"
|
2010-04-06 06:59:21 +08:00
|
|
|
#include "llvm/Constants.h"
|
2009-05-15 17:23:25 +08:00
|
|
|
#include "llvm/Module.h"
|
2009-08-20 05:52:55 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2009-05-15 17:23:25 +08:00
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2010-03-09 09:58:53 +08:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2009-08-01 02:48:30 +08:00
|
|
|
#include "llvm/MC/MCSection.h"
|
2009-08-19 13:49:37 +08:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2010-03-09 09:58:53 +08:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2010-01-17 05:57:06 +08:00
|
|
|
#include "llvm/Target/Mangler.h"
|
2009-05-15 17:23:25 +08:00
|
|
|
#include "llvm/Target/TargetData.h"
|
|
|
|
#include "llvm/Target/TargetFrameInfo.h"
|
2009-07-28 11:13:23 +08:00
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
2010-04-05 02:06:11 +08:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2009-07-28 11:13:23 +08:00
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2010-04-20 03:14:02 +08:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2010-04-05 13:24:55 +08:00
|
|
|
#include "llvm/Analysis/DebugInfo.h"
|
2010-10-26 04:45:32 +08:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
2010-03-13 01:45:06 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2009-08-24 11:52:50 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2010-04-28 03:46:33 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2009-10-13 14:47:08 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2010-01-27 05:39:14 +08:00
|
|
|
#include "llvm/Support/ValueHandle.h"
|
2010-01-23 06:09:00 +08:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
2009-08-01 02:48:30 +08:00
|
|
|
#include "llvm/Support/Timer.h"
|
|
|
|
#include "llvm/System/Path.h"
|
2009-05-15 17:23:25 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2010-04-28 03:46:33 +08:00
|
|
|
static cl::opt<bool> PrintDbgScope("print-dbgscope", cl::Hidden,
|
|
|
|
cl::desc("Print DbgScope information for each machine instruction"));
|
|
|
|
|
2010-07-22 05:21:52 +08:00
|
|
|
static cl::opt<bool> DisableDebugInfoPrinting("disable-debug-info-print",
|
2010-07-08 04:12:52 +08:00
|
|
|
cl::Hidden,
|
2010-04-28 03:46:33 +08:00
|
|
|
cl::desc("Disable debug info printing"));
|
|
|
|
|
2010-05-07 09:08:53 +08:00
|
|
|
static cl::opt<bool> UnknownLocations("use-unknown-locations", cl::Hidden,
|
|
|
|
cl::desc("Make an absense of debug location information explicit."),
|
|
|
|
cl::init(false));
|
|
|
|
|
2010-10-26 08:51:57 +08:00
|
|
|
#ifndef NDEBUG
|
2010-10-26 04:45:32 +08:00
|
|
|
STATISTIC(BlocksWithoutLineNo, "Number of blocks without any line number");
|
2010-10-26 08:51:57 +08:00
|
|
|
#endif
|
2010-10-26 04:45:32 +08:00
|
|
|
|
2010-04-07 17:28:04 +08:00
|
|
|
namespace {
|
|
|
|
const char *DWARFGroupName = "DWARF Emission";
|
|
|
|
const char *DbgTimerName = "DWARF Debug Writer";
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2009-05-15 17:23:25 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// Configuration values for initial hash set sizes (log2).
|
|
|
|
///
|
|
|
|
static const unsigned InitAbbreviationsSetSize = 9; // log2(512)
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// CompileUnit - This dwarf writer support class manages information associate
|
|
|
|
/// with a source file.
|
2009-11-17 16:11:44 +08:00
|
|
|
class CompileUnit {
|
2009-05-15 17:23:25 +08:00
|
|
|
/// ID - File identifier for source.
|
|
|
|
///
|
|
|
|
unsigned ID;
|
|
|
|
|
|
|
|
/// Die - Compile unit debug information entry.
|
|
|
|
///
|
2010-03-13 01:45:06 +08:00
|
|
|
const OwningPtr<DIE> CUDie;
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-03-12 02:29:55 +08:00
|
|
|
/// IndexTyDie - An anonymous type for index type. Owned by CUDie.
|
2009-11-21 08:31:03 +08:00
|
|
|
DIE *IndexTyDie;
|
|
|
|
|
2010-07-08 04:49:57 +08:00
|
|
|
/// MDNodeToDieMap - Tracks the mapping of unit level debug informaton
|
2009-05-15 17:23:25 +08:00
|
|
|
/// variables to debug information entries.
|
2010-07-08 04:49:57 +08:00
|
|
|
DenseMap<const MDNode *, DIE *> MDNodeToDieMap;
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-07-08 04:49:57 +08:00
|
|
|
/// MDNodeToDIEEntryMap - Tracks the mapping of unit level debug informaton
|
2009-05-15 17:23:25 +08:00
|
|
|
/// descriptors to debug information entries using a DIEEntry proxy.
|
2010-07-08 04:49:57 +08:00
|
|
|
DenseMap<const MDNode *, DIEEntry *> MDNodeToDIEEntryMap;
|
2009-05-15 17:23:25 +08:00
|
|
|
|
|
|
|
/// Globals - A map of globally visible named entities for this unit.
|
|
|
|
///
|
|
|
|
StringMap<DIE*> Globals;
|
|
|
|
|
2009-11-24 09:14:22 +08:00
|
|
|
/// GlobalTypes - A map of globally visible types for this unit.
|
|
|
|
///
|
|
|
|
StringMap<DIE*> GlobalTypes;
|
|
|
|
|
2009-05-15 17:23:25 +08:00
|
|
|
public:
|
|
|
|
CompileUnit(unsigned I, DIE *D)
|
2009-11-21 10:48:08 +08:00
|
|
|
: ID(I), CUDie(D), IndexTyDie(0) {}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
|
|
|
// Accessors.
|
2009-11-24 09:14:22 +08:00
|
|
|
unsigned getID() const { return ID; }
|
2010-03-12 02:29:55 +08:00
|
|
|
DIE* getCUDie() const { return CUDie.get(); }
|
2009-11-24 09:14:22 +08:00
|
|
|
const StringMap<DIE*> &getGlobals() const { return Globals; }
|
|
|
|
const StringMap<DIE*> &getGlobalTypes() const { return GlobalTypes; }
|
2009-05-15 17:23:25 +08:00
|
|
|
|
|
|
|
/// hasContent - Return true if this compile unit has something to write out.
|
|
|
|
///
|
2009-11-21 10:48:08 +08:00
|
|
|
bool hasContent() const { return !CUDie->getChildren().empty(); }
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// addGlobal - Add a new global entity to the compile unit.
|
2009-05-15 17:23:25 +08:00
|
|
|
///
|
2010-04-01 04:15:45 +08:00
|
|
|
void addGlobal(StringRef Name, DIE *Die) { Globals[Name] = Die; }
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-11-24 09:14:22 +08:00
|
|
|
/// addGlobalType - Add a new global type to the compile unit.
|
|
|
|
///
|
2010-07-22 05:21:52 +08:00
|
|
|
void addGlobalType(StringRef Name, DIE *Die) {
|
|
|
|
GlobalTypes[Name] = Die;
|
2009-11-24 09:14:22 +08:00
|
|
|
}
|
|
|
|
|
2009-11-21 05:37:22 +08:00
|
|
|
/// getDIE - Returns the debug information entry map slot for the
|
2009-05-15 17:23:25 +08:00
|
|
|
/// specified debug variable.
|
2010-07-08 04:49:57 +08:00
|
|
|
DIE *getDIE(const MDNode *N) { return MDNodeToDieMap.lookup(N); }
|
2009-11-22 07:12:12 +08:00
|
|
|
|
2009-11-21 05:37:22 +08:00
|
|
|
/// insertDIE - Insert DIE into the map.
|
2010-05-08 04:54:48 +08:00
|
|
|
void insertDIE(const MDNode *N, DIE *D) {
|
2010-07-08 04:49:57 +08:00
|
|
|
MDNodeToDieMap.insert(std::make_pair(N, D));
|
2009-11-21 05:37:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getDIEEntry - Returns the debug information entry for the speciefied
|
|
|
|
/// debug variable.
|
2010-07-22 05:21:52 +08:00
|
|
|
DIEEntry *getDIEEntry(const MDNode *N) {
|
|
|
|
DenseMap<const MDNode *, DIEEntry *>::iterator I =
|
|
|
|
MDNodeToDIEEntryMap.find(N);
|
2010-07-08 04:49:57 +08:00
|
|
|
if (I == MDNodeToDIEEntryMap.end())
|
2009-12-16 03:16:48 +08:00
|
|
|
return NULL;
|
|
|
|
return I->second;
|
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-11-21 05:37:22 +08:00
|
|
|
/// insertDIEEntry - Insert debug information entry into the map.
|
2010-05-08 04:54:48 +08:00
|
|
|
void insertDIEEntry(const MDNode *N, DIEEntry *E) {
|
2010-07-08 04:49:57 +08:00
|
|
|
MDNodeToDIEEntryMap.insert(std::make_pair(N, E));
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// addDie - Adds or interns the DIE to the compile unit.
|
2009-05-15 17:23:25 +08:00
|
|
|
///
|
2009-11-21 10:48:08 +08:00
|
|
|
void addDie(DIE *Buffer) {
|
|
|
|
this->CUDie->addChild(Buffer);
|
2009-11-21 08:31:03 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-11-21 08:31:03 +08:00
|
|
|
// getIndexTyDie - Get an anonymous type for index type.
|
|
|
|
DIE *getIndexTyDie() {
|
|
|
|
return IndexTyDie;
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
2009-11-21 08:31:03 +08:00
|
|
|
|
2009-11-23 03:20:36 +08:00
|
|
|
// setIndexTyDie - Set D as anonymous type for index which can be reused
|
|
|
|
// later.
|
2009-11-21 08:31:03 +08:00
|
|
|
void setIndexTyDie(DIE *D) {
|
|
|
|
IndexTyDie = D;
|
|
|
|
}
|
|
|
|
|
2009-05-15 17:23:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// DbgVariable - This class is used to track local variable information.
|
|
|
|
///
|
2009-11-17 05:53:40 +08:00
|
|
|
class DbgVariable {
|
2009-05-15 17:23:25 +08:00
|
|
|
DIVariable Var; // Variable Descriptor.
|
2010-05-26 07:40:22 +08:00
|
|
|
DIE *TheDIE; // Variable DIE.
|
|
|
|
unsigned DotDebugLocOffset; // Offset in DotDebugLocEntries.
|
2009-05-15 17:23:25 +08:00
|
|
|
public:
|
2010-03-13 01:45:06 +08:00
|
|
|
// AbsVar may be NULL.
|
2010-05-26 07:40:22 +08:00
|
|
|
DbgVariable(DIVariable V) : Var(V), TheDIE(0), DotDebugLocOffset(~0U) {}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
|
|
|
// Accessors.
|
2009-11-11 07:06:00 +08:00
|
|
|
DIVariable getVariable() const { return Var; }
|
|
|
|
void setDIE(DIE *D) { TheDIE = D; }
|
|
|
|
DIE *getDIE() const { return TheDIE; }
|
2010-05-26 07:40:22 +08:00
|
|
|
void setDotDebugLocOffset(unsigned O) { DotDebugLocOffset = O; }
|
|
|
|
unsigned getDotDebugLocOffset() const { return DotDebugLocOffset; }
|
2010-08-10 05:01:39 +08:00
|
|
|
StringRef getName() const { return Var.getName(); }
|
|
|
|
unsigned getTag() const { return Var.getTag(); }
|
|
|
|
bool variableHasComplexAddress() const {
|
|
|
|
assert(Var.Verify() && "Invalid complex DbgVariable!");
|
|
|
|
return Var.hasComplexAddress();
|
|
|
|
}
|
|
|
|
bool isBlockByrefVariable() const {
|
|
|
|
assert(Var.Verify() && "Invalid complex DbgVariable!");
|
|
|
|
return Var.isBlockByrefVariable();
|
|
|
|
}
|
|
|
|
unsigned getNumAddrElements() const {
|
|
|
|
assert(Var.Verify() && "Invalid complex DbgVariable!");
|
|
|
|
return Var.getNumAddrElements();
|
|
|
|
}
|
|
|
|
uint64_t getAddrElement(unsigned i) const {
|
|
|
|
return Var.getAddrElement(i);
|
|
|
|
}
|
|
|
|
DIType getType() const {
|
|
|
|
DIType Ty = Var.getType();
|
|
|
|
// FIXME: isBlockByrefVariable should be reformulated in terms of complex
|
|
|
|
// addresses instead.
|
|
|
|
if (Var.isBlockByrefVariable()) {
|
|
|
|
/* Byref variables, in Blocks, are declared by the programmer as
|
|
|
|
"SomeType VarName;", but the compiler creates a
|
|
|
|
__Block_byref_x_VarName struct, and gives the variable VarName
|
|
|
|
either the struct, or a pointer to the struct, as its type. This
|
|
|
|
is necessary for various behind-the-scenes things the compiler
|
|
|
|
needs to do with by-reference variables in blocks.
|
|
|
|
|
|
|
|
However, as far as the original *programmer* is concerned, the
|
|
|
|
variable should still have type 'SomeType', as originally declared.
|
|
|
|
|
|
|
|
The following function dives into the __Block_byref_x_VarName
|
|
|
|
struct to find the original type of the variable. This will be
|
|
|
|
passed back to the code generating the type for the Debug
|
|
|
|
Information Entry for the variable 'VarName'. 'VarName' will then
|
|
|
|
have the original type 'SomeType' in its debug information.
|
|
|
|
|
|
|
|
The original type 'SomeType' will be the type of the field named
|
|
|
|
'VarName' inside the __Block_byref_x_VarName struct.
|
|
|
|
|
|
|
|
NOTE: In order for this to not completely fail on the debugger
|
|
|
|
side, the Debug Information Entry for the variable VarName needs to
|
|
|
|
have a DW_AT_location that tells the debugger how to unwind through
|
|
|
|
the pointers and __Block_byref_x_VarName struct to find the actual
|
|
|
|
value of the variable. The function addBlockByrefType does this. */
|
|
|
|
DIType subType = Ty;
|
|
|
|
unsigned tag = Ty.getTag();
|
|
|
|
|
|
|
|
if (tag == dwarf::DW_TAG_pointer_type) {
|
|
|
|
DIDerivedType DTy = DIDerivedType(Ty);
|
|
|
|
subType = DTy.getTypeDerivedFrom();
|
|
|
|
}
|
|
|
|
|
|
|
|
DICompositeType blockStruct = DICompositeType(subType);
|
|
|
|
DIArray Elements = blockStruct.getTypeArray();
|
|
|
|
|
|
|
|
for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
|
|
|
|
DIDescriptor Element = Elements.getElement(i);
|
|
|
|
DIDerivedType DT = DIDerivedType(Element);
|
|
|
|
if (getName() == DT.getName())
|
|
|
|
return (DT.getTypeDerivedFrom());
|
|
|
|
}
|
|
|
|
return Ty;
|
|
|
|
}
|
|
|
|
return Ty;
|
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
};
|
|
|
|
|
2010-04-28 03:46:33 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// DbgRange - This is used to track range of instructions with identical
|
|
|
|
/// debug info scope.
|
|
|
|
///
|
|
|
|
typedef std::pair<const MachineInstr *, const MachineInstr *> DbgRange;
|
|
|
|
|
2009-05-15 17:23:25 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// DbgScope - This class is used to track scope information.
|
|
|
|
///
|
2009-11-17 05:53:40 +08:00
|
|
|
class DbgScope {
|
2009-05-15 17:23:25 +08:00
|
|
|
DbgScope *Parent; // Parent to this scope.
|
2009-11-22 07:12:12 +08:00
|
|
|
DIDescriptor Desc; // Debug info descriptor for scope.
|
2010-01-27 05:39:14 +08:00
|
|
|
// Location at which this scope is inlined.
|
2010-07-22 05:21:52 +08:00
|
|
|
AssertingVH<const MDNode> InlinedAtLocation;
|
2009-11-11 07:06:00 +08:00
|
|
|
bool AbstractScope; // Abstract Scope
|
2009-10-02 02:25:23 +08:00
|
|
|
const MachineInstr *LastInsn; // Last instruction of this scope.
|
|
|
|
const MachineInstr *FirstInsn; // First instruction of this scope.
|
2010-04-28 03:46:33 +08:00
|
|
|
unsigned DFSIn, DFSOut;
|
2010-03-13 01:45:06 +08:00
|
|
|
// Scopes defined in scope. Contents not owned.
|
|
|
|
SmallVector<DbgScope *, 4> Scopes;
|
|
|
|
// Variables declared in scope. Contents owned.
|
|
|
|
SmallVector<DbgVariable *, 8> Variables;
|
2010-04-28 03:46:33 +08:00
|
|
|
SmallVector<DbgRange, 4> Ranges;
|
2009-06-25 06:53:20 +08:00
|
|
|
// Private state for dump()
|
|
|
|
mutable unsigned IndentLevel;
|
2009-05-15 17:23:25 +08:00
|
|
|
public:
|
2010-05-08 04:54:48 +08:00
|
|
|
DbgScope(DbgScope *P, DIDescriptor D, const MDNode *I = 0)
|
2009-11-11 07:06:00 +08:00
|
|
|
: Parent(P), Desc(D), InlinedAtLocation(I), AbstractScope(false),
|
2010-04-28 03:46:33 +08:00
|
|
|
LastInsn(0), FirstInsn(0),
|
|
|
|
DFSIn(0), DFSOut(0), IndentLevel(0) {}
|
2009-05-15 17:23:25 +08:00
|
|
|
virtual ~DbgScope();
|
|
|
|
|
|
|
|
// Accessors.
|
|
|
|
DbgScope *getParent() const { return Parent; }
|
2009-11-11 07:06:00 +08:00
|
|
|
void setParent(DbgScope *P) { Parent = P; }
|
2009-05-15 17:23:25 +08:00
|
|
|
DIDescriptor getDesc() const { return Desc; }
|
2010-05-08 04:54:48 +08:00
|
|
|
const MDNode *getInlinedAt() const { return InlinedAtLocation; }
|
|
|
|
const MDNode *getScopeNode() const { return Desc; }
|
2010-03-13 01:45:06 +08:00
|
|
|
const SmallVector<DbgScope *, 4> &getScopes() { return Scopes; }
|
2010-08-10 02:51:29 +08:00
|
|
|
const SmallVector<DbgVariable *, 8> &getDbgVariables() { return Variables; }
|
2010-04-28 03:46:33 +08:00
|
|
|
const SmallVector<DbgRange, 4> &getRanges() { return Ranges; }
|
|
|
|
|
|
|
|
/// openInsnRange - This scope covers instruction range starting from MI.
|
|
|
|
void openInsnRange(const MachineInstr *MI) {
|
2010-07-22 05:21:52 +08:00
|
|
|
if (!FirstInsn)
|
2010-04-28 03:46:33 +08:00
|
|
|
FirstInsn = MI;
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-04-28 03:46:33 +08:00
|
|
|
if (Parent)
|
|
|
|
Parent->openInsnRange(MI);
|
|
|
|
}
|
|
|
|
|
2010-07-22 05:21:52 +08:00
|
|
|
/// extendInsnRange - Extend the current instruction range covered by
|
2010-04-28 03:46:33 +08:00
|
|
|
/// this scope.
|
|
|
|
void extendInsnRange(const MachineInstr *MI) {
|
|
|
|
assert (FirstInsn && "MI Range is not open!");
|
|
|
|
LastInsn = MI;
|
|
|
|
if (Parent)
|
|
|
|
Parent->extendInsnRange(MI);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// closeInsnRange - Create a range based on FirstInsn and LastInsn collected
|
|
|
|
/// until now. This is used when a new scope is encountered while walking
|
|
|
|
/// machine instructions.
|
|
|
|
void closeInsnRange(DbgScope *NewScope = NULL) {
|
|
|
|
assert (LastInsn && "Last insn missing!");
|
|
|
|
Ranges.push_back(DbgRange(FirstInsn, LastInsn));
|
2010-07-22 05:21:52 +08:00
|
|
|
FirstInsn = NULL;
|
2010-04-28 03:46:33 +08:00
|
|
|
LastInsn = NULL;
|
2010-07-22 05:21:52 +08:00
|
|
|
// If Parent dominates NewScope then do not close Parent's instruction
|
2010-04-28 03:46:33 +08:00
|
|
|
// range.
|
|
|
|
if (Parent && (!NewScope || !Parent->dominates(NewScope)))
|
|
|
|
Parent->closeInsnRange(NewScope);
|
|
|
|
}
|
|
|
|
|
2009-11-11 07:06:00 +08:00
|
|
|
void setAbstractScope() { AbstractScope = true; }
|
|
|
|
bool isAbstractScope() const { return AbstractScope; }
|
2010-04-28 03:46:33 +08:00
|
|
|
|
|
|
|
// Depth First Search support to walk and mainpluate DbgScope hierarchy.
|
|
|
|
unsigned getDFSOut() const { return DFSOut; }
|
|
|
|
void setDFSOut(unsigned O) { DFSOut = O; }
|
|
|
|
unsigned getDFSIn() const { return DFSIn; }
|
|
|
|
void setDFSIn(unsigned I) { DFSIn = I; }
|
|
|
|
bool dominates(const DbgScope *S) {
|
2010-07-22 05:21:52 +08:00
|
|
|
if (S == this)
|
2010-04-28 03:46:33 +08:00
|
|
|
return true;
|
|
|
|
if (DFSIn < S->getDFSIn() && DFSOut > S->getDFSOut())
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
2009-11-11 07:06:00 +08:00
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// addScope - Add a scope to the scope.
|
2009-05-15 17:23:25 +08:00
|
|
|
///
|
2009-11-21 10:48:08 +08:00
|
|
|
void addScope(DbgScope *S) { Scopes.push_back(S); }
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// addVariable - Add a variable to the scope.
|
2009-05-15 17:23:25 +08:00
|
|
|
///
|
2009-11-21 10:48:08 +08:00
|
|
|
void addVariable(DbgVariable *V) { Variables.push_back(V); }
|
2009-05-15 17:23:25 +08:00
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
void dump() const;
|
|
|
|
#endif
|
|
|
|
};
|
2010-04-28 03:46:33 +08:00
|
|
|
|
2010-04-05 12:09:20 +08:00
|
|
|
} // end llvm namespace
|
2009-05-15 17:23:25 +08:00
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
void DbgScope::dump() const {
|
2009-12-24 08:31:35 +08:00
|
|
|
raw_ostream &err = dbgs();
|
2009-08-23 08:51:00 +08:00
|
|
|
err.indent(IndentLevel);
|
2010-05-08 04:54:48 +08:00
|
|
|
const MDNode *N = Desc;
|
2009-11-11 07:06:00 +08:00
|
|
|
N->dump();
|
|
|
|
if (AbstractScope)
|
|
|
|
err << "Abstract Scope\n";
|
2009-05-15 17:23:25 +08:00
|
|
|
|
|
|
|
IndentLevel += 2;
|
2009-11-11 07:06:00 +08:00
|
|
|
if (!Scopes.empty())
|
|
|
|
err << "Children ...\n";
|
2009-05-15 17:23:25 +08:00
|
|
|
for (unsigned i = 0, e = Scopes.size(); i != e; ++i)
|
|
|
|
if (Scopes[i] != this)
|
|
|
|
Scopes[i]->dump();
|
|
|
|
|
|
|
|
IndentLevel -= 2;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
DbgScope::~DbgScope() {
|
|
|
|
for (unsigned j = 0, M = Variables.size(); j < M; ++j)
|
|
|
|
delete Variables[j];
|
|
|
|
}
|
|
|
|
|
2010-04-05 13:11:15 +08:00
|
|
|
DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
|
2010-05-11 06:49:55 +08:00
|
|
|
: Asm(A), MMI(Asm->MMI), FirstCU(0),
|
2010-07-22 05:21:52 +08:00
|
|
|
AbbreviationsSet(InitAbbreviationsSetSize),
|
2010-04-17 07:33:45 +08:00
|
|
|
CurrentFnDbgScope(0), PrevLabel(NULL) {
|
2010-03-13 10:17:42 +08:00
|
|
|
NextStringPoolNumber = 0;
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-04-05 07:10:38 +08:00
|
|
|
DwarfFrameSectionSym = DwarfInfoSectionSym = DwarfAbbrevSectionSym = 0;
|
|
|
|
DwarfStrSectionSym = TextSectionSym = 0;
|
2010-07-22 05:21:52 +08:00
|
|
|
DwarfDebugRangeSectionSym = DwarfDebugLocSectionSym = 0;
|
2010-05-26 07:40:22 +08:00
|
|
|
FunctionBeginSym = FunctionEndSym = 0;
|
2010-07-09 04:10:35 +08:00
|
|
|
DIEIntegerOne = new (DIEValueAllocator) DIEInteger(1);
|
2010-06-18 23:56:31 +08:00
|
|
|
{
|
|
|
|
NamedRegionTimer T(DbgTimerName, DWARFGroupName, TimePassesIsEnabled);
|
|
|
|
beginModule(M);
|
2010-04-07 18:44:46 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
DwarfDebug::~DwarfDebug() {
|
2010-04-01 03:34:01 +08:00
|
|
|
for (unsigned j = 0, M = DIEBlocks.size(); j < M; ++j)
|
|
|
|
DIEBlocks[j]->~DIEBlock();
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
2010-03-13 10:17:42 +08:00
|
|
|
MCSymbol *DwarfDebug::getStringPoolEntry(StringRef Str) {
|
|
|
|
std::pair<MCSymbol*, unsigned> &Entry = StringPool[Str];
|
|
|
|
if (Entry.first) return Entry.first;
|
|
|
|
|
|
|
|
Entry.second = NextStringPoolNumber++;
|
2010-04-05 03:25:43 +08:00
|
|
|
return Entry.first = Asm->GetTempSymbol("string", Entry.second);
|
2010-03-13 10:17:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// assignAbbrevNumber - Define a unique number for the abbreviation.
|
2009-05-15 17:23:25 +08:00
|
|
|
///
|
2009-11-21 10:48:08 +08:00
|
|
|
void DwarfDebug::assignAbbrevNumber(DIEAbbrev &Abbrev) {
|
2009-05-15 17:23:25 +08:00
|
|
|
// Profile the node so that we can make it unique.
|
|
|
|
FoldingSetNodeID ID;
|
|
|
|
Abbrev.Profile(ID);
|
|
|
|
|
|
|
|
// Check the set for priors.
|
|
|
|
DIEAbbrev *InSet = AbbreviationsSet.GetOrInsertNode(&Abbrev);
|
|
|
|
|
|
|
|
// If it's newly added.
|
|
|
|
if (InSet == &Abbrev) {
|
|
|
|
// Add to abbreviation list.
|
|
|
|
Abbreviations.push_back(&Abbrev);
|
|
|
|
|
|
|
|
// Assign the vector position + 1 as its number.
|
|
|
|
Abbrev.setNumber(Abbreviations.size());
|
|
|
|
} else {
|
|
|
|
// Assign existing abbreviation number.
|
|
|
|
Abbrev.setNumber(InSet->getNumber());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
|
2009-05-21 07:24:48 +08:00
|
|
|
/// information entry.
|
2009-11-21 10:48:08 +08:00
|
|
|
DIEEntry *DwarfDebug::createDIEEntry(DIE *Entry) {
|
2010-04-01 03:34:01 +08:00
|
|
|
DIEEntry *Value = new (DIEValueAllocator) DIEEntry(Entry);
|
2009-05-15 17:23:25 +08:00
|
|
|
return Value;
|
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// addUInt - Add an unsigned integer attribute data and value.
|
2009-05-15 17:23:25 +08:00
|
|
|
///
|
2009-11-21 10:48:08 +08:00
|
|
|
void DwarfDebug::addUInt(DIE *Die, unsigned Attribute,
|
2009-05-15 17:23:25 +08:00
|
|
|
unsigned Form, uint64_t Integer) {
|
|
|
|
if (!Form) Form = DIEInteger::BestForm(false, Integer);
|
2010-07-22 05:21:52 +08:00
|
|
|
DIEValue *Value = Integer == 1 ?
|
2010-07-09 04:10:35 +08:00
|
|
|
DIEIntegerOne : new (DIEValueAllocator) DIEInteger(Integer);
|
2009-11-21 10:48:08 +08:00
|
|
|
Die->addValue(Attribute, Form, Value);
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// addSInt - Add an signed integer attribute data and value.
|
2009-05-15 17:23:25 +08:00
|
|
|
///
|
2009-11-21 10:48:08 +08:00
|
|
|
void DwarfDebug::addSInt(DIE *Die, unsigned Attribute,
|
2009-05-15 17:23:25 +08:00
|
|
|
unsigned Form, int64_t Integer) {
|
|
|
|
if (!Form) Form = DIEInteger::BestForm(true, Integer);
|
2010-04-01 03:34:01 +08:00
|
|
|
DIEValue *Value = new (DIEValueAllocator) DIEInteger(Integer);
|
2009-11-21 10:48:08 +08:00
|
|
|
Die->addValue(Attribute, Form, Value);
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
2009-12-02 23:25:16 +08:00
|
|
|
/// addString - Add a string attribute data and value. DIEString only
|
2010-07-22 05:21:52 +08:00
|
|
|
/// keeps string reference.
|
2009-11-21 10:48:08 +08:00
|
|
|
void DwarfDebug::addString(DIE *Die, unsigned Attribute, unsigned Form,
|
2010-01-23 11:11:46 +08:00
|
|
|
StringRef String) {
|
2010-04-01 03:34:01 +08:00
|
|
|
DIEValue *Value = new (DIEValueAllocator) DIEString(String);
|
2009-11-21 10:48:08 +08:00
|
|
|
Die->addValue(Attribute, Form, Value);
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// addLabel - Add a Dwarf label attribute data and value.
|
2009-05-15 17:23:25 +08:00
|
|
|
///
|
2009-11-21 10:48:08 +08:00
|
|
|
void DwarfDebug::addLabel(DIE *Die, unsigned Attribute, unsigned Form,
|
2010-03-09 06:23:36 +08:00
|
|
|
const MCSymbol *Label) {
|
2010-04-01 03:34:01 +08:00
|
|
|
DIEValue *Value = new (DIEValueAllocator) DIELabel(Label);
|
2009-11-21 10:48:08 +08:00
|
|
|
Die->addValue(Attribute, Form, Value);
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// addDelta - Add a label delta attribute data and value.
|
2009-05-15 17:23:25 +08:00
|
|
|
///
|
2009-11-21 10:48:08 +08:00
|
|
|
void DwarfDebug::addDelta(DIE *Die, unsigned Attribute, unsigned Form,
|
2010-03-09 06:23:36 +08:00
|
|
|
const MCSymbol *Hi, const MCSymbol *Lo) {
|
2010-04-01 03:34:01 +08:00
|
|
|
DIEValue *Value = new (DIEValueAllocator) DIEDelta(Hi, Lo);
|
2009-11-21 10:48:08 +08:00
|
|
|
Die->addValue(Attribute, Form, Value);
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
2010-04-05 13:24:55 +08:00
|
|
|
/// addDIEEntry - Add a DIE attribute data and value.
|
|
|
|
///
|
|
|
|
void DwarfDebug::addDIEEntry(DIE *Die, unsigned Attribute, unsigned Form,
|
|
|
|
DIE *Entry) {
|
|
|
|
Die->addValue(Attribute, Form, createDIEEntry(Entry));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// addBlock - Add block data.
|
2009-05-15 17:23:25 +08:00
|
|
|
///
|
2009-11-21 10:48:08 +08:00
|
|
|
void DwarfDebug::addBlock(DIE *Die, unsigned Attribute, unsigned Form,
|
2009-05-15 17:23:25 +08:00
|
|
|
DIEBlock *Block) {
|
2010-04-05 08:18:22 +08:00
|
|
|
Block->ComputeSize(Asm);
|
2010-04-01 03:34:01 +08:00
|
|
|
DIEBlocks.push_back(Block); // Memoize so we can call the destructor later on.
|
2009-11-21 10:48:08 +08:00
|
|
|
Die->addValue(Attribute, Block->BestForm(), Block);
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// addSourceLine - Add location information to specified debug information
|
2009-05-15 17:23:25 +08:00
|
|
|
/// entry.
|
2010-08-10 12:09:06 +08:00
|
|
|
void DwarfDebug::addSourceLine(DIE *Die, DIVariable V) {
|
2010-05-08 07:33:41 +08:00
|
|
|
// Verify variable.
|
2010-08-10 04:20:05 +08:00
|
|
|
if (!V.Verify())
|
2009-05-15 17:23:25 +08:00
|
|
|
return;
|
|
|
|
|
2010-08-10 04:20:05 +08:00
|
|
|
unsigned Line = V.getLineNumber();
|
2010-10-09 01:18:54 +08:00
|
|
|
if (Line == 0)
|
|
|
|
return;
|
2010-08-10 04:20:05 +08:00
|
|
|
unsigned FileID = GetOrCreateSourceID(V.getContext().getDirectory(),
|
|
|
|
V.getContext().getFilename());
|
2009-05-15 17:23:25 +08:00
|
|
|
assert(FileID && "Invalid file id");
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID);
|
|
|
|
addUInt(Die, dwarf::DW_AT_decl_line, 0, Line);
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// addSourceLine - Add location information to specified debug information
|
2009-05-15 17:23:25 +08:00
|
|
|
/// entry.
|
2010-08-10 12:09:06 +08:00
|
|
|
void DwarfDebug::addSourceLine(DIE *Die, DIGlobalVariable G) {
|
2010-05-08 07:33:41 +08:00
|
|
|
// Verify global variable.
|
2010-08-10 04:20:05 +08:00
|
|
|
if (!G.Verify())
|
2009-05-15 17:23:25 +08:00
|
|
|
return;
|
|
|
|
|
2010-08-10 04:20:05 +08:00
|
|
|
unsigned Line = G.getLineNumber();
|
2010-10-09 01:18:54 +08:00
|
|
|
if (Line == 0)
|
|
|
|
return;
|
2010-08-10 04:20:05 +08:00
|
|
|
unsigned FileID = GetOrCreateSourceID(G.getContext().getDirectory(),
|
|
|
|
G.getContext().getFilename());
|
2009-05-15 17:23:25 +08:00
|
|
|
assert(FileID && "Invalid file id");
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID);
|
|
|
|
addUInt(Die, dwarf::DW_AT_decl_line, 0, Line);
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
2009-09-01 06:47:13 +08:00
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// addSourceLine - Add location information to specified debug information
|
2009-09-01 06:47:13 +08:00
|
|
|
/// entry.
|
2010-08-10 12:09:06 +08:00
|
|
|
void DwarfDebug::addSourceLine(DIE *Die, DISubprogram SP) {
|
2010-05-08 07:33:41 +08:00
|
|
|
// Verify subprogram.
|
2010-08-10 04:20:05 +08:00
|
|
|
if (!SP.Verify())
|
2009-09-01 06:47:13 +08:00
|
|
|
return;
|
2009-09-12 02:25:54 +08:00
|
|
|
// If the line number is 0, don't add it.
|
2010-08-10 04:20:05 +08:00
|
|
|
if (SP.getLineNumber() == 0)
|
2009-09-12 02:25:54 +08:00
|
|
|
return;
|
|
|
|
|
2010-08-10 04:20:05 +08:00
|
|
|
unsigned Line = SP.getLineNumber();
|
|
|
|
if (!SP.getContext().Verify())
|
2010-03-09 06:02:50 +08:00
|
|
|
return;
|
2010-08-10 04:20:05 +08:00
|
|
|
unsigned FileID = GetOrCreateSourceID(SP.getDirectory(),
|
|
|
|
SP.getFilename());
|
2009-09-01 06:47:13 +08:00
|
|
|
assert(FileID && "Invalid file id");
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID);
|
|
|
|
addUInt(Die, dwarf::DW_AT_decl_line, 0, Line);
|
2009-09-01 06:47:13 +08:00
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// addSourceLine - Add location information to specified debug information
|
2009-09-01 06:47:13 +08:00
|
|
|
/// entry.
|
2010-08-10 12:09:06 +08:00
|
|
|
void DwarfDebug::addSourceLine(DIE *Die, DIType Ty) {
|
2010-05-08 07:33:41 +08:00
|
|
|
// Verify type.
|
2010-08-10 04:20:05 +08:00
|
|
|
if (!Ty.Verify())
|
2009-05-15 17:23:25 +08:00
|
|
|
return;
|
|
|
|
|
2010-08-10 04:20:05 +08:00
|
|
|
unsigned Line = Ty.getLineNumber();
|
2010-10-09 01:18:54 +08:00
|
|
|
if (Line == 0 || !Ty.getContext().Verify())
|
2010-03-09 06:02:50 +08:00
|
|
|
return;
|
2010-10-29 03:50:08 +08:00
|
|
|
unsigned FileID = GetOrCreateSourceID(Ty.getDirectory(),
|
|
|
|
Ty.getFilename());
|
2009-05-15 17:23:25 +08:00
|
|
|
assert(FileID && "Invalid file id");
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID);
|
|
|
|
addUInt(Die, dwarf::DW_AT_decl_line, 0, Line);
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
2009-12-16 03:16:48 +08:00
|
|
|
/// addSourceLine - Add location information to specified debug information
|
|
|
|
/// entry.
|
2010-08-10 12:09:06 +08:00
|
|
|
void DwarfDebug::addSourceLine(DIE *Die, DINameSpace NS) {
|
2010-05-08 07:33:41 +08:00
|
|
|
// Verify namespace.
|
2010-08-10 04:20:05 +08:00
|
|
|
if (!NS.Verify())
|
2009-12-16 03:16:48 +08:00
|
|
|
return;
|
|
|
|
|
2010-08-10 04:20:05 +08:00
|
|
|
unsigned Line = NS.getLineNumber();
|
2010-10-09 01:18:54 +08:00
|
|
|
if (Line == 0)
|
|
|
|
return;
|
2010-08-10 04:20:05 +08:00
|
|
|
StringRef FN = NS.getFilename();
|
|
|
|
StringRef Dir = NS.getDirectory();
|
2009-12-16 03:16:48 +08:00
|
|
|
|
|
|
|
unsigned FileID = GetOrCreateSourceID(Dir, FN);
|
|
|
|
assert(FileID && "Invalid file id");
|
|
|
|
addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID);
|
|
|
|
addUInt(Die, dwarf::DW_AT_decl_line, 0, Line);
|
|
|
|
}
|
|
|
|
|
2010-08-31 14:11:28 +08:00
|
|
|
/// addVariableAddress - Add DW_AT_location attribute for a DbgVariable based
|
|
|
|
/// on provided frame index.
|
|
|
|
void DwarfDebug::addVariableAddress(DbgVariable *&DV, DIE *Die, int64_t FI) {
|
|
|
|
MachineLocation Location;
|
|
|
|
unsigned FrameReg;
|
|
|
|
const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo();
|
|
|
|
int Offset = RI->getFrameIndexReference(*Asm->MF, FI, FrameReg);
|
|
|
|
Location.set(FrameReg, Offset);
|
|
|
|
|
2010-08-10 05:01:39 +08:00
|
|
|
if (DV->variableHasComplexAddress())
|
|
|
|
addComplexAddress(DV, Die, dwarf::DW_AT_location, Location);
|
|
|
|
else if (DV->isBlockByrefVariable())
|
|
|
|
addBlockByrefAddress(DV, Die, dwarf::DW_AT_location, Location);
|
|
|
|
else
|
|
|
|
addAddress(Die, dwarf::DW_AT_location, Location);
|
2009-09-01 05:19:37 +08:00
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// addComplexAddress - Start with the address based on the location provided,
|
2009-09-30 08:08:22 +08:00
|
|
|
/// and generate the DWARF information necessary to find the actual variable
|
|
|
|
/// given the extra address information encoded in the DIVariable, starting from
|
|
|
|
/// the starting location. Add the DWARF information to the die.
|
|
|
|
///
|
2009-11-21 10:48:08 +08:00
|
|
|
void DwarfDebug::addComplexAddress(DbgVariable *&DV, DIE *Die,
|
2009-09-30 08:08:22 +08:00
|
|
|
unsigned Attribute,
|
|
|
|
const MachineLocation &Location) {
|
2010-08-10 05:01:39 +08:00
|
|
|
DIType Ty = DV->getType();
|
2009-09-30 08:08:22 +08:00
|
|
|
|
|
|
|
// Decode the original location, and use that as the start of the byref
|
|
|
|
// variable's location.
|
2010-04-05 08:13:49 +08:00
|
|
|
const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo();
|
2009-09-30 08:08:22 +08:00
|
|
|
unsigned Reg = RI->getDwarfRegNum(Location.getReg(), false);
|
2010-04-01 03:34:01 +08:00
|
|
|
DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
|
2009-09-30 08:08:22 +08:00
|
|
|
|
|
|
|
if (Location.isReg()) {
|
|
|
|
if (Reg < 32) {
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_reg0 + Reg);
|
2009-09-30 08:08:22 +08:00
|
|
|
} else {
|
|
|
|
Reg = Reg - dwarf::DW_OP_reg0;
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_breg0 + Reg);
|
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_udata, Reg);
|
2009-09-30 08:08:22 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (Reg < 32)
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_breg0 + Reg);
|
2009-09-30 08:08:22 +08:00
|
|
|
else {
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_bregx);
|
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_udata, Reg);
|
2009-09-30 08:08:22 +08:00
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_sdata, Location.getOffset());
|
2009-09-30 08:08:22 +08:00
|
|
|
}
|
|
|
|
|
2010-08-10 05:01:39 +08:00
|
|
|
for (unsigned i = 0, N = DV->getNumAddrElements(); i < N; ++i) {
|
|
|
|
uint64_t Element = DV->getAddrElement(i);
|
2009-09-30 08:08:22 +08:00
|
|
|
|
|
|
|
if (Element == DIFactory::OpPlus) {
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
|
2010-08-10 05:01:39 +08:00
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_udata, DV->getAddrElement(++i));
|
2009-09-30 08:08:22 +08:00
|
|
|
} else if (Element == DIFactory::OpDeref) {
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
|
2009-09-30 08:08:22 +08:00
|
|
|
} else llvm_unreachable("unknown DIFactory Opcode");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now attach the location information to the DIE.
|
2009-11-21 10:48:08 +08:00
|
|
|
addBlock(Die, Attribute, 0, Block);
|
2009-09-30 08:08:22 +08:00
|
|
|
}
|
|
|
|
|
2009-09-01 05:19:37 +08:00
|
|
|
/* Byref variables, in Blocks, are declared by the programmer as "SomeType
|
|
|
|
VarName;", but the compiler creates a __Block_byref_x_VarName struct, and
|
|
|
|
gives the variable VarName either the struct, or a pointer to the struct, as
|
|
|
|
its type. This is necessary for various behind-the-scenes things the
|
|
|
|
compiler needs to do with by-reference variables in Blocks.
|
|
|
|
|
|
|
|
However, as far as the original *programmer* is concerned, the variable
|
|
|
|
should still have type 'SomeType', as originally declared.
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
The function getBlockByrefType dives into the __Block_byref_x_VarName
|
2009-09-01 05:19:37 +08:00
|
|
|
struct to find the original type of the variable, which is then assigned to
|
|
|
|
the variable's Debug Information Entry as its real type. So far, so good.
|
|
|
|
However now the debugger will expect the variable VarName to have the type
|
|
|
|
SomeType. So we need the location attribute for the variable to be an
|
2009-09-20 04:40:05 +08:00
|
|
|
expression that explains to the debugger how to navigate through the
|
2009-09-01 05:19:37 +08:00
|
|
|
pointers and struct to find the actual variable of type SomeType.
|
|
|
|
|
|
|
|
The following function does just that. We start by getting
|
|
|
|
the "normal" location for the variable. This will be the location
|
|
|
|
of either the struct __Block_byref_x_VarName or the pointer to the
|
|
|
|
struct __Block_byref_x_VarName.
|
|
|
|
|
|
|
|
The struct will look something like:
|
|
|
|
|
|
|
|
struct __Block_byref_x_VarName {
|
|
|
|
... <various fields>
|
|
|
|
struct __Block_byref_x_VarName *forwarding;
|
|
|
|
... <various other fields>
|
|
|
|
SomeType VarName;
|
|
|
|
... <maybe more fields>
|
|
|
|
};
|
|
|
|
|
|
|
|
If we are given the struct directly (as our starting point) we
|
|
|
|
need to tell the debugger to:
|
|
|
|
|
|
|
|
1). Add the offset of the forwarding field.
|
|
|
|
|
2010-02-11 00:03:48 +08:00
|
|
|
2). Follow that pointer to get the real __Block_byref_x_VarName
|
2009-09-01 05:19:37 +08:00
|
|
|
struct to use (the real one may have been copied onto the heap).
|
|
|
|
|
|
|
|
3). Add the offset for the field VarName, to find the actual variable.
|
|
|
|
|
|
|
|
If we started with a pointer to the struct, then we need to
|
|
|
|
dereference that pointer first, before the other steps.
|
|
|
|
Translating this into DWARF ops, we will need to append the following
|
|
|
|
to the current location description for the variable:
|
|
|
|
|
|
|
|
DW_OP_deref -- optional, if we start with a pointer
|
|
|
|
DW_OP_plus_uconst <forward_fld_offset>
|
|
|
|
DW_OP_deref
|
|
|
|
DW_OP_plus_uconst <varName_fld_offset>
|
|
|
|
|
|
|
|
That is what this function does. */
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// addBlockByrefAddress - Start with the address based on the location
|
2009-09-01 05:19:37 +08:00
|
|
|
/// provided, and generate the DWARF information necessary to find the
|
|
|
|
/// actual Block variable (navigating the Block struct) based on the
|
|
|
|
/// starting location. Add the DWARF information to the die. For
|
|
|
|
/// more information, read large comment just above here.
|
|
|
|
///
|
2009-11-21 10:48:08 +08:00
|
|
|
void DwarfDebug::addBlockByrefAddress(DbgVariable *&DV, DIE *Die,
|
2009-09-20 04:40:14 +08:00
|
|
|
unsigned Attribute,
|
|
|
|
const MachineLocation &Location) {
|
2010-08-10 05:01:39 +08:00
|
|
|
DIType Ty = DV->getType();
|
2009-09-01 05:19:37 +08:00
|
|
|
DIType TmpTy = Ty;
|
|
|
|
unsigned Tag = Ty.getTag();
|
|
|
|
bool isPointer = false;
|
|
|
|
|
2010-08-10 05:01:39 +08:00
|
|
|
StringRef varName = DV->getName();
|
2009-09-01 05:19:37 +08:00
|
|
|
|
|
|
|
if (Tag == dwarf::DW_TAG_pointer_type) {
|
2010-05-08 02:11:54 +08:00
|
|
|
DIDerivedType DTy = DIDerivedType(Ty);
|
2009-09-01 05:19:37 +08:00
|
|
|
TmpTy = DTy.getTypeDerivedFrom();
|
|
|
|
isPointer = true;
|
|
|
|
}
|
|
|
|
|
2010-05-08 02:11:54 +08:00
|
|
|
DICompositeType blockStruct = DICompositeType(TmpTy);
|
2009-09-01 05:19:37 +08:00
|
|
|
|
2009-09-20 04:40:14 +08:00
|
|
|
// Find the __forwarding field and the variable field in the __Block_byref
|
|
|
|
// struct.
|
|
|
|
DIArray Fields = blockStruct.getTypeArray();
|
|
|
|
DIDescriptor varField = DIDescriptor();
|
|
|
|
DIDescriptor forwardingField = DIDescriptor();
|
2009-09-01 05:19:37 +08:00
|
|
|
|
2009-09-20 04:40:14 +08:00
|
|
|
for (unsigned i = 0, N = Fields.getNumElements(); i < N; ++i) {
|
|
|
|
DIDescriptor Element = Fields.getElement(i);
|
2010-05-08 02:11:54 +08:00
|
|
|
DIDerivedType DT = DIDerivedType(Element);
|
2009-11-26 01:36:49 +08:00
|
|
|
StringRef fieldName = DT.getName();
|
|
|
|
if (fieldName == "__forwarding")
|
2009-09-20 04:40:14 +08:00
|
|
|
forwardingField = Element;
|
2009-11-26 01:36:49 +08:00
|
|
|
else if (fieldName == varName)
|
2009-09-20 04:40:14 +08:00
|
|
|
varField = Element;
|
|
|
|
}
|
2009-09-20 04:40:05 +08:00
|
|
|
|
2009-09-20 04:40:14 +08:00
|
|
|
// Get the offsets for the forwarding field and the variable field.
|
2010-03-31 14:06:37 +08:00
|
|
|
unsigned forwardingFieldOffset =
|
2010-05-08 02:11:54 +08:00
|
|
|
DIDerivedType(forwardingField).getOffsetInBits() >> 3;
|
2010-03-31 14:06:37 +08:00
|
|
|
unsigned varFieldOffset =
|
2010-05-08 02:11:54 +08:00
|
|
|
DIDerivedType(varField).getOffsetInBits() >> 3;
|
2009-09-01 05:19:37 +08:00
|
|
|
|
2009-09-25 07:21:26 +08:00
|
|
|
// Decode the original location, and use that as the start of the byref
|
|
|
|
// variable's location.
|
2010-04-05 08:13:49 +08:00
|
|
|
const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo();
|
2009-09-20 04:40:14 +08:00
|
|
|
unsigned Reg = RI->getDwarfRegNum(Location.getReg(), false);
|
2010-04-01 03:34:01 +08:00
|
|
|
DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
|
2009-09-01 05:19:37 +08:00
|
|
|
|
2009-09-20 04:40:14 +08:00
|
|
|
if (Location.isReg()) {
|
|
|
|
if (Reg < 32)
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_reg0 + Reg);
|
2009-09-20 04:40:14 +08:00
|
|
|
else {
|
|
|
|
Reg = Reg - dwarf::DW_OP_reg0;
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_breg0 + Reg);
|
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_udata, Reg);
|
2009-09-20 04:40:14 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (Reg < 32)
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_breg0 + Reg);
|
2009-09-20 04:40:14 +08:00
|
|
|
else {
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_bregx);
|
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_udata, Reg);
|
2009-09-20 04:40:14 +08:00
|
|
|
}
|
2009-09-01 05:19:37 +08:00
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_sdata, Location.getOffset());
|
2009-09-20 04:40:14 +08:00
|
|
|
}
|
2009-09-01 05:19:37 +08:00
|
|
|
|
2009-09-25 07:21:26 +08:00
|
|
|
// If we started with a pointer to the __Block_byref... struct, then
|
2009-09-20 04:40:14 +08:00
|
|
|
// the first thing we need to do is dereference the pointer (DW_OP_deref).
|
|
|
|
if (isPointer)
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
|
2009-09-01 05:19:37 +08:00
|
|
|
|
2009-09-20 04:40:14 +08:00
|
|
|
// Next add the offset for the '__forwarding' field:
|
|
|
|
// DW_OP_plus_uconst ForwardingFieldOffset. Note there's no point in
|
|
|
|
// adding the offset if it's 0.
|
|
|
|
if (forwardingFieldOffset > 0) {
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
|
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_udata, forwardingFieldOffset);
|
2009-09-20 04:40:14 +08:00
|
|
|
}
|
2009-09-01 05:19:37 +08:00
|
|
|
|
2009-09-20 04:40:14 +08:00
|
|
|
// Now dereference the __forwarding field to get to the real __Block_byref
|
|
|
|
// struct: DW_OP_deref.
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
|
2009-09-01 05:19:37 +08:00
|
|
|
|
2009-09-20 04:40:14 +08:00
|
|
|
// Now that we've got the real __Block_byref... struct, add the offset
|
|
|
|
// for the variable's field to get to the location of the actual variable:
|
|
|
|
// DW_OP_plus_uconst varFieldOffset. Again, don't add if it's 0.
|
|
|
|
if (varFieldOffset > 0) {
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
|
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_udata, varFieldOffset);
|
2009-09-20 04:40:14 +08:00
|
|
|
}
|
2009-09-01 05:19:37 +08:00
|
|
|
|
2009-09-20 04:40:14 +08:00
|
|
|
// Now attach the location information to the DIE.
|
2009-11-21 10:48:08 +08:00
|
|
|
addBlock(Die, Attribute, 0, Block);
|
2009-09-01 05:19:37 +08:00
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// addAddress - Add an address attribute to a die based on the location
|
2009-05-15 17:23:25 +08:00
|
|
|
/// provided.
|
2009-11-21 10:48:08 +08:00
|
|
|
void DwarfDebug::addAddress(DIE *Die, unsigned Attribute,
|
2009-05-15 17:23:25 +08:00
|
|
|
const MachineLocation &Location) {
|
2010-04-05 08:13:49 +08:00
|
|
|
const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo();
|
2009-05-15 17:23:25 +08:00
|
|
|
unsigned Reg = RI->getDwarfRegNum(Location.getReg(), false);
|
2010-04-01 03:34:01 +08:00
|
|
|
DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
|
2010-09-23 05:10:38 +08:00
|
|
|
const TargetRegisterInfo *TRI = Asm->TM.getRegisterInfo();
|
|
|
|
|
|
|
|
if (TRI->getFrameRegister(*Asm->MF) == Location.getReg()
|
|
|
|
&& Location.getOffset()) {
|
|
|
|
// If variable offset is based in frame register then use fbreg.
|
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_fbreg);
|
|
|
|
addSInt(Block, 0, dwarf::DW_FORM_sdata, Location.getOffset());
|
|
|
|
addBlock(Die, Attribute, 0, Block);
|
|
|
|
return;
|
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
|
|
|
if (Location.isReg()) {
|
|
|
|
if (Reg < 32) {
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_reg0 + Reg);
|
2009-05-15 17:23:25 +08:00
|
|
|
} else {
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_regx);
|
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_udata, Reg);
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (Reg < 32) {
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_breg0 + Reg);
|
2009-05-15 17:23:25 +08:00
|
|
|
} else {
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_bregx);
|
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_udata, Reg);
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_sdata, Location.getOffset());
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
addBlock(Die, Attribute, 0, Block);
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
2010-04-28 09:03:09 +08:00
|
|
|
/// addRegisterAddress - Add register location entry in variable DIE.
|
2010-05-21 00:36:41 +08:00
|
|
|
bool DwarfDebug::addRegisterAddress(DIE *Die, const MCSymbol *VS,
|
2010-04-28 09:03:09 +08:00
|
|
|
const MachineOperand &MO) {
|
|
|
|
assert (MO.isReg() && "Invalid machine operand!");
|
|
|
|
if (!MO.getReg())
|
|
|
|
return false;
|
|
|
|
MachineLocation Location;
|
|
|
|
Location.set(MO.getReg());
|
|
|
|
addAddress(Die, dwarf::DW_AT_location, Location);
|
2010-05-21 00:36:41 +08:00
|
|
|
if (VS)
|
2010-04-28 09:03:09 +08:00
|
|
|
addLabel(Die, dwarf::DW_AT_start_scope, dwarf::DW_FORM_addr, VS);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// addConstantValue - Add constant value entry in variable DIE.
|
2010-05-21 00:36:41 +08:00
|
|
|
bool DwarfDebug::addConstantValue(DIE *Die, const MCSymbol *VS,
|
2010-04-28 09:03:09 +08:00
|
|
|
const MachineOperand &MO) {
|
|
|
|
assert (MO.isImm() && "Invalid machine operand!");
|
|
|
|
DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
|
|
|
|
unsigned Imm = MO.getImm();
|
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_udata, Imm);
|
|
|
|
addBlock(Die, dwarf::DW_AT_const_value, 0, Block);
|
2010-05-21 00:36:41 +08:00
|
|
|
if (VS)
|
2010-04-28 09:03:09 +08:00
|
|
|
addLabel(Die, dwarf::DW_AT_start_scope, dwarf::DW_FORM_addr, VS);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// addConstantFPValue - Add constant value entry in variable DIE.
|
2010-05-21 00:36:41 +08:00
|
|
|
bool DwarfDebug::addConstantFPValue(DIE *Die, const MCSymbol *VS,
|
2010-04-28 09:03:09 +08:00
|
|
|
const MachineOperand &MO) {
|
|
|
|
assert (MO.isFPImm() && "Invalid machine operand!");
|
|
|
|
DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
|
|
|
|
APFloat FPImm = MO.getFPImm()->getValueAPF();
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-04-28 09:03:09 +08:00
|
|
|
// Get the raw data form of the floating point.
|
|
|
|
const APInt FltVal = FPImm.bitcastToAPInt();
|
|
|
|
const char *FltPtr = (const char*)FltVal.getRawData();
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-04-28 09:03:09 +08:00
|
|
|
int NumBytes = FltVal.getBitWidth() / 8; // 8 bits per byte.
|
|
|
|
bool LittleEndian = Asm->getTargetData().isLittleEndian();
|
|
|
|
int Incr = (LittleEndian ? 1 : -1);
|
|
|
|
int Start = (LittleEndian ? 0 : NumBytes - 1);
|
|
|
|
int Stop = (LittleEndian ? NumBytes : -1);
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-04-28 09:03:09 +08:00
|
|
|
// Output the constant to DWARF one byte at a time.
|
|
|
|
for (; Start != Stop; Start += Incr)
|
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_data1,
|
|
|
|
(unsigned char)0xFF & FltPtr[Start]);
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-04-28 09:03:09 +08:00
|
|
|
addBlock(Die, dwarf::DW_AT_const_value, 0, Block);
|
2010-05-21 00:36:41 +08:00
|
|
|
if (VS)
|
|
|
|
addLabel(Die, dwarf::DW_AT_start_scope, dwarf::DW_FORM_addr, VS);
|
2010-07-22 05:21:52 +08:00
|
|
|
return true;
|
2010-04-28 09:03:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-11 03:14:49 +08:00
|
|
|
/// addToContextOwner - Add Die into the list of its context owner's children.
|
|
|
|
void DwarfDebug::addToContextOwner(DIE *Die, DIDescriptor Context) {
|
2010-03-09 04:52:55 +08:00
|
|
|
if (Context.isType()) {
|
2010-05-08 02:11:54 +08:00
|
|
|
DIE *ContextDIE = getOrCreateTypeDIE(DIType(Context));
|
2009-12-11 03:14:49 +08:00
|
|
|
ContextDIE->addChild(Die);
|
2009-12-16 03:16:48 +08:00
|
|
|
} else if (Context.isNameSpace()) {
|
2010-05-08 02:11:54 +08:00
|
|
|
DIE *ContextDIE = getOrCreateNameSpace(DINameSpace(Context));
|
2009-12-16 03:16:48 +08:00
|
|
|
ContextDIE->addChild(Die);
|
2010-06-12 04:08:44 +08:00
|
|
|
} else if (Context.isSubprogram()) {
|
2010-09-28 07:15:27 +08:00
|
|
|
DIE *ContextDIE = createSubprogramDIE(DISubprogram(Context));
|
2010-06-12 04:08:44 +08:00
|
|
|
ContextDIE->addChild(Die);
|
2010-05-11 06:49:55 +08:00
|
|
|
} else if (DIE *ContextDIE = getCompileUnit(Context)->getDIE(Context))
|
2009-12-11 03:14:49 +08:00
|
|
|
ContextDIE->addChild(Die);
|
2010-07-22 05:21:52 +08:00
|
|
|
else
|
2010-05-11 06:49:55 +08:00
|
|
|
getCompileUnit(Context)->addDie(Die);
|
2009-12-11 03:14:49 +08:00
|
|
|
}
|
|
|
|
|
2009-12-11 02:05:33 +08:00
|
|
|
/// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
|
|
|
|
/// given DIType.
|
|
|
|
DIE *DwarfDebug::getOrCreateTypeDIE(DIType Ty) {
|
2010-05-11 06:49:55 +08:00
|
|
|
CompileUnit *TypeCU = getCompileUnit(Ty);
|
|
|
|
DIE *TyDIE = TypeCU->getDIE(Ty);
|
2009-12-11 02:05:33 +08:00
|
|
|
if (TyDIE)
|
|
|
|
return TyDIE;
|
|
|
|
|
|
|
|
// Create new type.
|
|
|
|
TyDIE = new DIE(dwarf::DW_TAG_base_type);
|
2010-05-11 06:49:55 +08:00
|
|
|
TypeCU->insertDIE(Ty, TyDIE);
|
2009-12-11 02:05:33 +08:00
|
|
|
if (Ty.isBasicType())
|
2010-05-08 02:11:54 +08:00
|
|
|
constructTypeDIE(*TyDIE, DIBasicType(Ty));
|
2009-12-11 02:05:33 +08:00
|
|
|
else if (Ty.isCompositeType())
|
2010-05-08 02:11:54 +08:00
|
|
|
constructTypeDIE(*TyDIE, DICompositeType(Ty));
|
2009-12-11 02:05:33 +08:00
|
|
|
else {
|
|
|
|
assert(Ty.isDerivedType() && "Unknown kind of DIType");
|
2010-05-08 02:11:54 +08:00
|
|
|
constructTypeDIE(*TyDIE, DIDerivedType(Ty));
|
2009-12-11 02:05:33 +08:00
|
|
|
}
|
|
|
|
|
2009-12-11 03:14:49 +08:00
|
|
|
addToContextOwner(TyDIE, Ty.getContext());
|
2009-12-11 02:05:33 +08:00
|
|
|
return TyDIE;
|
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// addType - Add a new type attribute to the specified entity.
|
2009-12-10 02:24:21 +08:00
|
|
|
void DwarfDebug::addType(DIE *Entity, DIType Ty) {
|
2010-05-08 05:45:47 +08:00
|
|
|
if (!Ty.Verify())
|
2009-05-15 17:23:25 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Check for pre-existence.
|
2010-05-11 06:49:55 +08:00
|
|
|
CompileUnit *TypeCU = getCompileUnit(Ty);
|
|
|
|
DIEEntry *Entry = TypeCU->getDIEEntry(Ty);
|
2009-05-15 17:23:25 +08:00
|
|
|
// If it exists then use the existing value.
|
2009-11-21 10:48:08 +08:00
|
|
|
if (Entry) {
|
|
|
|
Entity->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, Entry);
|
2009-05-15 17:23:25 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Construct type.
|
2009-12-11 02:05:33 +08:00
|
|
|
DIE *Buffer = getOrCreateTypeDIE(Ty);
|
2009-12-09 07:21:45 +08:00
|
|
|
|
2010-03-13 01:45:06 +08:00
|
|
|
// Set up proxy.
|
|
|
|
Entry = createDIEEntry(Buffer);
|
2010-05-11 06:49:55 +08:00
|
|
|
TypeCU->insertDIEEntry(Ty, Entry);
|
2010-03-13 01:45:06 +08:00
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
Entity->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, Entry);
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// constructTypeDIE - Construct basic type die from DIBasicType.
|
2009-12-10 02:24:21 +08:00
|
|
|
void DwarfDebug::constructTypeDIE(DIE &Buffer, DIBasicType BTy) {
|
2009-05-15 17:23:25 +08:00
|
|
|
// Get core information.
|
2009-11-26 01:36:49 +08:00
|
|
|
StringRef Name = BTy.getName();
|
2009-05-15 17:23:25 +08:00
|
|
|
Buffer.setTag(dwarf::DW_TAG_base_type);
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(&Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
|
2009-05-15 17:23:25 +08:00
|
|
|
BTy.getEncoding());
|
|
|
|
|
|
|
|
// Add name if not anonymous or intermediate type.
|
2009-11-26 01:36:49 +08:00
|
|
|
if (!Name.empty())
|
2009-11-21 10:48:08 +08:00
|
|
|
addString(&Buffer, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name);
|
2009-05-15 17:23:25 +08:00
|
|
|
uint64_t Size = BTy.getSizeInBits() >> 3;
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(&Buffer, dwarf::DW_AT_byte_size, 0, Size);
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// constructTypeDIE - Construct derived type die from DIDerivedType.
|
2009-12-10 02:24:21 +08:00
|
|
|
void DwarfDebug::constructTypeDIE(DIE &Buffer, DIDerivedType DTy) {
|
2009-05-15 17:23:25 +08:00
|
|
|
// Get core information.
|
2009-11-26 01:36:49 +08:00
|
|
|
StringRef Name = DTy.getName();
|
2009-05-15 17:23:25 +08:00
|
|
|
uint64_t Size = DTy.getSizeInBits() >> 3;
|
|
|
|
unsigned Tag = DTy.getTag();
|
|
|
|
|
|
|
|
// FIXME - Workaround for templates.
|
|
|
|
if (Tag == dwarf::DW_TAG_inheritance) Tag = dwarf::DW_TAG_reference_type;
|
|
|
|
|
|
|
|
Buffer.setTag(Tag);
|
|
|
|
|
|
|
|
// Map to main type, void will not have a type.
|
|
|
|
DIType FromTy = DTy.getTypeDerivedFrom();
|
2009-12-10 02:24:21 +08:00
|
|
|
addType(&Buffer, FromTy);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
|
|
|
// Add name if not anonymous or intermediate type.
|
2009-12-01 07:56:56 +08:00
|
|
|
if (!Name.empty())
|
2009-11-21 10:48:08 +08:00
|
|
|
addString(&Buffer, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
|
|
|
// Add size if non-zero (derived types might be zero-sized.)
|
|
|
|
if (Size)
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(&Buffer, dwarf::DW_AT_byte_size, 0, Size);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
|
|
|
// Add source line info if available and TyDesc is not a forward declaration.
|
2009-11-24 02:43:37 +08:00
|
|
|
if (!DTy.isForwardDecl())
|
2010-08-10 04:20:05 +08:00
|
|
|
addSourceLine(&Buffer, DTy);
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// constructTypeDIE - Construct type DIE from DICompositeType.
|
2009-12-10 02:24:21 +08:00
|
|
|
void DwarfDebug::constructTypeDIE(DIE &Buffer, DICompositeType CTy) {
|
2009-05-15 17:23:25 +08:00
|
|
|
// Get core information.
|
2009-11-26 01:36:49 +08:00
|
|
|
StringRef Name = CTy.getName();
|
2009-05-15 17:23:25 +08:00
|
|
|
|
|
|
|
uint64_t Size = CTy.getSizeInBits() >> 3;
|
|
|
|
unsigned Tag = CTy.getTag();
|
|
|
|
Buffer.setTag(Tag);
|
|
|
|
|
|
|
|
switch (Tag) {
|
|
|
|
case dwarf::DW_TAG_vector_type:
|
|
|
|
case dwarf::DW_TAG_array_type:
|
2009-12-10 02:24:21 +08:00
|
|
|
constructArrayTypeDIE(Buffer, &CTy);
|
2009-05-15 17:23:25 +08:00
|
|
|
break;
|
|
|
|
case dwarf::DW_TAG_enumeration_type: {
|
|
|
|
DIArray Elements = CTy.getTypeArray();
|
|
|
|
|
|
|
|
// Add enumerators to enumeration type.
|
|
|
|
for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
|
|
|
|
DIE *ElemDie = NULL;
|
2010-05-08 02:11:54 +08:00
|
|
|
DIDescriptor Enum(Elements.getElement(i));
|
2010-03-09 04:52:55 +08:00
|
|
|
if (Enum.isEnumerator()) {
|
2010-05-08 02:11:54 +08:00
|
|
|
ElemDie = constructEnumTypeDIE(DIEnumerator(Enum));
|
2009-11-21 10:48:08 +08:00
|
|
|
Buffer.addChild(ElemDie);
|
2009-10-10 01:51:49 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case dwarf::DW_TAG_subroutine_type: {
|
|
|
|
// Add return type.
|
|
|
|
DIArray Elements = CTy.getTypeArray();
|
|
|
|
DIDescriptor RTy = Elements.getElement(0);
|
2010-05-08 02:11:54 +08:00
|
|
|
addType(&Buffer, DIType(RTy));
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-10-07 04:50:40 +08:00
|
|
|
bool isPrototyped = true;
|
2009-05-15 17:23:25 +08:00
|
|
|
// Add arguments.
|
|
|
|
for (unsigned i = 1, N = Elements.getNumElements(); i < N; ++i) {
|
|
|
|
DIDescriptor Ty = Elements.getElement(i);
|
2010-10-07 04:50:40 +08:00
|
|
|
if (Ty.isUnspecifiedParameter()) {
|
|
|
|
DIE *Arg = new DIE(dwarf::DW_TAG_unspecified_parameters);
|
|
|
|
Buffer.addChild(Arg);
|
|
|
|
isPrototyped = false;
|
|
|
|
} else {
|
|
|
|
DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter);
|
|
|
|
addType(Arg, DIType(Ty));
|
|
|
|
Buffer.addChild(Arg);
|
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
2010-10-07 04:50:40 +08:00
|
|
|
// Add prototype flag.
|
|
|
|
if (isPrototyped)
|
|
|
|
addUInt(&Buffer, dwarf::DW_AT_prototyped, dwarf::DW_FORM_flag, 1);
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case dwarf::DW_TAG_structure_type:
|
|
|
|
case dwarf::DW_TAG_union_type:
|
|
|
|
case dwarf::DW_TAG_class_type: {
|
|
|
|
// Add elements to structure type.
|
|
|
|
DIArray Elements = CTy.getTypeArray();
|
|
|
|
|
|
|
|
// A forward struct declared type may not have elements available.
|
2010-03-09 04:52:55 +08:00
|
|
|
unsigned N = Elements.getNumElements();
|
|
|
|
if (N == 0)
|
2009-05-15 17:23:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Add elements to structure type.
|
2010-03-09 04:52:55 +08:00
|
|
|
for (unsigned i = 0; i < N; ++i) {
|
2009-05-15 17:23:25 +08:00
|
|
|
DIDescriptor Element = Elements.getElement(i);
|
|
|
|
DIE *ElemDie = NULL;
|
2010-09-30 05:44:16 +08:00
|
|
|
if (Element.isSubprogram()) {
|
|
|
|
DISubprogram SP(Element);
|
2010-05-08 02:11:54 +08:00
|
|
|
ElemDie = createSubprogramDIE(DISubprogram(Element));
|
2010-09-30 05:44:16 +08:00
|
|
|
if (SP.isProtected())
|
|
|
|
addUInt(ElemDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_flag,
|
|
|
|
dwarf::DW_ACCESS_protected);
|
|
|
|
else if (SP.isPrivate())
|
|
|
|
addUInt(ElemDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_flag,
|
|
|
|
dwarf::DW_ACCESS_private);
|
|
|
|
else
|
|
|
|
addUInt(ElemDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_flag,
|
|
|
|
dwarf::DW_ACCESS_public);
|
2010-10-02 07:31:40 +08:00
|
|
|
if (SP.isExplicit())
|
|
|
|
addUInt(ElemDie, dwarf::DW_AT_explicit, dwarf::DW_FORM_flag, 1);
|
2010-09-30 05:44:16 +08:00
|
|
|
}
|
2010-03-09 04:52:55 +08:00
|
|
|
else if (Element.isVariable()) {
|
2010-05-08 02:11:54 +08:00
|
|
|
DIVariable DV(Element);
|
2010-01-30 09:08:30 +08:00
|
|
|
ElemDie = new DIE(dwarf::DW_TAG_variable);
|
|
|
|
addString(ElemDie, dwarf::DW_AT_name, dwarf::DW_FORM_string,
|
|
|
|
DV.getName());
|
|
|
|
addType(ElemDie, DV.getType());
|
|
|
|
addUInt(ElemDie, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1);
|
|
|
|
addUInt(ElemDie, dwarf::DW_AT_external, dwarf::DW_FORM_flag, 1);
|
2010-08-10 04:20:05 +08:00
|
|
|
addSourceLine(ElemDie, DV);
|
2010-03-09 04:52:55 +08:00
|
|
|
} else if (Element.isDerivedType())
|
2010-05-08 02:11:54 +08:00
|
|
|
ElemDie = createMemberDIE(DIDerivedType(Element));
|
2010-03-09 04:52:55 +08:00
|
|
|
else
|
|
|
|
continue;
|
2009-11-21 10:48:08 +08:00
|
|
|
Buffer.addChild(ElemDie);
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
2009-08-28 07:51:51 +08:00
|
|
|
if (CTy.isAppleBlockExtension())
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(&Buffer, dwarf::DW_AT_APPLE_block, dwarf::DW_FORM_flag, 1);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
|
|
|
unsigned RLang = CTy.getRunTimeLang();
|
|
|
|
if (RLang)
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(&Buffer, dwarf::DW_AT_APPLE_runtime_class,
|
2009-05-15 17:23:25 +08:00
|
|
|
dwarf::DW_FORM_data1, RLang);
|
2010-01-27 05:16:06 +08:00
|
|
|
|
|
|
|
DICompositeType ContainingType = CTy.getContainingType();
|
2010-05-08 02:11:54 +08:00
|
|
|
if (DIDescriptor(ContainingType).isCompositeType())
|
2010-07-22 05:21:52 +08:00
|
|
|
addDIEEntry(&Buffer, dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
|
2010-05-08 02:11:54 +08:00
|
|
|
getOrCreateTypeDIE(DIType(ContainingType)));
|
2010-06-12 04:08:44 +08:00
|
|
|
else {
|
|
|
|
DIDescriptor Context = CTy.getContext();
|
|
|
|
addToContextOwner(&Buffer, Context);
|
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add name if not anonymous or intermediate type.
|
2009-11-26 01:36:49 +08:00
|
|
|
if (!Name.empty())
|
2009-11-21 10:48:08 +08:00
|
|
|
addString(&Buffer, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-07-22 05:21:52 +08:00
|
|
|
if (Tag == dwarf::DW_TAG_enumeration_type || Tag == dwarf::DW_TAG_class_type
|
2010-07-08 04:12:52 +08:00
|
|
|
|| Tag == dwarf::DW_TAG_structure_type || Tag == dwarf::DW_TAG_union_type)
|
|
|
|
{
|
2009-05-15 17:23:25 +08:00
|
|
|
// Add size if non-zero (derived types might be zero-sized.)
|
|
|
|
if (Size)
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(&Buffer, dwarf::DW_AT_byte_size, 0, Size);
|
2009-05-15 17:23:25 +08:00
|
|
|
else {
|
|
|
|
// Add zero size if it is not a forward declaration.
|
|
|
|
if (CTy.isForwardDecl())
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(&Buffer, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1);
|
2009-05-15 17:23:25 +08:00
|
|
|
else
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(&Buffer, dwarf::DW_AT_byte_size, 0, 0);
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add source line info if available.
|
|
|
|
if (!CTy.isForwardDecl())
|
2010-08-10 04:20:05 +08:00
|
|
|
addSourceLine(&Buffer, CTy);
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// constructSubrangeDIE - Construct subrange DIE from DISubrange.
|
|
|
|
void DwarfDebug::constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy){
|
2009-05-15 17:23:25 +08:00
|
|
|
int64_t L = SR.getLo();
|
|
|
|
int64_t H = SR.getHi();
|
|
|
|
DIE *DW_Subrange = new DIE(dwarf::DW_TAG_subrange_type);
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
addDIEEntry(DW_Subrange, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IndexTy);
|
2009-08-15 04:59:16 +08:00
|
|
|
if (L)
|
2009-11-21 10:48:08 +08:00
|
|
|
addSInt(DW_Subrange, dwarf::DW_AT_lower_bound, 0, L);
|
2009-12-05 07:10:24 +08:00
|
|
|
addSInt(DW_Subrange, dwarf::DW_AT_upper_bound, 0, H);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
Buffer.addChild(DW_Subrange);
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
|
2009-12-10 02:24:21 +08:00
|
|
|
void DwarfDebug::constructArrayTypeDIE(DIE &Buffer,
|
2009-05-15 17:23:25 +08:00
|
|
|
DICompositeType *CTy) {
|
|
|
|
Buffer.setTag(dwarf::DW_TAG_array_type);
|
|
|
|
if (CTy->getTag() == dwarf::DW_TAG_vector_type)
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(&Buffer, dwarf::DW_AT_GNU_vector, dwarf::DW_FORM_flag, 1);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
|
|
|
// Emit derived type.
|
2009-12-10 02:24:21 +08:00
|
|
|
addType(&Buffer, CTy->getTypeDerivedFrom());
|
2009-05-15 17:23:25 +08:00
|
|
|
DIArray Elements = CTy->getTypeArray();
|
|
|
|
|
2009-11-21 08:31:03 +08:00
|
|
|
// Get an anonymous type for index type.
|
2010-05-11 06:49:55 +08:00
|
|
|
CompileUnit *TheCU = getCompileUnit(*CTy);
|
|
|
|
DIE *IdxTy = TheCU->getIndexTyDie();
|
2009-11-21 08:31:03 +08:00
|
|
|
if (!IdxTy) {
|
|
|
|
// Construct an anonymous type for index type.
|
|
|
|
IdxTy = new DIE(dwarf::DW_TAG_base_type);
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(IdxTy, dwarf::DW_AT_byte_size, 0, sizeof(int32_t));
|
|
|
|
addUInt(IdxTy, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
|
2009-11-21 08:31:03 +08:00
|
|
|
dwarf::DW_ATE_signed);
|
2010-05-11 06:49:55 +08:00
|
|
|
TheCU->addDie(IdxTy);
|
|
|
|
TheCU->setIndexTyDie(IdxTy);
|
2009-11-21 08:31:03 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
|
|
|
// Add subranges to array type.
|
|
|
|
for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
|
|
|
|
DIDescriptor Element = Elements.getElement(i);
|
|
|
|
if (Element.getTag() == dwarf::DW_TAG_subrange_type)
|
2010-05-08 02:11:54 +08:00
|
|
|
constructSubrangeDIE(Buffer, DISubrange(Element), IdxTy);
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
|
2010-03-09 04:52:55 +08:00
|
|
|
DIE *DwarfDebug::constructEnumTypeDIE(DIEnumerator ETy) {
|
2009-05-15 17:23:25 +08:00
|
|
|
DIE *Enumerator = new DIE(dwarf::DW_TAG_enumerator);
|
2010-03-09 04:52:55 +08:00
|
|
|
StringRef Name = ETy.getName();
|
2009-11-21 10:48:08 +08:00
|
|
|
addString(Enumerator, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name);
|
2010-03-09 04:52:55 +08:00
|
|
|
int64_t Value = ETy.getEnumValue();
|
2009-11-21 10:48:08 +08:00
|
|
|
addSInt(Enumerator, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata, Value);
|
2009-05-15 17:23:25 +08:00
|
|
|
return Enumerator;
|
|
|
|
}
|
|
|
|
|
2010-07-22 05:21:52 +08:00
|
|
|
/// getRealLinkageName - If special LLVM prefix that is used to inform the asm
|
2010-01-05 09:46:14 +08:00
|
|
|
/// printer to not emit usual symbol prefix before the symbol name is used then
|
|
|
|
/// return linkage name after skipping this special LLVM prefix.
|
|
|
|
static StringRef getRealLinkageName(StringRef LinkageName) {
|
|
|
|
char One = '\1';
|
|
|
|
if (LinkageName.startswith(StringRef(&One, 1)))
|
|
|
|
return LinkageName.substr(1);
|
|
|
|
return LinkageName;
|
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// createMemberDIE - Create new member DIE.
|
2010-08-10 12:12:17 +08:00
|
|
|
DIE *DwarfDebug::createMemberDIE(DIDerivedType DT) {
|
2009-05-15 17:23:25 +08:00
|
|
|
DIE *MemberDie = new DIE(DT.getTag());
|
2009-11-26 01:36:49 +08:00
|
|
|
StringRef Name = DT.getName();
|
|
|
|
if (!Name.empty())
|
2009-11-21 10:48:08 +08:00
|
|
|
addString(MemberDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name);
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2009-12-10 02:24:21 +08:00
|
|
|
addType(MemberDie, DT.getTypeDerivedFrom());
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-08-10 04:20:05 +08:00
|
|
|
addSourceLine(MemberDie, DT);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-04-01 03:34:01 +08:00
|
|
|
DIEBlock *MemLocationDie = new (DIEValueAllocator) DIEBlock();
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(MemLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
|
2009-11-05 06:06:12 +08:00
|
|
|
|
2009-05-15 17:23:25 +08:00
|
|
|
uint64_t Size = DT.getSizeInBits();
|
2009-11-05 07:48:00 +08:00
|
|
|
uint64_t FieldSize = DT.getOriginalTypeSize();
|
2009-05-15 17:23:25 +08:00
|
|
|
|
|
|
|
if (Size != FieldSize) {
|
|
|
|
// Handle bitfield.
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(MemberDie, dwarf::DW_AT_byte_size, 0, DT.getOriginalTypeSize()>>3);
|
|
|
|
addUInt(MemberDie, dwarf::DW_AT_bit_size, 0, DT.getSizeInBits());
|
2009-05-15 17:23:25 +08:00
|
|
|
|
|
|
|
uint64_t Offset = DT.getOffsetInBits();
|
|
|
|
uint64_t AlignMask = ~(DT.getAlignInBits() - 1);
|
|
|
|
uint64_t HiMark = (Offset + FieldSize) & AlignMask;
|
2010-01-08 01:50:57 +08:00
|
|
|
uint64_t FieldOffset = (HiMark - FieldSize);
|
2009-05-15 17:23:25 +08:00
|
|
|
Offset -= FieldOffset;
|
|
|
|
|
|
|
|
// Maybe we need to work from the other end.
|
2010-04-05 08:13:49 +08:00
|
|
|
if (Asm->getTargetData().isLittleEndian())
|
|
|
|
Offset = FieldSize - (Offset + Size);
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(MemberDie, dwarf::DW_AT_bit_offset, 0, Offset);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-11-05 06:06:12 +08:00
|
|
|
// Here WD_AT_data_member_location points to the anonymous
|
|
|
|
// field that includes this bit field.
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(MemLocationDie, 0, dwarf::DW_FORM_udata, FieldOffset >> 3);
|
2009-11-05 06:06:12 +08:00
|
|
|
|
|
|
|
} else
|
|
|
|
// This is not a bitfield.
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(MemLocationDie, 0, dwarf::DW_FORM_udata, DT.getOffsetInBits() >> 3);
|
2009-11-05 06:06:12 +08:00
|
|
|
|
2010-02-04 04:08:48 +08:00
|
|
|
if (DT.getTag() == dwarf::DW_TAG_inheritance
|
|
|
|
&& DT.isVirtual()) {
|
|
|
|
|
|
|
|
// For C++, virtual base classes are not at fixed offset. Use following
|
|
|
|
// expression to extract appropriate offset from vtable.
|
|
|
|
// BaseAddr = ObAddr + *((*ObAddr) - Offset)
|
|
|
|
|
2010-04-01 03:34:01 +08:00
|
|
|
DIEBlock *VBaseLocationDie = new (DIEValueAllocator) DIEBlock();
|
2010-02-04 04:08:48 +08:00
|
|
|
addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_dup);
|
|
|
|
addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
|
|
|
|
addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
|
|
|
|
addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_udata, DT.getOffsetInBits());
|
|
|
|
addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_minus);
|
|
|
|
addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
|
|
|
|
addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
|
|
|
|
|
2010-07-22 05:21:52 +08:00
|
|
|
addBlock(MemberDie, dwarf::DW_AT_data_member_location, 0,
|
2010-02-04 04:08:48 +08:00
|
|
|
VBaseLocationDie);
|
|
|
|
} else
|
|
|
|
addBlock(MemberDie, dwarf::DW_AT_data_member_location, 0, MemLocationDie);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
|
|
|
if (DT.isProtected())
|
2009-12-04 03:11:07 +08:00
|
|
|
addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_flag,
|
2009-05-15 17:23:25 +08:00
|
|
|
dwarf::DW_ACCESS_protected);
|
|
|
|
else if (DT.isPrivate())
|
2009-12-04 03:11:07 +08:00
|
|
|
addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_flag,
|
2009-05-15 17:23:25 +08:00
|
|
|
dwarf::DW_ACCESS_private);
|
2010-09-30 03:08:08 +08:00
|
|
|
// Otherwise C++ member and base classes are considered public.
|
|
|
|
else if (DT.getCompileUnit().getLanguage() == dwarf::DW_LANG_C_plus_plus)
|
2009-12-04 03:11:07 +08:00
|
|
|
addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_flag,
|
|
|
|
dwarf::DW_ACCESS_public);
|
|
|
|
if (DT.isVirtual())
|
|
|
|
addUInt(MemberDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_flag,
|
|
|
|
dwarf::DW_VIRTUALITY_virtual);
|
2009-05-15 17:23:25 +08:00
|
|
|
return MemberDie;
|
|
|
|
}
|
|
|
|
|
2009-12-15 00:18:45 +08:00
|
|
|
/// createSubprogramDIE - Create new DIE using SP.
|
2010-09-28 07:15:27 +08:00
|
|
|
DIE *DwarfDebug::createSubprogramDIE(DISubprogram SP) {
|
2010-05-11 06:49:55 +08:00
|
|
|
CompileUnit *SPCU = getCompileUnit(SP);
|
|
|
|
DIE *SPDie = SPCU->getDIE(SP);
|
2009-12-15 00:18:45 +08:00
|
|
|
if (SPDie)
|
|
|
|
return SPDie;
|
|
|
|
|
|
|
|
SPDie = new DIE(dwarf::DW_TAG_subprogram);
|
2010-03-03 01:58:15 +08:00
|
|
|
// Constructors and operators for anonymous aggregates do not have names.
|
2010-03-02 09:26:20 +08:00
|
|
|
if (!SP.getName().empty())
|
|
|
|
addString(SPDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, SP.getName());
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-11-26 01:36:49 +08:00
|
|
|
StringRef LinkageName = SP.getLinkageName();
|
2010-01-05 09:46:14 +08:00
|
|
|
if (!LinkageName.empty())
|
2009-11-21 10:48:08 +08:00
|
|
|
addString(SPDie, dwarf::DW_AT_MIPS_linkage_name, dwarf::DW_FORM_string,
|
2010-01-05 09:46:14 +08:00
|
|
|
getRealLinkageName(LinkageName));
|
|
|
|
|
2010-08-10 04:20:05 +08:00
|
|
|
addSourceLine(SPDie, SP);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-10-08 06:03:01 +08:00
|
|
|
if (SP.isPrototyped())
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(SPDie, dwarf::DW_AT_prototyped, dwarf::DW_FORM_flag, 1);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
|
|
|
// Add Return Type.
|
2009-12-03 09:25:38 +08:00
|
|
|
DICompositeType SPTy = SP.getType();
|
|
|
|
DIArray Args = SPTy.getTypeArray();
|
2009-05-15 17:23:25 +08:00
|
|
|
unsigned SPTag = SPTy.getTag();
|
2009-12-04 03:11:07 +08:00
|
|
|
|
2010-03-09 04:52:55 +08:00
|
|
|
if (Args.getNumElements() == 0 || SPTag != dwarf::DW_TAG_subroutine_type)
|
2009-12-10 02:24:21 +08:00
|
|
|
addType(SPDie, SPTy);
|
2009-12-03 09:25:38 +08:00
|
|
|
else
|
2010-05-08 02:11:54 +08:00
|
|
|
addType(SPDie, DIType(Args.getElement(0)));
|
2009-12-03 09:25:38 +08:00
|
|
|
|
2009-12-04 03:11:07 +08:00
|
|
|
unsigned VK = SP.getVirtuality();
|
|
|
|
if (VK) {
|
|
|
|
addUInt(SPDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_flag, VK);
|
2010-04-01 03:34:01 +08:00
|
|
|
DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
|
2009-12-04 03:11:07 +08:00
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
|
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_data1, SP.getVirtualIndex());
|
|
|
|
addBlock(SPDie, dwarf::DW_AT_vtable_elem_location, 0, Block);
|
2010-07-22 05:21:52 +08:00
|
|
|
ContainingTypeMap.insert(std::make_pair(SPDie,
|
2010-05-08 02:11:54 +08:00
|
|
|
SP.getContainingType()));
|
2009-12-04 03:11:07 +08:00
|
|
|
}
|
|
|
|
|
2010-09-28 07:15:27 +08:00
|
|
|
if (!SP.isDefinition()) {
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(SPDie, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
|
|
|
// Add arguments. Do not add arguments for subprogram definition. They will
|
2009-12-03 09:25:38 +08:00
|
|
|
// be handled while processing variables.
|
|
|
|
DICompositeType SPTy = SP.getType();
|
|
|
|
DIArray Args = SPTy.getTypeArray();
|
|
|
|
unsigned SPTag = SPTy.getTag();
|
|
|
|
|
2009-05-15 17:23:25 +08:00
|
|
|
if (SPTag == dwarf::DW_TAG_subroutine_type)
|
|
|
|
for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
|
|
|
|
DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter);
|
2010-05-08 02:11:54 +08:00
|
|
|
DIType ATy = DIType(DIType(Args.getElement(i)));
|
2010-02-06 09:02:37 +08:00
|
|
|
addType(Arg, ATy);
|
|
|
|
if (ATy.isArtificial())
|
|
|
|
addUInt(Arg, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1);
|
2009-11-21 10:48:08 +08:00
|
|
|
SPDie->addChild(Arg);
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-04 03:57:19 +08:00
|
|
|
if (SP.isArtificial())
|
|
|
|
addUInt(SPDie, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1);
|
|
|
|
|
2010-05-01 03:38:23 +08:00
|
|
|
if (!SP.isLocalToUnit())
|
|
|
|
addUInt(SPDie, dwarf::DW_AT_external, dwarf::DW_FORM_flag, 1);
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-01 03:38:23 +08:00
|
|
|
if (SP.isOptimized())
|
|
|
|
addUInt(SPDie, dwarf::DW_AT_APPLE_optimized, dwarf::DW_FORM_flag, 1);
|
|
|
|
|
2010-07-22 07:03:52 +08:00
|
|
|
if (unsigned isa = Asm->getISAEncoding()) {
|
|
|
|
addUInt(SPDie, dwarf::DW_AT_APPLE_isa, dwarf::DW_FORM_flag, isa);
|
|
|
|
}
|
|
|
|
|
2010-05-01 03:38:23 +08:00
|
|
|
// DW_TAG_inlined_subroutine may refer to this DIE.
|
2010-05-11 06:49:55 +08:00
|
|
|
SPCU->insertDIE(SP, SPDie);
|
2010-05-01 03:38:23 +08:00
|
|
|
|
2010-06-12 04:08:44 +08:00
|
|
|
// Add to context owner.
|
|
|
|
addToContextOwner(SPDie, SP.getContext());
|
|
|
|
|
2009-05-15 17:23:25 +08:00
|
|
|
return SPDie;
|
|
|
|
}
|
|
|
|
|
2010-05-08 04:54:48 +08:00
|
|
|
DbgScope *DwarfDebug::getOrCreateAbstractScope(const MDNode *N) {
|
2010-03-31 13:36:29 +08:00
|
|
|
assert(N && "Invalid Scope encoding!");
|
2009-11-11 07:06:00 +08:00
|
|
|
|
|
|
|
DbgScope *AScope = AbstractScopes.lookup(N);
|
|
|
|
if (AScope)
|
|
|
|
return AScope;
|
2009-11-22 07:12:12 +08:00
|
|
|
|
2009-11-11 07:06:00 +08:00
|
|
|
DbgScope *Parent = NULL;
|
|
|
|
|
|
|
|
DIDescriptor Scope(N);
|
|
|
|
if (Scope.isLexicalBlock()) {
|
|
|
|
DILexicalBlock DB(N);
|
|
|
|
DIDescriptor ParentDesc = DB.getContext();
|
2010-05-08 02:11:54 +08:00
|
|
|
Parent = getOrCreateAbstractScope(ParentDesc);
|
2009-11-11 07:06:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
AScope = new DbgScope(Parent, DIDescriptor(N), NULL);
|
|
|
|
|
|
|
|
if (Parent)
|
2009-11-21 10:48:08 +08:00
|
|
|
Parent->addScope(AScope);
|
2009-11-11 07:06:00 +08:00
|
|
|
AScope->setAbstractScope();
|
|
|
|
AbstractScopes[N] = AScope;
|
|
|
|
if (DIDescriptor(N).isSubprogram())
|
|
|
|
AbstractScopesList.push_back(AScope);
|
|
|
|
return AScope;
|
|
|
|
}
|
2009-10-02 04:31:14 +08:00
|
|
|
|
2010-04-07 07:53:48 +08:00
|
|
|
/// isSubprogramContext - Return true if Context is either a subprogram
|
|
|
|
/// or another context nested inside a subprogram.
|
2010-05-08 04:54:48 +08:00
|
|
|
static bool isSubprogramContext(const MDNode *Context) {
|
2010-04-07 07:53:48 +08:00
|
|
|
if (!Context)
|
|
|
|
return false;
|
|
|
|
DIDescriptor D(Context);
|
|
|
|
if (D.isSubprogram())
|
|
|
|
return true;
|
|
|
|
if (D.isType())
|
2010-05-08 02:11:54 +08:00
|
|
|
return isSubprogramContext(DIType(Context).getContext());
|
2010-04-07 07:53:48 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-11-22 07:12:12 +08:00
|
|
|
/// updateSubprogramScopeDIE - Find DIE for the given subprogram and
|
2009-11-21 10:48:08 +08:00
|
|
|
/// attach appropriate DW_AT_low_pc and DW_AT_high_pc attributes.
|
|
|
|
/// If there are global variables in this scope then create and insert
|
|
|
|
/// DIEs for these variables.
|
2010-05-08 04:54:48 +08:00
|
|
|
DIE *DwarfDebug::updateSubprogramScopeDIE(const MDNode *SPNode) {
|
2010-05-11 06:49:55 +08:00
|
|
|
CompileUnit *SPCU = getCompileUnit(SPNode);
|
|
|
|
DIE *SPDie = SPCU->getDIE(SPNode);
|
2010-07-08 06:20:57 +08:00
|
|
|
|
2010-04-05 08:13:49 +08:00
|
|
|
assert(SPDie && "Unable to find subprogram DIE!");
|
|
|
|
DISubprogram SP(SPNode);
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-04-05 08:13:49 +08:00
|
|
|
// There is not any need to generate specification DIE for a function
|
|
|
|
// defined at compile unit level. If a function is defined inside another
|
|
|
|
// function then gdb prefers the definition at top level and but does not
|
2010-07-22 05:21:52 +08:00
|
|
|
// expect specification DIE in parent function. So avoid creating
|
2010-04-05 08:13:49 +08:00
|
|
|
// specification DIE for a function defined inside a function.
|
|
|
|
if (SP.isDefinition() && !SP.getContext().isCompileUnit() &&
|
2010-07-22 05:21:52 +08:00
|
|
|
!SP.getContext().isFile() &&
|
2010-05-08 02:11:54 +08:00
|
|
|
!isSubprogramContext(SP.getContext())) {
|
2010-04-05 08:13:49 +08:00
|
|
|
addUInt(SPDie, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1);
|
2010-07-22 05:21:52 +08:00
|
|
|
|
|
|
|
// Add arguments.
|
2010-04-05 08:13:49 +08:00
|
|
|
DICompositeType SPTy = SP.getType();
|
|
|
|
DIArray Args = SPTy.getTypeArray();
|
|
|
|
unsigned SPTag = SPTy.getTag();
|
|
|
|
if (SPTag == dwarf::DW_TAG_subroutine_type)
|
|
|
|
for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
|
|
|
|
DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter);
|
2010-05-08 02:11:54 +08:00
|
|
|
DIType ATy = DIType(DIType(Args.getElement(i)));
|
2010-04-05 08:13:49 +08:00
|
|
|
addType(Arg, ATy);
|
|
|
|
if (ATy.isArtificial())
|
|
|
|
addUInt(Arg, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1);
|
|
|
|
SPDie->addChild(Arg);
|
|
|
|
}
|
|
|
|
DIE *SPDeclDie = SPDie;
|
|
|
|
SPDie = new DIE(dwarf::DW_TAG_subprogram);
|
2010-07-22 05:21:52 +08:00
|
|
|
addDIEEntry(SPDie, dwarf::DW_AT_specification, dwarf::DW_FORM_ref4,
|
2010-04-05 08:13:49 +08:00
|
|
|
SPDeclDie);
|
2010-05-11 06:49:55 +08:00
|
|
|
SPCU->addDie(SPDie);
|
2010-04-05 08:13:49 +08:00
|
|
|
}
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-07-08 06:20:57 +08:00
|
|
|
// Pick up abstract subprogram DIE.
|
|
|
|
if (DIE *AbsSPDIE = AbstractSPDies.lookup(SPNode)) {
|
|
|
|
SPDie = new DIE(dwarf::DW_TAG_subprogram);
|
|
|
|
addDIEEntry(SPDie, dwarf::DW_AT_abstract_origin,
|
|
|
|
dwarf::DW_FORM_ref4, AbsSPDIE);
|
|
|
|
SPCU->addDie(SPDie);
|
|
|
|
}
|
|
|
|
|
2010-04-05 08:13:49 +08:00
|
|
|
addLabel(SPDie, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
|
|
|
|
Asm->GetTempSymbol("func_begin", Asm->getFunctionNumber()));
|
|
|
|
addLabel(SPDie, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr,
|
|
|
|
Asm->GetTempSymbol("func_end", Asm->getFunctionNumber()));
|
|
|
|
const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo();
|
|
|
|
MachineLocation Location(RI->getFrameRegister(*Asm->MF));
|
|
|
|
addAddress(SPDie, dwarf::DW_AT_frame_base, Location);
|
|
|
|
|
|
|
|
return SPDie;
|
2009-11-11 07:06:00 +08:00
|
|
|
}
|
|
|
|
|
2009-11-22 07:12:12 +08:00
|
|
|
/// constructLexicalScope - Construct new DW_TAG_lexical_block
|
2009-11-21 10:48:08 +08:00
|
|
|
/// for this scope and attach DW_AT_low_pc/DW_AT_high_pc labels.
|
|
|
|
DIE *DwarfDebug::constructLexicalScopeDIE(DbgScope *Scope) {
|
2010-04-22 00:32:19 +08:00
|
|
|
|
2010-04-23 09:18:53 +08:00
|
|
|
DIE *ScopeDIE = new DIE(dwarf::DW_TAG_lexical_block);
|
|
|
|
if (Scope->isAbstractScope())
|
|
|
|
return ScopeDIE;
|
|
|
|
|
2010-04-28 03:46:33 +08:00
|
|
|
const SmallVector<DbgRange, 4> &Ranges = Scope->getRanges();
|
|
|
|
if (Ranges.empty())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
SmallVector<DbgRange, 4>::const_iterator RI = Ranges.begin();
|
|
|
|
if (Ranges.size() > 1) {
|
|
|
|
// .debug_range section has not been laid out yet. Emit offset in
|
2010-07-22 05:21:52 +08:00
|
|
|
// .debug_range as a uint, size 4, for now. emitDIE will handle
|
2010-04-28 03:46:33 +08:00
|
|
|
// DW_AT_ranges appropriately.
|
|
|
|
addUInt(ScopeDIE, dwarf::DW_AT_ranges, dwarf::DW_FORM_data4,
|
|
|
|
DebugRangeSymbols.size() * Asm->getTargetData().getPointerSize());
|
|
|
|
for (SmallVector<DbgRange, 4>::const_iterator RI = Ranges.begin(),
|
|
|
|
RE = Ranges.end(); RI != RE; ++RI) {
|
2010-05-26 07:40:22 +08:00
|
|
|
DebugRangeSymbols.push_back(getLabelBeforeInsn(RI->first));
|
|
|
|
DebugRangeSymbols.push_back(getLabelAfterInsn(RI->second));
|
2010-04-28 03:46:33 +08:00
|
|
|
}
|
|
|
|
DebugRangeSymbols.push_back(NULL);
|
|
|
|
DebugRangeSymbols.push_back(NULL);
|
|
|
|
return ScopeDIE;
|
|
|
|
}
|
|
|
|
|
2010-05-26 07:40:22 +08:00
|
|
|
const MCSymbol *Start = getLabelBeforeInsn(RI->first);
|
|
|
|
const MCSymbol *End = getLabelAfterInsn(RI->second);
|
2010-04-28 03:46:33 +08:00
|
|
|
|
2010-05-26 07:40:22 +08:00
|
|
|
if (End == 0) return 0;
|
2010-04-28 03:46:33 +08:00
|
|
|
|
|
|
|
assert(Start->isDefined() && "Invalid starting label for an inlined scope!");
|
|
|
|
assert(End->isDefined() && "Invalid end label for an inlined scope!");
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-04-28 03:46:33 +08:00
|
|
|
addLabel(ScopeDIE, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, Start);
|
|
|
|
addLabel(ScopeDIE, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr, End);
|
2009-11-11 07:06:00 +08:00
|
|
|
|
|
|
|
return ScopeDIE;
|
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// constructInlinedScopeDIE - This scope represents inlined body of
|
|
|
|
/// a function. Construct DIE to represent this concrete inlined copy
|
|
|
|
/// of the function.
|
|
|
|
DIE *DwarfDebug::constructInlinedScopeDIE(DbgScope *Scope) {
|
2010-04-28 03:46:33 +08:00
|
|
|
|
|
|
|
const SmallVector<DbgRange, 4> &Ranges = Scope->getRanges();
|
2010-07-22 05:21:52 +08:00
|
|
|
assert (Ranges.empty() == false
|
2010-04-28 03:46:33 +08:00
|
|
|
&& "DbgScope does not have instruction markers!");
|
|
|
|
|
|
|
|
// FIXME : .debug_inlined section specification does not clearly state how
|
|
|
|
// to emit inlined scope that is split into multiple instruction ranges.
|
|
|
|
// For now, use first instruction range and emit low_pc/high_pc pair and
|
|
|
|
// corresponding .debug_inlined section entry for this pair.
|
|
|
|
SmallVector<DbgRange, 4>::const_iterator RI = Ranges.begin();
|
2010-05-26 07:40:22 +08:00
|
|
|
const MCSymbol *StartLabel = getLabelBeforeInsn(RI->first);
|
|
|
|
const MCSymbol *EndLabel = getLabelAfterInsn(RI->second);
|
2010-04-28 03:46:33 +08:00
|
|
|
|
2010-07-09 06:39:20 +08:00
|
|
|
if (StartLabel == 0 || EndLabel == 0) {
|
2010-04-28 03:46:33 +08:00
|
|
|
assert (0 && "Unexpected Start and End labels for a inlined scope!");
|
|
|
|
return 0;
|
|
|
|
}
|
2010-03-09 09:58:53 +08:00
|
|
|
assert(StartLabel->isDefined() &&
|
2010-03-09 09:51:43 +08:00
|
|
|
"Invalid starting label for an inlined scope!");
|
2010-03-09 09:58:53 +08:00
|
|
|
assert(EndLabel->isDefined() &&
|
2010-03-09 09:51:43 +08:00
|
|
|
"Invalid end label for an inlined scope!");
|
2010-04-28 03:46:33 +08:00
|
|
|
|
2010-03-09 04:52:55 +08:00
|
|
|
if (!Scope->getScopeNode())
|
2010-03-09 03:20:38 +08:00
|
|
|
return NULL;
|
2010-03-09 04:52:55 +08:00
|
|
|
DIScope DS(Scope->getScopeNode());
|
2009-11-11 07:06:00 +08:00
|
|
|
DIE *ScopeDIE = new DIE(dwarf::DW_TAG_inlined_subroutine);
|
|
|
|
|
2010-05-08 02:11:54 +08:00
|
|
|
DISubprogram InlinedSP = getDISubprogram(DS);
|
2010-05-11 06:49:55 +08:00
|
|
|
CompileUnit *TheCU = getCompileUnit(InlinedSP);
|
|
|
|
DIE *OriginDIE = TheCU->getDIE(InlinedSP);
|
2010-03-31 13:36:29 +08:00
|
|
|
assert(OriginDIE && "Unable to find Origin DIE!");
|
2009-11-21 10:48:08 +08:00
|
|
|
addDIEEntry(ScopeDIE, dwarf::DW_AT_abstract_origin,
|
2009-11-11 07:06:00 +08:00
|
|
|
dwarf::DW_FORM_ref4, OriginDIE);
|
|
|
|
|
2010-03-09 08:31:02 +08:00
|
|
|
addLabel(ScopeDIE, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, StartLabel);
|
2010-03-09 09:58:53 +08:00
|
|
|
addLabel(ScopeDIE, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr, EndLabel);
|
2009-11-11 07:06:00 +08:00
|
|
|
|
|
|
|
InlinedSubprogramDIEs.insert(OriginDIE);
|
|
|
|
|
|
|
|
// Track the start label for this inlined function.
|
2010-05-08 04:54:48 +08:00
|
|
|
DenseMap<const MDNode *, SmallVector<InlineInfoLabels, 4> >::iterator
|
2010-05-08 02:11:54 +08:00
|
|
|
I = InlineInfo.find(InlinedSP);
|
2009-11-11 07:06:00 +08:00
|
|
|
|
|
|
|
if (I == InlineInfo.end()) {
|
2010-05-08 02:11:54 +08:00
|
|
|
InlineInfo[InlinedSP].push_back(std::make_pair(StartLabel,
|
2009-11-23 03:20:36 +08:00
|
|
|
ScopeDIE));
|
2010-05-08 02:11:54 +08:00
|
|
|
InlinedSPNodes.push_back(InlinedSP);
|
2009-11-11 07:06:00 +08:00
|
|
|
} else
|
2010-03-09 08:31:02 +08:00
|
|
|
I->second.push_back(std::make_pair(StartLabel, ScopeDIE));
|
2009-11-11 07:06:00 +08:00
|
|
|
|
|
|
|
DILocation DL(Scope->getInlinedAt());
|
2010-05-11 06:49:55 +08:00
|
|
|
addUInt(ScopeDIE, dwarf::DW_AT_call_file, 0, TheCU->getID());
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(ScopeDIE, dwarf::DW_AT_call_line, 0, DL.getLineNumber());
|
2009-11-11 07:06:00 +08:00
|
|
|
|
|
|
|
return ScopeDIE;
|
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
|
|
|
|
/// constructVariableDIE - Construct a DIE for the given DbgVariable.
|
2009-12-10 02:24:21 +08:00
|
|
|
DIE *DwarfDebug::constructVariableDIE(DbgVariable *DV, DbgScope *Scope) {
|
2010-08-10 05:01:39 +08:00
|
|
|
StringRef Name = DV->getName();
|
2009-11-26 01:36:49 +08:00
|
|
|
if (Name.empty())
|
2009-11-13 10:25:26 +08:00
|
|
|
return NULL;
|
2009-11-11 07:06:00 +08:00
|
|
|
|
|
|
|
// Translate tag to proper Dwarf tag. The result variable is dropped for
|
|
|
|
// now.
|
|
|
|
unsigned Tag;
|
2010-08-10 05:01:39 +08:00
|
|
|
switch (DV->getTag()) {
|
2009-11-11 07:06:00 +08:00
|
|
|
case dwarf::DW_TAG_return_variable:
|
|
|
|
return NULL;
|
|
|
|
case dwarf::DW_TAG_arg_variable:
|
|
|
|
Tag = dwarf::DW_TAG_formal_parameter;
|
|
|
|
break;
|
|
|
|
case dwarf::DW_TAG_auto_variable: // fall thru
|
|
|
|
default:
|
|
|
|
Tag = dwarf::DW_TAG_variable;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Define variable debug information entry.
|
|
|
|
DIE *VariableDie = new DIE(Tag);
|
|
|
|
|
|
|
|
DIE *AbsDIE = NULL;
|
2010-05-21 00:36:41 +08:00
|
|
|
DenseMap<const DbgVariable *, const DbgVariable *>::iterator
|
|
|
|
V2AVI = VarToAbstractVarMap.find(DV);
|
|
|
|
if (V2AVI != VarToAbstractVarMap.end())
|
|
|
|
AbsDIE = V2AVI->second->getDIE();
|
|
|
|
|
|
|
|
if (AbsDIE)
|
2009-11-21 10:48:08 +08:00
|
|
|
addDIEEntry(VariableDie, dwarf::DW_AT_abstract_origin,
|
2009-11-11 07:06:00 +08:00
|
|
|
dwarf::DW_FORM_ref4, AbsDIE);
|
|
|
|
else {
|
2009-11-21 10:48:08 +08:00
|
|
|
addString(VariableDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name);
|
2010-08-10 05:01:39 +08:00
|
|
|
addSourceLine(VariableDie, DV->getVariable());
|
2009-11-11 07:06:00 +08:00
|
|
|
|
|
|
|
// Add variable type.
|
2010-08-10 05:01:39 +08:00
|
|
|
addType(VariableDie, DV->getType());
|
2009-11-11 07:06:00 +08:00
|
|
|
}
|
|
|
|
|
2010-08-10 05:01:39 +08:00
|
|
|
if (Tag == dwarf::DW_TAG_formal_parameter && DV->getType().isArtificial())
|
2010-05-26 07:40:22 +08:00
|
|
|
addUInt(VariableDie, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1);
|
2010-09-30 07:07:21 +08:00
|
|
|
else if (DIVariable(DV->getVariable()).isArtificial())
|
|
|
|
addUInt(VariableDie, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1);
|
2010-05-26 07:40:22 +08:00
|
|
|
|
|
|
|
if (Scope->isAbstractScope()) {
|
|
|
|
DV->setDIE(VariableDie);
|
|
|
|
return VariableDie;
|
|
|
|
}
|
|
|
|
|
2009-11-11 07:06:00 +08:00
|
|
|
// Add variable address.
|
2010-05-26 07:40:22 +08:00
|
|
|
|
|
|
|
unsigned Offset = DV->getDotDebugLocOffset();
|
|
|
|
if (Offset != ~0U) {
|
|
|
|
addLabel(VariableDie, dwarf::DW_AT_location, dwarf::DW_FORM_data4,
|
|
|
|
Asm->GetTempSymbol("debug_loc", Offset));
|
|
|
|
DV->setDIE(VariableDie);
|
|
|
|
UseDotDebugLocEntry.insert(VariableDie);
|
|
|
|
return VariableDie;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if variable is described by a DBG_VALUE instruction.
|
|
|
|
DenseMap<const DbgVariable *, const MachineInstr *>::iterator DVI =
|
|
|
|
DbgVariableToDbgInstMap.find(DV);
|
|
|
|
if (DVI != DbgVariableToDbgInstMap.end()) {
|
|
|
|
const MachineInstr *DVInsn = DVI->second;
|
|
|
|
const MCSymbol *DVLabel = findVariableLabel(DV);
|
|
|
|
bool updated = false;
|
2010-07-22 05:21:52 +08:00
|
|
|
// FIXME : Handle getNumOperands != 3
|
2010-05-26 07:40:22 +08:00
|
|
|
if (DVInsn->getNumOperands() == 3) {
|
2010-09-01 06:22:42 +08:00
|
|
|
if (DVInsn->getOperand(0).isReg()) {
|
|
|
|
const MachineOperand RegOp = DVInsn->getOperand(0);
|
|
|
|
const TargetRegisterInfo *TRI = Asm->TM.getRegisterInfo();
|
|
|
|
if (DVInsn->getOperand(1).isImm() &&
|
|
|
|
TRI->getFrameRegister(*Asm->MF) == RegOp.getReg()) {
|
|
|
|
addVariableAddress(DV, VariableDie, DVInsn->getOperand(1).getImm());
|
|
|
|
updated = true;
|
|
|
|
} else
|
|
|
|
updated = addRegisterAddress(VariableDie, DVLabel, RegOp);
|
|
|
|
}
|
2010-05-26 07:40:22 +08:00
|
|
|
else if (DVInsn->getOperand(0).isImm())
|
|
|
|
updated = addConstantValue(VariableDie, DVLabel, DVInsn->getOperand(0));
|
2010-07-22 05:21:52 +08:00
|
|
|
else if (DVInsn->getOperand(0).isFPImm())
|
|
|
|
updated =
|
2010-07-08 04:12:52 +08:00
|
|
|
addConstantFPValue(VariableDie, DVLabel, DVInsn->getOperand(0));
|
2010-05-26 07:40:22 +08:00
|
|
|
} else {
|
|
|
|
MachineLocation Location = Asm->getDebugValueLocation(DVInsn);
|
|
|
|
if (Location.getReg()) {
|
|
|
|
addAddress(VariableDie, dwarf::DW_AT_location, Location);
|
|
|
|
if (DVLabel)
|
|
|
|
addLabel(VariableDie, dwarf::DW_AT_start_scope, dwarf::DW_FORM_addr,
|
|
|
|
DVLabel);
|
|
|
|
updated = true;
|
2010-05-15 05:01:35 +08:00
|
|
|
}
|
2010-03-16 02:33:46 +08:00
|
|
|
}
|
2010-05-26 07:40:22 +08:00
|
|
|
if (!updated) {
|
|
|
|
// If variableDie is not updated then DBG_VALUE instruction does not
|
|
|
|
// have valid variable info.
|
|
|
|
delete VariableDie;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
DV->setDIE(VariableDie);
|
|
|
|
return VariableDie;
|
2010-07-22 05:21:52 +08:00
|
|
|
}
|
2010-02-06 09:02:37 +08:00
|
|
|
|
2010-05-26 07:40:22 +08:00
|
|
|
// .. else use frame index, if available.
|
|
|
|
int FI = 0;
|
2010-08-31 14:11:28 +08:00
|
|
|
if (findVariableFrameIndex(DV, &FI))
|
|
|
|
addVariableAddress(DV, VariableDie, FI);
|
|
|
|
|
2009-11-11 07:06:00 +08:00
|
|
|
DV->setDIE(VariableDie);
|
|
|
|
return VariableDie;
|
|
|
|
|
|
|
|
}
|
2009-11-21 10:48:08 +08:00
|
|
|
|
2009-11-24 09:14:22 +08:00
|
|
|
void DwarfDebug::addPubTypes(DISubprogram SP) {
|
|
|
|
DICompositeType SPTy = SP.getType();
|
|
|
|
unsigned SPTag = SPTy.getTag();
|
2010-07-22 05:21:52 +08:00
|
|
|
if (SPTag != dwarf::DW_TAG_subroutine_type)
|
2009-11-24 09:14:22 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
DIArray Args = SPTy.getTypeArray();
|
|
|
|
for (unsigned i = 0, e = Args.getNumElements(); i != e; ++i) {
|
2010-05-08 02:11:54 +08:00
|
|
|
DIType ATy(Args.getElement(i));
|
2010-05-08 05:45:47 +08:00
|
|
|
if (!ATy.Verify())
|
2009-11-24 09:14:22 +08:00
|
|
|
continue;
|
|
|
|
DICompositeType CATy = getDICompositeType(ATy);
|
2010-05-08 02:11:54 +08:00
|
|
|
if (DIDescriptor(CATy).Verify() && !CATy.getName().empty()
|
2010-04-14 04:35:04 +08:00
|
|
|
&& !CATy.isForwardDecl()) {
|
2010-05-11 06:49:55 +08:00
|
|
|
CompileUnit *TheCU = getCompileUnit(CATy);
|
|
|
|
if (DIEEntry *Entry = TheCU->getDIEEntry(CATy))
|
|
|
|
TheCU->addGlobalType(CATy.getName(), Entry->getEntry());
|
2009-11-24 09:14:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// constructScopeDIE - Construct a DIE for this scope.
|
|
|
|
DIE *DwarfDebug::constructScopeDIE(DbgScope *Scope) {
|
2010-03-09 04:52:55 +08:00
|
|
|
if (!Scope || !Scope->getScopeNode())
|
|
|
|
return NULL;
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-03-09 04:52:55 +08:00
|
|
|
DIScope DS(Scope->getScopeNode());
|
|
|
|
DIE *ScopeDIE = NULL;
|
|
|
|
if (Scope->getInlinedAt())
|
|
|
|
ScopeDIE = constructInlinedScopeDIE(Scope);
|
|
|
|
else if (DS.isSubprogram()) {
|
2010-06-29 04:53:04 +08:00
|
|
|
ProcessedSPNodes.insert(DS);
|
2010-07-08 06:20:57 +08:00
|
|
|
if (Scope->isAbstractScope()) {
|
2010-05-11 06:49:55 +08:00
|
|
|
ScopeDIE = getCompileUnit(DS)->getDIE(DS);
|
2010-07-08 06:20:57 +08:00
|
|
|
// Note down abstract DIE.
|
|
|
|
if (ScopeDIE)
|
|
|
|
AbstractSPDies.insert(std::make_pair(DS, ScopeDIE));
|
|
|
|
}
|
2010-03-09 04:52:55 +08:00
|
|
|
else
|
2010-05-08 02:11:54 +08:00
|
|
|
ScopeDIE = updateSubprogramScopeDIE(DS);
|
2010-03-09 04:52:55 +08:00
|
|
|
}
|
2010-03-30 06:59:58 +08:00
|
|
|
else
|
2010-03-09 04:52:55 +08:00
|
|
|
ScopeDIE = constructLexicalScopeDIE(Scope);
|
2010-03-30 06:59:58 +08:00
|
|
|
if (!ScopeDIE) return NULL;
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2009-11-11 07:06:00 +08:00
|
|
|
// Add variables to scope.
|
2010-08-10 02:51:29 +08:00
|
|
|
const SmallVector<DbgVariable *, 8> &Variables = Scope->getDbgVariables();
|
2009-11-11 07:06:00 +08:00
|
|
|
for (unsigned i = 0, N = Variables.size(); i < N; ++i) {
|
2009-12-10 02:24:21 +08:00
|
|
|
DIE *VariableDIE = constructVariableDIE(Variables[i], Scope);
|
2009-11-22 07:12:12 +08:00
|
|
|
if (VariableDIE)
|
2009-11-21 10:48:08 +08:00
|
|
|
ScopeDIE->addChild(VariableDIE);
|
2009-11-11 07:06:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add nested scopes.
|
2010-03-13 01:45:06 +08:00
|
|
|
const SmallVector<DbgScope *, 4> &Scopes = Scope->getScopes();
|
2009-11-11 07:06:00 +08:00
|
|
|
for (unsigned j = 0, M = Scopes.size(); j < M; ++j) {
|
|
|
|
// Define the Scope debug information entry.
|
2009-11-21 10:48:08 +08:00
|
|
|
DIE *NestedDIE = constructScopeDIE(Scopes[j]);
|
2009-11-22 07:12:12 +08:00
|
|
|
if (NestedDIE)
|
2009-11-21 10:48:08 +08:00
|
|
|
ScopeDIE->addChild(NestedDIE);
|
2009-11-11 07:06:00 +08:00
|
|
|
}
|
2009-11-24 09:14:22 +08:00
|
|
|
|
2010-07-22 05:21:52 +08:00
|
|
|
if (DS.isSubprogram())
|
2010-05-08 02:11:54 +08:00
|
|
|
addPubTypes(DISubprogram(DS));
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2009-11-24 09:14:22 +08:00
|
|
|
return ScopeDIE;
|
2009-11-11 07:06:00 +08:00
|
|
|
}
|
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
/// 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.
|
2010-03-31 14:06:37 +08:00
|
|
|
unsigned DwarfDebug::GetOrCreateSourceID(StringRef DirName, StringRef FileName){
|
2009-05-21 07:21:38 +08:00
|
|
|
unsigned DId;
|
2010-07-28 04:51:15 +08:00
|
|
|
assert (DirName.empty() == false && "Invalid directory name!");
|
2010-07-24 08:53:22 +08:00
|
|
|
|
2010-09-17 04:57:49 +08:00
|
|
|
// If FE did not provide a file name, then assume stdin.
|
|
|
|
if (FileName.empty())
|
|
|
|
return GetOrCreateSourceID(DirName, "<stdin>");
|
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
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);
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
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);
|
2009-05-21 07:19:06 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
DenseMap<std::pair<unsigned, unsigned>, unsigned>::iterator SI =
|
|
|
|
SourceIdMap.find(std::make_pair(DId, FId));
|
|
|
|
if (SI != SourceIdMap.end())
|
|
|
|
return SI->second;
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
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));
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
return SrcId;
|
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-12-16 03:16:48 +08:00
|
|
|
/// getOrCreateNameSpace - Create a DIE for DINameSpace.
|
|
|
|
DIE *DwarfDebug::getOrCreateNameSpace(DINameSpace NS) {
|
2010-05-11 06:49:55 +08:00
|
|
|
CompileUnit *TheCU = getCompileUnit(NS);
|
|
|
|
DIE *NDie = TheCU->getDIE(NS);
|
2009-12-16 03:16:48 +08:00
|
|
|
if (NDie)
|
|
|
|
return NDie;
|
|
|
|
NDie = new DIE(dwarf::DW_TAG_namespace);
|
2010-05-11 06:49:55 +08:00
|
|
|
TheCU->insertDIE(NS, NDie);
|
2009-12-16 03:16:48 +08:00
|
|
|
if (!NS.getName().empty())
|
|
|
|
addString(NDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, NS.getName());
|
2010-08-10 04:20:05 +08:00
|
|
|
addSourceLine(NDie, NS);
|
2009-12-16 03:16:48 +08:00
|
|
|
addToContextOwner(NDie, NS.getContext());
|
|
|
|
return NDie;
|
|
|
|
}
|
|
|
|
|
2010-07-22 05:21:52 +08:00
|
|
|
/// constructCompileUnit - Create new CompileUnit for the given
|
2010-05-11 06:49:55 +08:00
|
|
|
/// metadata node with tag DW_TAG_compile_unit.
|
2010-05-08 04:54:48 +08:00
|
|
|
void DwarfDebug::constructCompileUnit(const MDNode *N) {
|
2009-08-29 07:24:31 +08:00
|
|
|
DICompileUnit DIUnit(N);
|
2009-11-26 01:36:49 +08:00
|
|
|
StringRef FN = DIUnit.getFilename();
|
|
|
|
StringRef Dir = DIUnit.getDirectory();
|
2009-09-30 02:40:58 +08:00
|
|
|
unsigned ID = GetOrCreateSourceID(Dir, FN);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
DIE *Die = new DIE(dwarf::DW_TAG_compile_unit);
|
2009-11-21 10:48:08 +08:00
|
|
|
addString(Die, dwarf::DW_AT_producer, dwarf::DW_FORM_string,
|
2009-09-30 02:40:58 +08:00
|
|
|
DIUnit.getProducer());
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data1,
|
2009-05-21 07:21:38 +08:00
|
|
|
DIUnit.getLanguage());
|
2009-11-21 10:48:08 +08:00
|
|
|
addString(Die, dwarf::DW_AT_name, dwarf::DW_FORM_string, FN);
|
2010-04-27 06:54:28 +08:00
|
|
|
// Use DW_AT_entry_pc instead of DW_AT_low_pc/DW_AT_high_pc pair. This
|
|
|
|
// simplifies debug range entries.
|
2010-06-29 06:22:47 +08:00
|
|
|
addUInt(Die, dwarf::DW_AT_entry_pc, dwarf::DW_FORM_addr, 0);
|
2010-03-23 07:11:36 +08:00
|
|
|
// DW_AT_stmt_list is a offset of line number information for this
|
2010-08-24 08:06:12 +08:00
|
|
|
// compile unit in debug_line section.
|
2010-09-01 07:50:19 +08:00
|
|
|
if (Asm->MAI->doesDwarfUsesAbsoluteLabelForStmtList())
|
|
|
|
addLabel(Die, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_addr,
|
|
|
|
Asm->GetTempSymbol("section_line"));
|
|
|
|
else
|
|
|
|
addUInt(Die, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_data4, 0);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-11-26 01:36:49 +08:00
|
|
|
if (!Dir.empty())
|
2009-11-21 10:48:08 +08:00
|
|
|
addString(Die, dwarf::DW_AT_comp_dir, dwarf::DW_FORM_string, Dir);
|
2009-05-21 07:21:38 +08:00
|
|
|
if (DIUnit.isOptimized())
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Die, dwarf::DW_AT_APPLE_optimized, dwarf::DW_FORM_flag, 1);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-11-26 01:36:49 +08:00
|
|
|
StringRef Flags = DIUnit.getFlags();
|
|
|
|
if (!Flags.empty())
|
2009-11-21 10:48:08 +08:00
|
|
|
addString(Die, dwarf::DW_AT_APPLE_flags, dwarf::DW_FORM_string, Flags);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
unsigned RVer = DIUnit.getRunTimeVersion();
|
|
|
|
if (RVer)
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(Die, dwarf::DW_AT_APPLE_major_runtime_vers,
|
2009-05-21 07:21:38 +08:00
|
|
|
dwarf::DW_FORM_data1, RVer);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-05-11 06:49:55 +08:00
|
|
|
CompileUnit *NewCU = new CompileUnit(ID, Die);
|
|
|
|
if (!FirstCU)
|
|
|
|
FirstCU = NewCU;
|
|
|
|
CUMap.insert(std::make_pair(N, NewCU));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getCompielUnit - Get CompileUnit DIE.
|
|
|
|
CompileUnit *DwarfDebug::getCompileUnit(const MDNode *N) const {
|
|
|
|
assert (N && "Invalid DwarfDebug::getCompileUnit argument!");
|
|
|
|
DIDescriptor D(N);
|
|
|
|
const MDNode *CUNode = NULL;
|
|
|
|
if (D.isCompileUnit())
|
|
|
|
CUNode = N;
|
|
|
|
else if (D.isSubprogram())
|
|
|
|
CUNode = DISubprogram(N).getCompileUnit();
|
|
|
|
else if (D.isType())
|
|
|
|
CUNode = DIType(N).getCompileUnit();
|
|
|
|
else if (D.isGlobalVariable())
|
|
|
|
CUNode = DIGlobalVariable(N).getCompileUnit();
|
|
|
|
else if (D.isVariable())
|
|
|
|
CUNode = DIVariable(N).getCompileUnit();
|
|
|
|
else if (D.isNameSpace())
|
|
|
|
CUNode = DINameSpace(N).getCompileUnit();
|
|
|
|
else if (D.isFile())
|
|
|
|
CUNode = DIFile(N).getCompileUnit();
|
|
|
|
else
|
|
|
|
return FirstCU;
|
|
|
|
|
|
|
|
DenseMap<const MDNode *, CompileUnit *>::const_iterator I
|
|
|
|
= CUMap.find(CUNode);
|
|
|
|
if (I == CUMap.end())
|
|
|
|
return FirstCU;
|
|
|
|
return I->second;
|
2009-05-21 07:19:06 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-08-24 02:25:56 +08:00
|
|
|
/// isUnsignedDIType - Return true if type encoding is unsigned.
|
|
|
|
static bool isUnsignedDIType(DIType Ty) {
|
|
|
|
DIDerivedType DTy(Ty);
|
|
|
|
if (DTy.Verify())
|
|
|
|
return isUnsignedDIType(DTy.getTypeDerivedFrom());
|
|
|
|
|
|
|
|
DIBasicType BTy(Ty);
|
|
|
|
if (BTy.Verify()) {
|
|
|
|
unsigned Encoding = BTy.getEncoding();
|
|
|
|
if (Encoding == dwarf::DW_ATE_unsigned ||
|
|
|
|
Encoding == dwarf::DW_ATE_unsigned_char)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2010-05-11 06:49:55 +08:00
|
|
|
|
|
|
|
/// constructGlobalVariableDIE - Construct global variable DIE.
|
2010-05-08 04:54:48 +08:00
|
|
|
void DwarfDebug::constructGlobalVariableDIE(const MDNode *N) {
|
2010-08-10 09:37:23 +08:00
|
|
|
DIGlobalVariable GV(N);
|
2009-09-20 04:40:05 +08:00
|
|
|
|
2009-09-05 07:59:07 +08:00
|
|
|
// If debug information is malformed then ignore it.
|
2010-08-10 09:37:23 +08:00
|
|
|
if (GV.Verify() == false)
|
2009-09-05 07:59:07 +08:00
|
|
|
return;
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Check for pre-existence.
|
2010-05-11 06:49:55 +08:00
|
|
|
CompileUnit *TheCU = getCompileUnit(N);
|
2010-08-10 09:37:23 +08:00
|
|
|
if (TheCU->getDIE(GV))
|
2009-06-26 09:49:18 +08:00
|
|
|
return;
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-08-10 09:37:23 +08:00
|
|
|
DIType GTy = GV.getType();
|
2010-08-10 15:11:13 +08:00
|
|
|
DIE *VariableDIE = new DIE(GV.getTag());
|
|
|
|
|
|
|
|
bool isGlobalVariable = GV.getGlobal() != NULL;
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-08-10 09:37:23 +08:00
|
|
|
// Add name.
|
|
|
|
addString(VariableDIE, dwarf::DW_AT_name, dwarf::DW_FORM_string,
|
|
|
|
GV.getDisplayName());
|
|
|
|
StringRef LinkageName = GV.getLinkageName();
|
2010-08-10 15:11:13 +08:00
|
|
|
if (!LinkageName.empty() && isGlobalVariable)
|
2010-08-10 09:37:23 +08:00
|
|
|
addString(VariableDIE, dwarf::DW_AT_MIPS_linkage_name, dwarf::DW_FORM_string,
|
|
|
|
getRealLinkageName(LinkageName));
|
|
|
|
// Add type.
|
|
|
|
addType(VariableDIE, GTy);
|
|
|
|
if (GTy.isCompositeType() && !GTy.getName().empty()
|
|
|
|
&& !GTy.isForwardDecl()) {
|
|
|
|
DIEEntry *Entry = TheCU->getDIEEntry(GTy);
|
|
|
|
assert(Entry && "Missing global type!");
|
|
|
|
TheCU->addGlobalType(GTy.getName(), Entry->getEntry());
|
|
|
|
}
|
|
|
|
// Add scoping info.
|
|
|
|
if (!GV.isLocalToUnit()) {
|
|
|
|
addUInt(VariableDIE, dwarf::DW_AT_external, dwarf::DW_FORM_flag, 1);
|
|
|
|
// Expose as global.
|
|
|
|
TheCU->addGlobal(GV.getName(), VariableDIE);
|
|
|
|
}
|
|
|
|
// Add line number info.
|
|
|
|
addSourceLine(VariableDIE, GV);
|
2009-05-21 07:21:38 +08:00
|
|
|
// Add to map.
|
2010-08-10 09:37:23 +08:00
|
|
|
TheCU->insertDIE(N, VariableDIE);
|
2009-05-21 07:21:38 +08:00
|
|
|
// Add to context owner.
|
2010-08-10 09:37:23 +08:00
|
|
|
DIDescriptor GVContext = GV.getContext();
|
|
|
|
addToContextOwner(VariableDIE, GVContext);
|
|
|
|
// Add location.
|
2010-08-10 15:11:13 +08:00
|
|
|
if (isGlobalVariable) {
|
|
|
|
DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
|
|
|
|
addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_addr);
|
|
|
|
addLabel(Block, 0, dwarf::DW_FORM_udata,
|
|
|
|
Asm->Mang->getSymbol(GV.getGlobal()));
|
|
|
|
// Do not create specification DIE if context is either compile unit
|
|
|
|
// or a subprogram.
|
|
|
|
if (GV.isDefinition() && !GVContext.isCompileUnit() &&
|
|
|
|
!GVContext.isFile() && !isSubprogramContext(GVContext)) {
|
|
|
|
// Create specification DIE.
|
|
|
|
DIE *VariableSpecDIE = new DIE(dwarf::DW_TAG_variable);
|
|
|
|
addDIEEntry(VariableSpecDIE, dwarf::DW_AT_specification,
|
|
|
|
dwarf::DW_FORM_ref4, VariableDIE);
|
|
|
|
addBlock(VariableSpecDIE, dwarf::DW_AT_location, 0, Block);
|
|
|
|
addUInt(VariableDIE, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1);
|
|
|
|
TheCU->addDie(VariableSpecDIE);
|
|
|
|
} else {
|
|
|
|
addBlock(VariableDIE, dwarf::DW_AT_location, 0, Block);
|
|
|
|
}
|
|
|
|
} else if (Constant *C = GV.getConstant()) {
|
|
|
|
if (ConstantInt *CI = dyn_cast<ConstantInt>(C)) {
|
2010-08-24 02:25:56 +08:00
|
|
|
if (isUnsignedDIType(GTy))
|
2010-08-10 15:11:13 +08:00
|
|
|
addUInt(VariableDIE, dwarf::DW_AT_const_value, dwarf::DW_FORM_udata,
|
|
|
|
CI->getZExtValue());
|
|
|
|
else
|
|
|
|
addSInt(VariableDIE, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata,
|
|
|
|
CI->getSExtValue());
|
|
|
|
}
|
2009-12-16 03:16:48 +08:00
|
|
|
}
|
2009-06-26 09:49:18 +08:00
|
|
|
return;
|
2009-05-21 07:19:06 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-05-11 06:49:55 +08:00
|
|
|
/// construct SubprogramDIE - Construct subprogram DIE.
|
2010-05-08 04:54:48 +08:00
|
|
|
void DwarfDebug::constructSubprogramDIE(const MDNode *N) {
|
2009-08-29 07:24:31 +08:00
|
|
|
DISubprogram SP(N);
|
2009-05-21 07:04:56 +08:00
|
|
|
|
2010-04-07 05:38:29 +08:00
|
|
|
// Check for pre-existence.
|
2010-05-11 06:49:55 +08:00
|
|
|
CompileUnit *TheCU = getCompileUnit(N);
|
|
|
|
if (TheCU->getDIE(N))
|
2010-04-07 05:38:29 +08:00
|
|
|
return;
|
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
if (!SP.isDefinition())
|
|
|
|
// This is a method declaration which will be handled while constructing
|
|
|
|
// class type.
|
2009-06-26 09:49:18 +08:00
|
|
|
return;
|
2009-05-21 07:04:56 +08:00
|
|
|
|
2010-04-07 05:38:29 +08:00
|
|
|
DIE *SubprogramDie = createSubprogramDIE(SP);
|
|
|
|
|
|
|
|
// Add to map.
|
2010-05-11 06:49:55 +08:00
|
|
|
TheCU->insertDIE(N, SubprogramDie);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Add to context owner.
|
2009-12-16 03:16:48 +08:00
|
|
|
addToContextOwner(SubprogramDie, SP.getContext());
|
2009-12-09 07:21:45 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Expose as global.
|
2010-05-11 06:49:55 +08:00
|
|
|
TheCU->addGlobal(SP.getName(), SubprogramDie);
|
2009-11-24 09:14:22 +08:00
|
|
|
|
2009-06-26 09:49:18 +08:00
|
|
|
return;
|
2009-05-21 07:19:06 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// beginModule - Emit all Dwarf sections that should come prior to the
|
2009-09-20 04:40:14 +08:00
|
|
|
/// content. Create global DIEs and emit initial debug info sections.
|
|
|
|
/// This is inovked by the target AsmPrinter.
|
2010-04-04 15:48:20 +08:00
|
|
|
void DwarfDebug::beginModule(Module *M) {
|
2010-04-28 03:46:33 +08:00
|
|
|
if (DisableDebugInfoPrinting)
|
|
|
|
return;
|
|
|
|
|
2009-07-31 02:56:46 +08:00
|
|
|
DebugInfoFinder DbgFinder;
|
|
|
|
DbgFinder.processModule(*M);
|
2009-06-26 09:49:18 +08:00
|
|
|
|
2010-04-05 10:19:28 +08:00
|
|
|
bool HasDebugInfo = false;
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-04-05 10:19:28 +08:00
|
|
|
// Scan all the compile-units to see if there are any marked as the main unit.
|
|
|
|
// if not, we do not generate debug info.
|
|
|
|
for (DebugInfoFinder::iterator I = DbgFinder.compile_unit_begin(),
|
|
|
|
E = DbgFinder.compile_unit_end(); I != E; ++I) {
|
|
|
|
if (DICompileUnit(*I).isMain()) {
|
|
|
|
HasDebugInfo = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-04-05 10:19:28 +08:00
|
|
|
if (!HasDebugInfo) return;
|
|
|
|
|
|
|
|
// Tell MMI that we have debug info.
|
|
|
|
MMI->setDebugInfoAvailability(true);
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-04-05 07:17:54 +08:00
|
|
|
// Emit initial sections.
|
2010-04-05 10:19:28 +08:00
|
|
|
EmitSectionLabels();
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Create all the compile unit DIEs.
|
2009-07-31 02:56:46 +08:00
|
|
|
for (DebugInfoFinder::iterator I = DbgFinder.compile_unit_begin(),
|
|
|
|
E = DbgFinder.compile_unit_end(); I != E; ++I)
|
2009-11-21 10:48:08 +08:00
|
|
|
constructCompileUnit(*I);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-11-11 07:06:00 +08:00
|
|
|
// Create DIEs for each subprogram.
|
2009-07-31 02:56:46 +08:00
|
|
|
for (DebugInfoFinder::iterator I = DbgFinder.subprogram_begin(),
|
|
|
|
E = DbgFinder.subprogram_end(); I != E; ++I)
|
2009-11-21 10:48:08 +08:00
|
|
|
constructSubprogramDIE(*I);
|
2009-06-26 09:49:18 +08:00
|
|
|
|
2009-12-11 03:14:49 +08:00
|
|
|
// Create DIEs for each global variable.
|
|
|
|
for (DebugInfoFinder::iterator I = DbgFinder.global_variable_begin(),
|
|
|
|
E = DbgFinder.global_variable_end(); I != E; ++I)
|
|
|
|
constructGlobalVariableDIE(*I);
|
|
|
|
|
2010-08-11 04:01:20 +08:00
|
|
|
//getOrCreateTypeDIE
|
|
|
|
if (NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.enum"))
|
|
|
|
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
|
|
|
|
getOrCreateTypeDIE(DIType(NMD->getOperand(i)));
|
|
|
|
|
2010-09-29 02:08:20 +08:00
|
|
|
if (NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.ty"))
|
|
|
|
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
|
|
|
|
getOrCreateTypeDIE(DIType(NMD->getOperand(i)));
|
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Prime section data.
|
2009-07-28 11:13:23 +08:00
|
|
|
SectionMap.insert(Asm->getObjFileLowering().getTextSection());
|
2009-05-21 07:21:38 +08:00
|
|
|
|
|
|
|
// Print out .file directives to specify files for .loc directives. These are
|
|
|
|
// printed out early so that they precede any .loc directives.
|
2010-04-05 08:13:49 +08:00
|
|
|
if (Asm->MAI->hasDotLocAndDotFile()) {
|
2009-05-21 07:21:38 +08:00
|
|
|
for (unsigned i = 1, e = getNumSourceIds()+1; i != e; ++i) {
|
|
|
|
// Remember source id starts at 1.
|
|
|
|
std::pair<unsigned, unsigned> Id = getSourceDirectoryAndFileIds(i);
|
2010-01-23 06:09:00 +08:00
|
|
|
// FIXME: don't use sys::path for this! This should not depend on the
|
|
|
|
// host.
|
2009-05-21 07:21:38 +08:00
|
|
|
sys::Path FullPath(getSourceDirectoryName(Id.first));
|
|
|
|
bool AppendOk =
|
|
|
|
FullPath.appendComponent(getSourceFileName(Id.second));
|
|
|
|
assert(AppendOk && "Could not append filename to directory!");
|
|
|
|
AppendOk = false;
|
2010-01-26 02:58:59 +08:00
|
|
|
Asm->OutStreamer.EmitDwarfFileDirective(i, FullPath.str());
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
2009-05-21 07:19:06 +08:00
|
|
|
}
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// endModule - Emit all Dwarf sections that should come after the content.
|
2009-05-21 07:21:38 +08:00
|
|
|
///
|
2009-11-21 10:48:08 +08:00
|
|
|
void DwarfDebug::endModule() {
|
2010-05-11 06:49:55 +08:00
|
|
|
if (!FirstCU) return;
|
2010-06-29 02:25:03 +08:00
|
|
|
const Module *M = MMI->getModule();
|
2010-08-03 01:32:15 +08:00
|
|
|
DenseMap<const MDNode *, DbgScope *> DeadFnScopeMap;
|
2010-06-29 02:25:03 +08:00
|
|
|
if (NamedMDNode *AllSPs = M->getNamedMetadata("llvm.dbg.sp")) {
|
|
|
|
for (unsigned SI = 0, SE = AllSPs->getNumOperands(); SI != SE; ++SI) {
|
|
|
|
if (ProcessedSPNodes.count(AllSPs->getOperand(SI)) != 0) continue;
|
|
|
|
DISubprogram SP(AllSPs->getOperand(SI));
|
|
|
|
if (!SP.Verify()) continue;
|
|
|
|
|
|
|
|
// Collect info for variables that were optimized out.
|
2010-07-20 01:53:55 +08:00
|
|
|
if (!SP.isDefinition()) continue;
|
2010-06-29 02:25:03 +08:00
|
|
|
StringRef FName = SP.getLinkageName();
|
|
|
|
if (FName.empty())
|
|
|
|
FName = SP.getName();
|
2010-07-22 05:21:52 +08:00
|
|
|
NamedMDNode *NMD =
|
2010-06-29 02:25:03 +08:00
|
|
|
M->getNamedMetadata(Twine("llvm.dbg.lv.", getRealLinkageName(FName)));
|
|
|
|
if (!NMD) continue;
|
|
|
|
unsigned E = NMD->getNumOperands();
|
|
|
|
if (!E) continue;
|
|
|
|
DbgScope *Scope = new DbgScope(NULL, DIDescriptor(SP), NULL);
|
2010-08-03 01:32:15 +08:00
|
|
|
DeadFnScopeMap[SP] = Scope;
|
2010-06-29 02:25:03 +08:00
|
|
|
for (unsigned I = 0; I != E; ++I) {
|
|
|
|
DIVariable DV(NMD->getOperand(I));
|
|
|
|
if (!DV.Verify()) continue;
|
|
|
|
Scope->addVariable(new DbgVariable(DV));
|
|
|
|
}
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-06-29 02:25:03 +08:00
|
|
|
// Construct subprogram DIE and add variables DIEs.
|
|
|
|
constructSubprogramDIE(SP);
|
|
|
|
DIE *ScopeDIE = getCompileUnit(SP)->getDIE(SP);
|
2010-08-10 02:51:29 +08:00
|
|
|
const SmallVector<DbgVariable *, 8> &Variables = Scope->getDbgVariables();
|
2010-06-29 02:25:03 +08:00
|
|
|
for (unsigned i = 0, N = Variables.size(); i < N; ++i) {
|
|
|
|
DIE *VariableDIE = constructVariableDIE(Variables[i], Scope);
|
|
|
|
if (VariableDIE)
|
|
|
|
ScopeDIE->addChild(VariableDIE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-11-11 07:06:00 +08:00
|
|
|
// Attach DW_AT_inline attribute with inlined subprogram DIEs.
|
|
|
|
for (SmallPtrSet<DIE *, 4>::iterator AI = InlinedSubprogramDIEs.begin(),
|
|
|
|
AE = InlinedSubprogramDIEs.end(); AI != AE; ++AI) {
|
|
|
|
DIE *ISP = *AI;
|
2009-11-21 10:48:08 +08:00
|
|
|
addUInt(ISP, dwarf::DW_AT_inline, 0, dwarf::DW_INL_inlined);
|
2009-11-11 07:06:00 +08:00
|
|
|
}
|
|
|
|
|
2010-05-08 04:54:48 +08:00
|
|
|
for (DenseMap<DIE *, const MDNode *>::iterator CI = ContainingTypeMap.begin(),
|
2009-12-04 03:11:07 +08:00
|
|
|
CE = ContainingTypeMap.end(); CI != CE; ++CI) {
|
|
|
|
DIE *SPDie = CI->first;
|
2010-05-08 04:54:48 +08:00
|
|
|
const MDNode *N = dyn_cast_or_null<MDNode>(CI->second);
|
2009-12-04 03:11:07 +08:00
|
|
|
if (!N) continue;
|
2010-05-11 06:49:55 +08:00
|
|
|
DIE *NDie = getCompileUnit(N)->getDIE(N);
|
2009-12-04 03:11:07 +08:00
|
|
|
if (!NDie) continue;
|
|
|
|
addDIEEntry(SPDie, dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4, NDie);
|
|
|
|
}
|
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Standard sections final addresses.
|
2009-08-19 13:49:37 +08:00
|
|
|
Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering().getTextSection());
|
2010-04-05 03:25:43 +08:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("text_end"));
|
2009-08-19 13:49:37 +08:00
|
|
|
Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering().getDataSection());
|
2010-04-05 03:25:43 +08:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("data_end"));
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// End text sections.
|
|
|
|
for (unsigned i = 1, N = SectionMap.size(); i <= N; ++i) {
|
2009-08-19 13:49:37 +08:00
|
|
|
Asm->OutStreamer.SwitchSection(SectionMap[i]);
|
2010-04-05 03:25:43 +08:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("section_end", i));
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Emit common frame information.
|
2009-11-21 10:48:08 +08:00
|
|
|
emitCommonDebugFrame();
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Emit function debug frame information
|
|
|
|
for (std::vector<FunctionDebugFrameInfo>::iterator I = DebugFrames.begin(),
|
|
|
|
E = DebugFrames.end(); I != E; ++I)
|
2009-11-21 10:48:08 +08:00
|
|
|
emitFunctionDebugFrame(*I);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Compute DIE offsets and sizes.
|
2009-11-21 10:48:08 +08:00
|
|
|
computeSizeAndOffsets();
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Emit all the DIEs into a debug info section
|
2009-11-21 10:48:08 +08:00
|
|
|
emitDebugInfo();
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Corresponding abbreviations into a abbrev section.
|
2009-11-21 10:48:08 +08:00
|
|
|
emitAbbreviations();
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-08-24 08:06:12 +08:00
|
|
|
// Emit source line correspondence into a debug line section.
|
|
|
|
emitDebugLines();
|
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Emit info into a debug pubnames section.
|
2009-11-21 10:48:08 +08:00
|
|
|
emitDebugPubNames();
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-11-24 09:14:22 +08:00
|
|
|
// Emit info into a debug pubtypes section.
|
|
|
|
emitDebugPubTypes();
|
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Emit info into a debug loc section.
|
2009-11-21 10:48:08 +08:00
|
|
|
emitDebugLoc();
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Emit info into a debug aranges section.
|
|
|
|
EmitDebugARanges();
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Emit info into a debug ranges section.
|
2009-11-21 10:48:08 +08:00
|
|
|
emitDebugRanges();
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Emit info into a debug macinfo section.
|
2009-11-21 10:48:08 +08:00
|
|
|
emitDebugMacInfo();
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Emit inline info.
|
2009-11-21 10:48:08 +08:00
|
|
|
emitDebugInlineInfo();
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-03-13 10:17:42 +08:00
|
|
|
// Emit info into a debug str section.
|
|
|
|
emitDebugStr();
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-08-03 01:32:15 +08:00
|
|
|
// clean up.
|
|
|
|
DeleteContainerSeconds(DeadFnScopeMap);
|
2010-05-11 06:49:55 +08:00
|
|
|
for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
|
|
|
|
E = CUMap.end(); I != E; ++I)
|
|
|
|
delete I->second;
|
|
|
|
FirstCU = NULL; // Reset for the next Module, if any.
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-11-11 07:06:00 +08:00
|
|
|
/// findAbstractVariable - Find abstract variable, if any, associated with Var.
|
2010-07-22 05:21:52 +08:00
|
|
|
DbgVariable *DwarfDebug::findAbstractVariable(DIVariable &Var,
|
2010-04-03 03:42:39 +08:00
|
|
|
DebugLoc ScopeLoc) {
|
2010-03-16 02:33:46 +08:00
|
|
|
|
2010-05-08 02:11:54 +08:00
|
|
|
DbgVariable *AbsDbgVariable = AbstractVariables.lookup(Var);
|
2010-03-16 02:33:46 +08:00
|
|
|
if (AbsDbgVariable)
|
|
|
|
return AbsDbgVariable;
|
|
|
|
|
2010-05-08 02:11:54 +08:00
|
|
|
LLVMContext &Ctx = Var->getContext();
|
2010-04-03 03:42:39 +08:00
|
|
|
DbgScope *Scope = AbstractScopes.lookup(ScopeLoc.getScope(Ctx));
|
2010-03-16 02:33:46 +08:00
|
|
|
if (!Scope)
|
|
|
|
return NULL;
|
|
|
|
|
2010-05-21 00:36:41 +08:00
|
|
|
AbsDbgVariable = new DbgVariable(Var);
|
2010-03-16 02:33:46 +08:00
|
|
|
Scope->addVariable(AbsDbgVariable);
|
2010-05-08 02:11:54 +08:00
|
|
|
AbstractVariables[Var] = AbsDbgVariable;
|
2010-03-16 02:33:46 +08:00
|
|
|
return AbsDbgVariable;
|
|
|
|
}
|
|
|
|
|
2010-05-21 03:57:06 +08:00
|
|
|
/// collectVariableInfoFromMMITable - Collect variable information from
|
|
|
|
/// side table maintained by MMI.
|
2010-07-22 05:21:52 +08:00
|
|
|
void
|
2010-05-21 03:57:06 +08:00
|
|
|
DwarfDebug::collectVariableInfoFromMMITable(const MachineFunction * MF,
|
|
|
|
SmallPtrSet<const MDNode *, 16> &Processed) {
|
2010-04-05 08:13:49 +08:00
|
|
|
const LLVMContext &Ctx = Asm->MF->getFunction()->getContext();
|
2009-10-06 09:26:37 +08:00
|
|
|
MachineModuleInfo::VariableDbgInfoMapTy &VMap = MMI->getVariableDbgInfo();
|
|
|
|
for (MachineModuleInfo::VariableDbgInfoMapTy::iterator VI = VMap.begin(),
|
|
|
|
VE = VMap.end(); VI != VE; ++VI) {
|
2010-05-08 04:54:48 +08:00
|
|
|
const MDNode *Var = VI->first;
|
2009-11-11 07:06:00 +08:00
|
|
|
if (!Var) continue;
|
2010-05-15 05:01:35 +08:00
|
|
|
Processed.insert(Var);
|
2010-04-03 03:42:39 +08:00
|
|
|
DIVariable DV(Var);
|
|
|
|
const std::pair<unsigned, DebugLoc> &VP = VI->second;
|
|
|
|
|
|
|
|
DbgScope *Scope = 0;
|
2010-05-08 04:54:48 +08:00
|
|
|
if (const MDNode *IA = VP.second.getInlinedAt(Ctx))
|
2010-04-03 03:42:39 +08:00
|
|
|
Scope = ConcreteScopes.lookup(IA);
|
|
|
|
if (Scope == 0)
|
|
|
|
Scope = DbgScopeMap.lookup(VP.second.getScope(Ctx));
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2009-11-11 07:20:04 +08:00
|
|
|
// If variable scope is not found then skip this variable.
|
2010-04-03 03:42:39 +08:00
|
|
|
if (Scope == 0)
|
2009-11-11 07:20:04 +08:00
|
|
|
continue;
|
2009-11-11 07:06:00 +08:00
|
|
|
|
2010-05-21 00:36:41 +08:00
|
|
|
DbgVariable *AbsDbgVariable = findAbstractVariable(DV, VP.second);
|
|
|
|
DbgVariable *RegVar = new DbgVariable(DV);
|
|
|
|
recordVariableFrameIndex(RegVar, VP.first);
|
2009-11-21 10:48:08 +08:00
|
|
|
Scope->addVariable(RegVar);
|
2010-05-21 00:36:41 +08:00
|
|
|
if (AbsDbgVariable) {
|
|
|
|
recordVariableFrameIndex(AbsDbgVariable, VP.first);
|
|
|
|
VarToAbstractVarMap[RegVar] = AbsDbgVariable;
|
|
|
|
}
|
2009-10-06 09:26:37 +08:00
|
|
|
}
|
2010-05-21 03:57:06 +08:00
|
|
|
}
|
|
|
|
|
2010-07-22 05:21:52 +08:00
|
|
|
/// isDbgValueInUndefinedReg - Return true if debug value, encoded by
|
2010-05-26 07:40:22 +08:00
|
|
|
/// DBG_VALUE instruction, is in undefined reg.
|
|
|
|
static bool isDbgValueInUndefinedReg(const MachineInstr *MI) {
|
|
|
|
assert (MI->isDebugValue() && "Invalid DBG_VALUE machine instruction!");
|
|
|
|
if (MI->getOperand(0).isReg() && !MI->getOperand(0).getReg())
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-22 05:21:52 +08:00
|
|
|
/// isDbgValueInDefinedReg - Return true if debug value, encoded by
|
2010-05-26 07:40:22 +08:00
|
|
|
/// DBG_VALUE instruction, is in a defined reg.
|
|
|
|
static bool isDbgValueInDefinedReg(const MachineInstr *MI) {
|
|
|
|
assert (MI->isDebugValue() && "Invalid DBG_VALUE machine instruction!");
|
|
|
|
if (MI->getOperand(0).isReg() && MI->getOperand(0).getReg())
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-05-21 03:57:06 +08:00
|
|
|
/// collectVariableInfo - Populate DbgScope entries with variables' info.
|
2010-07-22 05:21:52 +08:00
|
|
|
void
|
2010-06-26 06:07:34 +08:00
|
|
|
DwarfDebug::collectVariableInfo(const MachineFunction *MF,
|
|
|
|
SmallPtrSet<const MDNode *, 16> &Processed) {
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-21 03:57:06 +08:00
|
|
|
/// collection info from MMI table.
|
|
|
|
collectVariableInfoFromMMITable(MF, Processed);
|
2010-03-16 02:33:46 +08:00
|
|
|
|
2010-05-21 03:57:06 +08:00
|
|
|
SmallVector<const MachineInstr *, 8> DbgValues;
|
2010-03-16 02:33:46 +08:00
|
|
|
// Collect variable information from DBG_VALUE machine instructions;
|
2010-04-05 08:13:49 +08:00
|
|
|
for (MachineFunction::const_iterator I = Asm->MF->begin(), E = Asm->MF->end();
|
2010-05-21 03:57:06 +08:00
|
|
|
I != E; ++I)
|
2010-03-16 02:33:46 +08:00
|
|
|
for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
|
|
|
|
II != IE; ++II) {
|
|
|
|
const MachineInstr *MInsn = II;
|
2010-05-26 07:40:22 +08:00
|
|
|
if (!MInsn->isDebugValue() || isDbgValueInUndefinedReg(MInsn))
|
2010-03-16 02:33:46 +08:00
|
|
|
continue;
|
2010-05-21 03:57:06 +08:00
|
|
|
DbgValues.push_back(MInsn);
|
|
|
|
}
|
2010-03-16 02:33:46 +08:00
|
|
|
|
2010-05-26 07:40:22 +08:00
|
|
|
// This is a collection of DBV_VALUE instructions describing same variable.
|
|
|
|
SmallVector<const MachineInstr *, 4> MultipleValues;
|
2010-05-21 03:57:06 +08:00
|
|
|
for(SmallVector<const MachineInstr *, 8>::iterator I = DbgValues.begin(),
|
|
|
|
E = DbgValues.end(); I != E; ++I) {
|
|
|
|
const MachineInstr *MInsn = *I;
|
2010-05-26 07:40:22 +08:00
|
|
|
MultipleValues.clear();
|
|
|
|
if (isDbgValueInDefinedReg(MInsn))
|
|
|
|
MultipleValues.push_back(MInsn);
|
2010-05-21 03:57:06 +08:00
|
|
|
DIVariable DV(MInsn->getOperand(MInsn->getNumOperands() - 1).getMetadata());
|
|
|
|
if (Processed.count(DV) != 0)
|
|
|
|
continue;
|
2010-03-16 02:33:46 +08:00
|
|
|
|
2010-06-03 03:05:13 +08:00
|
|
|
const MachineInstr *PrevMI = MInsn;
|
2010-07-22 05:21:52 +08:00
|
|
|
for (SmallVector<const MachineInstr *, 8>::iterator MI = I+1,
|
2010-05-26 07:40:22 +08:00
|
|
|
ME = DbgValues.end(); MI != ME; ++MI) {
|
2010-07-22 05:21:52 +08:00
|
|
|
const MDNode *Var =
|
2010-05-26 07:40:22 +08:00
|
|
|
(*MI)->getOperand((*MI)->getNumOperands()-1).getMetadata();
|
2010-07-22 05:21:52 +08:00
|
|
|
if (Var == DV && isDbgValueInDefinedReg(*MI) &&
|
2010-06-03 03:05:13 +08:00
|
|
|
!PrevMI->isIdenticalTo(*MI))
|
2010-05-26 07:40:22 +08:00
|
|
|
MultipleValues.push_back(*MI);
|
2010-06-03 03:05:13 +08:00
|
|
|
PrevMI = *MI;
|
2010-05-26 07:40:22 +08:00
|
|
|
}
|
|
|
|
|
2010-05-21 03:57:06 +08:00
|
|
|
DbgScope *Scope = findDbgScope(MInsn);
|
2010-05-28 04:25:04 +08:00
|
|
|
bool CurFnArg = false;
|
|
|
|
if (DV.getTag() == dwarf::DW_TAG_arg_variable &&
|
|
|
|
DISubprogram(DV.getContext()).describes(MF->getFunction()))
|
|
|
|
CurFnArg = true;
|
|
|
|
if (!Scope && CurFnArg)
|
2010-05-21 08:10:20 +08:00
|
|
|
Scope = CurrentFnDbgScope;
|
2010-05-21 03:57:06 +08:00
|
|
|
// If variable scope is not found then skip this variable.
|
2010-05-21 08:10:20 +08:00
|
|
|
if (!Scope)
|
2010-05-21 03:57:06 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
Processed.insert(DV);
|
|
|
|
DbgVariable *RegVar = new DbgVariable(DV);
|
|
|
|
Scope->addVariable(RegVar);
|
2010-05-28 04:25:04 +08:00
|
|
|
if (!CurFnArg)
|
2010-07-22 05:21:52 +08:00
|
|
|
DbgVariableLabelsMap[RegVar] = getLabelBeforeInsn(MInsn);
|
2010-05-21 08:10:20 +08:00
|
|
|
if (DbgVariable *AbsVar = findAbstractVariable(DV, MInsn->getDebugLoc())) {
|
|
|
|
DbgVariableToDbgInstMap[AbsVar] = MInsn;
|
|
|
|
VarToAbstractVarMap[RegVar] = AbsVar;
|
2010-03-16 02:33:46 +08:00
|
|
|
}
|
2010-05-26 07:40:22 +08:00
|
|
|
if (MultipleValues.size() <= 1) {
|
|
|
|
DbgVariableToDbgInstMap[RegVar] = MInsn;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle multiple DBG_VALUE instructions describing one variable.
|
|
|
|
if (DotDebugLocEntries.empty())
|
2010-05-27 07:55:23 +08:00
|
|
|
RegVar->setDotDebugLocOffset(0);
|
|
|
|
else
|
|
|
|
RegVar->setDotDebugLocOffset(DotDebugLocEntries.size());
|
2010-05-27 01:29:32 +08:00
|
|
|
const MachineInstr *Begin = NULL;
|
|
|
|
const MachineInstr *End = NULL;
|
2010-07-22 05:21:52 +08:00
|
|
|
for (SmallVector<const MachineInstr *, 4>::iterator
|
|
|
|
MVI = MultipleValues.begin(), MVE = MultipleValues.end();
|
2010-07-08 04:12:52 +08:00
|
|
|
MVI != MVE; ++MVI) {
|
2010-05-27 01:29:32 +08:00
|
|
|
if (!Begin) {
|
|
|
|
Begin = *MVI;
|
|
|
|
continue;
|
2010-07-22 05:21:52 +08:00
|
|
|
}
|
2010-05-27 01:29:32 +08:00
|
|
|
End = *MVI;
|
2010-05-26 07:40:22 +08:00
|
|
|
MachineLocation MLoc;
|
2010-08-05 02:40:52 +08:00
|
|
|
if (Begin->getNumOperands() == 3) {
|
|
|
|
if (Begin->getOperand(0).isReg() && Begin->getOperand(1).isImm())
|
|
|
|
MLoc.set(Begin->getOperand(0).getReg(), Begin->getOperand(1).getImm());
|
|
|
|
} else
|
|
|
|
MLoc = Asm->getDebugValueLocation(Begin);
|
|
|
|
|
2010-05-27 01:29:32 +08:00
|
|
|
const MCSymbol *FLabel = getLabelBeforeInsn(Begin);
|
|
|
|
const MCSymbol *SLabel = getLabelBeforeInsn(End);
|
2010-08-05 06:07:27 +08:00
|
|
|
if (MLoc.getReg())
|
|
|
|
DotDebugLocEntries.push_back(DotDebugLocEntry(FLabel, SLabel, MLoc));
|
|
|
|
|
2010-05-27 01:29:32 +08:00
|
|
|
Begin = End;
|
|
|
|
if (MVI + 1 == MVE) {
|
|
|
|
// If End is the last instruction then its value is valid
|
2010-05-26 07:40:22 +08:00
|
|
|
// until the end of the funtion.
|
2010-08-05 02:40:52 +08:00
|
|
|
MachineLocation EMLoc;
|
|
|
|
if (End->getNumOperands() == 3) {
|
|
|
|
if (End->getOperand(0).isReg() && Begin->getOperand(1).isImm())
|
|
|
|
EMLoc.set(Begin->getOperand(0).getReg(), Begin->getOperand(1).getImm());
|
|
|
|
} else
|
|
|
|
EMLoc = Asm->getDebugValueLocation(End);
|
2010-08-05 06:07:27 +08:00
|
|
|
if (EMLoc.getReg())
|
|
|
|
DotDebugLocEntries.
|
|
|
|
push_back(DotDebugLocEntry(SLabel, FunctionEndSym, EMLoc));
|
2010-05-26 07:40:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
DotDebugLocEntries.push_back(DotDebugLocEntry());
|
2010-03-16 02:33:46 +08:00
|
|
|
}
|
2010-05-15 05:01:35 +08:00
|
|
|
|
|
|
|
// Collect info for variables that were optimized out.
|
2010-06-22 09:01:58 +08:00
|
|
|
const Function *F = MF->getFunction();
|
|
|
|
const Module *M = F->getParent();
|
2010-07-22 05:21:52 +08:00
|
|
|
if (NamedMDNode *NMD =
|
|
|
|
M->getNamedMetadata(Twine("llvm.dbg.lv.",
|
2010-06-22 09:19:38 +08:00
|
|
|
getRealLinkageName(F->getName())))) {
|
2010-05-15 05:01:35 +08:00
|
|
|
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
|
2010-07-22 02:54:18 +08:00
|
|
|
DIVariable DV(cast<MDNode>(NMD->getOperand(i)));
|
2010-05-21 03:57:06 +08:00
|
|
|
if (!DV || !Processed.insert(DV))
|
2010-05-15 05:01:35 +08:00
|
|
|
continue;
|
|
|
|
DbgScope *Scope = DbgScopeMap.lookup(DV.getContext());
|
|
|
|
if (Scope)
|
2010-05-21 00:36:41 +08:00
|
|
|
Scope->addVariable(new DbgVariable(DV));
|
2010-05-15 05:01:35 +08:00
|
|
|
}
|
|
|
|
}
|
2010-05-26 07:40:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getLabelBeforeInsn - Return Label preceding the instruction.
|
|
|
|
const MCSymbol *DwarfDebug::getLabelBeforeInsn(const MachineInstr *MI) {
|
|
|
|
DenseMap<const MachineInstr *, MCSymbol *>::iterator I =
|
|
|
|
LabelsBeforeInsn.find(MI);
|
|
|
|
if (I == LabelsBeforeInsn.end())
|
|
|
|
// FunctionBeginSym always preceeds all the instruction in current function.
|
|
|
|
return FunctionBeginSym;
|
|
|
|
return I->second;
|
|
|
|
}
|
2010-05-15 05:01:35 +08:00
|
|
|
|
2010-05-26 07:40:22 +08:00
|
|
|
/// getLabelAfterInsn - Return Label immediately following the instruction.
|
|
|
|
const MCSymbol *DwarfDebug::getLabelAfterInsn(const MachineInstr *MI) {
|
|
|
|
DenseMap<const MachineInstr *, MCSymbol *>::iterator I =
|
|
|
|
LabelsAfterInsn.find(MI);
|
|
|
|
if (I == LabelsAfterInsn.end())
|
|
|
|
return NULL;
|
|
|
|
return I->second;
|
2009-10-06 09:26:37 +08:00
|
|
|
}
|
|
|
|
|
2010-10-27 01:49:02 +08:00
|
|
|
/// beginInstruction - Process beginning of an instruction.
|
|
|
|
void DwarfDebug::beginInstruction(const MachineInstr *MI) {
|
2010-05-27 03:37:24 +08:00
|
|
|
if (InsnNeedsLabel.count(MI) == 0) {
|
|
|
|
LabelsBeforeInsn[MI] = PrevLabel;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-03-30 01:20:31 +08:00
|
|
|
// Check location.
|
|
|
|
DebugLoc DL = MI->getDebugLoc();
|
2010-05-27 03:37:24 +08:00
|
|
|
if (!DL.isUnknown()) {
|
|
|
|
const MDNode *Scope = DL.getScope(Asm->MF->getFunction()->getContext());
|
|
|
|
PrevLabel = recordSourceLine(DL.getLine(), DL.getCol(), Scope);
|
|
|
|
PrevInstLoc = DL;
|
|
|
|
LabelsBeforeInsn[MI] = PrevLabel;
|
2010-03-30 01:20:31 +08:00
|
|
|
return;
|
2010-05-26 07:40:22 +08:00
|
|
|
}
|
2010-05-27 03:37:24 +08:00
|
|
|
|
2010-07-22 05:21:52 +08:00
|
|
|
// If location is unknown then use temp label for this DBG_VALUE
|
2010-05-27 03:37:24 +08:00
|
|
|
// instruction.
|
2010-03-31 13:39:57 +08:00
|
|
|
if (MI->isDebugValue()) {
|
2010-05-27 05:23:46 +08:00
|
|
|
PrevLabel = MMI->getContext().CreateTempSymbol();
|
|
|
|
Asm->OutStreamer.EmitLabel(PrevLabel);
|
2010-05-27 03:37:24 +08:00
|
|
|
LabelsBeforeInsn[MI] = PrevLabel;
|
|
|
|
return;
|
2010-04-28 03:46:33 +08:00
|
|
|
}
|
2010-03-30 01:20:31 +08:00
|
|
|
|
2010-05-27 03:37:24 +08:00
|
|
|
if (UnknownLocations) {
|
|
|
|
PrevLabel = recordSourceLine(0, 0, 0);
|
|
|
|
LabelsBeforeInsn[MI] = PrevLabel;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert (0 && "Instruction is not processed!");
|
2009-10-06 09:50:42 +08:00
|
|
|
}
|
|
|
|
|
2010-10-27 01:49:02 +08:00
|
|
|
/// endInstruction - Process end of an instruction.
|
|
|
|
void DwarfDebug::endInstruction(const MachineInstr *MI) {
|
2010-04-09 00:50:29 +08:00
|
|
|
if (InsnsEndScopeSet.count(MI) != 0) {
|
|
|
|
// Emit a label if this instruction ends a scope.
|
|
|
|
MCSymbol *Label = MMI->getContext().CreateTempSymbol();
|
|
|
|
Asm->OutStreamer.EmitLabel(Label);
|
2010-04-28 03:46:33 +08:00
|
|
|
LabelsAfterInsn[MI] = Label;
|
2010-04-09 00:50:29 +08:00
|
|
|
}
|
2009-11-11 07:06:00 +08:00
|
|
|
}
|
|
|
|
|
2010-04-28 03:46:33 +08:00
|
|
|
/// getOrCreateDbgScope - Create DbgScope for the scope.
|
2010-07-22 05:21:52 +08:00
|
|
|
DbgScope *DwarfDebug::getOrCreateDbgScope(const MDNode *Scope,
|
2010-07-08 04:12:52 +08:00
|
|
|
const MDNode *InlinedAt) {
|
2009-11-11 07:06:00 +08:00
|
|
|
if (!InlinedAt) {
|
|
|
|
DbgScope *WScope = DbgScopeMap.lookup(Scope);
|
|
|
|
if (WScope)
|
2010-04-28 03:46:33 +08:00
|
|
|
return WScope;
|
2009-11-11 07:06:00 +08:00
|
|
|
WScope = new DbgScope(NULL, DIDescriptor(Scope), NULL);
|
|
|
|
DbgScopeMap.insert(std::make_pair(Scope, WScope));
|
2010-04-28 03:46:33 +08:00
|
|
|
if (DIDescriptor(Scope).isLexicalBlock()) {
|
2010-07-22 05:21:52 +08:00
|
|
|
DbgScope *Parent =
|
2010-05-08 02:11:54 +08:00
|
|
|
getOrCreateDbgScope(DILexicalBlock(Scope).getContext(), NULL);
|
2010-04-28 03:46:33 +08:00
|
|
|
WScope->setParent(Parent);
|
|
|
|
Parent->addScope(WScope);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!WScope->getParent()) {
|
|
|
|
StringRef SPName = DISubprogram(Scope).getLinkageName();
|
2010-06-16 07:06:30 +08:00
|
|
|
// We used to check only for a linkage name, but that fails
|
|
|
|
// since we began omitting the linkage name for private
|
|
|
|
// functions. The new way is to check for the name in metadata,
|
|
|
|
// but that's not supported in old .ll test cases. Ergo, we
|
|
|
|
// check both.
|
2010-06-12 04:08:44 +08:00
|
|
|
if (SPName == Asm->MF->getFunction()->getName() ||
|
|
|
|
DISubprogram(Scope).getFunction() == Asm->MF->getFunction())
|
2010-04-28 03:46:33 +08:00
|
|
|
CurrentFnDbgScope = WScope;
|
|
|
|
}
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-04-28 03:46:33 +08:00
|
|
|
return WScope;
|
2009-11-11 07:06:00 +08:00
|
|
|
}
|
|
|
|
|
2010-06-26 06:07:34 +08:00
|
|
|
getOrCreateAbstractScope(Scope);
|
2009-11-11 07:06:00 +08:00
|
|
|
DbgScope *WScope = DbgScopeMap.lookup(InlinedAt);
|
|
|
|
if (WScope)
|
2010-04-28 03:46:33 +08:00
|
|
|
return WScope;
|
2009-11-11 07:06:00 +08:00
|
|
|
|
|
|
|
WScope = new DbgScope(NULL, DIDescriptor(Scope), InlinedAt);
|
|
|
|
DbgScopeMap.insert(std::make_pair(InlinedAt, WScope));
|
|
|
|
DILocation DL(InlinedAt);
|
2010-04-28 03:46:33 +08:00
|
|
|
DbgScope *Parent =
|
2010-05-08 02:11:54 +08:00
|
|
|
getOrCreateDbgScope(DL.getScope(), DL.getOrigLocation());
|
2010-04-28 03:46:33 +08:00
|
|
|
WScope->setParent(Parent);
|
|
|
|
Parent->addScope(WScope);
|
|
|
|
|
|
|
|
ConcreteScopes[InlinedAt] = WScope;
|
|
|
|
|
|
|
|
return WScope;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// hasValidLocation - Return true if debug location entry attached with
|
|
|
|
/// machine instruction encodes valid location info.
|
|
|
|
static bool hasValidLocation(LLVMContext &Ctx,
|
|
|
|
const MachineInstr *MInsn,
|
2010-05-08 04:54:48 +08:00
|
|
|
const MDNode *&Scope, const MDNode *&InlinedAt) {
|
2010-04-28 03:46:33 +08:00
|
|
|
DebugLoc DL = MInsn->getDebugLoc();
|
|
|
|
if (DL.isUnknown()) return false;
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-08 04:54:48 +08:00
|
|
|
const MDNode *S = DL.getScope(Ctx);
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-04-28 03:46:33 +08:00
|
|
|
// There is no need to create another DIE for compile unit. For all
|
|
|
|
// other scopes, create one DbgScope now. This will be translated
|
|
|
|
// into a scope DIE at the end.
|
|
|
|
if (DIScope(S).isCompileUnit()) return false;
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-04-28 03:46:33 +08:00
|
|
|
Scope = S;
|
|
|
|
InlinedAt = DL.getInlinedAt(Ctx);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// calculateDominanceGraph - Calculate dominance graph for DbgScope
|
|
|
|
/// hierarchy.
|
|
|
|
static void calculateDominanceGraph(DbgScope *Scope) {
|
|
|
|
assert (Scope && "Unable to calculate scop edominance graph!");
|
|
|
|
SmallVector<DbgScope *, 4> WorkStack;
|
|
|
|
WorkStack.push_back(Scope);
|
|
|
|
unsigned Counter = 0;
|
|
|
|
while (!WorkStack.empty()) {
|
|
|
|
DbgScope *WS = WorkStack.back();
|
|
|
|
const SmallVector<DbgScope *, 4> &Children = WS->getScopes();
|
|
|
|
bool visitedChildren = false;
|
|
|
|
for (SmallVector<DbgScope *, 4>::const_iterator SI = Children.begin(),
|
|
|
|
SE = Children.end(); SI != SE; ++SI) {
|
|
|
|
DbgScope *ChildScope = *SI;
|
|
|
|
if (!ChildScope->getDFSOut()) {
|
|
|
|
WorkStack.push_back(ChildScope);
|
|
|
|
visitedChildren = true;
|
|
|
|
ChildScope->setDFSIn(++Counter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!visitedChildren) {
|
|
|
|
WorkStack.pop_back();
|
|
|
|
WS->setDFSOut(++Counter);
|
|
|
|
}
|
|
|
|
}
|
2009-10-06 09:50:42 +08:00
|
|
|
}
|
|
|
|
|
2010-04-28 03:46:33 +08:00
|
|
|
/// printDbgScopeInfo - Print DbgScope info for each machine instruction.
|
2010-07-22 05:21:52 +08:00
|
|
|
static
|
2010-04-28 03:46:33 +08:00
|
|
|
void printDbgScopeInfo(LLVMContext &Ctx, const MachineFunction *MF,
|
|
|
|
DenseMap<const MachineInstr *, DbgScope *> &MI2ScopeMap)
|
|
|
|
{
|
|
|
|
#ifndef NDEBUG
|
|
|
|
unsigned PrevDFSIn = 0;
|
|
|
|
for (MachineFunction::const_iterator I = MF->begin(), E = MF->end();
|
|
|
|
I != E; ++I) {
|
|
|
|
for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
|
|
|
|
II != IE; ++II) {
|
|
|
|
const MachineInstr *MInsn = II;
|
2010-05-08 04:54:48 +08:00
|
|
|
const MDNode *Scope = NULL;
|
|
|
|
const MDNode *InlinedAt = NULL;
|
2010-04-28 03:46:33 +08:00
|
|
|
|
|
|
|
// Check if instruction has valid location information.
|
|
|
|
if (hasValidLocation(Ctx, MInsn, Scope, InlinedAt)) {
|
|
|
|
dbgs() << " [ ";
|
2010-07-22 05:21:52 +08:00
|
|
|
if (InlinedAt)
|
2010-04-28 03:46:33 +08:00
|
|
|
dbgs() << "*";
|
2010-07-22 05:21:52 +08:00
|
|
|
DenseMap<const MachineInstr *, DbgScope *>::iterator DI =
|
2010-04-28 03:46:33 +08:00
|
|
|
MI2ScopeMap.find(MInsn);
|
|
|
|
if (DI != MI2ScopeMap.end()) {
|
|
|
|
DbgScope *S = DI->second;
|
|
|
|
dbgs() << S->getDFSIn();
|
|
|
|
PrevDFSIn = S->getDFSIn();
|
|
|
|
} else
|
|
|
|
dbgs() << PrevDFSIn;
|
2010-07-22 05:21:52 +08:00
|
|
|
} else
|
2010-04-28 03:46:33 +08:00
|
|
|
dbgs() << " [ x" << PrevDFSIn;
|
|
|
|
dbgs() << " ]";
|
|
|
|
MInsn->dump();
|
|
|
|
}
|
|
|
|
dbgs() << "\n";
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2009-11-21 10:48:08 +08:00
|
|
|
/// extractScopeInformation - Scan machine instructions in this function
|
2010-03-31 13:39:57 +08:00
|
|
|
/// and collect DbgScopes. Return true, if at least one scope was found.
|
2010-01-27 07:18:02 +08:00
|
|
|
bool DwarfDebug::extractScopeInformation() {
|
2009-10-02 04:31:14 +08:00
|
|
|
// If scope information was extracted using .dbg intrinsics then there is not
|
|
|
|
// any need to extract these information by scanning each instruction.
|
|
|
|
if (!DbgScopeMap.empty())
|
|
|
|
return false;
|
|
|
|
|
2010-04-23 09:18:53 +08:00
|
|
|
// Scan each instruction and create scopes. First build working set of scopes.
|
2010-04-28 03:46:33 +08:00
|
|
|
LLVMContext &Ctx = Asm->MF->getFunction()->getContext();
|
|
|
|
SmallVector<DbgRange, 4> MIRanges;
|
|
|
|
DenseMap<const MachineInstr *, DbgScope *> MI2ScopeMap;
|
2010-05-08 04:54:48 +08:00
|
|
|
const MDNode *PrevScope = NULL;
|
|
|
|
const MDNode *PrevInlinedAt = NULL;
|
2010-04-28 03:46:33 +08:00
|
|
|
const MachineInstr *RangeBeginMI = NULL;
|
|
|
|
const MachineInstr *PrevMI = NULL;
|
2010-04-05 08:13:49 +08:00
|
|
|
for (MachineFunction::const_iterator I = Asm->MF->begin(), E = Asm->MF->end();
|
2009-10-02 04:31:14 +08:00
|
|
|
I != E; ++I) {
|
|
|
|
for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
|
|
|
|
II != IE; ++II) {
|
|
|
|
const MachineInstr *MInsn = II;
|
2010-05-08 04:54:48 +08:00
|
|
|
const MDNode *Scope = NULL;
|
|
|
|
const MDNode *InlinedAt = NULL;
|
2010-04-02 06:47:29 +08:00
|
|
|
|
2010-04-28 03:46:33 +08:00
|
|
|
// Check if instruction has valid location information.
|
|
|
|
if (!hasValidLocation(Ctx, MInsn, Scope, InlinedAt)) {
|
|
|
|
PrevMI = MInsn;
|
|
|
|
continue;
|
|
|
|
}
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-04-28 03:46:33 +08:00
|
|
|
// If scope has not changed then skip this instruction.
|
|
|
|
if (Scope == PrevScope && PrevInlinedAt == InlinedAt) {
|
|
|
|
PrevMI = MInsn;
|
|
|
|
continue;
|
|
|
|
}
|
2010-04-03 03:42:39 +08:00
|
|
|
|
2010-07-22 05:21:52 +08:00
|
|
|
if (RangeBeginMI) {
|
|
|
|
// If we have alread seen a beginning of a instruction range and
|
2010-04-28 03:46:33 +08:00
|
|
|
// current instruction scope does not match scope of first instruction
|
|
|
|
// in this range then create a new instruction range.
|
|
|
|
DbgRange R(RangeBeginMI, PrevMI);
|
2010-07-22 05:21:52 +08:00
|
|
|
MI2ScopeMap[RangeBeginMI] = getOrCreateDbgScope(PrevScope,
|
2010-07-08 04:12:52 +08:00
|
|
|
PrevInlinedAt);
|
2010-04-28 03:46:33 +08:00
|
|
|
MIRanges.push_back(R);
|
2010-07-22 05:21:52 +08:00
|
|
|
}
|
2010-04-23 09:18:53 +08:00
|
|
|
|
2010-04-28 03:46:33 +08:00
|
|
|
// This is a beginning of a new instruction range.
|
|
|
|
RangeBeginMI = MInsn;
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-04-28 03:46:33 +08:00
|
|
|
// Reset previous markers.
|
|
|
|
PrevMI = MInsn;
|
|
|
|
PrevScope = Scope;
|
|
|
|
PrevInlinedAt = InlinedAt;
|
2009-10-02 04:31:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-28 03:46:33 +08:00
|
|
|
// Create last instruction range.
|
|
|
|
if (RangeBeginMI && PrevMI && PrevScope) {
|
|
|
|
DbgRange R(RangeBeginMI, PrevMI);
|
|
|
|
MIRanges.push_back(R);
|
|
|
|
MI2ScopeMap[RangeBeginMI] = getOrCreateDbgScope(PrevScope, PrevInlinedAt);
|
|
|
|
}
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-01-05 04:44:00 +08:00
|
|
|
if (!CurrentFnDbgScope)
|
|
|
|
return false;
|
|
|
|
|
2010-04-28 03:46:33 +08:00
|
|
|
calculateDominanceGraph(CurrentFnDbgScope);
|
|
|
|
if (PrintDbgScope)
|
|
|
|
printDbgScopeInfo(Ctx, Asm->MF, MI2ScopeMap);
|
|
|
|
|
|
|
|
// Find ranges of instructions covered by each DbgScope;
|
|
|
|
DbgScope *PrevDbgScope = NULL;
|
|
|
|
for (SmallVector<DbgRange, 4>::const_iterator RI = MIRanges.begin(),
|
|
|
|
RE = MIRanges.end(); RI != RE; ++RI) {
|
|
|
|
const DbgRange &R = *RI;
|
|
|
|
DbgScope *S = MI2ScopeMap.lookup(R.first);
|
|
|
|
assert (S && "Lost DbgScope for a machine instruction!");
|
|
|
|
if (PrevDbgScope && !PrevDbgScope->dominates(S))
|
|
|
|
PrevDbgScope->closeInsnRange(S);
|
|
|
|
S->openInsnRange(R.first);
|
|
|
|
S->extendInsnRange(R.second);
|
|
|
|
PrevDbgScope = S;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PrevDbgScope)
|
|
|
|
PrevDbgScope->closeInsnRange();
|
2009-10-02 04:31:14 +08:00
|
|
|
|
2010-04-09 02:43:56 +08:00
|
|
|
identifyScopeMarkers();
|
2010-04-08 23:37:09 +08:00
|
|
|
|
|
|
|
return !DbgScopeMap.empty();
|
|
|
|
}
|
|
|
|
|
2010-07-22 05:21:52 +08:00
|
|
|
/// identifyScopeMarkers() -
|
2010-04-28 03:46:33 +08:00
|
|
|
/// Each DbgScope has first instruction and last instruction to mark beginning
|
|
|
|
/// and end of a scope respectively. Create an inverse map that list scopes
|
|
|
|
/// starts (and ends) with an instruction. One instruction may start (or end)
|
|
|
|
/// multiple scopes. Ignore scopes that are not reachable.
|
2010-04-09 02:43:56 +08:00
|
|
|
void DwarfDebug::identifyScopeMarkers() {
|
2010-01-20 10:05:23 +08:00
|
|
|
SmallVector<DbgScope *, 4> WorkList;
|
|
|
|
WorkList.push_back(CurrentFnDbgScope);
|
|
|
|
while (!WorkList.empty()) {
|
2010-03-31 13:39:57 +08:00
|
|
|
DbgScope *S = WorkList.pop_back_val();
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-03-13 01:45:06 +08:00
|
|
|
const SmallVector<DbgScope *, 4> &Children = S->getScopes();
|
2010-07-22 05:21:52 +08:00
|
|
|
if (!Children.empty())
|
2010-03-13 01:45:06 +08:00
|
|
|
for (SmallVector<DbgScope *, 4>::const_iterator SI = Children.begin(),
|
2010-01-20 10:05:23 +08:00
|
|
|
SE = Children.end(); SI != SE; ++SI)
|
|
|
|
WorkList.push_back(*SI);
|
|
|
|
|
2009-11-11 07:06:00 +08:00
|
|
|
if (S->isAbstractScope())
|
|
|
|
continue;
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-04-28 03:46:33 +08:00
|
|
|
const SmallVector<DbgRange, 4> &Ranges = S->getRanges();
|
|
|
|
if (Ranges.empty())
|
|
|
|
continue;
|
|
|
|
for (SmallVector<DbgRange, 4>::const_iterator RI = Ranges.begin(),
|
|
|
|
RE = Ranges.end(); RI != RE; ++RI) {
|
2010-07-22 05:21:52 +08:00
|
|
|
assert(RI->first && "DbgRange does not have first instruction!");
|
|
|
|
assert(RI->second && "DbgRange does not have second instruction!");
|
2010-04-28 03:46:33 +08:00
|
|
|
InsnsEndScopeSet.insert(RI->second);
|
|
|
|
}
|
2009-10-02 04:31:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-20 08:37:27 +08:00
|
|
|
/// FindFirstDebugLoc - Find the first debug location in the function. This
|
|
|
|
/// is intended to be an approximation for the source position of the
|
|
|
|
/// beginning of the function.
|
|
|
|
static DebugLoc FindFirstDebugLoc(const MachineFunction *MF) {
|
|
|
|
for (MachineFunction::const_iterator I = MF->begin(), E = MF->end();
|
|
|
|
I != E; ++I)
|
|
|
|
for (MachineBasicBlock::const_iterator MBBI = I->begin(), MBBE = I->end();
|
|
|
|
MBBI != MBBE; ++MBBI) {
|
|
|
|
DebugLoc DL = MBBI->getDebugLoc();
|
|
|
|
if (!DL.isUnknown())
|
|
|
|
return DL;
|
|
|
|
}
|
|
|
|
return DebugLoc();
|
|
|
|
}
|
|
|
|
|
2010-10-26 04:45:32 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
/// CheckLineNumbers - Count basicblocks whose instructions do not have any
|
|
|
|
/// line number information.
|
|
|
|
static void CheckLineNumbers(const MachineFunction *MF) {
|
|
|
|
for (MachineFunction::const_iterator I = MF->begin(), E = MF->end();
|
|
|
|
I != E; ++I) {
|
|
|
|
bool FoundLineNo = false;
|
|
|
|
for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
|
|
|
|
II != IE; ++II) {
|
|
|
|
const MachineInstr *MI = II;
|
|
|
|
if (!MI->getDebugLoc().isUnknown()) {
|
|
|
|
FoundLineNo = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-10-29 06:11:59 +08:00
|
|
|
if (!FoundLineNo && I->size())
|
2010-10-26 04:45:32 +08:00
|
|
|
++BlocksWithoutLineNo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// beginFunction - Gather pre-function debug information. Assumes being
|
2009-05-21 07:21:38 +08:00
|
|
|
/// emitted immediately after the function entry point.
|
2010-01-27 07:18:02 +08:00
|
|
|
void DwarfDebug::beginFunction(const MachineFunction *MF) {
|
2010-04-05 11:52:55 +08:00
|
|
|
if (!MMI->hasDebugInfo()) return;
|
2010-04-07 17:28:04 +08:00
|
|
|
if (!extractScopeInformation()) return;
|
2009-10-07 02:37:31 +08:00
|
|
|
|
2010-10-26 04:45:32 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
CheckLineNumbers(MF);
|
|
|
|
#endif
|
|
|
|
|
2010-04-28 03:46:33 +08:00
|
|
|
FunctionBeginSym = Asm->GetTempSymbol("func_begin",
|
|
|
|
Asm->getFunctionNumber());
|
2009-05-21 07:21:38 +08:00
|
|
|
// Assumes in correct section after the entry point.
|
2010-04-28 03:46:33 +08:00
|
|
|
Asm->OutStreamer.EmitLabel(FunctionBeginSym);
|
2009-05-21 07:21:38 +08:00
|
|
|
|
|
|
|
// Emit label for the implicitly defined dbg.stoppoint at the start of the
|
|
|
|
// function.
|
2010-04-20 08:37:27 +08:00
|
|
|
DebugLoc FDL = FindFirstDebugLoc(MF);
|
2010-04-03 03:42:39 +08:00
|
|
|
if (FDL.isUnknown()) return;
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-08 04:54:48 +08:00
|
|
|
const MDNode *Scope = FDL.getScope(MF->getFunction()->getContext());
|
2010-07-20 07:56:30 +08:00
|
|
|
const MDNode *TheScope = 0;
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-04-03 03:42:39 +08:00
|
|
|
DISubprogram SP = getDISubprogram(Scope);
|
|
|
|
unsigned Line, Col;
|
|
|
|
if (SP.Verify()) {
|
|
|
|
Line = SP.getLineNumber();
|
|
|
|
Col = 0;
|
2010-07-20 07:56:30 +08:00
|
|
|
TheScope = SP;
|
2010-04-03 03:42:39 +08:00
|
|
|
} else {
|
|
|
|
Line = FDL.getLine();
|
|
|
|
Col = FDL.getCol();
|
2010-07-20 07:56:30 +08:00
|
|
|
TheScope = Scope;
|
2009-10-10 06:42:28 +08:00
|
|
|
}
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-07-20 07:56:30 +08:00
|
|
|
recordSourceLine(Line, Col, TheScope);
|
2010-05-27 03:37:24 +08:00
|
|
|
|
2010-06-03 00:42:51 +08:00
|
|
|
/// ProcessedArgs - Collection of arguments already processed.
|
|
|
|
SmallPtrSet<const MDNode *, 8> ProcessedArgs;
|
|
|
|
|
2010-05-27 03:37:24 +08:00
|
|
|
DebugLoc PrevLoc;
|
|
|
|
for (MachineFunction::const_iterator I = MF->begin(), E = MF->end();
|
|
|
|
I != E; ++I)
|
|
|
|
for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
|
|
|
|
II != IE; ++II) {
|
|
|
|
const MachineInstr *MI = II;
|
|
|
|
DebugLoc DL = MI->getDebugLoc();
|
|
|
|
if (MI->isDebugValue()) {
|
|
|
|
assert (MI->getNumOperands() > 1 && "Invalid machine instruction!");
|
|
|
|
DIVariable DV(MI->getOperand(MI->getNumOperands() - 1).getMetadata());
|
|
|
|
if (!DV.Verify()) continue;
|
2010-05-28 00:47:30 +08:00
|
|
|
// If DBG_VALUE is for a local variable then it needs a label.
|
2010-07-22 05:21:52 +08:00
|
|
|
if (DV.getTag() != dwarf::DW_TAG_arg_variable
|
2010-07-02 05:38:08 +08:00
|
|
|
&& isDbgValueInUndefinedReg(MI) == false)
|
2010-05-27 03:37:24 +08:00
|
|
|
InsnNeedsLabel.insert(MI);
|
2010-05-28 00:47:30 +08:00
|
|
|
// DBG_VALUE for inlined functions argument needs a label.
|
2010-07-02 05:38:08 +08:00
|
|
|
else if (!DISubprogram(getDISubprogram(DV.getContext())).
|
|
|
|
describes(MF->getFunction()))
|
2010-05-28 00:47:30 +08:00
|
|
|
InsnNeedsLabel.insert(MI);
|
|
|
|
// DBG_VALUE indicating argument location change needs a label.
|
2010-07-22 05:21:52 +08:00
|
|
|
else if (isDbgValueInUndefinedReg(MI) == false
|
|
|
|
&& !ProcessedArgs.insert(DV))
|
2010-05-27 03:37:24 +08:00
|
|
|
InsnNeedsLabel.insert(MI);
|
|
|
|
} else {
|
2010-07-22 05:21:52 +08:00
|
|
|
// If location is unknown then instruction needs a location only if
|
2010-05-27 03:37:24 +08:00
|
|
|
// UnknownLocations flag is set.
|
|
|
|
if (DL.isUnknown()) {
|
|
|
|
if (UnknownLocations && !PrevLoc.isUnknown())
|
|
|
|
InsnNeedsLabel.insert(MI);
|
|
|
|
} else if (DL != PrevLoc)
|
|
|
|
// Otherwise, instruction needs a location only if it is new location.
|
|
|
|
InsnNeedsLabel.insert(MI);
|
|
|
|
}
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-27 03:37:24 +08:00
|
|
|
if (!DL.isUnknown() || UnknownLocations)
|
|
|
|
PrevLoc = DL;
|
|
|
|
}
|
|
|
|
|
|
|
|
PrevLabel = FunctionBeginSym;
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// endFunction - Gather and emit post-function debug information.
|
2009-05-21 07:21:38 +08:00
|
|
|
///
|
2010-01-27 07:18:02 +08:00
|
|
|
void DwarfDebug::endFunction(const MachineFunction *MF) {
|
2010-04-07 17:28:04 +08:00
|
|
|
if (!MMI->hasDebugInfo() || DbgScopeMap.empty()) return;
|
2009-11-13 03:02:56 +08:00
|
|
|
|
2010-01-05 04:44:00 +08:00
|
|
|
if (CurrentFnDbgScope) {
|
2010-05-22 08:04:14 +08:00
|
|
|
|
2010-01-05 04:44:00 +08:00
|
|
|
// Define end label for subprogram.
|
2010-05-26 07:40:22 +08:00
|
|
|
FunctionEndSym = Asm->GetTempSymbol("func_end",
|
|
|
|
Asm->getFunctionNumber());
|
|
|
|
// Assumes in correct section after the entry point.
|
|
|
|
Asm->OutStreamer.EmitLabel(FunctionEndSym);
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-06-26 06:07:34 +08:00
|
|
|
SmallPtrSet<const MDNode *, 16> ProcessedVars;
|
|
|
|
collectVariableInfo(MF, ProcessedVars);
|
2010-05-26 07:40:22 +08:00
|
|
|
|
2010-01-05 04:44:00 +08:00
|
|
|
// 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());
|
|
|
|
}
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-01-05 04:44:00 +08:00
|
|
|
// Construct abstract scopes.
|
|
|
|
for (SmallVector<DbgScope *, 4>::iterator AI = AbstractScopesList.begin(),
|
2010-06-26 06:07:34 +08:00
|
|
|
AE = AbstractScopesList.end(); AI != AE; ++AI) {
|
|
|
|
DISubprogram SP((*AI)->getScopeNode());
|
|
|
|
if (SP.Verify()) {
|
|
|
|
// Collect info for variables that were optimized out.
|
|
|
|
StringRef FName = SP.getLinkageName();
|
|
|
|
if (FName.empty())
|
|
|
|
FName = SP.getName();
|
|
|
|
const Module *M = MF->getFunction()->getParent();
|
2010-07-22 05:21:52 +08:00
|
|
|
if (NamedMDNode *NMD =
|
|
|
|
M->getNamedMetadata(Twine("llvm.dbg.lv.",
|
2010-06-26 06:07:34 +08:00
|
|
|
getRealLinkageName(FName)))) {
|
|
|
|
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
|
2010-07-22 02:54:18 +08:00
|
|
|
DIVariable DV(cast<MDNode>(NMD->getOperand(i)));
|
2010-06-26 06:07:34 +08:00
|
|
|
if (!DV || !ProcessedVars.insert(DV))
|
|
|
|
continue;
|
2010-06-30 08:11:08 +08:00
|
|
|
DbgScope *Scope = AbstractScopes.lookup(DV.getContext());
|
2010-06-26 06:07:34 +08:00
|
|
|
if (Scope)
|
|
|
|
Scope->addVariable(new DbgVariable(DV));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-06-30 09:40:11 +08:00
|
|
|
if (ProcessedSPNodes.count((*AI)->getScopeNode()) == 0)
|
|
|
|
constructScopeDIE(*AI);
|
2010-06-26 06:07:34 +08:00
|
|
|
}
|
2010-07-08 04:12:52 +08:00
|
|
|
|
2010-05-04 14:15:30 +08:00
|
|
|
DIE *CurFnDIE = constructScopeDIE(CurrentFnDbgScope);
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-04 14:15:30 +08:00
|
|
|
if (!DisableFramePointerElim(*MF))
|
2010-07-22 05:21:52 +08:00
|
|
|
addUInt(CurFnDIE, dwarf::DW_AT_APPLE_omit_frame_ptr,
|
2010-05-04 14:15:30 +08:00
|
|
|
dwarf::DW_FORM_flag, 1);
|
|
|
|
|
|
|
|
|
2010-04-05 08:13:49 +08:00
|
|
|
DebugFrames.push_back(FunctionDebugFrameInfo(Asm->getFunctionNumber(),
|
2010-01-05 04:44:00 +08:00
|
|
|
MMI->getFrameMoves()));
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Clear debug info
|
2010-01-19 09:26:02 +08:00
|
|
|
CurrentFnDbgScope = NULL;
|
2010-05-27 03:37:24 +08:00
|
|
|
InsnNeedsLabel.clear();
|
2010-05-21 00:36:41 +08:00
|
|
|
DbgVariableToFrameIndexMap.clear();
|
|
|
|
VarToAbstractVarMap.clear();
|
|
|
|
DbgVariableToDbgInstMap.clear();
|
|
|
|
DbgVariableLabelsMap.clear();
|
2010-03-13 01:45:06 +08:00
|
|
|
DeleteContainerSeconds(DbgScopeMap);
|
2010-04-10 00:04:20 +08:00
|
|
|
InsnsEndScopeSet.clear();
|
2010-01-19 09:26:02 +08:00
|
|
|
ConcreteScopes.clear();
|
2010-03-13 01:45:06 +08:00
|
|
|
DeleteContainerSeconds(AbstractScopes);
|
2010-01-19 09:26:02 +08:00
|
|
|
AbstractScopesList.clear();
|
2010-03-13 01:45:06 +08:00
|
|
|
AbstractVariables.clear();
|
2010-04-28 03:46:33 +08:00
|
|
|
LabelsBeforeInsn.clear();
|
|
|
|
LabelsAfterInsn.clear();
|
2009-05-21 07:21:38 +08:00
|
|
|
Lines.clear();
|
2010-04-17 07:33:45 +08:00
|
|
|
PrevLabel = NULL;
|
2009-05-21 07:19:06 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-05-21 00:36:41 +08:00
|
|
|
/// recordVariableFrameIndex - Record a variable's index.
|
|
|
|
void DwarfDebug::recordVariableFrameIndex(const DbgVariable *V, int Index) {
|
|
|
|
assert (V && "Invalid DbgVariable!");
|
|
|
|
DbgVariableToFrameIndexMap[V] = Index;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// findVariableFrameIndex - Return true if frame index for the variable
|
|
|
|
/// is found. Update FI to hold value of the index.
|
|
|
|
bool DwarfDebug::findVariableFrameIndex(const DbgVariable *V, int *FI) {
|
|
|
|
assert (V && "Invalid DbgVariable!");
|
|
|
|
DenseMap<const DbgVariable *, int>::iterator I =
|
|
|
|
DbgVariableToFrameIndexMap.find(V);
|
|
|
|
if (I == DbgVariableToFrameIndexMap.end())
|
|
|
|
return false;
|
|
|
|
*FI = I->second;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// findVariableLabel - Find MCSymbol for the variable.
|
|
|
|
const MCSymbol *DwarfDebug::findVariableLabel(const DbgVariable *V) {
|
|
|
|
DenseMap<const DbgVariable *, const MCSymbol *>::iterator I
|
|
|
|
= DbgVariableLabelsMap.find(V);
|
|
|
|
if (I == DbgVariableLabelsMap.end())
|
|
|
|
return NULL;
|
|
|
|
else return I->second;
|
|
|
|
}
|
|
|
|
|
2010-07-22 05:21:52 +08:00
|
|
|
/// findDbgScope - Find DbgScope for the debug loc attached with an
|
2010-05-21 03:57:06 +08:00
|
|
|
/// instruction.
|
|
|
|
DbgScope *DwarfDebug::findDbgScope(const MachineInstr *MInsn) {
|
|
|
|
DbgScope *Scope = NULL;
|
2010-07-22 05:21:52 +08:00
|
|
|
LLVMContext &Ctx =
|
2010-05-21 03:57:06 +08:00
|
|
|
MInsn->getParent()->getParent()->getFunction()->getContext();
|
|
|
|
DebugLoc DL = MInsn->getDebugLoc();
|
|
|
|
|
2010-07-22 05:21:52 +08:00
|
|
|
if (DL.isUnknown())
|
2010-05-21 03:57:06 +08:00
|
|
|
return Scope;
|
|
|
|
|
|
|
|
if (const MDNode *IA = DL.getInlinedAt(Ctx))
|
|
|
|
Scope = ConcreteScopes.lookup(IA);
|
|
|
|
if (Scope == 0)
|
|
|
|
Scope = DbgScopeMap.lookup(DL.getScope(Ctx));
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-21 03:57:06 +08:00
|
|
|
return Scope;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-09 12:54:43 +08:00
|
|
|
/// recordSourceLine - Register a source line with debug info. Returns the
|
|
|
|
/// unique label that was emitted and which provides correspondence to
|
|
|
|
/// the source line list.
|
2010-07-22 05:21:52 +08:00
|
|
|
MCSymbol *DwarfDebug::recordSourceLine(unsigned Line, unsigned Col,
|
2010-07-08 04:12:52 +08:00
|
|
|
const MDNode *S) {
|
2009-11-26 01:36:49 +08:00
|
|
|
StringRef Dir;
|
|
|
|
StringRef Fn;
|
2009-10-06 02:03:19 +08:00
|
|
|
|
2010-05-06 07:41:32 +08:00
|
|
|
unsigned Src = 1;
|
|
|
|
if (S) {
|
|
|
|
DIDescriptor Scope(S);
|
|
|
|
|
|
|
|
if (Scope.isCompileUnit()) {
|
|
|
|
DICompileUnit CU(S);
|
|
|
|
Dir = CU.getDirectory();
|
|
|
|
Fn = CU.getFilename();
|
2010-10-29 01:30:52 +08:00
|
|
|
} else if (Scope.isFile()) {
|
|
|
|
DIFile F(S);
|
|
|
|
Dir = F.getDirectory();
|
|
|
|
Fn = F.getFilename();
|
2010-05-06 07:41:32 +08:00
|
|
|
} 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);
|
|
|
|
}
|
2009-10-06 02:03:19 +08:00
|
|
|
|
2010-03-14 16:36:50 +08:00
|
|
|
MCSymbol *Label = MMI->getContext().CreateTempSymbol();
|
2010-03-14 16:15:55 +08:00
|
|
|
Lines.push_back(SrcLineInfo(Line, Col, Src, Label));
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-03-09 12:54:43 +08:00
|
|
|
Asm->OutStreamer.EmitLabel(Label);
|
|
|
|
return Label;
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
2009-05-21 07:22:40 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Emit Methods
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// computeSizeAndOffset - Compute the size and offset of a DIE.
|
2009-05-21 07:21:38 +08:00
|
|
|
///
|
2009-11-23 03:20:36 +08:00
|
|
|
unsigned
|
|
|
|
DwarfDebug::computeSizeAndOffset(DIE *Die, unsigned Offset, bool Last) {
|
2009-05-21 07:21:38 +08:00
|
|
|
// Get the children.
|
|
|
|
const std::vector<DIE *> &Children = Die->getChildren();
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// If not last sibling and has children then add sibling offset attribute.
|
2010-03-23 02:47:14 +08:00
|
|
|
if (!Last && !Children.empty())
|
2010-04-01 03:34:01 +08:00
|
|
|
Die->addSiblingOffset(DIEValueAllocator);
|
2009-05-21 07:21:38 +08:00
|
|
|
|
|
|
|
// Record the abbreviation.
|
2009-11-21 10:48:08 +08:00
|
|
|
assignAbbrevNumber(Die->getAbbrev());
|
2009-05-21 07:21:38 +08:00
|
|
|
|
|
|
|
// Get the abbreviation for this DIE.
|
|
|
|
unsigned AbbrevNumber = Die->getAbbrevNumber();
|
|
|
|
const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1];
|
|
|
|
|
|
|
|
// Set DIE offset
|
|
|
|
Die->setOffset(Offset);
|
|
|
|
|
|
|
|
// Start the size with the size of abbreviation code.
|
2009-08-23 04:48:53 +08:00
|
|
|
Offset += MCAsmInfo::getULEB128Size(AbbrevNumber);
|
2009-05-21 07:21:38 +08:00
|
|
|
|
|
|
|
const SmallVector<DIEValue*, 32> &Values = Die->getValues();
|
|
|
|
const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev->getData();
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Size the DIE attribute values.
|
|
|
|
for (unsigned i = 0, N = Values.size(); i < N; ++i)
|
|
|
|
// Size attribute value.
|
2010-04-05 08:18:22 +08:00
|
|
|
Offset += Values[i]->SizeOf(Asm, AbbrevData[i].getForm());
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Size the DIE children if any.
|
|
|
|
if (!Children.empty()) {
|
|
|
|
assert(Abbrev->getChildrenFlag() == dwarf::DW_CHILDREN_yes &&
|
|
|
|
"Children flag not set");
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
for (unsigned j = 0, M = Children.size(); j < M; ++j)
|
2009-11-21 10:48:08 +08:00
|
|
|
Offset = computeSizeAndOffset(Children[j], Offset, (j + 1) == M);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// End of children marker.
|
|
|
|
Offset += sizeof(int8_t);
|
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
Die->setSize(Offset - Die->getOffset());
|
|
|
|
return Offset;
|
2009-05-21 07:19:06 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// computeSizeAndOffsets - Compute the size and offset of all the DIEs.
|
2009-05-21 07:21:38 +08:00
|
|
|
///
|
2009-11-21 10:48:08 +08:00
|
|
|
void DwarfDebug::computeSizeAndOffsets() {
|
2010-05-11 06:49:55 +08:00
|
|
|
unsigned PrevOffset = 0;
|
|
|
|
for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
|
|
|
|
E = CUMap.end(); I != E; ++I) {
|
|
|
|
// Compute size of compile unit header.
|
|
|
|
static unsigned Offset = PrevOffset +
|
|
|
|
sizeof(int32_t) + // Length of Compilation Unit Info
|
|
|
|
sizeof(int16_t) + // DWARF version number
|
|
|
|
sizeof(int32_t) + // Offset Into Abbrev. Section
|
|
|
|
sizeof(int8_t); // Pointer Size (in bytes)
|
|
|
|
computeSizeAndOffset(I->second->getCUDie(), Offset, true);
|
|
|
|
PrevOffset = Offset;
|
|
|
|
}
|
2009-05-21 07:19:06 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-04-05 07:02:02 +08:00
|
|
|
/// EmitSectionSym - Switch to the specified MCSection and emit an assembler
|
|
|
|
/// temporary label to it if SymbolStem is specified.
|
2010-04-05 06:59:04 +08:00
|
|
|
static MCSymbol *EmitSectionSym(AsmPrinter *Asm, const MCSection *Section,
|
2010-04-05 07:02:02 +08:00
|
|
|
const char *SymbolStem = 0) {
|
2010-04-05 06:59:04 +08:00
|
|
|
Asm->OutStreamer.SwitchSection(Section);
|
2010-04-05 07:02:02 +08:00
|
|
|
if (!SymbolStem) return 0;
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-04-05 06:59:04 +08:00
|
|
|
MCSymbol *TmpSym = Asm->GetTempSymbol(SymbolStem);
|
|
|
|
Asm->OutStreamer.EmitLabel(TmpSym);
|
|
|
|
return TmpSym;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitSectionLabels - Emit initial Dwarf sections with a label at
|
|
|
|
/// the start of each one.
|
2010-04-05 06:33:59 +08:00
|
|
|
void DwarfDebug::EmitSectionLabels() {
|
2009-08-19 13:49:37 +08:00
|
|
|
const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
|
2009-09-20 04:40:05 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Dwarf sections base addresses.
|
2010-04-05 08:13:49 +08:00
|
|
|
if (Asm->MAI->doesDwarfRequireFrameSection()) {
|
2010-04-05 06:59:04 +08:00
|
|
|
DwarfFrameSectionSym =
|
|
|
|
EmitSectionSym(Asm, TLOF.getDwarfFrameSection(), "section_debug_frame");
|
|
|
|
}
|
|
|
|
|
2010-07-22 05:21:52 +08:00
|
|
|
DwarfInfoSectionSym =
|
2010-04-05 06:59:04 +08:00
|
|
|
EmitSectionSym(Asm, TLOF.getDwarfInfoSection(), "section_info");
|
2010-07-22 05:21:52 +08:00
|
|
|
DwarfAbbrevSectionSym =
|
2010-04-05 06:59:04 +08:00
|
|
|
EmitSectionSym(Asm, TLOF.getDwarfAbbrevSection(), "section_abbrev");
|
2010-04-05 07:02:02 +08:00
|
|
|
EmitSectionSym(Asm, TLOF.getDwarfARangesSection());
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-04-05 06:59:04 +08:00
|
|
|
if (const MCSection *MacroInfo = TLOF.getDwarfMacroInfoSection())
|
2010-04-05 07:02:02 +08:00
|
|
|
EmitSectionSym(Asm, MacroInfo);
|
2010-04-05 06:59:04 +08:00
|
|
|
|
2010-08-24 08:06:12 +08:00
|
|
|
EmitSectionSym(Asm, TLOF.getDwarfLineSection(), "section_line");
|
2010-04-05 07:02:02 +08:00
|
|
|
EmitSectionSym(Asm, TLOF.getDwarfLocSection());
|
|
|
|
EmitSectionSym(Asm, TLOF.getDwarfPubNamesSection());
|
|
|
|
EmitSectionSym(Asm, TLOF.getDwarfPubTypesSection());
|
2010-07-22 05:21:52 +08:00
|
|
|
DwarfStrSectionSym =
|
2010-04-05 06:59:04 +08:00
|
|
|
EmitSectionSym(Asm, TLOF.getDwarfStrSection(), "section_str");
|
2010-04-17 07:33:45 +08:00
|
|
|
DwarfDebugRangeSectionSym = EmitSectionSym(Asm, TLOF.getDwarfRangesSection(),
|
|
|
|
"debug_range");
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-05-26 07:40:22 +08:00
|
|
|
DwarfDebugLocSectionSym = EmitSectionSym(Asm, TLOF.getDwarfLocSection(),
|
|
|
|
"section_debug_loc");
|
|
|
|
|
2010-04-05 06:59:04 +08:00
|
|
|
TextSectionSym = EmitSectionSym(Asm, TLOF.getTextSection(), "text_begin");
|
2010-04-05 07:10:38 +08:00
|
|
|
EmitSectionSym(Asm, TLOF.getDataSection());
|
2009-05-21 07:04:56 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// emitDIE - Recusively Emits a debug information entry.
|
2009-05-21 07:21:38 +08:00
|
|
|
///
|
2009-11-21 10:48:08 +08:00
|
|
|
void DwarfDebug::emitDIE(DIE *Die) {
|
2009-05-21 07:21:38 +08:00
|
|
|
// Get the abbreviation for this DIE.
|
|
|
|
unsigned AbbrevNumber = Die->getAbbrevNumber();
|
|
|
|
const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1];
|
2009-05-21 07:04:56 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Emit the code (index) for the abbreviation.
|
2010-04-05 02:52:31 +08:00
|
|
|
if (Asm->isVerbose())
|
2010-01-23 07:18:42 +08:00
|
|
|
Asm->OutStreamer.AddComment("Abbrev [" + Twine(AbbrevNumber) + "] 0x" +
|
|
|
|
Twine::utohexstr(Die->getOffset()) + ":0x" +
|
|
|
|
Twine::utohexstr(Die->getSize()) + " " +
|
|
|
|
dwarf::TagString(Abbrev->getTag()));
|
2010-04-05 03:09:29 +08:00
|
|
|
Asm->EmitULEB128(AbbrevNumber);
|
2009-05-21 07:04:56 +08:00
|
|
|
|
2010-03-23 02:47:14 +08:00
|
|
|
const SmallVector<DIEValue*, 32> &Values = Die->getValues();
|
2009-05-21 07:21:38 +08:00
|
|
|
const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev->getData();
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Emit the DIE attribute values.
|
|
|
|
for (unsigned i = 0, N = Values.size(); i < N; ++i) {
|
|
|
|
unsigned Attr = AbbrevData[i].getAttribute();
|
|
|
|
unsigned Form = AbbrevData[i].getForm();
|
|
|
|
assert(Form && "Too many attributes for DIE (check abbreviation)");
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-04-05 02:52:31 +08:00
|
|
|
if (Asm->isVerbose())
|
2010-01-25 02:54:17 +08:00
|
|
|
Asm->OutStreamer.AddComment(dwarf::AttributeString(Attr));
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
switch (Attr) {
|
|
|
|
case dwarf::DW_AT_sibling:
|
2009-11-21 10:48:08 +08:00
|
|
|
Asm->EmitInt32(Die->getSiblingOffset());
|
2009-05-21 07:21:38 +08:00
|
|
|
break;
|
|
|
|
case dwarf::DW_AT_abstract_origin: {
|
|
|
|
DIEEntry *E = cast<DIEEntry>(Values[i]);
|
|
|
|
DIE *Origin = E->getEntry();
|
2009-11-11 07:06:00 +08:00
|
|
|
unsigned Addr = Origin->getOffset();
|
2009-05-21 07:21:38 +08:00
|
|
|
Asm->EmitInt32(Addr);
|
|
|
|
break;
|
|
|
|
}
|
2010-04-17 07:33:45 +08:00
|
|
|
case dwarf::DW_AT_ranges: {
|
|
|
|
// DW_AT_range Value encodes offset in debug_range section.
|
|
|
|
DIEInteger *V = cast<DIEInteger>(Values[i]);
|
2010-09-03 00:43:44 +08:00
|
|
|
|
|
|
|
if (Asm->MAI->doesDwarfUsesLabelOffsetForRanges()) {
|
|
|
|
Asm->EmitLabelPlusOffset(DwarfDebugRangeSectionSym,
|
|
|
|
V->getValue(),
|
|
|
|
4);
|
|
|
|
} else {
|
|
|
|
Asm->EmitLabelOffsetDifference(DwarfDebugRangeSectionSym,
|
|
|
|
V->getValue(),
|
|
|
|
DwarfDebugRangeSectionSym,
|
|
|
|
4);
|
|
|
|
}
|
2010-04-17 07:33:45 +08:00
|
|
|
break;
|
|
|
|
}
|
2010-05-26 07:40:22 +08:00
|
|
|
case dwarf::DW_AT_location: {
|
|
|
|
if (UseDotDebugLocEntry.count(Die) != 0) {
|
|
|
|
DIELabel *L = cast<DIELabel>(Values[i]);
|
|
|
|
Asm->EmitLabelDifference(L->getValue(), DwarfDebugLocSectionSym, 4);
|
|
|
|
} else
|
|
|
|
Values[i]->EmitValue(Asm, Form);
|
|
|
|
break;
|
2010-09-30 03:08:08 +08:00
|
|
|
}
|
|
|
|
case dwarf::DW_AT_accessibility: {
|
|
|
|
if (Asm->isVerbose()) {
|
|
|
|
DIEInteger *V = cast<DIEInteger>(Values[i]);
|
|
|
|
Asm->OutStreamer.AddComment(dwarf::AccessibilityString(V->getValue()));
|
|
|
|
}
|
|
|
|
Values[i]->EmitValue(Asm, Form);
|
|
|
|
break;
|
2010-05-26 07:40:22 +08:00
|
|
|
}
|
2009-05-21 07:21:38 +08:00
|
|
|
default:
|
|
|
|
// Emit an attribute using the defined form.
|
2010-04-05 08:13:49 +08:00
|
|
|
Values[i]->EmitValue(Asm, Form);
|
2009-05-21 07:21:38 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Emit the DIE children if any.
|
|
|
|
if (Abbrev->getChildrenFlag() == dwarf::DW_CHILDREN_yes) {
|
|
|
|
const std::vector<DIE *> &Children = Die->getChildren();
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
for (unsigned j = 0, M = Children.size(); j < M; ++j)
|
2009-11-21 10:48:08 +08:00
|
|
|
emitDIE(Children[j]);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-04-05 02:52:31 +08:00
|
|
|
if (Asm->isVerbose())
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("End Of Children Mark");
|
|
|
|
Asm->EmitInt8(0);
|
2009-05-21 07:19:06 +08:00
|
|
|
}
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-12-10 02:24:21 +08:00
|
|
|
/// emitDebugInfo - Emit the debug info section.
|
2009-05-21 07:21:38 +08:00
|
|
|
///
|
2009-12-10 02:24:21 +08:00
|
|
|
void DwarfDebug::emitDebugInfo() {
|
|
|
|
// Start debug info section.
|
|
|
|
Asm->OutStreamer.SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfInfoSection());
|
2010-05-11 06:49:55 +08:00
|
|
|
for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
|
|
|
|
E = CUMap.end(); I != E; ++I) {
|
|
|
|
CompileUnit *TheCU = I->second;
|
|
|
|
DIE *Die = TheCU->getCUDie();
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-11 06:49:55 +08:00
|
|
|
// Emit the compile units header.
|
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("info_begin",
|
|
|
|
TheCU->getID()));
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-11 06:49:55 +08:00
|
|
|
// Emit size of content not including length itself
|
|
|
|
unsigned ContentSize = Die->getSize() +
|
|
|
|
sizeof(int16_t) + // DWARF version number
|
|
|
|
sizeof(int32_t) + // Offset Into Abbrev. Section
|
|
|
|
sizeof(int8_t) + // Pointer Size (in bytes)
|
|
|
|
sizeof(int32_t); // FIXME - extra pad for gdb bug.
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-11 06:49:55 +08:00
|
|
|
Asm->OutStreamer.AddComment("Length of Compilation Unit Info");
|
|
|
|
Asm->EmitInt32(ContentSize);
|
|
|
|
Asm->OutStreamer.AddComment("DWARF version number");
|
|
|
|
Asm->EmitInt16(dwarf::DWARF_VERSION);
|
|
|
|
Asm->OutStreamer.AddComment("Offset Into Abbrev. Section");
|
|
|
|
Asm->EmitSectionOffset(Asm->GetTempSymbol("abbrev_begin"),
|
|
|
|
DwarfAbbrevSectionSym);
|
|
|
|
Asm->OutStreamer.AddComment("Address Size (in bytes)");
|
|
|
|
Asm->EmitInt8(Asm->getTargetData().getPointerSize());
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-11 06:49:55 +08:00
|
|
|
emitDIE(Die);
|
|
|
|
// FIXME - extra padding for gdb bug.
|
|
|
|
Asm->OutStreamer.AddComment("4 extra padding bytes for GDB");
|
|
|
|
Asm->EmitInt8(0);
|
|
|
|
Asm->EmitInt8(0);
|
|
|
|
Asm->EmitInt8(0);
|
|
|
|
Asm->EmitInt8(0);
|
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("info_end", TheCU->getID()));
|
|
|
|
}
|
2009-05-21 07:04:56 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// emitAbbreviations - Emit the abbreviation section.
|
2009-05-21 07:04:56 +08:00
|
|
|
///
|
2009-11-21 10:48:08 +08:00
|
|
|
void DwarfDebug::emitAbbreviations() const {
|
2009-05-21 07:21:38 +08:00
|
|
|
// Check to see if it is worth the effort.
|
|
|
|
if (!Abbreviations.empty()) {
|
|
|
|
// Start the debug abbrev section.
|
2009-08-19 13:49:37 +08:00
|
|
|
Asm->OutStreamer.SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfAbbrevSection());
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-04-05 03:25:43 +08:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("abbrev_begin"));
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// For each abbrevation.
|
|
|
|
for (unsigned i = 0, N = Abbreviations.size(); i < N; ++i) {
|
|
|
|
// Get abbreviation data
|
|
|
|
const DIEAbbrev *Abbrev = Abbreviations[i];
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Emit the abbrevations code (base 1 index.)
|
2010-04-05 03:09:29 +08:00
|
|
|
Asm->EmitULEB128(Abbrev->getNumber(), "Abbreviation Code");
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Emit the abbreviations data.
|
2010-04-05 08:13:49 +08:00
|
|
|
Abbrev->Emit(Asm);
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Mark end of abbreviations.
|
2010-04-05 03:09:29 +08:00
|
|
|
Asm->EmitULEB128(0, "EOM(3)");
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-04-05 03:25:43 +08:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("abbrev_end"));
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// emitEndOfLineMatrix - Emit the last address of the section and the end of
|
2009-05-21 07:21:38 +08:00
|
|
|
/// the line matrix.
|
|
|
|
///
|
2009-11-21 10:48:08 +08:00
|
|
|
void DwarfDebug::emitEndOfLineMatrix(unsigned SectionEnd) {
|
2009-05-21 07:21:38 +08:00
|
|
|
// Define last address of section.
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("Extended Op");
|
|
|
|
Asm->EmitInt8(0);
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("Op size");
|
2010-04-05 08:13:49 +08:00
|
|
|
Asm->EmitInt8(Asm->getTargetData().getPointerSize() + 1);
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("DW_LNE_set_address");
|
|
|
|
Asm->EmitInt8(dwarf::DW_LNE_set_address);
|
|
|
|
|
|
|
|
Asm->OutStreamer.AddComment("Section end label");
|
2010-03-10 09:17:49 +08:00
|
|
|
|
2010-04-05 03:25:43 +08:00
|
|
|
Asm->OutStreamer.EmitSymbolValue(Asm->GetTempSymbol("section_end",SectionEnd),
|
2010-04-05 08:13:49 +08:00
|
|
|
Asm->getTargetData().getPointerSize(),
|
|
|
|
0/*AddrSpace*/);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Mark end of matrix.
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("DW_LNE_end_sequence");
|
|
|
|
Asm->EmitInt8(0);
|
2010-01-23 06:09:00 +08:00
|
|
|
Asm->EmitInt8(1);
|
2010-01-23 07:18:42 +08:00
|
|
|
Asm->EmitInt8(1);
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// emitDebugLines - Emit source line information.
|
2009-05-21 07:21:38 +08:00
|
|
|
///
|
2009-11-21 10:48:08 +08:00
|
|
|
void DwarfDebug::emitDebugLines() {
|
2009-05-21 07:21:38 +08:00
|
|
|
// If the target is using .loc/.file, the assembler will be emitting the
|
|
|
|
// .debug_line table automatically.
|
2010-04-05 08:13:49 +08:00
|
|
|
if (Asm->MAI->hasDotLocAndDotFile())
|
2009-05-21 07:21:38 +08:00
|
|
|
return;
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// 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;
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Start the dwarf line section.
|
2009-08-19 13:49:37 +08:00
|
|
|
Asm->OutStreamer.SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfLineSection());
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Construct the section header.
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("Length of Source Line Info");
|
2010-04-05 03:58:12 +08:00
|
|
|
Asm->EmitLabelDifference(Asm->GetTempSymbol("line_end"),
|
|
|
|
Asm->GetTempSymbol("line_begin"), 4);
|
2010-04-05 03:25:43 +08:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("line_begin"));
|
2009-05-21 07:04:56 +08:00
|
|
|
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("DWARF version number");
|
2010-07-22 05:21:52 +08:00
|
|
|
Asm->EmitInt16(dwarf::DWARF_VERSION);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("Prolog Length");
|
2010-04-05 03:58:12 +08:00
|
|
|
Asm->EmitLabelDifference(Asm->GetTempSymbol("line_prolog_end"),
|
|
|
|
Asm->GetTempSymbol("line_prolog_begin"), 4);
|
2010-04-05 03:25:43 +08:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("line_prolog_begin"));
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-03-10 07:52:58 +08:00
|
|
|
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);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Line number standard opcode encodings argument count
|
2010-03-10 07:52:58 +08:00
|
|
|
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);
|
2009-05-21 07:04:56 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Emit directories.
|
|
|
|
for (unsigned DI = 1, DE = getNumSourceDirectories()+1; DI != DE; ++DI) {
|
2010-01-23 11:11:46 +08:00
|
|
|
const std::string &Dir = getSourceDirectoryName(DI);
|
2010-04-05 02:52:31 +08:00
|
|
|
if (Asm->isVerbose()) Asm->OutStreamer.AddComment("Directory");
|
2010-01-23 11:11:46 +08:00
|
|
|
Asm->OutStreamer.EmitBytes(StringRef(Dir.c_str(), Dir.size()+1), 0);
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("End of directories");
|
|
|
|
Asm->EmitInt8(0);
|
2009-05-21 07:21:38 +08:00
|
|
|
|
|
|
|
// 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);
|
2010-01-23 11:11:46 +08:00
|
|
|
const std::string &FN = getSourceFileName(Id.second);
|
2010-04-05 02:52:31 +08:00
|
|
|
if (Asm->isVerbose()) Asm->OutStreamer.AddComment("Source");
|
2010-01-23 11:11:46 +08:00
|
|
|
Asm->OutStreamer.EmitBytes(StringRef(FN.c_str(), FN.size()+1), 0);
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-04-05 03:09:29 +08:00
|
|
|
Asm->EmitULEB128(Id.first, "Directory #");
|
|
|
|
Asm->EmitULEB128(0, "Mod date");
|
|
|
|
Asm->EmitULEB128(0, "File size");
|
2009-05-21 07:19:06 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("End of files");
|
|
|
|
Asm->EmitInt8(0);
|
2009-05-21 07:19:06 +08:00
|
|
|
|
2010-04-05 03:25:43 +08:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("line_prolog_end"));
|
2009-05-21 07:19:06 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// A sequence for each text section.
|
|
|
|
unsigned SecSrcLinesSize = SectionSourceLines.size();
|
2009-05-21 07:19:06 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
for (unsigned j = 0; j < SecSrcLinesSize; ++j) {
|
|
|
|
// Isolate current sections line info.
|
|
|
|
const std::vector<SrcLineInfo> &LineInfos = SectionSourceLines[j];
|
2009-05-21 07:19:06 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Dwarf assumes we start with first line of first source file.
|
|
|
|
unsigned Source = 1;
|
|
|
|
unsigned Line = 1;
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Construct rows of the address, source, line, column matrix.
|
|
|
|
for (unsigned i = 0, N = LineInfos.size(); i < N; ++i) {
|
|
|
|
const SrcLineInfo &LineInfo = LineInfos[i];
|
2010-03-14 16:15:55 +08:00
|
|
|
MCSymbol *Label = LineInfo.getLabel();
|
2010-03-14 10:20:58 +08:00
|
|
|
if (!Label->isDefined()) continue; // Not emitted, in dead code.
|
2009-05-21 07:21:38 +08:00
|
|
|
|
2010-03-10 07:38:23 +08:00
|
|
|
if (Asm->isVerbose()) {
|
2010-03-10 09:04:13 +08:00
|
|
|
std::pair<unsigned, unsigned> SrcID =
|
2009-05-21 07:21:38 +08:00
|
|
|
getSourceDirectoryAndFileIds(LineInfo.getSourceID());
|
2010-03-10 09:04:13 +08:00
|
|
|
Asm->OutStreamer.AddComment(Twine(getSourceDirectoryName(SrcID.first)) +
|
2010-03-10 10:29:31 +08:00
|
|
|
"/" +
|
|
|
|
Twine(getSourceFileName(SrcID.second)) +
|
2010-03-10 09:04:13 +08:00
|
|
|
":" + Twine(LineInfo.getLine()));
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Define the line address.
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("Extended Op");
|
|
|
|
Asm->EmitInt8(0);
|
|
|
|
Asm->OutStreamer.AddComment("Op size");
|
2010-04-05 08:13:49 +08:00
|
|
|
Asm->EmitInt8(Asm->getTargetData().getPointerSize() + 1);
|
2010-03-10 07:52:58 +08:00
|
|
|
|
|
|
|
Asm->OutStreamer.AddComment("DW_LNE_set_address");
|
2010-07-22 05:21:52 +08:00
|
|
|
Asm->EmitInt8(dwarf::DW_LNE_set_address);
|
2010-03-10 07:52:58 +08:00
|
|
|
|
|
|
|
Asm->OutStreamer.AddComment("Location label");
|
2010-04-05 08:13:49 +08:00
|
|
|
Asm->OutStreamer.EmitSymbolValue(Label,
|
|
|
|
Asm->getTargetData().getPointerSize(),
|
2010-03-14 10:20:58 +08:00
|
|
|
0/*AddrSpace*/);
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// If change of source, then switch to the new source.
|
|
|
|
if (Source != LineInfo.getSourceID()) {
|
|
|
|
Source = LineInfo.getSourceID();
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("DW_LNS_set_file");
|
2010-07-22 05:21:52 +08:00
|
|
|
Asm->EmitInt8(dwarf::DW_LNS_set_file);
|
2010-04-05 03:09:29 +08:00
|
|
|
Asm->EmitULEB128(Source, "New Source");
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// If change of line.
|
|
|
|
if (Line != LineInfo.getLine()) {
|
|
|
|
// Determine offset.
|
|
|
|
int Offset = LineInfo.getLine() - Line;
|
|
|
|
int Delta = Offset - MinLineDelta;
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Update line.
|
|
|
|
Line = LineInfo.getLine();
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// If delta is small enough and in range...
|
|
|
|
if (Delta >= 0 && Delta < (MaxLineDelta - 1)) {
|
|
|
|
// ... then use fast opcode.
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("Line Delta");
|
|
|
|
Asm->EmitInt8(Delta - MinLineDelta);
|
2009-05-21 07:21:38 +08:00
|
|
|
} else {
|
|
|
|
// ... otherwise use long hand.
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("DW_LNS_advance_line");
|
2009-05-21 07:21:38 +08:00
|
|
|
Asm->EmitInt8(dwarf::DW_LNS_advance_line);
|
2010-04-05 03:09:29 +08:00
|
|
|
Asm->EmitSLEB128(Offset, "Line Offset");
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("DW_LNS_copy");
|
|
|
|
Asm->EmitInt8(dwarf::DW_LNS_copy);
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Copy the previous row (different address or source)
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("DW_LNS_copy");
|
|
|
|
Asm->EmitInt8(dwarf::DW_LNS_copy);
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
emitEndOfLineMatrix(j + 1);
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
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.
|
2009-11-21 10:48:08 +08:00
|
|
|
emitEndOfLineMatrix(1);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-04-05 03:25:43 +08:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("line_end"));
|
2009-05-21 07:19:06 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// emitCommonDebugFrame - Emit common frame info into a debug frame section.
|
2009-05-21 07:21:38 +08:00
|
|
|
///
|
2009-11-21 10:48:08 +08:00
|
|
|
void DwarfDebug::emitCommonDebugFrame() {
|
2010-04-05 08:13:49 +08:00
|
|
|
if (!Asm->MAI->doesDwarfRequireFrameSection())
|
2009-05-21 07:21:38 +08:00
|
|
|
return;
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-04-05 08:13:49 +08:00
|
|
|
int stackGrowth = Asm->getTargetData().getPointerSize();
|
|
|
|
if (Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
|
|
|
|
TargetFrameInfo::StackGrowsDown)
|
|
|
|
stackGrowth *= -1;
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Start the dwarf frame section.
|
2009-08-19 13:49:37 +08:00
|
|
|
Asm->OutStreamer.SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfFrameSection());
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-04-05 03:25:43 +08:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_frame_common"));
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("Length of Common Information Entry");
|
2010-04-05 03:58:12 +08:00
|
|
|
Asm->EmitLabelDifference(Asm->GetTempSymbol("debug_frame_common_end"),
|
|
|
|
Asm->GetTempSymbol("debug_frame_common_begin"), 4);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-04-05 03:25:43 +08:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_frame_common_begin"));
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("CIE Identifier Tag");
|
2009-05-21 07:21:38 +08:00
|
|
|
Asm->EmitInt32((int)dwarf::DW_CIE_ID);
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("CIE Version");
|
2009-05-21 07:21:38 +08:00
|
|
|
Asm->EmitInt8(dwarf::DW_CIE_VERSION);
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("CIE Augmentation");
|
2010-01-23 11:11:46 +08:00
|
|
|
Asm->OutStreamer.EmitIntValue(0, 1, /*addrspace*/0); // nul terminator.
|
2010-04-05 03:09:29 +08:00
|
|
|
Asm->EmitULEB128(1, "CIE Code Alignment Factor");
|
|
|
|
Asm->EmitSLEB128(stackGrowth, "CIE Data Alignment Factor");
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("CIE RA Column");
|
2010-04-05 08:13:49 +08:00
|
|
|
const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo();
|
2009-05-21 07:21:38 +08:00
|
|
|
Asm->EmitInt8(RI->getDwarfRegNum(RI->getRARegister(), false));
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
std::vector<MachineMove> Moves;
|
|
|
|
RI->getInitialFrameState(Moves);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-04-05 07:41:46 +08:00
|
|
|
Asm->EmitFrameMoves(Moves, 0, false);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-04-28 09:05:45 +08:00
|
|
|
Asm->EmitAlignment(2);
|
2010-04-05 03:25:43 +08:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_frame_common_end"));
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// emitFunctionDebugFrame - Emit per function frame info into a debug frame
|
2009-05-21 07:21:38 +08:00
|
|
|
/// section.
|
2010-03-13 15:26:18 +08:00
|
|
|
void DwarfDebug::
|
|
|
|
emitFunctionDebugFrame(const FunctionDebugFrameInfo &DebugFrameInfo) {
|
2010-04-05 08:13:49 +08:00
|
|
|
if (!Asm->MAI->doesDwarfRequireFrameSection())
|
2009-05-21 07:21:38 +08:00
|
|
|
return;
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Start the dwarf frame section.
|
2009-08-19 13:49:37 +08:00
|
|
|
Asm->OutStreamer.SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfFrameSection());
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("Length of Frame Information Entry");
|
2010-03-13 15:26:18 +08:00
|
|
|
MCSymbol *DebugFrameBegin =
|
2010-04-05 03:25:43 +08:00
|
|
|
Asm->GetTempSymbol("debug_frame_begin", DebugFrameInfo.Number);
|
2010-03-13 15:26:18 +08:00
|
|
|
MCSymbol *DebugFrameEnd =
|
2010-04-05 03:25:43 +08:00
|
|
|
Asm->GetTempSymbol("debug_frame_end", DebugFrameInfo.Number);
|
2010-04-05 03:58:12 +08:00
|
|
|
Asm->EmitLabelDifference(DebugFrameEnd, DebugFrameBegin, 4);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-03-13 15:26:18 +08:00
|
|
|
Asm->OutStreamer.EmitLabel(DebugFrameBegin);
|
2009-05-21 07:19:06 +08:00
|
|
|
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("FDE CIE offset");
|
2010-07-22 05:21:52 +08:00
|
|
|
Asm->EmitSectionOffset(Asm->GetTempSymbol("debug_frame_common"),
|
2010-04-05 07:25:33 +08:00
|
|
|
DwarfFrameSectionSym);
|
2009-05-21 07:19:06 +08:00
|
|
|
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("FDE initial location");
|
2010-04-05 03:25:43 +08:00
|
|
|
MCSymbol *FuncBeginSym =
|
|
|
|
Asm->GetTempSymbol("func_begin", DebugFrameInfo.Number);
|
2010-03-13 15:40:56 +08:00
|
|
|
Asm->OutStreamer.EmitSymbolValue(FuncBeginSym,
|
2010-04-05 08:13:49 +08:00
|
|
|
Asm->getTargetData().getPointerSize(),
|
|
|
|
0/*AddrSpace*/);
|
2010-07-22 05:21:52 +08:00
|
|
|
|
|
|
|
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("FDE address range");
|
2010-04-05 03:58:12 +08:00
|
|
|
Asm->EmitLabelDifference(Asm->GetTempSymbol("func_end",DebugFrameInfo.Number),
|
2010-04-05 08:13:49 +08:00
|
|
|
FuncBeginSym, Asm->getTargetData().getPointerSize());
|
2009-05-21 07:19:06 +08:00
|
|
|
|
2010-04-05 07:41:46 +08:00
|
|
|
Asm->EmitFrameMoves(DebugFrameInfo.Moves, FuncBeginSym, false);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-04-28 09:05:45 +08:00
|
|
|
Asm->EmitAlignment(2);
|
2010-03-13 15:26:18 +08:00
|
|
|
Asm->OutStreamer.EmitLabel(DebugFrameEnd);
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-12-10 02:24:21 +08:00
|
|
|
/// emitDebugPubNames - Emit visible names into a debug pubnames section.
|
|
|
|
///
|
|
|
|
void DwarfDebug::emitDebugPubNames() {
|
2010-05-11 06:49:55 +08:00
|
|
|
for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
|
|
|
|
E = CUMap.end(); I != E; ++I) {
|
|
|
|
CompileUnit *TheCU = I->second;
|
|
|
|
// Start the dwarf pubnames section.
|
|
|
|
Asm->OutStreamer.SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfPubNamesSection());
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-11 06:49:55 +08:00
|
|
|
Asm->OutStreamer.AddComment("Length of Public Names Info");
|
|
|
|
Asm->EmitLabelDifference(
|
|
|
|
Asm->GetTempSymbol("pubnames_end", TheCU->getID()),
|
|
|
|
Asm->GetTempSymbol("pubnames_begin", TheCU->getID()), 4);
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-11 06:49:55 +08:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubnames_begin",
|
|
|
|
TheCU->getID()));
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-11 06:49:55 +08:00
|
|
|
Asm->OutStreamer.AddComment("DWARF Version");
|
2010-07-22 05:21:52 +08:00
|
|
|
Asm->EmitInt16(dwarf::DWARF_VERSION);
|
|
|
|
|
2010-05-11 06:49:55 +08:00
|
|
|
Asm->OutStreamer.AddComment("Offset of Compilation Unit Info");
|
2010-07-22 05:21:52 +08:00
|
|
|
Asm->EmitSectionOffset(Asm->GetTempSymbol("info_begin", TheCU->getID()),
|
2010-05-11 06:49:55 +08:00
|
|
|
DwarfInfoSectionSym);
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-11 06:49:55 +08:00
|
|
|
Asm->OutStreamer.AddComment("Compilation Unit Length");
|
|
|
|
Asm->EmitLabelDifference(Asm->GetTempSymbol("info_end", TheCU->getID()),
|
|
|
|
Asm->GetTempSymbol("info_begin", TheCU->getID()),
|
|
|
|
4);
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-11 06:49:55 +08:00
|
|
|
const StringMap<DIE*> &Globals = TheCU->getGlobals();
|
|
|
|
for (StringMap<DIE*>::const_iterator
|
|
|
|
GI = Globals.begin(), GE = Globals.end(); GI != GE; ++GI) {
|
|
|
|
const char *Name = GI->getKeyData();
|
|
|
|
DIE *Entity = GI->second;
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-11 06:49:55 +08:00
|
|
|
Asm->OutStreamer.AddComment("DIE offset");
|
|
|
|
Asm->EmitInt32(Entity->getOffset());
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-11 06:49:55 +08:00
|
|
|
if (Asm->isVerbose())
|
|
|
|
Asm->OutStreamer.AddComment("External Name");
|
|
|
|
Asm->OutStreamer.EmitBytes(StringRef(Name, strlen(Name)+1), 0);
|
|
|
|
}
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-11 06:49:55 +08:00
|
|
|
Asm->OutStreamer.AddComment("End Mark");
|
|
|
|
Asm->EmitInt32(0);
|
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubnames_end",
|
|
|
|
TheCU->getID()));
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-24 09:14:22 +08:00
|
|
|
void DwarfDebug::emitDebugPubTypes() {
|
2010-05-11 06:49:55 +08:00
|
|
|
for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
|
|
|
|
E = CUMap.end(); I != E; ++I) {
|
|
|
|
CompileUnit *TheCU = I->second;
|
|
|
|
// Start the dwarf pubnames section.
|
|
|
|
Asm->OutStreamer.SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfPubTypesSection());
|
|
|
|
Asm->OutStreamer.AddComment("Length of Public Types Info");
|
|
|
|
Asm->EmitLabelDifference(
|
|
|
|
Asm->GetTempSymbol("pubtypes_end", TheCU->getID()),
|
|
|
|
Asm->GetTempSymbol("pubtypes_begin", TheCU->getID()), 4);
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-11 06:49:55 +08:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubtypes_begin",
|
|
|
|
TheCU->getID()));
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-11 06:49:55 +08:00
|
|
|
if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DWARF Version");
|
|
|
|
Asm->EmitInt16(dwarf::DWARF_VERSION);
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-11 06:49:55 +08:00
|
|
|
Asm->OutStreamer.AddComment("Offset of Compilation Unit Info");
|
|
|
|
Asm->EmitSectionOffset(Asm->GetTempSymbol("info_begin", TheCU->getID()),
|
|
|
|
DwarfInfoSectionSym);
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-11 06:49:55 +08:00
|
|
|
Asm->OutStreamer.AddComment("Compilation Unit Length");
|
|
|
|
Asm->EmitLabelDifference(Asm->GetTempSymbol("info_end", TheCU->getID()),
|
|
|
|
Asm->GetTempSymbol("info_begin", TheCU->getID()),
|
|
|
|
4);
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-11 06:49:55 +08:00
|
|
|
const StringMap<DIE*> &Globals = TheCU->getGlobalTypes();
|
|
|
|
for (StringMap<DIE*>::const_iterator
|
|
|
|
GI = Globals.begin(), GE = Globals.end(); GI != GE; ++GI) {
|
|
|
|
const char *Name = GI->getKeyData();
|
|
|
|
DIE * Entity = GI->second;
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-11 06:49:55 +08:00
|
|
|
if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DIE offset");
|
|
|
|
Asm->EmitInt32(Entity->getOffset());
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-11 06:49:55 +08:00
|
|
|
if (Asm->isVerbose()) Asm->OutStreamer.AddComment("External Name");
|
|
|
|
Asm->OutStreamer.EmitBytes(StringRef(Name, GI->getKeyLength()+1), 0);
|
|
|
|
}
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-05-11 06:49:55 +08:00
|
|
|
Asm->OutStreamer.AddComment("End Mark");
|
2010-07-22 05:21:52 +08:00
|
|
|
Asm->EmitInt32(0);
|
2010-05-11 06:49:55 +08:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubtypes_end",
|
|
|
|
TheCU->getID()));
|
2009-11-24 09:14:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// emitDebugStr - Emit visible names into a debug str section.
|
2009-05-21 07:21:38 +08:00
|
|
|
///
|
2009-11-21 10:48:08 +08:00
|
|
|
void DwarfDebug::emitDebugStr() {
|
2009-05-21 07:21:38 +08:00
|
|
|
// Check to see if it is worth the effort.
|
2010-03-10 07:38:23 +08:00
|
|
|
if (StringPool.empty()) return;
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-03-10 07:38:23 +08:00
|
|
|
// Start the dwarf str section.
|
|
|
|
Asm->OutStreamer.SwitchSection(
|
2009-08-19 13:49:37 +08:00
|
|
|
Asm->getObjFileLowering().getDwarfStrSection());
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-03-13 10:17:42 +08:00
|
|
|
// Get all of the string pool entries and put them in an array by their ID so
|
|
|
|
// we can sort them.
|
2010-07-22 05:21:52 +08:00
|
|
|
SmallVector<std::pair<unsigned,
|
2010-03-13 10:17:42 +08:00
|
|
|
StringMapEntry<std::pair<MCSymbol*, unsigned> >*>, 64> Entries;
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-03-13 10:17:42 +08:00
|
|
|
for (StringMap<std::pair<MCSymbol*, unsigned> >::iterator
|
|
|
|
I = StringPool.begin(), E = StringPool.end(); I != E; ++I)
|
|
|
|
Entries.push_back(std::make_pair(I->second.second, &*I));
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-03-13 10:17:42 +08:00
|
|
|
array_pod_sort(Entries.begin(), Entries.end());
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-03-13 10:17:42 +08:00
|
|
|
for (unsigned i = 0, e = Entries.size(); i != e; ++i) {
|
2010-03-10 07:38:23 +08:00
|
|
|
// Emit a label for reference from debug information entries.
|
2010-03-13 10:17:42 +08:00
|
|
|
Asm->OutStreamer.EmitLabel(Entries[i].second->getValue().first);
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2010-03-10 07:38:23 +08:00
|
|
|
// Emit the string itself.
|
2010-03-13 10:17:42 +08:00
|
|
|
Asm->OutStreamer.EmitBytes(Entries[i].second->getKey(), 0/*addrspace*/);
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// emitDebugLoc - Emit visible names into a debug loc section.
|
2009-05-21 07:21:38 +08:00
|
|
|
///
|
2009-11-21 10:48:08 +08:00
|
|
|
void DwarfDebug::emitDebugLoc() {
|
2010-05-27 07:55:23 +08:00
|
|
|
if (DotDebugLocEntries.empty())
|
|
|
|
return;
|
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Start the dwarf loc section.
|
2009-08-19 13:49:37 +08:00
|
|
|
Asm->OutStreamer.SwitchSection(
|
2010-05-26 07:40:22 +08:00
|
|
|
Asm->getObjFileLowering().getDwarfLocSection());
|
|
|
|
unsigned char Size = Asm->getTargetData().getPointerSize();
|
2010-05-27 07:55:23 +08:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_loc", 0));
|
|
|
|
unsigned index = 1;
|
2010-07-22 05:21:52 +08:00
|
|
|
for (SmallVector<DotDebugLocEntry, 4>::iterator
|
|
|
|
I = DotDebugLocEntries.begin(), E = DotDebugLocEntries.end();
|
2010-07-08 04:12:52 +08:00
|
|
|
I != E; ++I, ++index) {
|
2010-05-26 07:40:22 +08:00
|
|
|
DotDebugLocEntry Entry = *I;
|
|
|
|
if (Entry.isEmpty()) {
|
|
|
|
Asm->OutStreamer.EmitIntValue(0, Size, /*addrspace*/0);
|
|
|
|
Asm->OutStreamer.EmitIntValue(0, Size, /*addrspace*/0);
|
2010-05-27 07:55:23 +08:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_loc", index));
|
2010-05-26 07:40:22 +08:00
|
|
|
} else {
|
|
|
|
Asm->OutStreamer.EmitSymbolValue(Entry.Begin, Size, 0);
|
|
|
|
Asm->OutStreamer.EmitSymbolValue(Entry.End, Size, 0);
|
|
|
|
const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo();
|
|
|
|
unsigned Reg = RI->getDwarfRegNum(Entry.Loc.getReg(), false);
|
2010-08-05 02:40:52 +08:00
|
|
|
if (int Offset = Entry.Loc.getOffset()) {
|
|
|
|
// If the value is at a certain offset from frame register then
|
|
|
|
// use DW_OP_fbreg.
|
|
|
|
unsigned OffsetSize = Offset ? MCAsmInfo::getSLEB128Size(Offset) : 1;
|
2010-05-26 07:40:22 +08:00
|
|
|
Asm->OutStreamer.AddComment("Loc expr size");
|
2010-08-05 02:40:52 +08:00
|
|
|
Asm->EmitInt16(1 + OffsetSize);
|
|
|
|
Asm->OutStreamer.AddComment(
|
|
|
|
dwarf::OperationEncodingString(dwarf::DW_OP_fbreg));
|
|
|
|
Asm->EmitInt8(dwarf::DW_OP_fbreg);
|
|
|
|
Asm->OutStreamer.AddComment("Offset");
|
|
|
|
Asm->EmitSLEB128(Offset);
|
2010-05-26 07:40:22 +08:00
|
|
|
} else {
|
2010-08-05 02:40:52 +08:00
|
|
|
if (Reg < 32) {
|
|
|
|
Asm->OutStreamer.AddComment("Loc expr size");
|
|
|
|
Asm->EmitInt16(1);
|
|
|
|
Asm->OutStreamer.AddComment(
|
2010-08-05 04:32:36 +08:00
|
|
|
dwarf::OperationEncodingString(dwarf::DW_OP_reg0 + Reg));
|
2010-08-05 02:40:52 +08:00
|
|
|
Asm->EmitInt8(dwarf::DW_OP_reg0 + Reg);
|
|
|
|
} else {
|
|
|
|
Asm->OutStreamer.AddComment("Loc expr size");
|
|
|
|
Asm->EmitInt16(1 + MCAsmInfo::getULEB128Size(Reg));
|
|
|
|
Asm->EmitInt8(dwarf::DW_OP_regx);
|
|
|
|
Asm->EmitULEB128(Reg);
|
|
|
|
}
|
2010-05-26 07:40:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
/// EmitDebugARanges - Emit visible names into a debug aranges section.
|
|
|
|
///
|
|
|
|
void DwarfDebug::EmitDebugARanges() {
|
|
|
|
// Start the dwarf aranges section.
|
2009-08-19 13:49:37 +08:00
|
|
|
Asm->OutStreamer.SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfARangesSection());
|
2009-05-21 07:04:56 +08:00
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// emitDebugRanges - Emit visible names into a debug ranges section.
|
2009-05-21 07:21:38 +08:00
|
|
|
///
|
2009-11-21 10:48:08 +08:00
|
|
|
void DwarfDebug::emitDebugRanges() {
|
2009-05-21 07:21:38 +08:00
|
|
|
// Start the dwarf ranges section.
|
2009-08-19 13:49:37 +08:00
|
|
|
Asm->OutStreamer.SwitchSection(
|
2010-04-17 07:33:45 +08:00
|
|
|
Asm->getObjFileLowering().getDwarfRangesSection());
|
2010-04-28 03:46:33 +08:00
|
|
|
unsigned char Size = Asm->getTargetData().getPointerSize();
|
|
|
|
for (SmallVector<const MCSymbol *, 8>::iterator
|
2010-07-22 05:21:52 +08:00
|
|
|
I = DebugRangeSymbols.begin(), E = DebugRangeSymbols.end();
|
2010-04-28 03:46:33 +08:00
|
|
|
I != E; ++I) {
|
|
|
|
if (*I)
|
|
|
|
Asm->OutStreamer.EmitSymbolValue(const_cast<MCSymbol*>(*I), Size, 0);
|
2010-04-17 07:33:45 +08:00
|
|
|
else
|
2010-04-28 03:46:33 +08:00
|
|
|
Asm->OutStreamer.EmitIntValue(0, Size, /*addrspace*/0);
|
2010-04-17 07:33:45 +08:00
|
|
|
}
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// emitDebugMacInfo - Emit visible names into a debug macinfo section.
|
2009-05-21 07:21:38 +08:00
|
|
|
///
|
2009-11-21 10:48:08 +08:00
|
|
|
void DwarfDebug::emitDebugMacInfo() {
|
2009-09-20 04:40:05 +08:00
|
|
|
if (const MCSection *LineInfo =
|
2009-08-02 15:24:22 +08:00
|
|
|
Asm->getObjFileLowering().getDwarfMacroInfoSection()) {
|
2009-05-21 07:21:38 +08:00
|
|
|
// Start the dwarf macinfo section.
|
2009-08-19 13:49:37 +08:00
|
|
|
Asm->OutStreamer.SwitchSection(LineInfo);
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-21 10:48:08 +08:00
|
|
|
/// emitDebugInlineInfo - Emit inline info using following format.
|
2009-05-21 07:21:38 +08:00
|
|
|
/// Section Header:
|
|
|
|
/// 1. length of section
|
|
|
|
/// 2. Dwarf version number
|
|
|
|
/// 3. address size.
|
|
|
|
///
|
|
|
|
/// Entries (one "entry" for each function that was inlined):
|
|
|
|
///
|
|
|
|
/// 1. offset into __debug_str section for MIPS linkage name, if exists;
|
|
|
|
/// otherwise offset into __debug_str for regular function name.
|
|
|
|
/// 2. offset into __debug_str section for regular function name.
|
|
|
|
/// 3. an unsigned LEB128 number indicating the number of distinct inlining
|
|
|
|
/// instances for the function.
|
|
|
|
///
|
|
|
|
/// The rest of the entry consists of a {die_offset, low_pc} pair for each
|
|
|
|
/// inlined instance; the die_offset points to the inlined_subroutine die in the
|
|
|
|
/// __debug_info section, and the low_pc is the starting address for the
|
|
|
|
/// inlining instance.
|
2009-11-21 10:48:08 +08:00
|
|
|
void DwarfDebug::emitDebugInlineInfo() {
|
2010-04-05 08:13:49 +08:00
|
|
|
if (!Asm->MAI->doesDwarfUsesInlineInfoSection())
|
2009-05-21 07:21:38 +08:00
|
|
|
return;
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-05-11 06:49:55 +08:00
|
|
|
if (!FirstCU)
|
2009-05-21 07:21:38 +08:00
|
|
|
return;
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-08-19 13:49:37 +08:00
|
|
|
Asm->OutStreamer.SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfDebugInlineSection());
|
2010-01-23 06:09:00 +08:00
|
|
|
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("Length of Debug Inlined Information Entry");
|
2010-04-05 03:58:12 +08:00
|
|
|
Asm->EmitLabelDifference(Asm->GetTempSymbol("debug_inlined_end", 1),
|
|
|
|
Asm->GetTempSymbol("debug_inlined_begin", 1), 4);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-04-05 03:25:43 +08:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_inlined_begin", 1));
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("Dwarf Version");
|
|
|
|
Asm->EmitInt16(dwarf::DWARF_VERSION);
|
|
|
|
Asm->OutStreamer.AddComment("Address Size (in bytes)");
|
2010-04-05 08:13:49 +08:00
|
|
|
Asm->EmitInt8(Asm->getTargetData().getPointerSize());
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-05-08 04:54:48 +08:00
|
|
|
for (SmallVector<const MDNode *, 4>::iterator I = InlinedSPNodes.begin(),
|
2009-11-11 07:06:00 +08:00
|
|
|
E = InlinedSPNodes.end(); I != E; ++I) {
|
2009-11-22 07:12:12 +08:00
|
|
|
|
2010-05-08 04:54:48 +08:00
|
|
|
const MDNode *Node = *I;
|
|
|
|
DenseMap<const MDNode *, SmallVector<InlineInfoLabels, 4> >::iterator II
|
2009-11-23 03:20:36 +08:00
|
|
|
= InlineInfo.find(Node);
|
2009-11-11 07:06:00 +08:00
|
|
|
SmallVector<InlineInfoLabels, 4> &Labels = II->second;
|
2009-08-29 07:24:31 +08:00
|
|
|
DISubprogram SP(Node);
|
2009-11-26 01:36:49 +08:00
|
|
|
StringRef LName = SP.getLinkageName();
|
|
|
|
StringRef Name = SP.getName();
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("MIPS linkage name");
|
2010-01-23 11:11:46 +08:00
|
|
|
if (LName.empty()) {
|
|
|
|
Asm->OutStreamer.EmitBytes(Name, 0);
|
|
|
|
Asm->OutStreamer.EmitIntValue(0, 1, 0); // nul terminator.
|
2010-07-22 05:21:52 +08:00
|
|
|
} else
|
2010-04-05 07:25:33 +08:00
|
|
|
Asm->EmitSectionOffset(getStringPoolEntry(getRealLinkageName(LName)),
|
|
|
|
DwarfStrSectionSym);
|
2009-11-11 07:06:00 +08:00
|
|
|
|
2010-03-10 07:52:58 +08:00
|
|
|
Asm->OutStreamer.AddComment("Function name");
|
2010-04-05 07:25:33 +08:00
|
|
|
Asm->EmitSectionOffset(getStringPoolEntry(Name), DwarfStrSectionSym);
|
2010-04-05 03:09:29 +08:00
|
|
|
Asm->EmitULEB128(Labels.size(), "Inline count");
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2009-11-11 07:06:00 +08:00
|
|
|
for (SmallVector<InlineInfoLabels, 4>::iterator LI = Labels.begin(),
|
2009-05-21 07:21:38 +08:00
|
|
|
LE = Labels.end(); LI != LE; ++LI) {
|
2010-04-05 02:52:31 +08:00
|
|
|
if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DIE offset");
|
2010-03-09 08:31:02 +08:00
|
|
|
Asm->EmitInt32(LI->second->getOffset());
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2010-04-05 02:52:31 +08:00
|
|
|
if (Asm->isVerbose()) Asm->OutStreamer.AddComment("low_pc");
|
2010-04-05 08:13:49 +08:00
|
|
|
Asm->OutStreamer.EmitSymbolValue(LI->first,
|
|
|
|
Asm->getTargetData().getPointerSize(),0);
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
|
|
|
}
|
2009-05-21 07:19:06 +08:00
|
|
|
|
2010-04-05 03:25:43 +08:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_inlined_end", 1));
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|