DwarfDebug.h revision bf47fdb91c3bc7c26fb7eb6096ca3657c69bd26f
13ed852eea50f9d4cd633efb8c2b054b8e33c253cristy//===-- llvm/CodeGen/DwarfDebug.h - Dwarf Debug Framework ------*- C++ -*--===// 23ed852eea50f9d4cd633efb8c2b054b8e33c253cristy// 33ed852eea50f9d4cd633efb8c2b054b8e33c253cristy// The LLVM Compiler Infrastructure 43ed852eea50f9d4cd633efb8c2b054b8e33c253cristy// 53ed852eea50f9d4cd633efb8c2b054b8e33c253cristy// This file is distributed under the University of Illinois Open Source 63ed852eea50f9d4cd633efb8c2b054b8e33c253cristy// License. See LICENSE.TXT for details. 73ed852eea50f9d4cd633efb8c2b054b8e33c253cristy// 83ed852eea50f9d4cd633efb8c2b054b8e33c253cristy//===----------------------------------------------------------------------===// 93ed852eea50f9d4cd633efb8c2b054b8e33c253cristy// 103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy// This file contains support for writing dwarf debug info into asm files. 113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy// 123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy//===----------------------------------------------------------------------===// 133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#ifndef CODEGEN_ASMPRINTER_DWARFDEBUG_H__ 153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define CODEGEN_ASMPRINTER_DWARFDEBUG_H__ 163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "llvm/CodeGen/AsmPrinter.h" 183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "llvm/CodeGen/LexicalScopes.h" 193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "llvm/MC/MachineLocation.h" 2045ef08fd6a09813e4a8f5ddadf85ba9e0ec2cdc7cristy#include "llvm/Analysis/DebugInfo.h" 213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "DIE.h" 223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "llvm/ADT/DenseMap.h" 233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "llvm/ADT/FoldingSet.h" 243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "llvm/ADT/SmallPtrSet.h" 253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "llvm/ADT/StringMap.h" 263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "llvm/ADT/UniqueVector.h" 273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "llvm/Support/Allocator.h" 283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "llvm/Support/DebugLoc.h" 293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 303ed852eea50f9d4cd633efb8c2b054b8e33c253cristynamespace llvm { 313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 323ed852eea50f9d4cd633efb8c2b054b8e33c253cristyclass CompileUnit; 333ed852eea50f9d4cd633efb8c2b054b8e33c253cristyclass DbgConcreteScope; 343ed852eea50f9d4cd633efb8c2b054b8e33c253cristyclass DbgVariable; 353ed852eea50f9d4cd633efb8c2b054b8e33c253cristyclass MachineFrameInfo; 363ed852eea50f9d4cd633efb8c2b054b8e33c253cristyclass MachineModuleInfo; 373ed852eea50f9d4cd633efb8c2b054b8e33c253cristyclass MachineOperand; 383ed852eea50f9d4cd633efb8c2b054b8e33c253cristyclass MCAsmInfo; 393ed852eea50f9d4cd633efb8c2b054b8e33c253cristyclass DIEAbbrev; 403ed852eea50f9d4cd633efb8c2b054b8e33c253cristyclass DIE; 413ed852eea50f9d4cd633efb8c2b054b8e33c253cristyclass DIEBlock; 424c08aed51c5899665ade97263692328eea4af106cristyclass DIEEntry; 434c08aed51c5899665ade97263692328eea4af106cristy 4476ce6e193e5a305875173a744bbd59d27ddb3148cristy//===----------------------------------------------------------------------===// 454c08aed51c5899665ade97263692328eea4af106cristy/// SrcLineInfo - This class is used to record source line correspondence. 464c08aed51c5899665ade97263692328eea4af106cristy/// 478a3ce7f37eeb9deabe9134cb75cd69e7dae75301cristyclass SrcLineInfo { 484c08aed51c5899665ade97263692328eea4af106cristy unsigned Line; // Source line number. 498a3ce7f37eeb9deabe9134cb75cd69e7dae75301cristy unsigned Column; // Source column. 504c08aed51c5899665ade97263692328eea4af106cristy unsigned SourceID; // Source ID number. 514c08aed51c5899665ade97263692328eea4af106cristy MCSymbol *Label; // Label in code ID number. 524c08aed51c5899665ade97263692328eea4af106cristypublic: 534c08aed51c5899665ade97263692328eea4af106cristy SrcLineInfo(unsigned L, unsigned C, unsigned S, MCSymbol *label) 544c08aed51c5899665ade97263692328eea4af106cristy : Line(L), Column(C), SourceID(S), Label(label) {} 554c08aed51c5899665ade97263692328eea4af106cristy 564c08aed51c5899665ade97263692328eea4af106cristy // Accessors 578a3ce7f37eeb9deabe9134cb75cd69e7dae75301cristy unsigned getLine() const { return Line; } 584c08aed51c5899665ade97263692328eea4af106cristy unsigned getColumn() const { return Column; } 594c08aed51c5899665ade97263692328eea4af106cristy unsigned getSourceID() const { return SourceID; } 604c08aed51c5899665ade97263692328eea4af106cristy MCSymbol *getLabel() const { return Label; } 614c08aed51c5899665ade97263692328eea4af106cristy}; 624c08aed51c5899665ade97263692328eea4af106cristy 638a3ce7f37eeb9deabe9134cb75cd69e7dae75301cristy/// DotDebugLocEntry - This struct describes location entries emitted in 648a3ce7f37eeb9deabe9134cb75cd69e7dae75301cristy/// .debug_loc section. 653ed852eea50f9d4cd633efb8c2b054b8e33c253cristytypedef struct DotDebugLocEntry { 663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy const MCSymbol *Begin; 673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy const MCSymbol *End; 683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MachineLocation Loc; 693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy const MDNode *Variable; 703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy bool Merged; 713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy bool Constant; 723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy enum EntryType { 733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy E_Location, 743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy E_Integer, 753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy E_ConstantFP, 763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy E_ConstantInt 773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy }; 783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy enum EntryType EntryKind; 793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy union { 813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy int64_t Int; 823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy const ConstantFP *CFP; 833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy const ConstantInt *CIP; 843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } Constants; 853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy DotDebugLocEntry() 863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy : Begin(0), End(0), Variable(0), Merged(false), 873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Constant(false) { Constants.Int = 0;} 883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, MachineLocation &L, 893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy const MDNode *V) 903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy : Begin(B), End(E), Loc(L), Variable(V), Merged(false), 913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Constant(false) { Constants.Int = 0; EntryKind = E_Location; } 923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, int64_t i) 933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy : Begin(B), End(E), Variable(0), Merged(false), 943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Constant(true) { Constants.Int = i; EntryKind = E_Integer; } 953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, const ConstantFP *FPtr) 963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy : Begin(B), End(E), Variable(0), Merged(false), 973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Constant(true) { Constants.CFP = FPtr; EntryKind = E_ConstantFP; } 983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, const ConstantInt *IPtr) 9954ec42737fdec7527afa06ca95be82c8ca0bd866cristy : Begin(B), End(E), Variable(0), Merged(false), 10054ec42737fdec7527afa06ca95be82c8ca0bd866cristy Constant(true) { Constants.CIP = IPtr; EntryKind = E_ConstantInt; } 1013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// Empty entries are also used as a trigger to emit temp label. Such 103ab272ac4f115daf25c032de9dbb49a399eebe49bcristy /// labels are referenced is used to find debug_loc offset for a given DIE. 104ab272ac4f115daf25c032de9dbb49a399eebe49bcristy bool isEmpty() { return Begin == 0 && End == 0; } 1053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy bool isMerged() { return Merged; } 1063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy void Merge(DotDebugLocEntry *Next) { 1073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy if (!(Begin && Loc == Next->Loc && End == Next->Begin)) 1083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy return; 1093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Next->Begin = Begin; 1103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy Merged = true; 1113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 1123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy bool isLocation() const { return EntryKind == E_Location; } 1133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy bool isInt() const { return EntryKind == E_Integer; } 1143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy bool isConstantFP() const { return EntryKind == E_ConstantFP; } 115bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy bool isConstantInt() const { return EntryKind == E_ConstantInt; } 1163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy int64_t getInt() { return Constants.Int; } 1173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy const ConstantFP *getConstantFP() { return Constants.CFP; } 118bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy const ConstantInt *getConstantInt() { return Constants.CIP; } 1193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} DotDebugLocEntry; 1203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy//===----------------------------------------------------------------------===// 1224e82e51d7ebce7b4ef0f808d906124dd6f812248cristy/// DbgVariable - This class is used to track local variable information. 1234e82e51d7ebce7b4ef0f808d906124dd6f812248cristy/// 1244e82e51d7ebce7b4ef0f808d906124dd6f812248cristyclass DbgVariable { 1253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy DIVariable Var; // Variable Descriptor. 1263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy DIE *TheDIE; // Variable DIE. 1273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned DotDebugLocOffset; // Offset in DotDebugLocEntries. 1283ed852eea50f9d4cd633efb8c2b054b8e33c253cristypublic: 1293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy // AbsVar may be NULL. 1303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy DbgVariable(DIVariable V) : Var(V), TheDIE(0), DotDebugLocOffset(~0U) {} 1313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 1323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy // Accessors. 1333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy DIVariable getVariable() const { return Var; } 1343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy void setDIE(DIE *D) { TheDIE = D; } 1359950d57e1124b73f684fb5946e206994cefda628cristy DIE *getDIE() const { return TheDIE; } 1363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy void setDotDebugLocOffset(unsigned O) { DotDebugLocOffset = O; } 1373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned getDotDebugLocOffset() const { return DotDebugLocOffset; } 1383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy StringRef getName() const { return Var.getName(); } 1393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned getTag() const { return Var.getTag(); } 140092ec8d083fedaedfb7792995e7ea42164553cffcristy bool variableHasComplexAddress() const { 141ab272ac4f115daf25c032de9dbb49a399eebe49bcristy assert(Var.Verify() && "Invalid complex DbgVariable!"); 142e67f43f8af5feb0f08d04b14dce7ccc162973715cristy return Var.hasComplexAddress(); 143e67f43f8af5feb0f08d04b14dce7ccc162973715cristy } 144ab272ac4f115daf25c032de9dbb49a399eebe49bcristy bool isBlockByrefVariable() const { 145ab272ac4f115daf25c032de9dbb49a399eebe49bcristy assert(Var.Verify() && "Invalid complex DbgVariable!"); 146e67f43f8af5feb0f08d04b14dce7ccc162973715cristy return Var.isBlockByrefVariable(); 147e67f43f8af5feb0f08d04b14dce7ccc162973715cristy } 148ab272ac4f115daf25c032de9dbb49a399eebe49bcristy unsigned getNumAddrElements() const { 149e67f43f8af5feb0f08d04b14dce7ccc162973715cristy assert(Var.Verify() && "Invalid complex DbgVariable!"); 150e67f43f8af5feb0f08d04b14dce7ccc162973715cristy return Var.getNumAddrElements(); 151d15e65928aec551b7388c2863de3e3e628e2e0ddcristy } 1523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy uint64_t getAddrElement(unsigned i) const { 153d15e65928aec551b7388c2863de3e3e628e2e0ddcristy return Var.getAddrElement(i); 1543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy } 1556fc392931fb03ddff4853716af6d51e329f59696cristy DIType getType() const; 156092ec8d083fedaedfb7792995e7ea42164553cffcristy}; 1573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 158042ee78fa9004bf1ac6a95f09d9d1faca631dda1cristyclass DwarfDebug { 1593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// Asm - Target of Dwarf emission. 1608db9ca45d3b9861f5b18cdc760c8e8f0f157b270cristy AsmPrinter *Asm; 1618db9ca45d3b9861f5b18cdc760c8e8f0f157b270cristy 162e275ada1a7f4f90e73328c35e9f02464bafed8becristy /// MMI - Collected machine module information. 163e275ada1a7f4f90e73328c35e9f02464bafed8becristy MachineModuleInfo *MMI; 164e275ada1a7f4f90e73328c35e9f02464bafed8becristy 165e275ada1a7f4f90e73328c35e9f02464bafed8becristy //===--------------------------------------------------------------------===// 166e275ada1a7f4f90e73328c35e9f02464bafed8becristy // Attributes used to construct specific Dwarf sections. 167e275ada1a7f4f90e73328c35e9f02464bafed8becristy // 168e275ada1a7f4f90e73328c35e9f02464bafed8becristy 169e275ada1a7f4f90e73328c35e9f02464bafed8becristy CompileUnit *FirstCU; 170e275ada1a7f4f90e73328c35e9f02464bafed8becristy DenseMap <const MDNode *, CompileUnit *> CUMap; 171b712c6e549e8dbd76a125beb14182d41cc8027eecristy 172a492593efccb08b72392d64966b5c7728e56f16acristy /// AbbreviationsSet - Used to uniquely define abbreviations. 1738db9ca45d3b9861f5b18cdc760c8e8f0f157b270cristy /// 1748db9ca45d3b9861f5b18cdc760c8e8f0f157b270cristy FoldingSet<DIEAbbrev> AbbreviationsSet; 1758db9ca45d3b9861f5b18cdc760c8e8f0f157b270cristy 1768db9ca45d3b9861f5b18cdc760c8e8f0f157b270cristy /// Abbreviations - A list of all the unique abbreviations in use. 177e275ada1a7f4f90e73328c35e9f02464bafed8becristy /// 178e275ada1a7f4f90e73328c35e9f02464bafed8becristy std::vector<DIEAbbrev *> Abbreviations; 179e275ada1a7f4f90e73328c35e9f02464bafed8becristy 180e275ada1a7f4f90e73328c35e9f02464bafed8becristy /// SourceIdMap - Source id map, i.e. pair of directory id and source file 181e275ada1a7f4f90e73328c35e9f02464bafed8becristy /// id mapped to a unique id. 182e275ada1a7f4f90e73328c35e9f02464bafed8becristy StringMap<unsigned> SourceIdMap; 183e275ada1a7f4f90e73328c35e9f02464bafed8becristy 184e275ada1a7f4f90e73328c35e9f02464bafed8becristy /// StringPool - A String->Symbol mapping of strings used by indirect 185e275ada1a7f4f90e73328c35e9f02464bafed8becristy /// references. 186a492593efccb08b72392d64966b5c7728e56f16acristy StringMap<std::pair<MCSymbol*, unsigned> > StringPool; 18754ec42737fdec7527afa06ca95be82c8ca0bd866cristy unsigned NextStringPoolNumber; 18854ec42737fdec7527afa06ca95be82c8ca0bd866cristy 1898db9ca45d3b9861f5b18cdc760c8e8f0f157b270cristy MCSymbol *getStringPoolEntry(StringRef Str); 190a492593efccb08b72392d64966b5c7728e56f16acristy 1913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// SectionMap - Provides a unique id per text section. 192bdf24b20c5b02c773580a7b8cbf4ae8bb11ef994cristy /// 193bdf24b20c5b02c773580a7b8cbf4ae8bb11ef994cristy UniqueVector<const MCSection*> SectionMap; 194bdf24b20c5b02c773580a7b8cbf4ae8bb11ef994cristy 195bdf24b20c5b02c773580a7b8cbf4ae8bb11ef994cristy /// CurrentFnArguments - List of Arguments (DbgValues) for current function. 1963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy SmallVector<DbgVariable *, 8> CurrentFnArguments; 197bdf24b20c5b02c773580a7b8cbf4ae8bb11ef994cristy 1983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy LexicalScopes LScopes; 1998592b059b2b4f03c0280b0e1146b225207e624f8cristy 2003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// AbstractSPDies - Collection of abstract subprogram DIEs. 2013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy DenseMap<const MDNode *, DIE *> AbstractSPDies; 2029f92e3cee3ca2d153ccb77ee02fd27eed563021ecristy 2035cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy /// ScopeVariables - Collection of dbg variables of a scope. 2043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8> > ScopeVariables; 2053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 206b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy /// AbstractVariables - Collection on abstract variables. 2073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy DenseMap<const MDNode *, DbgVariable *> AbstractVariables; 2083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 2093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// DbgVariableToFrameIndexMap - Tracks frame index used to find 2105cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy /// variable's value. 211bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy DenseMap<const DbgVariable *, int> DbgVariableToFrameIndexMap; 2124e82e51d7ebce7b4ef0f808d906124dd6f812248cristy 21354ec42737fdec7527afa06ca95be82c8ca0bd866cristy /// DbgVariableToDbgInstMap - Maps DbgVariable to corresponding DBG_VALUE 2143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// machine instruction. 21554ec42737fdec7527afa06ca95be82c8ca0bd866cristy DenseMap<const DbgVariable *, const MachineInstr *> DbgVariableToDbgInstMap; 2168b235b2d0ea1bce8f9743d2d25bd6ddc9f72ff1dcristy 2173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// DotDebugLocEntries - Collection of DotDebugLocEntry. 2180839c55af3e04dec06756f60da81a58210557c29cristy SmallVector<DotDebugLocEntry, 4> DotDebugLocEntries; 219e275ada1a7f4f90e73328c35e9f02464bafed8becristy 2203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// UseDotDebugLocEntry - DW_AT_location attributes for the DIEs in this set 221bdf24b20c5b02c773580a7b8cbf4ae8bb11ef994cristy /// idetifies corresponding .debug_loc entry offset. 2223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy SmallPtrSet<const DIE *, 4> UseDotDebugLocEntry; 2239f92e3cee3ca2d153ccb77ee02fd27eed563021ecristy 2245cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy /// VarToAbstractVarMap - Maps DbgVariable with corresponding Abstract 2253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// DbgVariable, if any. 2263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy DenseMap<const DbgVariable *, const DbgVariable *> VarToAbstractVarMap; 227b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy 2283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// InliendSubprogramDIEs - Collection of subprgram DIEs that are marked 2293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// (at the end of the module) as DW_AT_inline. 2303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy SmallPtrSet<DIE *, 4> InlinedSubprogramDIEs; 2315cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy 232bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy /// ContainingTypeMap - This map is used to keep track of subprogram DIEs that 2334e82e51d7ebce7b4ef0f808d906124dd6f812248cristy /// need DW_AT_containing_type attribute. This attribute points to a DIE that 23442f5a6a8af8b1e4fd5f341e709c4d06778b8d85fcristy /// corresponds to the MDNode mapped with the subprogram DIE. 235bdf24b20c5b02c773580a7b8cbf4ae8bb11ef994cristy DenseMap<DIE *, const MDNode *> ContainingTypeMap; 236bdf24b20c5b02c773580a7b8cbf4ae8bb11ef994cristy 237bdf24b20c5b02c773580a7b8cbf4ae8bb11ef994cristy /// InlineInfo - Keep track of inlined functions and their location. This 2383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// information is used to populate debug_inlined section. 2396cd29479f50f920eb9e65e97ba682037204f7708cristy typedef std::pair<const MCSymbol *, DIE *> InlineInfoLabels; 24017386ff059907b275aeb762297179b2d26d95a33cristy DenseMap<const MDNode *, SmallVector<InlineInfoLabels, 4> > InlineInfo; 24117386ff059907b275aeb762297179b2d26d95a33cristy SmallVector<const MDNode *, 4> InlinedSPNodes; 2429f92e3cee3ca2d153ccb77ee02fd27eed563021ecristy 24317386ff059907b275aeb762297179b2d26d95a33cristy // ProcessedSPNodes - This is a collection of subprogram MDNodes that 24417386ff059907b275aeb762297179b2d26d95a33cristy // are processed to create DIEs. 24517386ff059907b275aeb762297179b2d26d95a33cristy SmallPtrSet<const MDNode *, 16> ProcessedSPNodes; 24617386ff059907b275aeb762297179b2d26d95a33cristy 24717386ff059907b275aeb762297179b2d26d95a33cristy /// LabelsBeforeInsn - Maps instruction with label emitted before 24817386ff059907b275aeb762297179b2d26d95a33cristy /// instruction. 24917386ff059907b275aeb762297179b2d26d95a33cristy DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn; 25017386ff059907b275aeb762297179b2d26d95a33cristy 25117386ff059907b275aeb762297179b2d26d95a33cristy /// LabelsAfterInsn - Maps instruction with label emitted after 25217386ff059907b275aeb762297179b2d26d95a33cristy /// instruction. 25317386ff059907b275aeb762297179b2d26d95a33cristy DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn; 25417386ff059907b275aeb762297179b2d26d95a33cristy 2556cd29479f50f920eb9e65e97ba682037204f7708cristy /// UserVariables - Every user variable mentioned by a DBG_VALUE instruction 25617386ff059907b275aeb762297179b2d26d95a33cristy /// in order of appearance. 257ec0bf4bde1f4ae360eaad31b98fb9ffe06d3b35dcristy SmallVector<const MDNode*, 8> UserVariables; 2583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 259a492593efccb08b72392d64966b5c7728e56f16acristy /// DbgValues - For each user variable, keep a list of DBG_VALUE 260a492593efccb08b72392d64966b5c7728e56f16acristy /// instructions in order. The list can also contain normal instructions that 261a492593efccb08b72392d64966b5c7728e56f16acristy /// clobber the previous DBG_VALUE. 262ea1a8aa04a9fe1500104284407c1cc06d20da699cristy typedef DenseMap<const MDNode*, SmallVector<const MachineInstr*, 4> > 26395524f92fc346f548f202d36ffc6a17fdbd1b1cbcristy DbgValueHistoryMap; 26495524f92fc346f548f202d36ffc6a17fdbd1b1cbcristy DbgValueHistoryMap DbgValues; 26595524f92fc346f548f202d36ffc6a17fdbd1b1cbcristy 26695524f92fc346f548f202d36ffc6a17fdbd1b1cbcristy SmallVector<const MCSymbol *, 8> DebugRangeSymbols; 2673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 2683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// Previous instruction's location information. This is used to determine 2693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// label location to indicate scope boundries in dwarf debug info. 2703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy DebugLoc PrevInstLoc; 2715cbc016effaa2d7ee617f46ca0a2371533d4ae17cristy MCSymbol *PrevLabel; 272024843f38984cd26602f0b3b28a0768dfa056bb5cristy 273024843f38984cd26602f0b3b28a0768dfa056bb5cristy /// PrologEndLoc - This location indicates end of function prologue and 274bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy /// beginning of function body. 2753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy DebugLoc PrologEndLoc; 2763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 277b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy struct FunctionDebugFrameInfo { 2783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned Number; 2793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy std::vector<MachineMove> Moves; 280024843f38984cd26602f0b3b28a0768dfa056bb5cristy 281024843f38984cd26602f0b3b28a0768dfa056bb5cristy FunctionDebugFrameInfo(unsigned Num, const std::vector<MachineMove> &M) 282024843f38984cd26602f0b3b28a0768dfa056bb5cristy : Number(Num), Moves(M) {} 283024843f38984cd26602f0b3b28a0768dfa056bb5cristy }; 284024843f38984cd26602f0b3b28a0768dfa056bb5cristy 2853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy std::vector<FunctionDebugFrameInfo> DebugFrames; 286ab272ac4f115daf25c032de9dbb49a399eebe49bcristy 2873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy // DIEValueAllocator - All DIEValues are allocated through this allocator. 2883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy BumpPtrAllocator DIEValueAllocator; 289ab272ac4f115daf25c032de9dbb49a399eebe49bcristy 290ab272ac4f115daf25c032de9dbb49a399eebe49bcristy // Section Symbols: these are assembler temporary labels that are emitted at 291ab272ac4f115daf25c032de9dbb49a399eebe49bcristy // the beginning of each supported dwarf section. These are used to form 292ab272ac4f115daf25c032de9dbb49a399eebe49bcristy // section offsets and are created by EmitSectionLabels. 293ab272ac4f115daf25c032de9dbb49a399eebe49bcristy MCSymbol *DwarfInfoSectionSym, *DwarfAbbrevSectionSym; 2943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MCSymbol *DwarfStrSectionSym, *TextSectionSym, *DwarfDebugRangeSectionSym; 2953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MCSymbol *DwarfDebugLocSectionSym; 2963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MCSymbol *FunctionBeginSym, *FunctionEndSym; 2973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 2983ed852eea50f9d4cd633efb8c2b054b8e33c253cristyprivate: 2993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// assignAbbrevNumber - Define a unique number for the abbreviation. 3013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// 3023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy void assignAbbrevNumber(DIEAbbrev &Abbrev); 3033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy void addScopeVariable(LexicalScope *LS, DbgVariable *Var); 3053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// findAbstractVariable - Find abstract variable associated with Var. 3073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy DbgVariable *findAbstractVariable(DIVariable &Var, DebugLoc Loc); 3083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// updateSubprogramScopeDIE - Find DIE for the given subprogram and 3103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// attach appropriate DW_AT_low_pc and DW_AT_high_pc attributes. 3113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// If there are global variables in this scope then create and insert 3123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// DIEs for these variables. 3133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy DIE *updateSubprogramScopeDIE(const MDNode *SPNode); 3143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// constructLexicalScope - Construct new DW_TAG_lexical_block 3163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// for this scope and attach DW_AT_low_pc/DW_AT_high_pc labels. 317bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy DIE *constructLexicalScopeDIE(LexicalScope *Scope); 3183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// constructInlinedScopeDIE - This scope represents inlined body of 320bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy /// a function. Construct DIE to represent this concrete inlined copy 3213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// of the function. 3223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy DIE *constructInlinedScopeDIE(LexicalScope *Scope); 3233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// constructVariableDIE - Construct a DIE for the given DbgVariable. 3253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy DIE *constructVariableDIE(DbgVariable *DV, LexicalScope *S); 3263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3278a3ce7f37eeb9deabe9134cb75cd69e7dae75301cristy /// constructScopeDIE - Construct a DIE for this scope. 3283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy DIE *constructScopeDIE(LexicalScope *Scope); 3293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// EmitSectionLabels - Emit initial Dwarf sections with a label at 3313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// the start of each one. 3323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy void EmitSectionLabels(); 3333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// emitDIE - Recusively Emits a debug information entry. 3353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// 3363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy void emitDIE(DIE *Die); 3373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// computeSizeAndOffset - Compute the size and offset of a DIE. 3393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// 3403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy unsigned computeSizeAndOffset(DIE *Die, unsigned Offset, bool Last); 3413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// computeSizeAndOffsets - Compute the size and offset of all the DIEs. 3433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// 3443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy void computeSizeAndOffsets(); 3453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// EmitDebugInfo - Emit the debug info section. 3473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// 3483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy void emitDebugInfo(); 3493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// emitAbbreviations - Emit the abbreviation section. 3513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// 3523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy void emitAbbreviations() const; 3533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 3543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// emitEndOfLineMatrix - Emit the last address of the section and the end of 3553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// the line matrix. 3563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy /// 357 void emitEndOfLineMatrix(unsigned SectionEnd); 358 359 /// emitDebugPubNames - Emit visible names into a debug pubnames section. 360 /// 361 void emitDebugPubNames(); 362 363 /// emitDebugPubTypes - Emit visible types into a debug pubtypes section. 364 /// 365 void emitDebugPubTypes(); 366 367 /// emitDebugStr - Emit visible names into a debug str section. 368 /// 369 void emitDebugStr(); 370 371 /// emitDebugLoc - Emit visible names into a debug loc section. 372 /// 373 void emitDebugLoc(); 374 375 /// EmitDebugARanges - Emit visible names into a debug aranges section. 376 /// 377 void EmitDebugARanges(); 378 379 /// emitDebugRanges - Emit visible names into a debug ranges section. 380 /// 381 void emitDebugRanges(); 382 383 /// emitDebugMacInfo - Emit visible names into a debug macinfo section. 384 /// 385 void emitDebugMacInfo(); 386 387 /// emitDebugInlineInfo - Emit inline info using following format. 388 /// Section Header: 389 /// 1. length of section 390 /// 2. Dwarf version number 391 /// 3. address size. 392 /// 393 /// Entries (one "entry" for each function that was inlined): 394 /// 395 /// 1. offset into __debug_str section for MIPS linkage name, if exists; 396 /// otherwise offset into __debug_str for regular function name. 397 /// 2. offset into __debug_str section for regular function name. 398 /// 3. an unsigned LEB128 number indicating the number of distinct inlining 399 /// instances for the function. 400 /// 401 /// The rest of the entry consists of a {die_offset, low_pc} pair for each 402 /// inlined instance; the die_offset points to the inlined_subroutine die in 403 /// the __debug_info section, and the low_pc is the starting address for the 404 /// inlining instance. 405 void emitDebugInlineInfo(); 406 407 /// constructCompileUnit - Create new CompileUnit for the given 408 /// metadata node with tag DW_TAG_compile_unit. 409 void constructCompileUnit(const MDNode *N); 410 411 /// getCompielUnit - Get CompileUnit DIE. 412 CompileUnit *getCompileUnit(const MDNode *N) const; 413 414 /// constructGlobalVariableDIE - Construct global variable DIE. 415 void constructGlobalVariableDIE(const MDNode *N); 416 417 /// construct SubprogramDIE - Construct subprogram DIE. 418 void constructSubprogramDIE(const MDNode *N); 419 420 /// recordSourceLine - Register a source line with debug info. Returns the 421 /// unique label that was emitted and which provides correspondence to 422 /// the source line list. 423 void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope, 424 unsigned Flags); 425 426 /// recordVariableFrameIndex - Record a variable's index. 427 void recordVariableFrameIndex(const DbgVariable *V, int Index); 428 429 /// findVariableFrameIndex - Return true if frame index for the variable 430 /// is found. Update FI to hold value of the index. 431 bool findVariableFrameIndex(const DbgVariable *V, int *FI); 432 433 /// identifyScopeMarkers() - Indentify instructions that are marking 434 /// beginning of or end of a scope. 435 void identifyScopeMarkers(); 436 437 /// addCurrentFnArgument - If Var is an current function argument that add 438 /// it in CurrentFnArguments list. 439 bool addCurrentFnArgument(const MachineFunction *MF, 440 DbgVariable *Var, LexicalScope *Scope); 441 442 /// collectVariableInfo - Populate LexicalScope entries with variables' info. 443 void collectVariableInfo(const MachineFunction *, 444 SmallPtrSet<const MDNode *, 16> &ProcessedVars); 445 446 /// collectVariableInfoFromMMITable - Collect variable information from 447 /// side table maintained by MMI. 448 void collectVariableInfoFromMMITable(const MachineFunction * MF, 449 SmallPtrSet<const MDNode *, 16> &P); 450 451 /// requestLabelBeforeInsn - Ensure that a label will be emitted before MI. 452 void requestLabelBeforeInsn(const MachineInstr *MI) { 453 LabelsBeforeInsn.insert(std::make_pair(MI, (MCSymbol*)0)); 454 } 455 456 /// getLabelBeforeInsn - Return Label preceding the instruction. 457 const MCSymbol *getLabelBeforeInsn(const MachineInstr *MI); 458 459 /// requestLabelAfterInsn - Ensure that a label will be emitted after MI. 460 void requestLabelAfterInsn(const MachineInstr *MI) { 461 LabelsAfterInsn.insert(std::make_pair(MI, (MCSymbol*)0)); 462 } 463 464 /// getLabelAfterInsn - Return Label immediately following the instruction. 465 const MCSymbol *getLabelAfterInsn(const MachineInstr *MI); 466 467public: 468 //===--------------------------------------------------------------------===// 469 // Main entry points. 470 // 471 DwarfDebug(AsmPrinter *A, Module *M); 472 ~DwarfDebug(); 473 474 /// beginModule - Emit all Dwarf sections that should come prior to the 475 /// content. 476 void beginModule(Module *M); 477 478 /// endModule - Emit all Dwarf sections that should come after the content. 479 /// 480 void endModule(); 481 482 /// beginFunction - Gather pre-function debug information. Assumes being 483 /// emitted immediately after the function entry point. 484 void beginFunction(const MachineFunction *MF); 485 486 /// endFunction - Gather and emit post-function debug information. 487 /// 488 void endFunction(const MachineFunction *MF); 489 490 /// beginInstruction - Process beginning of an instruction. 491 void beginInstruction(const MachineInstr *MI); 492 493 /// endInstruction - Prcess end of an instruction. 494 void endInstruction(const MachineInstr *MI); 495 496 /// GetOrCreateSourceID - Look up the source id with the given directory and 497 /// source file names. If none currently exists, create a new id and insert it 498 /// in the SourceIds map. 499 unsigned GetOrCreateSourceID(StringRef DirName, StringRef FullName); 500 501 /// createSubprogramDIE - Create new DIE using SP. 502 DIE *createSubprogramDIE(DISubprogram SP); 503}; 504} // End of namespace llvm 505 506#endif 507