Jim Laskey | e503289 | 2005-12-21 19:48:16 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/DwarfWriter.cpp - Dwarf Framework ----------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Jim Laskey | e503289 | 2005-12-21 19:48:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 10 | // This file contains support for writing dwarf info into asm files. |
Jim Laskey | e503289 | 2005-12-21 19:48:16 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
Jim Laskey | 3ea0e0e | 2006-01-27 18:32:41 +0000 | [diff] [blame] | 13 | |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 14 | #include "llvm/CodeGen/DwarfWriter.h" |
Jim Laskey | e503289 | 2005-12-21 19:48:16 +0000 | [diff] [blame] | 15 | |
Duncan Sands | 53c3a33 | 2007-05-16 12:12:23 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/DenseMap.h" |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/FoldingSet.h" |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/StringExtras.h" |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/UniqueVector.h" |
Jim Laskey | 52060a0 | 2006-01-24 00:49:18 +0000 | [diff] [blame] | 20 | #include "llvm/Module.h" |
Devang Patel | d1ca925 | 2009-01-05 23:03:32 +0000 | [diff] [blame] | 21 | #include "llvm/DerivedTypes.h" |
Devang Patel | cf3a448 | 2009-01-15 23:41:32 +0000 | [diff] [blame] | 22 | #include "llvm/Constants.h" |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/AsmPrinter.h" |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 26 | #include "llvm/CodeGen/MachineLocation.h" |
Devang Patel | 08f053f | 2009-01-05 17:57:47 +0000 | [diff] [blame] | 27 | #include "llvm/Analysis/DebugInfo.h" |
Jim Laskey | 3f09fc2 | 2007-02-28 18:38:31 +0000 | [diff] [blame] | 28 | #include "llvm/Support/Debug.h" |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 29 | #include "llvm/Support/Dwarf.h" |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 30 | #include "llvm/Support/CommandLine.h" |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 31 | #include "llvm/Support/DataTypes.h" |
Jim Laskey | 52060a0 | 2006-01-24 00:49:18 +0000 | [diff] [blame] | 32 | #include "llvm/Support/Mangler.h" |
Owen Anderson | cb37188 | 2008-08-21 00:14:44 +0000 | [diff] [blame] | 33 | #include "llvm/Support/raw_ostream.h" |
Dan Gohman | 8549636 | 2007-09-24 21:32:18 +0000 | [diff] [blame] | 34 | #include "llvm/System/Path.h" |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 35 | #include "llvm/Target/TargetAsmInfo.h" |
Dan Gohman | 6f0d024 | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 36 | #include "llvm/Target/TargetRegisterInfo.h" |
Owen Anderson | 07000c6 | 2006-05-12 06:33:49 +0000 | [diff] [blame] | 37 | #include "llvm/Target/TargetData.h" |
Jim Laskey | 1069fbd | 2006-04-10 23:09:19 +0000 | [diff] [blame] | 38 | #include "llvm/Target/TargetFrameInfo.h" |
Duncan Sands | 53c3a33 | 2007-05-16 12:12:23 +0000 | [diff] [blame] | 39 | #include "llvm/Target/TargetInstrInfo.h" |
Jim Laskey | 1b340dc | 2007-01-29 20:48:32 +0000 | [diff] [blame] | 40 | #include "llvm/Target/TargetMachine.h" |
Jim Laskey | c1c47c3 | 2007-01-29 23:40:33 +0000 | [diff] [blame] | 41 | #include "llvm/Target/TargetOptions.h" |
Bill Wendling | bdc679d | 2006-11-29 00:39:47 +0000 | [diff] [blame] | 42 | #include <ostream> |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 43 | #include <string> |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 44 | using namespace llvm; |
Jim Laskey | 9a777a3 | 2006-02-27 22:37:23 +0000 | [diff] [blame] | 45 | using namespace llvm::dwarf; |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 46 | |
Devang Patel | eb3fc28 | 2009-01-08 23:40:34 +0000 | [diff] [blame] | 47 | static RegisterPass<DwarfWriter> |
| 48 | X("dwarfwriter", "DWARF Information Writer"); |
| 49 | char DwarfWriter::ID = 0; |
| 50 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 51 | namespace llvm { |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 52 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 53 | //===----------------------------------------------------------------------===// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 54 | |
| 55 | /// Configuration values for initial hash set sizes (log2). |
| 56 | /// |
| 57 | static const unsigned InitDiesSetSize = 9; // 512 |
| 58 | static const unsigned InitAbbreviationsSetSize = 9; // 512 |
| 59 | static const unsigned InitValuesSetSize = 9; // 512 |
| 60 | |
| 61 | //===----------------------------------------------------------------------===// |
| 62 | /// Forward declarations. |
| 63 | /// |
| 64 | class DIE; |
| 65 | class DIEValue; |
| 66 | |
| 67 | //===----------------------------------------------------------------------===// |
Devang Patel | d1ca925 | 2009-01-05 23:03:32 +0000 | [diff] [blame] | 68 | /// Utility routines. |
| 69 | /// |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 70 | /// getGlobalVariablesUsing - Return all of the GlobalVariables which have the |
| 71 | /// specified value in their initializer somewhere. |
Devang Patel | d1ca925 | 2009-01-05 23:03:32 +0000 | [diff] [blame] | 72 | static void |
| 73 | getGlobalVariablesUsing(Value *V, std::vector<GlobalVariable*> &Result) { |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 74 | // Scan though value users. |
Devang Patel | d1ca925 | 2009-01-05 23:03:32 +0000 | [diff] [blame] | 75 | for (Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I) { |
| 76 | if (GlobalVariable *GV = dyn_cast<GlobalVariable>(*I)) { |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 77 | // If the user is a GlobalVariable then add to result. |
Devang Patel | d1ca925 | 2009-01-05 23:03:32 +0000 | [diff] [blame] | 78 | Result.push_back(GV); |
| 79 | } else if (Constant *C = dyn_cast<Constant>(*I)) { |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 80 | // If the user is a constant variable then scan its users. |
Devang Patel | d1ca925 | 2009-01-05 23:03:32 +0000 | [diff] [blame] | 81 | getGlobalVariablesUsing(C, Result); |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 86 | /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the |
| 87 | /// named GlobalVariable. |
Devang Patel | d1ca925 | 2009-01-05 23:03:32 +0000 | [diff] [blame] | 88 | static void |
| 89 | getGlobalVariablesUsing(Module &M, const std::string &RootName, |
| 90 | std::vector<GlobalVariable*> &Result) { |
| 91 | std::vector<const Type*> FieldTypes; |
| 92 | FieldTypes.push_back(Type::Int32Ty); |
| 93 | FieldTypes.push_back(Type::Int32Ty); |
| 94 | |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 95 | // Get the GlobalVariable root. |
Devang Patel | d1ca925 | 2009-01-05 23:03:32 +0000 | [diff] [blame] | 96 | GlobalVariable *UseRoot = M.getGlobalVariable(RootName, |
| 97 | StructType::get(FieldTypes)); |
| 98 | |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 99 | // If present and linkonce then scan for users. |
Devang Patel | d1ca925 | 2009-01-05 23:03:32 +0000 | [diff] [blame] | 100 | if (UseRoot && UseRoot->hasLinkOnceLinkage()) |
| 101 | getGlobalVariablesUsing(UseRoot, Result); |
| 102 | } |
| 103 | |
Devang Patel | cf3a448 | 2009-01-15 23:41:32 +0000 | [diff] [blame] | 104 | /// getGlobalVariable - Return either a direct or cast Global value. |
| 105 | /// |
| 106 | static GlobalVariable *getGlobalVariable(Value *V) { |
| 107 | if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) { |
| 108 | return GV; |
| 109 | } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) { |
| 110 | if (CE->getOpcode() == Instruction::BitCast) { |
| 111 | return dyn_cast<GlobalVariable>(CE->getOperand(0)); |
| 112 | } else if (CE->getOpcode() == Instruction::GetElementPtr) { |
| 113 | for (unsigned int i=1; i<CE->getNumOperands(); i++) { |
| 114 | if (!CE->getOperand(i)->isNullValue()) |
| 115 | return NULL; |
| 116 | } |
| 117 | return dyn_cast<GlobalVariable>(CE->getOperand(0)); |
| 118 | } |
| 119 | } |
| 120 | return NULL; |
| 121 | } |
| 122 | |
Devang Patel | d1ca925 | 2009-01-05 23:03:32 +0000 | [diff] [blame] | 123 | //===----------------------------------------------------------------------===// |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 124 | /// DWLabel - Labels are used to track locations in the assembler file. |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 125 | /// Labels appear in the form @verbatim <prefix><Tag><Number> @endverbatim, |
| 126 | /// where the tag is a category of label (Ex. location) and number is a value |
Reid Spencer | 181b6c9 | 2007-08-05 20:06:04 +0000 | [diff] [blame] | 127 | /// unique in that category. |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 128 | class DWLabel { |
| 129 | public: |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 130 | /// Tag - Label category tag. Should always be a staticly declared C string. |
| 131 | /// |
| 132 | const char *Tag; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 133 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 134 | /// Number - Value to make label unique. |
| 135 | /// |
| 136 | unsigned Number; |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 137 | |
| 138 | DWLabel(const char *T, unsigned N) : Tag(T), Number(N) {} |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 139 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 140 | void Profile(FoldingSetNodeID &ID) const { |
| 141 | ID.AddString(std::string(Tag)); |
| 142 | ID.AddInteger(Number); |
Jim Laskey | 90c79d7 | 2006-03-23 23:02:34 +0000 | [diff] [blame] | 143 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 144 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 145 | #ifndef NDEBUG |
Bill Wendling | 5c7e326 | 2006-12-17 05:15:13 +0000 | [diff] [blame] | 146 | void print(std::ostream *O) const { |
| 147 | if (O) print(*O); |
Bill Wendling | bdc679d | 2006-11-29 00:39:47 +0000 | [diff] [blame] | 148 | } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 149 | void print(std::ostream &O) const { |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 150 | O << "." << Tag; |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 151 | if (Number) O << Number; |
| 152 | } |
| 153 | #endif |
Jim Laskey | bd76184 | 2006-02-27 17:27:12 +0000 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | //===----------------------------------------------------------------------===// |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 157 | /// DIEAbbrevData - Dwarf abbreviation data, describes the one attribute of a |
| 158 | /// Dwarf abbreviation. |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 159 | class DIEAbbrevData { |
| 160 | private: |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 161 | /// Attribute - Dwarf attribute code. |
| 162 | /// |
| 163 | unsigned Attribute; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 164 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 165 | /// Form - Dwarf form code. |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 166 | /// |
| 167 | unsigned Form; |
| 168 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 169 | public: |
| 170 | DIEAbbrevData(unsigned A, unsigned F) |
| 171 | : Attribute(A) |
| 172 | , Form(F) |
| 173 | {} |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 174 | |
Jim Laskey | bd76184 | 2006-02-27 17:27:12 +0000 | [diff] [blame] | 175 | // Accessors. |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 176 | unsigned getAttribute() const { return Attribute; } |
| 177 | unsigned getForm() const { return Form; } |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 178 | |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 179 | /// Profile - Used to gather unique data for the abbreviation folding set. |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 180 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 181 | void Profile(FoldingSetNodeID &ID)const { |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 182 | ID.AddInteger(Attribute); |
| 183 | ID.AddInteger(Form); |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 184 | } |
| 185 | }; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 186 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 187 | //===----------------------------------------------------------------------===// |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 188 | /// DIEAbbrev - Dwarf abbreviation, describes the organization of a debug |
| 189 | /// information object. |
| 190 | class DIEAbbrev : public FoldingSetNode { |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 191 | private: |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 192 | /// Tag - Dwarf tag code. |
| 193 | /// |
| 194 | unsigned Tag; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 195 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 196 | /// Unique number for node. |
| 197 | /// |
| 198 | unsigned Number; |
| 199 | |
| 200 | /// ChildrenFlag - Dwarf children flag. |
| 201 | /// |
| 202 | unsigned ChildrenFlag; |
| 203 | |
| 204 | /// Data - Raw data bytes for abbreviation. |
| 205 | /// |
Owen Anderson | 873e1b5 | 2008-06-24 21:44:59 +0000 | [diff] [blame] | 206 | SmallVector<DIEAbbrevData, 8> Data; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 207 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 208 | public: |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 209 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 210 | DIEAbbrev(unsigned T, unsigned C) |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 211 | : Tag(T) |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 212 | , ChildrenFlag(C) |
| 213 | , Data() |
| 214 | {} |
| 215 | ~DIEAbbrev() {} |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 216 | |
Jim Laskey | bd76184 | 2006-02-27 17:27:12 +0000 | [diff] [blame] | 217 | // Accessors. |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 218 | unsigned getTag() const { return Tag; } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 219 | unsigned getNumber() const { return Number; } |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 220 | unsigned getChildrenFlag() const { return ChildrenFlag; } |
Owen Anderson | 873e1b5 | 2008-06-24 21:44:59 +0000 | [diff] [blame] | 221 | const SmallVector<DIEAbbrevData, 8> &getData() const { return Data; } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 222 | void setTag(unsigned T) { Tag = T; } |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 223 | void setChildrenFlag(unsigned CF) { ChildrenFlag = CF; } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 224 | void setNumber(unsigned N) { Number = N; } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 225 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 226 | /// AddAttribute - Adds another set of attribute information to the |
| 227 | /// abbreviation. |
| 228 | void AddAttribute(unsigned Attribute, unsigned Form) { |
| 229 | Data.push_back(DIEAbbrevData(Attribute, Form)); |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 230 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 231 | |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 232 | /// AddFirstAttribute - Adds a set of attribute information to the front |
| 233 | /// of the abbreviation. |
| 234 | void AddFirstAttribute(unsigned Attribute, unsigned Form) { |
| 235 | Data.insert(Data.begin(), DIEAbbrevData(Attribute, Form)); |
| 236 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 237 | |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 238 | /// Profile - Used to gather unique data for the abbreviation folding set. |
| 239 | /// |
| 240 | void Profile(FoldingSetNodeID &ID) { |
| 241 | ID.AddInteger(Tag); |
| 242 | ID.AddInteger(ChildrenFlag); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 243 | |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 244 | // For each attribute description. |
| 245 | for (unsigned i = 0, N = Data.size(); i < N; ++i) |
| 246 | Data[i].Profile(ID); |
| 247 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 248 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 249 | /// Emit - Print the abbreviation using the specified Dwarf writer. |
| 250 | /// |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 251 | void Emit(const DwarfDebug &DD) const; |
| 252 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 253 | #ifndef NDEBUG |
Bill Wendling | 5c7e326 | 2006-12-17 05:15:13 +0000 | [diff] [blame] | 254 | void print(std::ostream *O) { |
| 255 | if (O) print(*O); |
Bill Wendling | bdc679d | 2006-11-29 00:39:47 +0000 | [diff] [blame] | 256 | } |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 257 | void print(std::ostream &O); |
| 258 | void dump(); |
| 259 | #endif |
| 260 | }; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 261 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 262 | //===----------------------------------------------------------------------===// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 263 | /// DIE - A structured debug information entry. Has an abbreviation which |
| 264 | /// describes it's organization. |
| 265 | class DIE : public FoldingSetNode { |
| 266 | protected: |
| 267 | /// Abbrev - Buffer for constructing abbreviation. |
| 268 | /// |
| 269 | DIEAbbrev Abbrev; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 270 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 271 | /// Offset - Offset in debug info section. |
| 272 | /// |
| 273 | unsigned Offset; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 274 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 275 | /// Size - Size of instance + children. |
| 276 | /// |
| 277 | unsigned Size; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 278 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 279 | /// Children DIEs. |
| 280 | /// |
| 281 | std::vector<DIE *> Children; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 282 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 283 | /// Attributes values. |
| 284 | /// |
Owen Anderson | 873e1b5 | 2008-06-24 21:44:59 +0000 | [diff] [blame] | 285 | SmallVector<DIEValue*, 32> Values; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 286 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 287 | public: |
Dan Gohman | 81975f6 | 2007-08-27 14:50:10 +0000 | [diff] [blame] | 288 | explicit DIE(unsigned Tag) |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 289 | : Abbrev(Tag, DW_CHILDREN_no) |
| 290 | , Offset(0) |
| 291 | , Size(0) |
| 292 | , Children() |
| 293 | , Values() |
| 294 | {} |
| 295 | virtual ~DIE(); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 296 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 297 | // Accessors. |
| 298 | DIEAbbrev &getAbbrev() { return Abbrev; } |
| 299 | unsigned getAbbrevNumber() const { |
| 300 | return Abbrev.getNumber(); |
| 301 | } |
Jim Laskey | 85f419b | 2006-11-09 16:32:26 +0000 | [diff] [blame] | 302 | unsigned getTag() const { return Abbrev.getTag(); } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 303 | unsigned getOffset() const { return Offset; } |
| 304 | unsigned getSize() const { return Size; } |
| 305 | const std::vector<DIE *> &getChildren() const { return Children; } |
Owen Anderson | 873e1b5 | 2008-06-24 21:44:59 +0000 | [diff] [blame] | 306 | SmallVector<DIEValue*, 32> &getValues() { return Values; } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 307 | void setTag(unsigned Tag) { Abbrev.setTag(Tag); } |
| 308 | void setOffset(unsigned O) { Offset = O; } |
| 309 | void setSize(unsigned S) { Size = S; } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 310 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 311 | /// AddValue - Add a value and attributes to a DIE. |
| 312 | /// |
| 313 | void AddValue(unsigned Attribute, unsigned Form, DIEValue *Value) { |
| 314 | Abbrev.AddAttribute(Attribute, Form); |
| 315 | Values.push_back(Value); |
| 316 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 317 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 318 | /// SiblingOffset - Return the offset of the debug information entry's |
| 319 | /// sibling. |
| 320 | unsigned SiblingOffset() const { return Offset + Size; } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 321 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 322 | /// AddSiblingOffset - Add a sibling offset field to the front of the DIE. |
| 323 | /// |
| 324 | void AddSiblingOffset(); |
| 325 | |
| 326 | /// AddChild - Add a child to the DIE. |
| 327 | /// |
| 328 | void AddChild(DIE *Child) { |
| 329 | Abbrev.setChildrenFlag(DW_CHILDREN_yes); |
| 330 | Children.push_back(Child); |
| 331 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 332 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 333 | /// Detach - Detaches objects connected to it after copying. |
| 334 | /// |
| 335 | void Detach() { |
| 336 | Children.clear(); |
| 337 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 338 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 339 | /// Profile - Used to gather unique data for the value folding set. |
| 340 | /// |
| 341 | void Profile(FoldingSetNodeID &ID) ; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 342 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 343 | #ifndef NDEBUG |
Bill Wendling | 5c7e326 | 2006-12-17 05:15:13 +0000 | [diff] [blame] | 344 | void print(std::ostream *O, unsigned IncIndent = 0) { |
| 345 | if (O) print(*O, IncIndent); |
Bill Wendling | bdc679d | 2006-11-29 00:39:47 +0000 | [diff] [blame] | 346 | } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 347 | void print(std::ostream &O, unsigned IncIndent = 0); |
| 348 | void dump(); |
| 349 | #endif |
| 350 | }; |
| 351 | |
| 352 | //===----------------------------------------------------------------------===// |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 353 | /// DIEValue - A debug information entry value. |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 354 | /// |
| 355 | class DIEValue : public FoldingSetNode { |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 356 | public: |
| 357 | enum { |
| 358 | isInteger, |
| 359 | isString, |
| 360 | isLabel, |
| 361 | isAsIsLabel, |
Argyrios Kyrtzidis | f7acf8f | 2008-06-18 19:27:37 +0000 | [diff] [blame] | 362 | isSectionOffset, |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 363 | isDelta, |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 364 | isEntry, |
| 365 | isBlock |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 366 | }; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 367 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 368 | /// Type - Type of data stored in the value. |
| 369 | /// |
| 370 | unsigned Type; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 371 | |
Dan Gohman | 81975f6 | 2007-08-27 14:50:10 +0000 | [diff] [blame] | 372 | explicit DIEValue(unsigned T) |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 373 | : Type(T) |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 374 | {} |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 375 | virtual ~DIEValue() {} |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 376 | |
Jim Laskey | f673388 | 2006-11-02 21:48:18 +0000 | [diff] [blame] | 377 | // Accessors |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 378 | unsigned getType() const { return Type; } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 379 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 380 | // Implement isa/cast/dyncast. |
| 381 | static bool classof(const DIEValue *) { return true; } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 382 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 383 | /// EmitValue - Emit value via the Dwarf writer. |
| 384 | /// |
Anton Korobeynikov | 6a14359 | 2007-03-07 08:25:02 +0000 | [diff] [blame] | 385 | virtual void EmitValue(DwarfDebug &DD, unsigned Form) = 0; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 386 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 387 | /// SizeOf - Return the size of a value in bytes. |
| 388 | /// |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 389 | virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const = 0; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 390 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 391 | /// Profile - Used to gather unique data for the value folding set. |
| 392 | /// |
| 393 | virtual void Profile(FoldingSetNodeID &ID) = 0; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 394 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 395 | #ifndef NDEBUG |
Bill Wendling | 5c7e326 | 2006-12-17 05:15:13 +0000 | [diff] [blame] | 396 | void print(std::ostream *O) { |
| 397 | if (O) print(*O); |
Bill Wendling | bdc679d | 2006-11-29 00:39:47 +0000 | [diff] [blame] | 398 | } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 399 | virtual void print(std::ostream &O) = 0; |
| 400 | void dump(); |
| 401 | #endif |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 402 | }; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 403 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 404 | //===----------------------------------------------------------------------===// |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 405 | /// DWInteger - An integer value DIE. |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 406 | /// |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 407 | class DIEInteger : public DIEValue { |
| 408 | private: |
| 409 | uint64_t Integer; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 410 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 411 | public: |
Dan Gohman | 81975f6 | 2007-08-27 14:50:10 +0000 | [diff] [blame] | 412 | explicit DIEInteger(uint64_t I) : DIEValue(isInteger), Integer(I) {} |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 413 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 414 | // Implement isa/cast/dyncast. |
| 415 | static bool classof(const DIEInteger *) { return true; } |
| 416 | static bool classof(const DIEValue *I) { return I->Type == isInteger; } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 417 | |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 418 | /// BestForm - Choose the best form for integer. |
| 419 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 420 | static unsigned BestForm(bool IsSigned, uint64_t Integer) { |
| 421 | if (IsSigned) { |
| 422 | if ((char)Integer == (signed)Integer) return DW_FORM_data1; |
| 423 | if ((short)Integer == (signed)Integer) return DW_FORM_data2; |
| 424 | if ((int)Integer == (signed)Integer) return DW_FORM_data4; |
| 425 | } else { |
| 426 | if ((unsigned char)Integer == Integer) return DW_FORM_data1; |
| 427 | if ((unsigned short)Integer == Integer) return DW_FORM_data2; |
| 428 | if ((unsigned int)Integer == Integer) return DW_FORM_data4; |
| 429 | } |
| 430 | return DW_FORM_data8; |
| 431 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 432 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 433 | /// EmitValue - Emit integer of appropriate size. |
| 434 | /// |
Anton Korobeynikov | 6a14359 | 2007-03-07 08:25:02 +0000 | [diff] [blame] | 435 | virtual void EmitValue(DwarfDebug &DD, unsigned Form); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 436 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 437 | /// SizeOf - Determine size of integer value in bytes. |
| 438 | /// |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 439 | virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 440 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 441 | /// Profile - Used to gather unique data for the value folding set. |
| 442 | /// |
Jim Laskey | 5496f01 | 2006-11-09 14:52:14 +0000 | [diff] [blame] | 443 | static void Profile(FoldingSetNodeID &ID, unsigned Integer) { |
Jim Laskey | f673388 | 2006-11-02 21:48:18 +0000 | [diff] [blame] | 444 | ID.AddInteger(isInteger); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 445 | ID.AddInteger(Integer); |
| 446 | } |
Jim Laskey | 5496f01 | 2006-11-09 14:52:14 +0000 | [diff] [blame] | 447 | virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, Integer); } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 448 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 449 | #ifndef NDEBUG |
| 450 | virtual void print(std::ostream &O) { |
| 451 | O << "Int: " << (int64_t)Integer |
| 452 | << " 0x" << std::hex << Integer << std::dec; |
| 453 | } |
| 454 | #endif |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 455 | }; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 456 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 457 | //===----------------------------------------------------------------------===// |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 458 | /// DIEString - A string value DIE. |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 459 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 460 | class DIEString : public DIEValue { |
| 461 | public: |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 462 | const std::string String; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 463 | |
Dan Gohman | 81975f6 | 2007-08-27 14:50:10 +0000 | [diff] [blame] | 464 | explicit DIEString(const std::string &S) : DIEValue(isString), String(S) {} |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 465 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 466 | // Implement isa/cast/dyncast. |
| 467 | static bool classof(const DIEString *) { return true; } |
| 468 | static bool classof(const DIEValue *S) { return S->Type == isString; } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 469 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 470 | /// EmitValue - Emit string value. |
| 471 | /// |
Anton Korobeynikov | 6a14359 | 2007-03-07 08:25:02 +0000 | [diff] [blame] | 472 | virtual void EmitValue(DwarfDebug &DD, unsigned Form); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 473 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 474 | /// SizeOf - Determine size of string value in bytes. |
| 475 | /// |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 476 | virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const { |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 477 | return String.size() + sizeof(char); // sizeof('\0'); |
| 478 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 479 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 480 | /// Profile - Used to gather unique data for the value folding set. |
| 481 | /// |
Jim Laskey | 5496f01 | 2006-11-09 14:52:14 +0000 | [diff] [blame] | 482 | static void Profile(FoldingSetNodeID &ID, const std::string &String) { |
Jim Laskey | f673388 | 2006-11-02 21:48:18 +0000 | [diff] [blame] | 483 | ID.AddInteger(isString); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 484 | ID.AddString(String); |
| 485 | } |
Jim Laskey | 5496f01 | 2006-11-09 14:52:14 +0000 | [diff] [blame] | 486 | virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, String); } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 487 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 488 | #ifndef NDEBUG |
| 489 | virtual void print(std::ostream &O) { |
| 490 | O << "Str: \"" << String << "\""; |
| 491 | } |
| 492 | #endif |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 493 | }; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 494 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 495 | //===----------------------------------------------------------------------===// |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 496 | /// DIEDwarfLabel - A Dwarf internal label expression DIE. |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 497 | // |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 498 | class DIEDwarfLabel : public DIEValue { |
| 499 | public: |
| 500 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 501 | const DWLabel Label; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 502 | |
Dan Gohman | 81975f6 | 2007-08-27 14:50:10 +0000 | [diff] [blame] | 503 | explicit DIEDwarfLabel(const DWLabel &L) : DIEValue(isLabel), Label(L) {} |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 504 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 505 | // Implement isa/cast/dyncast. |
| 506 | static bool classof(const DIEDwarfLabel *) { return true; } |
| 507 | static bool classof(const DIEValue *L) { return L->Type == isLabel; } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 508 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 509 | /// EmitValue - Emit label value. |
| 510 | /// |
Anton Korobeynikov | 6a14359 | 2007-03-07 08:25:02 +0000 | [diff] [blame] | 511 | virtual void EmitValue(DwarfDebug &DD, unsigned Form); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 512 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 513 | /// SizeOf - Determine size of label value in bytes. |
| 514 | /// |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 515 | virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 516 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 517 | /// Profile - Used to gather unique data for the value folding set. |
| 518 | /// |
Jim Laskey | 5496f01 | 2006-11-09 14:52:14 +0000 | [diff] [blame] | 519 | static void Profile(FoldingSetNodeID &ID, const DWLabel &Label) { |
Jim Laskey | f673388 | 2006-11-02 21:48:18 +0000 | [diff] [blame] | 520 | ID.AddInteger(isLabel); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 521 | Label.Profile(ID); |
| 522 | } |
Jim Laskey | 5496f01 | 2006-11-09 14:52:14 +0000 | [diff] [blame] | 523 | virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, Label); } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 524 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 525 | #ifndef NDEBUG |
| 526 | virtual void print(std::ostream &O) { |
| 527 | O << "Lbl: "; |
| 528 | Label.print(O); |
| 529 | } |
| 530 | #endif |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 531 | }; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 532 | |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 533 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 534 | //===----------------------------------------------------------------------===// |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 535 | /// DIEObjectLabel - A label to an object in code or data. |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 536 | // |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 537 | class DIEObjectLabel : public DIEValue { |
| 538 | public: |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 539 | const std::string Label; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 540 | |
Dan Gohman | 81975f6 | 2007-08-27 14:50:10 +0000 | [diff] [blame] | 541 | explicit DIEObjectLabel(const std::string &L) |
| 542 | : DIEValue(isAsIsLabel), Label(L) {} |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 543 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 544 | // Implement isa/cast/dyncast. |
| 545 | static bool classof(const DIEObjectLabel *) { return true; } |
| 546 | static bool classof(const DIEValue *L) { return L->Type == isAsIsLabel; } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 547 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 548 | /// EmitValue - Emit label value. |
| 549 | /// |
Anton Korobeynikov | 6a14359 | 2007-03-07 08:25:02 +0000 | [diff] [blame] | 550 | virtual void EmitValue(DwarfDebug &DD, unsigned Form); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 551 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 552 | /// SizeOf - Determine size of label value in bytes. |
| 553 | /// |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 554 | virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 555 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 556 | /// Profile - Used to gather unique data for the value folding set. |
| 557 | /// |
Jim Laskey | 5496f01 | 2006-11-09 14:52:14 +0000 | [diff] [blame] | 558 | static void Profile(FoldingSetNodeID &ID, const std::string &Label) { |
Jim Laskey | f673388 | 2006-11-02 21:48:18 +0000 | [diff] [blame] | 559 | ID.AddInteger(isAsIsLabel); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 560 | ID.AddString(Label); |
| 561 | } |
Jim Laskey | 5496f01 | 2006-11-09 14:52:14 +0000 | [diff] [blame] | 562 | virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, Label); } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 563 | |
| 564 | #ifndef NDEBUG |
| 565 | virtual void print(std::ostream &O) { |
| 566 | O << "Obj: " << Label; |
| 567 | } |
| 568 | #endif |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 569 | }; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 570 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 571 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | f7acf8f | 2008-06-18 19:27:37 +0000 | [diff] [blame] | 572 | /// DIESectionOffset - A section offset DIE. |
| 573 | // |
| 574 | class DIESectionOffset : public DIEValue { |
| 575 | public: |
| 576 | const DWLabel Label; |
| 577 | const DWLabel Section; |
| 578 | bool IsEH : 1; |
| 579 | bool UseSet : 1; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 580 | |
Argyrios Kyrtzidis | f7acf8f | 2008-06-18 19:27:37 +0000 | [diff] [blame] | 581 | DIESectionOffset(const DWLabel &Lab, const DWLabel &Sec, |
| 582 | bool isEH = false, bool useSet = true) |
| 583 | : DIEValue(isSectionOffset), Label(Lab), Section(Sec), |
| 584 | IsEH(isEH), UseSet(useSet) {} |
| 585 | |
| 586 | // Implement isa/cast/dyncast. |
| 587 | static bool classof(const DIESectionOffset *) { return true; } |
| 588 | static bool classof(const DIEValue *D) { return D->Type == isSectionOffset; } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 589 | |
Argyrios Kyrtzidis | f7acf8f | 2008-06-18 19:27:37 +0000 | [diff] [blame] | 590 | /// EmitValue - Emit section offset. |
| 591 | /// |
| 592 | virtual void EmitValue(DwarfDebug &DD, unsigned Form); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 593 | |
Argyrios Kyrtzidis | f7acf8f | 2008-06-18 19:27:37 +0000 | [diff] [blame] | 594 | /// SizeOf - Determine size of section offset value in bytes. |
| 595 | /// |
| 596 | virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 597 | |
Argyrios Kyrtzidis | f7acf8f | 2008-06-18 19:27:37 +0000 | [diff] [blame] | 598 | /// Profile - Used to gather unique data for the value folding set. |
| 599 | /// |
| 600 | static void Profile(FoldingSetNodeID &ID, const DWLabel &Label, |
| 601 | const DWLabel &Section) { |
| 602 | ID.AddInteger(isSectionOffset); |
| 603 | Label.Profile(ID); |
| 604 | Section.Profile(ID); |
| 605 | // IsEH and UseSet are specific to the Label/Section that we will emit |
| 606 | // the offset for; so Label/Section are enough for uniqueness. |
| 607 | } |
| 608 | virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, Label, Section); } |
| 609 | |
| 610 | #ifndef NDEBUG |
| 611 | virtual void print(std::ostream &O) { |
| 612 | O << "Off: "; |
| 613 | Label.print(O); |
| 614 | O << "-"; |
| 615 | Section.print(O); |
| 616 | O << "-" << IsEH << "-" << UseSet; |
| 617 | } |
| 618 | #endif |
| 619 | }; |
| 620 | |
| 621 | //===----------------------------------------------------------------------===// |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 622 | /// DIEDelta - A simple label difference DIE. |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 623 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 624 | class DIEDelta : public DIEValue { |
| 625 | public: |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 626 | const DWLabel LabelHi; |
| 627 | const DWLabel LabelLo; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 628 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 629 | DIEDelta(const DWLabel &Hi, const DWLabel &Lo) |
| 630 | : DIEValue(isDelta), LabelHi(Hi), LabelLo(Lo) {} |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 631 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 632 | // Implement isa/cast/dyncast. |
| 633 | static bool classof(const DIEDelta *) { return true; } |
| 634 | static bool classof(const DIEValue *D) { return D->Type == isDelta; } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 635 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 636 | /// EmitValue - Emit delta value. |
| 637 | /// |
Anton Korobeynikov | 6a14359 | 2007-03-07 08:25:02 +0000 | [diff] [blame] | 638 | virtual void EmitValue(DwarfDebug &DD, unsigned Form); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 639 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 640 | /// SizeOf - Determine size of delta value in bytes. |
| 641 | /// |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 642 | virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 643 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 644 | /// Profile - Used to gather unique data for the value folding set. |
| 645 | /// |
Jim Laskey | 5496f01 | 2006-11-09 14:52:14 +0000 | [diff] [blame] | 646 | static void Profile(FoldingSetNodeID &ID, const DWLabel &LabelHi, |
| 647 | const DWLabel &LabelLo) { |
Jim Laskey | f673388 | 2006-11-02 21:48:18 +0000 | [diff] [blame] | 648 | ID.AddInteger(isDelta); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 649 | LabelHi.Profile(ID); |
| 650 | LabelLo.Profile(ID); |
| 651 | } |
Jim Laskey | 5496f01 | 2006-11-09 14:52:14 +0000 | [diff] [blame] | 652 | virtual void Profile(FoldingSetNodeID &ID) { Profile(ID, LabelHi, LabelLo); } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 653 | |
| 654 | #ifndef NDEBUG |
| 655 | virtual void print(std::ostream &O) { |
| 656 | O << "Del: "; |
| 657 | LabelHi.print(O); |
| 658 | O << "-"; |
| 659 | LabelLo.print(O); |
| 660 | } |
| 661 | #endif |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 662 | }; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 663 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 664 | //===----------------------------------------------------------------------===// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 665 | /// DIEntry - A pointer to another debug information entry. An instance of this |
| 666 | /// class can also be used as a proxy for a debug information entry not yet |
| 667 | /// defined (ie. types.) |
| 668 | class DIEntry : public DIEValue { |
| 669 | public: |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 670 | DIE *Entry; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 671 | |
Dan Gohman | 81975f6 | 2007-08-27 14:50:10 +0000 | [diff] [blame] | 672 | explicit DIEntry(DIE *E) : DIEValue(isEntry), Entry(E) {} |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 673 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 674 | // Implement isa/cast/dyncast. |
| 675 | static bool classof(const DIEntry *) { return true; } |
| 676 | static bool classof(const DIEValue *E) { return E->Type == isEntry; } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 677 | |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 678 | /// EmitValue - Emit debug information entry offset. |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 679 | /// |
Anton Korobeynikov | 6a14359 | 2007-03-07 08:25:02 +0000 | [diff] [blame] | 680 | virtual void EmitValue(DwarfDebug &DD, unsigned Form); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 681 | |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 682 | /// SizeOf - Determine size of debug information entry in bytes. |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 683 | /// |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 684 | virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const { |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 685 | return sizeof(int32_t); |
| 686 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 687 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 688 | /// Profile - Used to gather unique data for the value folding set. |
| 689 | /// |
Jim Laskey | 5496f01 | 2006-11-09 14:52:14 +0000 | [diff] [blame] | 690 | static void Profile(FoldingSetNodeID &ID, DIE *Entry) { |
| 691 | ID.AddInteger(isEntry); |
| 692 | ID.AddPointer(Entry); |
| 693 | } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 694 | virtual void Profile(FoldingSetNodeID &ID) { |
Jim Laskey | f673388 | 2006-11-02 21:48:18 +0000 | [diff] [blame] | 695 | ID.AddInteger(isEntry); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 696 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 697 | if (Entry) { |
| 698 | ID.AddPointer(Entry); |
| 699 | } else { |
| 700 | ID.AddPointer(this); |
| 701 | } |
| 702 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 703 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 704 | #ifndef NDEBUG |
| 705 | virtual void print(std::ostream &O) { |
| 706 | O << "Die: 0x" << std::hex << (intptr_t)Entry << std::dec; |
| 707 | } |
| 708 | #endif |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 709 | }; |
| 710 | |
| 711 | //===----------------------------------------------------------------------===// |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 712 | /// DIEBlock - A block of values. Primarily used for location expressions. |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 713 | // |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 714 | class DIEBlock : public DIEValue, public DIE { |
| 715 | public: |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 716 | unsigned Size; // Size in bytes excluding size header. |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 717 | |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 718 | DIEBlock() |
| 719 | : DIEValue(isBlock) |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 720 | , DIE(0) |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 721 | , Size(0) |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 722 | {} |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 723 | ~DIEBlock() { |
| 724 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 725 | |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 726 | // Implement isa/cast/dyncast. |
| 727 | static bool classof(const DIEBlock *) { return true; } |
| 728 | static bool classof(const DIEValue *E) { return E->Type == isBlock; } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 729 | |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 730 | /// ComputeSize - calculate the size of the block. |
| 731 | /// |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 732 | unsigned ComputeSize(DwarfDebug &DD); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 733 | |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 734 | /// BestForm - Choose the best form for data. |
| 735 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 736 | unsigned BestForm() const { |
| 737 | if ((unsigned char)Size == Size) return DW_FORM_block1; |
| 738 | if ((unsigned short)Size == Size) return DW_FORM_block2; |
| 739 | if ((unsigned int)Size == Size) return DW_FORM_block4; |
| 740 | return DW_FORM_block; |
| 741 | } |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 742 | |
| 743 | /// EmitValue - Emit block data. |
| 744 | /// |
Anton Korobeynikov | 6a14359 | 2007-03-07 08:25:02 +0000 | [diff] [blame] | 745 | virtual void EmitValue(DwarfDebug &DD, unsigned Form); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 746 | |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 747 | /// SizeOf - Determine size of block data in bytes. |
| 748 | /// |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 749 | virtual unsigned SizeOf(const DwarfDebug &DD, unsigned Form) const; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 750 | |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 751 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 752 | /// Profile - Used to gather unique data for the value folding set. |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 753 | /// |
Reid Spencer | 9782131 | 2006-11-02 23:56:21 +0000 | [diff] [blame] | 754 | virtual void Profile(FoldingSetNodeID &ID) { |
Jim Laskey | f673388 | 2006-11-02 21:48:18 +0000 | [diff] [blame] | 755 | ID.AddInteger(isBlock); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 756 | DIE::Profile(ID); |
| 757 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 758 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 759 | #ifndef NDEBUG |
| 760 | virtual void print(std::ostream &O) { |
| 761 | O << "Blk: "; |
| 762 | DIE::print(O, 5); |
| 763 | } |
| 764 | #endif |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 765 | }; |
| 766 | |
| 767 | //===----------------------------------------------------------------------===// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 768 | /// CompileUnit - This dwarf writer support class manages information associate |
| 769 | /// with a source file. |
| 770 | class CompileUnit { |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 771 | private: |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 772 | /// ID - File identifier for source. |
| 773 | /// |
| 774 | unsigned ID; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 775 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 776 | /// Die - Compile unit debug information entry. |
| 777 | /// |
| 778 | DIE *Die; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 779 | |
Devang Patel | bbdc820 | 2009-01-13 23:54:55 +0000 | [diff] [blame] | 780 | /// GVToDieMap - Tracks the mapping of unit level debug informaton |
| 781 | /// variables to debug information entries. |
Devang Patel | c2997f4 | 2009-01-20 00:58:55 +0000 | [diff] [blame] | 782 | std::map<GlobalVariable *, DIE *> GVToDieMap; |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 783 | |
Devang Patel | bbdc820 | 2009-01-13 23:54:55 +0000 | [diff] [blame] | 784 | /// GVToDIEntryMap - Tracks the mapping of unit level debug informaton |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 785 | /// descriptors to debug information entries using a DIEntry proxy. |
Devang Patel | c2997f4 | 2009-01-20 00:58:55 +0000 | [diff] [blame] | 786 | std::map<GlobalVariable *, DIEntry *> GVToDIEntryMap; |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 787 | |
| 788 | /// Globals - A map of globally visible named entities for this unit. |
| 789 | /// |
| 790 | std::map<std::string, DIE *> Globals; |
| 791 | |
| 792 | /// DiesSet - Used to uniquely define dies within the compile unit. |
| 793 | /// |
| 794 | FoldingSet<DIE> DiesSet; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 795 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 796 | public: |
Devang Patel | d1ca925 | 2009-01-05 23:03:32 +0000 | [diff] [blame] | 797 | CompileUnit(unsigned I, DIE *D) |
Devang Patel | bbdc820 | 2009-01-13 23:54:55 +0000 | [diff] [blame] | 798 | : ID(I), Die(D), GVToDieMap(), |
Devang Patel | 7e55b3a | 2009-01-17 06:51:37 +0000 | [diff] [blame] | 799 | GVToDIEntryMap(), Globals(), DiesSet(InitDiesSetSize) |
Devang Patel | d1ca925 | 2009-01-05 23:03:32 +0000 | [diff] [blame] | 800 | {} |
| 801 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 802 | ~CompileUnit() { |
| 803 | delete Die; |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 804 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 805 | |
Jim Laskey | bd76184 | 2006-02-27 17:27:12 +0000 | [diff] [blame] | 806 | // Accessors. |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 807 | unsigned getID() const { return ID; } |
| 808 | DIE* getDie() const { return Die; } |
| 809 | std::map<std::string, DIE *> &getGlobals() { return Globals; } |
| 810 | |
| 811 | /// hasContent - Return true if this compile unit has something to write out. |
| 812 | /// |
| 813 | bool hasContent() const { |
| 814 | return !Die->getChildren().empty(); |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 815 | } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 816 | |
| 817 | /// AddGlobal - Add a new global entity to the compile unit. |
| 818 | /// |
| 819 | void AddGlobal(const std::string &Name, DIE *Die) { |
| 820 | Globals[Name] = Die; |
| 821 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 822 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 823 | /// getDieMapSlotFor - Returns the debug information entry map slot for the |
Devang Patel | bbdc820 | 2009-01-13 23:54:55 +0000 | [diff] [blame] | 824 | /// specified debug variable. |
Devang Patel | 48d190f | 2009-01-05 21:47:57 +0000 | [diff] [blame] | 825 | DIE *&getDieMapSlotFor(GlobalVariable *GV) { |
| 826 | return GVToDieMap[GV]; |
| 827 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 828 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 829 | /// getDIEntrySlotFor - Returns the debug information entry proxy slot for the |
Devang Patel | bbdc820 | 2009-01-13 23:54:55 +0000 | [diff] [blame] | 830 | /// specified debug variable. |
Devang Patel | 48d190f | 2009-01-05 21:47:57 +0000 | [diff] [blame] | 831 | DIEntry *&getDIEntrySlotFor(GlobalVariable *GV) { |
| 832 | return GVToDIEntryMap[GV]; |
| 833 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 834 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 835 | /// AddDie - Adds or interns the DIE to the compile unit. |
| 836 | /// |
| 837 | DIE *AddDie(DIE &Buffer) { |
| 838 | FoldingSetNodeID ID; |
| 839 | Buffer.Profile(ID); |
| 840 | void *Where; |
| 841 | DIE *Die = DiesSet.FindNodeOrInsertPos(ID, Where); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 842 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 843 | if (!Die) { |
| 844 | Die = new DIE(Buffer); |
| 845 | DiesSet.InsertNode(Die, Where); |
| 846 | this->Die->AddChild(Die); |
| 847 | Buffer.Detach(); |
| 848 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 849 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 850 | return Die; |
| 851 | } |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 852 | }; |
| 853 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 854 | //===----------------------------------------------------------------------===// |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 855 | /// Dwarf - Emits general Dwarf directives. |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 856 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 857 | class Dwarf { |
| 858 | |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 859 | protected: |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 860 | |
| 861 | //===--------------------------------------------------------------------===// |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 862 | // Core attributes used by the Dwarf writer. |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 863 | // |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 864 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 865 | // |
| 866 | /// O - Stream to .s file. |
| 867 | /// |
Owen Anderson | cb37188 | 2008-08-21 00:14:44 +0000 | [diff] [blame] | 868 | raw_ostream &O; |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 869 | |
| 870 | /// Asm - Target of Dwarf emission. |
| 871 | /// |
| 872 | AsmPrinter *Asm; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 873 | |
Bill Wendling | aa8f888 | 2008-07-01 23:34:48 +0000 | [diff] [blame] | 874 | /// TAI - Target asm information. |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 875 | const TargetAsmInfo *TAI; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 876 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 877 | /// TD - Target data. |
| 878 | const TargetData *TD; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 879 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 880 | /// RI - Register Information. |
Dan Gohman | 6f0d024 | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 881 | const TargetRegisterInfo *RI; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 882 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 883 | /// M - Current module. |
| 884 | /// |
| 885 | Module *M; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 886 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 887 | /// MF - Current machine function. |
| 888 | /// |
| 889 | MachineFunction *MF; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 890 | |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 891 | /// MMI - Collected machine module information. |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 892 | /// |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 893 | MachineModuleInfo *MMI; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 894 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 895 | /// SubprogramCount - The running count of functions being compiled. |
| 896 | /// |
| 897 | unsigned SubprogramCount; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 898 | |
Chris Lattner | 9251f13 | 2007-09-24 03:35:37 +0000 | [diff] [blame] | 899 | /// Flavor - A unique string indicating what dwarf producer this is, used to |
| 900 | /// unique labels. |
| 901 | const char * const Flavor; |
Anton Korobeynikov | 6a14359 | 2007-03-07 08:25:02 +0000 | [diff] [blame] | 902 | |
| 903 | unsigned SetCounter; |
Owen Anderson | cb37188 | 2008-08-21 00:14:44 +0000 | [diff] [blame] | 904 | Dwarf(raw_ostream &OS, AsmPrinter *A, const TargetAsmInfo *T, |
Chris Lattner | 9251f13 | 2007-09-24 03:35:37 +0000 | [diff] [blame] | 905 | const char *flavor) |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 906 | : O(OS) |
| 907 | , Asm(A) |
| 908 | , TAI(T) |
| 909 | , TD(Asm->TM.getTargetData()) |
| 910 | , RI(Asm->TM.getRegisterInfo()) |
| 911 | , M(NULL) |
| 912 | , MF(NULL) |
| 913 | , MMI(NULL) |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 914 | , SubprogramCount(0) |
Chris Lattner | 9251f13 | 2007-09-24 03:35:37 +0000 | [diff] [blame] | 915 | , Flavor(flavor) |
Anton Korobeynikov | 6a14359 | 2007-03-07 08:25:02 +0000 | [diff] [blame] | 916 | , SetCounter(1) |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 917 | { |
| 918 | } |
| 919 | |
| 920 | public: |
| 921 | |
| 922 | //===--------------------------------------------------------------------===// |
| 923 | // Accessors. |
| 924 | // |
| 925 | AsmPrinter *getAsm() const { return Asm; } |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 926 | MachineModuleInfo *getMMI() const { return MMI; } |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 927 | const TargetAsmInfo *getTargetAsmInfo() const { return TAI; } |
Dan Gohman | 8248294 | 2007-09-27 23:12:31 +0000 | [diff] [blame] | 928 | const TargetData *getTargetData() const { return TD; } |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 929 | |
Anton Korobeynikov | 9cc54f5 | 2007-09-02 22:07:21 +0000 | [diff] [blame] | 930 | void PrintRelDirective(bool Force32Bit = false, bool isInSection = false) |
| 931 | const { |
| 932 | if (isInSection && TAI->getDwarfSectionOffsetDirective()) |
| 933 | O << TAI->getDwarfSectionOffsetDirective(); |
Dan Gohman | 8248294 | 2007-09-27 23:12:31 +0000 | [diff] [blame] | 934 | else if (Force32Bit || TD->getPointerSize() == sizeof(int32_t)) |
Anton Korobeynikov | 9cc54f5 | 2007-09-02 22:07:21 +0000 | [diff] [blame] | 935 | O << TAI->getData32bitsDirective(); |
| 936 | else |
| 937 | O << TAI->getData64bitsDirective(); |
| 938 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 939 | |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 940 | /// PrintLabelName - Print label name in form used by Dwarf writer. |
| 941 | /// |
| 942 | void PrintLabelName(DWLabel Label) const { |
| 943 | PrintLabelName(Label.Tag, Label.Number); |
| 944 | } |
Anton Korobeynikov | 9cc54f5 | 2007-09-02 22:07:21 +0000 | [diff] [blame] | 945 | void PrintLabelName(const char *Tag, unsigned Number) const { |
Anton Korobeynikov | 9cc54f5 | 2007-09-02 22:07:21 +0000 | [diff] [blame] | 946 | O << TAI->getPrivateGlobalPrefix() << Tag; |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 947 | if (Number) O << Number; |
| 948 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 949 | |
Chris Lattner | 9251f13 | 2007-09-24 03:35:37 +0000 | [diff] [blame] | 950 | void PrintLabelName(const char *Tag, unsigned Number, |
| 951 | const char *Suffix) const { |
| 952 | O << TAI->getPrivateGlobalPrefix() << Tag; |
| 953 | if (Number) O << Number; |
| 954 | O << Suffix; |
| 955 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 956 | |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 957 | /// EmitLabel - Emit location label for internal use by Dwarf. |
| 958 | /// |
| 959 | void EmitLabel(DWLabel Label) const { |
| 960 | EmitLabel(Label.Tag, Label.Number); |
| 961 | } |
| 962 | void EmitLabel(const char *Tag, unsigned Number) const { |
| 963 | PrintLabelName(Tag, Number); |
| 964 | O << ":\n"; |
| 965 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 966 | |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 967 | /// EmitReference - Emit a reference to a label. |
| 968 | /// |
Dan Gohman | 06ff4e6 | 2007-09-28 15:43:33 +0000 | [diff] [blame] | 969 | void EmitReference(DWLabel Label, bool IsPCRelative = false, |
| 970 | bool Force32Bit = false) const { |
| 971 | EmitReference(Label.Tag, Label.Number, IsPCRelative, Force32Bit); |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 972 | } |
| 973 | void EmitReference(const char *Tag, unsigned Number, |
Dan Gohman | 06ff4e6 | 2007-09-28 15:43:33 +0000 | [diff] [blame] | 974 | bool IsPCRelative = false, bool Force32Bit = false) const { |
| 975 | PrintRelDirective(Force32Bit); |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 976 | PrintLabelName(Tag, Number); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 977 | |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 978 | if (IsPCRelative) O << "-" << TAI->getPCSymbol(); |
| 979 | } |
Dan Gohman | 06ff4e6 | 2007-09-28 15:43:33 +0000 | [diff] [blame] | 980 | void EmitReference(const std::string &Name, bool IsPCRelative = false, |
| 981 | bool Force32Bit = false) const { |
| 982 | PrintRelDirective(Force32Bit); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 983 | |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 984 | O << Name; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 985 | |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 986 | if (IsPCRelative) O << "-" << TAI->getPCSymbol(); |
| 987 | } |
| 988 | |
| 989 | /// EmitDifference - Emit the difference between two labels. Some |
| 990 | /// assemblers do not behave with absolute expressions with data directives, |
| 991 | /// so there is an option (needsSet) to use an intermediary set expression. |
| 992 | void EmitDifference(DWLabel LabelHi, DWLabel LabelLo, |
Anton Korobeynikov | 6a14359 | 2007-03-07 08:25:02 +0000 | [diff] [blame] | 993 | bool IsSmall = false) { |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 994 | EmitDifference(LabelHi.Tag, LabelHi.Number, |
| 995 | LabelLo.Tag, LabelLo.Number, |
| 996 | IsSmall); |
| 997 | } |
| 998 | void EmitDifference(const char *TagHi, unsigned NumberHi, |
| 999 | const char *TagLo, unsigned NumberLo, |
Anton Korobeynikov | 6a14359 | 2007-03-07 08:25:02 +0000 | [diff] [blame] | 1000 | bool IsSmall = false) { |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1001 | if (TAI->needsSet()) { |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1002 | O << "\t.set\t"; |
Chris Lattner | 9251f13 | 2007-09-24 03:35:37 +0000 | [diff] [blame] | 1003 | PrintLabelName("set", SetCounter, Flavor); |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1004 | O << ","; |
| 1005 | PrintLabelName(TagHi, NumberHi); |
| 1006 | O << "-"; |
| 1007 | PrintLabelName(TagLo, NumberLo); |
| 1008 | O << "\n"; |
Anton Korobeynikov | 9cc54f5 | 2007-09-02 22:07:21 +0000 | [diff] [blame] | 1009 | |
| 1010 | PrintRelDirective(IsSmall); |
Chris Lattner | 9251f13 | 2007-09-24 03:35:37 +0000 | [diff] [blame] | 1011 | PrintLabelName("set", SetCounter, Flavor); |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1012 | ++SetCounter; |
| 1013 | } else { |
Anton Korobeynikov | 9cc54f5 | 2007-09-02 22:07:21 +0000 | [diff] [blame] | 1014 | PrintRelDirective(IsSmall); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1015 | |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1016 | PrintLabelName(TagHi, NumberHi); |
| 1017 | O << "-"; |
| 1018 | PrintLabelName(TagLo, NumberLo); |
| 1019 | } |
| 1020 | } |
Anton Korobeynikov | a6199c8 | 2007-03-07 02:47:57 +0000 | [diff] [blame] | 1021 | |
| 1022 | void EmitSectionOffset(const char* Label, const char* Section, |
| 1023 | unsigned LabelNumber, unsigned SectionNumber, |
Dale Johannesen | d9ffd4c | 2008-03-26 23:31:39 +0000 | [diff] [blame] | 1024 | bool IsSmall = false, bool isEH = false, |
| 1025 | bool useSet = true) { |
Anton Korobeynikov | 79dda2b | 2007-05-01 22:23:12 +0000 | [diff] [blame] | 1026 | bool printAbsolute = false; |
Dale Johannesen | d9ffd4c | 2008-03-26 23:31:39 +0000 | [diff] [blame] | 1027 | if (isEH) |
| 1028 | printAbsolute = TAI->isAbsoluteEHSectionOffsets(); |
| 1029 | else |
| 1030 | printAbsolute = TAI->isAbsoluteDebugSectionOffsets(); |
| 1031 | |
| 1032 | if (TAI->needsSet() && useSet) { |
Anton Korobeynikov | a6199c8 | 2007-03-07 02:47:57 +0000 | [diff] [blame] | 1033 | O << "\t.set\t"; |
Chris Lattner | 9251f13 | 2007-09-24 03:35:37 +0000 | [diff] [blame] | 1034 | PrintLabelName("set", SetCounter, Flavor); |
Anton Korobeynikov | a6199c8 | 2007-03-07 02:47:57 +0000 | [diff] [blame] | 1035 | O << ","; |
Anton Korobeynikov | 9cc54f5 | 2007-09-02 22:07:21 +0000 | [diff] [blame] | 1036 | PrintLabelName(Label, LabelNumber); |
Anton Korobeynikov | 79dda2b | 2007-05-01 22:23:12 +0000 | [diff] [blame] | 1037 | |
Anton Korobeynikov | 79dda2b | 2007-05-01 22:23:12 +0000 | [diff] [blame] | 1038 | if (!printAbsolute) { |
Anton Korobeynikov | a6199c8 | 2007-03-07 02:47:57 +0000 | [diff] [blame] | 1039 | O << "-"; |
| 1040 | PrintLabelName(Section, SectionNumber); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1041 | } |
Anton Korobeynikov | a6199c8 | 2007-03-07 02:47:57 +0000 | [diff] [blame] | 1042 | O << "\n"; |
Anton Korobeynikov | 9cc54f5 | 2007-09-02 22:07:21 +0000 | [diff] [blame] | 1043 | |
| 1044 | PrintRelDirective(IsSmall); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1045 | |
Chris Lattner | 9251f13 | 2007-09-24 03:35:37 +0000 | [diff] [blame] | 1046 | PrintLabelName("set", SetCounter, Flavor); |
Anton Korobeynikov | a6199c8 | 2007-03-07 02:47:57 +0000 | [diff] [blame] | 1047 | ++SetCounter; |
| 1048 | } else { |
Anton Korobeynikov | 9cc54f5 | 2007-09-02 22:07:21 +0000 | [diff] [blame] | 1049 | PrintRelDirective(IsSmall, true); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1050 | |
Anton Korobeynikov | 9cc54f5 | 2007-09-02 22:07:21 +0000 | [diff] [blame] | 1051 | PrintLabelName(Label, LabelNumber); |
Anton Korobeynikov | 79dda2b | 2007-05-01 22:23:12 +0000 | [diff] [blame] | 1052 | |
Anton Korobeynikov | 79dda2b | 2007-05-01 22:23:12 +0000 | [diff] [blame] | 1053 | if (!printAbsolute) { |
Anton Korobeynikov | a6199c8 | 2007-03-07 02:47:57 +0000 | [diff] [blame] | 1054 | O << "-"; |
| 1055 | PrintLabelName(Section, SectionNumber); |
| 1056 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1057 | } |
Anton Korobeynikov | a6199c8 | 2007-03-07 02:47:57 +0000 | [diff] [blame] | 1058 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1059 | |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1060 | /// EmitFrameMoves - Emit frame instructions to describe the layout of the |
| 1061 | /// frame. |
| 1062 | void EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID, |
Dale Johannesen | b97aec6 | 2007-11-13 19:13:01 +0000 | [diff] [blame] | 1063 | const std::vector<MachineMove> &Moves, bool isEH) { |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1064 | int stackGrowth = |
| 1065 | Asm->TM.getFrameInfo()->getStackGrowthDirection() == |
| 1066 | TargetFrameInfo::StackGrowsUp ? |
Dan Gohman | 8248294 | 2007-09-27 23:12:31 +0000 | [diff] [blame] | 1067 | TD->getPointerSize() : -TD->getPointerSize(); |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 1068 | bool IsLocal = BaseLabel && strcmp(BaseLabel, "label") == 0; |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1069 | |
| 1070 | for (unsigned i = 0, N = Moves.size(); i < N; ++i) { |
Anton Korobeynikov | 0ff3ca4 | 2007-05-12 22:36:25 +0000 | [diff] [blame] | 1071 | const MachineMove &Move = Moves[i]; |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1072 | unsigned LabelID = Move.getLabelID(); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1073 | |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1074 | if (LabelID) { |
| 1075 | LabelID = MMI->MappedLabel(LabelID); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1076 | |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1077 | // Throw out move if the label is invalid. |
| 1078 | if (!LabelID) continue; |
| 1079 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1080 | |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1081 | const MachineLocation &Dst = Move.getDestination(); |
| 1082 | const MachineLocation &Src = Move.getSource(); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1083 | |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1084 | // Advance row if new location. |
| 1085 | if (BaseLabel && LabelID && (BaseLabelID != LabelID || !IsLocal)) { |
| 1086 | Asm->EmitInt8(DW_CFA_advance_loc4); |
| 1087 | Asm->EOL("DW_CFA_advance_loc4"); |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 1088 | EmitDifference("label", LabelID, BaseLabel, BaseLabelID, true); |
| 1089 | Asm->EOL(); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1090 | |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1091 | BaseLabelID = LabelID; |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 1092 | BaseLabel = "label"; |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1093 | IsLocal = true; |
| 1094 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1095 | |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1096 | // If advancing cfa. |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 1097 | if (Dst.isReg() && Dst.getReg() == MachineLocation::VirtualFP) { |
| 1098 | if (!Src.isReg()) { |
| 1099 | if (Src.getReg() == MachineLocation::VirtualFP) { |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1100 | Asm->EmitInt8(DW_CFA_def_cfa_offset); |
| 1101 | Asm->EOL("DW_CFA_def_cfa_offset"); |
| 1102 | } else { |
| 1103 | Asm->EmitInt8(DW_CFA_def_cfa); |
| 1104 | Asm->EOL("DW_CFA_def_cfa"); |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 1105 | Asm->EmitULEB128Bytes(RI->getDwarfRegNum(Src.getReg(), isEH)); |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1106 | Asm->EOL("Register"); |
| 1107 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1108 | |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1109 | int Offset = -Src.getOffset(); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1110 | |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1111 | Asm->EmitULEB128Bytes(Offset); |
| 1112 | Asm->EOL("Offset"); |
| 1113 | } else { |
| 1114 | assert(0 && "Machine move no supported yet."); |
| 1115 | } |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 1116 | } else if (Src.isReg() && |
| 1117 | Src.getReg() == MachineLocation::VirtualFP) { |
| 1118 | if (Dst.isReg()) { |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1119 | Asm->EmitInt8(DW_CFA_def_cfa_register); |
| 1120 | Asm->EOL("DW_CFA_def_cfa_register"); |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 1121 | Asm->EmitULEB128Bytes(RI->getDwarfRegNum(Dst.getReg(), isEH)); |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1122 | Asm->EOL("Register"); |
| 1123 | } else { |
| 1124 | assert(0 && "Machine move no supported yet."); |
| 1125 | } |
| 1126 | } else { |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 1127 | unsigned Reg = RI->getDwarfRegNum(Src.getReg(), isEH); |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1128 | int Offset = Dst.getOffset() / stackGrowth; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1129 | |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1130 | if (Offset < 0) { |
| 1131 | Asm->EmitInt8(DW_CFA_offset_extended_sf); |
| 1132 | Asm->EOL("DW_CFA_offset_extended_sf"); |
| 1133 | Asm->EmitULEB128Bytes(Reg); |
| 1134 | Asm->EOL("Reg"); |
| 1135 | Asm->EmitSLEB128Bytes(Offset); |
| 1136 | Asm->EOL("Offset"); |
| 1137 | } else if (Reg < 64) { |
| 1138 | Asm->EmitInt8(DW_CFA_offset + Reg); |
Evan Cheng | d411419 | 2008-07-09 21:53:02 +0000 | [diff] [blame] | 1139 | if (VerboseAsm) |
| 1140 | Asm->EOL("DW_CFA_offset + Reg (" + utostr(Reg) + ")"); |
| 1141 | else |
| 1142 | Asm->EOL(); |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 1143 | Asm->EmitULEB128Bytes(Offset); |
| 1144 | Asm->EOL("Offset"); |
| 1145 | } else { |
| 1146 | Asm->EmitInt8(DW_CFA_offset_extended); |
| 1147 | Asm->EOL("DW_CFA_offset_extended"); |
| 1148 | Asm->EmitULEB128Bytes(Reg); |
| 1149 | Asm->EOL("Reg"); |
| 1150 | Asm->EmitULEB128Bytes(Offset); |
| 1151 | Asm->EOL("Offset"); |
| 1152 | } |
| 1153 | } |
| 1154 | } |
| 1155 | } |
| 1156 | |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 1157 | }; |
| 1158 | |
| 1159 | //===----------------------------------------------------------------------===// |
Devang Patel | f3ee514 | 2009-01-12 22:54:42 +0000 | [diff] [blame] | 1160 | /// SrcLineInfo - This class is used to record source line correspondence. |
Devang Patel | 9f8fcfc | 2009-01-08 17:19:22 +0000 | [diff] [blame] | 1161 | /// |
| 1162 | class SrcLineInfo { |
| 1163 | unsigned Line; // Source line number. |
| 1164 | unsigned Column; // Source column. |
| 1165 | unsigned SourceID; // Source ID number. |
| 1166 | unsigned LabelID; // Label in code ID number. |
| 1167 | public: |
| 1168 | SrcLineInfo(unsigned L, unsigned C, unsigned S, unsigned I) |
| 1169 | : Line(L), Column(C), SourceID(S), LabelID(I) {} |
| 1170 | |
| 1171 | // Accessors |
| 1172 | unsigned getLine() const { return Line; } |
| 1173 | unsigned getColumn() const { return Column; } |
| 1174 | unsigned getSourceID() const { return SourceID; } |
| 1175 | unsigned getLabelID() const { return LabelID; } |
| 1176 | }; |
| 1177 | |
| 1178 | |
| 1179 | //===----------------------------------------------------------------------===// |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 1180 | /// SrcFileInfo - This class is used to track source information. |
| 1181 | /// |
| 1182 | class SrcFileInfo { |
| 1183 | unsigned DirectoryID; // Directory ID number. |
| 1184 | std::string Name; // File name (not including directory.) |
| 1185 | public: |
| 1186 | SrcFileInfo(unsigned D, const std::string &N) : DirectoryID(D), Name(N) {} |
| 1187 | |
| 1188 | // Accessors |
| 1189 | unsigned getDirectoryID() const { return DirectoryID; } |
| 1190 | const std::string &getName() const { return Name; } |
| 1191 | |
| 1192 | /// operator== - Used by UniqueVector to locate entry. |
| 1193 | /// |
Devang Patel | bbdc820 | 2009-01-13 23:54:55 +0000 | [diff] [blame] | 1194 | bool operator==(const SrcFileInfo &SI) const { |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 1195 | return getDirectoryID() == SI.getDirectoryID() && getName() == SI.getName(); |
| 1196 | } |
| 1197 | |
| 1198 | /// operator< - Used by UniqueVector to locate entry. |
| 1199 | /// |
| 1200 | bool operator<(const SrcFileInfo &SI) const { |
| 1201 | return getDirectoryID() < SI.getDirectoryID() || |
| 1202 | (getDirectoryID() == SI.getDirectoryID() && getName() < SI.getName()); |
| 1203 | } |
| 1204 | }; |
| 1205 | |
| 1206 | //===----------------------------------------------------------------------===// |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 1207 | /// DbgVariable - This class is used to track local variable information. |
| 1208 | /// |
| 1209 | class DbgVariable { |
| 1210 | private: |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 1211 | DIVariable Var; // Variable Descriptor. |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 1212 | unsigned FrameIndex; // Variable frame index. |
| 1213 | |
| 1214 | public: |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 1215 | DbgVariable(DIVariable V, unsigned I) : Var(V), FrameIndex(I) {} |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 1216 | |
| 1217 | // Accessors. |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 1218 | DIVariable getVariable() const { return Var; } |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 1219 | unsigned getFrameIndex() const { return FrameIndex; } |
| 1220 | }; |
| 1221 | |
| 1222 | //===----------------------------------------------------------------------===// |
| 1223 | /// DbgScope - This class is used to track scope information. |
| 1224 | /// |
| 1225 | class DbgScope { |
| 1226 | private: |
| 1227 | DbgScope *Parent; // Parent to this scope. |
Devang Patel | 7103c6a | 2009-01-16 18:01:58 +0000 | [diff] [blame] | 1228 | DIDescriptor Desc; // Debug info descriptor for scope. |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 1229 | // Either subprogram or block. |
| 1230 | unsigned StartLabelID; // Label ID of the beginning of scope. |
| 1231 | unsigned EndLabelID; // Label ID of the end of scope. |
Devang Patel | 7103c6a | 2009-01-16 18:01:58 +0000 | [diff] [blame] | 1232 | SmallVector<DbgScope *, 4> Scopes; // Scopes defined in scope. |
Devang Patel | 9795da5 | 2009-01-10 02:42:49 +0000 | [diff] [blame] | 1233 | SmallVector<DbgVariable *, 8> Variables;// Variables declared in scope. |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 1234 | |
| 1235 | public: |
Devang Patel | 0e5200f | 2009-01-15 18:25:17 +0000 | [diff] [blame] | 1236 | DbgScope(DbgScope *P, DIDescriptor D) |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 1237 | : Parent(P), Desc(D), StartLabelID(0), EndLabelID(0), Scopes(), Variables() |
| 1238 | {} |
Devang Patel | 481ff5b | 2009-01-12 18:48:36 +0000 | [diff] [blame] | 1239 | ~DbgScope() { |
| 1240 | for (unsigned i = 0, N = Scopes.size(); i < N; ++i) delete Scopes[i]; |
| 1241 | for (unsigned j = 0, M = Variables.size(); j < M; ++j) delete Variables[j]; |
| 1242 | } |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 1243 | |
| 1244 | // Accessors. |
Devang Patel | 7103c6a | 2009-01-16 18:01:58 +0000 | [diff] [blame] | 1245 | DbgScope *getParent() const { return Parent; } |
| 1246 | DIDescriptor getDesc() const { return Desc; } |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 1247 | unsigned getStartLabelID() const { return StartLabelID; } |
| 1248 | unsigned getEndLabelID() const { return EndLabelID; } |
Devang Patel | 9795da5 | 2009-01-10 02:42:49 +0000 | [diff] [blame] | 1249 | SmallVector<DbgScope *, 4> &getScopes() { return Scopes; } |
| 1250 | SmallVector<DbgVariable *, 8> &getVariables() { return Variables; } |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 1251 | void setStartLabelID(unsigned S) { StartLabelID = S; } |
| 1252 | void setEndLabelID(unsigned E) { EndLabelID = E; } |
| 1253 | |
| 1254 | /// AddScope - Add a scope to the scope. |
| 1255 | /// |
| 1256 | void AddScope(DbgScope *S) { Scopes.push_back(S); } |
| 1257 | |
| 1258 | /// AddVariable - Add a variable to the scope. |
| 1259 | /// |
| 1260 | void AddVariable(DbgVariable *V) { Variables.push_back(V); } |
| 1261 | }; |
| 1262 | |
| 1263 | //===----------------------------------------------------------------------===// |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1264 | /// DwarfDebug - Emits Dwarf debug directives. |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 1265 | /// |
| 1266 | class DwarfDebug : public Dwarf { |
| 1267 | |
| 1268 | private: |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1269 | //===--------------------------------------------------------------------===// |
| 1270 | // Attributes used to construct specific Dwarf sections. |
| 1271 | // |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1272 | |
Devang Patel | 7e55b3a | 2009-01-17 06:51:37 +0000 | [diff] [blame] | 1273 | /// DW_CUs - All the compile units involved in this build. The index |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 1274 | /// of each entry in this vector corresponds to the sources in MMI. |
Devang Patel | 9f8fcfc | 2009-01-08 17:19:22 +0000 | [diff] [blame] | 1275 | DenseMap<Value *, CompileUnit *> DW_CUs; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1276 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1277 | /// AbbreviationsSet - Used to uniquely define abbreviations. |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1278 | /// |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 1279 | FoldingSet<DIEAbbrev> AbbreviationsSet; |
| 1280 | |
| 1281 | /// Abbreviations - A list of all the unique abbreviations in use. |
| 1282 | /// |
| 1283 | std::vector<DIEAbbrev *> Abbreviations; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1284 | |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 1285 | /// Directories - Uniquing vector for directories. |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 1286 | UniqueVector<std::string> Directories; |
| 1287 | |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 1288 | /// SourceFiles - Uniquing vector for source files. |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 1289 | UniqueVector<SrcFileInfo> SrcFiles; |
| 1290 | |
Devang Patel | 07354e5 | 2009-01-16 21:07:53 +0000 | [diff] [blame] | 1291 | /// Lines - List of of source line correspondence. |
Devang Patel | 9f8fcfc | 2009-01-08 17:19:22 +0000 | [diff] [blame] | 1292 | std::vector<SrcLineInfo> Lines; |
| 1293 | |
Devang Patel | 07354e5 | 2009-01-16 21:07:53 +0000 | [diff] [blame] | 1294 | /// ValuesSet - Used to uniquely define values. |
| 1295 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1296 | FoldingSet<DIEValue> ValuesSet; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1297 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1298 | /// Values - A list of all the unique values in use. |
| 1299 | /// |
| 1300 | std::vector<DIEValue *> Values; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1301 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1302 | /// StringPool - A UniqueVector of strings used by indirect references. |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1303 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1304 | UniqueVector<std::string> StringPool; |
| 1305 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1306 | /// SectionMap - Provides a unique id per text section. |
| 1307 | /// |
Anton Korobeynikov | d7ca416 | 2008-09-24 22:15:21 +0000 | [diff] [blame] | 1308 | UniqueVector<const Section*> SectionMap; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1309 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1310 | /// SectionSourceLines - Tracks line numbers per text section. |
| 1311 | /// |
Devang Patel | f3ee514 | 2009-01-12 22:54:42 +0000 | [diff] [blame] | 1312 | std::vector<std::vector<SrcLineInfo> > SectionSourceLines; |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1313 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 1314 | /// didInitial - Flag to indicate if initial emission has been done. |
| 1315 | /// |
| 1316 | bool didInitial; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1317 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 1318 | /// shouldEmit - Flag to indicate if debug information should be emitted. |
| 1319 | /// |
| 1320 | bool shouldEmit; |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1321 | |
Devang Patel | 0e5200f | 2009-01-15 18:25:17 +0000 | [diff] [blame] | 1322 | // RootDbgScope - Top level scope for the current function. |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 1323 | // |
| 1324 | DbgScope *RootDbgScope; |
| 1325 | |
| 1326 | // DbgScopeMap - Tracks the scopes in the current function. |
| 1327 | DenseMap<GlobalVariable *, DbgScope *> DbgScopeMap; |
| 1328 | |
Anton Korobeynikov | 185bc89 | 2007-05-13 17:30:11 +0000 | [diff] [blame] | 1329 | struct FunctionDebugFrameInfo { |
| 1330 | unsigned Number; |
| 1331 | std::vector<MachineMove> Moves; |
| 1332 | |
| 1333 | FunctionDebugFrameInfo(unsigned Num, const std::vector<MachineMove> &M): |
Dan Gohman | 81975f6 | 2007-08-27 14:50:10 +0000 | [diff] [blame] | 1334 | Number(Num), Moves(M) { } |
Anton Korobeynikov | 185bc89 | 2007-05-13 17:30:11 +0000 | [diff] [blame] | 1335 | }; |
| 1336 | |
| 1337 | std::vector<FunctionDebugFrameInfo> DebugFrames; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1338 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1339 | public: |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1340 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 1341 | /// ShouldEmitDwarf - Returns true if Dwarf declarations should be made. |
| 1342 | /// |
| 1343 | bool ShouldEmitDwarf() const { return shouldEmit; } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1344 | |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 1345 | /// AssignAbbrevNumber - Define a unique number for the abbreviation. |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1346 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1347 | void AssignAbbrevNumber(DIEAbbrev &Abbrev) { |
| 1348 | // Profile the node so that we can make it unique. |
| 1349 | FoldingSetNodeID ID; |
| 1350 | Abbrev.Profile(ID); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1351 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1352 | // Check the set for priors. |
| 1353 | DIEAbbrev *InSet = AbbreviationsSet.GetOrInsertNode(&Abbrev); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1354 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1355 | // If it's newly added. |
| 1356 | if (InSet == &Abbrev) { |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1357 | // Add to abbreviation list. |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1358 | Abbreviations.push_back(&Abbrev); |
| 1359 | // Assign the vector position + 1 as its number. |
| 1360 | Abbrev.setNumber(Abbreviations.size()); |
| 1361 | } else { |
| 1362 | // Assign existing abbreviation number. |
| 1363 | Abbrev.setNumber(InSet->getNumber()); |
| 1364 | } |
| 1365 | } |
| 1366 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1367 | /// NewString - Add a string to the constant pool and returns a label. |
| 1368 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1369 | DWLabel NewString(const std::string &String) { |
| 1370 | unsigned StringID = StringPool.insert(String); |
| 1371 | return DWLabel("string", StringID); |
| 1372 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1373 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1374 | /// NewDIEntry - Creates a new DIEntry to be a proxy for a debug information |
| 1375 | /// entry. |
| 1376 | DIEntry *NewDIEntry(DIE *Entry = NULL) { |
| 1377 | DIEntry *Value; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1378 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1379 | if (Entry) { |
| 1380 | FoldingSetNodeID ID; |
Jim Laskey | 5496f01 | 2006-11-09 14:52:14 +0000 | [diff] [blame] | 1381 | DIEntry::Profile(ID, Entry); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1382 | void *Where; |
| 1383 | Value = static_cast<DIEntry *>(ValuesSet.FindNodeOrInsertPos(ID, Where)); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1384 | |
Jim Laskey | f673388 | 2006-11-02 21:48:18 +0000 | [diff] [blame] | 1385 | if (Value) return Value; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1386 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1387 | Value = new DIEntry(Entry); |
| 1388 | ValuesSet.InsertNode(Value, Where); |
| 1389 | } else { |
| 1390 | Value = new DIEntry(Entry); |
| 1391 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1392 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1393 | Values.push_back(Value); |
| 1394 | return Value; |
| 1395 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1396 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1397 | /// SetDIEntry - Set a DIEntry once the debug information entry is defined. |
| 1398 | /// |
| 1399 | void SetDIEntry(DIEntry *Value, DIE *Entry) { |
| 1400 | Value->Entry = Entry; |
| 1401 | // Add to values set if not already there. If it is, we merely have a |
| 1402 | // duplicate in the values list (no harm.) |
| 1403 | ValuesSet.GetOrInsertNode(Value); |
| 1404 | } |
| 1405 | |
| 1406 | /// AddUInt - Add an unsigned integer attribute data and value. |
| 1407 | /// |
| 1408 | void AddUInt(DIE *Die, unsigned Attribute, unsigned Form, uint64_t Integer) { |
| 1409 | if (!Form) Form = DIEInteger::BestForm(false, Integer); |
| 1410 | |
| 1411 | FoldingSetNodeID ID; |
Jim Laskey | 5496f01 | 2006-11-09 14:52:14 +0000 | [diff] [blame] | 1412 | DIEInteger::Profile(ID, Integer); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1413 | void *Where; |
| 1414 | DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where); |
| 1415 | if (!Value) { |
| 1416 | Value = new DIEInteger(Integer); |
| 1417 | ValuesSet.InsertNode(Value, Where); |
| 1418 | Values.push_back(Value); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1419 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1420 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1421 | Die->AddValue(Attribute, Form, Value); |
| 1422 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1423 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1424 | /// AddSInt - Add an signed integer attribute data and value. |
| 1425 | /// |
| 1426 | void AddSInt(DIE *Die, unsigned Attribute, unsigned Form, int64_t Integer) { |
| 1427 | if (!Form) Form = DIEInteger::BestForm(true, Integer); |
| 1428 | |
| 1429 | FoldingSetNodeID ID; |
Jim Laskey | 5496f01 | 2006-11-09 14:52:14 +0000 | [diff] [blame] | 1430 | DIEInteger::Profile(ID, (uint64_t)Integer); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1431 | void *Where; |
| 1432 | DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where); |
| 1433 | if (!Value) { |
| 1434 | Value = new DIEInteger(Integer); |
| 1435 | ValuesSet.InsertNode(Value, Where); |
| 1436 | Values.push_back(Value); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1437 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1438 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1439 | Die->AddValue(Attribute, Form, Value); |
| 1440 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1441 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1442 | /// AddString - Add a std::string attribute data and value. |
| 1443 | /// |
| 1444 | void AddString(DIE *Die, unsigned Attribute, unsigned Form, |
| 1445 | const std::string &String) { |
| 1446 | FoldingSetNodeID ID; |
Jim Laskey | 5496f01 | 2006-11-09 14:52:14 +0000 | [diff] [blame] | 1447 | DIEString::Profile(ID, String); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1448 | void *Where; |
| 1449 | DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where); |
| 1450 | if (!Value) { |
| 1451 | Value = new DIEString(String); |
| 1452 | ValuesSet.InsertNode(Value, Where); |
| 1453 | Values.push_back(Value); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1454 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1455 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1456 | Die->AddValue(Attribute, Form, Value); |
| 1457 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1458 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1459 | /// AddLabel - Add a Dwarf label attribute data and value. |
| 1460 | /// |
| 1461 | void AddLabel(DIE *Die, unsigned Attribute, unsigned Form, |
| 1462 | const DWLabel &Label) { |
| 1463 | FoldingSetNodeID ID; |
Jim Laskey | 5496f01 | 2006-11-09 14:52:14 +0000 | [diff] [blame] | 1464 | DIEDwarfLabel::Profile(ID, Label); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1465 | void *Where; |
| 1466 | DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where); |
| 1467 | if (!Value) { |
| 1468 | Value = new DIEDwarfLabel(Label); |
| 1469 | ValuesSet.InsertNode(Value, Where); |
| 1470 | Values.push_back(Value); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1471 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1472 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1473 | Die->AddValue(Attribute, Form, Value); |
| 1474 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1475 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1476 | /// AddObjectLabel - Add an non-Dwarf label attribute data and value. |
| 1477 | /// |
| 1478 | void AddObjectLabel(DIE *Die, unsigned Attribute, unsigned Form, |
| 1479 | const std::string &Label) { |
| 1480 | FoldingSetNodeID ID; |
Jim Laskey | 5496f01 | 2006-11-09 14:52:14 +0000 | [diff] [blame] | 1481 | DIEObjectLabel::Profile(ID, Label); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1482 | void *Where; |
| 1483 | DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where); |
| 1484 | if (!Value) { |
| 1485 | Value = new DIEObjectLabel(Label); |
| 1486 | ValuesSet.InsertNode(Value, Where); |
| 1487 | Values.push_back(Value); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1488 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1489 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1490 | Die->AddValue(Attribute, Form, Value); |
| 1491 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1492 | |
Argyrios Kyrtzidis | f7acf8f | 2008-06-18 19:27:37 +0000 | [diff] [blame] | 1493 | /// AddSectionOffset - Add a section offset label attribute data and value. |
| 1494 | /// |
| 1495 | void AddSectionOffset(DIE *Die, unsigned Attribute, unsigned Form, |
| 1496 | const DWLabel &Label, const DWLabel &Section, |
| 1497 | bool isEH = false, bool useSet = true) { |
| 1498 | FoldingSetNodeID ID; |
| 1499 | DIESectionOffset::Profile(ID, Label, Section); |
| 1500 | void *Where; |
| 1501 | DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where); |
| 1502 | if (!Value) { |
| 1503 | Value = new DIESectionOffset(Label, Section, isEH, useSet); |
| 1504 | ValuesSet.InsertNode(Value, Where); |
| 1505 | Values.push_back(Value); |
| 1506 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1507 | |
Argyrios Kyrtzidis | f7acf8f | 2008-06-18 19:27:37 +0000 | [diff] [blame] | 1508 | Die->AddValue(Attribute, Form, Value); |
| 1509 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1510 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1511 | /// AddDelta - Add a label delta attribute data and value. |
| 1512 | /// |
| 1513 | void AddDelta(DIE *Die, unsigned Attribute, unsigned Form, |
| 1514 | const DWLabel &Hi, const DWLabel &Lo) { |
| 1515 | FoldingSetNodeID ID; |
Jim Laskey | 5496f01 | 2006-11-09 14:52:14 +0000 | [diff] [blame] | 1516 | DIEDelta::Profile(ID, Hi, Lo); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1517 | void *Where; |
| 1518 | DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where); |
| 1519 | if (!Value) { |
| 1520 | Value = new DIEDelta(Hi, Lo); |
| 1521 | ValuesSet.InsertNode(Value, Where); |
| 1522 | Values.push_back(Value); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1523 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1524 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1525 | Die->AddValue(Attribute, Form, Value); |
| 1526 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1527 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1528 | /// AddDIEntry - Add a DIE attribute data and value. |
| 1529 | /// |
| 1530 | void AddDIEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry) { |
| 1531 | Die->AddValue(Attribute, Form, NewDIEntry(Entry)); |
| 1532 | } |
| 1533 | |
| 1534 | /// AddBlock - Add block data. |
| 1535 | /// |
| 1536 | void AddBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block) { |
| 1537 | Block->ComputeSize(*this); |
| 1538 | FoldingSetNodeID ID; |
| 1539 | Block->Profile(ID); |
| 1540 | void *Where; |
| 1541 | DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where); |
| 1542 | if (!Value) { |
| 1543 | Value = Block; |
| 1544 | ValuesSet.InsertNode(Value, Where); |
| 1545 | Values.push_back(Value); |
| 1546 | } else { |
Chris Lattner | c369bd7 | 2007-09-21 18:25:53 +0000 | [diff] [blame] | 1547 | // Already exists, reuse the previous one. |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1548 | delete Block; |
Chris Lattner | c369bd7 | 2007-09-21 18:25:53 +0000 | [diff] [blame] | 1549 | Block = cast<DIEBlock>(Value); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1550 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1551 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1552 | Die->AddValue(Attribute, Block->BestForm(), Value); |
| 1553 | } |
| 1554 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1555 | private: |
| 1556 | |
| 1557 | /// AddSourceLine - Add location information to specified debug information |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1558 | /// entry. |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 1559 | void AddSourceLine(DIE *Die, const DIVariable *V) { |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 1560 | unsigned FileID = 0; |
| 1561 | unsigned Line = V->getLineNumber(); |
| 1562 | if (V->getVersion() < DIDescriptor::Version7) { |
| 1563 | // Version6 or earlier. Use compile unit info to get file id. |
| 1564 | CompileUnit *Unit = FindCompileUnit(V->getCompileUnit()); |
| 1565 | FileID = Unit->getID(); |
| 1566 | } else { |
| 1567 | // Version7 or newer, use filename and directory info from DIVariable |
| 1568 | // directly. |
| 1569 | unsigned DID = Directories.idFor(V->getDirectory()); |
| 1570 | FileID = SrcFiles.idFor(SrcFileInfo(DID, V->getFilename())); |
| 1571 | } |
| 1572 | AddUInt(Die, DW_AT_decl_file, 0, FileID); |
| 1573 | AddUInt(Die, DW_AT_decl_line, 0, Line); |
| 1574 | } |
| 1575 | |
| 1576 | /// AddSourceLine - Add location information to specified debug information |
| 1577 | /// entry. |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 1578 | void AddSourceLine(DIE *Die, const DIGlobal *G) { |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 1579 | unsigned FileID = 0; |
| 1580 | unsigned Line = G->getLineNumber(); |
| 1581 | if (G->getVersion() < DIDescriptor::Version7) { |
| 1582 | // Version6 or earlier. Use compile unit info to get file id. |
| 1583 | CompileUnit *Unit = FindCompileUnit(G->getCompileUnit()); |
| 1584 | FileID = Unit->getID(); |
| 1585 | } else { |
| 1586 | // Version7 or newer, use filename and directory info from DIGlobal |
| 1587 | // directly. |
| 1588 | unsigned DID = Directories.idFor(G->getDirectory()); |
| 1589 | FileID = SrcFiles.idFor(SrcFileInfo(DID, G->getFilename())); |
| 1590 | } |
| 1591 | AddUInt(Die, DW_AT_decl_file, 0, FileID); |
| 1592 | AddUInt(Die, DW_AT_decl_line, 0, Line); |
| 1593 | } |
| 1594 | |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 1595 | void AddSourceLine(DIE *Die, const DIType *Ty) { |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 1596 | unsigned FileID = 0; |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 1597 | unsigned Line = Ty->getLineNumber(); |
| 1598 | if (Ty->getVersion() < DIDescriptor::Version7) { |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 1599 | // Version6 or earlier. Use compile unit info to get file id. |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 1600 | CompileUnit *Unit = FindCompileUnit(Ty->getCompileUnit()); |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 1601 | FileID = Unit->getID(); |
| 1602 | } else { |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 1603 | // Version7 or newer, use filename and directory info from DIType |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 1604 | // directly. |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 1605 | unsigned DID = Directories.idFor(Ty->getDirectory()); |
| 1606 | FileID = SrcFiles.idFor(SrcFileInfo(DID, Ty->getFilename())); |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 1607 | } |
| 1608 | AddUInt(Die, DW_AT_decl_file, 0, FileID); |
| 1609 | AddUInt(Die, DW_AT_decl_line, 0, Line); |
| 1610 | } |
| 1611 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1612 | /// AddAddress - Add an address attribute to a die based on the location |
| 1613 | /// provided. |
| 1614 | void AddAddress(DIE *Die, unsigned Attribute, |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1615 | const MachineLocation &Location) { |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 1616 | unsigned Reg = RI->getDwarfRegNum(Location.getReg(), false); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1617 | DIEBlock *Block = new DIEBlock(); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1618 | |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 1619 | if (Location.isReg()) { |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1620 | if (Reg < 32) { |
| 1621 | AddUInt(Block, 0, DW_FORM_data1, DW_OP_reg0 + Reg); |
| 1622 | } else { |
| 1623 | AddUInt(Block, 0, DW_FORM_data1, DW_OP_regx); |
| 1624 | AddUInt(Block, 0, DW_FORM_udata, Reg); |
| 1625 | } |
| 1626 | } else { |
| 1627 | if (Reg < 32) { |
| 1628 | AddUInt(Block, 0, DW_FORM_data1, DW_OP_breg0 + Reg); |
| 1629 | } else { |
| 1630 | AddUInt(Block, 0, DW_FORM_data1, DW_OP_bregx); |
| 1631 | AddUInt(Block, 0, DW_FORM_udata, Reg); |
| 1632 | } |
| 1633 | AddUInt(Block, 0, DW_FORM_sdata, Location.getOffset()); |
| 1634 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1635 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1636 | AddBlock(Die, Attribute, 0, Block); |
| 1637 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1638 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1639 | /// AddBasicType - Add a new basic type attribute to the specified entity. |
| 1640 | /// |
| 1641 | void AddBasicType(DIE *Entity, CompileUnit *Unit, |
| 1642 | const std::string &Name, |
| 1643 | unsigned Encoding, unsigned Size) { |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1644 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1645 | DIE Buffer(DW_TAG_base_type); |
| 1646 | AddUInt(&Buffer, DW_AT_byte_size, 0, Size); |
| 1647 | AddUInt(&Buffer, DW_AT_encoding, DW_FORM_data1, Encoding); |
| 1648 | if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name); |
Devang Patel | 9ede3f2 | 2009-01-05 17:44:11 +0000 | [diff] [blame] | 1649 | DIE *BasicTypeDie = Unit->AddDie(Buffer); |
| 1650 | AddDIEntry(Entity, DW_AT_type, DW_FORM_ref4, BasicTypeDie); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1651 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1652 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1653 | /// AddPointerType - Add a new pointer type attribute to the specified entity. |
| 1654 | /// |
| 1655 | void AddPointerType(DIE *Entity, CompileUnit *Unit, const std::string &Name) { |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1656 | DIE Buffer(DW_TAG_pointer_type); |
Dan Gohman | 8248294 | 2007-09-27 23:12:31 +0000 | [diff] [blame] | 1657 | AddUInt(&Buffer, DW_AT_byte_size, 0, TD->getPointerSize()); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1658 | if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name); |
Devang Patel | ca03c27 | 2009-01-05 17:45:59 +0000 | [diff] [blame] | 1659 | DIE *PointerTypeDie = Unit->AddDie(Buffer); |
| 1660 | AddDIEntry(Entity, DW_AT_type, DW_FORM_ref4, PointerTypeDie); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1661 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 1662 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 1663 | /// AddType - Add a new type attribute to the specified entity. |
Devang Patel | 48d190f | 2009-01-05 21:47:57 +0000 | [diff] [blame] | 1664 | void AddType(CompileUnit *DW_Unit, DIE *Entity, DIType Ty) { |
| 1665 | if (Ty.isNull()) { |
| 1666 | AddBasicType(Entity, DW_Unit, "", DW_ATE_signed, sizeof(int32_t)); |
| 1667 | return; |
| 1668 | } |
| 1669 | |
| 1670 | // Check for pre-existence. |
| 1671 | DIEntry *&Slot = DW_Unit->getDIEntrySlotFor(Ty.getGV()); |
| 1672 | // If it exists then use the existing value. |
| 1673 | if (Slot) { |
| 1674 | Entity->AddValue(DW_AT_type, DW_FORM_ref4, Slot); |
| 1675 | return; |
| 1676 | } |
| 1677 | |
| 1678 | // Set up proxy. |
| 1679 | Slot = NewDIEntry(); |
| 1680 | |
| 1681 | // Construct type. |
| 1682 | DIE Buffer(DW_TAG_base_type); |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 1683 | if (Ty.isBasicType(Ty.getTag())) |
| 1684 | ConstructTypeDIE(DW_Unit, Buffer, DIBasicType(Ty.getGV())); |
| 1685 | else if (Ty.isDerivedType(Ty.getTag())) |
| 1686 | ConstructTypeDIE(DW_Unit, Buffer, DIDerivedType(Ty.getGV())); |
| 1687 | else { |
| 1688 | assert (Ty.isCompositeType(Ty.getTag()) && "Unknown kind of DIType"); |
| 1689 | ConstructTypeDIE(DW_Unit, Buffer, DICompositeType(Ty.getGV())); |
| 1690 | } |
| 1691 | |
Devang Patel | 48d190f | 2009-01-05 21:47:57 +0000 | [diff] [blame] | 1692 | // Add debug information entry to entity and unit. |
| 1693 | DIE *Die = DW_Unit->AddDie(Buffer); |
| 1694 | SetDIEntry(Slot, Die); |
| 1695 | Entity->AddValue(DW_AT_type, DW_FORM_ref4, Slot); |
| 1696 | } |
| 1697 | |
Devang Patel | e520273 | 2009-01-05 19:07:53 +0000 | [diff] [blame] | 1698 | /// ConstructTypeDIE - Construct basic type die from DIBasicType. |
| 1699 | void ConstructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer, |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 1700 | DIBasicType BTy) { |
Devang Patel | 08f053f | 2009-01-05 17:57:47 +0000 | [diff] [blame] | 1701 | |
| 1702 | // Get core information. |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 1703 | const std::string &Name = BTy.getName(); |
Devang Patel | 08f053f | 2009-01-05 17:57:47 +0000 | [diff] [blame] | 1704 | Buffer.setTag(DW_TAG_base_type); |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 1705 | AddUInt(&Buffer, DW_AT_encoding, DW_FORM_data1, BTy.getEncoding()); |
Devang Patel | 08f053f | 2009-01-05 17:57:47 +0000 | [diff] [blame] | 1706 | // Add name if not anonymous or intermediate type. |
| 1707 | if (!Name.empty()) |
| 1708 | AddString(&Buffer, DW_AT_name, DW_FORM_string, Name); |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 1709 | uint64_t Size = BTy.getSizeInBits() >> 3; |
Devang Patel | 08f053f | 2009-01-05 17:57:47 +0000 | [diff] [blame] | 1710 | AddUInt(&Buffer, DW_AT_byte_size, 0, Size); |
| 1711 | } |
| 1712 | |
Devang Patel | e520273 | 2009-01-05 19:07:53 +0000 | [diff] [blame] | 1713 | /// ConstructTypeDIE - Construct derived type die from DIDerivedType. |
| 1714 | void ConstructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer, |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 1715 | DIDerivedType DTy) { |
Devang Patel | 08f053f | 2009-01-05 17:57:47 +0000 | [diff] [blame] | 1716 | |
| 1717 | // Get core information. |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 1718 | const std::string &Name = DTy.getName(); |
| 1719 | uint64_t Size = DTy.getSizeInBits() >> 3; |
| 1720 | unsigned Tag = DTy.getTag(); |
Devang Patel | 08f053f | 2009-01-05 17:57:47 +0000 | [diff] [blame] | 1721 | // FIXME - Workaround for templates. |
| 1722 | if (Tag == DW_TAG_inheritance) Tag = DW_TAG_reference_type; |
| 1723 | |
| 1724 | Buffer.setTag(Tag); |
| 1725 | // Map to main type, void will not have a type. |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 1726 | DIType FromTy = DTy.getTypeDerivedFrom(); |
Devang Patel | 48d190f | 2009-01-05 21:47:57 +0000 | [diff] [blame] | 1727 | AddType(DW_Unit, &Buffer, FromTy); |
Devang Patel | 08f053f | 2009-01-05 17:57:47 +0000 | [diff] [blame] | 1728 | |
| 1729 | // Add name if not anonymous or intermediate type. |
| 1730 | if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name); |
| 1731 | |
| 1732 | // Add size if non-zero (derived types might be zero-sized.) |
| 1733 | if (Size) |
| 1734 | AddUInt(&Buffer, DW_AT_byte_size, 0, Size); |
| 1735 | |
| 1736 | // Add source line info if available and TyDesc is not a forward |
| 1737 | // declaration. |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 1738 | // FIXME - Enable this. if (!DTy.isForwardDecl()) |
Devang Patel | 08f053f | 2009-01-05 17:57:47 +0000 | [diff] [blame] | 1739 | // FIXME - Enable this. AddSourceLine(&Buffer, *DTy); |
| 1740 | } |
| 1741 | |
Devang Patel | f421533 | 2009-01-05 19:55:51 +0000 | [diff] [blame] | 1742 | /// ConstructTypeDIE - Construct type DIE from DICompositeType. |
| 1743 | void ConstructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer, |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 1744 | DICompositeType CTy) { |
Devang Patel | f421533 | 2009-01-05 19:55:51 +0000 | [diff] [blame] | 1745 | |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 1746 | // Get core information. |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 1747 | const std::string &Name = CTy.getName(); |
| 1748 | uint64_t Size = CTy.getSizeInBits() >> 3; |
| 1749 | unsigned Tag = CTy.getTag(); |
Devang Patel | f421533 | 2009-01-05 19:55:51 +0000 | [diff] [blame] | 1750 | switch (Tag) { |
| 1751 | case DW_TAG_vector_type: |
| 1752 | case DW_TAG_array_type: |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 1753 | ConstructArrayTypeDIE(DW_Unit, Buffer, &CTy); |
Devang Patel | f421533 | 2009-01-05 19:55:51 +0000 | [diff] [blame] | 1754 | break; |
Devang Patel | eab4a2e | 2009-01-20 18:35:14 +0000 | [diff] [blame^] | 1755 | case DW_TAG_enumeration_type: |
| 1756 | { |
| 1757 | DIArray Elements = CTy.getTypeArray(); |
| 1758 | // Add enumerators to enumeration type. |
| 1759 | for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) { |
| 1760 | DIE *ElemDie = NULL; |
| 1761 | DIEnumerator Enum(Elements.getElement(i).getGV()); |
| 1762 | ElemDie = ConstructEnumTypeDIE(DW_Unit, &Enum); |
| 1763 | Buffer.AddChild(ElemDie); |
| 1764 | } |
| 1765 | } |
| 1766 | break; |
Devang Patel | f421533 | 2009-01-05 19:55:51 +0000 | [diff] [blame] | 1767 | case DW_TAG_subroutine_type: |
| 1768 | { |
| 1769 | // Add prototype flag. |
| 1770 | AddUInt(&Buffer, DW_AT_prototyped, DW_FORM_flag, 1); |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 1771 | DIArray Elements = CTy.getTypeArray(); |
Devang Patel | f421533 | 2009-01-05 19:55:51 +0000 | [diff] [blame] | 1772 | // Add return type. |
Devang Patel | 48d190f | 2009-01-05 21:47:57 +0000 | [diff] [blame] | 1773 | DIDescriptor RTy = Elements.getElement(0); |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 1774 | AddType(DW_Unit, &Buffer, DIType(RTy.getGV())); |
Devang Patel | 48d190f | 2009-01-05 21:47:57 +0000 | [diff] [blame] | 1775 | |
Devang Patel | f421533 | 2009-01-05 19:55:51 +0000 | [diff] [blame] | 1776 | // Add arguments. |
| 1777 | for (unsigned i = 1, N = Elements.getNumElements(); i < N; ++i) { |
| 1778 | DIE *Arg = new DIE(DW_TAG_formal_parameter); |
Devang Patel | 48d190f | 2009-01-05 21:47:57 +0000 | [diff] [blame] | 1779 | DIDescriptor Ty = Elements.getElement(i); |
Devang Patel | 7ab2450 | 2009-01-17 06:57:25 +0000 | [diff] [blame] | 1780 | AddType(DW_Unit, Arg, DIType(Ty.getGV())); |
Devang Patel | f421533 | 2009-01-05 19:55:51 +0000 | [diff] [blame] | 1781 | Buffer.AddChild(Arg); |
| 1782 | } |
| 1783 | } |
| 1784 | break; |
| 1785 | case DW_TAG_structure_type: |
| 1786 | case DW_TAG_union_type: |
| 1787 | { |
| 1788 | // Add elements to structure type. |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 1789 | DIArray Elements = CTy.getTypeArray(); |
Devang Patel | 153745c | 2009-01-16 00:50:53 +0000 | [diff] [blame] | 1790 | |
| 1791 | // A forward struct declared type may not have elements available. |
| 1792 | if (Elements.isNull()) |
| 1793 | break; |
| 1794 | |
Devang Patel | f421533 | 2009-01-05 19:55:51 +0000 | [diff] [blame] | 1795 | // Add elements to structure type. |
| 1796 | for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) { |
| 1797 | DIDescriptor Element = Elements.getElement(i); |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 1798 | DIE *ElemDie = NULL; |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 1799 | if (Element.getTag() == dwarf::DW_TAG_subprogram) |
Devang Patel | 2d1768c | 2009-01-17 08:05:14 +0000 | [diff] [blame] | 1800 | ElemDie = CreateSubprogramDIE(DW_Unit, |
| 1801 | DISubprogram(Element.getGV())); |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 1802 | else if (Element.getTag() == dwarf::DW_TAG_variable) // ??? |
| 1803 | ElemDie = CreateGlobalVariableDIE(DW_Unit, |
| 1804 | DIGlobalVariable(Element.getGV())); |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 1805 | else { |
| 1806 | DIDerivedType DT = DIDerivedType(Element.getGV()); |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 1807 | assert (DT.isDerivedType(DT.getTag()) |
Devang Patel | 2d1768c | 2009-01-17 08:05:14 +0000 | [diff] [blame] | 1808 | && "Unexpected struct element type"); |
| 1809 | ElemDie = new DIE(DT.getTag()); |
| 1810 | AddType(DW_Unit, ElemDie, DT); |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 1811 | } |
Devang Patel | 2d1768c | 2009-01-17 08:05:14 +0000 | [diff] [blame] | 1812 | Buffer.AddChild(ElemDie); |
Devang Patel | f421533 | 2009-01-05 19:55:51 +0000 | [diff] [blame] | 1813 | } |
| 1814 | } |
| 1815 | break; |
| 1816 | default: |
| 1817 | break; |
| 1818 | } |
| 1819 | |
| 1820 | // Add name if not anonymous or intermediate type. |
| 1821 | if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name); |
| 1822 | |
| 1823 | // Add size if non-zero (derived types might be zero-sized.) |
| 1824 | if (Size) |
| 1825 | AddUInt(&Buffer, DW_AT_byte_size, 0, Size); |
| 1826 | else { |
| 1827 | // Add zero size even if it is not a forward declaration. |
| 1828 | // FIXME - Enable this. |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 1829 | // if (!CTy.isDefinition()) |
Devang Patel | f421533 | 2009-01-05 19:55:51 +0000 | [diff] [blame] | 1830 | // AddUInt(&Buffer, DW_AT_declaration, DW_FORM_flag, 1); |
| 1831 | // else |
| 1832 | // AddUInt(&Buffer, DW_AT_byte_size, 0, 0); |
| 1833 | } |
| 1834 | |
| 1835 | // Add source line info if available and TyDesc is not a forward |
| 1836 | // declaration. |
| 1837 | // FIXME - Enable this. |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 1838 | // if (CTy.isForwardDecl()) |
Devang Patel | f421533 | 2009-01-05 19:55:51 +0000 | [diff] [blame] | 1839 | // AddSourceLine(&Buffer, *CTy); |
| 1840 | } |
| 1841 | |
Devang Patel | 68afdc3 | 2009-01-05 18:33:01 +0000 | [diff] [blame] | 1842 | // ConstructSubrangeDIE - Construct subrange DIE from DISubrange. |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 1843 | void ConstructSubrangeDIE (DIE &Buffer, DISubrange SR, DIE *IndexTy) { |
| 1844 | int64_t L = SR.getLo(); |
| 1845 | int64_t H = SR.getHi(); |
Devang Patel | 68afdc3 | 2009-01-05 18:33:01 +0000 | [diff] [blame] | 1846 | DIE *DW_Subrange = new DIE(DW_TAG_subrange_type); |
| 1847 | if (L != H) { |
| 1848 | AddDIEntry(DW_Subrange, DW_AT_type, DW_FORM_ref4, IndexTy); |
| 1849 | if (L) |
Devang Patel | 2d1768c | 2009-01-17 08:05:14 +0000 | [diff] [blame] | 1850 | AddSInt(DW_Subrange, DW_AT_lower_bound, 0, L); |
| 1851 | AddSInt(DW_Subrange, DW_AT_upper_bound, 0, H); |
Devang Patel | 68afdc3 | 2009-01-05 18:33:01 +0000 | [diff] [blame] | 1852 | } |
| 1853 | Buffer.AddChild(DW_Subrange); |
| 1854 | } |
| 1855 | |
| 1856 | /// ConstructArrayTypeDIE - Construct array type DIE from DICompositeType. |
| 1857 | void ConstructArrayTypeDIE(CompileUnit *DW_Unit, DIE &Buffer, |
| 1858 | DICompositeType *CTy) { |
| 1859 | Buffer.setTag(DW_TAG_array_type); |
| 1860 | if (CTy->getTag() == DW_TAG_vector_type) |
| 1861 | AddUInt(&Buffer, DW_AT_GNU_vector, DW_FORM_flag, 1); |
| 1862 | |
| 1863 | DIArray Elements = CTy->getTypeArray(); |
Devang Patel | 48d190f | 2009-01-05 21:47:57 +0000 | [diff] [blame] | 1864 | AddType(DW_Unit, &Buffer, CTy->getTypeDerivedFrom()); |
Devang Patel | 68afdc3 | 2009-01-05 18:33:01 +0000 | [diff] [blame] | 1865 | |
| 1866 | // Construct an anonymous type for index type. |
| 1867 | DIE IdxBuffer(DW_TAG_base_type); |
| 1868 | AddUInt(&IdxBuffer, DW_AT_byte_size, 0, sizeof(int32_t)); |
| 1869 | AddUInt(&IdxBuffer, DW_AT_encoding, DW_FORM_data1, DW_ATE_signed); |
| 1870 | DIE *IndexTy = DW_Unit->AddDie(IdxBuffer); |
| 1871 | |
| 1872 | // Add subranges to array type. |
| 1873 | for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) { |
Devang Patel | f421533 | 2009-01-05 19:55:51 +0000 | [diff] [blame] | 1874 | DIDescriptor Element = Elements.getElement(i); |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 1875 | if (Element.getTag() == dwarf::DW_TAG_subrange_type) |
| 1876 | ConstructSubrangeDIE(Buffer, DISubrange(Element.getGV()), IndexTy); |
Devang Patel | 68afdc3 | 2009-01-05 18:33:01 +0000 | [diff] [blame] | 1877 | } |
| 1878 | } |
| 1879 | |
Devang Patel | c69bf2c | 2009-01-05 18:38:38 +0000 | [diff] [blame] | 1880 | /// ConstructEnumTypeDIE - Construct enum type DIE from |
| 1881 | /// DIEnumerator. |
Devang Patel | eab4a2e | 2009-01-20 18:35:14 +0000 | [diff] [blame^] | 1882 | DIE *ConstructEnumTypeDIE(CompileUnit *DW_Unit, DIEnumerator *ETy) { |
Devang Patel | c69bf2c | 2009-01-05 18:38:38 +0000 | [diff] [blame] | 1883 | |
| 1884 | DIE *Enumerator = new DIE(DW_TAG_enumerator); |
| 1885 | AddString(Enumerator, DW_AT_name, DW_FORM_string, ETy->getName()); |
| 1886 | int64_t Value = ETy->getEnumValue(); |
| 1887 | AddSInt(Enumerator, DW_AT_const_value, DW_FORM_sdata, Value); |
Devang Patel | eab4a2e | 2009-01-20 18:35:14 +0000 | [diff] [blame^] | 1888 | return Enumerator; |
Devang Patel | c69bf2c | 2009-01-05 18:38:38 +0000 | [diff] [blame] | 1889 | } |
Devang Patel | 68afdc3 | 2009-01-05 18:33:01 +0000 | [diff] [blame] | 1890 | |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 1891 | /// CreateGlobalVariableDIE - Create new DIE using GV. |
| 1892 | DIE *CreateGlobalVariableDIE(CompileUnit *DW_Unit, const DIGlobalVariable &GV) |
| 1893 | { |
| 1894 | DIE *GVDie = new DIE(DW_TAG_variable); |
| 1895 | AddString(GVDie, DW_AT_name, DW_FORM_string, GV.getName()); |
| 1896 | const std::string &LinkageName = GV.getLinkageName(); |
Devang Patel | 86ae142 | 2009-01-05 18:59:44 +0000 | [diff] [blame] | 1897 | if (!LinkageName.empty()) |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 1898 | AddString(GVDie, DW_AT_MIPS_linkage_name, DW_FORM_string, LinkageName); |
| 1899 | AddType(DW_Unit, GVDie, GV.getType()); |
| 1900 | if (!GV.isLocalToUnit()) |
| 1901 | AddUInt(GVDie, DW_AT_external, DW_FORM_flag, 1); |
| 1902 | AddSourceLine(GVDie, &GV); |
| 1903 | return GVDie; |
Devang Patel | 86ae142 | 2009-01-05 18:59:44 +0000 | [diff] [blame] | 1904 | } |
| 1905 | |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 1906 | /// CreateSubprogramDIE - Create new DIE using SP. |
| 1907 | DIE *CreateSubprogramDIE(CompileUnit *DW_Unit, |
Devang Patel | 2d1768c | 2009-01-17 08:05:14 +0000 | [diff] [blame] | 1908 | const DISubprogram &SP, |
| 1909 | bool IsConstructor = false) { |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 1910 | DIE *SPDie = new DIE(DW_TAG_subprogram); |
| 1911 | AddString(SPDie, DW_AT_name, DW_FORM_string, SP.getName()); |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 1912 | const std::string &LinkageName = SP.getLinkageName(); |
Devang Patel | 86ae142 | 2009-01-05 18:59:44 +0000 | [diff] [blame] | 1913 | if (!LinkageName.empty()) |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 1914 | AddString(SPDie, DW_AT_MIPS_linkage_name, DW_FORM_string, |
Devang Patel | 2d1768c | 2009-01-17 08:05:14 +0000 | [diff] [blame] | 1915 | LinkageName); |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 1916 | AddSourceLine(SPDie, &SP); |
Devang Patel | 86ae142 | 2009-01-05 18:59:44 +0000 | [diff] [blame] | 1917 | |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 1918 | DICompositeType SPTy = SP.getType(); |
| 1919 | DIArray Args = SPTy.getTypeArray(); |
| 1920 | |
Devang Patel | 86ae142 | 2009-01-05 18:59:44 +0000 | [diff] [blame] | 1921 | // Add Return Type. |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 1922 | if (!IsConstructor) |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 1923 | AddType(DW_Unit, SPDie, DIType(Args.getElement(0).getGV())); |
| 1924 | |
Devang Patel | 86ae142 | 2009-01-05 18:59:44 +0000 | [diff] [blame] | 1925 | // Add arguments. |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 1926 | if (!Args.isNull()) |
| 1927 | for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) { |
Devang Patel | 2d1768c | 2009-01-17 08:05:14 +0000 | [diff] [blame] | 1928 | DIE *Arg = new DIE(DW_TAG_formal_parameter); |
| 1929 | AddType(DW_Unit, Arg, DIType(Args.getElement(i).getGV())); |
| 1930 | AddUInt(Arg, DW_AT_artificial, DW_FORM_flag, 1); // ??? |
| 1931 | SPDie->AddChild(Arg); |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 1932 | } |
| 1933 | |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 1934 | if (!SP.isLocalToUnit()) |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 1935 | AddUInt(SPDie, DW_AT_external, DW_FORM_flag, 1); |
| 1936 | return SPDie; |
Devang Patel | 86ae142 | 2009-01-05 18:59:44 +0000 | [diff] [blame] | 1937 | } |
| 1938 | |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 1939 | /// FindCompileUnit - Get the compile unit for the given descriptor. |
| 1940 | /// |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 1941 | CompileUnit *FindCompileUnit(DICompileUnit Unit) { |
| 1942 | CompileUnit *DW_Unit = DW_CUs[Unit.getGV()]; |
| 1943 | assert(DW_Unit && "Missing compile unit."); |
| 1944 | return DW_Unit; |
| 1945 | } |
| 1946 | |
Devang Patel | bbdc820 | 2009-01-13 23:54:55 +0000 | [diff] [blame] | 1947 | /// NewDbgScopeVariable - Create a new scope variable. |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 1948 | /// |
| 1949 | DIE *NewDbgScopeVariable(DbgVariable *DV, CompileUnit *Unit) { |
| 1950 | // Get the descriptor. |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 1951 | const DIVariable &VD = DV->getVariable(); |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 1952 | |
| 1953 | // Translate tag to proper Dwarf tag. The result variable is dropped for |
| 1954 | // now. |
| 1955 | unsigned Tag; |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 1956 | switch (VD.getTag()) { |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 1957 | case DW_TAG_return_variable: return NULL; |
| 1958 | case DW_TAG_arg_variable: Tag = DW_TAG_formal_parameter; break; |
| 1959 | case DW_TAG_auto_variable: // fall thru |
| 1960 | default: Tag = DW_TAG_variable; break; |
| 1961 | } |
| 1962 | |
| 1963 | // Define variable debug information entry. |
| 1964 | DIE *VariableDie = new DIE(Tag); |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 1965 | AddString(VariableDie, DW_AT_name, DW_FORM_string, VD.getName()); |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 1966 | |
| 1967 | // Add source line info if available. |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 1968 | AddSourceLine(VariableDie, &VD); |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 1969 | |
| 1970 | // Add variable type. |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 1971 | AddType(Unit, VariableDie, VD.getType()); |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 1972 | |
| 1973 | // Add variable address. |
| 1974 | MachineLocation Location; |
| 1975 | Location.set(RI->getFrameRegister(*MF), |
| 1976 | RI->getFrameIndexOffset(*MF, DV->getFrameIndex())); |
| 1977 | AddAddress(VariableDie, DW_AT_location, Location); |
| 1978 | |
| 1979 | return VariableDie; |
| 1980 | } |
| 1981 | |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 1982 | /// getOrCreateScope - Returns the scope associated with the given descriptor. |
| 1983 | /// |
| 1984 | DbgScope *getOrCreateScope(GlobalVariable *V) { |
| 1985 | DbgScope *&Slot = DbgScopeMap[V]; |
| 1986 | if (!Slot) { |
| 1987 | // FIXME - breaks down when the context is an inlined function. |
| 1988 | DIDescriptor ParentDesc; |
Devang Patel | 0e5200f | 2009-01-15 18:25:17 +0000 | [diff] [blame] | 1989 | DIDescriptor Desc(V); |
| 1990 | if (Desc.getTag() == dwarf::DW_TAG_lexical_block) { |
| 1991 | DIBlock Block(V); |
| 1992 | ParentDesc = Block.getContext(); |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 1993 | } |
| 1994 | DbgScope *Parent = ParentDesc.isNull() ? |
Devang Patel | 0dc969e | 2009-01-10 02:34:18 +0000 | [diff] [blame] | 1995 | NULL : getOrCreateScope(ParentDesc.getGV()); |
Devang Patel | 0e5200f | 2009-01-15 18:25:17 +0000 | [diff] [blame] | 1996 | Slot = new DbgScope(Parent, Desc); |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 1997 | if (Parent) { |
| 1998 | Parent->AddScope(Slot); |
| 1999 | } else if (RootDbgScope) { |
| 2000 | // FIXME - Add inlined function scopes to the root so we can delete |
| 2001 | // them later. Long term, handle inlined functions properly. |
| 2002 | RootDbgScope->AddScope(Slot); |
| 2003 | } else { |
| 2004 | // First function is top level function. |
| 2005 | RootDbgScope = Slot; |
| 2006 | } |
| 2007 | } |
| 2008 | return Slot; |
| 2009 | } |
| 2010 | |
| 2011 | /// ConstructDbgScope - Construct the components of a scope. |
| 2012 | /// |
| 2013 | void ConstructDbgScope(DbgScope *ParentScope, |
| 2014 | unsigned ParentStartID, unsigned ParentEndID, |
| 2015 | DIE *ParentDie, CompileUnit *Unit) { |
| 2016 | // Add variables to scope. |
Devang Patel | 9795da5 | 2009-01-10 02:42:49 +0000 | [diff] [blame] | 2017 | SmallVector<DbgVariable *, 8> &Variables = ParentScope->getVariables(); |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 2018 | for (unsigned i = 0, N = Variables.size(); i < N; ++i) { |
| 2019 | DIE *VariableDie = NewDbgScopeVariable(Variables[i], Unit); |
| 2020 | if (VariableDie) ParentDie->AddChild(VariableDie); |
| 2021 | } |
| 2022 | |
| 2023 | // Add nested scopes. |
Devang Patel | 9795da5 | 2009-01-10 02:42:49 +0000 | [diff] [blame] | 2024 | SmallVector<DbgScope *, 4> &Scopes = ParentScope->getScopes(); |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 2025 | for (unsigned j = 0, M = Scopes.size(); j < M; ++j) { |
| 2026 | // Define the Scope debug information entry. |
| 2027 | DbgScope *Scope = Scopes[j]; |
| 2028 | // FIXME - Ignore inlined functions for the time being. |
| 2029 | if (!Scope->getParent()) continue; |
| 2030 | |
Devang Patel | e9bfb0f | 2009-01-12 18:41:00 +0000 | [diff] [blame] | 2031 | unsigned StartID = MMI->MappedLabel(Scope->getStartLabelID()); |
| 2032 | unsigned EndID = MMI->MappedLabel(Scope->getEndLabelID()); |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 2033 | |
| 2034 | // Ignore empty scopes. |
| 2035 | if (StartID == EndID && StartID != 0) continue; |
| 2036 | if (Scope->getScopes().empty() && Scope->getVariables().empty()) continue; |
| 2037 | |
| 2038 | if (StartID == ParentStartID && EndID == ParentEndID) { |
| 2039 | // Just add stuff to the parent scope. |
| 2040 | ConstructDbgScope(Scope, ParentStartID, ParentEndID, ParentDie, Unit); |
| 2041 | } else { |
| 2042 | DIE *ScopeDie = new DIE(DW_TAG_lexical_block); |
| 2043 | |
| 2044 | // Add the scope bounds. |
| 2045 | if (StartID) { |
| 2046 | AddLabel(ScopeDie, DW_AT_low_pc, DW_FORM_addr, |
| 2047 | DWLabel("label", StartID)); |
| 2048 | } else { |
| 2049 | AddLabel(ScopeDie, DW_AT_low_pc, DW_FORM_addr, |
| 2050 | DWLabel("func_begin", SubprogramCount)); |
| 2051 | } |
| 2052 | if (EndID) { |
| 2053 | AddLabel(ScopeDie, DW_AT_high_pc, DW_FORM_addr, |
| 2054 | DWLabel("label", EndID)); |
| 2055 | } else { |
| 2056 | AddLabel(ScopeDie, DW_AT_high_pc, DW_FORM_addr, |
| 2057 | DWLabel("func_end", SubprogramCount)); |
| 2058 | } |
| 2059 | |
| 2060 | // Add the scope contents. |
| 2061 | ConstructDbgScope(Scope, StartID, EndID, ScopeDie, Unit); |
| 2062 | ParentDie->AddChild(ScopeDie); |
| 2063 | } |
| 2064 | } |
| 2065 | } |
| 2066 | |
| 2067 | /// ConstructRootDbgScope - Construct the scope for the subprogram. |
| 2068 | /// |
| 2069 | void ConstructRootDbgScope(DbgScope *RootScope) { |
| 2070 | // Exit if there is no root scope. |
| 2071 | if (!RootScope) return; |
Devang Patel | 0e5200f | 2009-01-15 18:25:17 +0000 | [diff] [blame] | 2072 | DIDescriptor Desc = RootScope->getDesc(); |
| 2073 | if (Desc.isNull()) |
| 2074 | return; |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 2075 | |
| 2076 | // Get the subprogram debug information entry. |
Devang Patel | 0e5200f | 2009-01-15 18:25:17 +0000 | [diff] [blame] | 2077 | DISubprogram SPD(Desc.getGV()); |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 2078 | |
| 2079 | // Get the compile unit context. |
Devang Patel | f6bac3e | 2009-01-12 22:58:14 +0000 | [diff] [blame] | 2080 | CompileUnit *Unit = FindCompileUnit(SPD.getCompileUnit()); |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 2081 | |
| 2082 | // Get the subprogram die. |
Devang Patel | f6bac3e | 2009-01-12 22:58:14 +0000 | [diff] [blame] | 2083 | DIE *SPDie = Unit->getDieMapSlotFor(SPD.getGV()); |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 2084 | assert(SPDie && "Missing subprogram descriptor"); |
| 2085 | |
| 2086 | // Add the function bounds. |
| 2087 | AddLabel(SPDie, DW_AT_low_pc, DW_FORM_addr, |
| 2088 | DWLabel("func_begin", SubprogramCount)); |
| 2089 | AddLabel(SPDie, DW_AT_high_pc, DW_FORM_addr, |
| 2090 | DWLabel("func_end", SubprogramCount)); |
| 2091 | MachineLocation Location(RI->getFrameRegister(*MF)); |
| 2092 | AddAddress(SPDie, DW_AT_frame_base, Location); |
| 2093 | |
| 2094 | ConstructDbgScope(RootScope, 0, 0, SPDie, Unit); |
| 2095 | } |
| 2096 | |
| 2097 | /// ConstructDefaultDbgScope - Construct a default scope for the subprogram. |
| 2098 | /// |
| 2099 | void ConstructDefaultDbgScope(MachineFunction *MF) { |
| 2100 | // Find the correct subprogram descriptor. |
| 2101 | std::string SPName = "llvm.dbg.subprograms"; |
| 2102 | std::vector<GlobalVariable*> Result; |
| 2103 | getGlobalVariablesUsing(*M, SPName, Result); |
| 2104 | for (std::vector<GlobalVariable *>::iterator I = Result.begin(), |
| 2105 | E = Result.end(); I != E; ++I) { |
| 2106 | |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 2107 | DISubprogram SPD(*I); |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 2108 | |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 2109 | if (SPD.getName() == MF->getFunction()->getName()) { |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 2110 | // Get the compile unit context. |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 2111 | CompileUnit *Unit = FindCompileUnit(SPD.getCompileUnit()); |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 2112 | |
| 2113 | // Get the subprogram die. |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 2114 | DIE *SPDie = Unit->getDieMapSlotFor(SPD.getGV()); |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 2115 | assert(SPDie && "Missing subprogram descriptor"); |
| 2116 | |
| 2117 | // Add the function bounds. |
| 2118 | AddLabel(SPDie, DW_AT_low_pc, DW_FORM_addr, |
| 2119 | DWLabel("func_begin", SubprogramCount)); |
| 2120 | AddLabel(SPDie, DW_AT_high_pc, DW_FORM_addr, |
| 2121 | DWLabel("func_end", SubprogramCount)); |
| 2122 | |
| 2123 | MachineLocation Location(RI->getFrameRegister(*MF)); |
| 2124 | AddAddress(SPDie, DW_AT_frame_base, Location); |
| 2125 | return; |
| 2126 | } |
| 2127 | } |
| 2128 | #if 0 |
| 2129 | // FIXME: This is causing an abort because C++ mangled names are compared |
| 2130 | // with their unmangled counterparts. See PR2885. Don't do this assert. |
| 2131 | assert(0 && "Couldn't find DIE for machine function!"); |
| 2132 | #endif |
| 2133 | } |
| 2134 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2135 | /// EmitInitial - Emit initial Dwarf declarations. This is necessary for cc |
| 2136 | /// tools to recognize the object file contains Dwarf information. |
| 2137 | void EmitInitial() { |
| 2138 | // Check to see if we already emitted intial headers. |
| 2139 | if (didInitial) return; |
| 2140 | didInitial = true; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2141 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2142 | // Dwarf sections base addresses. |
Anton Korobeynikov | 2a07e2f | 2007-05-05 09:04:50 +0000 | [diff] [blame] | 2143 | if (TAI->doesDwarfRequireFrameSection()) { |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2144 | Asm->SwitchToDataSection(TAI->getDwarfFrameSection()); |
Anton Korobeynikov | 185bc89 | 2007-05-13 17:30:11 +0000 | [diff] [blame] | 2145 | EmitLabel("section_debug_frame", 0); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2146 | } |
| 2147 | Asm->SwitchToDataSection(TAI->getDwarfInfoSection()); |
| 2148 | EmitLabel("section_info", 0); |
| 2149 | Asm->SwitchToDataSection(TAI->getDwarfAbbrevSection()); |
| 2150 | EmitLabel("section_abbrev", 0); |
| 2151 | Asm->SwitchToDataSection(TAI->getDwarfARangesSection()); |
| 2152 | EmitLabel("section_aranges", 0); |
| 2153 | Asm->SwitchToDataSection(TAI->getDwarfMacInfoSection()); |
| 2154 | EmitLabel("section_macinfo", 0); |
| 2155 | Asm->SwitchToDataSection(TAI->getDwarfLineSection()); |
| 2156 | EmitLabel("section_line", 0); |
| 2157 | Asm->SwitchToDataSection(TAI->getDwarfLocSection()); |
| 2158 | EmitLabel("section_loc", 0); |
| 2159 | Asm->SwitchToDataSection(TAI->getDwarfPubNamesSection()); |
| 2160 | EmitLabel("section_pubnames", 0); |
| 2161 | Asm->SwitchToDataSection(TAI->getDwarfStrSection()); |
| 2162 | EmitLabel("section_str", 0); |
| 2163 | Asm->SwitchToDataSection(TAI->getDwarfRangesSection()); |
| 2164 | EmitLabel("section_ranges", 0); |
| 2165 | |
Anton Korobeynikov | d7ca416 | 2008-09-24 22:15:21 +0000 | [diff] [blame] | 2166 | Asm->SwitchToSection(TAI->getTextSection()); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2167 | EmitLabel("text_begin", 0); |
Anton Korobeynikov | 315690e | 2008-09-24 22:16:16 +0000 | [diff] [blame] | 2168 | Asm->SwitchToSection(TAI->getDataSection()); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2169 | EmitLabel("data_begin", 0); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2170 | } |
| 2171 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2172 | /// EmitDIE - Recusively Emits a debug information entry. |
| 2173 | /// |
Anton Korobeynikov | 6a14359 | 2007-03-07 08:25:02 +0000 | [diff] [blame] | 2174 | void EmitDIE(DIE *Die) { |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2175 | // Get the abbreviation for this DIE. |
| 2176 | unsigned AbbrevNumber = Die->getAbbrevNumber(); |
| 2177 | const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1]; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2178 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 2179 | Asm->EOL(); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2180 | |
| 2181 | // Emit the code (index) for the abbreviation. |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2182 | Asm->EmitULEB128Bytes(AbbrevNumber); |
Evan Cheng | 6547e40 | 2008-07-01 23:18:29 +0000 | [diff] [blame] | 2183 | |
| 2184 | if (VerboseAsm) |
| 2185 | Asm->EOL(std::string("Abbrev [" + |
| 2186 | utostr(AbbrevNumber) + |
| 2187 | "] 0x" + utohexstr(Die->getOffset()) + |
| 2188 | ":0x" + utohexstr(Die->getSize()) + " " + |
| 2189 | TagString(Abbrev->getTag()))); |
| 2190 | else |
| 2191 | Asm->EOL(); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2192 | |
Owen Anderson | 873e1b5 | 2008-06-24 21:44:59 +0000 | [diff] [blame] | 2193 | SmallVector<DIEValue*, 32> &Values = Die->getValues(); |
| 2194 | const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev->getData(); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2195 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2196 | // Emit the DIE attribute values. |
| 2197 | for (unsigned i = 0, N = Values.size(); i < N; ++i) { |
| 2198 | unsigned Attr = AbbrevData[i].getAttribute(); |
| 2199 | unsigned Form = AbbrevData[i].getForm(); |
| 2200 | assert(Form && "Too many attributes for DIE (check abbreviation)"); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2201 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2202 | switch (Attr) { |
| 2203 | case DW_AT_sibling: { |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2204 | Asm->EmitInt32(Die->SiblingOffset()); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2205 | break; |
| 2206 | } |
| 2207 | default: { |
| 2208 | // Emit an attribute using the defined form. |
| 2209 | Values[i]->EmitValue(*this, Form); |
| 2210 | break; |
| 2211 | } |
| 2212 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2213 | |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2214 | Asm->EOL(AttributeString(Attr)); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2215 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2216 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2217 | // Emit the DIE children if any. |
| 2218 | if (Abbrev->getChildrenFlag() == DW_CHILDREN_yes) { |
| 2219 | const std::vector<DIE *> &Children = Die->getChildren(); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2220 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2221 | for (unsigned j = 0, M = Children.size(); j < M; ++j) { |
| 2222 | EmitDIE(Children[j]); |
| 2223 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2224 | |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2225 | Asm->EmitInt8(0); Asm->EOL("End Of Children Mark"); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2226 | } |
| 2227 | } |
| 2228 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2229 | /// SizeAndOffsetDie - Compute the size and offset of a DIE. |
| 2230 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2231 | unsigned SizeAndOffsetDie(DIE *Die, unsigned Offset, bool Last) { |
| 2232 | // Get the children. |
| 2233 | const std::vector<DIE *> &Children = Die->getChildren(); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2234 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2235 | // If not last sibling and has children then add sibling offset attribute. |
| 2236 | if (!Last && !Children.empty()) Die->AddSiblingOffset(); |
| 2237 | |
| 2238 | // Record the abbreviation. |
| 2239 | AssignAbbrevNumber(Die->getAbbrev()); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2240 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2241 | // Get the abbreviation for this DIE. |
| 2242 | unsigned AbbrevNumber = Die->getAbbrevNumber(); |
| 2243 | const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1]; |
| 2244 | |
| 2245 | // Set DIE offset |
| 2246 | Die->setOffset(Offset); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2247 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2248 | // Start the size with the size of abbreviation code. |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2249 | Offset += TargetAsmInfo::getULEB128Size(AbbrevNumber); |
| 2250 | |
Owen Anderson | 873e1b5 | 2008-06-24 21:44:59 +0000 | [diff] [blame] | 2251 | const SmallVector<DIEValue*, 32> &Values = Die->getValues(); |
| 2252 | const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev->getData(); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2253 | |
| 2254 | // Size the DIE attribute values. |
| 2255 | for (unsigned i = 0, N = Values.size(); i < N; ++i) { |
| 2256 | // Size attribute value. |
| 2257 | Offset += Values[i]->SizeOf(*this, AbbrevData[i].getForm()); |
| 2258 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2259 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2260 | // Size the DIE children if any. |
| 2261 | if (!Children.empty()) { |
| 2262 | assert(Abbrev->getChildrenFlag() == DW_CHILDREN_yes && |
| 2263 | "Children flag not set"); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2264 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2265 | for (unsigned j = 0, M = Children.size(); j < M; ++j) { |
| 2266 | Offset = SizeAndOffsetDie(Children[j], Offset, (j + 1) == M); |
| 2267 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2268 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2269 | // End of children marker. |
| 2270 | Offset += sizeof(int8_t); |
| 2271 | } |
| 2272 | |
| 2273 | Die->setSize(Offset - Die->getOffset()); |
| 2274 | return Offset; |
| 2275 | } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2276 | |
| 2277 | /// SizeAndOffsets - Compute the size and offset of all the DIEs. |
| 2278 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2279 | void SizeAndOffsets() { |
Jim Laskey | 5496f01 | 2006-11-09 14:52:14 +0000 | [diff] [blame] | 2280 | // Process base compile unit. |
Devang Patel | 72b6635 | 2009-01-12 23:05:55 +0000 | [diff] [blame] | 2281 | for (DenseMap<Value *, CompileUnit *>::iterator CI = DW_CUs.begin(), |
| 2282 | CE = DW_CUs.end(); CI != CE; ++CI) { |
| 2283 | CompileUnit *Unit = CI->second; |
| 2284 | // Compute size of compile unit header |
| 2285 | unsigned Offset = sizeof(int32_t) + // Length of Compilation Unit Info |
| 2286 | sizeof(int16_t) + // DWARF version number |
| 2287 | sizeof(int32_t) + // Offset Into Abbrev. Section |
| 2288 | sizeof(int8_t); // Pointer Size (in bytes) |
| 2289 | SizeAndOffsetDie(Unit->getDie(), Offset, true); |
| 2290 | } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2291 | } |
| 2292 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2293 | /// EmitDebugInfo - Emit the debug info section. |
| 2294 | /// |
Anton Korobeynikov | 6a14359 | 2007-03-07 08:25:02 +0000 | [diff] [blame] | 2295 | void EmitDebugInfo() { |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2296 | // Start debug info section. |
| 2297 | Asm->SwitchToDataSection(TAI->getDwarfInfoSection()); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2298 | |
Devang Patel | 72b6635 | 2009-01-12 23:05:55 +0000 | [diff] [blame] | 2299 | for (DenseMap<Value *, CompileUnit *>::iterator CI = DW_CUs.begin(), |
| 2300 | CE = DW_CUs.end(); CI != CE; ++CI) { |
| 2301 | CompileUnit *Unit = CI->second; |
| 2302 | DIE *Die = Unit->getDie(); |
| 2303 | // Emit the compile units header. |
| 2304 | EmitLabel("info_begin", Unit->getID()); |
| 2305 | // Emit size of content not including length itself |
| 2306 | unsigned ContentSize = Die->getSize() + |
| 2307 | sizeof(int16_t) + // DWARF version number |
| 2308 | sizeof(int32_t) + // Offset Into Abbrev. Section |
| 2309 | sizeof(int8_t) + // Pointer Size (in bytes) |
| 2310 | sizeof(int32_t); // FIXME - extra pad for gdb bug. |
| 2311 | |
| 2312 | Asm->EmitInt32(ContentSize); Asm->EOL("Length of Compilation Unit Info"); |
| 2313 | Asm->EmitInt16(DWARF_VERSION); Asm->EOL("DWARF version number"); |
| 2314 | EmitSectionOffset("abbrev_begin", "section_abbrev", 0, 0, true, false); |
| 2315 | Asm->EOL("Offset Into Abbrev. Section"); |
| 2316 | Asm->EmitInt8(TD->getPointerSize()); Asm->EOL("Address Size (in bytes)"); |
| 2317 | |
| 2318 | EmitDIE(Die); |
| 2319 | // FIXME - extra padding for gdb bug. |
| 2320 | Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB"); |
| 2321 | Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB"); |
| 2322 | Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB"); |
| 2323 | Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB"); |
| 2324 | EmitLabel("info_end", Unit->getID()); |
| 2325 | |
| 2326 | Asm->EOL(); |
| 2327 | } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2328 | } |
| 2329 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2330 | /// EmitAbbreviations - Emit the abbreviation section. |
| 2331 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2332 | void EmitAbbreviations() const { |
| 2333 | // Check to see if it is worth the effort. |
| 2334 | if (!Abbreviations.empty()) { |
| 2335 | // Start the debug abbrev section. |
| 2336 | Asm->SwitchToDataSection(TAI->getDwarfAbbrevSection()); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2337 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2338 | EmitLabel("abbrev_begin", 0); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2339 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2340 | // For each abbrevation. |
| 2341 | for (unsigned i = 0, N = Abbreviations.size(); i < N; ++i) { |
| 2342 | // Get abbreviation data |
| 2343 | const DIEAbbrev *Abbrev = Abbreviations[i]; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2344 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2345 | // Emit the abbrevations code (base 1 index.) |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2346 | Asm->EmitULEB128Bytes(Abbrev->getNumber()); |
| 2347 | Asm->EOL("Abbreviation Code"); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2348 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2349 | // Emit the abbreviations data. |
| 2350 | Abbrev->Emit(*this); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2351 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 2352 | Asm->EOL(); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2353 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2354 | |
Jim Laskey | 7b1b39d | 2007-02-22 18:22:42 +0000 | [diff] [blame] | 2355 | // Mark end of abbreviations. |
Jim Laskey | 5df3ad8 | 2007-02-22 18:48:52 +0000 | [diff] [blame] | 2356 | Asm->EmitULEB128Bytes(0); Asm->EOL("EOM(3)"); |
Jim Laskey | 7b1b39d | 2007-02-22 18:22:42 +0000 | [diff] [blame] | 2357 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2358 | EmitLabel("abbrev_end", 0); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2359 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 2360 | Asm->EOL(); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2361 | } |
| 2362 | } |
| 2363 | |
Bill Wendling | fbbd701 | 2008-07-20 00:11:19 +0000 | [diff] [blame] | 2364 | /// EmitEndOfLineMatrix - Emit the last address of the section and the end of |
| 2365 | /// the line matrix. |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2366 | /// |
Bill Wendling | fbbd701 | 2008-07-20 00:11:19 +0000 | [diff] [blame] | 2367 | void EmitEndOfLineMatrix(unsigned SectionEnd) { |
| 2368 | // Define last address of section. |
| 2369 | Asm->EmitInt8(0); Asm->EOL("Extended Op"); |
| 2370 | Asm->EmitInt8(TD->getPointerSize() + 1); Asm->EOL("Op size"); |
| 2371 | Asm->EmitInt8(DW_LNE_set_address); Asm->EOL("DW_LNE_set_address"); |
| 2372 | EmitReference("section_end", SectionEnd); Asm->EOL("Section end label"); |
| 2373 | |
| 2374 | // Mark end of matrix. |
| 2375 | Asm->EmitInt8(0); Asm->EOL("DW_LNE_end_sequence"); |
| 2376 | Asm->EmitULEB128Bytes(1); Asm->EOL(); |
| 2377 | Asm->EmitInt8(1); Asm->EOL(); |
| 2378 | } |
| 2379 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2380 | /// EmitDebugLines - Emit source line information. |
| 2381 | /// |
Anton Korobeynikov | 6a14359 | 2007-03-07 08:25:02 +0000 | [diff] [blame] | 2382 | void EmitDebugLines() { |
Bill Wendling | fbbd701 | 2008-07-20 00:11:19 +0000 | [diff] [blame] | 2383 | // If the target is using .loc/.file, the assembler will be emitting the |
| 2384 | // .debug_line table automatically. |
| 2385 | if (TAI->hasDotLocAndDotFile()) |
Dan Gohman | 81a148b | 2007-09-24 21:43:52 +0000 | [diff] [blame] | 2386 | return; |
| 2387 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2388 | // Minimum line delta, thus ranging from -10..(255-10). |
| 2389 | const int MinLineDelta = -(DW_LNS_fixed_advance_pc + 1); |
| 2390 | // Maximum line delta, thus ranging from -10..(255-10). |
| 2391 | const int MaxLineDelta = 255 + MinLineDelta; |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2392 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2393 | // Start the dwarf line section. |
| 2394 | Asm->SwitchToDataSection(TAI->getDwarfLineSection()); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2395 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2396 | // Construct the section header. |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2397 | |
Jim Laskey | 2b4e98c | 2006-12-06 17:43:18 +0000 | [diff] [blame] | 2398 | EmitDifference("line_end", 0, "line_begin", 0, true); |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2399 | Asm->EOL("Length of Source Line Info"); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2400 | EmitLabel("line_begin", 0); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2401 | |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2402 | Asm->EmitInt16(DWARF_VERSION); Asm->EOL("DWARF version number"); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2403 | |
Jim Laskey | 2b4e98c | 2006-12-06 17:43:18 +0000 | [diff] [blame] | 2404 | EmitDifference("line_prolog_end", 0, "line_prolog_begin", 0, true); |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2405 | Asm->EOL("Prolog Length"); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2406 | EmitLabel("line_prolog_begin", 0); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2407 | |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2408 | Asm->EmitInt8(1); Asm->EOL("Minimum Instruction Length"); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2409 | |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2410 | Asm->EmitInt8(1); Asm->EOL("Default is_stmt_start flag"); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2411 | |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2412 | Asm->EmitInt8(MinLineDelta); Asm->EOL("Line Base Value (Special Opcodes)"); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2413 | |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2414 | Asm->EmitInt8(MaxLineDelta); Asm->EOL("Line Range Value (Special Opcodes)"); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2415 | |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2416 | Asm->EmitInt8(-MinLineDelta); Asm->EOL("Special Opcode Base"); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2417 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2418 | // Line number standard opcode encodings argument count |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2419 | Asm->EmitInt8(0); Asm->EOL("DW_LNS_copy arg count"); |
| 2420 | Asm->EmitInt8(1); Asm->EOL("DW_LNS_advance_pc arg count"); |
| 2421 | Asm->EmitInt8(1); Asm->EOL("DW_LNS_advance_line arg count"); |
| 2422 | Asm->EmitInt8(1); Asm->EOL("DW_LNS_set_file arg count"); |
| 2423 | Asm->EmitInt8(1); Asm->EOL("DW_LNS_set_column arg count"); |
| 2424 | Asm->EmitInt8(0); Asm->EOL("DW_LNS_negate_stmt arg count"); |
| 2425 | Asm->EmitInt8(0); Asm->EOL("DW_LNS_set_basic_block arg count"); |
| 2426 | Asm->EmitInt8(0); Asm->EOL("DW_LNS_const_add_pc arg count"); |
| 2427 | Asm->EmitInt8(1); Asm->EOL("DW_LNS_fixed_advance_pc arg count"); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2428 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2429 | // Emit directories. |
| 2430 | for (unsigned DirectoryID = 1, NDID = Directories.size(); |
| 2431 | DirectoryID <= NDID; ++DirectoryID) { |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2432 | Asm->EmitString(Directories[DirectoryID]); Asm->EOL("Directory"); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2433 | } |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2434 | Asm->EmitInt8(0); Asm->EOL("End of directories"); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2435 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2436 | // Emit files. |
Devang Patel | 7bb89ed | 2009-01-13 00:20:51 +0000 | [diff] [blame] | 2437 | for (unsigned SourceID = 1, NSID = SrcFiles.size(); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2438 | SourceID <= NSID; ++SourceID) { |
Devang Patel | 7bb89ed | 2009-01-13 00:20:51 +0000 | [diff] [blame] | 2439 | const SrcFileInfo &SourceFile = SrcFiles[SourceID]; |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2440 | Asm->EmitString(SourceFile.getName()); |
| 2441 | Asm->EOL("Source"); |
| 2442 | Asm->EmitULEB128Bytes(SourceFile.getDirectoryID()); |
| 2443 | Asm->EOL("Directory #"); |
| 2444 | Asm->EmitULEB128Bytes(0); |
| 2445 | Asm->EOL("Mod date"); |
| 2446 | Asm->EmitULEB128Bytes(0); |
| 2447 | Asm->EOL("File size"); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2448 | } |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2449 | Asm->EmitInt8(0); Asm->EOL("End of files"); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2450 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2451 | EmitLabel("line_prolog_end", 0); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2452 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2453 | // A sequence for each text section. |
Bill Wendling | fbbd701 | 2008-07-20 00:11:19 +0000 | [diff] [blame] | 2454 | unsigned SecSrcLinesSize = SectionSourceLines.size(); |
| 2455 | |
| 2456 | for (unsigned j = 0; j < SecSrcLinesSize; ++j) { |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2457 | // Isolate current sections line info. |
Devang Patel | f3ee514 | 2009-01-12 22:54:42 +0000 | [diff] [blame] | 2458 | const std::vector<SrcLineInfo> &LineInfos = SectionSourceLines[j]; |
Evan Cheng | 6547e40 | 2008-07-01 23:18:29 +0000 | [diff] [blame] | 2459 | |
Anton Korobeynikov | d7ca416 | 2008-09-24 22:15:21 +0000 | [diff] [blame] | 2460 | if (VerboseAsm) { |
| 2461 | const Section* S = SectionMap[j + 1]; |
| 2462 | Asm->EOL(std::string("Section ") + S->getName()); |
| 2463 | } else |
Evan Cheng | 6547e40 | 2008-07-01 23:18:29 +0000 | [diff] [blame] | 2464 | Asm->EOL(); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2465 | |
| 2466 | // Dwarf assumes we start with first line of first source file. |
| 2467 | unsigned Source = 1; |
| 2468 | unsigned Line = 1; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2469 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2470 | // Construct rows of the address, source, line, column matrix. |
| 2471 | for (unsigned i = 0, N = LineInfos.size(); i < N; ++i) { |
Devang Patel | f3ee514 | 2009-01-12 22:54:42 +0000 | [diff] [blame] | 2472 | const SrcLineInfo &LineInfo = LineInfos[i]; |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 2473 | unsigned LabelID = MMI->MappedLabel(LineInfo.getLabelID()); |
Jim Laskey | 9d4209f | 2006-11-07 19:33:46 +0000 | [diff] [blame] | 2474 | if (!LabelID) continue; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2475 | |
Jim Laskey | 1a4a83c | 2007-01-25 15:45:58 +0000 | [diff] [blame] | 2476 | unsigned SourceID = LineInfo.getSourceID(); |
Devang Patel | 7bb89ed | 2009-01-13 00:20:51 +0000 | [diff] [blame] | 2477 | const SrcFileInfo &SourceFile = SrcFiles[SourceID]; |
Jim Laskey | 1a4a83c | 2007-01-25 15:45:58 +0000 | [diff] [blame] | 2478 | unsigned DirectoryID = SourceFile.getDirectoryID(); |
Evan Cheng | 6547e40 | 2008-07-01 23:18:29 +0000 | [diff] [blame] | 2479 | if (VerboseAsm) |
| 2480 | Asm->EOL(Directories[DirectoryID] |
| 2481 | + SourceFile.getName() |
| 2482 | + ":" |
| 2483 | + utostr_32(LineInfo.getLine())); |
| 2484 | else |
| 2485 | Asm->EOL(); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2486 | |
| 2487 | // Define the line address. |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2488 | Asm->EmitInt8(0); Asm->EOL("Extended Op"); |
Dan Gohman | 8248294 | 2007-09-27 23:12:31 +0000 | [diff] [blame] | 2489 | Asm->EmitInt8(TD->getPointerSize() + 1); Asm->EOL("Op size"); |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2490 | Asm->EmitInt8(DW_LNE_set_address); Asm->EOL("DW_LNE_set_address"); |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 2491 | EmitReference("label", LabelID); Asm->EOL("Location label"); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2492 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2493 | // If change of source, then switch to the new source. |
| 2494 | if (Source != LineInfo.getSourceID()) { |
| 2495 | Source = LineInfo.getSourceID(); |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2496 | Asm->EmitInt8(DW_LNS_set_file); Asm->EOL("DW_LNS_set_file"); |
| 2497 | Asm->EmitULEB128Bytes(Source); Asm->EOL("New Source"); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2498 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2499 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2500 | // If change of line. |
| 2501 | if (Line != LineInfo.getLine()) { |
| 2502 | // Determine offset. |
| 2503 | int Offset = LineInfo.getLine() - Line; |
| 2504 | int Delta = Offset - MinLineDelta; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2505 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2506 | // Update line. |
| 2507 | Line = LineInfo.getLine(); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2508 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2509 | // If delta is small enough and in range... |
| 2510 | if (Delta >= 0 && Delta < (MaxLineDelta - 1)) { |
| 2511 | // ... then use fast opcode. |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2512 | Asm->EmitInt8(Delta - MinLineDelta); Asm->EOL("Line Delta"); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2513 | } else { |
| 2514 | // ... otherwise use long hand. |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2515 | Asm->EmitInt8(DW_LNS_advance_line); Asm->EOL("DW_LNS_advance_line"); |
| 2516 | Asm->EmitSLEB128Bytes(Offset); Asm->EOL("Line Offset"); |
| 2517 | Asm->EmitInt8(DW_LNS_copy); Asm->EOL("DW_LNS_copy"); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2518 | } |
| 2519 | } else { |
| 2520 | // Copy the previous row (different address or source) |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2521 | Asm->EmitInt8(DW_LNS_copy); Asm->EOL("DW_LNS_copy"); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2522 | } |
| 2523 | } |
| 2524 | |
Bill Wendling | fbbd701 | 2008-07-20 00:11:19 +0000 | [diff] [blame] | 2525 | EmitEndOfLineMatrix(j + 1); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2526 | } |
Bill Wendling | fbbd701 | 2008-07-20 00:11:19 +0000 | [diff] [blame] | 2527 | |
| 2528 | if (SecSrcLinesSize == 0) |
| 2529 | // Because we're emitting a debug_line section, we still need a line |
| 2530 | // table. The linker and friends expect it to exist. If there's nothing to |
| 2531 | // put into it, emit an empty table. |
| 2532 | EmitEndOfLineMatrix(1); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2533 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2534 | EmitLabel("line_end", 0); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2535 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 2536 | Asm->EOL(); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2537 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2538 | |
Anton Korobeynikov | 185bc89 | 2007-05-13 17:30:11 +0000 | [diff] [blame] | 2539 | /// EmitCommonDebugFrame - Emit common frame info into a debug frame section. |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2540 | /// |
Anton Korobeynikov | 185bc89 | 2007-05-13 17:30:11 +0000 | [diff] [blame] | 2541 | void EmitCommonDebugFrame() { |
Anton Korobeynikov | 2a07e2f | 2007-05-05 09:04:50 +0000 | [diff] [blame] | 2542 | if (!TAI->doesDwarfRequireFrameSection()) |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2543 | return; |
| 2544 | |
| 2545 | int stackGrowth = |
| 2546 | Asm->TM.getFrameInfo()->getStackGrowthDirection() == |
| 2547 | TargetFrameInfo::StackGrowsUp ? |
Dan Gohman | 8248294 | 2007-09-27 23:12:31 +0000 | [diff] [blame] | 2548 | TD->getPointerSize() : -TD->getPointerSize(); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2549 | |
| 2550 | // Start the dwarf frame section. |
| 2551 | Asm->SwitchToDataSection(TAI->getDwarfFrameSection()); |
| 2552 | |
Anton Korobeynikov | 185bc89 | 2007-05-13 17:30:11 +0000 | [diff] [blame] | 2553 | EmitLabel("debug_frame_common", 0); |
| 2554 | EmitDifference("debug_frame_common_end", 0, |
| 2555 | "debug_frame_common_begin", 0, true); |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2556 | Asm->EOL("Length of Common Information Entry"); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2557 | |
Anton Korobeynikov | 185bc89 | 2007-05-13 17:30:11 +0000 | [diff] [blame] | 2558 | EmitLabel("debug_frame_common_begin", 0); |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2559 | Asm->EmitInt32((int)DW_CIE_ID); |
| 2560 | Asm->EOL("CIE Identifier Tag"); |
| 2561 | Asm->EmitInt8(DW_CIE_VERSION); |
| 2562 | Asm->EOL("CIE Version"); |
| 2563 | Asm->EmitString(""); |
| 2564 | Asm->EOL("CIE Augmentation"); |
| 2565 | Asm->EmitULEB128Bytes(1); |
| 2566 | Asm->EOL("CIE Code Alignment Factor"); |
| 2567 | Asm->EmitSLEB128Bytes(stackGrowth); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2568 | Asm->EOL("CIE Data Alignment Factor"); |
Dale Johannesen | b97aec6 | 2007-11-13 19:13:01 +0000 | [diff] [blame] | 2569 | Asm->EmitInt8(RI->getDwarfRegNum(RI->getRARegister(), false)); |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2570 | Asm->EOL("CIE RA Column"); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2571 | |
Jim Laskey | 5e73d5b | 2007-01-24 18:45:13 +0000 | [diff] [blame] | 2572 | std::vector<MachineMove> Moves; |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2573 | RI->getInitialFrameState(Moves); |
Anton Korobeynikov | 0ff3ca4 | 2007-05-12 22:36:25 +0000 | [diff] [blame] | 2574 | |
Dale Johannesen | b97aec6 | 2007-11-13 19:13:01 +0000 | [diff] [blame] | 2575 | EmitFrameMoves(NULL, 0, Moves, false); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2576 | |
Evan Cheng | 05548eb | 2008-02-29 19:36:59 +0000 | [diff] [blame] | 2577 | Asm->EmitAlignment(2, 0, 0, false); |
Anton Korobeynikov | 185bc89 | 2007-05-13 17:30:11 +0000 | [diff] [blame] | 2578 | EmitLabel("debug_frame_common_end", 0); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2579 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 2580 | Asm->EOL(); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2581 | } |
| 2582 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2583 | /// EmitFunctionDebugFrame - Emit per function frame info into a debug frame |
| 2584 | /// section. |
Anton Korobeynikov | 185bc89 | 2007-05-13 17:30:11 +0000 | [diff] [blame] | 2585 | void EmitFunctionDebugFrame(const FunctionDebugFrameInfo &DebugFrameInfo) { |
Anton Korobeynikov | 2a07e2f | 2007-05-05 09:04:50 +0000 | [diff] [blame] | 2586 | if (!TAI->doesDwarfRequireFrameSection()) |
Reid Spencer | 5a4951e | 2006-11-07 06:36:36 +0000 | [diff] [blame] | 2587 | return; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2588 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2589 | // Start the dwarf frame section. |
| 2590 | Asm->SwitchToDataSection(TAI->getDwarfFrameSection()); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2591 | |
Anton Korobeynikov | 185bc89 | 2007-05-13 17:30:11 +0000 | [diff] [blame] | 2592 | EmitDifference("debug_frame_end", DebugFrameInfo.Number, |
| 2593 | "debug_frame_begin", DebugFrameInfo.Number, true); |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2594 | Asm->EOL("Length of Frame Information Entry"); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2595 | |
Anton Korobeynikov | 185bc89 | 2007-05-13 17:30:11 +0000 | [diff] [blame] | 2596 | EmitLabel("debug_frame_begin", DebugFrameInfo.Number); |
Anton Korobeynikov | a6199c8 | 2007-03-07 02:47:57 +0000 | [diff] [blame] | 2597 | |
Anton Korobeynikov | 185bc89 | 2007-05-13 17:30:11 +0000 | [diff] [blame] | 2598 | EmitSectionOffset("debug_frame_common", "section_debug_frame", |
| 2599 | 0, 0, true, false); |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2600 | Asm->EOL("FDE CIE offset"); |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2601 | |
Anton Korobeynikov | 185bc89 | 2007-05-13 17:30:11 +0000 | [diff] [blame] | 2602 | EmitReference("func_begin", DebugFrameInfo.Number); |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2603 | Asm->EOL("FDE initial location"); |
Anton Korobeynikov | 185bc89 | 2007-05-13 17:30:11 +0000 | [diff] [blame] | 2604 | EmitDifference("func_end", DebugFrameInfo.Number, |
| 2605 | "func_begin", DebugFrameInfo.Number); |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2606 | Asm->EOL("FDE address range"); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2607 | |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 2608 | EmitFrameMoves("func_begin", DebugFrameInfo.Number, DebugFrameInfo.Moves, |
Devang Patel | 2d1768c | 2009-01-17 08:05:14 +0000 | [diff] [blame] | 2609 | false); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2610 | |
Evan Cheng | 05548eb | 2008-02-29 19:36:59 +0000 | [diff] [blame] | 2611 | Asm->EmitAlignment(2, 0, 0, false); |
Anton Korobeynikov | 185bc89 | 2007-05-13 17:30:11 +0000 | [diff] [blame] | 2612 | EmitLabel("debug_frame_end", DebugFrameInfo.Number); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2613 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 2614 | Asm->EOL(); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2615 | } |
| 2616 | |
| 2617 | /// EmitDebugPubNames - Emit visible names into a debug pubnames section. |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2618 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2619 | void EmitDebugPubNames() { |
| 2620 | // Start the dwarf pubnames section. |
| 2621 | Asm->SwitchToDataSection(TAI->getDwarfPubNamesSection()); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2622 | |
Devang Patel | 72b6635 | 2009-01-12 23:05:55 +0000 | [diff] [blame] | 2623 | for (DenseMap<Value *, CompileUnit *>::iterator CI = DW_CUs.begin(), |
| 2624 | CE = DW_CUs.end(); CI != CE; ++CI) { |
| 2625 | CompileUnit *Unit = CI->second; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2626 | |
Devang Patel | 72b6635 | 2009-01-12 23:05:55 +0000 | [diff] [blame] | 2627 | EmitDifference("pubnames_end", Unit->getID(), |
| 2628 | "pubnames_begin", Unit->getID(), true); |
| 2629 | Asm->EOL("Length of Public Names Info"); |
| 2630 | |
| 2631 | EmitLabel("pubnames_begin", Unit->getID()); |
| 2632 | |
| 2633 | Asm->EmitInt16(DWARF_VERSION); Asm->EOL("DWARF Version"); |
| 2634 | |
| 2635 | EmitSectionOffset("info_begin", "section_info", |
| 2636 | Unit->getID(), 0, true, false); |
| 2637 | Asm->EOL("Offset of Compilation Unit Info"); |
| 2638 | |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 2639 | EmitDifference("info_end", Unit->getID(), "info_begin", Unit->getID(), |
Devang Patel | 2d1768c | 2009-01-17 08:05:14 +0000 | [diff] [blame] | 2640 | true); |
Devang Patel | 72b6635 | 2009-01-12 23:05:55 +0000 | [diff] [blame] | 2641 | Asm->EOL("Compilation Unit Length"); |
| 2642 | |
| 2643 | std::map<std::string, DIE *> &Globals = Unit->getGlobals(); |
| 2644 | |
| 2645 | for (std::map<std::string, DIE *>::iterator GI = Globals.begin(), |
| 2646 | GE = Globals.end(); |
| 2647 | GI != GE; ++GI) { |
| 2648 | const std::string &Name = GI->first; |
| 2649 | DIE * Entity = GI->second; |
| 2650 | |
| 2651 | Asm->EmitInt32(Entity->getOffset()); Asm->EOL("DIE offset"); |
| 2652 | Asm->EmitString(Name); Asm->EOL("External Name"); |
| 2653 | } |
| 2654 | |
| 2655 | Asm->EmitInt32(0); Asm->EOL("End Mark"); |
| 2656 | EmitLabel("pubnames_end", Unit->getID()); |
| 2657 | |
| 2658 | Asm->EOL(); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2659 | } |
| 2660 | } |
| 2661 | |
| 2662 | /// EmitDebugStr - Emit visible names into a debug str section. |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2663 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2664 | void EmitDebugStr() { |
| 2665 | // Check to see if it is worth the effort. |
| 2666 | if (!StringPool.empty()) { |
| 2667 | // Start the dwarf str section. |
| 2668 | Asm->SwitchToDataSection(TAI->getDwarfStrSection()); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2669 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2670 | // For each of strings in the string pool. |
| 2671 | for (unsigned StringID = 1, N = StringPool.size(); |
| 2672 | StringID <= N; ++StringID) { |
| 2673 | // Emit a label for reference from debug information entries. |
| 2674 | EmitLabel("string", StringID); |
| 2675 | // Emit the string itself. |
| 2676 | const std::string &String = StringPool[StringID]; |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 2677 | Asm->EmitString(String); Asm->EOL(); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2678 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2679 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 2680 | Asm->EOL(); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2681 | } |
| 2682 | } |
| 2683 | |
| 2684 | /// EmitDebugLoc - Emit visible names into a debug loc section. |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2685 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2686 | void EmitDebugLoc() { |
| 2687 | // Start the dwarf loc section. |
| 2688 | Asm->SwitchToDataSection(TAI->getDwarfLocSection()); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2689 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 2690 | Asm->EOL(); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2691 | } |
| 2692 | |
| 2693 | /// EmitDebugARanges - Emit visible names into a debug aranges section. |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2694 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2695 | void EmitDebugARanges() { |
| 2696 | // Start the dwarf aranges section. |
| 2697 | Asm->SwitchToDataSection(TAI->getDwarfARangesSection()); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2698 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2699 | // FIXME - Mock up |
Bill Wendling | d751c64 | 2008-09-26 00:28:12 +0000 | [diff] [blame] | 2700 | #if 0 |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2701 | CompileUnit *Unit = GetBaseCompileUnit(); |
| 2702 | |
Jim Laskey | 5496f01 | 2006-11-09 14:52:14 +0000 | [diff] [blame] | 2703 | // Don't include size of length |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2704 | Asm->EmitInt32(0x1c); Asm->EOL("Length of Address Ranges Info"); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2705 | |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2706 | Asm->EmitInt16(DWARF_VERSION); Asm->EOL("Dwarf Version"); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2707 | |
Jim Laskey | 5496f01 | 2006-11-09 14:52:14 +0000 | [diff] [blame] | 2708 | EmitReference("info_begin", Unit->getID()); |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2709 | Asm->EOL("Offset of Compilation Unit Info"); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2710 | |
Dan Gohman | 8248294 | 2007-09-27 23:12:31 +0000 | [diff] [blame] | 2711 | Asm->EmitInt8(TD->getPointerSize()); Asm->EOL("Size of Address"); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2712 | |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2713 | Asm->EmitInt8(0); Asm->EOL("Size of Segment Descriptor"); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2714 | |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2715 | Asm->EmitInt16(0); Asm->EOL("Pad (1)"); |
| 2716 | Asm->EmitInt16(0); Asm->EOL("Pad (2)"); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2717 | |
Jim Laskey | 5496f01 | 2006-11-09 14:52:14 +0000 | [diff] [blame] | 2718 | // Range 1 |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2719 | EmitReference("text_begin", 0); Asm->EOL("Address"); |
| 2720 | EmitDifference("text_end", 0, "text_begin", 0, true); Asm->EOL("Length"); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2721 | |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 2722 | Asm->EmitInt32(0); Asm->EOL("EOM (1)"); |
| 2723 | Asm->EmitInt32(0); Asm->EOL("EOM (2)"); |
Bill Wendling | d751c64 | 2008-09-26 00:28:12 +0000 | [diff] [blame] | 2724 | #endif |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2725 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 2726 | Asm->EOL(); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2727 | } |
| 2728 | |
| 2729 | /// EmitDebugRanges - Emit visible names into a debug ranges section. |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2730 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2731 | void EmitDebugRanges() { |
| 2732 | // Start the dwarf ranges section. |
| 2733 | Asm->SwitchToDataSection(TAI->getDwarfRangesSection()); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2734 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 2735 | Asm->EOL(); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2736 | } |
| 2737 | |
| 2738 | /// EmitDebugMacInfo - Emit visible names into a debug macinfo section. |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2739 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2740 | void EmitDebugMacInfo() { |
| 2741 | // Start the dwarf macinfo section. |
| 2742 | Asm->SwitchToDataSection(TAI->getDwarfMacInfoSection()); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2743 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 2744 | Asm->EOL(); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2745 | } |
| 2746 | |
Devang Patel | c452324 | 2009-01-05 23:11:11 +0000 | [diff] [blame] | 2747 | /// ConstructCompileUnits - Create a compile unit DIEs. |
Devang Patel | d1ca925 | 2009-01-05 23:03:32 +0000 | [diff] [blame] | 2748 | void ConstructCompileUnits() { |
| 2749 | std::string CUName = "llvm.dbg.compile_units"; |
| 2750 | std::vector<GlobalVariable*> Result; |
| 2751 | getGlobalVariablesUsing(*M, CUName, Result); |
| 2752 | for (std::vector<GlobalVariable *>::iterator RI = Result.begin(), |
| 2753 | RE = Result.end(); RI != RE; ++RI) { |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 2754 | DICompileUnit DIUnit(*RI); |
| 2755 | unsigned ID = RecordSource(DIUnit.getDirectory(), |
| 2756 | DIUnit.getFilename()); |
Devang Patel | d1ca925 | 2009-01-05 23:03:32 +0000 | [diff] [blame] | 2757 | |
| 2758 | DIE *Die = new DIE(DW_TAG_compile_unit); |
| 2759 | AddSectionOffset(Die, DW_AT_stmt_list, DW_FORM_data4, |
| 2760 | DWLabel("section_line", 0), DWLabel("section_line", 0), |
| 2761 | false); |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 2762 | AddString(Die, DW_AT_producer, DW_FORM_string, DIUnit.getProducer()); |
| 2763 | AddUInt(Die, DW_AT_language, DW_FORM_data1, DIUnit.getLanguage()); |
| 2764 | AddString(Die, DW_AT_name, DW_FORM_string, DIUnit.getFilename()); |
| 2765 | if (!DIUnit.getDirectory().empty()) |
| 2766 | AddString(Die, DW_AT_comp_dir, DW_FORM_string, DIUnit.getDirectory()); |
Devang Patel | d1ca925 | 2009-01-05 23:03:32 +0000 | [diff] [blame] | 2767 | |
| 2768 | CompileUnit *Unit = new CompileUnit(ID, Die); |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 2769 | DW_CUs[DIUnit.getGV()] = Unit; |
Devang Patel | d1ca925 | 2009-01-05 23:03:32 +0000 | [diff] [blame] | 2770 | } |
| 2771 | } |
| 2772 | |
Devang Patel | c452324 | 2009-01-05 23:11:11 +0000 | [diff] [blame] | 2773 | /// ConstructGlobalVariableDIEs - Create DIEs for each of the externally |
| 2774 | /// visible global variables. |
| 2775 | void ConstructGlobalVariableDIEs() { |
| 2776 | std::string GVName = "llvm.dbg.global_variables"; |
| 2777 | std::vector<GlobalVariable*> Result; |
| 2778 | getGlobalVariablesUsing(*M, GVName, Result); |
| 2779 | for (std::vector<GlobalVariable *>::iterator GVI = Result.begin(), |
| 2780 | GVE = Result.end(); GVI != GVE; ++GVI) { |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 2781 | DIGlobalVariable DI_GV(*GVI); |
| 2782 | CompileUnit *DW_Unit = FindCompileUnit(DI_GV.getCompileUnit()); |
Devang Patel | c452324 | 2009-01-05 23:11:11 +0000 | [diff] [blame] | 2783 | |
| 2784 | // Check for pre-existence. |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 2785 | DIE *&Slot = DW_Unit->getDieMapSlotFor(DI_GV.getGV()); |
Devang Patel | c452324 | 2009-01-05 23:11:11 +0000 | [diff] [blame] | 2786 | if (Slot) continue; |
| 2787 | |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 2788 | DIE *VariableDie = CreateGlobalVariableDIE(DW_Unit, DI_GV); |
Devang Patel | c452324 | 2009-01-05 23:11:11 +0000 | [diff] [blame] | 2789 | |
| 2790 | // Add address. |
| 2791 | DIEBlock *Block = new DIEBlock(); |
| 2792 | AddUInt(Block, 0, DW_FORM_data1, DW_OP_addr); |
| 2793 | AddObjectLabel(Block, 0, DW_FORM_udata, |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 2794 | Asm->getGlobalLinkName(DI_GV.getGV())); |
Devang Patel | c452324 | 2009-01-05 23:11:11 +0000 | [diff] [blame] | 2795 | AddBlock(VariableDie, DW_AT_location, 0, Block); |
| 2796 | |
| 2797 | //Add to map. |
| 2798 | Slot = VariableDie; |
| 2799 | |
| 2800 | //Add to context owner. |
| 2801 | DW_Unit->getDie()->AddChild(VariableDie); |
| 2802 | |
| 2803 | //Expose as global. FIXME - need to check external flag. |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 2804 | DW_Unit->AddGlobal(DI_GV.getName(), VariableDie); |
Devang Patel | c452324 | 2009-01-05 23:11:11 +0000 | [diff] [blame] | 2805 | } |
| 2806 | } |
| 2807 | |
Devang Patel | 78eb6ad | 2009-01-05 23:21:35 +0000 | [diff] [blame] | 2808 | /// ConstructSubprograms - Create DIEs for each of the externally visible |
| 2809 | /// subprograms. |
| 2810 | void ConstructSubprograms() { |
| 2811 | |
| 2812 | std::string SPName = "llvm.dbg.subprograms"; |
| 2813 | std::vector<GlobalVariable*> Result; |
| 2814 | getGlobalVariablesUsing(*M, SPName, Result); |
| 2815 | for (std::vector<GlobalVariable *>::iterator RI = Result.begin(), |
| 2816 | RE = Result.end(); RI != RE; ++RI) { |
| 2817 | |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 2818 | DISubprogram SP(*RI); |
| 2819 | CompileUnit *Unit = FindCompileUnit(SP.getCompileUnit()); |
Devang Patel | 78eb6ad | 2009-01-05 23:21:35 +0000 | [diff] [blame] | 2820 | |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 2821 | // Check for pre-existence. |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 2822 | DIE *&Slot = Unit->getDieMapSlotFor(SP.getGV()); |
Devang Patel | 78eb6ad | 2009-01-05 23:21:35 +0000 | [diff] [blame] | 2823 | if (Slot) continue; |
| 2824 | |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 2825 | DIE *SubprogramDie = CreateSubprogramDIE(Unit, SP); |
Devang Patel | 78eb6ad | 2009-01-05 23:21:35 +0000 | [diff] [blame] | 2826 | |
Devang Patel | 78eb6ad | 2009-01-05 23:21:35 +0000 | [diff] [blame] | 2827 | //Add to map. |
| 2828 | Slot = SubprogramDie; |
| 2829 | //Add to context owner. |
| 2830 | Unit->getDie()->AddChild(SubprogramDie); |
| 2831 | //Expose as global. |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 2832 | Unit->AddGlobal(SP.getName(), SubprogramDie); |
Devang Patel | 78eb6ad | 2009-01-05 23:21:35 +0000 | [diff] [blame] | 2833 | } |
| 2834 | } |
| 2835 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2836 | public: |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2837 | //===--------------------------------------------------------------------===// |
| 2838 | // Main entry points. |
| 2839 | // |
Owen Anderson | cb37188 | 2008-08-21 00:14:44 +0000 | [diff] [blame] | 2840 | DwarfDebug(raw_ostream &OS, AsmPrinter *A, const TargetAsmInfo *T) |
Chris Lattner | 9251f13 | 2007-09-24 03:35:37 +0000 | [diff] [blame] | 2841 | : Dwarf(OS, A, T, "dbg") |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2842 | , AbbreviationsSet(InitAbbreviationsSetSize) |
| 2843 | , Abbreviations() |
| 2844 | , ValuesSet(InitValuesSetSize) |
| 2845 | , Values() |
| 2846 | , StringPool() |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2847 | , SectionMap() |
| 2848 | , SectionSourceLines() |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 2849 | , didInitial(false) |
| 2850 | , shouldEmit(false) |
Devang Patel | 7a6e5a3 | 2009-01-08 02:33:41 +0000 | [diff] [blame] | 2851 | , RootDbgScope(NULL) |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2852 | { |
| 2853 | } |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 2854 | virtual ~DwarfDebug() { |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2855 | for (unsigned j = 0, M = Values.size(); j < M; ++j) |
| 2856 | delete Values[j]; |
| 2857 | } |
| 2858 | |
Devang Patel | 5d31598 | 2009-01-06 21:07:30 +0000 | [diff] [blame] | 2859 | /// SetDebugInfo - Create global DIEs and emit initial debug info sections. |
| 2860 | /// This is inovked by the target AsmPrinter. |
Devang Patel | 3f7833a | 2009-01-12 23:09:42 +0000 | [diff] [blame] | 2861 | void SetDebugInfo(MachineModuleInfo *mmi) { |
| 2862 | |
Devang Patel | 5d31598 | 2009-01-06 21:07:30 +0000 | [diff] [blame] | 2863 | // Create all the compile unit DIEs. |
| 2864 | ConstructCompileUnits(); |
Devang Patel | 3f7833a | 2009-01-12 23:09:42 +0000 | [diff] [blame] | 2865 | |
| 2866 | if (DW_CUs.empty()) |
| 2867 | return; |
| 2868 | |
| 2869 | MMI = mmi; |
| 2870 | shouldEmit = true; |
Devang Patel | e205162 | 2009-01-13 23:02:17 +0000 | [diff] [blame] | 2871 | MMI->setDebugInfoAvailability(true); |
Devang Patel | 5d31598 | 2009-01-06 21:07:30 +0000 | [diff] [blame] | 2872 | |
| 2873 | // Create DIEs for each of the externally visible global variables. |
| 2874 | ConstructGlobalVariableDIEs(); |
| 2875 | |
| 2876 | // Create DIEs for each of the externally visible subprograms. |
| 2877 | ConstructSubprograms(); |
| 2878 | |
| 2879 | // Prime section data. |
| 2880 | SectionMap.insert(TAI->getTextSection()); |
| 2881 | |
| 2882 | // Print out .file directives to specify files for .loc directives. These |
| 2883 | // are printed out early so that they precede any .loc directives. |
| 2884 | if (TAI->hasDotLocAndDotFile()) { |
| 2885 | for (unsigned i = 1, e = SrcFiles.size(); i <= e; ++i) { |
| 2886 | sys::Path FullPath(Directories[SrcFiles[i].getDirectoryID()]); |
| 2887 | bool AppendOk = FullPath.appendComponent(SrcFiles[i].getName()); |
| 2888 | assert(AppendOk && "Could not append filename to directory!"); |
| 2889 | AppendOk = false; |
| 2890 | Asm->EmitFile(i, FullPath.toString()); |
| 2891 | Asm->EOL(); |
| 2892 | } |
| 2893 | } |
| 2894 | |
| 2895 | // Emit initial sections |
| 2896 | EmitInitial(); |
| 2897 | } |
| 2898 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2899 | /// BeginModule - Emit all Dwarf sections that should come prior to the |
| 2900 | /// content. |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2901 | void BeginModule(Module *M) { |
| 2902 | this->M = M; |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2903 | } |
| 2904 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2905 | /// EndModule - Emit all Dwarf sections that should come after the content. |
| 2906 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2907 | void EndModule() { |
| 2908 | if (!ShouldEmitDwarf()) return; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2909 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2910 | // Standard sections final addresses. |
Anton Korobeynikov | d7ca416 | 2008-09-24 22:15:21 +0000 | [diff] [blame] | 2911 | Asm->SwitchToSection(TAI->getTextSection()); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2912 | EmitLabel("text_end", 0); |
Anton Korobeynikov | 315690e | 2008-09-24 22:16:16 +0000 | [diff] [blame] | 2913 | Asm->SwitchToSection(TAI->getDataSection()); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2914 | EmitLabel("data_end", 0); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2915 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2916 | // End text sections. |
| 2917 | for (unsigned i = 1, N = SectionMap.size(); i <= N; ++i) { |
Anton Korobeynikov | d7ca416 | 2008-09-24 22:15:21 +0000 | [diff] [blame] | 2918 | Asm->SwitchToSection(SectionMap[i]); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2919 | EmitLabel("section_end", i); |
| 2920 | } |
Anton Korobeynikov | 185bc89 | 2007-05-13 17:30:11 +0000 | [diff] [blame] | 2921 | |
| 2922 | // Emit common frame information. |
| 2923 | EmitCommonDebugFrame(); |
| 2924 | |
| 2925 | // Emit function debug frame information |
| 2926 | for (std::vector<FunctionDebugFrameInfo>::iterator I = DebugFrames.begin(), |
| 2927 | E = DebugFrames.end(); I != E; ++I) |
| 2928 | EmitFunctionDebugFrame(*I); |
| 2929 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2930 | // Compute DIE offsets and sizes. |
| 2931 | SizeAndOffsets(); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2932 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2933 | // Emit all the DIEs into a debug info section |
| 2934 | EmitDebugInfo(); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2935 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2936 | // Corresponding abbreviations into a abbrev section. |
| 2937 | EmitAbbreviations(); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2938 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2939 | // Emit source line correspondence into a debug line section. |
| 2940 | EmitDebugLines(); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2941 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2942 | // Emit info into a debug pubnames section. |
| 2943 | EmitDebugPubNames(); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2944 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2945 | // Emit info into a debug str section. |
| 2946 | EmitDebugStr(); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2947 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2948 | // Emit info into a debug loc section. |
| 2949 | EmitDebugLoc(); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2950 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2951 | // Emit info into a debug aranges section. |
| 2952 | EmitDebugARanges(); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2953 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2954 | // Emit info into a debug ranges section. |
| 2955 | EmitDebugRanges(); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2956 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2957 | // Emit info into a debug macinfo section. |
| 2958 | EmitDebugMacInfo(); |
| 2959 | } |
| 2960 | |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2961 | /// BeginFunction - Gather pre-function debug information. Assumes being |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2962 | /// emitted immediately after the function entry point. |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2963 | void BeginFunction(MachineFunction *MF) { |
| 2964 | this->MF = MF; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2965 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2966 | if (!ShouldEmitDwarf()) return; |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2967 | |
| 2968 | // Begin accumulating function debug information. |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 2969 | MMI->BeginFunction(MF); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2970 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2971 | // Assumes in correct section after the entry point. |
| 2972 | EmitLabel("func_begin", ++SubprogramCount); |
Evan Cheng | 1b08bbc | 2008-02-01 09:10:45 +0000 | [diff] [blame] | 2973 | |
| 2974 | // Emit label for the implicitly defined dbg.stoppoint at the start of |
| 2975 | // the function. |
Devang Patel | f3ee514 | 2009-01-12 22:54:42 +0000 | [diff] [blame] | 2976 | if (!Lines.empty()) { |
| 2977 | const SrcLineInfo &LineInfo = Lines[0]; |
Andrew Lenharth | 51dd8c9 | 2008-04-03 17:37:43 +0000 | [diff] [blame] | 2978 | Asm->printLabel(LineInfo.getLabelID()); |
| 2979 | } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2980 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2981 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2982 | /// EndFunction - Gather and emit post-function debug information. |
| 2983 | /// |
Bill Wendling | d751c64 | 2008-09-26 00:28:12 +0000 | [diff] [blame] | 2984 | void EndFunction(MachineFunction *MF) { |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2985 | if (!ShouldEmitDwarf()) return; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2986 | |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 2987 | // Define end label for subprogram. |
| 2988 | EmitLabel("func_end", SubprogramCount); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 2989 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2990 | // Get function line info. |
Devang Patel | f3ee514 | 2009-01-12 22:54:42 +0000 | [diff] [blame] | 2991 | if (!Lines.empty()) { |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2992 | // Get section line info. |
Anton Korobeynikov | d7ca416 | 2008-09-24 22:15:21 +0000 | [diff] [blame] | 2993 | unsigned ID = SectionMap.insert(Asm->CurrentSection_); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2994 | if (SectionSourceLines.size() < ID) SectionSourceLines.resize(ID); |
Devang Patel | f3ee514 | 2009-01-12 22:54:42 +0000 | [diff] [blame] | 2995 | std::vector<SrcLineInfo> &SectionLineInfos = SectionSourceLines[ID-1]; |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2996 | // Append the function info to section info. |
| 2997 | SectionLineInfos.insert(SectionLineInfos.end(), |
Devang Patel | f3ee514 | 2009-01-12 22:54:42 +0000 | [diff] [blame] | 2998 | Lines.begin(), Lines.end()); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 2999 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3000 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 3001 | // Construct scopes for subprogram. |
Devang Patel | 7bb89ed | 2009-01-13 00:20:51 +0000 | [diff] [blame] | 3002 | if (RootDbgScope) |
| 3003 | ConstructRootDbgScope(RootDbgScope); |
Bill Wendling | d751c64 | 2008-09-26 00:28:12 +0000 | [diff] [blame] | 3004 | else |
| 3005 | // FIXME: This is wrong. We are essentially getting past a problem with |
| 3006 | // debug information not being able to handle unreachable blocks that have |
| 3007 | // debug information in them. In particular, those unreachable blocks that |
| 3008 | // have "region end" info in them. That situation results in the "root |
| 3009 | // scope" not being created. If that's the case, then emit a "default" |
| 3010 | // scope, i.e., one that encompasses the whole function. This isn't |
| 3011 | // desirable. And a better way of handling this (and all of the debugging |
| 3012 | // information) needs to be explored. |
Devang Patel | 7bb89ed | 2009-01-13 00:20:51 +0000 | [diff] [blame] | 3013 | ConstructDefaultDbgScope(MF); |
Anton Korobeynikov | 185bc89 | 2007-05-13 17:30:11 +0000 | [diff] [blame] | 3014 | |
| 3015 | DebugFrames.push_back(FunctionDebugFrameInfo(SubprogramCount, |
| 3016 | MMI->getFrameMoves())); |
Devang Patel | 481ff5b | 2009-01-12 18:48:36 +0000 | [diff] [blame] | 3017 | |
| 3018 | // Clear debug info |
| 3019 | if (RootDbgScope) { |
| 3020 | delete RootDbgScope; |
| 3021 | DbgScopeMap.clear(); |
| 3022 | RootDbgScope = NULL; |
| 3023 | } |
| 3024 | Lines.clear(); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 3025 | } |
Devang Patel | ccca7fe | 2009-01-12 19:17:34 +0000 | [diff] [blame] | 3026 | |
| 3027 | public: |
| 3028 | |
Devang Patel | cf3a448 | 2009-01-15 23:41:32 +0000 | [diff] [blame] | 3029 | /// ValidDebugInfo - Return true if V represents valid debug info value. |
| 3030 | bool ValidDebugInfo(Value *V) { |
Devang Patel | 61c6bf3 | 2009-01-16 01:49:46 +0000 | [diff] [blame] | 3031 | |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 3032 | if (!V) |
| 3033 | return false; |
| 3034 | |
Devang Patel | 61c6bf3 | 2009-01-16 01:49:46 +0000 | [diff] [blame] | 3035 | if (!shouldEmit) |
| 3036 | return false; |
| 3037 | |
Devang Patel | cf3a448 | 2009-01-15 23:41:32 +0000 | [diff] [blame] | 3038 | GlobalVariable *GV = getGlobalVariable(V); |
| 3039 | if (!GV) |
| 3040 | return false; |
| 3041 | |
| 3042 | if (GV->getLinkage() != GlobalValue::InternalLinkage |
| 3043 | && GV->getLinkage() != GlobalValue::LinkOnceLinkage) |
| 3044 | return false; |
| 3045 | |
| 3046 | DIDescriptor DI(GV); |
| 3047 | // Check current version. Allow Version6 for now. |
| 3048 | unsigned Version = DI.getVersion(); |
| 3049 | if (Version != DIDescriptor::Version7 && Version != DIDescriptor::Version6) |
| 3050 | return false; |
| 3051 | |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 3052 | unsigned Tag = DI.getTag(); |
| 3053 | switch (Tag) { |
| 3054 | case DW_TAG_variable: |
| 3055 | assert (DIVariable(GV).Verify() && "Invalid DebugInfo value"); |
| 3056 | break; |
| 3057 | case DW_TAG_compile_unit: |
| 3058 | assert (DICompileUnit(GV).Verify() && "Invalid DebugInfo value"); |
| 3059 | break; |
| 3060 | case DW_TAG_subprogram: |
| 3061 | assert (DISubprogram(GV).Verify() && "Invalid DebugInfo value"); |
| 3062 | break; |
| 3063 | default: |
| 3064 | break; |
| 3065 | } |
| 3066 | |
Devang Patel | cf3a448 | 2009-01-15 23:41:32 +0000 | [diff] [blame] | 3067 | return true; |
| 3068 | } |
| 3069 | |
Devang Patel | ccca7fe | 2009-01-12 19:17:34 +0000 | [diff] [blame] | 3070 | /// RecordSourceLine - Records location information and associates it with a |
| 3071 | /// label. Returns a unique label ID used to generate a label and provide |
| 3072 | /// correspondence to the source line list. |
| 3073 | unsigned RecordSourceLine(Value *V, unsigned Line, unsigned Col) { |
| 3074 | CompileUnit *Unit = DW_CUs[V]; |
| 3075 | assert (Unit && "Unable to find CompileUnit"); |
| 3076 | unsigned ID = MMI->NextLabelID(); |
| 3077 | Lines.push_back(SrcLineInfo(Line, Col, Unit->getID(), ID)); |
| 3078 | return ID; |
| 3079 | } |
| 3080 | |
| 3081 | /// RecordSourceLine - Records location information and associates it with a |
| 3082 | /// label. Returns a unique label ID used to generate a label and provide |
| 3083 | /// correspondence to the source line list. |
| 3084 | unsigned RecordSourceLine(unsigned Line, unsigned Col, unsigned Src) { |
| 3085 | unsigned ID = MMI->NextLabelID(); |
| 3086 | Lines.push_back(SrcLineInfo(Line, Col, Src, ID)); |
| 3087 | return ID; |
| 3088 | } |
| 3089 | |
| 3090 | unsigned getRecordSourceLineCount() { |
| 3091 | return Lines.size(); |
| 3092 | } |
| 3093 | |
| 3094 | /// RecordSource - Register a source file with debug info. Returns an source |
| 3095 | /// ID. |
| 3096 | unsigned RecordSource(const std::string &Directory, |
| 3097 | const std::string &File) { |
| 3098 | unsigned DID = Directories.insert(Directory); |
| 3099 | return SrcFiles.insert(SrcFileInfo(DID,File)); |
| 3100 | } |
| 3101 | |
| 3102 | /// RecordRegionStart - Indicate the start of a region. |
| 3103 | /// |
| 3104 | unsigned RecordRegionStart(GlobalVariable *V) { |
| 3105 | DbgScope *Scope = getOrCreateScope(V); |
| 3106 | unsigned ID = MMI->NextLabelID(); |
| 3107 | if (!Scope->getStartLabelID()) Scope->setStartLabelID(ID); |
| 3108 | return ID; |
| 3109 | } |
| 3110 | |
| 3111 | /// RecordRegionEnd - Indicate the end of a region. |
| 3112 | /// |
| 3113 | unsigned RecordRegionEnd(GlobalVariable *V) { |
| 3114 | DbgScope *Scope = getOrCreateScope(V); |
| 3115 | unsigned ID = MMI->NextLabelID(); |
| 3116 | Scope->setEndLabelID(ID); |
| 3117 | return ID; |
| 3118 | } |
| 3119 | |
| 3120 | /// RecordVariable - Indicate the declaration of a local variable. |
| 3121 | /// |
| 3122 | void RecordVariable(GlobalVariable *GV, unsigned FrameIndex) { |
Devang Patel | 0e5200f | 2009-01-15 18:25:17 +0000 | [diff] [blame] | 3123 | DIDescriptor Desc(GV); |
| 3124 | DbgScope *Scope = NULL; |
| 3125 | if (Desc.getTag() == DW_TAG_variable) { |
| 3126 | // GV is a global variable. |
| 3127 | DIGlobalVariable DG(GV); |
| 3128 | Scope = getOrCreateScope(DG.getContext().getGV()); |
| 3129 | } else { |
| 3130 | // or GV is a local variable. |
| 3131 | DIVariable DV(GV); |
| 3132 | Scope = getOrCreateScope(DV.getContext().getGV()); |
| 3133 | } |
| 3134 | assert (Scope && "Unable to find variable' scope"); |
Devang Patel | 99ec353 | 2009-01-16 19:28:14 +0000 | [diff] [blame] | 3135 | DbgVariable *DV = new DbgVariable(DIVariable(GV), FrameIndex); |
Devang Patel | ccca7fe | 2009-01-12 19:17:34 +0000 | [diff] [blame] | 3136 | Scope->AddVariable(DV); |
| 3137 | } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 3138 | }; |
| 3139 | |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 3140 | //===----------------------------------------------------------------------===// |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3141 | /// DwarfException - Emits Dwarf exception handling directives. |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 3142 | /// |
| 3143 | class DwarfException : public Dwarf { |
| 3144 | |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 3145 | private: |
Anton Korobeynikov | 0ff3ca4 | 2007-05-12 22:36:25 +0000 | [diff] [blame] | 3146 | struct FunctionEHFrameInfo { |
| 3147 | std::string FnName; |
| 3148 | unsigned Number; |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 3149 | unsigned PersonalityIndex; |
Anton Korobeynikov | 0ff3ca4 | 2007-05-12 22:36:25 +0000 | [diff] [blame] | 3150 | bool hasCalls; |
| 3151 | bool hasLandingPads; |
| 3152 | std::vector<MachineMove> Moves; |
Dale Johannesen | 48ae02f | 2008-01-16 19:59:28 +0000 | [diff] [blame] | 3153 | const Function * function; |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 3154 | |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 3155 | FunctionEHFrameInfo(const std::string &FN, unsigned Num, unsigned P, |
| 3156 | bool hC, bool hL, |
Dale Johannesen | 1d4ce2a | 2007-11-20 23:24:42 +0000 | [diff] [blame] | 3157 | const std::vector<MachineMove> &M, |
Dale Johannesen | 48ae02f | 2008-01-16 19:59:28 +0000 | [diff] [blame] | 3158 | const Function *f): |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 3159 | FnName(FN), Number(Num), PersonalityIndex(P), |
Dale Johannesen | 48ae02f | 2008-01-16 19:59:28 +0000 | [diff] [blame] | 3160 | hasCalls(hC), hasLandingPads(hL), Moves(M), function (f) { } |
Anton Korobeynikov | 0ff3ca4 | 2007-05-12 22:36:25 +0000 | [diff] [blame] | 3161 | }; |
| 3162 | |
| 3163 | std::vector<FunctionEHFrameInfo> EHFrames; |
Dale Johannesen | 1532f3d | 2008-04-02 00:25:04 +0000 | [diff] [blame] | 3164 | |
| 3165 | /// shouldEmitTable - Per-function flag to indicate if EH tables should |
| 3166 | /// be emitted. |
| 3167 | bool shouldEmitTable; |
| 3168 | |
| 3169 | /// shouldEmitMoves - Per-function flag to indicate if frame moves info |
| 3170 | /// should be emitted. |
| 3171 | bool shouldEmitMoves; |
| 3172 | |
| 3173 | /// shouldEmitTableModule - Per-module flag to indicate if EH tables |
| 3174 | /// should be emitted. |
| 3175 | bool shouldEmitTableModule; |
| 3176 | |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3177 | /// shouldEmitFrameModule - Per-module flag to indicate if frame moves |
Dale Johannesen | 1532f3d | 2008-04-02 00:25:04 +0000 | [diff] [blame] | 3178 | /// should be emitted. |
| 3179 | bool shouldEmitMovesModule; |
Duncan Sands | 671fa97 | 2008-05-07 19:11:09 +0000 | [diff] [blame] | 3180 | |
Jim Laskey | 3f09fc2 | 2007-02-28 18:38:31 +0000 | [diff] [blame] | 3181 | /// EmitCommonEHFrame - Emit the common eh unwind frame. |
| 3182 | /// |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 3183 | void EmitCommonEHFrame(const Function *Personality, unsigned Index) { |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3184 | // Size and sign of stack growth. |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 3185 | int stackGrowth = |
| 3186 | Asm->TM.getFrameInfo()->getStackGrowthDirection() == |
| 3187 | TargetFrameInfo::StackGrowsUp ? |
Dan Gohman | 8248294 | 2007-09-27 23:12:31 +0000 | [diff] [blame] | 3188 | TD->getPointerSize() : -TD->getPointerSize(); |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 3189 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3190 | // Begin eh frame section. |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 3191 | Asm->SwitchToTextSection(TAI->getDwarfEHFrameSection()); |
Bill Wendling | 722f5f1 | 2008-12-24 08:05:17 +0000 | [diff] [blame] | 3192 | |
| 3193 | if (!TAI->doesRequireNonLocalEHFrameLabel()) |
| 3194 | O << TAI->getEHGlobalPrefix(); |
| 3195 | O << "EH_frame" << Index << ":\n"; |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 3196 | EmitLabel("section_eh_frame", Index); |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 3197 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3198 | // Define base labels. |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 3199 | EmitLabel("eh_frame_common", Index); |
Duncan Sands | 671fa97 | 2008-05-07 19:11:09 +0000 | [diff] [blame] | 3200 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3201 | // Define the eh frame length. |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 3202 | EmitDifference("eh_frame_common_end", Index, |
| 3203 | "eh_frame_common_begin", Index, true); |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 3204 | Asm->EOL("Length of Common Information Entry"); |
| 3205 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3206 | // EH frame header. |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 3207 | EmitLabel("eh_frame_common_begin", Index); |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 3208 | Asm->EmitInt32((int)0); |
| 3209 | Asm->EOL("CIE Identifier Tag"); |
| 3210 | Asm->EmitInt8(DW_CIE_VERSION); |
| 3211 | Asm->EOL("CIE Version"); |
Duncan Sands | 671fa97 | 2008-05-07 19:11:09 +0000 | [diff] [blame] | 3212 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3213 | // The personality presence indicates that language specific information |
| 3214 | // will show up in the eh frame. |
| 3215 | Asm->EmitString(Personality ? "zPLR" : "zR"); |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 3216 | Asm->EOL("CIE Augmentation"); |
Duncan Sands | 671fa97 | 2008-05-07 19:11:09 +0000 | [diff] [blame] | 3217 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3218 | // Round out reader. |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 3219 | Asm->EmitULEB128Bytes(1); |
| 3220 | Asm->EOL("CIE Code Alignment Factor"); |
| 3221 | Asm->EmitSLEB128Bytes(stackGrowth); |
Duncan Sands | 671fa97 | 2008-05-07 19:11:09 +0000 | [diff] [blame] | 3222 | Asm->EOL("CIE Data Alignment Factor"); |
Dale Johannesen | b97aec6 | 2007-11-13 19:13:01 +0000 | [diff] [blame] | 3223 | Asm->EmitInt8(RI->getDwarfRegNum(RI->getRARegister(), true)); |
Duncan Sands | 671fa97 | 2008-05-07 19:11:09 +0000 | [diff] [blame] | 3224 | Asm->EOL("CIE Return Address Column"); |
| 3225 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3226 | // If there is a personality, we need to indicate the functions location. |
| 3227 | if (Personality) { |
| 3228 | Asm->EmitULEB128Bytes(7); |
| 3229 | Asm->EOL("Augmentation Size"); |
Bill Wendling | ef4a661 | 2007-09-11 17:20:55 +0000 | [diff] [blame] | 3230 | |
Duncan Sands | 671fa97 | 2008-05-07 19:11:09 +0000 | [diff] [blame] | 3231 | if (TAI->getNeedsIndirectEncoding()) { |
Bill Wendling | ef4a661 | 2007-09-11 17:20:55 +0000 | [diff] [blame] | 3232 | Asm->EmitInt8(DW_EH_PE_pcrel | DW_EH_PE_sdata4 | DW_EH_PE_indirect); |
Duncan Sands | 671fa97 | 2008-05-07 19:11:09 +0000 | [diff] [blame] | 3233 | Asm->EOL("Personality (pcrel sdata4 indirect)"); |
| 3234 | } else { |
Bill Wendling | ef4a661 | 2007-09-11 17:20:55 +0000 | [diff] [blame] | 3235 | Asm->EmitInt8(DW_EH_PE_pcrel | DW_EH_PE_sdata4); |
Duncan Sands | 671fa97 | 2008-05-07 19:11:09 +0000 | [diff] [blame] | 3236 | Asm->EOL("Personality (pcrel sdata4)"); |
| 3237 | } |
Bill Wendling | ef4a661 | 2007-09-11 17:20:55 +0000 | [diff] [blame] | 3238 | |
Duncan Sands | 671fa97 | 2008-05-07 19:11:09 +0000 | [diff] [blame] | 3239 | PrintRelDirective(true); |
Bill Wendling | d60da49 | 2007-09-11 08:27:17 +0000 | [diff] [blame] | 3240 | O << TAI->getPersonalityPrefix(); |
| 3241 | Asm->EmitExternalGlobal((const GlobalVariable *)(Personality)); |
| 3242 | O << TAI->getPersonalitySuffix(); |
Duncan Sands | 43b30a8 | 2008-05-08 12:33:11 +0000 | [diff] [blame] | 3243 | if (strcmp(TAI->getPersonalitySuffix(), "+4@GOTPCREL")) |
| 3244 | O << "-" << TAI->getPCSymbol(); |
Bill Wendling | d60da49 | 2007-09-11 08:27:17 +0000 | [diff] [blame] | 3245 | Asm->EOL("Personality"); |
Bill Wendling | cf4bb31 | 2007-08-25 00:51:55 +0000 | [diff] [blame] | 3246 | |
Duncan Sands | 671fa97 | 2008-05-07 19:11:09 +0000 | [diff] [blame] | 3247 | Asm->EmitInt8(DW_EH_PE_pcrel | DW_EH_PE_sdata4); |
| 3248 | Asm->EOL("LSDA Encoding (pcrel sdata4)"); |
Bill Wendling | d4121be | 2008-12-24 05:25:49 +0000 | [diff] [blame] | 3249 | |
Bill Wendling | d60de51 | 2009-01-05 22:53:45 +0000 | [diff] [blame] | 3250 | Asm->EmitInt8(DW_EH_PE_pcrel | DW_EH_PE_sdata4); |
| 3251 | Asm->EOL("FDE Encoding (pcrel sdata4)"); |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3252 | } else { |
| 3253 | Asm->EmitULEB128Bytes(1); |
| 3254 | Asm->EOL("Augmentation Size"); |
Bill Wendling | d4121be | 2008-12-24 05:25:49 +0000 | [diff] [blame] | 3255 | |
Bill Wendling | d60de51 | 2009-01-05 22:53:45 +0000 | [diff] [blame] | 3256 | Asm->EmitInt8(DW_EH_PE_pcrel | DW_EH_PE_sdata4); |
| 3257 | Asm->EOL("FDE Encoding (pcrel sdata4)"); |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3258 | } |
| 3259 | |
| 3260 | // Indicate locations of general callee saved registers in frame. |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 3261 | std::vector<MachineMove> Moves; |
| 3262 | RI->getInitialFrameState(Moves); |
Dale Johannesen | b97aec6 | 2007-11-13 19:13:01 +0000 | [diff] [blame] | 3263 | EmitFrameMoves(NULL, 0, Moves, true); |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 3264 | |
Dale Johannesen | 21d972a | 2008-04-30 00:43:29 +0000 | [diff] [blame] | 3265 | // On Darwin the linker honors the alignment of eh_frame, which means it |
| 3266 | // must be 8-byte on 64-bit targets to match what gcc does. Otherwise |
| 3267 | // you get holes which confuse readers of eh_frame. |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3268 | Asm->EmitAlignment(TD->getPointerSize() == sizeof(int32_t) ? 2 : 3, |
Dale Johannesen | 7b251e0 | 2008-04-29 22:58:20 +0000 | [diff] [blame] | 3269 | 0, 0, false); |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 3270 | EmitLabel("eh_frame_common_end", Index); |
Duncan Sands | 671fa97 | 2008-05-07 19:11:09 +0000 | [diff] [blame] | 3271 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3272 | Asm->EOL(); |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 3273 | } |
Duncan Sands | 671fa97 | 2008-05-07 19:11:09 +0000 | [diff] [blame] | 3274 | |
Anton Korobeynikov | 0ff3ca4 | 2007-05-12 22:36:25 +0000 | [diff] [blame] | 3275 | /// EmitEHFrame - Emit function exception frame information. |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 3276 | /// |
Anton Korobeynikov | 0ff3ca4 | 2007-05-12 22:36:25 +0000 | [diff] [blame] | 3277 | void EmitEHFrame(const FunctionEHFrameInfo &EHFrameInfo) { |
Dale Johannesen | 48ae02f | 2008-01-16 19:59:28 +0000 | [diff] [blame] | 3278 | Function::LinkageTypes linkage = EHFrameInfo.function->getLinkage(); |
| 3279 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3280 | Asm->SwitchToTextSection(TAI->getDwarfEHFrameSection()); |
| 3281 | |
| 3282 | // Externally visible entry into the functions eh frame info. |
Dale Johannesen | 1d4ce2a | 2007-11-20 23:24:42 +0000 | [diff] [blame] | 3283 | // If the corresponding function is static, this should not be |
| 3284 | // externally visible. |
Rafael Espindola | bb46f52 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 3285 | if (linkage != Function::InternalLinkage && |
Devang Patel | 2d1768c | 2009-01-17 08:05:14 +0000 | [diff] [blame] | 3286 | linkage != Function::PrivateLinkage) { |
Dale Johannesen | 1d4ce2a | 2007-11-20 23:24:42 +0000 | [diff] [blame] | 3287 | if (const char *GlobalEHDirective = TAI->getGlobalEHDirective()) |
| 3288 | O << GlobalEHDirective << EHFrameInfo.FnName << "\n"; |
| 3289 | } |
| 3290 | |
Dale Johannesen | 038129d | 2008-01-10 02:03:30 +0000 | [diff] [blame] | 3291 | // If corresponding function is weak definition, this should be too. |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3292 | if ((linkage == Function::WeakLinkage || |
Dale Johannesen | 48ae02f | 2008-01-16 19:59:28 +0000 | [diff] [blame] | 3293 | linkage == Function::LinkOnceLinkage) && |
Dale Johannesen | 038129d | 2008-01-10 02:03:30 +0000 | [diff] [blame] | 3294 | TAI->getWeakDefDirective()) |
| 3295 | O << TAI->getWeakDefDirective() << EHFrameInfo.FnName << "\n"; |
| 3296 | |
| 3297 | // If there are no calls then you can't unwind. This may mean we can |
| 3298 | // omit the EH Frame, but some environments do not handle weak absolute |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3299 | // symbols. |
Dale Johannesen | 3541af7 | 2008-04-14 17:54:17 +0000 | [diff] [blame] | 3300 | // If UnwindTablesMandatory is set we cannot do this optimization; the |
Dale Johannesen | 4e1b794 | 2008-04-08 00:10:24 +0000 | [diff] [blame] | 3301 | // unwind info is to be available for non-EH uses. |
Dale Johannesen | 038129d | 2008-01-10 02:03:30 +0000 | [diff] [blame] | 3302 | if (!EHFrameInfo.hasCalls && |
Dale Johannesen | 3541af7 | 2008-04-14 17:54:17 +0000 | [diff] [blame] | 3303 | !UnwindTablesMandatory && |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3304 | ((linkage != Function::WeakLinkage && |
Dale Johannesen | 48ae02f | 2008-01-16 19:59:28 +0000 | [diff] [blame] | 3305 | linkage != Function::LinkOnceLinkage) || |
Dale Johannesen | 038129d | 2008-01-10 02:03:30 +0000 | [diff] [blame] | 3306 | !TAI->getWeakDefDirective() || |
| 3307 | TAI->getSupportsWeakOmittedEHFrame())) |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3308 | { |
Bill Wendling | 6e19896 | 2007-09-18 01:47:22 +0000 | [diff] [blame] | 3309 | O << EHFrameInfo.FnName << " = 0\n"; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3310 | // This name has no connection to the function, so it might get |
| 3311 | // dead-stripped when the function is not, erroneously. Prohibit |
Dale Johannesen | 48ae02f | 2008-01-16 19:59:28 +0000 | [diff] [blame] | 3312 | // dead-stripping unconditionally. |
| 3313 | if (const char *UsedDirective = TAI->getUsedDirective()) |
| 3314 | O << UsedDirective << EHFrameInfo.FnName << "\n\n"; |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3315 | } else { |
Bill Wendling | 6e19896 | 2007-09-18 01:47:22 +0000 | [diff] [blame] | 3316 | O << EHFrameInfo.FnName << ":\n"; |
Dale Johannesen | 1d4ce2a | 2007-11-20 23:24:42 +0000 | [diff] [blame] | 3317 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3318 | // EH frame header. |
Anton Korobeynikov | 0ff3ca4 | 2007-05-12 22:36:25 +0000 | [diff] [blame] | 3319 | EmitDifference("eh_frame_end", EHFrameInfo.Number, |
| 3320 | "eh_frame_begin", EHFrameInfo.Number, true); |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3321 | Asm->EOL("Length of Frame Information Entry"); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3322 | |
Anton Korobeynikov | 0ff3ca4 | 2007-05-12 22:36:25 +0000 | [diff] [blame] | 3323 | EmitLabel("eh_frame_begin", EHFrameInfo.Number); |
Anton Korobeynikov | a6199c8 | 2007-03-07 02:47:57 +0000 | [diff] [blame] | 3324 | |
Bill Wendling | 722f5f1 | 2008-12-24 08:05:17 +0000 | [diff] [blame] | 3325 | if (TAI->doesRequireNonLocalEHFrameLabel()) { |
| 3326 | PrintRelDirective(true, true); |
| 3327 | PrintLabelName("eh_frame_begin", EHFrameInfo.Number); |
| 3328 | |
| 3329 | if (!TAI->isAbsoluteEHSectionOffsets()) |
| 3330 | O << "-EH_frame" << EHFrameInfo.PersonalityIndex; |
| 3331 | } else { |
| 3332 | EmitSectionOffset("eh_frame_begin", "eh_frame_common", |
| 3333 | EHFrameInfo.Number, EHFrameInfo.PersonalityIndex, |
| 3334 | true, true, false); |
| 3335 | } |
| 3336 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3337 | Asm->EOL("FDE CIE offset"); |
| 3338 | |
Bill Wendling | 5fe1fac | 2009-01-06 19:13:55 +0000 | [diff] [blame] | 3339 | EmitReference("eh_func_begin", EHFrameInfo.Number, true, true); |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3340 | Asm->EOL("FDE initial location"); |
Anton Korobeynikov | 0ff3ca4 | 2007-05-12 22:36:25 +0000 | [diff] [blame] | 3341 | EmitDifference("eh_func_end", EHFrameInfo.Number, |
Bill Wendling | 5fe1fac | 2009-01-06 19:13:55 +0000 | [diff] [blame] | 3342 | "eh_func_begin", EHFrameInfo.Number, true); |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3343 | Asm->EOL("FDE address range"); |
Duncan Sands | 671fa97 | 2008-05-07 19:11:09 +0000 | [diff] [blame] | 3344 | |
Jim Laskey | 3f09fc2 | 2007-02-28 18:38:31 +0000 | [diff] [blame] | 3345 | // If there is a personality and landing pads then point to the language |
| 3346 | // specific data area in the exception table. |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 3347 | if (EHFrameInfo.PersonalityIndex) { |
Duncan Sands | 671fa97 | 2008-05-07 19:11:09 +0000 | [diff] [blame] | 3348 | Asm->EmitULEB128Bytes(4); |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3349 | Asm->EOL("Augmentation size"); |
Duncan Sands | 671fa97 | 2008-05-07 19:11:09 +0000 | [diff] [blame] | 3350 | |
| 3351 | if (EHFrameInfo.hasLandingPads) |
| 3352 | EmitReference("exception", EHFrameInfo.Number, true, true); |
| 3353 | else |
Jim Laskey | 3f09fc2 | 2007-02-28 18:38:31 +0000 | [diff] [blame] | 3354 | Asm->EmitInt32((int)0); |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3355 | Asm->EOL("Language Specific Data Area"); |
| 3356 | } else { |
| 3357 | Asm->EmitULEB128Bytes(0); |
| 3358 | Asm->EOL("Augmentation size"); |
| 3359 | } |
Duncan Sands | 671fa97 | 2008-05-07 19:11:09 +0000 | [diff] [blame] | 3360 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3361 | // Indicate locations of function specific callee saved registers in |
| 3362 | // frame. |
Devang Patel | 5aac3d3 | 2009-01-17 08:01:33 +0000 | [diff] [blame] | 3363 | EmitFrameMoves("eh_func_begin", EHFrameInfo.Number, EHFrameInfo.Moves, |
Devang Patel | 2d1768c | 2009-01-17 08:05:14 +0000 | [diff] [blame] | 3364 | true); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3365 | |
Dale Johannesen | 21d972a | 2008-04-30 00:43:29 +0000 | [diff] [blame] | 3366 | // On Darwin the linker honors the alignment of eh_frame, which means it |
| 3367 | // must be 8-byte on 64-bit targets to match what gcc does. Otherwise |
| 3368 | // you get holes which confuse readers of eh_frame. |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3369 | Asm->EmitAlignment(TD->getPointerSize() == sizeof(int32_t) ? 2 : 3, |
Dale Johannesen | 7b251e0 | 2008-04-29 22:58:20 +0000 | [diff] [blame] | 3370 | 0, 0, false); |
Anton Korobeynikov | 0ff3ca4 | 2007-05-12 22:36:25 +0000 | [diff] [blame] | 3371 | EmitLabel("eh_frame_end", EHFrameInfo.Number); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3372 | |
| 3373 | // If the function is marked used, this table should be also. We cannot |
Dale Johannesen | 48ae02f | 2008-01-16 19:59:28 +0000 | [diff] [blame] | 3374 | // make the mark unconditional in this case, since retaining the table |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3375 | // also retains the function in this case, and there is code around |
Dale Johannesen | 48ae02f | 2008-01-16 19:59:28 +0000 | [diff] [blame] | 3376 | // that depends on unused functions (calling undefined externals) being |
| 3377 | // dead-stripped to link correctly. Yes, there really is. |
| 3378 | if (MMI->getUsedFunctions().count(EHFrameInfo.function)) |
| 3379 | if (const char *UsedDirective = TAI->getUsedDirective()) |
| 3380 | O << UsedDirective << EHFrameInfo.FnName << "\n\n"; |
| 3381 | } |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3382 | } |
Duncan Sands | 7bf7a44 | 2007-05-21 18:50:28 +0000 | [diff] [blame] | 3383 | |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3384 | /// EmitExceptionTable - Emit landing pads and actions. |
Duncan Sands | fccf0a2 | 2007-07-06 12:46:24 +0000 | [diff] [blame] | 3385 | /// |
| 3386 | /// The general organization of the table is complex, but the basic concepts |
| 3387 | /// are easy. First there is a header which describes the location and |
| 3388 | /// organization of the three components that follow. |
| 3389 | /// 1. The landing pad site information describes the range of code covered |
| 3390 | /// by the try. In our case it's an accumulation of the ranges covered |
| 3391 | /// by the invokes in the try. There is also a reference to the landing |
| 3392 | /// pad that handles the exception once processed. Finally an index into |
| 3393 | /// the actions table. |
| 3394 | /// 2. The action table, in our case, is composed of pairs of type ids |
| 3395 | /// and next action offset. Starting with the action index from the |
| 3396 | /// landing pad site, each type Id is checked for a match to the current |
| 3397 | /// exception. If it matches then the exception and type id are passed |
| 3398 | /// on to the landing pad. Otherwise the next action is looked up. This |
| 3399 | /// chain is terminated with a next action of zero. If no type id is |
| 3400 | /// found the the frame is unwound and handling continues. |
| 3401 | /// 3. Type id table contains references to all the C++ typeinfo for all |
| 3402 | /// catches in the function. This tables is reversed indexed base 1. |
| 3403 | |
Duncan Sands | b32edb4 | 2007-06-06 15:37:31 +0000 | [diff] [blame] | 3404 | /// SharedTypeIds - How many leading type ids two landing pads have in common. |
| 3405 | static unsigned SharedTypeIds(const LandingPadInfo *L, |
| 3406 | const LandingPadInfo *R) { |
| 3407 | const std::vector<int> &LIds = L->TypeIds, &RIds = R->TypeIds; |
Duncan Sands | 7bf7a44 | 2007-05-21 18:50:28 +0000 | [diff] [blame] | 3408 | unsigned LSize = LIds.size(), RSize = RIds.size(); |
Duncan Sands | b32edb4 | 2007-06-06 15:37:31 +0000 | [diff] [blame] | 3409 | unsigned MinSize = LSize < RSize ? LSize : RSize; |
| 3410 | unsigned Count = 0; |
Duncan Sands | 7bf7a44 | 2007-05-21 18:50:28 +0000 | [diff] [blame] | 3411 | |
Duncan Sands | b32edb4 | 2007-06-06 15:37:31 +0000 | [diff] [blame] | 3412 | for (; Count != MinSize; ++Count) |
| 3413 | if (LIds[Count] != RIds[Count]) |
| 3414 | return Count; |
Duncan Sands | 7bf7a44 | 2007-05-21 18:50:28 +0000 | [diff] [blame] | 3415 | |
Duncan Sands | b32edb4 | 2007-06-06 15:37:31 +0000 | [diff] [blame] | 3416 | return Count; |
Duncan Sands | 7bf7a44 | 2007-05-21 18:50:28 +0000 | [diff] [blame] | 3417 | } |
| 3418 | |
Duncan Sands | b32edb4 | 2007-06-06 15:37:31 +0000 | [diff] [blame] | 3419 | /// PadLT - Order landing pads lexicographically by type id. |
Duncan Sands | 7bf7a44 | 2007-05-21 18:50:28 +0000 | [diff] [blame] | 3420 | static bool PadLT(const LandingPadInfo *L, const LandingPadInfo *R) { |
Duncan Sands | b32edb4 | 2007-06-06 15:37:31 +0000 | [diff] [blame] | 3421 | const std::vector<int> &LIds = L->TypeIds, &RIds = R->TypeIds; |
Duncan Sands | 7bf7a44 | 2007-05-21 18:50:28 +0000 | [diff] [blame] | 3422 | unsigned LSize = LIds.size(), RSize = RIds.size(); |
Duncan Sands | b32edb4 | 2007-06-06 15:37:31 +0000 | [diff] [blame] | 3423 | unsigned MinSize = LSize < RSize ? LSize : RSize; |
Duncan Sands | 7bf7a44 | 2007-05-21 18:50:28 +0000 | [diff] [blame] | 3424 | |
Duncan Sands | b32edb4 | 2007-06-06 15:37:31 +0000 | [diff] [blame] | 3425 | for (unsigned i = 0; i != MinSize; ++i) |
Duncan Sands | 7bf7a44 | 2007-05-21 18:50:28 +0000 | [diff] [blame] | 3426 | if (LIds[i] != RIds[i]) |
| 3427 | return LIds[i] < RIds[i]; |
| 3428 | |
Duncan Sands | b32edb4 | 2007-06-06 15:37:31 +0000 | [diff] [blame] | 3429 | return LSize < RSize; |
Duncan Sands | 7bf7a44 | 2007-05-21 18:50:28 +0000 | [diff] [blame] | 3430 | } |
| 3431 | |
Duncan Sands | 53c3a33 | 2007-05-16 12:12:23 +0000 | [diff] [blame] | 3432 | struct KeyInfo { |
| 3433 | static inline unsigned getEmptyKey() { return -1U; } |
| 3434 | static inline unsigned getTombstoneKey() { return -2U; } |
| 3435 | static unsigned getHashValue(const unsigned &Key) { return Key; } |
Chris Lattner | 76c1b97 | 2007-09-17 18:34:04 +0000 | [diff] [blame] | 3436 | static bool isEqual(unsigned LHS, unsigned RHS) { return LHS == RHS; } |
Duncan Sands | 53c3a33 | 2007-05-16 12:12:23 +0000 | [diff] [blame] | 3437 | static bool isPod() { return true; } |
| 3438 | }; |
| 3439 | |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3440 | /// ActionEntry - Structure describing an entry in the actions table. |
Duncan Sands | b32edb4 | 2007-06-06 15:37:31 +0000 | [diff] [blame] | 3441 | struct ActionEntry { |
Duncan Sands | fccf0a2 | 2007-07-06 12:46:24 +0000 | [diff] [blame] | 3442 | int ValueForTypeID; // The value to write - may not be equal to the type id. |
Duncan Sands | b32edb4 | 2007-06-06 15:37:31 +0000 | [diff] [blame] | 3443 | int NextAction; |
| 3444 | struct ActionEntry *Previous; |
| 3445 | }; |
| 3446 | |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3447 | /// PadRange - Structure holding a try-range and the associated landing pad. |
| 3448 | struct PadRange { |
| 3449 | // The index of the landing pad. |
| 3450 | unsigned PadIndex; |
| 3451 | // The index of the begin and end labels in the landing pad's label lists. |
| 3452 | unsigned RangeIndex; |
| 3453 | }; |
| 3454 | |
| 3455 | typedef DenseMap<unsigned, PadRange, KeyInfo> RangeMapType; |
| 3456 | |
| 3457 | /// CallSiteEntry - Structure describing an entry in the call-site table. |
| 3458 | struct CallSiteEntry { |
Duncan Sands | 481dc72 | 2007-12-19 07:36:31 +0000 | [diff] [blame] | 3459 | // The 'try-range' is BeginLabel .. EndLabel. |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3460 | unsigned BeginLabel; // zero indicates the start of the function. |
| 3461 | unsigned EndLabel; // zero indicates the end of the function. |
Duncan Sands | 481dc72 | 2007-12-19 07:36:31 +0000 | [diff] [blame] | 3462 | // The landing pad starts at PadLabel. |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3463 | unsigned PadLabel; // zero indicates that there is no landing pad. |
| 3464 | unsigned Action; |
| 3465 | }; |
| 3466 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3467 | void EmitExceptionTable() { |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3468 | const std::vector<GlobalVariable *> &TypeInfos = MMI->getTypeInfos(); |
Duncan Sands | 73ef58a | 2007-06-02 16:53:42 +0000 | [diff] [blame] | 3469 | const std::vector<unsigned> &FilterIds = MMI->getFilterIds(); |
Duncan Sands | 7bf7a44 | 2007-05-21 18:50:28 +0000 | [diff] [blame] | 3470 | const std::vector<LandingPadInfo> &PadInfos = MMI->getLandingPads(); |
| 3471 | if (PadInfos.empty()) return; |
| 3472 | |
| 3473 | // Sort the landing pads in order of their type ids. This is used to fold |
| 3474 | // duplicate actions. |
Duncan Sands | 6cc7608 | 2007-06-08 08:59:11 +0000 | [diff] [blame] | 3475 | SmallVector<const LandingPadInfo *, 64> LandingPads; |
Duncan Sands | 6cc7608 | 2007-06-08 08:59:11 +0000 | [diff] [blame] | 3476 | LandingPads.reserve(PadInfos.size()); |
Duncan Sands | 7bf7a44 | 2007-05-21 18:50:28 +0000 | [diff] [blame] | 3477 | for (unsigned i = 0, N = PadInfos.size(); i != N; ++i) |
Duncan Sands | 6cc7608 | 2007-06-08 08:59:11 +0000 | [diff] [blame] | 3478 | LandingPads.push_back(&PadInfos[i]); |
Duncan Sands | 7bf7a44 | 2007-05-21 18:50:28 +0000 | [diff] [blame] | 3479 | std::sort(LandingPads.begin(), LandingPads.end(), PadLT); |
| 3480 | |
Duncan Sands | fccf0a2 | 2007-07-06 12:46:24 +0000 | [diff] [blame] | 3481 | // Negative type ids index into FilterIds, positive type ids index into |
| 3482 | // TypeInfos. The value written for a positive type id is just the type |
| 3483 | // id itself. For a negative type id, however, the value written is the |
| 3484 | // (negative) byte offset of the corresponding FilterIds entry. The byte |
| 3485 | // offset is usually equal to the type id, because the FilterIds entries |
| 3486 | // are written using a variable width encoding which outputs one byte per |
| 3487 | // entry as long as the value written is not too large, but can differ. |
| 3488 | // This kind of complication does not occur for positive type ids because |
| 3489 | // type infos are output using a fixed width encoding. |
| 3490 | // FilterOffsets[i] holds the byte offset corresponding to FilterIds[i]. |
| 3491 | SmallVector<int, 16> FilterOffsets; |
| 3492 | FilterOffsets.reserve(FilterIds.size()); |
| 3493 | int Offset = -1; |
| 3494 | for(std::vector<unsigned>::const_iterator I = FilterIds.begin(), |
| 3495 | E = FilterIds.end(); I != E; ++I) { |
| 3496 | FilterOffsets.push_back(Offset); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3497 | Offset -= TargetAsmInfo::getULEB128Size(*I); |
Duncan Sands | fccf0a2 | 2007-07-06 12:46:24 +0000 | [diff] [blame] | 3498 | } |
| 3499 | |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3500 | // Compute the actions table and gather the first action index for each |
| 3501 | // landing pad site. |
| 3502 | SmallVector<ActionEntry, 32> Actions; |
| 3503 | SmallVector<unsigned, 64> FirstActions; |
| 3504 | FirstActions.reserve(LandingPads.size()); |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3505 | |
Duncan Sands | b32edb4 | 2007-06-06 15:37:31 +0000 | [diff] [blame] | 3506 | int FirstAction = 0; |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3507 | unsigned SizeActions = 0; |
Duncan Sands | 7bf7a44 | 2007-05-21 18:50:28 +0000 | [diff] [blame] | 3508 | for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) { |
Duncan Sands | b32edb4 | 2007-06-06 15:37:31 +0000 | [diff] [blame] | 3509 | const LandingPadInfo *LP = LandingPads[i]; |
| 3510 | const std::vector<int> &TypeIds = LP->TypeIds; |
| 3511 | const unsigned NumShared = i ? SharedTypeIds(LP, LandingPads[i-1]) : 0; |
Duncan Sands | 7bf7a44 | 2007-05-21 18:50:28 +0000 | [diff] [blame] | 3512 | unsigned SizeSiteActions = 0; |
| 3513 | |
Duncan Sands | b32edb4 | 2007-06-06 15:37:31 +0000 | [diff] [blame] | 3514 | if (NumShared < TypeIds.size()) { |
Duncan Sands | 7bf7a44 | 2007-05-21 18:50:28 +0000 | [diff] [blame] | 3515 | unsigned SizeAction = 0; |
Duncan Sands | b32edb4 | 2007-06-06 15:37:31 +0000 | [diff] [blame] | 3516 | ActionEntry *PrevAction = 0; |
Duncan Sands | 7bf7a44 | 2007-05-21 18:50:28 +0000 | [diff] [blame] | 3517 | |
Duncan Sands | b32edb4 | 2007-06-06 15:37:31 +0000 | [diff] [blame] | 3518 | if (NumShared) { |
| 3519 | const unsigned SizePrevIds = LandingPads[i-1]->TypeIds.size(); |
| 3520 | assert(Actions.size()); |
| 3521 | PrevAction = &Actions.back(); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3522 | SizeAction = TargetAsmInfo::getSLEB128Size(PrevAction->NextAction) + |
| 3523 | TargetAsmInfo::getSLEB128Size(PrevAction->ValueForTypeID); |
Duncan Sands | b32edb4 | 2007-06-06 15:37:31 +0000 | [diff] [blame] | 3524 | for (unsigned j = NumShared; j != SizePrevIds; ++j) { |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3525 | SizeAction -= |
| 3526 | TargetAsmInfo::getSLEB128Size(PrevAction->ValueForTypeID); |
Duncan Sands | b32edb4 | 2007-06-06 15:37:31 +0000 | [diff] [blame] | 3527 | SizeAction += -PrevAction->NextAction; |
| 3528 | PrevAction = PrevAction->Previous; |
Duncan Sands | 7bf7a44 | 2007-05-21 18:50:28 +0000 | [diff] [blame] | 3529 | } |
Anton Korobeynikov | eeb37e0 | 2007-05-10 22:34:59 +0000 | [diff] [blame] | 3530 | } |
Duncan Sands | 7bf7a44 | 2007-05-21 18:50:28 +0000 | [diff] [blame] | 3531 | |
Duncan Sands | b32edb4 | 2007-06-06 15:37:31 +0000 | [diff] [blame] | 3532 | // Compute the actions. |
| 3533 | for (unsigned I = NumShared, M = TypeIds.size(); I != M; ++I) { |
| 3534 | int TypeID = TypeIds[I]; |
Duncan Sands | fccf0a2 | 2007-07-06 12:46:24 +0000 | [diff] [blame] | 3535 | assert(-1-TypeID < (int)FilterOffsets.size() && "Unknown filter id!"); |
| 3536 | int ValueForTypeID = TypeID < 0 ? FilterOffsets[-1 - TypeID] : TypeID; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3537 | unsigned SizeTypeID = TargetAsmInfo::getSLEB128Size(ValueForTypeID); |
Duncan Sands | b32edb4 | 2007-06-06 15:37:31 +0000 | [diff] [blame] | 3538 | |
| 3539 | int NextAction = SizeAction ? -(SizeAction + SizeTypeID) : 0; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3540 | SizeAction = SizeTypeID + TargetAsmInfo::getSLEB128Size(NextAction); |
Duncan Sands | b32edb4 | 2007-06-06 15:37:31 +0000 | [diff] [blame] | 3541 | SizeSiteActions += SizeAction; |
| 3542 | |
Duncan Sands | fccf0a2 | 2007-07-06 12:46:24 +0000 | [diff] [blame] | 3543 | ActionEntry Action = {ValueForTypeID, NextAction, PrevAction}; |
Duncan Sands | b32edb4 | 2007-06-06 15:37:31 +0000 | [diff] [blame] | 3544 | Actions.push_back(Action); |
| 3545 | |
| 3546 | PrevAction = &Actions.back(); |
| 3547 | } |
| 3548 | |
| 3549 | // Record the first action of the landing pad site. |
| 3550 | FirstAction = SizeActions + SizeSiteActions - SizeAction + 1; |
| 3551 | } // else identical - re-use previous FirstAction |
| 3552 | |
| 3553 | FirstActions.push_back(FirstAction); |
Duncan Sands | 7bf7a44 | 2007-05-21 18:50:28 +0000 | [diff] [blame] | 3554 | |
Anton Korobeynikov | 29c9caf | 2007-05-11 08:23:57 +0000 | [diff] [blame] | 3555 | // Compute this sites contribution to size. |
Anton Korobeynikov | 22d5c37 | 2007-05-11 08:47:35 +0000 | [diff] [blame] | 3556 | SizeActions += SizeSiteActions; |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3557 | } |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3558 | |
Duncan Sands | 481dc72 | 2007-12-19 07:36:31 +0000 | [diff] [blame] | 3559 | // Compute the call-site table. The entry for an invoke has a try-range |
| 3560 | // containing the call, a non-zero landing pad and an appropriate action. |
| 3561 | // The entry for an ordinary call has a try-range containing the call and |
| 3562 | // zero for the landing pad and the action. Calls marked 'nounwind' have |
| 3563 | // no entry and must not be contained in the try-range of any entry - they |
| 3564 | // form gaps in the table. Entries must be ordered by try-range address. |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3565 | SmallVector<CallSiteEntry, 64> CallSites; |
| 3566 | |
| 3567 | RangeMapType PadMap; |
Duncan Sands | 481dc72 | 2007-12-19 07:36:31 +0000 | [diff] [blame] | 3568 | // Invokes and nounwind calls have entries in PadMap (due to being bracketed |
| 3569 | // by try-range labels when lowered). Ordinary calls do not, so appropriate |
| 3570 | // try-ranges for them need be deduced. |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3571 | for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) { |
| 3572 | const LandingPadInfo *LandingPad = LandingPads[i]; |
Duncan Sands | 481dc72 | 2007-12-19 07:36:31 +0000 | [diff] [blame] | 3573 | for (unsigned j = 0, E = LandingPad->BeginLabels.size(); j != E; ++j) { |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3574 | unsigned BeginLabel = LandingPad->BeginLabels[j]; |
| 3575 | assert(!PadMap.count(BeginLabel) && "Duplicate landing pad labels!"); |
| 3576 | PadRange P = { i, j }; |
| 3577 | PadMap[BeginLabel] = P; |
| 3578 | } |
| 3579 | } |
| 3580 | |
Duncan Sands | 481dc72 | 2007-12-19 07:36:31 +0000 | [diff] [blame] | 3581 | // The end label of the previous invoke or nounwind try-range. |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3582 | unsigned LastLabel = 0; |
Duncan Sands | 481dc72 | 2007-12-19 07:36:31 +0000 | [diff] [blame] | 3583 | |
| 3584 | // Whether there is a potentially throwing instruction (currently this means |
| 3585 | // an ordinary call) between the end of the previous try-range and now. |
| 3586 | bool SawPotentiallyThrowing = false; |
| 3587 | |
| 3588 | // Whether the last callsite entry was for an invoke. |
| 3589 | bool PreviousIsInvoke = false; |
| 3590 | |
Duncan Sands | 481dc72 | 2007-12-19 07:36:31 +0000 | [diff] [blame] | 3591 | // Visit all instructions in order of address. |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3592 | for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); |
| 3593 | I != E; ++I) { |
| 3594 | for (MachineBasicBlock::const_iterator MI = I->begin(), E = I->end(); |
| 3595 | MI != E; ++MI) { |
Dan Gohman | 4406604 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 3596 | if (!MI->isLabel()) { |
Chris Lattner | 749c6f6 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 3597 | SawPotentiallyThrowing |= MI->getDesc().isCall(); |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3598 | continue; |
| 3599 | } |
| 3600 | |
Chris Lattner | 9e33049 | 2007-12-30 20:50:28 +0000 | [diff] [blame] | 3601 | unsigned BeginLabel = MI->getOperand(0).getImm(); |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3602 | assert(BeginLabel && "Invalid label!"); |
Duncan Sands | 9886504 | 2007-09-05 14:12:46 +0000 | [diff] [blame] | 3603 | |
Duncan Sands | 481dc72 | 2007-12-19 07:36:31 +0000 | [diff] [blame] | 3604 | // End of the previous try-range? |
Duncan Sands | 9886504 | 2007-09-05 14:12:46 +0000 | [diff] [blame] | 3605 | if (BeginLabel == LastLabel) |
Duncan Sands | 481dc72 | 2007-12-19 07:36:31 +0000 | [diff] [blame] | 3606 | SawPotentiallyThrowing = false; |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3607 | |
Duncan Sands | 481dc72 | 2007-12-19 07:36:31 +0000 | [diff] [blame] | 3608 | // Beginning of a new try-range? |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3609 | RangeMapType::iterator L = PadMap.find(BeginLabel); |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3610 | if (L == PadMap.end()) |
Duncan Sands | 481dc72 | 2007-12-19 07:36:31 +0000 | [diff] [blame] | 3611 | // Nope, it was just some random label. |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3612 | continue; |
| 3613 | |
| 3614 | PadRange P = L->second; |
| 3615 | const LandingPadInfo *LandingPad = LandingPads[P.PadIndex]; |
| 3616 | |
| 3617 | assert(BeginLabel == LandingPad->BeginLabels[P.RangeIndex] && |
| 3618 | "Inconsistent landing pad map!"); |
| 3619 | |
| 3620 | // If some instruction between the previous try-range and this one may |
| 3621 | // throw, create a call-site entry with no landing pad for the region |
| 3622 | // between the try-ranges. |
Duncan Sands | 481dc72 | 2007-12-19 07:36:31 +0000 | [diff] [blame] | 3623 | if (SawPotentiallyThrowing) { |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3624 | CallSiteEntry Site = {LastLabel, BeginLabel, 0, 0}; |
| 3625 | CallSites.push_back(Site); |
Duncan Sands | 481dc72 | 2007-12-19 07:36:31 +0000 | [diff] [blame] | 3626 | PreviousIsInvoke = false; |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3627 | } |
| 3628 | |
| 3629 | LastLabel = LandingPad->EndLabels[P.RangeIndex]; |
Duncan Sands | 481dc72 | 2007-12-19 07:36:31 +0000 | [diff] [blame] | 3630 | assert(BeginLabel && LastLabel && "Invalid landing pad!"); |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3631 | |
Duncan Sands | 481dc72 | 2007-12-19 07:36:31 +0000 | [diff] [blame] | 3632 | if (LandingPad->LandingPadLabel) { |
| 3633 | // This try-range is for an invoke. |
| 3634 | CallSiteEntry Site = {BeginLabel, LastLabel, |
| 3635 | LandingPad->LandingPadLabel, FirstActions[P.PadIndex]}; |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3636 | |
Duncan Sands | 481dc72 | 2007-12-19 07:36:31 +0000 | [diff] [blame] | 3637 | // Try to merge with the previous call-site. |
| 3638 | if (PreviousIsInvoke) { |
Dan Gohman | 719de53 | 2008-06-21 22:00:54 +0000 | [diff] [blame] | 3639 | CallSiteEntry &Prev = CallSites.back(); |
Duncan Sands | 481dc72 | 2007-12-19 07:36:31 +0000 | [diff] [blame] | 3640 | if (Site.PadLabel == Prev.PadLabel && Site.Action == Prev.Action) { |
| 3641 | // Extend the range of the previous entry. |
| 3642 | Prev.EndLabel = Site.EndLabel; |
| 3643 | continue; |
| 3644 | } |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3645 | } |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3646 | |
Duncan Sands | 481dc72 | 2007-12-19 07:36:31 +0000 | [diff] [blame] | 3647 | // Otherwise, create a new call-site. |
| 3648 | CallSites.push_back(Site); |
| 3649 | PreviousIsInvoke = true; |
| 3650 | } else { |
| 3651 | // Create a gap. |
| 3652 | PreviousIsInvoke = false; |
| 3653 | } |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3654 | } |
| 3655 | } |
| 3656 | // If some instruction between the previous try-range and the end of the |
| 3657 | // function may throw, create a call-site entry with no landing pad for the |
| 3658 | // region following the try-range. |
Duncan Sands | 481dc72 | 2007-12-19 07:36:31 +0000 | [diff] [blame] | 3659 | if (SawPotentiallyThrowing) { |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3660 | CallSiteEntry Site = {LastLabel, 0, 0, 0}; |
| 3661 | CallSites.push_back(Site); |
| 3662 | } |
| 3663 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3664 | // Final tallies. |
Duncan Sands | 671fa97 | 2008-05-07 19:11:09 +0000 | [diff] [blame] | 3665 | |
| 3666 | // Call sites. |
| 3667 | const unsigned SiteStartSize = sizeof(int32_t); // DW_EH_PE_udata4 |
| 3668 | const unsigned SiteLengthSize = sizeof(int32_t); // DW_EH_PE_udata4 |
| 3669 | const unsigned LandingPadSize = sizeof(int32_t); // DW_EH_PE_udata4 |
| 3670 | unsigned SizeSites = CallSites.size() * (SiteStartSize + |
| 3671 | SiteLengthSize + |
| 3672 | LandingPadSize); |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3673 | for (unsigned i = 0, e = CallSites.size(); i < e; ++i) |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3674 | SizeSites += TargetAsmInfo::getULEB128Size(CallSites[i].Action); |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3675 | |
Duncan Sands | 671fa97 | 2008-05-07 19:11:09 +0000 | [diff] [blame] | 3676 | // Type infos. |
| 3677 | const unsigned TypeInfoSize = TD->getPointerSize(); // DW_EH_PE_absptr |
| 3678 | unsigned SizeTypes = TypeInfos.size() * TypeInfoSize; |
Anton Korobeynikov | 0ff3ca4 | 2007-05-12 22:36:25 +0000 | [diff] [blame] | 3679 | |
| 3680 | unsigned TypeOffset = sizeof(int8_t) + // Call site format |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3681 | TargetAsmInfo::getULEB128Size(SizeSites) + // Call-site table length |
Anton Korobeynikov | 0ff3ca4 | 2007-05-12 22:36:25 +0000 | [diff] [blame] | 3682 | SizeSites + SizeActions + SizeTypes; |
| 3683 | |
| 3684 | unsigned TotalSize = sizeof(int8_t) + // LPStart format |
| 3685 | sizeof(int8_t) + // TType format |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3686 | TargetAsmInfo::getULEB128Size(TypeOffset) + // TType base offset |
Anton Korobeynikov | 0ff3ca4 | 2007-05-12 22:36:25 +0000 | [diff] [blame] | 3687 | TypeOffset; |
| 3688 | |
| 3689 | unsigned SizeAlign = (4 - TotalSize) & 3; |
Duncan Sands | c1fe166 | 2007-05-10 18:40:24 +0000 | [diff] [blame] | 3690 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3691 | // Begin the exception table. |
| 3692 | Asm->SwitchToDataSection(TAI->getDwarfExceptionSection()); |
Evan Cheng | 05548eb | 2008-02-29 19:36:59 +0000 | [diff] [blame] | 3693 | Asm->EmitAlignment(2, 0, 0, false); |
Dale Johannesen | d65b264 | 2008-10-08 21:50:21 +0000 | [diff] [blame] | 3694 | O << "GCC_except_table" << SubprogramCount << ":\n"; |
Anton Korobeynikov | 0ff3ca4 | 2007-05-12 22:36:25 +0000 | [diff] [blame] | 3695 | for (unsigned i = 0; i != SizeAlign; ++i) { |
| 3696 | Asm->EmitInt8(0); |
| 3697 | Asm->EOL("Padding"); |
| 3698 | } |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3699 | EmitLabel("exception", SubprogramCount); |
Duncan Sands | c1fe166 | 2007-05-10 18:40:24 +0000 | [diff] [blame] | 3700 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3701 | // Emit the header. |
| 3702 | Asm->EmitInt8(DW_EH_PE_omit); |
| 3703 | Asm->EOL("LPStart format (DW_EH_PE_omit)"); |
| 3704 | Asm->EmitInt8(DW_EH_PE_absptr); |
| 3705 | Asm->EOL("TType format (DW_EH_PE_absptr)"); |
| 3706 | Asm->EmitULEB128Bytes(TypeOffset); |
| 3707 | Asm->EOL("TType base offset"); |
| 3708 | Asm->EmitInt8(DW_EH_PE_udata4); |
| 3709 | Asm->EOL("Call site format (DW_EH_PE_udata4)"); |
| 3710 | Asm->EmitULEB128Bytes(SizeSites); |
| 3711 | Asm->EOL("Call-site table length"); |
Duncan Sands | 53c3a33 | 2007-05-16 12:12:23 +0000 | [diff] [blame] | 3712 | |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3713 | // Emit the landing pad site information. |
| 3714 | for (unsigned i = 0; i < CallSites.size(); ++i) { |
| 3715 | CallSiteEntry &S = CallSites[i]; |
| 3716 | const char *BeginTag; |
| 3717 | unsigned BeginNumber; |
Duncan Sands | 53c3a33 | 2007-05-16 12:12:23 +0000 | [diff] [blame] | 3718 | |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3719 | if (!S.BeginLabel) { |
| 3720 | BeginTag = "eh_func_begin"; |
| 3721 | BeginNumber = SubprogramCount; |
| 3722 | } else { |
| 3723 | BeginTag = "label"; |
| 3724 | BeginNumber = S.BeginLabel; |
Duncan Sands | 53c3a33 | 2007-05-16 12:12:23 +0000 | [diff] [blame] | 3725 | } |
Duncan Sands | 53c3a33 | 2007-05-16 12:12:23 +0000 | [diff] [blame] | 3726 | |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3727 | EmitSectionOffset(BeginTag, "eh_func_begin", BeginNumber, SubprogramCount, |
Duncan Sands | 671fa97 | 2008-05-07 19:11:09 +0000 | [diff] [blame] | 3728 | true, true); |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3729 | Asm->EOL("Region start"); |
Duncan Sands | 53c3a33 | 2007-05-16 12:12:23 +0000 | [diff] [blame] | 3730 | |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3731 | if (!S.EndLabel) { |
Dale Johannesen | 4af3494 | 2008-01-15 23:24:56 +0000 | [diff] [blame] | 3732 | EmitDifference("eh_func_end", SubprogramCount, BeginTag, BeginNumber, |
Duncan Sands | 671fa97 | 2008-05-07 19:11:09 +0000 | [diff] [blame] | 3733 | true); |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3734 | } else { |
Duncan Sands | 671fa97 | 2008-05-07 19:11:09 +0000 | [diff] [blame] | 3735 | EmitDifference("label", S.EndLabel, BeginTag, BeginNumber, true); |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3736 | } |
| 3737 | Asm->EOL("Region length"); |
Duncan Sands | 53c3a33 | 2007-05-16 12:12:23 +0000 | [diff] [blame] | 3738 | |
Duncan Sands | 671fa97 | 2008-05-07 19:11:09 +0000 | [diff] [blame] | 3739 | if (!S.PadLabel) |
| 3740 | Asm->EmitInt32(0); |
| 3741 | else |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3742 | EmitSectionOffset("label", "eh_func_begin", S.PadLabel, SubprogramCount, |
Duncan Sands | 671fa97 | 2008-05-07 19:11:09 +0000 | [diff] [blame] | 3743 | true, true); |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3744 | Asm->EOL("Landing pad"); |
| 3745 | |
| 3746 | Asm->EmitULEB128Bytes(S.Action); |
| 3747 | Asm->EOL("Action"); |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3748 | } |
Duncan Sands | 53c3a33 | 2007-05-16 12:12:23 +0000 | [diff] [blame] | 3749 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3750 | // Emit the actions. |
Duncan Sands | b32edb4 | 2007-06-06 15:37:31 +0000 | [diff] [blame] | 3751 | for (unsigned I = 0, N = Actions.size(); I != N; ++I) { |
| 3752 | ActionEntry &Action = Actions[I]; |
Duncan Sands | 7bf7a44 | 2007-05-21 18:50:28 +0000 | [diff] [blame] | 3753 | |
Duncan Sands | fccf0a2 | 2007-07-06 12:46:24 +0000 | [diff] [blame] | 3754 | Asm->EmitSLEB128Bytes(Action.ValueForTypeID); |
Duncan Sands | b32edb4 | 2007-06-06 15:37:31 +0000 | [diff] [blame] | 3755 | Asm->EOL("TypeInfo index"); |
| 3756 | Asm->EmitSLEB128Bytes(Action.NextAction); |
| 3757 | Asm->EOL("Next action"); |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3758 | } |
| 3759 | |
| 3760 | // Emit the type ids. |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3761 | for (unsigned M = TypeInfos.size(); M; --M) { |
| 3762 | GlobalVariable *GV = TypeInfos[M - 1]; |
Anton Korobeynikov | 9cc54f5 | 2007-09-02 22:07:21 +0000 | [diff] [blame] | 3763 | |
| 3764 | PrintRelDirective(); |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3765 | |
| 3766 | if (GV) |
| 3767 | O << Asm->getGlobalLinkName(GV); |
| 3768 | else |
| 3769 | O << "0"; |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3770 | |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 3771 | Asm->EOL("TypeInfo"); |
| 3772 | } |
| 3773 | |
Duncan Sands | 73ef58a | 2007-06-02 16:53:42 +0000 | [diff] [blame] | 3774 | // Emit the filter typeids. |
| 3775 | for (unsigned j = 0, M = FilterIds.size(); j < M; ++j) { |
| 3776 | unsigned TypeID = FilterIds[j]; |
Duncan Sands | bb821dd | 2007-07-12 13:51:39 +0000 | [diff] [blame] | 3777 | Asm->EmitULEB128Bytes(TypeID); |
Duncan Sands | 73ef58a | 2007-06-02 16:53:42 +0000 | [diff] [blame] | 3778 | Asm->EOL("Filter TypeInfo index"); |
Jim Laskey | 0102ca8 | 2007-03-01 20:26:43 +0000 | [diff] [blame] | 3779 | } |
Duncan Sands | 57810cd | 2007-09-05 11:27:52 +0000 | [diff] [blame] | 3780 | |
Evan Cheng | 05548eb | 2008-02-29 19:36:59 +0000 | [diff] [blame] | 3781 | Asm->EmitAlignment(2, 0, 0, false); |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 3782 | } |
| 3783 | |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 3784 | public: |
| 3785 | //===--------------------------------------------------------------------===// |
| 3786 | // Main entry points. |
| 3787 | // |
Owen Anderson | cb37188 | 2008-08-21 00:14:44 +0000 | [diff] [blame] | 3788 | DwarfException(raw_ostream &OS, AsmPrinter *A, const TargetAsmInfo *T) |
Chris Lattner | 9251f13 | 2007-09-24 03:35:37 +0000 | [diff] [blame] | 3789 | : Dwarf(OS, A, T, "eh") |
Dale Johannesen | 1532f3d | 2008-04-02 00:25:04 +0000 | [diff] [blame] | 3790 | , shouldEmitTable(false) |
| 3791 | , shouldEmitMoves(false) |
| 3792 | , shouldEmitTableModule(false) |
| 3793 | , shouldEmitMovesModule(false) |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 3794 | {} |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3795 | |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 3796 | virtual ~DwarfException() {} |
| 3797 | |
| 3798 | /// SetModuleInfo - Set machine module information when it's known that pass |
| 3799 | /// manager has created it. Set by the target AsmPrinter. |
| 3800 | void SetModuleInfo(MachineModuleInfo *mmi) { |
Jim Laskey | 3f09fc2 | 2007-02-28 18:38:31 +0000 | [diff] [blame] | 3801 | MMI = mmi; |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 3802 | } |
| 3803 | |
| 3804 | /// BeginModule - Emit all exception information that should come prior to the |
| 3805 | /// content. |
| 3806 | void BeginModule(Module *M) { |
| 3807 | this->M = M; |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 3808 | } |
| 3809 | |
| 3810 | /// EndModule - Emit all exception information that should come after the |
| 3811 | /// content. |
| 3812 | void EndModule() { |
Dale Johannesen | 1532f3d | 2008-04-02 00:25:04 +0000 | [diff] [blame] | 3813 | if (shouldEmitMovesModule || shouldEmitTableModule) { |
| 3814 | const std::vector<Function *> Personalities = MMI->getPersonalities(); |
| 3815 | for (unsigned i =0; i < Personalities.size(); ++i) |
| 3816 | EmitCommonEHFrame(Personalities[i], i); |
Anton Korobeynikov | 8c7c173 | 2007-05-13 15:42:26 +0000 | [diff] [blame] | 3817 | |
Dale Johannesen | 1532f3d | 2008-04-02 00:25:04 +0000 | [diff] [blame] | 3818 | for (std::vector<FunctionEHFrameInfo>::iterator I = EHFrames.begin(), |
| 3819 | E = EHFrames.end(); I != E; ++I) |
| 3820 | EmitEHFrame(*I); |
| 3821 | } |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 3822 | } |
| 3823 | |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3824 | /// BeginFunction - Gather pre-function exception information. Assumes being |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 3825 | /// emitted immediately after the function entry point. |
| 3826 | void BeginFunction(MachineFunction *MF) { |
| 3827 | this->MF = MF; |
Dale Johannesen | 1532f3d | 2008-04-02 00:25:04 +0000 | [diff] [blame] | 3828 | shouldEmitTable = shouldEmitMoves = false; |
Dale Johannesen | e004062 | 2008-04-02 17:04:45 +0000 | [diff] [blame] | 3829 | if (MMI && TAI->doesSupportExceptionHandling()) { |
Dale Johannesen | 1532f3d | 2008-04-02 00:25:04 +0000 | [diff] [blame] | 3830 | |
| 3831 | // Map all labels and get rid of any dead landing pads. |
| 3832 | MMI->TidyLandingPads(); |
| 3833 | // If any landing pads survive, we need an EH table. |
| 3834 | if (MMI->getLandingPads().size()) |
| 3835 | shouldEmitTable = true; |
| 3836 | |
| 3837 | // See if we need frame move info. |
Duncan Sands | ececf99 | 2008-07-04 09:55:48 +0000 | [diff] [blame] | 3838 | if (!MF->getFunction()->doesNotThrow() || UnwindTablesMandatory) |
Dale Johannesen | 1532f3d | 2008-04-02 00:25:04 +0000 | [diff] [blame] | 3839 | shouldEmitMoves = true; |
| 3840 | |
| 3841 | if (shouldEmitMoves || shouldEmitTable) |
| 3842 | // Assumes in correct section after the entry point. |
| 3843 | EmitLabel("eh_func_begin", ++SubprogramCount); |
Jim Laskey | 3f09fc2 | 2007-02-28 18:38:31 +0000 | [diff] [blame] | 3844 | } |
Dale Johannesen | 1532f3d | 2008-04-02 00:25:04 +0000 | [diff] [blame] | 3845 | shouldEmitTableModule |= shouldEmitTable; |
| 3846 | shouldEmitMovesModule |= shouldEmitMoves; |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 3847 | } |
| 3848 | |
| 3849 | /// EndFunction - Gather and emit post-function exception information. |
| 3850 | /// |
| 3851 | void EndFunction() { |
Dale Johannesen | 1532f3d | 2008-04-02 00:25:04 +0000 | [diff] [blame] | 3852 | if (shouldEmitMoves || shouldEmitTable) { |
| 3853 | EmitLabel("eh_func_end", SubprogramCount); |
| 3854 | EmitExceptionTable(); |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 3855 | |
Dale Johannesen | 1532f3d | 2008-04-02 00:25:04 +0000 | [diff] [blame] | 3856 | // Save EH frame information |
| 3857 | EHFrames. |
| 3858 | push_back(FunctionEHFrameInfo(getAsm()->getCurrentFunctionEHName(MF), |
Bill Wendling | 6e19896 | 2007-09-18 01:47:22 +0000 | [diff] [blame] | 3859 | SubprogramCount, |
| 3860 | MMI->getPersonalityIndex(), |
| 3861 | MF->getFrameInfo()->hasCalls(), |
| 3862 | !MMI->getLandingPads().empty(), |
Dale Johannesen | 1d4ce2a | 2007-11-20 23:24:42 +0000 | [diff] [blame] | 3863 | MMI->getFrameMoves(), |
Dale Johannesen | 48ae02f | 2008-01-16 19:59:28 +0000 | [diff] [blame] | 3864 | MF->getFunction())); |
Dale Johannesen | 1532f3d | 2008-04-02 00:25:04 +0000 | [diff] [blame] | 3865 | } |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 3866 | } |
| 3867 | }; |
| 3868 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 3869 | } // End of namespace llvm |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 3870 | |
| 3871 | //===----------------------------------------------------------------------===// |
| 3872 | |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 3873 | /// Emit - Print the abbreviation using the specified Dwarf writer. |
| 3874 | /// |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 3875 | void DIEAbbrev::Emit(const DwarfDebug &DD) const { |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 3876 | // Emit its Dwarf tag type. |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 3877 | DD.getAsm()->EmitULEB128Bytes(Tag); |
| 3878 | DD.getAsm()->EOL(TagString(Tag)); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3879 | |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 3880 | // Emit whether it has children DIEs. |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 3881 | DD.getAsm()->EmitULEB128Bytes(ChildrenFlag); |
| 3882 | DD.getAsm()->EOL(ChildrenString(ChildrenFlag)); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3883 | |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 3884 | // For each attribute description. |
Jim Laskey | 52060a0 | 2006-01-24 00:49:18 +0000 | [diff] [blame] | 3885 | for (unsigned i = 0, N = Data.size(); i < N; ++i) { |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 3886 | const DIEAbbrevData &AttrData = Data[i]; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3887 | |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 3888 | // Emit attribute type. |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 3889 | DD.getAsm()->EmitULEB128Bytes(AttrData.getAttribute()); |
| 3890 | DD.getAsm()->EOL(AttributeString(AttrData.getAttribute())); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3891 | |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 3892 | // Emit form type. |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 3893 | DD.getAsm()->EmitULEB128Bytes(AttrData.getForm()); |
| 3894 | DD.getAsm()->EOL(FormEncodingString(AttrData.getForm())); |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 3895 | } |
| 3896 | |
| 3897 | // Mark end of abbreviation. |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 3898 | DD.getAsm()->EmitULEB128Bytes(0); DD.getAsm()->EOL("EOM(1)"); |
| 3899 | DD.getAsm()->EmitULEB128Bytes(0); DD.getAsm()->EOL("EOM(2)"); |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 3900 | } |
| 3901 | |
| 3902 | #ifndef NDEBUG |
Jim Laskey | a0f3d17 | 2006-09-07 22:06:40 +0000 | [diff] [blame] | 3903 | void DIEAbbrev::print(std::ostream &O) { |
| 3904 | O << "Abbreviation @" |
| 3905 | << std::hex << (intptr_t)this << std::dec |
| 3906 | << " " |
| 3907 | << TagString(Tag) |
| 3908 | << " " |
| 3909 | << ChildrenString(ChildrenFlag) |
| 3910 | << "\n"; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3911 | |
Jim Laskey | a0f3d17 | 2006-09-07 22:06:40 +0000 | [diff] [blame] | 3912 | for (unsigned i = 0, N = Data.size(); i < N; ++i) { |
| 3913 | O << " " |
| 3914 | << AttributeString(Data[i].getAttribute()) |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 3915 | << " " |
Jim Laskey | a0f3d17 | 2006-09-07 22:06:40 +0000 | [diff] [blame] | 3916 | << FormEncodingString(Data[i].getForm()) |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 3917 | << "\n"; |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 3918 | } |
Jim Laskey | a0f3d17 | 2006-09-07 22:06:40 +0000 | [diff] [blame] | 3919 | } |
Bill Wendling | e815619 | 2006-12-07 01:30:32 +0000 | [diff] [blame] | 3920 | void DIEAbbrev::dump() { print(cerr); } |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 3921 | #endif |
| 3922 | |
| 3923 | //===----------------------------------------------------------------------===// |
| 3924 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 3925 | #ifndef NDEBUG |
| 3926 | void DIEValue::dump() { |
Bill Wendling | e815619 | 2006-12-07 01:30:32 +0000 | [diff] [blame] | 3927 | print(cerr); |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 3928 | } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 3929 | #endif |
| 3930 | |
| 3931 | //===----------------------------------------------------------------------===// |
| 3932 | |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 3933 | /// EmitValue - Emit integer of appropriate size. |
| 3934 | /// |
Anton Korobeynikov | 6a14359 | 2007-03-07 08:25:02 +0000 | [diff] [blame] | 3935 | void DIEInteger::EmitValue(DwarfDebug &DD, unsigned Form) { |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 3936 | switch (Form) { |
Jim Laskey | 4002017 | 2006-01-20 21:02:36 +0000 | [diff] [blame] | 3937 | case DW_FORM_flag: // Fall thru |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 3938 | case DW_FORM_ref1: // Fall thru |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 3939 | case DW_FORM_data1: DD.getAsm()->EmitInt8(Integer); break; |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 3940 | case DW_FORM_ref2: // Fall thru |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 3941 | case DW_FORM_data2: DD.getAsm()->EmitInt16(Integer); break; |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 3942 | case DW_FORM_ref4: // Fall thru |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 3943 | case DW_FORM_data4: DD.getAsm()->EmitInt32(Integer); break; |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 3944 | case DW_FORM_ref8: // Fall thru |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 3945 | case DW_FORM_data8: DD.getAsm()->EmitInt64(Integer); break; |
| 3946 | case DW_FORM_udata: DD.getAsm()->EmitULEB128Bytes(Integer); break; |
| 3947 | case DW_FORM_sdata: DD.getAsm()->EmitSLEB128Bytes(Integer); break; |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 3948 | default: assert(0 && "DIE Value form not supported yet"); break; |
| 3949 | } |
| 3950 | } |
| 3951 | |
| 3952 | /// SizeOf - Determine size of integer value in bytes. |
| 3953 | /// |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 3954 | unsigned DIEInteger::SizeOf(const DwarfDebug &DD, unsigned Form) const { |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 3955 | switch (Form) { |
| 3956 | case DW_FORM_flag: // Fall thru |
| 3957 | case DW_FORM_ref1: // Fall thru |
| 3958 | case DW_FORM_data1: return sizeof(int8_t); |
| 3959 | case DW_FORM_ref2: // Fall thru |
| 3960 | case DW_FORM_data2: return sizeof(int16_t); |
| 3961 | case DW_FORM_ref4: // Fall thru |
| 3962 | case DW_FORM_data4: return sizeof(int32_t); |
| 3963 | case DW_FORM_ref8: // Fall thru |
| 3964 | case DW_FORM_data8: return sizeof(int64_t); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 3965 | case DW_FORM_udata: return TargetAsmInfo::getULEB128Size(Integer); |
| 3966 | case DW_FORM_sdata: return TargetAsmInfo::getSLEB128Size(Integer); |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 3967 | default: assert(0 && "DIE Value form not supported yet"); break; |
| 3968 | } |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 3969 | return 0; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 3970 | } |
| 3971 | |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 3972 | //===----------------------------------------------------------------------===// |
| 3973 | |
| 3974 | /// EmitValue - Emit string value. |
| 3975 | /// |
Anton Korobeynikov | 6a14359 | 2007-03-07 08:25:02 +0000 | [diff] [blame] | 3976 | void DIEString::EmitValue(DwarfDebug &DD, unsigned Form) { |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 3977 | DD.getAsm()->EmitString(String); |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 3978 | } |
| 3979 | |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 3980 | //===----------------------------------------------------------------------===// |
| 3981 | |
| 3982 | /// EmitValue - Emit label value. |
| 3983 | /// |
Anton Korobeynikov | 6a14359 | 2007-03-07 08:25:02 +0000 | [diff] [blame] | 3984 | void DIEDwarfLabel::EmitValue(DwarfDebug &DD, unsigned Form) { |
Dan Gohman | 9fda5be | 2007-09-28 16:50:28 +0000 | [diff] [blame] | 3985 | bool IsSmall = Form == DW_FORM_data4; |
| 3986 | DD.EmitReference(Label, false, IsSmall); |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 3987 | } |
| 3988 | |
| 3989 | /// SizeOf - Determine size of label value in bytes. |
| 3990 | /// |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 3991 | unsigned DIEDwarfLabel::SizeOf(const DwarfDebug &DD, unsigned Form) const { |
Dan Gohman | 9fda5be | 2007-09-28 16:50:28 +0000 | [diff] [blame] | 3992 | if (Form == DW_FORM_data4) return 4; |
Dan Gohman | 8248294 | 2007-09-27 23:12:31 +0000 | [diff] [blame] | 3993 | return DD.getTargetData()->getPointerSize(); |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 3994 | } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 3995 | |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 3996 | //===----------------------------------------------------------------------===// |
| 3997 | |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 3998 | /// EmitValue - Emit label value. |
| 3999 | /// |
Anton Korobeynikov | 6a14359 | 2007-03-07 08:25:02 +0000 | [diff] [blame] | 4000 | void DIEObjectLabel::EmitValue(DwarfDebug &DD, unsigned Form) { |
Dan Gohman | 9fda5be | 2007-09-28 16:50:28 +0000 | [diff] [blame] | 4001 | bool IsSmall = Form == DW_FORM_data4; |
| 4002 | DD.EmitReference(Label, false, IsSmall); |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 4003 | } |
| 4004 | |
| 4005 | /// SizeOf - Determine size of label value in bytes. |
| 4006 | /// |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 4007 | unsigned DIEObjectLabel::SizeOf(const DwarfDebug &DD, unsigned Form) const { |
Dan Gohman | 9fda5be | 2007-09-28 16:50:28 +0000 | [diff] [blame] | 4008 | if (Form == DW_FORM_data4) return 4; |
Dan Gohman | 8248294 | 2007-09-27 23:12:31 +0000 | [diff] [blame] | 4009 | return DD.getTargetData()->getPointerSize(); |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 4010 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 4011 | |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 4012 | //===----------------------------------------------------------------------===// |
| 4013 | |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 4014 | /// EmitValue - Emit delta value. |
| 4015 | /// |
Argyrios Kyrtzidis | f7acf8f | 2008-06-18 19:27:37 +0000 | [diff] [blame] | 4016 | void DIESectionOffset::EmitValue(DwarfDebug &DD, unsigned Form) { |
| 4017 | bool IsSmall = Form == DW_FORM_data4; |
| 4018 | DD.EmitSectionOffset(Label.Tag, Section.Tag, |
| 4019 | Label.Number, Section.Number, IsSmall, IsEH, UseSet); |
| 4020 | } |
| 4021 | |
| 4022 | /// SizeOf - Determine size of delta value in bytes. |
| 4023 | /// |
| 4024 | unsigned DIESectionOffset::SizeOf(const DwarfDebug &DD, unsigned Form) const { |
| 4025 | if (Form == DW_FORM_data4) return 4; |
| 4026 | return DD.getTargetData()->getPointerSize(); |
| 4027 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 4028 | |
Argyrios Kyrtzidis | f7acf8f | 2008-06-18 19:27:37 +0000 | [diff] [blame] | 4029 | //===----------------------------------------------------------------------===// |
| 4030 | |
| 4031 | /// EmitValue - Emit delta value. |
| 4032 | /// |
Anton Korobeynikov | 6a14359 | 2007-03-07 08:25:02 +0000 | [diff] [blame] | 4033 | void DIEDelta::EmitValue(DwarfDebug &DD, unsigned Form) { |
Jim Laskey | 2b4e98c | 2006-12-06 17:43:18 +0000 | [diff] [blame] | 4034 | bool IsSmall = Form == DW_FORM_data4; |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 4035 | DD.EmitDifference(LabelHi, LabelLo, IsSmall); |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 4036 | } |
| 4037 | |
| 4038 | /// SizeOf - Determine size of delta value in bytes. |
| 4039 | /// |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 4040 | unsigned DIEDelta::SizeOf(const DwarfDebug &DD, unsigned Form) const { |
Jim Laskey | 2b4e98c | 2006-12-06 17:43:18 +0000 | [diff] [blame] | 4041 | if (Form == DW_FORM_data4) return 4; |
Dan Gohman | 8248294 | 2007-09-27 23:12:31 +0000 | [diff] [blame] | 4042 | return DD.getTargetData()->getPointerSize(); |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 4043 | } |
| 4044 | |
| 4045 | //===----------------------------------------------------------------------===// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 4046 | |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 4047 | /// EmitValue - Emit debug information entry offset. |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 4048 | /// |
Anton Korobeynikov | 6a14359 | 2007-03-07 08:25:02 +0000 | [diff] [blame] | 4049 | void DIEntry::EmitValue(DwarfDebug &DD, unsigned Form) { |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 4050 | DD.getAsm()->EmitInt32(Entry->getOffset()); |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 4051 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 4052 | |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 4053 | //===----------------------------------------------------------------------===// |
| 4054 | |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 4055 | /// ComputeSize - calculate the size of the block. |
| 4056 | /// |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 4057 | unsigned DIEBlock::ComputeSize(DwarfDebug &DD) { |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 4058 | if (!Size) { |
Owen Anderson | 873e1b5 | 2008-06-24 21:44:59 +0000 | [diff] [blame] | 4059 | const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev.getData(); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 4060 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 4061 | for (unsigned i = 0, N = Values.size(); i < N; ++i) { |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 4062 | Size += Values[i]->SizeOf(DD, AbbrevData[i].getForm()); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 4063 | } |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 4064 | } |
| 4065 | return Size; |
| 4066 | } |
| 4067 | |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 4068 | /// EmitValue - Emit block data. |
| 4069 | /// |
Anton Korobeynikov | 6a14359 | 2007-03-07 08:25:02 +0000 | [diff] [blame] | 4070 | void DIEBlock::EmitValue(DwarfDebug &DD, unsigned Form) { |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 4071 | switch (Form) { |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 4072 | case DW_FORM_block1: DD.getAsm()->EmitInt8(Size); break; |
| 4073 | case DW_FORM_block2: DD.getAsm()->EmitInt16(Size); break; |
| 4074 | case DW_FORM_block4: DD.getAsm()->EmitInt32(Size); break; |
| 4075 | case DW_FORM_block: DD.getAsm()->EmitULEB128Bytes(Size); break; |
Jim Laskey | f1cdea1 | 2007-01-25 15:12:02 +0000 | [diff] [blame] | 4076 | default: assert(0 && "Improper form for block"); break; |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 4077 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 4078 | |
Owen Anderson | 873e1b5 | 2008-06-24 21:44:59 +0000 | [diff] [blame] | 4079 | const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev.getData(); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 4080 | |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 4081 | for (unsigned i = 0, N = Values.size(); i < N; ++i) { |
Jim Laskey | bacd304 | 2007-02-21 22:48:45 +0000 | [diff] [blame] | 4082 | DD.getAsm()->EOL(); |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 4083 | Values[i]->EmitValue(DD, AbbrevData[i].getForm()); |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 4084 | } |
| 4085 | } |
| 4086 | |
| 4087 | /// SizeOf - Determine size of block data in bytes. |
| 4088 | /// |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 4089 | unsigned DIEBlock::SizeOf(const DwarfDebug &DD, unsigned Form) const { |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 4090 | switch (Form) { |
| 4091 | case DW_FORM_block1: return Size + sizeof(int8_t); |
| 4092 | case DW_FORM_block2: return Size + sizeof(int16_t); |
| 4093 | case DW_FORM_block4: return Size + sizeof(int32_t); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 4094 | case DW_FORM_block: return Size + TargetAsmInfo::getULEB128Size(Size); |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 4095 | default: assert(0 && "Improper form for block"); break; |
| 4096 | } |
| 4097 | return 0; |
| 4098 | } |
| 4099 | |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 4100 | //===----------------------------------------------------------------------===// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 4101 | /// DIE Implementation |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 4102 | |
| 4103 | DIE::~DIE() { |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 4104 | for (unsigned i = 0, N = Children.size(); i < N; ++i) |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 4105 | delete Children[i]; |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 4106 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 4107 | |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 4108 | /// AddSiblingOffset - Add a sibling offset field to the front of the DIE. |
| 4109 | /// |
| 4110 | void DIE::AddSiblingOffset() { |
| 4111 | DIEInteger *DI = new DIEInteger(0); |
| 4112 | Values.insert(Values.begin(), DI); |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 4113 | Abbrev.AddFirstAttribute(DW_AT_sibling, DW_FORM_ref4); |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 4114 | } |
| 4115 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 4116 | /// Profile - Used to gather unique data for the value folding set. |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 4117 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 4118 | void DIE::Profile(FoldingSetNodeID &ID) { |
| 4119 | Abbrev.Profile(ID); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 4120 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 4121 | for (unsigned i = 0, N = Children.size(); i < N; ++i) |
| 4122 | ID.AddPointer(Children[i]); |
| 4123 | |
| 4124 | for (unsigned j = 0, M = Values.size(); j < M; ++j) |
| 4125 | ID.AddPointer(Values[j]); |
Jim Laskey | d8f77ba | 2006-01-27 15:20:54 +0000 | [diff] [blame] | 4126 | } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 4127 | |
| 4128 | #ifndef NDEBUG |
| 4129 | void DIE::print(std::ostream &O, unsigned IncIndent) { |
| 4130 | static unsigned IndentCount = 0; |
| 4131 | IndentCount += IncIndent; |
| 4132 | const std::string Indent(IndentCount, ' '); |
| 4133 | bool isBlock = Abbrev.getTag() == 0; |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 4134 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 4135 | if (!isBlock) { |
| 4136 | O << Indent |
| 4137 | << "Die: " |
| 4138 | << "0x" << std::hex << (intptr_t)this << std::dec |
| 4139 | << ", Offset: " << Offset |
| 4140 | << ", Size: " << Size |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 4141 | << "\n"; |
| 4142 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 4143 | O << Indent |
| 4144 | << TagString(Abbrev.getTag()) |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 4145 | << " " |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 4146 | << ChildrenString(Abbrev.getChildrenFlag()); |
| 4147 | } else { |
| 4148 | O << "Size: " << Size; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 4149 | } |
| 4150 | O << "\n"; |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 4151 | |
Owen Anderson | 873e1b5 | 2008-06-24 21:44:59 +0000 | [diff] [blame] | 4152 | const SmallVector<DIEAbbrevData, 8> &Data = Abbrev.getData(); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 4153 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 4154 | IndentCount += 2; |
| 4155 | for (unsigned i = 0, N = Data.size(); i < N; ++i) { |
| 4156 | O << Indent; |
Bill Wendling | 4e97401 | 2008-07-22 00:28:47 +0000 | [diff] [blame] | 4157 | |
| 4158 | if (!isBlock) |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 4159 | O << AttributeString(Data[i].getAttribute()); |
Bill Wendling | 4e97401 | 2008-07-22 00:28:47 +0000 | [diff] [blame] | 4160 | else |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 4161 | O << "Blk[" << i << "]"; |
Bill Wendling | 4e97401 | 2008-07-22 00:28:47 +0000 | [diff] [blame] | 4162 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 4163 | O << " " |
| 4164 | << FormEncodingString(Data[i].getForm()) |
| 4165 | << " "; |
| 4166 | Values[i]->print(O); |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 4167 | O << "\n"; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 4168 | } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 4169 | IndentCount -= 2; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 4170 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 4171 | for (unsigned j = 0, M = Children.size(); j < M; ++j) { |
| 4172 | Children[j]->print(O, 4); |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 4173 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 4174 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 4175 | if (!isBlock) O << "\n"; |
| 4176 | IndentCount -= IncIndent; |
Jim Laskey | 19ef4ef | 2006-01-17 20:41:40 +0000 | [diff] [blame] | 4177 | } |
| 4178 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 4179 | void DIE::dump() { |
Bill Wendling | e815619 | 2006-12-07 01:30:32 +0000 | [diff] [blame] | 4180 | print(cerr); |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 4181 | } |
Jim Laskey | bd76184 | 2006-02-27 17:27:12 +0000 | [diff] [blame] | 4182 | #endif |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 4183 | |
| 4184 | //===----------------------------------------------------------------------===// |
| 4185 | /// DwarfWriter Implementation |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 4186 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 4187 | |
Devang Patel | eb3fc28 | 2009-01-08 23:40:34 +0000 | [diff] [blame] | 4188 | DwarfWriter::DwarfWriter() : ImmutablePass(&ID), DD(NULL), DE(NULL) { |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 4189 | } |
| 4190 | |
| 4191 | DwarfWriter::~DwarfWriter() { |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 4192 | delete DE; |
| 4193 | delete DD; |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 4194 | } |
| 4195 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 4196 | /// BeginModule - Emit all Dwarf sections that should come prior to the |
| 4197 | /// content. |
Devang Patel | eb3fc28 | 2009-01-08 23:40:34 +0000 | [diff] [blame] | 4198 | void DwarfWriter::BeginModule(Module *M, |
| 4199 | MachineModuleInfo *MMI, |
| 4200 | raw_ostream &OS, AsmPrinter *A, |
| 4201 | const TargetAsmInfo *T) { |
| 4202 | DE = new DwarfException(OS, A, T); |
| 4203 | DD = new DwarfDebug(OS, A, T); |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 4204 | DE->BeginModule(M); |
| 4205 | DD->BeginModule(M); |
Devang Patel | 7bb89ed | 2009-01-13 00:20:51 +0000 | [diff] [blame] | 4206 | DD->SetDebugInfo(MMI); |
Devang Patel | eb3fc28 | 2009-01-08 23:40:34 +0000 | [diff] [blame] | 4207 | DE->SetModuleInfo(MMI); |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 4208 | } |
| 4209 | |
| 4210 | /// EndModule - Emit all Dwarf sections that should come after the content. |
| 4211 | /// |
| 4212 | void DwarfWriter::EndModule() { |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 4213 | DE->EndModule(); |
| 4214 | DD->EndModule(); |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 4215 | } |
| 4216 | |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 4217 | /// BeginFunction - Gather pre-function debug information. Assumes being |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 4218 | /// emitted immediately after the function entry point. |
| 4219 | void DwarfWriter::BeginFunction(MachineFunction *MF) { |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 4220 | DE->BeginFunction(MF); |
| 4221 | DD->BeginFunction(MF); |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 4222 | } |
| 4223 | |
| 4224 | /// EndFunction - Gather and emit post-function debug information. |
| 4225 | /// |
Bill Wendling | d751c64 | 2008-09-26 00:28:12 +0000 | [diff] [blame] | 4226 | void DwarfWriter::EndFunction(MachineFunction *MF) { |
| 4227 | DD->EndFunction(MF); |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 4228 | DE->EndFunction(); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 4229 | |
Bill Wendling | c91d0b9 | 2008-07-22 00:53:37 +0000 | [diff] [blame] | 4230 | if (MachineModuleInfo *MMI = DD->getMMI() ? DD->getMMI() : DE->getMMI()) |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 4231 | // Clear function debug information. |
| 4232 | MMI->EndFunction(); |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 4233 | } |
Devang Patel | ccca7fe | 2009-01-12 19:17:34 +0000 | [diff] [blame] | 4234 | |
Devang Patel | cf3a448 | 2009-01-15 23:41:32 +0000 | [diff] [blame] | 4235 | /// ValidDebugInfo - Return true if V represents valid debug info value. |
| 4236 | bool DwarfWriter::ValidDebugInfo(Value *V) { |
Devang Patel | 5be9355 | 2009-01-16 02:15:14 +0000 | [diff] [blame] | 4237 | return DD && DD->ValidDebugInfo(V); |
Devang Patel | cf3a448 | 2009-01-15 23:41:32 +0000 | [diff] [blame] | 4238 | } |
| 4239 | |
Devang Patel | ccca7fe | 2009-01-12 19:17:34 +0000 | [diff] [blame] | 4240 | /// RecordSourceLine - Records location information and associates it with a |
| 4241 | /// label. Returns a unique label ID used to generate a label and provide |
| 4242 | /// correspondence to the source line list. |
| 4243 | unsigned DwarfWriter::RecordSourceLine(unsigned Line, unsigned Col, |
| 4244 | unsigned Src) { |
| 4245 | return DD->RecordSourceLine(Line, Col, Src); |
| 4246 | } |
| 4247 | |
| 4248 | /// RecordSource - Register a source file with debug info. Returns an source |
| 4249 | /// ID. |
| 4250 | unsigned DwarfWriter::RecordSource(const std::string &Dir, |
| 4251 | const std::string &File) { |
| 4252 | return DD->RecordSource(Dir, File); |
| 4253 | } |
| 4254 | |
| 4255 | /// RecordRegionStart - Indicate the start of a region. |
| 4256 | unsigned DwarfWriter::RecordRegionStart(GlobalVariable *V) { |
| 4257 | return DD->RecordRegionStart(V); |
| 4258 | } |
| 4259 | |
| 4260 | /// RecordRegionEnd - Indicate the end of a region. |
| 4261 | unsigned DwarfWriter::RecordRegionEnd(GlobalVariable *V) { |
| 4262 | return DD->RecordRegionEnd(V); |
| 4263 | } |
| 4264 | |
| 4265 | /// getRecordSourceLineCount - Count source lines. |
| 4266 | unsigned DwarfWriter::getRecordSourceLineCount() { |
| 4267 | return DD->getRecordSourceLineCount(); |
| 4268 | } |
Devang Patel | bb8c595 | 2009-01-13 21:25:00 +0000 | [diff] [blame] | 4269 | |
Devang Patel | c48c550 | 2009-01-13 21:44:10 +0000 | [diff] [blame] | 4270 | /// RecordVariable - Indicate the declaration of a local variable. |
| 4271 | /// |
| 4272 | void DwarfWriter::RecordVariable(GlobalVariable *GV, unsigned FrameIndex) { |
| 4273 | DD->RecordVariable(GV, FrameIndex); |
| 4274 | } |
Devang Patel | bbdc820 | 2009-01-13 23:54:55 +0000 | [diff] [blame] | 4275 | |