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 | // |
| 5 | // This file was developed by James M. Laskey and is distributed under the |
| 6 | // University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains support for writing dwarf debug info into asm files. |
| 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 | |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/FoldingSet.h" |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/StringExtras.h" |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/UniqueVector.h" |
Jim Laskey | 52060a0 | 2006-01-24 00:49:18 +0000 | [diff] [blame] | 19 | #include "llvm/Module.h" |
| 20 | #include "llvm/Type.h" |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/AsmPrinter.h" |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/MachineDebugInfo.h" |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/MachineLocation.h" |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 25 | #include "llvm/Support/Dwarf.h" |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 26 | #include "llvm/Support/CommandLine.h" |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 27 | #include "llvm/Support/DataTypes.h" |
Jim Laskey | 52060a0 | 2006-01-24 00:49:18 +0000 | [diff] [blame] | 28 | #include "llvm/Support/Mangler.h" |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 29 | #include "llvm/Target/TargetAsmInfo.h" |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 30 | #include "llvm/Target/MRegisterInfo.h" |
Owen Anderson | 07000c6 | 2006-05-12 06:33:49 +0000 | [diff] [blame] | 31 | #include "llvm/Target/TargetData.h" |
Jim Laskey | 52060a0 | 2006-01-24 00:49:18 +0000 | [diff] [blame] | 32 | #include "llvm/Target/TargetMachine.h" |
Jim Laskey | 1069fbd | 2006-04-10 23:09:19 +0000 | [diff] [blame] | 33 | #include "llvm/Target/TargetFrameInfo.h" |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 34 | |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 35 | #include <iostream> |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 36 | #include <string> |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 37 | |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 38 | using namespace llvm; |
Jim Laskey | 9a777a3 | 2006-02-27 22:37:23 +0000 | [diff] [blame] | 39 | using namespace llvm::dwarf; |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 40 | |
| 41 | static cl::opt<bool> |
| 42 | DwarfVerbose("dwarf-verbose", cl::Hidden, |
Jim Laskey | ce50a16 | 2006-08-29 16:24:26 +0000 | [diff] [blame] | 43 | cl::desc("Add comments to Dwarf directives.")); |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 44 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 45 | namespace llvm { |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 46 | |
| 47 | //===----------------------------------------------------------------------===// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 48 | |
| 49 | /// Configuration values for initial hash set sizes (log2). |
| 50 | /// |
| 51 | static const unsigned InitDiesSetSize = 9; // 512 |
| 52 | static const unsigned InitAbbreviationsSetSize = 9; // 512 |
| 53 | static const unsigned InitValuesSetSize = 9; // 512 |
| 54 | |
| 55 | //===----------------------------------------------------------------------===// |
| 56 | /// Forward declarations. |
| 57 | /// |
| 58 | class DIE; |
| 59 | class DIEValue; |
| 60 | |
| 61 | //===----------------------------------------------------------------------===// |
| 62 | /// LEB 128 number encoding. |
| 63 | |
| 64 | /// PrintULEB128 - Print a series of hexidecimal values (separated by commas) |
| 65 | /// representing an unsigned leb128 value. |
| 66 | static void PrintULEB128(std::ostream &O, unsigned Value) { |
| 67 | do { |
| 68 | unsigned Byte = Value & 0x7f; |
| 69 | Value >>= 7; |
| 70 | if (Value) Byte |= 0x80; |
| 71 | O << "0x" << std::hex << Byte << std::dec; |
| 72 | if (Value) O << ", "; |
| 73 | } while (Value); |
| 74 | } |
| 75 | |
| 76 | /// SizeULEB128 - Compute the number of bytes required for an unsigned leb128 |
| 77 | /// value. |
| 78 | static unsigned SizeULEB128(unsigned Value) { |
| 79 | unsigned Size = 0; |
| 80 | do { |
| 81 | Value >>= 7; |
| 82 | Size += sizeof(int8_t); |
| 83 | } while (Value); |
| 84 | return Size; |
| 85 | } |
| 86 | |
| 87 | /// PrintSLEB128 - Print a series of hexidecimal values (separated by commas) |
| 88 | /// representing a signed leb128 value. |
| 89 | static void PrintSLEB128(std::ostream &O, int Value) { |
| 90 | int Sign = Value >> (8 * sizeof(Value) - 1); |
| 91 | bool IsMore; |
| 92 | |
| 93 | do { |
| 94 | unsigned Byte = Value & 0x7f; |
| 95 | Value >>= 7; |
| 96 | IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0; |
| 97 | if (IsMore) Byte |= 0x80; |
| 98 | O << "0x" << std::hex << Byte << std::dec; |
| 99 | if (IsMore) O << ", "; |
| 100 | } while (IsMore); |
| 101 | } |
| 102 | |
| 103 | /// SizeSLEB128 - Compute the number of bytes required for a signed leb128 |
| 104 | /// value. |
| 105 | static unsigned SizeSLEB128(int Value) { |
| 106 | unsigned Size = 0; |
| 107 | int Sign = Value >> (8 * sizeof(Value) - 1); |
| 108 | bool IsMore; |
| 109 | |
| 110 | do { |
| 111 | unsigned Byte = Value & 0x7f; |
| 112 | Value >>= 7; |
| 113 | IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0; |
| 114 | Size += sizeof(int8_t); |
| 115 | } while (IsMore); |
| 116 | return Size; |
| 117 | } |
| 118 | |
| 119 | //===----------------------------------------------------------------------===// |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 120 | /// DWLabel - Labels are used to track locations in the assembler file. |
| 121 | /// Labels appear in the form <prefix>debug_<Tag><Number>, where the tag is a |
| 122 | /// category of label (Ex. location) and number is a value unique in that |
| 123 | /// category. |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 124 | class DWLabel { |
| 125 | public: |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 126 | /// Tag - Label category tag. Should always be a staticly declared C string. |
| 127 | /// |
| 128 | const char *Tag; |
| 129 | |
| 130 | /// Number - Value to make label unique. |
| 131 | /// |
| 132 | unsigned Number; |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 133 | |
| 134 | DWLabel(const char *T, unsigned N) : Tag(T), Number(N) {} |
Jim Laskey | bd76184 | 2006-02-27 17:27:12 +0000 | [diff] [blame] | 135 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 136 | void Profile(FoldingSetNodeID &ID) const { |
| 137 | ID.AddString(std::string(Tag)); |
| 138 | ID.AddInteger(Number); |
Jim Laskey | 90c79d7 | 2006-03-23 23:02:34 +0000 | [diff] [blame] | 139 | } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 140 | |
| 141 | #ifndef NDEBUG |
| 142 | void print(std::ostream &O) const { |
| 143 | O << ".debug_" << Tag; |
| 144 | if (Number) O << Number; |
| 145 | } |
| 146 | #endif |
Jim Laskey | bd76184 | 2006-02-27 17:27:12 +0000 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | //===----------------------------------------------------------------------===// |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 150 | /// DIEAbbrevData - Dwarf abbreviation data, describes the one attribute of a |
| 151 | /// Dwarf abbreviation. |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 152 | class DIEAbbrevData { |
| 153 | private: |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 154 | /// Attribute - Dwarf attribute code. |
| 155 | /// |
| 156 | unsigned Attribute; |
| 157 | |
| 158 | /// Form - Dwarf form code. |
| 159 | /// |
| 160 | unsigned Form; |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 161 | |
| 162 | public: |
| 163 | DIEAbbrevData(unsigned A, unsigned F) |
| 164 | : Attribute(A) |
| 165 | , Form(F) |
| 166 | {} |
| 167 | |
Jim Laskey | bd76184 | 2006-02-27 17:27:12 +0000 | [diff] [blame] | 168 | // Accessors. |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 169 | unsigned getAttribute() const { return Attribute; } |
| 170 | unsigned getForm() const { return Form; } |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 171 | |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 172 | /// Profile - Used to gather unique data for the abbreviation folding set. |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 173 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 174 | void Profile(FoldingSetNodeID &ID)const { |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 175 | ID.AddInteger(Attribute); |
| 176 | ID.AddInteger(Form); |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 177 | } |
| 178 | }; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 179 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 180 | //===----------------------------------------------------------------------===// |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 181 | /// DIEAbbrev - Dwarf abbreviation, describes the organization of a debug |
| 182 | /// information object. |
| 183 | class DIEAbbrev : public FoldingSetNode { |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 184 | private: |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 185 | /// Tag - Dwarf tag code. |
| 186 | /// |
| 187 | unsigned Tag; |
| 188 | |
| 189 | /// Unique number for node. |
| 190 | /// |
| 191 | unsigned Number; |
| 192 | |
| 193 | /// ChildrenFlag - Dwarf children flag. |
| 194 | /// |
| 195 | unsigned ChildrenFlag; |
| 196 | |
| 197 | /// Data - Raw data bytes for abbreviation. |
| 198 | /// |
| 199 | std::vector<DIEAbbrevData> Data; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 200 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 201 | public: |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 202 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 203 | DIEAbbrev(unsigned T, unsigned C) |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 204 | : Tag(T) |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 205 | , ChildrenFlag(C) |
| 206 | , Data() |
| 207 | {} |
| 208 | ~DIEAbbrev() {} |
| 209 | |
Jim Laskey | bd76184 | 2006-02-27 17:27:12 +0000 | [diff] [blame] | 210 | // Accessors. |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 211 | unsigned getTag() const { return Tag; } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 212 | unsigned getNumber() const { return Number; } |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 213 | unsigned getChildrenFlag() const { return ChildrenFlag; } |
| 214 | const std::vector<DIEAbbrevData> &getData() const { return Data; } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 215 | void setTag(unsigned T) { Tag = T; } |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 216 | void setChildrenFlag(unsigned CF) { ChildrenFlag = CF; } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 217 | void setNumber(unsigned N) { Number = N; } |
| 218 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 219 | /// AddAttribute - Adds another set of attribute information to the |
| 220 | /// abbreviation. |
| 221 | void AddAttribute(unsigned Attribute, unsigned Form) { |
| 222 | Data.push_back(DIEAbbrevData(Attribute, Form)); |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 223 | } |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 224 | |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 225 | /// AddFirstAttribute - Adds a set of attribute information to the front |
| 226 | /// of the abbreviation. |
| 227 | void AddFirstAttribute(unsigned Attribute, unsigned Form) { |
| 228 | Data.insert(Data.begin(), DIEAbbrevData(Attribute, Form)); |
| 229 | } |
| 230 | |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 231 | /// Profile - Used to gather unique data for the abbreviation folding set. |
| 232 | /// |
| 233 | void Profile(FoldingSetNodeID &ID) { |
| 234 | ID.AddInteger(Tag); |
| 235 | ID.AddInteger(ChildrenFlag); |
| 236 | |
| 237 | // For each attribute description. |
| 238 | for (unsigned i = 0, N = Data.size(); i < N; ++i) |
| 239 | Data[i].Profile(ID); |
| 240 | } |
| 241 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 242 | /// Emit - Print the abbreviation using the specified Dwarf writer. |
| 243 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 244 | void Emit(const Dwarf &DW) const; |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 245 | |
| 246 | #ifndef NDEBUG |
| 247 | void print(std::ostream &O); |
| 248 | void dump(); |
| 249 | #endif |
| 250 | }; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 251 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 252 | //===----------------------------------------------------------------------===// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 253 | /// DIE - A structured debug information entry. Has an abbreviation which |
| 254 | /// describes it's organization. |
| 255 | class DIE : public FoldingSetNode { |
| 256 | protected: |
| 257 | /// Abbrev - Buffer for constructing abbreviation. |
| 258 | /// |
| 259 | DIEAbbrev Abbrev; |
| 260 | |
| 261 | /// Offset - Offset in debug info section. |
| 262 | /// |
| 263 | unsigned Offset; |
| 264 | |
| 265 | /// Size - Size of instance + children. |
| 266 | /// |
| 267 | unsigned Size; |
| 268 | |
| 269 | /// Children DIEs. |
| 270 | /// |
| 271 | std::vector<DIE *> Children; |
| 272 | |
| 273 | /// Attributes values. |
| 274 | /// |
| 275 | std::vector<DIEValue *> Values; |
| 276 | |
| 277 | public: |
| 278 | DIE(unsigned Tag) |
| 279 | : Abbrev(Tag, DW_CHILDREN_no) |
| 280 | , Offset(0) |
| 281 | , Size(0) |
| 282 | , Children() |
| 283 | , Values() |
| 284 | {} |
| 285 | virtual ~DIE(); |
| 286 | |
| 287 | // Accessors. |
| 288 | DIEAbbrev &getAbbrev() { return Abbrev; } |
| 289 | unsigned getAbbrevNumber() const { |
| 290 | return Abbrev.getNumber(); |
| 291 | } |
| 292 | unsigned getOffset() const { return Offset; } |
| 293 | unsigned getSize() const { return Size; } |
| 294 | const std::vector<DIE *> &getChildren() const { return Children; } |
| 295 | const std::vector<DIEValue *> &getValues() const { return Values; } |
| 296 | void setTag(unsigned Tag) { Abbrev.setTag(Tag); } |
| 297 | void setOffset(unsigned O) { Offset = O; } |
| 298 | void setSize(unsigned S) { Size = S; } |
| 299 | |
| 300 | /// AddValue - Add a value and attributes to a DIE. |
| 301 | /// |
| 302 | void AddValue(unsigned Attribute, unsigned Form, DIEValue *Value) { |
| 303 | Abbrev.AddAttribute(Attribute, Form); |
| 304 | Values.push_back(Value); |
| 305 | } |
| 306 | |
| 307 | /// SiblingOffset - Return the offset of the debug information entry's |
| 308 | /// sibling. |
| 309 | unsigned SiblingOffset() const { return Offset + Size; } |
| 310 | |
| 311 | /// AddSiblingOffset - Add a sibling offset field to the front of the DIE. |
| 312 | /// |
| 313 | void AddSiblingOffset(); |
| 314 | |
| 315 | /// AddChild - Add a child to the DIE. |
| 316 | /// |
| 317 | void AddChild(DIE *Child) { |
| 318 | Abbrev.setChildrenFlag(DW_CHILDREN_yes); |
| 319 | Children.push_back(Child); |
| 320 | } |
| 321 | |
| 322 | /// Detach - Detaches objects connected to it after copying. |
| 323 | /// |
| 324 | void Detach() { |
| 325 | Children.clear(); |
| 326 | } |
| 327 | |
| 328 | /// Profile - Used to gather unique data for the value folding set. |
| 329 | /// |
| 330 | void Profile(FoldingSetNodeID &ID) ; |
| 331 | |
| 332 | #ifndef NDEBUG |
| 333 | void print(std::ostream &O, unsigned IncIndent = 0); |
| 334 | void dump(); |
| 335 | #endif |
| 336 | }; |
| 337 | |
| 338 | //===----------------------------------------------------------------------===// |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 339 | /// DIEValue - A debug information entry value. |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 340 | /// |
| 341 | class DIEValue : public FoldingSetNode { |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 342 | public: |
| 343 | enum { |
| 344 | isInteger, |
| 345 | isString, |
| 346 | isLabel, |
| 347 | isAsIsLabel, |
| 348 | isDelta, |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 349 | isEntry, |
| 350 | isBlock |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 351 | }; |
| 352 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 353 | /// Type - Type of data stored in the value. |
| 354 | /// |
| 355 | unsigned Type; |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 356 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 357 | /// Usage - Number of uses of this value. |
| 358 | /// |
| 359 | unsigned Usage; |
| 360 | |
| 361 | DIEValue(unsigned T) |
| 362 | : Type(T) |
| 363 | , Usage(1) |
| 364 | {} |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 365 | virtual ~DIEValue() {} |
| 366 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 367 | unsigned getType() const { return Type; } |
| 368 | unsigned getUsage() const { return Usage; } |
| 369 | void IncUsage() { ++Usage; } |
| 370 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 371 | // Implement isa/cast/dyncast. |
| 372 | static bool classof(const DIEValue *) { return true; } |
| 373 | |
| 374 | /// EmitValue - Emit value via the Dwarf writer. |
| 375 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 376 | virtual void EmitValue(const Dwarf &DW, unsigned Form) const = 0; |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 377 | |
| 378 | /// SizeOf - Return the size of a value in bytes. |
| 379 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 380 | virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const = 0; |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 381 | |
| 382 | /// Profile - Used to gather unique data for the value folding set. |
| 383 | /// |
| 384 | virtual void Profile(FoldingSetNodeID &ID) = 0; |
| 385 | |
| 386 | #ifndef NDEBUG |
| 387 | virtual void print(std::ostream &O) = 0; |
| 388 | void dump(); |
| 389 | #endif |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 390 | }; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 391 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 392 | //===----------------------------------------------------------------------===// |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 393 | /// DWInteger - An integer value DIE. |
| 394 | /// |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 395 | class DIEInteger : public DIEValue { |
| 396 | private: |
| 397 | uint64_t Integer; |
| 398 | |
| 399 | public: |
| 400 | DIEInteger(uint64_t I) : DIEValue(isInteger), Integer(I) {} |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 401 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 402 | // Implement isa/cast/dyncast. |
| 403 | static bool classof(const DIEInteger *) { return true; } |
| 404 | static bool classof(const DIEValue *I) { return I->Type == isInteger; } |
| 405 | |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 406 | /// BestForm - Choose the best form for integer. |
| 407 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 408 | static unsigned BestForm(bool IsSigned, uint64_t Integer) { |
| 409 | if (IsSigned) { |
| 410 | if ((char)Integer == (signed)Integer) return DW_FORM_data1; |
| 411 | if ((short)Integer == (signed)Integer) return DW_FORM_data2; |
| 412 | if ((int)Integer == (signed)Integer) return DW_FORM_data4; |
| 413 | } else { |
| 414 | if ((unsigned char)Integer == Integer) return DW_FORM_data1; |
| 415 | if ((unsigned short)Integer == Integer) return DW_FORM_data2; |
| 416 | if ((unsigned int)Integer == Integer) return DW_FORM_data4; |
| 417 | } |
| 418 | return DW_FORM_data8; |
| 419 | } |
| 420 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 421 | /// EmitValue - Emit integer of appropriate size. |
| 422 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 423 | virtual void EmitValue(const Dwarf &DW, unsigned Form) const; |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 424 | |
| 425 | /// SizeOf - Determine size of integer value in bytes. |
| 426 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 427 | virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const { |
| 428 | switch (Form) { |
| 429 | case DW_FORM_flag: // Fall thru |
| 430 | case DW_FORM_ref1: // Fall thru |
| 431 | case DW_FORM_data1: return sizeof(int8_t); |
| 432 | case DW_FORM_ref2: // Fall thru |
| 433 | case DW_FORM_data2: return sizeof(int16_t); |
| 434 | case DW_FORM_ref4: // Fall thru |
| 435 | case DW_FORM_data4: return sizeof(int32_t); |
| 436 | case DW_FORM_ref8: // Fall thru |
| 437 | case DW_FORM_data8: return sizeof(int64_t); |
| 438 | case DW_FORM_udata: return SizeULEB128(Integer); |
| 439 | case DW_FORM_sdata: return SizeSLEB128(Integer); |
| 440 | default: assert(0 && "DIE Value form not supported yet"); break; |
| 441 | } |
| 442 | return 0; |
| 443 | } |
| 444 | |
| 445 | /// Profile - Used to gather unique data for the value folding set. |
| 446 | /// |
| 447 | virtual void Profile(FoldingSetNodeID &ID) { |
| 448 | ID.AddInteger(Integer); |
| 449 | } |
| 450 | |
| 451 | #ifndef NDEBUG |
| 452 | virtual void print(std::ostream &O) { |
| 453 | O << "Int: " << (int64_t)Integer |
| 454 | << " 0x" << std::hex << Integer << std::dec; |
| 455 | } |
| 456 | #endif |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 457 | }; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 458 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 459 | //===----------------------------------------------------------------------===// |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 460 | /// DIEString - A string value DIE. |
| 461 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 462 | class DIEString : public DIEValue { |
| 463 | public: |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 464 | const std::string String; |
| 465 | |
| 466 | DIEString(const std::string &S) : DIEValue(isString), String(S) {} |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 467 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 468 | // Implement isa/cast/dyncast. |
| 469 | static bool classof(const DIEString *) { return true; } |
| 470 | static bool classof(const DIEValue *S) { return S->Type == isString; } |
| 471 | |
| 472 | /// EmitValue - Emit string value. |
| 473 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 474 | virtual void EmitValue(const Dwarf &DW, unsigned Form) const; |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 475 | |
| 476 | /// SizeOf - Determine size of string value in bytes. |
| 477 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 478 | virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const { |
| 479 | return String.size() + sizeof(char); // sizeof('\0'); |
| 480 | } |
| 481 | |
| 482 | /// Profile - Used to gather unique data for the value folding set. |
| 483 | /// |
| 484 | virtual void Profile(FoldingSetNodeID &ID) { |
| 485 | ID.AddString(String); |
| 486 | } |
| 487 | |
| 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; |
| 502 | |
| 503 | 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; } |
| 508 | |
| 509 | /// EmitValue - Emit label value. |
| 510 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 511 | virtual void EmitValue(const Dwarf &DW, unsigned Form) const; |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 512 | |
| 513 | /// SizeOf - Determine size of label value in bytes. |
| 514 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 515 | virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const; |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 516 | |
| 517 | /// Profile - Used to gather unique data for the value folding set. |
| 518 | /// |
| 519 | virtual void Profile(FoldingSetNodeID &ID) { |
| 520 | Label.Profile(ID); |
| 521 | } |
| 522 | |
| 523 | #ifndef NDEBUG |
| 524 | virtual void print(std::ostream &O) { |
| 525 | O << "Lbl: "; |
| 526 | Label.print(O); |
| 527 | } |
| 528 | #endif |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 529 | }; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 530 | |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 531 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 532 | //===----------------------------------------------------------------------===// |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 533 | /// DIEObjectLabel - A label to an object in code or data. |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 534 | // |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 535 | class DIEObjectLabel : public DIEValue { |
| 536 | public: |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 537 | const std::string Label; |
| 538 | |
| 539 | DIEObjectLabel(const std::string &L) : DIEValue(isAsIsLabel), Label(L) {} |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 540 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 541 | // Implement isa/cast/dyncast. |
| 542 | static bool classof(const DIEObjectLabel *) { return true; } |
| 543 | static bool classof(const DIEValue *L) { return L->Type == isAsIsLabel; } |
| 544 | |
| 545 | /// EmitValue - Emit label value. |
| 546 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 547 | virtual void EmitValue(const Dwarf &DW, unsigned Form) const; |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 548 | |
| 549 | /// SizeOf - Determine size of label value in bytes. |
| 550 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 551 | virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const; |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 552 | |
| 553 | /// Profile - Used to gather unique data for the value folding set. |
| 554 | /// |
| 555 | virtual void Profile(FoldingSetNodeID &ID) { |
| 556 | ID.AddString(Label); |
| 557 | } |
| 558 | |
| 559 | #ifndef NDEBUG |
| 560 | virtual void print(std::ostream &O) { |
| 561 | O << "Obj: " << Label; |
| 562 | } |
| 563 | #endif |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 564 | }; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 565 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 566 | //===----------------------------------------------------------------------===// |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 567 | /// DIEDelta - A simple label difference DIE. |
| 568 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 569 | class DIEDelta : public DIEValue { |
| 570 | public: |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 571 | const DWLabel LabelHi; |
| 572 | const DWLabel LabelLo; |
| 573 | |
| 574 | DIEDelta(const DWLabel &Hi, const DWLabel &Lo) |
| 575 | : DIEValue(isDelta), LabelHi(Hi), LabelLo(Lo) {} |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 576 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 577 | // Implement isa/cast/dyncast. |
| 578 | static bool classof(const DIEDelta *) { return true; } |
| 579 | static bool classof(const DIEValue *D) { return D->Type == isDelta; } |
| 580 | |
| 581 | /// EmitValue - Emit delta value. |
| 582 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 583 | virtual void EmitValue(const Dwarf &DW, unsigned Form) const; |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 584 | |
| 585 | /// SizeOf - Determine size of delta value in bytes. |
| 586 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 587 | virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const; |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 588 | |
| 589 | /// Profile - Used to gather unique data for the value folding set. |
| 590 | /// |
| 591 | virtual void Profile(FoldingSetNodeID &ID){ |
| 592 | LabelHi.Profile(ID); |
| 593 | LabelLo.Profile(ID); |
| 594 | } |
| 595 | |
| 596 | #ifndef NDEBUG |
| 597 | virtual void print(std::ostream &O) { |
| 598 | O << "Del: "; |
| 599 | LabelHi.print(O); |
| 600 | O << "-"; |
| 601 | LabelLo.print(O); |
| 602 | } |
| 603 | #endif |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 604 | }; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 605 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 606 | //===----------------------------------------------------------------------===// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 607 | /// DIEntry - A pointer to another debug information entry. An instance of this |
| 608 | /// class can also be used as a proxy for a debug information entry not yet |
| 609 | /// defined (ie. types.) |
| 610 | class DIEntry : public DIEValue { |
| 611 | public: |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 612 | DIE *Entry; |
| 613 | |
| 614 | DIEntry(DIE *E) : DIEValue(isEntry), Entry(E) {} |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 615 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 616 | // Implement isa/cast/dyncast. |
| 617 | static bool classof(const DIEntry *) { return true; } |
| 618 | static bool classof(const DIEValue *E) { return E->Type == isEntry; } |
| 619 | |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 620 | /// EmitValue - Emit debug information entry offset. |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 621 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 622 | virtual void EmitValue(const Dwarf &DW, unsigned Form) const; |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 623 | |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 624 | /// SizeOf - Determine size of debug information entry in bytes. |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 625 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 626 | virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const { |
| 627 | return sizeof(int32_t); |
| 628 | } |
| 629 | |
| 630 | /// Profile - Used to gather unique data for the value folding set. |
| 631 | /// |
| 632 | virtual void Profile(FoldingSetNodeID &ID) { |
| 633 | if (Entry) { |
| 634 | ID.AddPointer(Entry); |
| 635 | } else { |
| 636 | ID.AddPointer(this); |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | #ifndef NDEBUG |
| 641 | virtual void print(std::ostream &O) { |
| 642 | O << "Die: 0x" << std::hex << (intptr_t)Entry << std::dec; |
| 643 | } |
| 644 | #endif |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 645 | }; |
| 646 | |
| 647 | //===----------------------------------------------------------------------===// |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 648 | /// DIEBlock - A block of values. Primarily used for location expressions. |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 649 | // |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 650 | class DIEBlock : public DIEValue, public DIE { |
| 651 | public: |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 652 | unsigned Size; // Size in bytes excluding size header. |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 653 | |
| 654 | DIEBlock() |
| 655 | : DIEValue(isBlock) |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 656 | , DIE(0) |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 657 | , Size(0) |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 658 | {} |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 659 | ~DIEBlock() { |
| 660 | } |
| 661 | |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 662 | // Implement isa/cast/dyncast. |
| 663 | static bool classof(const DIEBlock *) { return true; } |
| 664 | static bool classof(const DIEValue *E) { return E->Type == isBlock; } |
| 665 | |
| 666 | /// ComputeSize - calculate the size of the block. |
| 667 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 668 | unsigned ComputeSize(Dwarf &DW); |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 669 | |
| 670 | /// BestForm - Choose the best form for data. |
| 671 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 672 | unsigned BestForm() const { |
| 673 | if ((unsigned char)Size == Size) return DW_FORM_block1; |
| 674 | if ((unsigned short)Size == Size) return DW_FORM_block2; |
| 675 | if ((unsigned int)Size == Size) return DW_FORM_block4; |
| 676 | return DW_FORM_block; |
| 677 | } |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 678 | |
| 679 | /// EmitValue - Emit block data. |
| 680 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 681 | virtual void EmitValue(const Dwarf &DW, unsigned Form) const; |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 682 | |
| 683 | /// SizeOf - Determine size of block data in bytes. |
| 684 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 685 | virtual unsigned SizeOf(const Dwarf &DW, unsigned Form) const; |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 686 | |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +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. |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 689 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 690 | virtual void DIEBlock::Profile(FoldingSetNodeID &ID) { |
| 691 | DIE::Profile(ID); |
| 692 | } |
| 693 | |
| 694 | #ifndef NDEBUG |
| 695 | virtual void print(std::ostream &O) { |
| 696 | O << "Blk: "; |
| 697 | DIE::print(O, 5); |
| 698 | } |
| 699 | #endif |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 700 | }; |
| 701 | |
| 702 | //===----------------------------------------------------------------------===// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 703 | /// CompileUnit - This dwarf writer support class manages information associate |
| 704 | /// with a source file. |
| 705 | class CompileUnit { |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 706 | private: |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 707 | /// Desc - Compile unit debug descriptor. |
| 708 | /// |
| 709 | CompileUnitDesc *Desc; |
| 710 | |
| 711 | /// ID - File identifier for source. |
| 712 | /// |
| 713 | unsigned ID; |
| 714 | |
| 715 | /// Die - Compile unit debug information entry. |
| 716 | /// |
| 717 | DIE *Die; |
| 718 | |
| 719 | /// DescToDieMap - Tracks the mapping of unit level debug informaton |
| 720 | /// descriptors to debug information entries. |
| 721 | std::map<DebugInfoDesc *, DIE *> DescToDieMap; |
| 722 | |
| 723 | /// DescToDIEntryMap - Tracks the mapping of unit level debug informaton |
| 724 | /// descriptors to debug information entries using a DIEntry proxy. |
| 725 | std::map<DebugInfoDesc *, DIEntry *> DescToDIEntryMap; |
| 726 | |
| 727 | /// Globals - A map of globally visible named entities for this unit. |
| 728 | /// |
| 729 | std::map<std::string, DIE *> Globals; |
| 730 | |
| 731 | /// DiesSet - Used to uniquely define dies within the compile unit. |
| 732 | /// |
| 733 | FoldingSet<DIE> DiesSet; |
| 734 | |
| 735 | /// Dies - List of all dies in the compile unit. |
| 736 | /// |
| 737 | std::vector<DIE *> Dies; |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 738 | |
| 739 | public: |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 740 | CompileUnit(CompileUnitDesc *CUD, unsigned I, DIE *D) |
| 741 | : Desc(CUD) |
| 742 | , ID(I) |
| 743 | , Die(D) |
| 744 | , DescToDieMap() |
| 745 | , DescToDIEntryMap() |
| 746 | , Globals() |
| 747 | , DiesSet(InitDiesSetSize) |
| 748 | , Dies() |
| 749 | {} |
| 750 | |
| 751 | ~CompileUnit() { |
| 752 | delete Die; |
| 753 | |
| 754 | for (unsigned i = 0, N = Dies.size(); i < N; ++i) |
| 755 | delete Dies[i]; |
| 756 | } |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 757 | |
Jim Laskey | bd76184 | 2006-02-27 17:27:12 +0000 | [diff] [blame] | 758 | // Accessors. |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 759 | CompileUnitDesc *getDesc() const { return Desc; } |
| 760 | unsigned getID() const { return ID; } |
| 761 | DIE* getDie() const { return Die; } |
| 762 | std::map<std::string, DIE *> &getGlobals() { return Globals; } |
| 763 | |
| 764 | /// hasContent - Return true if this compile unit has something to write out. |
| 765 | /// |
| 766 | bool hasContent() const { |
| 767 | return !Die->getChildren().empty(); |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 768 | } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 769 | |
| 770 | /// AddGlobal - Add a new global entity to the compile unit. |
| 771 | /// |
| 772 | void AddGlobal(const std::string &Name, DIE *Die) { |
| 773 | Globals[Name] = Die; |
| 774 | } |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 775 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 776 | /// getDieMapSlotFor - Returns the debug information entry map slot for the |
| 777 | /// specified debug descriptor. |
| 778 | DIE *&getDieMapSlotFor(DebugInfoDesc *DD) { |
| 779 | return DescToDieMap[DD]; |
| 780 | } |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 781 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 782 | /// getDIEntrySlotFor - Returns the debug information entry proxy slot for the |
| 783 | /// specified debug descriptor. |
| 784 | DIEntry *&getDIEntrySlotFor(DebugInfoDesc *DD) { |
| 785 | return DescToDIEntryMap[DD]; |
| 786 | } |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 787 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 788 | /// AddDie - Adds or interns the DIE to the compile unit. |
| 789 | /// |
| 790 | DIE *AddDie(DIE &Buffer) { |
| 791 | FoldingSetNodeID ID; |
| 792 | Buffer.Profile(ID); |
| 793 | void *Where; |
| 794 | DIE *Die = DiesSet.FindNodeOrInsertPos(ID, Where); |
| 795 | |
| 796 | if (!Die) { |
| 797 | Die = new DIE(Buffer); |
| 798 | DiesSet.InsertNode(Die, Where); |
| 799 | this->Die->AddChild(Die); |
| 800 | Buffer.Detach(); |
| 801 | } |
| 802 | |
| 803 | return Die; |
| 804 | } |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 805 | }; |
| 806 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 807 | //===----------------------------------------------------------------------===// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 808 | /// Dwarf - Emits Dwarf debug and exception handling directives. |
| 809 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 810 | class Dwarf { |
| 811 | |
| 812 | private: |
| 813 | |
| 814 | //===--------------------------------------------------------------------===// |
| 815 | // Core attributes used by the Dwarf writer. |
| 816 | // |
| 817 | |
| 818 | // |
| 819 | /// O - Stream to .s file. |
| 820 | /// |
| 821 | std::ostream &O; |
| 822 | |
| 823 | /// Asm - Target of Dwarf emission. |
| 824 | /// |
| 825 | AsmPrinter *Asm; |
| 826 | |
| 827 | /// TAI - Target Asm Printer. |
| 828 | const TargetAsmInfo *TAI; |
| 829 | |
| 830 | /// TD - Target data. |
| 831 | const TargetData *TD; |
| 832 | |
| 833 | /// RI - Register Information. |
| 834 | const MRegisterInfo *RI; |
| 835 | |
| 836 | /// M - Current module. |
| 837 | /// |
| 838 | Module *M; |
| 839 | |
| 840 | /// MF - Current machine function. |
| 841 | /// |
| 842 | MachineFunction *MF; |
| 843 | |
| 844 | /// DebugInfo - Collected debug information. |
| 845 | /// |
| 846 | MachineDebugInfo *DebugInfo; |
| 847 | |
| 848 | /// didInitial - Flag to indicate if initial emission has been done. |
| 849 | /// |
| 850 | bool didInitial; |
| 851 | |
| 852 | /// shouldEmit - Flag to indicate if debug information should be emitted. |
| 853 | /// |
| 854 | bool shouldEmit; |
| 855 | |
| 856 | /// SubprogramCount - The running count of functions being compiled. |
| 857 | /// |
| 858 | unsigned SubprogramCount; |
| 859 | |
| 860 | //===--------------------------------------------------------------------===// |
| 861 | // Attributes used to construct specific Dwarf sections. |
| 862 | // |
| 863 | |
| 864 | /// CompileUnits - All the compile units involved in this build. The index |
| 865 | /// of each entry in this vector corresponds to the sources in DebugInfo. |
| 866 | std::vector<CompileUnit *> CompileUnits; |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 867 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 868 | /// AbbreviationsSet - Used to uniquely define abbreviations. |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 869 | /// |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 870 | FoldingSet<DIEAbbrev> AbbreviationsSet; |
| 871 | |
| 872 | /// Abbreviations - A list of all the unique abbreviations in use. |
| 873 | /// |
| 874 | std::vector<DIEAbbrev *> Abbreviations; |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 875 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 876 | /// ValuesSet - Used to uniquely define values. |
| 877 | /// |
| 878 | FoldingSet<DIEValue> ValuesSet; |
| 879 | |
| 880 | /// Values - A list of all the unique values in use. |
| 881 | /// |
| 882 | std::vector<DIEValue *> Values; |
| 883 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 884 | /// StringPool - A UniqueVector of strings used by indirect references. |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 885 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 886 | UniqueVector<std::string> StringPool; |
| 887 | |
| 888 | /// UnitMap - Map debug information descriptor to compile unit. |
| 889 | /// |
| 890 | std::map<DebugInfoDesc *, CompileUnit *> DescToUnitMap; |
| 891 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 892 | /// SectionMap - Provides a unique id per text section. |
| 893 | /// |
| 894 | UniqueVector<std::string> SectionMap; |
| 895 | |
| 896 | /// SectionSourceLines - Tracks line numbers per text section. |
| 897 | /// |
| 898 | std::vector<std::vector<SourceLineInfo> > SectionSourceLines; |
| 899 | |
| 900 | |
| 901 | public: |
| 902 | |
| 903 | //===--------------------------------------------------------------------===// |
| 904 | // Emission and print routines |
| 905 | // |
| 906 | |
| 907 | /// PrintHex - Print a value as a hexidecimal value. |
| 908 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 909 | void PrintHex(int Value) const { |
| 910 | O << "0x" << std::hex << Value << std::dec; |
| 911 | } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 912 | |
| 913 | /// EOL - Print a newline character to asm stream. If a comment is present |
| 914 | /// then it will be printed first. Comments should not contain '\n'. |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 915 | void EOL(const std::string &Comment) const { |
| 916 | if (DwarfVerbose && !Comment.empty()) { |
| 917 | O << "\t" |
| 918 | << TAI->getCommentString() |
| 919 | << " " |
| 920 | << Comment; |
| 921 | } |
| 922 | O << "\n"; |
| 923 | } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 924 | |
| 925 | /// EmitAlign - Print a align directive. |
| 926 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 927 | void EmitAlign(unsigned Alignment) const { |
| 928 | O << TAI->getAlignDirective() << Alignment << "\n"; |
| 929 | } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 930 | |
| 931 | /// EmitULEB128Bytes - Emit an assembler byte data directive to compose an |
| 932 | /// unsigned leb128 value. |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 933 | void EmitULEB128Bytes(unsigned Value) const { |
| 934 | if (TAI->hasLEB128()) { |
| 935 | O << "\t.uleb128\t" |
| 936 | << Value; |
| 937 | } else { |
| 938 | O << TAI->getData8bitsDirective(); |
| 939 | PrintULEB128(O, Value); |
| 940 | } |
| 941 | } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 942 | |
| 943 | /// EmitSLEB128Bytes - print an assembler byte data directive to compose a |
| 944 | /// signed leb128 value. |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 945 | void EmitSLEB128Bytes(int Value) const { |
| 946 | if (TAI->hasLEB128()) { |
| 947 | O << "\t.sleb128\t" |
| 948 | << Value; |
| 949 | } else { |
| 950 | O << TAI->getData8bitsDirective(); |
| 951 | PrintSLEB128(O, Value); |
| 952 | } |
| 953 | } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 954 | |
| 955 | /// EmitInt8 - Emit a byte directive and value. |
| 956 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 957 | void EmitInt8(int Value) const { |
| 958 | O << TAI->getData8bitsDirective(); |
| 959 | PrintHex(Value & 0xFF); |
| 960 | } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 961 | |
| 962 | /// EmitInt16 - Emit a short directive and value. |
| 963 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 964 | void EmitInt16(int Value) const { |
| 965 | O << TAI->getData16bitsDirective(); |
| 966 | PrintHex(Value & 0xFFFF); |
| 967 | } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 968 | |
| 969 | /// EmitInt32 - Emit a long directive and value. |
| 970 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 971 | void EmitInt32(int Value) const { |
| 972 | O << TAI->getData32bitsDirective(); |
| 973 | PrintHex(Value); |
| 974 | } |
| 975 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 976 | /// EmitInt64 - Emit a long long directive and value. |
| 977 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 978 | void EmitInt64(uint64_t Value) const { |
| 979 | if (TAI->getData64bitsDirective()) { |
| 980 | O << TAI->getData64bitsDirective(); |
| 981 | PrintHex(Value); |
| 982 | } else { |
| 983 | if (TD->isBigEndian()) { |
| 984 | EmitInt32(unsigned(Value >> 32)); O << "\n"; |
| 985 | EmitInt32(unsigned(Value)); |
| 986 | } else { |
| 987 | EmitInt32(unsigned(Value)); O << "\n"; |
| 988 | EmitInt32(unsigned(Value >> 32)); |
| 989 | } |
| 990 | } |
| 991 | } |
| 992 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 993 | /// EmitString - Emit a string with quotes and a null terminator. |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 994 | /// Special characters are emitted properly. |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 995 | /// \literal (Eg. '\t') \endliteral |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 996 | void EmitString(const std::string &String) const { |
| 997 | O << TAI->getAsciiDirective() |
| 998 | << "\""; |
| 999 | for (unsigned i = 0, N = String.size(); i < N; ++i) { |
| 1000 | unsigned char C = String[i]; |
| 1001 | |
| 1002 | if (!isascii(C) || iscntrl(C)) { |
| 1003 | switch(C) { |
| 1004 | case '\b': O << "\\b"; break; |
| 1005 | case '\f': O << "\\f"; break; |
| 1006 | case '\n': O << "\\n"; break; |
| 1007 | case '\r': O << "\\r"; break; |
| 1008 | case '\t': O << "\\t"; break; |
| 1009 | default: |
| 1010 | O << '\\'; |
| 1011 | O << char('0' + ((C >> 6) & 7)); |
| 1012 | O << char('0' + ((C >> 3) & 7)); |
| 1013 | O << char('0' + ((C >> 0) & 7)); |
| 1014 | break; |
| 1015 | } |
| 1016 | } else if (C == '\"') { |
| 1017 | O << "\\\""; |
| 1018 | } else if (C == '\'') { |
| 1019 | O << "\\\'"; |
| 1020 | } else { |
| 1021 | O << C; |
| 1022 | } |
| 1023 | } |
| 1024 | O << "\\0\""; |
| 1025 | } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1026 | |
| 1027 | /// PrintLabelName - Print label name in form used by Dwarf writer. |
| 1028 | /// |
| 1029 | void PrintLabelName(DWLabel Label) const { |
| 1030 | PrintLabelName(Label.Tag, Label.Number); |
| 1031 | } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 1032 | void PrintLabelName(const char *Tag, unsigned Number) const { |
| 1033 | O << TAI->getPrivateGlobalPrefix() |
| 1034 | << "debug_" |
| 1035 | << Tag; |
| 1036 | if (Number) O << Number; |
| 1037 | } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1038 | |
| 1039 | /// EmitLabel - Emit location label for internal use by Dwarf. |
| 1040 | /// |
| 1041 | void EmitLabel(DWLabel Label) const { |
| 1042 | EmitLabel(Label.Tag, Label.Number); |
| 1043 | } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 1044 | void EmitLabel(const char *Tag, unsigned Number) const { |
| 1045 | PrintLabelName(Tag, Number); |
| 1046 | O << ":\n"; |
| 1047 | } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1048 | |
| 1049 | /// EmitReference - Emit a reference to a label. |
| 1050 | /// |
| 1051 | void EmitReference(DWLabel Label) const { |
| 1052 | EmitReference(Label.Tag, Label.Number); |
| 1053 | } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 1054 | void EmitReference(const char *Tag, unsigned Number) const { |
| 1055 | if (TAI->getAddressSize() == 4) |
| 1056 | O << TAI->getData32bitsDirective(); |
| 1057 | else |
| 1058 | O << TAI->getData64bitsDirective(); |
| 1059 | |
| 1060 | PrintLabelName(Tag, Number); |
| 1061 | } |
| 1062 | void EmitReference(const std::string &Name) const { |
| 1063 | if (TAI->getAddressSize() == 4) |
| 1064 | O << TAI->getData32bitsDirective(); |
| 1065 | else |
| 1066 | O << TAI->getData64bitsDirective(); |
| 1067 | |
| 1068 | O << Name; |
| 1069 | } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1070 | |
| 1071 | /// EmitDifference - Emit the difference between two labels. Some |
| 1072 | /// assemblers do not behave with absolute expressions with data directives, |
| 1073 | /// so there is an option (needsSet) to use an intermediary set expression. |
| 1074 | void EmitDifference(DWLabel LabelHi, DWLabel LabelLo) const { |
| 1075 | EmitDifference(LabelHi.Tag, LabelHi.Number, LabelLo.Tag, LabelLo.Number); |
| 1076 | } |
| 1077 | void EmitDifference(const char *TagHi, unsigned NumberHi, |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 1078 | const char *TagLo, unsigned NumberLo) const { |
| 1079 | if (TAI->needsSet()) { |
| 1080 | static unsigned SetCounter = 0; |
| 1081 | |
| 1082 | O << "\t.set\t"; |
| 1083 | PrintLabelName("set", SetCounter); |
| 1084 | O << ","; |
| 1085 | PrintLabelName(TagHi, NumberHi); |
| 1086 | O << "-"; |
| 1087 | PrintLabelName(TagLo, NumberLo); |
| 1088 | O << "\n"; |
| 1089 | |
| 1090 | if (TAI->getAddressSize() == sizeof(int32_t)) |
| 1091 | O << TAI->getData32bitsDirective(); |
| 1092 | else |
| 1093 | O << TAI->getData64bitsDirective(); |
| 1094 | |
| 1095 | PrintLabelName("set", SetCounter); |
| 1096 | |
| 1097 | ++SetCounter; |
| 1098 | } else { |
| 1099 | if (TAI->getAddressSize() == sizeof(int32_t)) |
| 1100 | O << TAI->getData32bitsDirective(); |
| 1101 | else |
| 1102 | O << TAI->getData64bitsDirective(); |
| 1103 | |
| 1104 | PrintLabelName(TagHi, NumberHi); |
| 1105 | O << "-"; |
| 1106 | PrintLabelName(TagLo, NumberLo); |
| 1107 | } |
| 1108 | } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1109 | |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 1110 | /// AssignAbbrevNumber - Define a unique number for the abbreviation. |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1111 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 1112 | void AssignAbbrevNumber(DIEAbbrev &Abbrev) { |
| 1113 | // Profile the node so that we can make it unique. |
| 1114 | FoldingSetNodeID ID; |
| 1115 | Abbrev.Profile(ID); |
| 1116 | |
| 1117 | // Check the set for priors. |
| 1118 | DIEAbbrev *InSet = AbbreviationsSet.GetOrInsertNode(&Abbrev); |
| 1119 | |
| 1120 | // If it's newly added. |
| 1121 | if (InSet == &Abbrev) { |
| 1122 | // Add to abbreviation list. |
| 1123 | Abbreviations.push_back(&Abbrev); |
| 1124 | // Assign the vector position + 1 as its number. |
| 1125 | Abbrev.setNumber(Abbreviations.size()); |
| 1126 | } else { |
| 1127 | // Assign existing abbreviation number. |
| 1128 | Abbrev.setNumber(InSet->getNumber()); |
| 1129 | } |
| 1130 | } |
| 1131 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1132 | /// NewString - Add a string to the constant pool and returns a label. |
| 1133 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 1134 | DWLabel NewString(const std::string &String) { |
| 1135 | unsigned StringID = StringPool.insert(String); |
| 1136 | return DWLabel("string", StringID); |
| 1137 | } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1138 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 1139 | /// NewDIEntry - Creates a new DIEntry to be a proxy for a debug information |
| 1140 | /// entry. |
| 1141 | DIEntry *NewDIEntry(DIE *Entry = NULL) { |
| 1142 | DIEntry *Value; |
| 1143 | |
| 1144 | if (Entry) { |
| 1145 | FoldingSetNodeID ID; |
| 1146 | ID.AddPointer(Entry); |
| 1147 | void *Where; |
| 1148 | Value = static_cast<DIEntry *>(ValuesSet.FindNodeOrInsertPos(ID, Where)); |
| 1149 | |
| 1150 | if (Value) { |
| 1151 | Value->IncUsage(); |
| 1152 | return Value; |
| 1153 | } |
| 1154 | |
| 1155 | Value = new DIEntry(Entry); |
| 1156 | ValuesSet.InsertNode(Value, Where); |
| 1157 | } else { |
| 1158 | Value = new DIEntry(Entry); |
| 1159 | } |
| 1160 | |
| 1161 | Values.push_back(Value); |
| 1162 | return Value; |
| 1163 | } |
| 1164 | |
| 1165 | /// SetDIEntry - Set a DIEntry once the debug information entry is defined. |
| 1166 | /// |
| 1167 | void SetDIEntry(DIEntry *Value, DIE *Entry) { |
| 1168 | Value->Entry = Entry; |
| 1169 | // Add to values set if not already there. If it is, we merely have a |
| 1170 | // duplicate in the values list (no harm.) |
| 1171 | ValuesSet.GetOrInsertNode(Value); |
| 1172 | } |
| 1173 | |
| 1174 | /// AddUInt - Add an unsigned integer attribute data and value. |
| 1175 | /// |
| 1176 | void AddUInt(DIE *Die, unsigned Attribute, unsigned Form, uint64_t Integer) { |
| 1177 | if (!Form) Form = DIEInteger::BestForm(false, Integer); |
| 1178 | |
| 1179 | FoldingSetNodeID ID; |
| 1180 | ID.AddInteger(Integer); |
| 1181 | void *Where; |
| 1182 | DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where); |
| 1183 | if (!Value) { |
| 1184 | Value = new DIEInteger(Integer); |
| 1185 | ValuesSet.InsertNode(Value, Where); |
| 1186 | Values.push_back(Value); |
| 1187 | } else { |
| 1188 | Value->IncUsage(); |
| 1189 | } |
| 1190 | |
| 1191 | Die->AddValue(Attribute, Form, Value); |
| 1192 | } |
| 1193 | |
| 1194 | /// AddSInt - Add an signed integer attribute data and value. |
| 1195 | /// |
| 1196 | void AddSInt(DIE *Die, unsigned Attribute, unsigned Form, int64_t Integer) { |
| 1197 | if (!Form) Form = DIEInteger::BestForm(true, Integer); |
| 1198 | |
| 1199 | FoldingSetNodeID ID; |
| 1200 | ID.AddInteger((uint64_t)Integer); |
| 1201 | void *Where; |
| 1202 | DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where); |
| 1203 | if (!Value) { |
| 1204 | Value = new DIEInteger(Integer); |
| 1205 | ValuesSet.InsertNode(Value, Where); |
| 1206 | Values.push_back(Value); |
| 1207 | } else { |
| 1208 | Value->IncUsage(); |
| 1209 | } |
| 1210 | |
| 1211 | Die->AddValue(Attribute, Form, Value); |
| 1212 | } |
| 1213 | |
| 1214 | /// AddString - Add a std::string attribute data and value. |
| 1215 | /// |
| 1216 | void AddString(DIE *Die, unsigned Attribute, unsigned Form, |
| 1217 | const std::string &String) { |
| 1218 | FoldingSetNodeID ID; |
| 1219 | ID.AddString(String); |
| 1220 | void *Where; |
| 1221 | DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where); |
| 1222 | if (!Value) { |
| 1223 | Value = new DIEString(String); |
| 1224 | ValuesSet.InsertNode(Value, Where); |
| 1225 | Values.push_back(Value); |
| 1226 | } else { |
| 1227 | Value->IncUsage(); |
| 1228 | } |
| 1229 | |
| 1230 | Die->AddValue(Attribute, Form, Value); |
| 1231 | } |
| 1232 | |
| 1233 | /// AddLabel - Add a Dwarf label attribute data and value. |
| 1234 | /// |
| 1235 | void AddLabel(DIE *Die, unsigned Attribute, unsigned Form, |
| 1236 | const DWLabel &Label) { |
| 1237 | FoldingSetNodeID ID; |
| 1238 | Label.Profile(ID); |
| 1239 | void *Where; |
| 1240 | DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where); |
| 1241 | if (!Value) { |
| 1242 | Value = new DIEDwarfLabel(Label); |
| 1243 | ValuesSet.InsertNode(Value, Where); |
| 1244 | Values.push_back(Value); |
| 1245 | } else { |
| 1246 | Value->IncUsage(); |
| 1247 | } |
| 1248 | |
| 1249 | Die->AddValue(Attribute, Form, Value); |
| 1250 | } |
| 1251 | |
| 1252 | /// AddObjectLabel - Add an non-Dwarf label attribute data and value. |
| 1253 | /// |
| 1254 | void AddObjectLabel(DIE *Die, unsigned Attribute, unsigned Form, |
| 1255 | const std::string &Label) { |
| 1256 | FoldingSetNodeID ID; |
| 1257 | ID.AddString(Label); |
| 1258 | void *Where; |
| 1259 | DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where); |
| 1260 | if (!Value) { |
| 1261 | Value = new DIEObjectLabel(Label); |
| 1262 | ValuesSet.InsertNode(Value, Where); |
| 1263 | Values.push_back(Value); |
| 1264 | } else { |
| 1265 | Value->IncUsage(); |
| 1266 | } |
| 1267 | |
| 1268 | Die->AddValue(Attribute, Form, Value); |
| 1269 | } |
| 1270 | |
| 1271 | /// AddDelta - Add a label delta attribute data and value. |
| 1272 | /// |
| 1273 | void AddDelta(DIE *Die, unsigned Attribute, unsigned Form, |
| 1274 | const DWLabel &Hi, const DWLabel &Lo) { |
| 1275 | FoldingSetNodeID ID; |
| 1276 | Hi.Profile(ID); |
| 1277 | Lo.Profile(ID); |
| 1278 | void *Where; |
| 1279 | DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where); |
| 1280 | if (!Value) { |
| 1281 | Value = new DIEDelta(Hi, Lo); |
| 1282 | ValuesSet.InsertNode(Value, Where); |
| 1283 | Values.push_back(Value); |
| 1284 | } else { |
| 1285 | Value->IncUsage(); |
| 1286 | } |
| 1287 | |
| 1288 | Die->AddValue(Attribute, Form, Value); |
| 1289 | } |
| 1290 | |
| 1291 | /// AddDIEntry - Add a DIE attribute data and value. |
| 1292 | /// |
| 1293 | void AddDIEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry) { |
| 1294 | Die->AddValue(Attribute, Form, NewDIEntry(Entry)); |
| 1295 | } |
| 1296 | |
| 1297 | /// AddBlock - Add block data. |
| 1298 | /// |
| 1299 | void AddBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block) { |
| 1300 | Block->ComputeSize(*this); |
| 1301 | FoldingSetNodeID ID; |
| 1302 | Block->Profile(ID); |
| 1303 | void *Where; |
| 1304 | DIEValue *Value = ValuesSet.FindNodeOrInsertPos(ID, Where); |
| 1305 | if (!Value) { |
| 1306 | Value = Block; |
| 1307 | ValuesSet.InsertNode(Value, Where); |
| 1308 | Values.push_back(Value); |
| 1309 | } else { |
| 1310 | Value->IncUsage(); |
| 1311 | delete Block; |
| 1312 | } |
| 1313 | |
| 1314 | Die->AddValue(Attribute, Block->BestForm(), Value); |
| 1315 | } |
| 1316 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1317 | private: |
| 1318 | |
| 1319 | /// AddSourceLine - Add location information to specified debug information |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 1320 | /// entry. |
| 1321 | void AddSourceLine(DIE *Die, CompileUnitDesc *File, unsigned Line) { |
| 1322 | if (File && Line) { |
| 1323 | CompileUnit *FileUnit = FindCompileUnit(File); |
| 1324 | unsigned FileID = FileUnit->getID(); |
| 1325 | AddUInt(Die, DW_AT_decl_file, 0, FileID); |
| 1326 | AddUInt(Die, DW_AT_decl_line, 0, Line); |
| 1327 | } |
| 1328 | } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1329 | |
| 1330 | /// AddAddress - Add an address attribute to a die based on the location |
| 1331 | /// provided. |
| 1332 | void AddAddress(DIE *Die, unsigned Attribute, |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 1333 | const MachineLocation &Location) { |
| 1334 | unsigned Reg = RI->getDwarfRegNum(Location.getRegister()); |
| 1335 | DIEBlock *Block = new DIEBlock(); |
| 1336 | |
| 1337 | if (Location.isRegister()) { |
| 1338 | if (Reg < 32) { |
| 1339 | AddUInt(Block, 0, DW_FORM_data1, DW_OP_reg0 + Reg); |
| 1340 | } else { |
| 1341 | AddUInt(Block, 0, DW_FORM_data1, DW_OP_regx); |
| 1342 | AddUInt(Block, 0, DW_FORM_udata, Reg); |
| 1343 | } |
| 1344 | } else { |
| 1345 | if (Reg < 32) { |
| 1346 | AddUInt(Block, 0, DW_FORM_data1, DW_OP_breg0 + Reg); |
| 1347 | } else { |
| 1348 | AddUInt(Block, 0, DW_FORM_data1, DW_OP_bregx); |
| 1349 | AddUInt(Block, 0, DW_FORM_udata, Reg); |
| 1350 | } |
| 1351 | AddUInt(Block, 0, DW_FORM_sdata, Location.getOffset()); |
| 1352 | } |
| 1353 | |
| 1354 | AddBlock(Die, Attribute, 0, Block); |
| 1355 | } |
| 1356 | |
| 1357 | /// AddBasicType - Add a new basic type attribute to the specified entity. |
| 1358 | /// |
| 1359 | void AddBasicType(DIE *Entity, CompileUnit *Unit, |
| 1360 | const std::string &Name, |
| 1361 | unsigned Encoding, unsigned Size) { |
| 1362 | DIE *Die = ConstructBasicType(Unit, Name, Encoding, Size); |
| 1363 | AddDIEntry(Entity, DW_AT_type, DW_FORM_ref4, Die); |
| 1364 | } |
| 1365 | |
| 1366 | /// ConstructBasicType - Construct a new basic type. |
| 1367 | /// |
| 1368 | DIE *ConstructBasicType(CompileUnit *Unit, |
| 1369 | const std::string &Name, |
| 1370 | unsigned Encoding, unsigned Size) { |
| 1371 | DIE Buffer(DW_TAG_base_type); |
| 1372 | AddUInt(&Buffer, DW_AT_byte_size, 0, Size); |
| 1373 | AddUInt(&Buffer, DW_AT_encoding, DW_FORM_data1, Encoding); |
| 1374 | if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name); |
| 1375 | return Unit->AddDie(Buffer); |
| 1376 | } |
| 1377 | |
| 1378 | /// AddPointerType - Add a new pointer type attribute to the specified entity. |
| 1379 | /// |
| 1380 | void AddPointerType(DIE *Entity, CompileUnit *Unit, const std::string &Name) { |
| 1381 | DIE *Die = ConstructPointerType(Unit, Name); |
| 1382 | AddDIEntry(Entity, DW_AT_type, DW_FORM_ref4, Die); |
| 1383 | } |
| 1384 | |
| 1385 | /// ConstructPointerType - Construct a new pointer type. |
| 1386 | /// |
| 1387 | DIE *ConstructPointerType(CompileUnit *Unit, const std::string &Name) { |
| 1388 | DIE Buffer(DW_TAG_pointer_type); |
| 1389 | AddUInt(&Buffer, DW_AT_byte_size, 0, TAI->getAddressSize()); |
| 1390 | if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name); |
| 1391 | return Unit->AddDie(Buffer); |
| 1392 | } |
| 1393 | |
| 1394 | /// AddType - Add a new type attribute to the specified entity. |
| 1395 | /// |
| 1396 | void AddType(DIE *Entity, TypeDesc *TyDesc, CompileUnit *Unit) { |
| 1397 | if (!TyDesc) { |
| 1398 | AddBasicType(Entity, Unit, "", DW_ATE_signed, 4); |
| 1399 | } else { |
| 1400 | // Check for pre-existence. |
| 1401 | DIEntry *&Slot = Unit->getDIEntrySlotFor(TyDesc); |
| 1402 | |
| 1403 | // If it exists then use the existing value. |
| 1404 | if (Slot) { |
| 1405 | Slot->IncUsage(); |
| 1406 | Entity->AddValue(DW_AT_type, DW_FORM_ref4, Slot); |
| 1407 | return; |
| 1408 | } |
| 1409 | |
| 1410 | if (SubprogramDesc *SubprogramTy = dyn_cast<SubprogramDesc>(TyDesc)) { |
| 1411 | // FIXME - Not sure why programs and variables are coming through here. |
| 1412 | // Short cut for handling subprogram types (not really a TyDesc.) |
| 1413 | AddPointerType(Entity, Unit, SubprogramTy->getName()); |
| 1414 | } else if (GlobalVariableDesc *GlobalTy = |
| 1415 | dyn_cast<GlobalVariableDesc>(TyDesc)) { |
| 1416 | // FIXME - Not sure why programs and variables are coming through here. |
| 1417 | // Short cut for handling global variable types (not really a TyDesc.) |
| 1418 | AddPointerType(Entity, Unit, GlobalTy->getName()); |
| 1419 | } else { |
| 1420 | // Set up proxy. |
| 1421 | Slot = NewDIEntry(); |
| 1422 | |
| 1423 | // Construct type. |
| 1424 | DIE Buffer(DW_TAG_base_type); |
| 1425 | ConstructType(Buffer, TyDesc, Unit); |
| 1426 | |
| 1427 | // Add debug information entry to entity and unit. |
| 1428 | DIE *Die = Unit->AddDie(Buffer); |
| 1429 | SetDIEntry(Slot, Die); |
| 1430 | Entity->AddValue(DW_AT_type, DW_FORM_ref4, Slot); |
| 1431 | } |
| 1432 | } |
| 1433 | } |
| 1434 | |
| 1435 | /// ConstructType - Adds all the required attributes to the type. |
| 1436 | /// |
| 1437 | void ConstructType(DIE &Buffer, TypeDesc *TyDesc, CompileUnit *Unit) { |
| 1438 | // Get core information. |
| 1439 | const std::string &Name = TyDesc->getName(); |
| 1440 | uint64_t Size = TyDesc->getSize() >> 3; |
| 1441 | |
| 1442 | if (BasicTypeDesc *BasicTy = dyn_cast<BasicTypeDesc>(TyDesc)) { |
| 1443 | // Fundamental types like int, float, bool |
| 1444 | Buffer.setTag(DW_TAG_base_type); |
| 1445 | AddUInt(&Buffer, DW_AT_encoding, DW_FORM_data1, BasicTy->getEncoding()); |
| 1446 | } else if (DerivedTypeDesc *DerivedTy = dyn_cast<DerivedTypeDesc>(TyDesc)) { |
| 1447 | // Pointers, tyepdefs et al. |
| 1448 | Buffer.setTag(DerivedTy->getTag()); |
| 1449 | // Map to main type, void will not have a type. |
| 1450 | if (TypeDesc *FromTy = DerivedTy->getFromType()) |
| 1451 | AddType(&Buffer, FromTy, Unit); |
| 1452 | } else if (CompositeTypeDesc *CompTy = dyn_cast<CompositeTypeDesc>(TyDesc)){ |
| 1453 | // Fetch tag. |
| 1454 | unsigned Tag = CompTy->getTag(); |
| 1455 | |
| 1456 | // Set tag accordingly. |
| 1457 | if (Tag == DW_TAG_vector_type) |
| 1458 | Buffer.setTag(DW_TAG_array_type); |
| 1459 | else |
| 1460 | Buffer.setTag(Tag); |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1461 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 1462 | std::vector<DebugInfoDesc *> &Elements = CompTy->getElements(); |
| 1463 | |
| 1464 | switch (Tag) { |
| 1465 | case DW_TAG_vector_type: |
| 1466 | AddUInt(&Buffer, DW_AT_GNU_vector, DW_FORM_flag, 1); |
| 1467 | // Fall thru |
| 1468 | case DW_TAG_array_type: { |
| 1469 | // Add element type. |
| 1470 | if (TypeDesc *FromTy = CompTy->getFromType()) |
| 1471 | AddType(&Buffer, FromTy, Unit); |
| 1472 | |
| 1473 | // Don't emit size attribute. |
| 1474 | Size = 0; |
| 1475 | |
| 1476 | // Construct an anonymous type for index type. |
| 1477 | DIE *IndexTy = ConstructBasicType(Unit, "", DW_ATE_signed, 4); |
| 1478 | |
| 1479 | // Add subranges to array type. |
| 1480 | for(unsigned i = 0, N = Elements.size(); i < N; ++i) { |
| 1481 | SubrangeDesc *SRD = cast<SubrangeDesc>(Elements[i]); |
| 1482 | int64_t Lo = SRD->getLo(); |
| 1483 | int64_t Hi = SRD->getHi(); |
| 1484 | DIE *Subrange = new DIE(DW_TAG_subrange_type); |
| 1485 | |
| 1486 | // If a range is available. |
| 1487 | if (Lo != Hi) { |
| 1488 | AddDIEntry(Subrange, DW_AT_type, DW_FORM_ref4, IndexTy); |
| 1489 | // Only add low if non-zero. |
| 1490 | if (Lo) AddSInt(Subrange, DW_AT_lower_bound, 0, Lo); |
| 1491 | AddSInt(Subrange, DW_AT_upper_bound, 0, Hi); |
| 1492 | } |
| 1493 | |
| 1494 | Buffer.AddChild(Subrange); |
| 1495 | } |
| 1496 | break; |
| 1497 | } |
| 1498 | case DW_TAG_structure_type: |
| 1499 | case DW_TAG_union_type: { |
| 1500 | // Add elements to structure type. |
| 1501 | for(unsigned i = 0, N = Elements.size(); i < N; ++i) { |
| 1502 | DebugInfoDesc *Element = Elements[i]; |
| 1503 | |
| 1504 | if (DerivedTypeDesc *MemberDesc = dyn_cast<DerivedTypeDesc>(Element)){ |
| 1505 | // Add field or base class. |
| 1506 | |
| 1507 | unsigned Tag = MemberDesc->getTag(); |
| 1508 | |
| 1509 | // Extract the basic information. |
| 1510 | const std::string &Name = MemberDesc->getName(); |
| 1511 | TypeDesc *MemTy = MemberDesc->getFromType(); |
| 1512 | uint64_t Size = MemberDesc->getSize(); |
| 1513 | uint64_t Align = MemberDesc->getAlign(); |
| 1514 | uint64_t Offset = MemberDesc->getOffset(); |
| 1515 | |
| 1516 | // Construct member debug information entry. |
| 1517 | DIE *Member = new DIE(Tag); |
| 1518 | |
| 1519 | // Add name if not "". |
| 1520 | if (!Name.empty()) |
| 1521 | AddString(Member, DW_AT_name, DW_FORM_string, Name); |
| 1522 | // Add location if available. |
| 1523 | AddSourceLine(Member, MemberDesc->getFile(), MemberDesc->getLine()); |
| 1524 | |
| 1525 | // Most of the time the field info is the same as the members. |
| 1526 | uint64_t FieldSize = Size; |
| 1527 | uint64_t FieldAlign = Align; |
| 1528 | uint64_t FieldOffset = Offset; |
| 1529 | |
| 1530 | if (TypeDesc *FromTy = MemberDesc->getFromType()) { |
| 1531 | AddType(Member, FromTy, Unit); |
| 1532 | FieldSize = FromTy->getSize(); |
| 1533 | FieldAlign = FromTy->getSize(); |
| 1534 | } |
| 1535 | |
| 1536 | // Unless we have a bit field. |
| 1537 | if (Tag == DW_TAG_member && FieldSize != Size) { |
| 1538 | // Construct the alignment mask. |
| 1539 | uint64_t AlignMask = ~(FieldAlign - 1); |
| 1540 | // Determine the high bit + 1 of the declared size. |
| 1541 | uint64_t HiMark = (Offset + FieldSize) & AlignMask; |
| 1542 | // Work backwards to determine the base offset of the field. |
| 1543 | FieldOffset = HiMark - FieldSize; |
| 1544 | // Now normalize offset to the field. |
| 1545 | Offset -= FieldOffset; |
| 1546 | |
| 1547 | // Maybe we need to work from the other end. |
| 1548 | if (TD->isLittleEndian()) Offset = FieldSize - (Offset + Size); |
| 1549 | |
| 1550 | // Add size and offset. |
| 1551 | AddUInt(Member, DW_AT_byte_size, 0, FieldSize >> 3); |
| 1552 | AddUInt(Member, DW_AT_bit_size, 0, Size); |
| 1553 | AddUInt(Member, DW_AT_bit_offset, 0, Offset); |
| 1554 | } |
| 1555 | |
| 1556 | // Add computation for offset. |
| 1557 | DIEBlock *Block = new DIEBlock(); |
| 1558 | AddUInt(Block, 0, DW_FORM_data1, DW_OP_plus_uconst); |
| 1559 | AddUInt(Block, 0, DW_FORM_udata, FieldOffset >> 3); |
| 1560 | AddBlock(Member, DW_AT_data_member_location, 0, Block); |
| 1561 | |
| 1562 | // Add accessibility (public default unless is base class. |
| 1563 | if (MemberDesc->isProtected()) { |
| 1564 | AddUInt(Member, DW_AT_accessibility, 0, DW_ACCESS_protected); |
| 1565 | } else if (MemberDesc->isPrivate()) { |
| 1566 | AddUInt(Member, DW_AT_accessibility, 0, DW_ACCESS_private); |
| 1567 | } else if (Tag == DW_TAG_inheritance) { |
| 1568 | AddUInt(Member, DW_AT_accessibility, 0, DW_ACCESS_public); |
| 1569 | } |
| 1570 | |
| 1571 | Buffer.AddChild(Member); |
| 1572 | } else if (GlobalVariableDesc *StaticDesc = |
| 1573 | dyn_cast<GlobalVariableDesc>(Element)) { |
| 1574 | // Add static member. |
| 1575 | |
| 1576 | // Construct member debug information entry. |
| 1577 | DIE *Static = new DIE(DW_TAG_variable); |
| 1578 | |
| 1579 | // Add name and mangled name. |
| 1580 | const std::string &Name = StaticDesc->getDisplayName(); |
| 1581 | const std::string &MangledName = StaticDesc->getName(); |
| 1582 | AddString(Static, DW_AT_name, DW_FORM_string, Name); |
| 1583 | AddString(Static, DW_AT_MIPS_linkage_name, DW_FORM_string, |
| 1584 | MangledName); |
| 1585 | |
| 1586 | // Add location. |
| 1587 | AddSourceLine(Static, StaticDesc->getFile(), StaticDesc->getLine()); |
| 1588 | |
| 1589 | // Add type. |
| 1590 | if (TypeDesc *StaticTy = StaticDesc->getType()) |
| 1591 | AddType(Static, StaticTy, Unit); |
| 1592 | |
| 1593 | // Add flags. |
| 1594 | AddUInt(Static, DW_AT_external, DW_FORM_flag, 1); |
| 1595 | AddUInt(Static, DW_AT_declaration, DW_FORM_flag, 1); |
| 1596 | |
| 1597 | Buffer.AddChild(Static); |
| 1598 | } else if (SubprogramDesc *MethodDesc = |
| 1599 | dyn_cast<SubprogramDesc>(Element)) { |
| 1600 | // Add member function. |
| 1601 | |
| 1602 | // Construct member debug information entry. |
| 1603 | DIE *Method = new DIE(DW_TAG_subprogram); |
| 1604 | |
| 1605 | // Add name and mangled name. |
| 1606 | const std::string &Name = MethodDesc->getDisplayName(); |
| 1607 | const std::string &MangledName = MethodDesc->getName(); |
| 1608 | bool IsCTor = false; |
| 1609 | |
| 1610 | if (Name.empty()) { |
| 1611 | AddString(Method, DW_AT_name, DW_FORM_string, MangledName); |
| 1612 | IsCTor = TyDesc->getName() == MangledName; |
| 1613 | } else { |
| 1614 | AddString(Method, DW_AT_name, DW_FORM_string, Name); |
| 1615 | AddString(Method, DW_AT_MIPS_linkage_name, DW_FORM_string, |
| 1616 | MangledName); |
| 1617 | } |
| 1618 | |
| 1619 | // Add location. |
| 1620 | AddSourceLine(Method, MethodDesc->getFile(), MethodDesc->getLine()); |
| 1621 | |
| 1622 | // Add type. |
| 1623 | if (CompositeTypeDesc *MethodTy = |
| 1624 | dyn_cast_or_null<CompositeTypeDesc>(MethodDesc->getType())) { |
| 1625 | // Get argument information. |
| 1626 | std::vector<DebugInfoDesc *> &Args = MethodTy->getElements(); |
| 1627 | |
| 1628 | // If not a ctor. |
| 1629 | if (!IsCTor) { |
| 1630 | // Add return type. |
| 1631 | AddType(Method, dyn_cast<TypeDesc>(Args[0]), Unit); |
| 1632 | } |
| 1633 | |
| 1634 | // Add arguments. |
| 1635 | for(unsigned i = 1, N = Args.size(); i < N; ++i) { |
| 1636 | DIE *Arg = new DIE(DW_TAG_formal_parameter); |
| 1637 | AddType(Arg, cast<TypeDesc>(Args[i]), Unit); |
| 1638 | AddUInt(Arg, DW_AT_artificial, DW_FORM_flag, 1); |
| 1639 | Method->AddChild(Arg); |
| 1640 | } |
| 1641 | } |
| 1642 | |
| 1643 | // Add flags. |
| 1644 | AddUInt(Method, DW_AT_external, DW_FORM_flag, 1); |
| 1645 | AddUInt(Method, DW_AT_declaration, DW_FORM_flag, 1); |
| 1646 | |
| 1647 | Buffer.AddChild(Method); |
| 1648 | } |
| 1649 | } |
| 1650 | break; |
| 1651 | } |
| 1652 | case DW_TAG_enumeration_type: { |
| 1653 | // Add enumerators to enumeration type. |
| 1654 | for(unsigned i = 0, N = Elements.size(); i < N; ++i) { |
| 1655 | EnumeratorDesc *ED = cast<EnumeratorDesc>(Elements[i]); |
| 1656 | const std::string &Name = ED->getName(); |
| 1657 | int64_t Value = ED->getValue(); |
| 1658 | DIE *Enumerator = new DIE(DW_TAG_enumerator); |
| 1659 | AddString(Enumerator, DW_AT_name, DW_FORM_string, Name); |
| 1660 | AddSInt(Enumerator, DW_AT_const_value, DW_FORM_sdata, Value); |
| 1661 | Buffer.AddChild(Enumerator); |
| 1662 | } |
| 1663 | |
| 1664 | break; |
| 1665 | } |
| 1666 | case DW_TAG_subroutine_type: { |
| 1667 | // Add prototype flag. |
| 1668 | AddUInt(&Buffer, DW_AT_prototyped, DW_FORM_flag, 1); |
| 1669 | // Add return type. |
| 1670 | AddType(&Buffer, dyn_cast<TypeDesc>(Elements[0]), Unit); |
| 1671 | |
| 1672 | // Add arguments. |
| 1673 | for(unsigned i = 1, N = Elements.size(); i < N; ++i) { |
| 1674 | DIE *Arg = new DIE(DW_TAG_formal_parameter); |
| 1675 | AddType(Arg, cast<TypeDesc>(Elements[i]), Unit); |
| 1676 | Buffer.AddChild(Arg); |
| 1677 | } |
| 1678 | |
| 1679 | break; |
| 1680 | } |
| 1681 | default: break; |
| 1682 | } |
| 1683 | } |
| 1684 | |
| 1685 | // Add size if non-zero (derived types don't have a size.) |
| 1686 | if (Size) AddUInt(&Buffer, DW_AT_byte_size, 0, Size); |
| 1687 | // Add name if not anonymous or intermediate type. |
| 1688 | if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name); |
| 1689 | // Add source line info if available. |
| 1690 | AddSourceLine(&Buffer, TyDesc->getFile(), TyDesc->getLine()); |
| 1691 | } |
| 1692 | |
| 1693 | /// NewCompileUnit - Create new compile unit and it's debug information entry. |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1694 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 1695 | CompileUnit *NewCompileUnit(CompileUnitDesc *UnitDesc, unsigned ID) { |
| 1696 | // Construct debug information entry. |
| 1697 | DIE *Die = new DIE(DW_TAG_compile_unit); |
| 1698 | AddDelta(Die, DW_AT_stmt_list, DW_FORM_data4, DWLabel("section_line", 0), |
| 1699 | DWLabel("section_line", 0)); |
| 1700 | AddString(Die, DW_AT_producer, DW_FORM_string, UnitDesc->getProducer()); |
| 1701 | AddUInt (Die, DW_AT_language, DW_FORM_data1, UnitDesc->getLanguage()); |
| 1702 | AddString(Die, DW_AT_name, DW_FORM_string, UnitDesc->getFileName()); |
| 1703 | AddString(Die, DW_AT_comp_dir, DW_FORM_string, UnitDesc->getDirectory()); |
| 1704 | |
| 1705 | // Construct compile unit. |
| 1706 | CompileUnit *Unit = new CompileUnit(UnitDesc, ID, Die); |
| 1707 | |
| 1708 | // Add Unit to compile unit map. |
| 1709 | DescToUnitMap[UnitDesc] = Unit; |
| 1710 | |
| 1711 | return Unit; |
| 1712 | } |
| 1713 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1714 | /// FindCompileUnit - Get the compile unit for the given descriptor. |
| 1715 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 1716 | CompileUnit *FindCompileUnit(CompileUnitDesc *UnitDesc) { |
| 1717 | #if 1 |
| 1718 | // FIXME - Using only one compile unit. Needs to me fixed at the FE. |
| 1719 | CompileUnit *Unit = CompileUnits[0]; |
| 1720 | #else |
| 1721 | CompileUnit *Unit = DescToUnitMap[UnitDesc]; |
| 1722 | #endif |
| 1723 | assert(Unit && "Missing compile unit."); |
| 1724 | return Unit; |
| 1725 | } |
| 1726 | |
| 1727 | /// NewGlobalVariable - Add a new global variable DIE. |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1728 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 1729 | DIE *NewGlobalVariable(GlobalVariableDesc *GVD) { |
| 1730 | // Get the compile unit context. |
| 1731 | CompileUnitDesc *UnitDesc = |
| 1732 | static_cast<CompileUnitDesc *>(GVD->getContext()); |
| 1733 | CompileUnit *Unit = FindCompileUnit(UnitDesc); |
| 1734 | |
| 1735 | // Check for pre-existence. |
| 1736 | DIE *&Slot = Unit->getDieMapSlotFor(GVD); |
| 1737 | if (Slot) return Slot; |
| 1738 | |
| 1739 | // Get the global variable itself. |
| 1740 | GlobalVariable *GV = GVD->getGlobalVariable(); |
| 1741 | |
| 1742 | const std::string &Name = GVD->hasMangledName() ? GVD->getDisplayName() |
| 1743 | : GVD->getName(); |
| 1744 | const std::string &MangledName = GVD->hasMangledName() ? GVD->getName() |
| 1745 | : ""; |
| 1746 | // Create the global's variable DIE. |
| 1747 | DIE *VariableDie = new DIE(DW_TAG_variable); |
| 1748 | AddString(VariableDie, DW_AT_name, DW_FORM_string, Name); |
| 1749 | if (!MangledName.empty()) { |
| 1750 | AddString(VariableDie, DW_AT_MIPS_linkage_name, DW_FORM_string, |
| 1751 | MangledName); |
| 1752 | } |
| 1753 | AddType(VariableDie, GVD->getType(), Unit); |
| 1754 | AddUInt(VariableDie, DW_AT_external, DW_FORM_flag, 1); |
| 1755 | |
| 1756 | // Add source line info if available. |
| 1757 | AddSourceLine(VariableDie, UnitDesc, GVD->getLine()); |
| 1758 | |
| 1759 | // Work up linkage name. |
| 1760 | const std::string LinkageName = Asm->getGlobalLinkName(GV); |
| 1761 | |
| 1762 | // Add address. |
| 1763 | DIEBlock *Block = new DIEBlock(); |
| 1764 | AddUInt(Block, 0, DW_FORM_data1, DW_OP_addr); |
| 1765 | AddObjectLabel(Block, 0, DW_FORM_udata, LinkageName); |
| 1766 | AddBlock(VariableDie, DW_AT_location, 0, Block); |
| 1767 | |
| 1768 | // Add to map. |
| 1769 | Slot = VariableDie; |
| 1770 | |
| 1771 | // Add to context owner. |
| 1772 | Unit->getDie()->AddChild(VariableDie); |
| 1773 | |
| 1774 | // Expose as global. |
| 1775 | // FIXME - need to check external flag. |
| 1776 | Unit->AddGlobal(Name, VariableDie); |
| 1777 | |
| 1778 | return VariableDie; |
| 1779 | } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1780 | |
| 1781 | /// NewSubprogram - Add a new subprogram DIE. |
| 1782 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 1783 | DIE *NewSubprogram(SubprogramDesc *SPD) { |
| 1784 | // Get the compile unit context. |
| 1785 | CompileUnitDesc *UnitDesc = |
| 1786 | static_cast<CompileUnitDesc *>(SPD->getContext()); |
| 1787 | CompileUnit *Unit = FindCompileUnit(UnitDesc); |
| 1788 | |
| 1789 | // Check for pre-existence. |
| 1790 | DIE *&Slot = Unit->getDieMapSlotFor(SPD); |
| 1791 | if (Slot) return Slot; |
| 1792 | |
| 1793 | // Gather the details (simplify add attribute code.) |
| 1794 | const std::string &Name = SPD->hasMangledName() ? SPD->getDisplayName() |
| 1795 | : SPD->getName(); |
| 1796 | const std::string &MangledName = SPD->hasMangledName() ? SPD->getName() |
| 1797 | : ""; |
| 1798 | unsigned IsExternal = SPD->isStatic() ? 0 : 1; |
| 1799 | |
| 1800 | DIE *SubprogramDie = new DIE(DW_TAG_subprogram); |
| 1801 | AddString(SubprogramDie, DW_AT_name, DW_FORM_string, Name); |
| 1802 | if (!MangledName.empty()) { |
| 1803 | AddString(SubprogramDie, DW_AT_MIPS_linkage_name, DW_FORM_string, |
| 1804 | MangledName); |
| 1805 | } |
| 1806 | if (SPD->getType()) AddType(SubprogramDie, SPD->getType(), Unit); |
| 1807 | AddUInt(SubprogramDie, DW_AT_external, DW_FORM_flag, IsExternal); |
| 1808 | AddUInt(SubprogramDie, DW_AT_prototyped, DW_FORM_flag, 1); |
| 1809 | |
| 1810 | // Add source line info if available. |
| 1811 | AddSourceLine(SubprogramDie, UnitDesc, SPD->getLine()); |
| 1812 | |
| 1813 | // Add to map. |
| 1814 | Slot = SubprogramDie; |
| 1815 | |
| 1816 | // Add to context owner. |
| 1817 | Unit->getDie()->AddChild(SubprogramDie); |
| 1818 | |
| 1819 | // Expose as global. |
| 1820 | Unit->AddGlobal(Name, SubprogramDie); |
| 1821 | |
| 1822 | return SubprogramDie; |
| 1823 | } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1824 | |
| 1825 | /// NewScopeVariable - Create a new scope variable. |
| 1826 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 1827 | DIE *NewScopeVariable(DebugVariable *DV, CompileUnit *Unit) { |
| 1828 | // Get the descriptor. |
| 1829 | VariableDesc *VD = DV->getDesc(); |
| 1830 | |
| 1831 | // Translate tag to proper Dwarf tag. The result variable is dropped for |
| 1832 | // now. |
| 1833 | unsigned Tag; |
| 1834 | switch (VD->getTag()) { |
| 1835 | case DW_TAG_return_variable: return NULL; |
| 1836 | case DW_TAG_arg_variable: Tag = DW_TAG_formal_parameter; break; |
| 1837 | case DW_TAG_auto_variable: // fall thru |
| 1838 | default: Tag = DW_TAG_variable; break; |
| 1839 | } |
| 1840 | |
| 1841 | // Define variable debug information entry. |
| 1842 | DIE *VariableDie = new DIE(Tag); |
| 1843 | AddString(VariableDie, DW_AT_name, DW_FORM_string, VD->getName()); |
| 1844 | |
| 1845 | // Add source line info if available. |
| 1846 | AddSourceLine(VariableDie, VD->getFile(), VD->getLine()); |
| 1847 | |
| 1848 | // Add variable type. |
| 1849 | AddType(VariableDie, VD->getType(), Unit); |
| 1850 | |
| 1851 | // Add variable address. |
| 1852 | MachineLocation Location; |
| 1853 | RI->getLocation(*MF, DV->getFrameIndex(), Location); |
| 1854 | AddAddress(VariableDie, DW_AT_location, Location); |
| 1855 | |
| 1856 | return VariableDie; |
| 1857 | } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1858 | |
| 1859 | /// ConstructScope - Construct the components of a scope. |
| 1860 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 1861 | void ConstructScope(DebugScope *ParentScope, |
| 1862 | DIE *ParentDie, CompileUnit *Unit) { |
| 1863 | // Add variables to scope. |
| 1864 | std::vector<DebugVariable *> &Variables = ParentScope->getVariables(); |
| 1865 | for (unsigned i = 0, N = Variables.size(); i < N; ++i) { |
| 1866 | DIE *VariableDie = NewScopeVariable(Variables[i], Unit); |
| 1867 | if (VariableDie) ParentDie->AddChild(VariableDie); |
| 1868 | } |
| 1869 | |
| 1870 | // Add nested scopes. |
| 1871 | std::vector<DebugScope *> &Scopes = ParentScope->getScopes(); |
| 1872 | for (unsigned j = 0, M = Scopes.size(); j < M; ++j) { |
| 1873 | // Define the Scope debug information entry. |
| 1874 | DebugScope *Scope = Scopes[j]; |
| 1875 | // FIXME - Ignore inlined functions for the time being. |
| 1876 | if (!Scope->getParent()) continue; |
| 1877 | |
| 1878 | unsigned StartID = Scope->getStartLabelID(); |
| 1879 | unsigned EndID = Scope->getEndLabelID(); |
| 1880 | |
| 1881 | // Throw out scope if block is discarded. |
| 1882 | if (StartID && !DebugInfo->isLabelValid(StartID)) continue; |
| 1883 | if (EndID && !DebugInfo->isLabelValid(EndID)) continue; |
| 1884 | |
| 1885 | DIE *ScopeDie = new DIE(DW_TAG_lexical_block); |
| 1886 | |
| 1887 | // Add the scope bounds. |
| 1888 | if (StartID) { |
| 1889 | AddLabel(ScopeDie, DW_AT_low_pc, DW_FORM_addr, |
| 1890 | DWLabel("loc", StartID)); |
| 1891 | } else { |
| 1892 | AddLabel(ScopeDie, DW_AT_low_pc, DW_FORM_addr, |
| 1893 | DWLabel("func_begin", SubprogramCount)); |
| 1894 | } |
| 1895 | if (EndID) { |
| 1896 | AddLabel(ScopeDie, DW_AT_high_pc, DW_FORM_addr, |
| 1897 | DWLabel("loc", EndID)); |
| 1898 | } else { |
| 1899 | AddLabel(ScopeDie, DW_AT_high_pc, DW_FORM_addr, |
| 1900 | DWLabel("func_end", SubprogramCount)); |
| 1901 | } |
| 1902 | |
| 1903 | // Add the scope contents. |
| 1904 | ConstructScope(Scope, ScopeDie, Unit); |
| 1905 | ParentDie->AddChild(ScopeDie); |
| 1906 | } |
| 1907 | } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1908 | |
| 1909 | /// ConstructRootScope - Construct the scope for the subprogram. |
| 1910 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 1911 | void ConstructRootScope(DebugScope *RootScope) { |
| 1912 | // Exit if there is no root scope. |
| 1913 | if (!RootScope) return; |
| 1914 | |
| 1915 | // Get the subprogram debug information entry. |
| 1916 | SubprogramDesc *SPD = cast<SubprogramDesc>(RootScope->getDesc()); |
| 1917 | |
| 1918 | // Get the compile unit context. |
| 1919 | CompileUnitDesc *UnitDesc = |
| 1920 | static_cast<CompileUnitDesc *>(SPD->getContext()); |
| 1921 | CompileUnit *Unit = FindCompileUnit(UnitDesc); |
| 1922 | |
| 1923 | // Get the subprogram die. |
| 1924 | DIE *SPDie = Unit->getDieMapSlotFor(SPD); |
| 1925 | assert(SPDie && "Missing subprogram descriptor"); |
| 1926 | |
| 1927 | // Add the function bounds. |
| 1928 | AddLabel(SPDie, DW_AT_low_pc, DW_FORM_addr, |
| 1929 | DWLabel("func_begin", SubprogramCount)); |
| 1930 | AddLabel(SPDie, DW_AT_high_pc, DW_FORM_addr, |
| 1931 | DWLabel("func_end", SubprogramCount)); |
| 1932 | MachineLocation Location(RI->getFrameRegister(*MF)); |
| 1933 | AddAddress(SPDie, DW_AT_frame_base, Location); |
| 1934 | |
| 1935 | ConstructScope(RootScope, SPDie, Unit); |
| 1936 | } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1937 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 1938 | /// EmitInitial - Emit initial Dwarf declarations. This is necessary for cc |
| 1939 | /// tools to recognize the object file contains Dwarf information. |
| 1940 | void EmitInitial() { |
| 1941 | // Check to see if we already emitted intial headers. |
| 1942 | if (didInitial) return; |
| 1943 | didInitial = true; |
| 1944 | |
| 1945 | // Dwarf sections base addresses. |
| 1946 | if (TAI->getDwarfRequiresFrameSection()) { |
| 1947 | Asm->SwitchToDataSection(TAI->getDwarfFrameSection()); |
| 1948 | EmitLabel("section_frame", 0); |
| 1949 | } |
| 1950 | Asm->SwitchToDataSection(TAI->getDwarfInfoSection()); |
| 1951 | EmitLabel("section_info", 0); |
| 1952 | Asm->SwitchToDataSection(TAI->getDwarfAbbrevSection()); |
| 1953 | EmitLabel("section_abbrev", 0); |
| 1954 | Asm->SwitchToDataSection(TAI->getDwarfARangesSection()); |
| 1955 | EmitLabel("section_aranges", 0); |
| 1956 | Asm->SwitchToDataSection(TAI->getDwarfMacInfoSection()); |
| 1957 | EmitLabel("section_macinfo", 0); |
| 1958 | Asm->SwitchToDataSection(TAI->getDwarfLineSection()); |
| 1959 | EmitLabel("section_line", 0); |
| 1960 | Asm->SwitchToDataSection(TAI->getDwarfLocSection()); |
| 1961 | EmitLabel("section_loc", 0); |
| 1962 | Asm->SwitchToDataSection(TAI->getDwarfPubNamesSection()); |
| 1963 | EmitLabel("section_pubnames", 0); |
| 1964 | Asm->SwitchToDataSection(TAI->getDwarfStrSection()); |
| 1965 | EmitLabel("section_str", 0); |
| 1966 | Asm->SwitchToDataSection(TAI->getDwarfRangesSection()); |
| 1967 | EmitLabel("section_ranges", 0); |
| 1968 | |
| 1969 | Asm->SwitchToTextSection(TAI->getTextSection()); |
| 1970 | EmitLabel("text_begin", 0); |
| 1971 | Asm->SwitchToDataSection(TAI->getDataSection()); |
| 1972 | EmitLabel("data_begin", 0); |
| 1973 | |
| 1974 | // Emit common frame information. |
| 1975 | EmitInitialDebugFrame(); |
| 1976 | } |
| 1977 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 1978 | /// EmitDIE - Recusively Emits a debug information entry. |
| 1979 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 1980 | void EmitDIE(DIE *Die) const { |
| 1981 | // Get the abbreviation for this DIE. |
| 1982 | unsigned AbbrevNumber = Die->getAbbrevNumber(); |
| 1983 | const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1]; |
| 1984 | |
| 1985 | O << "\n"; |
| 1986 | |
| 1987 | // Emit the code (index) for the abbreviation. |
| 1988 | EmitULEB128Bytes(AbbrevNumber); |
| 1989 | EOL(std::string("Abbrev [" + |
| 1990 | utostr(AbbrevNumber) + |
| 1991 | "] 0x" + utohexstr(Die->getOffset()) + |
| 1992 | ":0x" + utohexstr(Die->getSize()) + " " + |
| 1993 | TagString(Abbrev->getTag()))); |
| 1994 | |
| 1995 | const std::vector<DIEValue *> &Values = Die->getValues(); |
| 1996 | const std::vector<DIEAbbrevData> &AbbrevData = Abbrev->getData(); |
| 1997 | |
| 1998 | // Emit the DIE attribute values. |
| 1999 | for (unsigned i = 0, N = Values.size(); i < N; ++i) { |
| 2000 | unsigned Attr = AbbrevData[i].getAttribute(); |
| 2001 | unsigned Form = AbbrevData[i].getForm(); |
| 2002 | assert(Form && "Too many attributes for DIE (check abbreviation)"); |
| 2003 | |
| 2004 | switch (Attr) { |
| 2005 | case DW_AT_sibling: { |
| 2006 | EmitInt32(Die->SiblingOffset()); |
| 2007 | break; |
| 2008 | } |
| 2009 | default: { |
| 2010 | // Emit an attribute using the defined form. |
| 2011 | Values[i]->EmitValue(*this, Form); |
| 2012 | break; |
| 2013 | } |
| 2014 | } |
| 2015 | |
| 2016 | EOL(AttributeString(Attr)); |
| 2017 | } |
| 2018 | |
| 2019 | // Emit the DIE children if any. |
| 2020 | if (Abbrev->getChildrenFlag() == DW_CHILDREN_yes) { |
| 2021 | const std::vector<DIE *> &Children = Die->getChildren(); |
| 2022 | |
| 2023 | for (unsigned j = 0, M = Children.size(); j < M; ++j) { |
| 2024 | EmitDIE(Children[j]); |
| 2025 | } |
| 2026 | |
| 2027 | EmitInt8(0); EOL("End Of Children Mark"); |
| 2028 | } |
| 2029 | } |
| 2030 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2031 | /// SizeAndOffsetDie - Compute the size and offset of a DIE. |
| 2032 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2033 | unsigned SizeAndOffsetDie(DIE *Die, unsigned Offset, bool Last) { |
| 2034 | // Get the children. |
| 2035 | const std::vector<DIE *> &Children = Die->getChildren(); |
| 2036 | |
| 2037 | // If not last sibling and has children then add sibling offset attribute. |
| 2038 | if (!Last && !Children.empty()) Die->AddSiblingOffset(); |
| 2039 | |
| 2040 | // Record the abbreviation. |
| 2041 | AssignAbbrevNumber(Die->getAbbrev()); |
| 2042 | |
| 2043 | // Get the abbreviation for this DIE. |
| 2044 | unsigned AbbrevNumber = Die->getAbbrevNumber(); |
| 2045 | const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1]; |
| 2046 | |
| 2047 | // Set DIE offset |
| 2048 | Die->setOffset(Offset); |
| 2049 | |
| 2050 | // Start the size with the size of abbreviation code. |
| 2051 | Offset += SizeULEB128(AbbrevNumber); |
| 2052 | |
| 2053 | const std::vector<DIEValue *> &Values = Die->getValues(); |
| 2054 | const std::vector<DIEAbbrevData> &AbbrevData = Abbrev->getData(); |
| 2055 | |
| 2056 | // Size the DIE attribute values. |
| 2057 | for (unsigned i = 0, N = Values.size(); i < N; ++i) { |
| 2058 | // Size attribute value. |
| 2059 | Offset += Values[i]->SizeOf(*this, AbbrevData[i].getForm()); |
| 2060 | } |
| 2061 | |
| 2062 | // Size the DIE children if any. |
| 2063 | if (!Children.empty()) { |
| 2064 | assert(Abbrev->getChildrenFlag() == DW_CHILDREN_yes && |
| 2065 | "Children flag not set"); |
| 2066 | |
| 2067 | for (unsigned j = 0, M = Children.size(); j < M; ++j) { |
| 2068 | Offset = SizeAndOffsetDie(Children[j], Offset, (j + 1) == M); |
| 2069 | } |
| 2070 | |
| 2071 | // End of children marker. |
| 2072 | Offset += sizeof(int8_t); |
| 2073 | } |
| 2074 | |
| 2075 | Die->setSize(Offset - Die->getOffset()); |
| 2076 | return Offset; |
| 2077 | } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2078 | |
| 2079 | /// SizeAndOffsets - Compute the size and offset of all the DIEs. |
| 2080 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2081 | void SizeAndOffsets() { |
| 2082 | // Process each compile unit. |
| 2083 | for (unsigned i = 0, N = CompileUnits.size(); i < N; ++i) { |
| 2084 | CompileUnit *Unit = CompileUnits[i]; |
| 2085 | if (Unit->hasContent()) { |
| 2086 | // Compute size of compile unit header |
| 2087 | unsigned Offset = sizeof(int32_t) + // Length of Compilation Unit Info |
| 2088 | sizeof(int16_t) + // DWARF version number |
| 2089 | sizeof(int32_t) + // Offset Into Abbrev. Section |
| 2090 | sizeof(int8_t); // Pointer Size (in bytes) |
| 2091 | SizeAndOffsetDie(Unit->getDie(), Offset, (i + 1) == N); |
| 2092 | } |
| 2093 | } |
| 2094 | } |
| 2095 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2096 | /// EmitFrameMoves - Emit frame instructions to describe the layout of the |
| 2097 | /// frame. |
| 2098 | void EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID, |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2099 | std::vector<MachineMove *> &Moves) { |
| 2100 | for (unsigned i = 0, N = Moves.size(); i < N; ++i) { |
| 2101 | MachineMove *Move = Moves[i]; |
| 2102 | unsigned LabelID = Move->getLabelID(); |
| 2103 | |
| 2104 | // Throw out move if the label is invalid. |
| 2105 | if (LabelID && !DebugInfo->isLabelValid(LabelID)) continue; |
| 2106 | |
| 2107 | const MachineLocation &Dst = Move->getDestination(); |
| 2108 | const MachineLocation &Src = Move->getSource(); |
| 2109 | |
| 2110 | // Advance row if new location. |
| 2111 | if (BaseLabel && LabelID && BaseLabelID != LabelID) { |
| 2112 | EmitInt8(DW_CFA_advance_loc4); |
| 2113 | EOL("DW_CFA_advance_loc4"); |
| 2114 | EmitDifference("loc", LabelID, BaseLabel, BaseLabelID); |
| 2115 | EOL(""); |
| 2116 | |
| 2117 | BaseLabelID = LabelID; |
| 2118 | BaseLabel = "loc"; |
| 2119 | } |
| 2120 | |
| 2121 | int stackGrowth = |
| 2122 | Asm->TM.getFrameInfo()->getStackGrowthDirection() == |
| 2123 | TargetFrameInfo::StackGrowsUp ? |
| 2124 | TAI->getAddressSize() : -TAI->getAddressSize(); |
| 2125 | |
| 2126 | // If advancing cfa. |
| 2127 | if (Dst.isRegister() && Dst.getRegister() == MachineLocation::VirtualFP) { |
| 2128 | if (!Src.isRegister()) { |
| 2129 | if (Src.getRegister() == MachineLocation::VirtualFP) { |
| 2130 | EmitInt8(DW_CFA_def_cfa_offset); |
| 2131 | EOL("DW_CFA_def_cfa_offset"); |
| 2132 | } else { |
| 2133 | EmitInt8(DW_CFA_def_cfa); |
| 2134 | EOL("DW_CFA_def_cfa"); |
| 2135 | |
| 2136 | EmitULEB128Bytes(RI->getDwarfRegNum(Src.getRegister())); |
| 2137 | EOL("Register"); |
| 2138 | } |
| 2139 | |
| 2140 | int Offset = Src.getOffset() / stackGrowth; |
| 2141 | |
| 2142 | EmitULEB128Bytes(Offset); |
| 2143 | EOL("Offset"); |
| 2144 | } else { |
| 2145 | assert(0 && "Machine move no supported yet."); |
| 2146 | } |
| 2147 | } else { |
| 2148 | unsigned Reg = RI->getDwarfRegNum(Src.getRegister()); |
| 2149 | int Offset = Dst.getOffset() / stackGrowth; |
| 2150 | |
| 2151 | if (Offset < 0) { |
| 2152 | EmitInt8(DW_CFA_offset_extended_sf); |
| 2153 | EOL("DW_CFA_offset_extended_sf"); |
| 2154 | EmitULEB128Bytes(Reg); |
| 2155 | EOL("Reg"); |
| 2156 | EmitSLEB128Bytes(Offset); |
| 2157 | EOL("Offset"); |
| 2158 | } else if (Reg < 64) { |
| 2159 | EmitInt8(DW_CFA_offset + Reg); |
| 2160 | EOL("DW_CFA_offset + Reg"); |
| 2161 | EmitULEB128Bytes(Offset); |
| 2162 | EOL("Offset"); |
| 2163 | } else { |
| 2164 | EmitInt8(DW_CFA_offset_extended); |
| 2165 | EOL("DW_CFA_offset_extended"); |
| 2166 | EmitULEB128Bytes(Reg); |
| 2167 | EOL("Reg"); |
| 2168 | EmitULEB128Bytes(Offset); |
| 2169 | EOL("Offset"); |
| 2170 | } |
| 2171 | } |
| 2172 | } |
| 2173 | } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2174 | |
| 2175 | /// EmitDebugInfo - Emit the debug info section. |
| 2176 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2177 | void EmitDebugInfo() const { |
| 2178 | // Start debug info section. |
| 2179 | Asm->SwitchToDataSection(TAI->getDwarfInfoSection()); |
| 2180 | |
| 2181 | // Process each compile unit. |
| 2182 | for (unsigned i = 0, N = CompileUnits.size(); i < N; ++i) { |
| 2183 | CompileUnit *Unit = CompileUnits[i]; |
| 2184 | |
| 2185 | if (Unit->hasContent()) { |
| 2186 | DIE *Die = Unit->getDie(); |
| 2187 | // Emit the compile units header. |
| 2188 | EmitLabel("info_begin", Unit->getID()); |
| 2189 | // Emit size of content not including length itself |
| 2190 | unsigned ContentSize = Die->getSize() + |
| 2191 | sizeof(int16_t) + // DWARF version number |
| 2192 | sizeof(int32_t) + // Offset Into Abbrev. Section |
| 2193 | sizeof(int8_t); // Pointer Size (in bytes) |
| 2194 | |
| 2195 | EmitInt32(ContentSize); EOL("Length of Compilation Unit Info"); |
| 2196 | EmitInt16(DWARF_VERSION); EOL("DWARF version number"); |
| 2197 | EmitDifference("abbrev_begin", 0, "section_abbrev", 0); |
| 2198 | EOL("Offset Into Abbrev. Section"); |
| 2199 | EmitInt8(TAI->getAddressSize()); EOL("Address Size (in bytes)"); |
| 2200 | |
| 2201 | EmitDIE(Die); |
| 2202 | EmitLabel("info_end", Unit->getID()); |
| 2203 | } |
| 2204 | |
| 2205 | O << "\n"; |
| 2206 | } |
| 2207 | } |
| 2208 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2209 | /// EmitAbbreviations - Emit the abbreviation section. |
| 2210 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2211 | void EmitAbbreviations() const { |
| 2212 | // Check to see if it is worth the effort. |
| 2213 | if (!Abbreviations.empty()) { |
| 2214 | // Start the debug abbrev section. |
| 2215 | Asm->SwitchToDataSection(TAI->getDwarfAbbrevSection()); |
| 2216 | |
| 2217 | EmitLabel("abbrev_begin", 0); |
| 2218 | |
| 2219 | // For each abbrevation. |
| 2220 | for (unsigned i = 0, N = Abbreviations.size(); i < N; ++i) { |
| 2221 | // Get abbreviation data |
| 2222 | const DIEAbbrev *Abbrev = Abbreviations[i]; |
| 2223 | |
| 2224 | // Emit the abbrevations code (base 1 index.) |
| 2225 | EmitULEB128Bytes(Abbrev->getNumber()); EOL("Abbreviation Code"); |
| 2226 | |
| 2227 | // Emit the abbreviations data. |
| 2228 | Abbrev->Emit(*this); |
| 2229 | |
| 2230 | O << "\n"; |
| 2231 | } |
| 2232 | |
| 2233 | EmitLabel("abbrev_end", 0); |
| 2234 | |
| 2235 | O << "\n"; |
| 2236 | } |
| 2237 | } |
| 2238 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2239 | /// EmitDebugLines - Emit source line information. |
| 2240 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2241 | void EmitDebugLines() const { |
| 2242 | // Minimum line delta, thus ranging from -10..(255-10). |
| 2243 | const int MinLineDelta = -(DW_LNS_fixed_advance_pc + 1); |
| 2244 | // Maximum line delta, thus ranging from -10..(255-10). |
| 2245 | const int MaxLineDelta = 255 + MinLineDelta; |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2246 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2247 | // Start the dwarf line section. |
| 2248 | Asm->SwitchToDataSection(TAI->getDwarfLineSection()); |
| 2249 | |
| 2250 | // Construct the section header. |
| 2251 | |
| 2252 | EmitDifference("line_end", 0, "line_begin", 0); |
| 2253 | EOL("Length of Source Line Info"); |
| 2254 | EmitLabel("line_begin", 0); |
| 2255 | |
| 2256 | EmitInt16(DWARF_VERSION); EOL("DWARF version number"); |
| 2257 | |
| 2258 | EmitDifference("line_prolog_end", 0, "line_prolog_begin", 0); |
| 2259 | EOL("Prolog Length"); |
| 2260 | EmitLabel("line_prolog_begin", 0); |
| 2261 | |
| 2262 | EmitInt8(1); EOL("Minimum Instruction Length"); |
| 2263 | |
| 2264 | EmitInt8(1); EOL("Default is_stmt_start flag"); |
| 2265 | |
| 2266 | EmitInt8(MinLineDelta); EOL("Line Base Value (Special Opcodes)"); |
| 2267 | |
| 2268 | EmitInt8(MaxLineDelta); EOL("Line Range Value (Special Opcodes)"); |
| 2269 | |
| 2270 | EmitInt8(-MinLineDelta); EOL("Special Opcode Base"); |
| 2271 | |
| 2272 | // Line number standard opcode encodings argument count |
| 2273 | EmitInt8(0); EOL("DW_LNS_copy arg count"); |
| 2274 | EmitInt8(1); EOL("DW_LNS_advance_pc arg count"); |
| 2275 | EmitInt8(1); EOL("DW_LNS_advance_line arg count"); |
| 2276 | EmitInt8(1); EOL("DW_LNS_set_file arg count"); |
| 2277 | EmitInt8(1); EOL("DW_LNS_set_column arg count"); |
| 2278 | EmitInt8(0); EOL("DW_LNS_negate_stmt arg count"); |
| 2279 | EmitInt8(0); EOL("DW_LNS_set_basic_block arg count"); |
| 2280 | EmitInt8(0); EOL("DW_LNS_const_add_pc arg count"); |
| 2281 | EmitInt8(1); EOL("DW_LNS_fixed_advance_pc arg count"); |
| 2282 | |
| 2283 | const UniqueVector<std::string> &Directories = DebugInfo->getDirectories(); |
| 2284 | const UniqueVector<SourceFileInfo> |
| 2285 | &SourceFiles = DebugInfo->getSourceFiles(); |
| 2286 | |
| 2287 | // Emit directories. |
| 2288 | for (unsigned DirectoryID = 1, NDID = Directories.size(); |
| 2289 | DirectoryID <= NDID; ++DirectoryID) { |
| 2290 | EmitString(Directories[DirectoryID]); EOL("Directory"); |
| 2291 | } |
| 2292 | EmitInt8(0); EOL("End of directories"); |
| 2293 | |
| 2294 | // Emit files. |
| 2295 | for (unsigned SourceID = 1, NSID = SourceFiles.size(); |
| 2296 | SourceID <= NSID; ++SourceID) { |
| 2297 | const SourceFileInfo &SourceFile = SourceFiles[SourceID]; |
| 2298 | EmitString(SourceFile.getName()); EOL("Source"); |
| 2299 | EmitULEB128Bytes(SourceFile.getDirectoryID()); EOL("Directory #"); |
| 2300 | EmitULEB128Bytes(0); EOL("Mod date"); |
| 2301 | EmitULEB128Bytes(0); EOL("File size"); |
| 2302 | } |
| 2303 | EmitInt8(0); EOL("End of files"); |
| 2304 | |
| 2305 | EmitLabel("line_prolog_end", 0); |
| 2306 | |
| 2307 | // A sequence for each text section. |
| 2308 | for (unsigned j = 0, M = SectionSourceLines.size(); j < M; ++j) { |
| 2309 | // Isolate current sections line info. |
| 2310 | const std::vector<SourceLineInfo> &LineInfos = SectionSourceLines[j]; |
| 2311 | |
| 2312 | if (DwarfVerbose) { |
| 2313 | O << "\t" |
| 2314 | << TAI->getCommentString() << " " |
| 2315 | << "Section " |
| 2316 | << SectionMap[j + 1].c_str() << "\n"; |
| 2317 | } |
| 2318 | |
| 2319 | // Dwarf assumes we start with first line of first source file. |
| 2320 | unsigned Source = 1; |
| 2321 | unsigned Line = 1; |
| 2322 | |
| 2323 | // Construct rows of the address, source, line, column matrix. |
| 2324 | for (unsigned i = 0, N = LineInfos.size(); i < N; ++i) { |
| 2325 | const SourceLineInfo &LineInfo = LineInfos[i]; |
| 2326 | unsigned LabelID = LineInfo.getLabelID(); |
| 2327 | |
| 2328 | // Source line labels are validated at the MachineDebugInfo level. |
| 2329 | |
| 2330 | if (DwarfVerbose) { |
| 2331 | unsigned SourceID = LineInfo.getSourceID(); |
| 2332 | const SourceFileInfo &SourceFile = SourceFiles[SourceID]; |
| 2333 | unsigned DirectoryID = SourceFile.getDirectoryID(); |
| 2334 | O << "\t" |
| 2335 | << TAI->getCommentString() << " " |
| 2336 | << Directories[DirectoryID] |
| 2337 | << SourceFile.getName() << ":" |
| 2338 | << LineInfo.getLine() << "\n"; |
| 2339 | } |
| 2340 | |
| 2341 | // Define the line address. |
| 2342 | EmitInt8(0); EOL("Extended Op"); |
| 2343 | EmitInt8(4 + 1); EOL("Op size"); |
| 2344 | EmitInt8(DW_LNE_set_address); EOL("DW_LNE_set_address"); |
| 2345 | EmitReference("loc", LabelID); EOL("Location label"); |
| 2346 | |
| 2347 | // If change of source, then switch to the new source. |
| 2348 | if (Source != LineInfo.getSourceID()) { |
| 2349 | Source = LineInfo.getSourceID(); |
| 2350 | EmitInt8(DW_LNS_set_file); EOL("DW_LNS_set_file"); |
| 2351 | EmitULEB128Bytes(Source); EOL("New Source"); |
| 2352 | } |
| 2353 | |
| 2354 | // If change of line. |
| 2355 | if (Line != LineInfo.getLine()) { |
| 2356 | // Determine offset. |
| 2357 | int Offset = LineInfo.getLine() - Line; |
| 2358 | int Delta = Offset - MinLineDelta; |
| 2359 | |
| 2360 | // Update line. |
| 2361 | Line = LineInfo.getLine(); |
| 2362 | |
| 2363 | // If delta is small enough and in range... |
| 2364 | if (Delta >= 0 && Delta < (MaxLineDelta - 1)) { |
| 2365 | // ... then use fast opcode. |
| 2366 | EmitInt8(Delta - MinLineDelta); EOL("Line Delta"); |
| 2367 | } else { |
| 2368 | // ... otherwise use long hand. |
| 2369 | EmitInt8(DW_LNS_advance_line); EOL("DW_LNS_advance_line"); |
| 2370 | EmitSLEB128Bytes(Offset); EOL("Line Offset"); |
| 2371 | EmitInt8(DW_LNS_copy); EOL("DW_LNS_copy"); |
| 2372 | } |
| 2373 | } else { |
| 2374 | // Copy the previous row (different address or source) |
| 2375 | EmitInt8(DW_LNS_copy); EOL("DW_LNS_copy"); |
| 2376 | } |
| 2377 | } |
| 2378 | |
| 2379 | // Define last address of section. |
| 2380 | EmitInt8(0); EOL("Extended Op"); |
| 2381 | EmitInt8(4 + 1); EOL("Op size"); |
| 2382 | EmitInt8(DW_LNE_set_address); EOL("DW_LNE_set_address"); |
| 2383 | EmitReference("section_end", j + 1); EOL("Section end label"); |
| 2384 | |
| 2385 | // Mark end of matrix. |
| 2386 | EmitInt8(0); EOL("DW_LNE_end_sequence"); |
| 2387 | EmitULEB128Bytes(1); O << "\n"; |
| 2388 | EmitInt8(1); O << "\n"; |
| 2389 | } |
| 2390 | |
| 2391 | EmitLabel("line_end", 0); |
| 2392 | |
| 2393 | O << "\n"; |
| 2394 | } |
| 2395 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2396 | /// EmitInitialDebugFrame - Emit common frame info into a debug frame section. |
| 2397 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2398 | void EmitInitialDebugFrame() { |
| 2399 | if (!TAI->getDwarfRequiresFrameSection()) |
| 2400 | return; |
| 2401 | |
| 2402 | int stackGrowth = |
| 2403 | Asm->TM.getFrameInfo()->getStackGrowthDirection() == |
| 2404 | TargetFrameInfo::StackGrowsUp ? |
| 2405 | TAI->getAddressSize() : -TAI->getAddressSize(); |
| 2406 | |
| 2407 | // Start the dwarf frame section. |
| 2408 | Asm->SwitchToDataSection(TAI->getDwarfFrameSection()); |
| 2409 | |
| 2410 | EmitLabel("frame_common", 0); |
| 2411 | EmitDifference("frame_common_end", 0, |
| 2412 | "frame_common_begin", 0); |
| 2413 | EOL("Length of Common Information Entry"); |
| 2414 | |
| 2415 | EmitLabel("frame_common_begin", 0); |
| 2416 | EmitInt32(DW_CIE_ID); EOL("CIE Identifier Tag"); |
| 2417 | EmitInt8(DW_CIE_VERSION); EOL("CIE Version"); |
| 2418 | EmitString(""); EOL("CIE Augmentation"); |
| 2419 | EmitULEB128Bytes(1); EOL("CIE Code Alignment Factor"); |
| 2420 | EmitSLEB128Bytes(stackGrowth); EOL("CIE Data Alignment Factor"); |
| 2421 | EmitInt8(RI->getDwarfRegNum(RI->getRARegister())); EOL("CIE RA Column"); |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2422 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2423 | std::vector<MachineMove *> Moves; |
| 2424 | RI->getInitialFrameState(Moves); |
| 2425 | EmitFrameMoves(NULL, 0, Moves); |
| 2426 | for (unsigned i = 0, N = Moves.size(); i < N; ++i) delete Moves[i]; |
| 2427 | |
| 2428 | EmitAlign(2); |
| 2429 | EmitLabel("frame_common_end", 0); |
| 2430 | |
| 2431 | O << "\n"; |
| 2432 | } |
| 2433 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2434 | /// EmitFunctionDebugFrame - Emit per function frame info into a debug frame |
| 2435 | /// section. |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2436 | void EmitFunctionDebugFrame() { |
| 2437 | // Start the dwarf frame section. |
| 2438 | Asm->SwitchToDataSection(TAI->getDwarfFrameSection()); |
| 2439 | |
| 2440 | EmitDifference("frame_end", SubprogramCount, |
| 2441 | "frame_begin", SubprogramCount); |
| 2442 | EOL("Length of Frame Information Entry"); |
| 2443 | |
| 2444 | EmitLabel("frame_begin", SubprogramCount); |
| 2445 | |
| 2446 | EmitDifference("frame_common", 0, "section_frame", 0); |
| 2447 | EOL("FDE CIE offset"); |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2448 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2449 | EmitReference("func_begin", SubprogramCount); EOL("FDE initial location"); |
| 2450 | EmitDifference("func_end", SubprogramCount, |
| 2451 | "func_begin", SubprogramCount); |
| 2452 | EOL("FDE address range"); |
| 2453 | |
| 2454 | std::vector<MachineMove *> &Moves = DebugInfo->getFrameMoves(); |
| 2455 | |
| 2456 | EmitFrameMoves("func_begin", SubprogramCount, Moves); |
| 2457 | |
| 2458 | EmitAlign(2); |
| 2459 | EmitLabel("frame_end", SubprogramCount); |
| 2460 | |
| 2461 | O << "\n"; |
| 2462 | } |
| 2463 | |
| 2464 | /// EmitDebugPubNames - Emit visible names into a debug pubnames section. |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2465 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2466 | void EmitDebugPubNames() { |
| 2467 | // Start the dwarf pubnames section. |
| 2468 | Asm->SwitchToDataSection(TAI->getDwarfPubNamesSection()); |
| 2469 | |
| 2470 | // Process each compile unit. |
| 2471 | for (unsigned i = 0, N = CompileUnits.size(); i < N; ++i) { |
| 2472 | CompileUnit *Unit = CompileUnits[i]; |
| 2473 | |
| 2474 | if (Unit->hasContent()) { |
| 2475 | EmitDifference("pubnames_end", Unit->getID(), |
| 2476 | "pubnames_begin", Unit->getID()); |
| 2477 | EOL("Length of Public Names Info"); |
| 2478 | |
| 2479 | EmitLabel("pubnames_begin", Unit->getID()); |
| 2480 | |
| 2481 | EmitInt16(DWARF_VERSION); EOL("DWARF Version"); |
| 2482 | |
| 2483 | EmitDifference("info_begin", Unit->getID(), "section_info", 0); |
| 2484 | EOL("Offset of Compilation Unit Info"); |
| 2485 | |
| 2486 | EmitDifference("info_end", Unit->getID(), "info_begin", Unit->getID()); |
| 2487 | EOL("Compilation Unit Length"); |
| 2488 | |
| 2489 | std::map<std::string, DIE *> &Globals = Unit->getGlobals(); |
| 2490 | |
| 2491 | for (std::map<std::string, DIE *>::iterator GI = Globals.begin(), |
| 2492 | GE = Globals.end(); |
| 2493 | GI != GE; ++GI) { |
| 2494 | const std::string &Name = GI->first; |
| 2495 | DIE * Entity = GI->second; |
| 2496 | |
| 2497 | EmitInt32(Entity->getOffset()); EOL("DIE offset"); |
| 2498 | EmitString(Name); EOL("External Name"); |
| 2499 | } |
| 2500 | |
| 2501 | EmitInt32(0); EOL("End Mark"); |
| 2502 | EmitLabel("pubnames_end", Unit->getID()); |
| 2503 | |
| 2504 | O << "\n"; |
| 2505 | } |
| 2506 | } |
| 2507 | } |
| 2508 | |
| 2509 | /// EmitDebugStr - Emit visible names into a debug str section. |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2510 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2511 | void EmitDebugStr() { |
| 2512 | // Check to see if it is worth the effort. |
| 2513 | if (!StringPool.empty()) { |
| 2514 | // Start the dwarf str section. |
| 2515 | Asm->SwitchToDataSection(TAI->getDwarfStrSection()); |
| 2516 | |
| 2517 | // For each of strings in the string pool. |
| 2518 | for (unsigned StringID = 1, N = StringPool.size(); |
| 2519 | StringID <= N; ++StringID) { |
| 2520 | // Emit a label for reference from debug information entries. |
| 2521 | EmitLabel("string", StringID); |
| 2522 | // Emit the string itself. |
| 2523 | const std::string &String = StringPool[StringID]; |
| 2524 | EmitString(String); O << "\n"; |
| 2525 | } |
| 2526 | |
| 2527 | O << "\n"; |
| 2528 | } |
| 2529 | } |
| 2530 | |
| 2531 | /// EmitDebugLoc - Emit visible names into a debug loc section. |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2532 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2533 | void EmitDebugLoc() { |
| 2534 | // Start the dwarf loc section. |
| 2535 | Asm->SwitchToDataSection(TAI->getDwarfLocSection()); |
| 2536 | |
| 2537 | O << "\n"; |
| 2538 | } |
| 2539 | |
| 2540 | /// EmitDebugARanges - Emit visible names into a debug aranges section. |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2541 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2542 | void EmitDebugARanges() { |
| 2543 | // Start the dwarf aranges section. |
| 2544 | Asm->SwitchToDataSection(TAI->getDwarfARangesSection()); |
| 2545 | |
| 2546 | // FIXME - Mock up |
| 2547 | #if 0 |
| 2548 | // Process each compile unit. |
| 2549 | for (unsigned i = 0, N = CompileUnits.size(); i < N; ++i) { |
| 2550 | CompileUnit *Unit = CompileUnits[i]; |
| 2551 | |
| 2552 | if (Unit->hasContent()) { |
| 2553 | // Don't include size of length |
| 2554 | EmitInt32(0x1c); EOL("Length of Address Ranges Info"); |
| 2555 | |
| 2556 | EmitInt16(DWARF_VERSION); EOL("Dwarf Version"); |
| 2557 | |
| 2558 | EmitReference("info_begin", Unit->getID()); |
| 2559 | EOL("Offset of Compilation Unit Info"); |
| 2560 | |
| 2561 | EmitInt8(TAI->getAddressSize()); EOL("Size of Address"); |
| 2562 | |
| 2563 | EmitInt8(0); EOL("Size of Segment Descriptor"); |
| 2564 | |
| 2565 | EmitInt16(0); EOL("Pad (1)"); |
| 2566 | EmitInt16(0); EOL("Pad (2)"); |
| 2567 | |
| 2568 | // Range 1 |
| 2569 | EmitReference("text_begin", 0); EOL("Address"); |
| 2570 | EmitDifference("text_end", 0, "text_begin", 0); EOL("Length"); |
| 2571 | |
| 2572 | EmitInt32(0); EOL("EOM (1)"); |
| 2573 | EmitInt32(0); EOL("EOM (2)"); |
| 2574 | |
| 2575 | O << "\n"; |
| 2576 | } |
| 2577 | } |
| 2578 | #endif |
| 2579 | } |
| 2580 | |
| 2581 | /// EmitDebugRanges - Emit visible names into a debug ranges section. |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2582 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2583 | void EmitDebugRanges() { |
| 2584 | // Start the dwarf ranges section. |
| 2585 | Asm->SwitchToDataSection(TAI->getDwarfRangesSection()); |
| 2586 | |
| 2587 | O << "\n"; |
| 2588 | } |
| 2589 | |
| 2590 | /// EmitDebugMacInfo - Emit visible names into a debug macinfo section. |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2591 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2592 | void EmitDebugMacInfo() { |
| 2593 | // Start the dwarf macinfo section. |
| 2594 | Asm->SwitchToDataSection(TAI->getDwarfMacInfoSection()); |
| 2595 | |
| 2596 | O << "\n"; |
| 2597 | } |
| 2598 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2599 | /// ConstructCompileUnitDIEs - Create a compile unit DIE for each source and |
| 2600 | /// header file. |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2601 | void ConstructCompileUnitDIEs() { |
| 2602 | const UniqueVector<CompileUnitDesc *> CUW = DebugInfo->getCompileUnits(); |
| 2603 | |
| 2604 | for (unsigned i = 1, N = CUW.size(); i <= N; ++i) { |
| 2605 | CompileUnit *Unit = NewCompileUnit(CUW[i], i); |
| 2606 | CompileUnits.push_back(Unit); |
| 2607 | } |
| 2608 | } |
| 2609 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2610 | /// ConstructGlobalDIEs - Create DIEs for each of the externally visible |
| 2611 | /// global variables. |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2612 | void ConstructGlobalDIEs() { |
| 2613 | std::vector<GlobalVariableDesc *> GlobalVariables = |
| 2614 | DebugInfo->getAnchoredDescriptors<GlobalVariableDesc>(*M); |
| 2615 | |
| 2616 | for (unsigned i = 0, N = GlobalVariables.size(); i < N; ++i) { |
| 2617 | GlobalVariableDesc *GVD = GlobalVariables[i]; |
| 2618 | NewGlobalVariable(GVD); |
| 2619 | } |
| 2620 | } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2621 | |
| 2622 | /// ConstructSubprogramDIEs - Create DIEs for each of the externally visible |
| 2623 | /// subprograms. |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2624 | void ConstructSubprogramDIEs() { |
| 2625 | std::vector<SubprogramDesc *> Subprograms = |
| 2626 | DebugInfo->getAnchoredDescriptors<SubprogramDesc>(*M); |
| 2627 | |
| 2628 | for (unsigned i = 0, N = Subprograms.size(); i < N; ++i) { |
| 2629 | SubprogramDesc *SPD = Subprograms[i]; |
| 2630 | NewSubprogram(SPD); |
| 2631 | } |
| 2632 | } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2633 | |
| 2634 | /// ShouldEmitDwarf - Returns true if Dwarf declarations should be made. |
| 2635 | /// |
| 2636 | bool ShouldEmitDwarf() const { return shouldEmit; } |
| 2637 | |
| 2638 | public: |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2639 | //===--------------------------------------------------------------------===// |
| 2640 | // Main entry points. |
| 2641 | // |
| 2642 | Dwarf(std::ostream &OS, AsmPrinter *A, const TargetAsmInfo *T) |
| 2643 | : O(OS) |
| 2644 | , Asm(A) |
| 2645 | , TAI(T) |
| 2646 | , TD(Asm->TM.getTargetData()) |
| 2647 | , RI(Asm->TM.getRegisterInfo()) |
| 2648 | , M(NULL) |
| 2649 | , MF(NULL) |
| 2650 | , DebugInfo(NULL) |
| 2651 | , didInitial(false) |
| 2652 | , shouldEmit(false) |
| 2653 | , SubprogramCount(0) |
| 2654 | , CompileUnits() |
| 2655 | , AbbreviationsSet(InitAbbreviationsSetSize) |
| 2656 | , Abbreviations() |
| 2657 | , ValuesSet(InitValuesSetSize) |
| 2658 | , Values() |
| 2659 | , StringPool() |
| 2660 | , DescToUnitMap() |
| 2661 | , SectionMap() |
| 2662 | , SectionSourceLines() |
| 2663 | { |
| 2664 | } |
| 2665 | virtual ~Dwarf() { |
| 2666 | for (unsigned i = 0, N = CompileUnits.size(); i < N; ++i) |
| 2667 | delete CompileUnits[i]; |
| 2668 | for (unsigned j = 0, M = Values.size(); j < M; ++j) |
| 2669 | delete Values[j]; |
| 2670 | } |
| 2671 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2672 | // Accessors. |
| 2673 | // |
| 2674 | const TargetAsmInfo *getTargetAsmInfo() const { return TAI; } |
| 2675 | |
| 2676 | /// SetDebugInfo - Set DebugInfo when it's known that pass manager has |
| 2677 | /// created it. Set by the target AsmPrinter. |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2678 | void SetDebugInfo(MachineDebugInfo *DI) { |
| 2679 | // Make sure initial declarations are made. |
| 2680 | if (!DebugInfo && DI->hasInfo()) { |
| 2681 | DebugInfo = DI; |
| 2682 | shouldEmit = true; |
| 2683 | |
| 2684 | // Emit initial sections |
| 2685 | EmitInitial(); |
| 2686 | |
| 2687 | // Create all the compile unit DIEs. |
| 2688 | ConstructCompileUnitDIEs(); |
| 2689 | |
| 2690 | // Create DIEs for each of the externally visible global variables. |
| 2691 | ConstructGlobalDIEs(); |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2692 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2693 | // Create DIEs for each of the externally visible subprograms. |
| 2694 | ConstructSubprogramDIEs(); |
| 2695 | |
| 2696 | // Prime section data. |
| 2697 | SectionMap.insert(std::string("\t") + TAI->getTextSection()); |
| 2698 | } |
| 2699 | } |
| 2700 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2701 | /// BeginModule - Emit all Dwarf sections that should come prior to the |
| 2702 | /// content. |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2703 | void BeginModule(Module *M) { |
| 2704 | this->M = M; |
| 2705 | |
| 2706 | if (!ShouldEmitDwarf()) return; |
| 2707 | EOL("Dwarf Begin Module"); |
| 2708 | } |
| 2709 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2710 | /// EndModule - Emit all Dwarf sections that should come after the content. |
| 2711 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2712 | void EndModule() { |
| 2713 | if (!ShouldEmitDwarf()) return; |
| 2714 | EOL("Dwarf End Module"); |
| 2715 | |
| 2716 | // Standard sections final addresses. |
| 2717 | Asm->SwitchToTextSection(TAI->getTextSection()); |
| 2718 | EmitLabel("text_end", 0); |
| 2719 | Asm->SwitchToDataSection(TAI->getDataSection()); |
| 2720 | EmitLabel("data_end", 0); |
| 2721 | |
| 2722 | // End text sections. |
| 2723 | for (unsigned i = 1, N = SectionMap.size(); i <= N; ++i) { |
| 2724 | Asm->SwitchToTextSection(SectionMap[i].c_str()); |
| 2725 | EmitLabel("section_end", i); |
| 2726 | } |
| 2727 | |
| 2728 | // Compute DIE offsets and sizes. |
| 2729 | SizeAndOffsets(); |
| 2730 | |
| 2731 | // Emit all the DIEs into a debug info section |
| 2732 | EmitDebugInfo(); |
| 2733 | |
| 2734 | // Corresponding abbreviations into a abbrev section. |
| 2735 | EmitAbbreviations(); |
| 2736 | |
| 2737 | // Emit source line correspondence into a debug line section. |
| 2738 | EmitDebugLines(); |
| 2739 | |
| 2740 | // Emit info into a debug pubnames section. |
| 2741 | EmitDebugPubNames(); |
| 2742 | |
| 2743 | // Emit info into a debug str section. |
| 2744 | EmitDebugStr(); |
| 2745 | |
| 2746 | // Emit info into a debug loc section. |
| 2747 | EmitDebugLoc(); |
| 2748 | |
| 2749 | // Emit info into a debug aranges section. |
| 2750 | EmitDebugARanges(); |
| 2751 | |
| 2752 | // Emit info into a debug ranges section. |
| 2753 | EmitDebugRanges(); |
| 2754 | |
| 2755 | // Emit info into a debug macinfo section. |
| 2756 | EmitDebugMacInfo(); |
| 2757 | } |
| 2758 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2759 | /// BeginFunction - Gather pre-function debug information. Assumes being |
| 2760 | /// emitted immediately after the function entry point. |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2761 | void BeginFunction(MachineFunction *MF) { |
| 2762 | this->MF = MF; |
| 2763 | |
| 2764 | if (!ShouldEmitDwarf()) return; |
| 2765 | EOL("Dwarf Begin Function"); |
| 2766 | |
| 2767 | // Begin accumulating function debug information. |
| 2768 | DebugInfo->BeginFunction(MF); |
| 2769 | |
| 2770 | // Assumes in correct section after the entry point. |
| 2771 | EmitLabel("func_begin", ++SubprogramCount); |
| 2772 | } |
| 2773 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2774 | /// EndFunction - Gather and emit post-function debug information. |
| 2775 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2776 | void EndFunction() { |
| 2777 | if (!ShouldEmitDwarf()) return; |
| 2778 | EOL("Dwarf End Function"); |
| 2779 | |
| 2780 | // Define end label for subprogram. |
| 2781 | EmitLabel("func_end", SubprogramCount); |
| 2782 | |
| 2783 | // Get function line info. |
| 2784 | const std::vector<SourceLineInfo> &LineInfos = DebugInfo->getSourceLines(); |
| 2785 | |
| 2786 | if (!LineInfos.empty()) { |
| 2787 | // Get section line info. |
| 2788 | unsigned ID = SectionMap.insert(Asm->CurrentSection); |
| 2789 | if (SectionSourceLines.size() < ID) SectionSourceLines.resize(ID); |
| 2790 | std::vector<SourceLineInfo> &SectionLineInfos = SectionSourceLines[ID-1]; |
| 2791 | // Append the function info to section info. |
| 2792 | SectionLineInfos.insert(SectionLineInfos.end(), |
| 2793 | LineInfos.begin(), LineInfos.end()); |
| 2794 | } |
| 2795 | |
| 2796 | // Construct scopes for subprogram. |
| 2797 | ConstructRootScope(DebugInfo->getRootScope()); |
| 2798 | |
| 2799 | // Emit function frame information. |
| 2800 | EmitFunctionDebugFrame(); |
| 2801 | |
| 2802 | // Reset the line numbers for the next function. |
| 2803 | DebugInfo->ClearLineInfo(); |
| 2804 | |
| 2805 | // Clear function debug information. |
| 2806 | DebugInfo->EndFunction(); |
| 2807 | } |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2808 | }; |
| 2809 | |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 2810 | } // End of namespace llvm |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 2811 | |
| 2812 | //===----------------------------------------------------------------------===// |
| 2813 | |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 2814 | /// Emit - Print the abbreviation using the specified Dwarf writer. |
| 2815 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2816 | void DIEAbbrev::Emit(const Dwarf &DW) const { |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 2817 | // Emit its Dwarf tag type. |
| 2818 | DW.EmitULEB128Bytes(Tag); |
| 2819 | DW.EOL(TagString(Tag)); |
| 2820 | |
| 2821 | // Emit whether it has children DIEs. |
| 2822 | DW.EmitULEB128Bytes(ChildrenFlag); |
| 2823 | DW.EOL(ChildrenString(ChildrenFlag)); |
| 2824 | |
| 2825 | // For each attribute description. |
Jim Laskey | 52060a0 | 2006-01-24 00:49:18 +0000 | [diff] [blame] | 2826 | for (unsigned i = 0, N = Data.size(); i < N; ++i) { |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 2827 | const DIEAbbrevData &AttrData = Data[i]; |
| 2828 | |
| 2829 | // Emit attribute type. |
| 2830 | DW.EmitULEB128Bytes(AttrData.getAttribute()); |
| 2831 | DW.EOL(AttributeString(AttrData.getAttribute())); |
| 2832 | |
| 2833 | // Emit form type. |
| 2834 | DW.EmitULEB128Bytes(AttrData.getForm()); |
| 2835 | DW.EOL(FormEncodingString(AttrData.getForm())); |
| 2836 | } |
| 2837 | |
| 2838 | // Mark end of abbreviation. |
| 2839 | DW.EmitULEB128Bytes(0); DW.EOL("EOM(1)"); |
| 2840 | DW.EmitULEB128Bytes(0); DW.EOL("EOM(2)"); |
| 2841 | } |
| 2842 | |
| 2843 | #ifndef NDEBUG |
Jim Laskey | a0f3d17 | 2006-09-07 22:06:40 +0000 | [diff] [blame] | 2844 | void DIEAbbrev::print(std::ostream &O) { |
| 2845 | O << "Abbreviation @" |
| 2846 | << std::hex << (intptr_t)this << std::dec |
| 2847 | << " " |
| 2848 | << TagString(Tag) |
| 2849 | << " " |
| 2850 | << ChildrenString(ChildrenFlag) |
| 2851 | << "\n"; |
| 2852 | |
| 2853 | for (unsigned i = 0, N = Data.size(); i < N; ++i) { |
| 2854 | O << " " |
| 2855 | << AttributeString(Data[i].getAttribute()) |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 2856 | << " " |
Jim Laskey | a0f3d17 | 2006-09-07 22:06:40 +0000 | [diff] [blame] | 2857 | << FormEncodingString(Data[i].getForm()) |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 2858 | << "\n"; |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 2859 | } |
Jim Laskey | a0f3d17 | 2006-09-07 22:06:40 +0000 | [diff] [blame] | 2860 | } |
| 2861 | void DIEAbbrev::dump() { print(std::cerr); } |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 2862 | #endif |
| 2863 | |
| 2864 | //===----------------------------------------------------------------------===// |
| 2865 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2866 | #ifndef NDEBUG |
| 2867 | void DIEValue::dump() { |
| 2868 | print(std::cerr); |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 2869 | } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2870 | #endif |
| 2871 | |
| 2872 | //===----------------------------------------------------------------------===// |
| 2873 | |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 2874 | /// EmitValue - Emit integer of appropriate size. |
| 2875 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2876 | void DIEInteger::EmitValue(const Dwarf &DW, unsigned Form) const { |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 2877 | switch (Form) { |
Jim Laskey | 4002017 | 2006-01-20 21:02:36 +0000 | [diff] [blame] | 2878 | case DW_FORM_flag: // Fall thru |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 2879 | case DW_FORM_ref1: // Fall thru |
Jim Laskey | da427fa | 2006-01-27 20:31:25 +0000 | [diff] [blame] | 2880 | case DW_FORM_data1: DW.EmitInt8(Integer); break; |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 2881 | case DW_FORM_ref2: // Fall thru |
Jim Laskey | da427fa | 2006-01-27 20:31:25 +0000 | [diff] [blame] | 2882 | case DW_FORM_data2: DW.EmitInt16(Integer); break; |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 2883 | case DW_FORM_ref4: // Fall thru |
Jim Laskey | da427fa | 2006-01-27 20:31:25 +0000 | [diff] [blame] | 2884 | case DW_FORM_data4: DW.EmitInt32(Integer); break; |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 2885 | case DW_FORM_ref8: // Fall thru |
Jim Laskey | da427fa | 2006-01-27 20:31:25 +0000 | [diff] [blame] | 2886 | case DW_FORM_data8: DW.EmitInt64(Integer); break; |
Jim Laskey | 4002017 | 2006-01-20 21:02:36 +0000 | [diff] [blame] | 2887 | case DW_FORM_udata: DW.EmitULEB128Bytes(Integer); break; |
| 2888 | case DW_FORM_sdata: DW.EmitSLEB128Bytes(Integer); break; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 2889 | default: assert(0 && "DIE Value form not supported yet"); break; |
| 2890 | } |
| 2891 | } |
| 2892 | |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 2893 | //===----------------------------------------------------------------------===// |
| 2894 | |
| 2895 | /// EmitValue - Emit string value. |
| 2896 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2897 | void DIEString::EmitValue(const Dwarf &DW, unsigned Form) const { |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 2898 | DW.EmitString(String); |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 2899 | } |
| 2900 | |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 2901 | //===----------------------------------------------------------------------===// |
| 2902 | |
| 2903 | /// EmitValue - Emit label value. |
| 2904 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2905 | void DIEDwarfLabel::EmitValue(const Dwarf &DW, unsigned Form) const { |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 2906 | DW.EmitReference(Label); |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 2907 | } |
| 2908 | |
| 2909 | /// SizeOf - Determine size of label value in bytes. |
| 2910 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2911 | unsigned DIEDwarfLabel::SizeOf(const Dwarf &DW, unsigned Form) const { |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 2912 | return DW.getTargetAsmInfo()->getAddressSize(); |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 2913 | } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2914 | |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 2915 | //===----------------------------------------------------------------------===// |
| 2916 | |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 2917 | /// EmitValue - Emit label value. |
| 2918 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2919 | void DIEObjectLabel::EmitValue(const Dwarf &DW, unsigned Form) const { |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 2920 | DW.EmitReference(Label); |
| 2921 | } |
| 2922 | |
| 2923 | /// SizeOf - Determine size of label value in bytes. |
| 2924 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2925 | unsigned DIEObjectLabel::SizeOf(const Dwarf &DW, unsigned Form) const { |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 2926 | return DW.getTargetAsmInfo()->getAddressSize(); |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 2927 | } |
| 2928 | |
| 2929 | //===----------------------------------------------------------------------===// |
| 2930 | |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 2931 | /// EmitValue - Emit delta value. |
| 2932 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2933 | void DIEDelta::EmitValue(const Dwarf &DW, unsigned Form) const { |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 2934 | DW.EmitDifference(LabelHi, LabelLo); |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 2935 | } |
| 2936 | |
| 2937 | /// SizeOf - Determine size of delta value in bytes. |
| 2938 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2939 | unsigned DIEDelta::SizeOf(const Dwarf &DW, unsigned Form) const { |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 2940 | return DW.getTargetAsmInfo()->getAddressSize(); |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 2941 | } |
| 2942 | |
| 2943 | //===----------------------------------------------------------------------===// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2944 | |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 2945 | /// EmitValue - Emit debug information entry offset. |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 2946 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2947 | void DIEntry::EmitValue(const Dwarf &DW, unsigned Form) const { |
Jim Laskey | da427fa | 2006-01-27 20:31:25 +0000 | [diff] [blame] | 2948 | DW.EmitInt32(Entry->getOffset()); |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 2949 | } |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 2950 | |
| 2951 | //===----------------------------------------------------------------------===// |
| 2952 | |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 2953 | /// ComputeSize - calculate the size of the block. |
| 2954 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2955 | unsigned DIEBlock::ComputeSize(Dwarf &DW) { |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2956 | if (!Size) { |
| 2957 | const std::vector<DIEAbbrevData> &AbbrevData = Abbrev.getData(); |
| 2958 | |
| 2959 | for (unsigned i = 0, N = Values.size(); i < N; ++i) { |
| 2960 | Size += Values[i]->SizeOf(DW, AbbrevData[i].getForm()); |
| 2961 | } |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 2962 | } |
| 2963 | return Size; |
| 2964 | } |
| 2965 | |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 2966 | /// EmitValue - Emit block data. |
| 2967 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2968 | void DIEBlock::EmitValue(const Dwarf &DW, unsigned Form) const { |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 2969 | switch (Form) { |
| 2970 | case DW_FORM_block1: DW.EmitInt8(Size); break; |
| 2971 | case DW_FORM_block2: DW.EmitInt16(Size); break; |
| 2972 | case DW_FORM_block4: DW.EmitInt32(Size); break; |
| 2973 | case DW_FORM_block: DW.EmitULEB128Bytes(Size); break; |
| 2974 | default: assert(0 && "Improper form for block"); break; |
| 2975 | } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2976 | |
| 2977 | const std::vector<DIEAbbrevData> &AbbrevData = Abbrev.getData(); |
| 2978 | |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 2979 | for (unsigned i = 0, N = Values.size(); i < N; ++i) { |
| 2980 | DW.EOL(""); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2981 | Values[i]->EmitValue(DW, AbbrevData[i].getForm()); |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 2982 | } |
| 2983 | } |
| 2984 | |
| 2985 | /// SizeOf - Determine size of block data in bytes. |
| 2986 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 2987 | unsigned DIEBlock::SizeOf(const Dwarf &DW, unsigned Form) const { |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 2988 | switch (Form) { |
| 2989 | case DW_FORM_block1: return Size + sizeof(int8_t); |
| 2990 | case DW_FORM_block2: return Size + sizeof(int16_t); |
| 2991 | case DW_FORM_block4: return Size + sizeof(int32_t); |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2992 | case DW_FORM_block: return Size + SizeULEB128(Size); |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 2993 | default: assert(0 && "Improper form for block"); break; |
| 2994 | } |
| 2995 | return 0; |
| 2996 | } |
| 2997 | |
Jim Laskey | b80af6f | 2006-03-03 21:00:14 +0000 | [diff] [blame] | 2998 | //===----------------------------------------------------------------------===// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 2999 | /// DIE Implementation |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 3000 | |
| 3001 | DIE::~DIE() { |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 3002 | for (unsigned i = 0, N = Children.size(); i < N; ++i) |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 3003 | delete Children[i]; |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 3004 | } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 3005 | |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 3006 | /// AddSiblingOffset - Add a sibling offset field to the front of the DIE. |
| 3007 | /// |
| 3008 | void DIE::AddSiblingOffset() { |
| 3009 | DIEInteger *DI = new DIEInteger(0); |
| 3010 | Values.insert(Values.begin(), DI); |
Jim Laskey | a9c83fe | 2006-10-30 15:59:54 +0000 | [diff] [blame] | 3011 | Abbrev.AddFirstAttribute(DW_AT_sibling, DW_FORM_ref4); |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 3012 | } |
| 3013 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 3014 | /// Profile - Used to gather unique data for the value folding set. |
Jim Laskey | d18e289 | 2006-01-20 20:34:06 +0000 | [diff] [blame] | 3015 | /// |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 3016 | void DIE::Profile(FoldingSetNodeID &ID) { |
| 3017 | Abbrev.Profile(ID); |
| 3018 | |
| 3019 | for (unsigned i = 0, N = Children.size(); i < N; ++i) |
| 3020 | ID.AddPointer(Children[i]); |
| 3021 | |
| 3022 | for (unsigned j = 0, M = Values.size(); j < M; ++j) |
| 3023 | ID.AddPointer(Values[j]); |
Jim Laskey | d8f77ba | 2006-01-27 15:20:54 +0000 | [diff] [blame] | 3024 | } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 3025 | |
| 3026 | #ifndef NDEBUG |
| 3027 | void DIE::print(std::ostream &O, unsigned IncIndent) { |
| 3028 | static unsigned IndentCount = 0; |
| 3029 | IndentCount += IncIndent; |
| 3030 | const std::string Indent(IndentCount, ' '); |
| 3031 | bool isBlock = Abbrev.getTag() == 0; |
| 3032 | |
| 3033 | if (!isBlock) { |
| 3034 | O << Indent |
| 3035 | << "Die: " |
| 3036 | << "0x" << std::hex << (intptr_t)this << std::dec |
| 3037 | << ", Offset: " << Offset |
| 3038 | << ", Size: " << Size |
| 3039 | << "\n"; |
Jim Laskey | d8f77ba | 2006-01-27 15:20:54 +0000 | [diff] [blame] | 3040 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 3041 | O << Indent |
| 3042 | << TagString(Abbrev.getTag()) |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 3043 | << " " |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 3044 | << ChildrenString(Abbrev.getChildrenFlag()); |
| 3045 | } else { |
| 3046 | O << "Size: " << Size; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 3047 | } |
| 3048 | O << "\n"; |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 3049 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 3050 | const std::vector<DIEAbbrevData> &Data = Abbrev.getData(); |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 3051 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 3052 | IndentCount += 2; |
| 3053 | for (unsigned i = 0, N = Data.size(); i < N; ++i) { |
| 3054 | O << Indent; |
| 3055 | if (!isBlock) { |
| 3056 | O << AttributeString(Data[i].getAttribute()); |
Jim Laskey | d8f77ba | 2006-01-27 15:20:54 +0000 | [diff] [blame] | 3057 | } else { |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 3058 | O << "Blk[" << i << "]"; |
Jim Laskey | d8f77ba | 2006-01-27 15:20:54 +0000 | [diff] [blame] | 3059 | } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 3060 | O << " " |
| 3061 | << FormEncodingString(Data[i].getForm()) |
| 3062 | << " "; |
| 3063 | Values[i]->print(O); |
Jim Laskey | 0d086af | 2006-02-27 12:43:29 +0000 | [diff] [blame] | 3064 | O << "\n"; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 3065 | } |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 3066 | IndentCount -= 2; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 3067 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 3068 | for (unsigned j = 0, M = Children.size(); j < M; ++j) { |
| 3069 | Children[j]->print(O, 4); |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 3070 | } |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 3071 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 3072 | if (!isBlock) O << "\n"; |
| 3073 | IndentCount -= IncIndent; |
Jim Laskey | 19ef4ef | 2006-01-17 20:41:40 +0000 | [diff] [blame] | 3074 | } |
| 3075 | |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 3076 | void DIE::dump() { |
| 3077 | print(std::cerr); |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 3078 | } |
Jim Laskey | bd76184 | 2006-02-27 17:27:12 +0000 | [diff] [blame] | 3079 | #endif |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 3080 | |
| 3081 | //===----------------------------------------------------------------------===// |
| 3082 | /// DwarfWriter Implementation |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame^] | 3083 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 3084 | |
| 3085 | DwarfWriter::DwarfWriter(std::ostream &OS, AsmPrinter *A, |
| 3086 | const TargetAsmInfo *T) { |
| 3087 | DW = new Dwarf(OS, A, T); |
| 3088 | } |
| 3089 | |
| 3090 | DwarfWriter::~DwarfWriter() { |
| 3091 | delete DW; |
| 3092 | } |
| 3093 | |
| 3094 | /// SetDebugInfo - Set DebugInfo when it's known that pass manager has |
| 3095 | /// created it. Set by the target AsmPrinter. |
| 3096 | void DwarfWriter::SetDebugInfo(MachineDebugInfo *DI) { |
| 3097 | DW->SetDebugInfo(DI); |
| 3098 | } |
| 3099 | |
| 3100 | /// BeginModule - Emit all Dwarf sections that should come prior to the |
| 3101 | /// content. |
| 3102 | void DwarfWriter::BeginModule(Module *M) { |
| 3103 | DW->BeginModule(M); |
| 3104 | } |
| 3105 | |
| 3106 | /// EndModule - Emit all Dwarf sections that should come after the content. |
| 3107 | /// |
| 3108 | void DwarfWriter::EndModule() { |
| 3109 | DW->EndModule(); |
| 3110 | } |
| 3111 | |
| 3112 | /// BeginFunction - Gather pre-function debug information. Assumes being |
| 3113 | /// emitted immediately after the function entry point. |
| 3114 | void DwarfWriter::BeginFunction(MachineFunction *MF) { |
| 3115 | DW->BeginFunction(MF); |
| 3116 | } |
| 3117 | |
| 3118 | /// EndFunction - Gather and emit post-function debug information. |
| 3119 | /// |
| 3120 | void DwarfWriter::EndFunction() { |
| 3121 | DW->EndFunction(); |
| 3122 | } |