blob: fee0a654d30213afac2dab078831382dceed8ced [file] [log] [blame]
Jim Laskeye5032892005-12-21 19:48:16 +00001//===-- 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 Laskey3ea0e0e2006-01-27 18:32:41 +000013
Jim Laskeyb2efb852006-01-04 22:28:25 +000014#include "llvm/CodeGen/DwarfWriter.h"
Jim Laskeye5032892005-12-21 19:48:16 +000015
Jim Laskey063e7652006-01-17 17:31:53 +000016#include "llvm/ADT/StringExtras.h"
Jim Laskey52060a02006-01-24 00:49:18 +000017#include "llvm/Module.h"
18#include "llvm/Type.h"
Jim Laskeya7cea6f2006-01-04 13:52:30 +000019#include "llvm/CodeGen/AsmPrinter.h"
Jim Laskeyb2efb852006-01-04 22:28:25 +000020#include "llvm/CodeGen/MachineDebugInfo.h"
Jim Laskeyb3e789a2006-01-26 20:21:46 +000021#include "llvm/Support/Dwarf.h"
Jim Laskeya7cea6f2006-01-04 13:52:30 +000022#include "llvm/Support/CommandLine.h"
Jim Laskey52060a02006-01-24 00:49:18 +000023#include "llvm/Support/Mangler.h"
24#include "llvm/Target/TargetMachine.h"
Jim Laskeya7cea6f2006-01-04 13:52:30 +000025
Jim Laskeyb2efb852006-01-04 22:28:25 +000026#include <iostream>
Jim Laskeya7cea6f2006-01-04 13:52:30 +000027
Jim Laskeyb2efb852006-01-04 22:28:25 +000028using namespace llvm;
Jim Laskey0d086af2006-02-27 12:43:29 +000029using namespace dwarf;
Jim Laskeya7cea6f2006-01-04 13:52:30 +000030
31static cl::opt<bool>
32DwarfVerbose("dwarf-verbose", cl::Hidden,
Jim Laskey063e7652006-01-17 17:31:53 +000033 cl::desc("Add comments to Dwarf directives."));
34
Jim Laskey0d086af2006-02-27 12:43:29 +000035namespace llvm {
36
Jim Laskey063e7652006-01-17 17:31:53 +000037//===----------------------------------------------------------------------===//
Jim Laskey0d086af2006-02-27 12:43:29 +000038// Forward declarations.
39//
40class CompileUnit;
41class DIE;
Jim Laskey063e7652006-01-17 17:31:53 +000042
Jim Laskey0d086af2006-02-27 12:43:29 +000043//===----------------------------------------------------------------------===//
44// DIEAbbrevData - Dwarf abbreviation data, describes the one attribute of a
45// Dwarf abbreviation.
46class DIEAbbrevData {
47private:
48 unsigned Attribute; // Dwarf attribute code.
49 unsigned Form; // Dwarf form code.
50
51public:
52 DIEAbbrevData(unsigned A, unsigned F)
53 : Attribute(A)
54 , Form(F)
55 {}
56
57 // Accessors
58 unsigned getAttribute() const { return Attribute; }
59 unsigned getForm() const { return Form; }
60
61 /// operator== - Used by DIEAbbrev to locate entry.
62 ///
63 bool operator==(const DIEAbbrevData &DAD) const {
64 return Attribute == DAD.Attribute && Form == DAD.Form;
Jim Laskey063e7652006-01-17 17:31:53 +000065 }
Jim Laskey063e7652006-01-17 17:31:53 +000066
Jim Laskey0d086af2006-02-27 12:43:29 +000067 /// operator!= - Used by DIEAbbrev to locate entry.
68 ///
69 bool operator!=(const DIEAbbrevData &DAD) const {
70 return Attribute != DAD.Attribute || Form != DAD.Form;
Jim Laskey063e7652006-01-17 17:31:53 +000071 }
Jim Laskey0d086af2006-02-27 12:43:29 +000072
73 /// operator< - Used by DIEAbbrev to locate entry.
74 ///
75 bool operator<(const DIEAbbrevData &DAD) const {
76 return Attribute < DAD.Attribute ||
77 (Attribute == DAD.Attribute && Form < DAD.Form);
78 }
79};
Jim Laskey063e7652006-01-17 17:31:53 +000080
Jim Laskey0d086af2006-02-27 12:43:29 +000081//===----------------------------------------------------------------------===//
82// DIEAbbrev - Dwarf abbreviation, describes the organization of a debug
83// information object.
84class DIEAbbrev {
85private:
86 unsigned Tag; // Dwarf tag code.
87 unsigned ChildrenFlag; // Dwarf children flag.
88 std::vector<DIEAbbrevData> Data; // Raw data bytes for abbreviation.
Jim Laskey063e7652006-01-17 17:31:53 +000089
Jim Laskey0d086af2006-02-27 12:43:29 +000090public:
Jim Laskey063e7652006-01-17 17:31:53 +000091
Jim Laskey0d086af2006-02-27 12:43:29 +000092 DIEAbbrev(unsigned T, unsigned C)
93 : Tag(T)
94 , ChildrenFlag(C)
95 , Data()
96 {}
97 ~DIEAbbrev() {}
98
99 // Accessors
100 unsigned getTag() const { return Tag; }
101 unsigned getChildrenFlag() const { return ChildrenFlag; }
102 const std::vector<DIEAbbrevData> &getData() const { return Data; }
103 void setChildrenFlag(unsigned CF) { ChildrenFlag = CF; }
Jim Laskey063e7652006-01-17 17:31:53 +0000104
Jim Laskey0d086af2006-02-27 12:43:29 +0000105 /// operator== - Used by UniqueVector to locate entry.
106 ///
107 bool operator==(const DIEAbbrev &DA) const;
Jim Laskey063e7652006-01-17 17:31:53 +0000108
Jim Laskey0d086af2006-02-27 12:43:29 +0000109 /// operator< - Used by UniqueVector to locate entry.
110 ///
111 bool operator<(const DIEAbbrev &DA) const;
Jim Laskey063e7652006-01-17 17:31:53 +0000112
Jim Laskey0d086af2006-02-27 12:43:29 +0000113 /// AddAttribute - Adds another set of attribute information to the
114 /// abbreviation.
115 void AddAttribute(unsigned Attribute, unsigned Form) {
116 Data.push_back(DIEAbbrevData(Attribute, Form));
Jim Laskey063e7652006-01-17 17:31:53 +0000117 }
Jim Laskey0d086af2006-02-27 12:43:29 +0000118
119 /// Emit - Print the abbreviation using the specified Dwarf writer.
120 ///
121 void Emit(const DwarfWriter &DW) const;
122
123#ifndef NDEBUG
124 void print(std::ostream &O);
125 void dump();
126#endif
127};
Jim Laskey063e7652006-01-17 17:31:53 +0000128
Jim Laskey0d086af2006-02-27 12:43:29 +0000129//===----------------------------------------------------------------------===//
130// DIEValue - A debug information entry value.
131//
132class DIEValue {
133public:
134 enum {
135 isInteger,
136 isString,
137 isLabel,
138 isAsIsLabel,
139 isDelta,
140 isEntry
141 };
142
143 unsigned Type; // Type of the value
144
145 DIEValue(unsigned T) : Type(T) {}
146 virtual ~DIEValue() {}
147
148 // Implement isa/cast/dyncast.
149 static bool classof(const DIEValue *) { return true; }
150
151 /// EmitValue - Emit value via the Dwarf writer.
152 ///
153 virtual void EmitValue(const DwarfWriter &DW, unsigned Form) const = 0;
154
155 /// SizeOf - Return the size of a value in bytes.
156 ///
157 virtual unsigned SizeOf(const DwarfWriter &DW, unsigned Form) const = 0;
158};
Jim Laskey063e7652006-01-17 17:31:53 +0000159
Jim Laskey0d086af2006-02-27 12:43:29 +0000160//===----------------------------------------------------------------------===//
161// DWInteger - An integer value DIE.
162//
163class DIEInteger : public DIEValue {
164private:
165 uint64_t Integer;
166
167public:
168 DIEInteger(uint64_t I) : DIEValue(isInteger), Integer(I) {}
Jim Laskey063e7652006-01-17 17:31:53 +0000169
Jim Laskey0d086af2006-02-27 12:43:29 +0000170 // Implement isa/cast/dyncast.
171 static bool classof(const DIEInteger *) { return true; }
172 static bool classof(const DIEValue *I) { return I->Type == isInteger; }
173
174 /// EmitValue - Emit integer of appropriate size.
175 ///
176 virtual void EmitValue(const DwarfWriter &DW, unsigned Form) const;
177
178 /// SizeOf - Determine size of integer value in bytes.
179 ///
180 virtual unsigned SizeOf(const DwarfWriter &DW, unsigned Form) const;
181};
Jim Laskey063e7652006-01-17 17:31:53 +0000182
Jim Laskey0d086af2006-02-27 12:43:29 +0000183//===----------------------------------------------------------------------===//
184// DIEString - A string value DIE.
185//
186struct DIEString : public DIEValue {
187 const std::string String;
188
189 DIEString(const std::string &S) : DIEValue(isString), String(S) {}
Jim Laskey063e7652006-01-17 17:31:53 +0000190
Jim Laskey0d086af2006-02-27 12:43:29 +0000191 // Implement isa/cast/dyncast.
192 static bool classof(const DIEString *) { return true; }
193 static bool classof(const DIEValue *S) { return S->Type == isString; }
194
195 /// EmitValue - Emit string value.
196 ///
197 virtual void EmitValue(const DwarfWriter &DW, unsigned Form) const;
198
199 /// SizeOf - Determine size of string value in bytes.
200 ///
201 virtual unsigned SizeOf(const DwarfWriter &DW, unsigned Form) const;
202};
Jim Laskey063e7652006-01-17 17:31:53 +0000203
Jim Laskey0d086af2006-02-27 12:43:29 +0000204//===----------------------------------------------------------------------===//
205// DIEDwarfLabel - A Dwarf internal label expression DIE.
206//
207struct DIEDwarfLabel : public DIEValue {
208 const DWLabel Label;
209
210 DIEDwarfLabel(const DWLabel &L) : DIEValue(isLabel), Label(L) {}
Jim Laskey063e7652006-01-17 17:31:53 +0000211
Jim Laskey0d086af2006-02-27 12:43:29 +0000212 // Implement isa/cast/dyncast.
213 static bool classof(const DIEDwarfLabel *) { return true; }
214 static bool classof(const DIEValue *L) { return L->Type == isLabel; }
215
216 /// EmitValue - Emit label value.
217 ///
218 virtual void EmitValue(const DwarfWriter &DW, unsigned Form) const;
219
220 /// SizeOf - Determine size of label value in bytes.
221 ///
222 virtual unsigned SizeOf(const DwarfWriter &DW, unsigned Form) const;
223};
Jim Laskey063e7652006-01-17 17:31:53 +0000224
Jim Laskey063e7652006-01-17 17:31:53 +0000225
Jim Laskey0d086af2006-02-27 12:43:29 +0000226//===----------------------------------------------------------------------===//
227// DIEObjectLabel - A label to an object in code or data.
228//
229struct DIEObjectLabel : public DIEValue {
230 const std::string Label;
231
232 DIEObjectLabel(const std::string &L) : DIEValue(isAsIsLabel), Label(L) {}
Jim Laskey063e7652006-01-17 17:31:53 +0000233
Jim Laskey0d086af2006-02-27 12:43:29 +0000234 // Implement isa/cast/dyncast.
235 static bool classof(const DIEObjectLabel *) { return true; }
236 static bool classof(const DIEValue *L) { return L->Type == isAsIsLabel; }
237
238 /// EmitValue - Emit label value.
239 ///
240 virtual void EmitValue(const DwarfWriter &DW, unsigned Form) const;
241
242 /// SizeOf - Determine size of label value in bytes.
243 ///
244 virtual unsigned SizeOf(const DwarfWriter &DW, unsigned Form) const;
245};
Jim Laskey063e7652006-01-17 17:31:53 +0000246
Jim Laskey0d086af2006-02-27 12:43:29 +0000247//===----------------------------------------------------------------------===//
248// DIEDelta - A simple label difference DIE.
249//
250struct DIEDelta : public DIEValue {
251 const DWLabel LabelHi;
252 const DWLabel LabelLo;
253
254 DIEDelta(const DWLabel &Hi, const DWLabel &Lo)
255 : DIEValue(isDelta), LabelHi(Hi), LabelLo(Lo) {}
Jim Laskey063e7652006-01-17 17:31:53 +0000256
Jim Laskey0d086af2006-02-27 12:43:29 +0000257 // Implement isa/cast/dyncast.
258 static bool classof(const DIEDelta *) { return true; }
259 static bool classof(const DIEValue *D) { return D->Type == isDelta; }
260
261 /// EmitValue - Emit delta value.
262 ///
263 virtual void EmitValue(const DwarfWriter &DW, unsigned Form) const;
264
265 /// SizeOf - Determine size of delta value in bytes.
266 ///
267 virtual unsigned SizeOf(const DwarfWriter &DW, unsigned Form) const;
268};
Jim Laskey063e7652006-01-17 17:31:53 +0000269
Jim Laskey0d086af2006-02-27 12:43:29 +0000270//===----------------------------------------------------------------------===//
271// DIEntry - A pointer to a debug information entry.
272//
273struct DIEntry : public DIEValue {
274 DIE *Entry;
275
276 DIEntry(DIE *E) : DIEValue(isEntry), Entry(E) {}
277
278 // Implement isa/cast/dyncast.
279 static bool classof(const DIEntry *) { return true; }
280 static bool classof(const DIEValue *E) { return E->Type == isEntry; }
281
282 /// EmitValue - Emit delta value.
283 ///
284 virtual void EmitValue(const DwarfWriter &DW, unsigned Form) const;
285
286 /// SizeOf - Determine size of delta value in bytes.
287 ///
288 virtual unsigned SizeOf(const DwarfWriter &DW, unsigned Form) const;
289};
290
291//===----------------------------------------------------------------------===//
292// DIE - A structured debug information entry. Has an abbreviation which
293// describes it's organization.
294class DIE {
295private:
296 DIEAbbrev *Abbrev; // Temporary buffer for abbreviation.
297 unsigned AbbrevID; // Decribing abbreviation ID.
298 unsigned Offset; // Offset in debug info section.
299 unsigned Size; // Size of instance + children.
300 std::vector<DIE *> Children; // Children DIEs.
301 std::vector<DIEValue *> Values; // Attributes values.
302
303public:
304 DIE(unsigned Tag);
305 ~DIE();
306
307 // Accessors
308 unsigned getAbbrevID() const { return AbbrevID; }
309 unsigned getOffset() const { return Offset; }
310 unsigned getSize() const { return Size; }
311 const std::vector<DIE *> &getChildren() const { return Children; }
312 const std::vector<DIEValue *> &getValues() const { return Values; }
313 void setOffset(unsigned O) { Offset = O; }
314 void setSize(unsigned S) { Size = S; }
315
316 /// SiblingOffset - Return the offset of the debug information entry's
317 /// sibling.
318 unsigned SiblingOffset() const { return Offset + Size; }
319
320 /// AddUInt - Add an unsigned integer attribute data and value.
321 ///
322 void AddUInt(unsigned Attribute, unsigned Form, uint64_t Integer);
323
324 /// AddSInt - Add an signed integer attribute data and value.
325 ///
326 void AddSInt(unsigned Attribute, unsigned Form, int64_t Integer);
327
328 /// AddString - Add a std::string attribute data and value.
329 ///
330 void AddString(unsigned Attribute, unsigned Form,
331 const std::string &String);
332
333 /// AddLabel - Add a Dwarf label attribute data and value.
334 ///
335 void AddLabel(unsigned Attribute, unsigned Form, const DWLabel &Label);
336
337 /// AddObjectLabel - Add a non-Dwarf label attribute data and value.
338 ///
339 void AddObjectLabel(unsigned Attribute, unsigned Form,
340 const std::string &Label);
341
342 /// AddDelta - Add a label delta attribute data and value.
343 ///
344 void AddDelta(unsigned Attribute, unsigned Form,
345 const DWLabel &Hi, const DWLabel &Lo);
346
347 /// AddDIEntry - Add a DIE attribute data and value.
348 ///
349 void AddDIEntry(unsigned Attribute, unsigned Form, DIE *Entry);
350
351 /// Complete - Indicate that all attributes have been added and
352 /// ready to get an abbreviation ID.
353 ///
354 void Complete(DwarfWriter &DW);
355
356 /// AddChild - Add a child to the DIE.
357 void AddChild(DIE *Child);
358};
359
360} // End of namespace llvm
Jim Laskey063e7652006-01-17 17:31:53 +0000361
362//===----------------------------------------------------------------------===//
363
Jim Laskeyd18e2892006-01-20 20:34:06 +0000364/// operator== - Used by UniqueVector to locate entry.
365///
366bool DIEAbbrev::operator==(const DIEAbbrev &DA) const {
367 if (Tag != DA.Tag) return false;
368 if (ChildrenFlag != DA.ChildrenFlag) return false;
369 if (Data.size() != DA.Data.size()) return false;
370
Jim Laskey52060a02006-01-24 00:49:18 +0000371 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
Jim Laskey63ae85f2006-01-21 01:13:18 +0000372 if (Data[i] != DA.Data[i]) return false;
Jim Laskeyd18e2892006-01-20 20:34:06 +0000373 }
374
375 return true;
376}
377
378/// operator< - Used by UniqueVector to locate entry.
379///
380bool DIEAbbrev::operator<(const DIEAbbrev &DA) const {
381 if (Tag != DA.Tag) return Tag < DA.Tag;
382 if (ChildrenFlag != DA.ChildrenFlag) return ChildrenFlag < DA.ChildrenFlag;
383 if (Data.size() != DA.Data.size()) return Data.size() < DA.Data.size();
384
Jim Laskey52060a02006-01-24 00:49:18 +0000385 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
Jim Laskey63ae85f2006-01-21 01:13:18 +0000386 if (Data[i] != DA.Data[i]) return Data[i] < DA.Data[i];
Jim Laskeyd18e2892006-01-20 20:34:06 +0000387 }
388
389 return false;
390}
391
392/// Emit - Print the abbreviation using the specified Dwarf writer.
393///
394void DIEAbbrev::Emit(const DwarfWriter &DW) const {
395 // Emit its Dwarf tag type.
396 DW.EmitULEB128Bytes(Tag);
397 DW.EOL(TagString(Tag));
398
399 // Emit whether it has children DIEs.
400 DW.EmitULEB128Bytes(ChildrenFlag);
401 DW.EOL(ChildrenString(ChildrenFlag));
402
403 // For each attribute description.
Jim Laskey52060a02006-01-24 00:49:18 +0000404 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
Jim Laskeyd18e2892006-01-20 20:34:06 +0000405 const DIEAbbrevData &AttrData = Data[i];
406
407 // Emit attribute type.
408 DW.EmitULEB128Bytes(AttrData.getAttribute());
409 DW.EOL(AttributeString(AttrData.getAttribute()));
410
411 // Emit form type.
412 DW.EmitULEB128Bytes(AttrData.getForm());
413 DW.EOL(FormEncodingString(AttrData.getForm()));
414 }
415
416 // Mark end of abbreviation.
417 DW.EmitULEB128Bytes(0); DW.EOL("EOM(1)");
418 DW.EmitULEB128Bytes(0); DW.EOL("EOM(2)");
419}
420
421#ifndef NDEBUG
422 void DIEAbbrev::print(std::ostream &O) {
423 O << "Abbreviation @"
Jeff Cohen05ebc8d2006-01-25 17:18:50 +0000424 << std::hex << (intptr_t)this << std::dec
Jim Laskeyd18e2892006-01-20 20:34:06 +0000425 << " "
426 << TagString(Tag)
427 << " "
428 << ChildrenString(ChildrenFlag)
429 << "\n";
430
Jim Laskey52060a02006-01-24 00:49:18 +0000431 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
Jim Laskeyd18e2892006-01-20 20:34:06 +0000432 O << " "
433 << AttributeString(Data[i].getAttribute())
434 << " "
435 << FormEncodingString(Data[i].getForm())
436 << "\n";
437 }
438 }
439 void DIEAbbrev::dump() { print(std::cerr); }
440#endif
441
442//===----------------------------------------------------------------------===//
443
Jim Laskey063e7652006-01-17 17:31:53 +0000444/// EmitValue - Emit integer of appropriate size.
445///
446void DIEInteger::EmitValue(const DwarfWriter &DW, unsigned Form) const {
447 switch (Form) {
Jim Laskey40020172006-01-20 21:02:36 +0000448 case DW_FORM_flag: // Fall thru
Jim Laskeyda427fa2006-01-27 20:31:25 +0000449 case DW_FORM_data1: DW.EmitInt8(Integer); break;
450 case DW_FORM_data2: DW.EmitInt16(Integer); break;
451 case DW_FORM_data4: DW.EmitInt32(Integer); break;
452 case DW_FORM_data8: DW.EmitInt64(Integer); break;
Jim Laskey40020172006-01-20 21:02:36 +0000453 case DW_FORM_udata: DW.EmitULEB128Bytes(Integer); break;
454 case DW_FORM_sdata: DW.EmitSLEB128Bytes(Integer); break;
Jim Laskey063e7652006-01-17 17:31:53 +0000455 default: assert(0 && "DIE Value form not supported yet"); break;
456 }
457}
458
459/// SizeOf - Determine size of integer value in bytes.
460///
461unsigned DIEInteger::SizeOf(const DwarfWriter &DW, unsigned Form) const {
462 switch (Form) {
Jim Laskeyd18e2892006-01-20 20:34:06 +0000463 case DW_FORM_flag: // Fall thru
Jim Laskey063e7652006-01-17 17:31:53 +0000464 case DW_FORM_data1: return sizeof(int8_t);
465 case DW_FORM_data2: return sizeof(int16_t);
466 case DW_FORM_data4: return sizeof(int32_t);
Jim Laskeyd8f77ba2006-01-27 15:20:54 +0000467 case DW_FORM_data8: return sizeof(int64_t);
Jim Laskey40020172006-01-20 21:02:36 +0000468 case DW_FORM_udata: return DW.SizeULEB128(Integer);
469 case DW_FORM_sdata: return DW.SizeSLEB128(Integer);
Jim Laskey063e7652006-01-17 17:31:53 +0000470 default: assert(0 && "DIE Value form not supported yet"); break;
471 }
472 return 0;
473}
474
475//===----------------------------------------------------------------------===//
476
477/// EmitValue - Emit string value.
478///
479void DIEString::EmitValue(const DwarfWriter &DW, unsigned Form) const {
Jim Laskeyd18e2892006-01-20 20:34:06 +0000480 DW.EmitString(String);
Jim Laskey063e7652006-01-17 17:31:53 +0000481}
482
483/// SizeOf - Determine size of string value in bytes.
484///
485unsigned DIEString::SizeOf(const DwarfWriter &DW, unsigned Form) const {
Jim Laskey40020172006-01-20 21:02:36 +0000486 return String.size() + sizeof(char); // sizeof('\0');
Jim Laskey063e7652006-01-17 17:31:53 +0000487}
488
489//===----------------------------------------------------------------------===//
490
491/// EmitValue - Emit label value.
492///
Jim Laskey52060a02006-01-24 00:49:18 +0000493void DIEDwarfLabel::EmitValue(const DwarfWriter &DW, unsigned Form) const {
Jim Laskeyd18e2892006-01-20 20:34:06 +0000494 DW.EmitReference(Label);
Jim Laskey063e7652006-01-17 17:31:53 +0000495}
496
497/// SizeOf - Determine size of label value in bytes.
498///
Jim Laskey52060a02006-01-24 00:49:18 +0000499unsigned DIEDwarfLabel::SizeOf(const DwarfWriter &DW, unsigned Form) const {
Jim Laskey063e7652006-01-17 17:31:53 +0000500 return DW.getAddressSize();
501}
502
503//===----------------------------------------------------------------------===//
504
Jim Laskeyd18e2892006-01-20 20:34:06 +0000505/// EmitValue - Emit label value.
506///
Jim Laskey52060a02006-01-24 00:49:18 +0000507void DIEObjectLabel::EmitValue(const DwarfWriter &DW, unsigned Form) const {
Jim Laskeyda427fa2006-01-27 20:31:25 +0000508 DW.EmitInt8(sizeof(int8_t) + DW.getAddressSize());
Jim Laskey52060a02006-01-24 00:49:18 +0000509 DW.EOL("DW_FORM_block1 length");
510
Jim Laskeyda427fa2006-01-27 20:31:25 +0000511 DW.EmitInt8(DW_OP_addr);
Jim Laskey52060a02006-01-24 00:49:18 +0000512 DW.EOL("DW_OP_addr");
513
Jim Laskeyd18e2892006-01-20 20:34:06 +0000514 DW.EmitReference(Label);
515}
516
517/// SizeOf - Determine size of label value in bytes.
518///
Jim Laskey52060a02006-01-24 00:49:18 +0000519unsigned DIEObjectLabel::SizeOf(const DwarfWriter &DW, unsigned Form) const {
520 return sizeof(int8_t) + sizeof(int8_t) + DW.getAddressSize();
Jim Laskeyd18e2892006-01-20 20:34:06 +0000521}
522
523//===----------------------------------------------------------------------===//
524
Jim Laskey063e7652006-01-17 17:31:53 +0000525/// EmitValue - Emit delta value.
526///
527void DIEDelta::EmitValue(const DwarfWriter &DW, unsigned Form) const {
Jim Laskeyd18e2892006-01-20 20:34:06 +0000528 DW.EmitDifference(LabelHi, LabelLo);
Jim Laskey063e7652006-01-17 17:31:53 +0000529}
530
531/// SizeOf - Determine size of delta value in bytes.
532///
533unsigned DIEDelta::SizeOf(const DwarfWriter &DW, unsigned Form) const {
534 return DW.getAddressSize();
535}
536
537//===----------------------------------------------------------------------===//
Jim Laskeyd18e2892006-01-20 20:34:06 +0000538/// EmitValue - Emit extry offset.
539///
540void DIEntry::EmitValue(const DwarfWriter &DW, unsigned Form) const {
Jim Laskeyda427fa2006-01-27 20:31:25 +0000541 DW.EmitInt32(Entry->getOffset());
Jim Laskeyd18e2892006-01-20 20:34:06 +0000542}
543
544/// SizeOf - Determine size of label value in bytes.
545///
546unsigned DIEntry::SizeOf(const DwarfWriter &DW, unsigned Form) const {
547 return sizeof(int32_t);
548}
549
550//===----------------------------------------------------------------------===//
551
Jim Laskey0420f2a2006-02-22 19:02:11 +0000552DIE::DIE(unsigned Tag)
553: Abbrev(new DIEAbbrev(Tag, DW_CHILDREN_no))
Jim Laskeyd18e2892006-01-20 20:34:06 +0000554, AbbrevID(0)
555, Offset(0)
556, Size(0)
Jim Laskeyd18e2892006-01-20 20:34:06 +0000557, Children()
558, Values()
559{}
560
561DIE::~DIE() {
562 if (Abbrev) delete Abbrev;
563
Jim Laskey52060a02006-01-24 00:49:18 +0000564 for (unsigned i = 0, N = Children.size(); i < N; ++i) {
Jim Laskeyd18e2892006-01-20 20:34:06 +0000565 delete Children[i];
566 }
567
Jim Laskey52060a02006-01-24 00:49:18 +0000568 for (unsigned j = 0, M = Values.size(); j < M; ++j) {
Jim Laskeyd18e2892006-01-20 20:34:06 +0000569 delete Values[j];
570 }
Jim Laskeyd18e2892006-01-20 20:34:06 +0000571}
572
Jim Laskeyd8f77ba2006-01-27 15:20:54 +0000573/// AddUInt - Add an unsigned integer attribute data and value.
Jim Laskeyd18e2892006-01-20 20:34:06 +0000574///
Jim Laskeyd8f77ba2006-01-27 15:20:54 +0000575void DIE::AddUInt(unsigned Attribute, unsigned Form, uint64_t Integer) {
Jim Laskey40020172006-01-20 21:02:36 +0000576 if (Form == 0) {
Jim Laskey40020172006-01-20 21:02:36 +0000577 if ((unsigned char)Integer == Integer) Form = DW_FORM_data1;
578 else if ((unsigned short)Integer == Integer) Form = DW_FORM_data2;
Jim Laskeyd8f77ba2006-01-27 15:20:54 +0000579 else if ((unsigned int)Integer == Integer) Form = DW_FORM_data4;
580 else Form = DW_FORM_data8;
581 }
582 Abbrev->AddAttribute(Attribute, Form);
583 Values.push_back(new DIEInteger(Integer));
584}
585
586/// AddSInt - Add an signed integer attribute data and value.
587///
588void DIE::AddSInt(unsigned Attribute, unsigned Form, int64_t Integer) {
589 if (Form == 0) {
590 if ((char)Integer == Integer) Form = DW_FORM_data1;
591 else if ((short)Integer == Integer) Form = DW_FORM_data2;
592 else if ((int)Integer == Integer) Form = DW_FORM_data4;
593 else Form = DW_FORM_data8;
Jim Laskey40020172006-01-20 21:02:36 +0000594 }
Jim Laskeyd18e2892006-01-20 20:34:06 +0000595 Abbrev->AddAttribute(Attribute, Form);
596 Values.push_back(new DIEInteger(Integer));
597}
598
599/// AddString - Add a std::string attribute data and value.
600///
601void DIE::AddString(unsigned Attribute, unsigned Form,
602 const std::string &String) {
603 Abbrev->AddAttribute(Attribute, Form);
604 Values.push_back(new DIEString(String));
605}
606
607/// AddLabel - Add a Dwarf label attribute data and value.
608///
609void DIE::AddLabel(unsigned Attribute, unsigned Form,
610 const DWLabel &Label) {
611 Abbrev->AddAttribute(Attribute, Form);
Jim Laskey52060a02006-01-24 00:49:18 +0000612 Values.push_back(new DIEDwarfLabel(Label));
Jim Laskeyd18e2892006-01-20 20:34:06 +0000613}
614
Jim Laskey52060a02006-01-24 00:49:18 +0000615/// AddObjectLabel - Add an non-Dwarf label attribute data and value.
Jim Laskeyd18e2892006-01-20 20:34:06 +0000616///
Jim Laskey52060a02006-01-24 00:49:18 +0000617void DIE::AddObjectLabel(unsigned Attribute, unsigned Form,
618 const std::string &Label) {
Jim Laskeyd18e2892006-01-20 20:34:06 +0000619 Abbrev->AddAttribute(Attribute, Form);
Jim Laskey52060a02006-01-24 00:49:18 +0000620 Values.push_back(new DIEObjectLabel(Label));
Jim Laskeyd18e2892006-01-20 20:34:06 +0000621}
622
623/// AddDelta - Add a label delta attribute data and value.
624///
625void DIE::AddDelta(unsigned Attribute, unsigned Form,
626 const DWLabel &Hi, const DWLabel &Lo) {
627 Abbrev->AddAttribute(Attribute, Form);
628 Values.push_back(new DIEDelta(Hi, Lo));
629}
630
631/// AddDIEntry - Add a DIE attribute data and value.
632///
633void DIE::AddDIEntry(unsigned Attribute,
634 unsigned Form, DIE *Entry) {
635 Abbrev->AddAttribute(Attribute, Form);
636 Values.push_back(new DIEntry(Entry));
637}
638
639/// Complete - Indicate that all attributes have been added and ready to get an
640/// abbreviation ID.
641void DIE::Complete(DwarfWriter &DW) {
642 AbbrevID = DW.NewAbbreviation(Abbrev);
643 delete Abbrev;
644 Abbrev = NULL;
645}
646
647/// AddChild - Add a child to the DIE.
648///
649void DIE::AddChild(DIE *Child) {
Jim Laskey0420f2a2006-02-22 19:02:11 +0000650 assert(Abbrev && "Adding children without an abbreviation");
651 Abbrev->setChildrenFlag(DW_CHILDREN_yes);
Jim Laskeyd18e2892006-01-20 20:34:06 +0000652 Children.push_back(Child);
653}
654
655//===----------------------------------------------------------------------===//
656
Jim Laskey0420f2a2006-02-22 19:02:11 +0000657/// DWContext
Jim Laskeyd18e2892006-01-20 20:34:06 +0000658
659//===----------------------------------------------------------------------===//
Jim Laskey063e7652006-01-17 17:31:53 +0000660
661/// PrintHex - Print a value as a hexidecimal value.
662///
663void DwarfWriter::PrintHex(int Value) const {
664 O << "0x" << std::hex << Value << std::dec;
665}
666
667/// EOL - Print a newline character to asm stream. If a comment is present
668/// then it will be printed first. Comments should not contain '\n'.
669void DwarfWriter::EOL(const std::string &Comment) const {
670 if (DwarfVerbose) {
671 O << "\t"
672 << Asm->CommentString
673 << " "
674 << Comment;
675 }
676 O << "\n";
677}
Jim Laskeya7cea6f2006-01-04 13:52:30 +0000678
679/// EmitULEB128Bytes - Emit an assembler byte data directive to compose an
Jim Laskey063e7652006-01-17 17:31:53 +0000680/// unsigned leb128 value.
681void DwarfWriter::EmitULEB128Bytes(unsigned Value) const {
Jim Laskeya7cea6f2006-01-04 13:52:30 +0000682 if (hasLEB128) {
683 O << "\t.uleb128\t"
684 << Value;
685 } else {
Jim Laskeyb2efb852006-01-04 22:28:25 +0000686 O << Asm->Data8bitsDirective;
Jim Laskey063e7652006-01-17 17:31:53 +0000687 PrintULEB128(Value);
Jim Laskeya7cea6f2006-01-04 13:52:30 +0000688 }
Jim Laskeya7cea6f2006-01-04 13:52:30 +0000689}
690
691/// EmitSLEB128Bytes - Emit an assembler byte data directive to compose a
Jim Laskey063e7652006-01-17 17:31:53 +0000692/// signed leb128 value.
693void DwarfWriter::EmitSLEB128Bytes(int Value) const {
Jim Laskeya7cea6f2006-01-04 13:52:30 +0000694 if (hasLEB128) {
695 O << "\t.sleb128\t"
696 << Value;
697 } else {
Jim Laskeyb2efb852006-01-04 22:28:25 +0000698 O << Asm->Data8bitsDirective;
Jim Laskey063e7652006-01-17 17:31:53 +0000699 PrintSLEB128(Value);
Jim Laskeya7cea6f2006-01-04 13:52:30 +0000700 }
Jim Laskeya7cea6f2006-01-04 13:52:30 +0000701}
702
Jim Laskey063e7652006-01-17 17:31:53 +0000703/// PrintULEB128 - Print a series of hexidecimal values (separated by commas)
Jim Laskeyb2efb852006-01-04 22:28:25 +0000704/// representing an unsigned leb128 value.
Jim Laskey063e7652006-01-17 17:31:53 +0000705void DwarfWriter::PrintULEB128(unsigned Value) const {
Jim Laskeyb2efb852006-01-04 22:28:25 +0000706 do {
707 unsigned Byte = Value & 0x7f;
708 Value >>= 7;
709 if (Value) Byte |= 0x80;
Jim Laskey063e7652006-01-17 17:31:53 +0000710 PrintHex(Byte);
Jim Laskeyb2efb852006-01-04 22:28:25 +0000711 if (Value) O << ", ";
712 } while (Value);
713}
714
Jim Laskey063e7652006-01-17 17:31:53 +0000715/// SizeULEB128 - Compute the number of bytes required for an unsigned leb128
716/// value.
717unsigned DwarfWriter::SizeULEB128(unsigned Value) {
718 unsigned Size = 0;
719 do {
720 Value >>= 7;
721 Size += sizeof(int8_t);
722 } while (Value);
723 return Size;
724}
725
726/// PrintSLEB128 - Print a series of hexidecimal values (separated by commas)
Jim Laskeyb2efb852006-01-04 22:28:25 +0000727/// representing a signed leb128 value.
Jim Laskey063e7652006-01-17 17:31:53 +0000728void DwarfWriter::PrintSLEB128(int Value) const {
Jim Laskeyb2efb852006-01-04 22:28:25 +0000729 int Sign = Value >> (8 * sizeof(Value) - 1);
730 bool IsMore;
Jim Laskeya7cea6f2006-01-04 13:52:30 +0000731
Jim Laskeyb2efb852006-01-04 22:28:25 +0000732 do {
733 unsigned Byte = Value & 0x7f;
734 Value >>= 7;
735 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
736 if (IsMore) Byte |= 0x80;
Jim Laskey063e7652006-01-17 17:31:53 +0000737 PrintHex(Byte);
Jim Laskeyb2efb852006-01-04 22:28:25 +0000738 if (IsMore) O << ", ";
739 } while (IsMore);
740}
741
Jim Laskey063e7652006-01-17 17:31:53 +0000742/// SizeSLEB128 - Compute the number of bytes required for a signed leb128
743/// value.
744unsigned DwarfWriter::SizeSLEB128(int Value) {
745 unsigned Size = 0;
746 int Sign = Value >> (8 * sizeof(Value) - 1);
747 bool IsMore;
748
749 do {
750 unsigned Byte = Value & 0x7f;
751 Value >>= 7;
752 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
753 Size += sizeof(int8_t);
754 } while (IsMore);
755 return Size;
756}
757
Jim Laskeyda427fa2006-01-27 20:31:25 +0000758/// EmitInt8 - Emit a byte directive and value.
Jim Laskeyb2efb852006-01-04 22:28:25 +0000759///
Jim Laskeyda427fa2006-01-27 20:31:25 +0000760void DwarfWriter::EmitInt8(int Value) const {
Jim Laskey063e7652006-01-17 17:31:53 +0000761 O << Asm->Data8bitsDirective;
Jim Laskey0420f2a2006-02-22 19:02:11 +0000762 PrintHex(Value & 0xFF);
Jim Laskey063e7652006-01-17 17:31:53 +0000763}
764
Jim Laskeyda427fa2006-01-27 20:31:25 +0000765/// EmitInt16 - Emit a short directive and value.
Jim Laskey063e7652006-01-17 17:31:53 +0000766///
Jim Laskeyda427fa2006-01-27 20:31:25 +0000767void DwarfWriter::EmitInt16(int Value) const {
Jim Laskey063e7652006-01-17 17:31:53 +0000768 O << Asm->Data16bitsDirective;
Jim Laskey0420f2a2006-02-22 19:02:11 +0000769 PrintHex(Value & 0xFFFF);
Jim Laskey063e7652006-01-17 17:31:53 +0000770}
771
Jim Laskeyda427fa2006-01-27 20:31:25 +0000772/// EmitInt32 - Emit a long directive and value.
Jim Laskey063e7652006-01-17 17:31:53 +0000773///
Jim Laskeyda427fa2006-01-27 20:31:25 +0000774void DwarfWriter::EmitInt32(int Value) const {
Jim Laskey063e7652006-01-17 17:31:53 +0000775 O << Asm->Data32bitsDirective;
776 PrintHex(Value);
777}
778
Jim Laskeyda427fa2006-01-27 20:31:25 +0000779/// EmitInt64 - Emit a long long directive and value.
Jim Laskeyd8f77ba2006-01-27 15:20:54 +0000780///
Jim Laskeyda427fa2006-01-27 20:31:25 +0000781void DwarfWriter::EmitInt64(uint64_t Value) const {
Jim Laskeyd8f77ba2006-01-27 15:20:54 +0000782 if (Asm->Data64bitsDirective) {
783 O << Asm->Data64bitsDirective << "0x" << std::hex << Value << std::dec;
784 } else {
785 const TargetData &TD = Asm->TM.getTargetData();
786
787 if (TD.isBigEndian()) {
Jim Laskeyda427fa2006-01-27 20:31:25 +0000788 EmitInt32(unsigned(Value >> 32)); O << "\n";
789 EmitInt32(unsigned(Value));
Jim Laskeyd8f77ba2006-01-27 15:20:54 +0000790 } else {
Jim Laskeyda427fa2006-01-27 20:31:25 +0000791 EmitInt32(unsigned(Value)); O << "\n";
792 EmitInt32(unsigned(Value >> 32));
Jim Laskeyd8f77ba2006-01-27 15:20:54 +0000793 }
794 }
795}
796
Jim Laskey063e7652006-01-17 17:31:53 +0000797/// EmitString - Emit a string with quotes and a null terminator.
798/// Special characters are emitted properly. (Eg. '\t')
799void DwarfWriter::EmitString(const std::string &String) const {
800 O << Asm->AsciiDirective
801 << "\"";
Jim Laskey52060a02006-01-24 00:49:18 +0000802 for (unsigned i = 0, N = String.size(); i < N; ++i) {
Jim Laskey063e7652006-01-17 17:31:53 +0000803 unsigned char C = String[i];
804
805 if (!isascii(C) || iscntrl(C)) {
806 switch(C) {
807 case '\b': O << "\\b"; break;
808 case '\f': O << "\\f"; break;
809 case '\n': O << "\\n"; break;
810 case '\r': O << "\\r"; break;
811 case '\t': O << "\\t"; break;
812 default:
813 O << '\\';
814 O << char('0' + (C >> 6));
815 O << char('0' + (C >> 3));
816 O << char('0' + (C >> 0));
817 break;
818 }
819 } else if (C == '\"') {
820 O << "\\\"";
821 } else if (C == '\'') {
822 O << "\\\'";
823 } else {
824 O << C;
825 }
826 }
827 O << "\\0\"";
828}
829
830/// PrintLabelName - Print label name in form used by Dwarf writer.
831///
832void DwarfWriter::PrintLabelName(const char *Tag, unsigned Number) const {
Jim Laskeyb2efb852006-01-04 22:28:25 +0000833 O << Asm->PrivateGlobalPrefix
834 << "debug_"
Jim Laskey0420f2a2006-02-22 19:02:11 +0000835 << Tag;
836 if (Number) O << Number;
Jim Laskeyb2efb852006-01-04 22:28:25 +0000837}
838
Jim Laskey063e7652006-01-17 17:31:53 +0000839/// EmitLabel - Emit location label for internal use by Dwarf.
Jim Laskeyb2efb852006-01-04 22:28:25 +0000840///
Jim Laskey063e7652006-01-17 17:31:53 +0000841void DwarfWriter::EmitLabel(const char *Tag, unsigned Number) const {
842 PrintLabelName(Tag, Number);
Jim Laskeyb2efb852006-01-04 22:28:25 +0000843 O << ":\n";
844}
845
Jim Laskeye719a7c2006-01-18 16:54:26 +0000846/// EmitReference - Emit a reference to a label.
Jim Laskey063e7652006-01-17 17:31:53 +0000847///
Jim Laskeye719a7c2006-01-18 16:54:26 +0000848void DwarfWriter::EmitReference(const char *Tag, unsigned Number) const {
Jim Laskey063e7652006-01-17 17:31:53 +0000849 if (AddressSize == 4)
850 O << Asm->Data32bitsDirective;
851 else
852 O << Asm->Data64bitsDirective;
853
854 PrintLabelName(Tag, Number);
855}
Jim Laskey73683212006-01-21 00:59:54 +0000856void DwarfWriter::EmitReference(const std::string &Name) const {
Jim Laskeyd18e2892006-01-20 20:34:06 +0000857 if (AddressSize == 4)
858 O << Asm->Data32bitsDirective;
859 else
860 O << Asm->Data64bitsDirective;
861
862 O << Name;
863}
Jim Laskey063e7652006-01-17 17:31:53 +0000864
865/// EmitDifference - Emit an label difference as sizeof(pointer) value. Some
866/// assemblers do not accept absolute expressions with data directives, so there
867/// is an option (needsSet) to use an intermediary 'set' expression.
Jim Laskeyd18e2892006-01-20 20:34:06 +0000868void DwarfWriter::EmitDifference(const char *TagHi, unsigned NumberHi,
869 const char *TagLo, unsigned NumberLo) const {
Jim Laskey063e7652006-01-17 17:31:53 +0000870 if (needsSet) {
871 static unsigned SetCounter = 0;
Jim Laskeyd18e2892006-01-20 20:34:06 +0000872
Jim Laskey063e7652006-01-17 17:31:53 +0000873 O << "\t.set\t";
874 PrintLabelName("set", SetCounter);
875 O << ",";
Jim Laskeyd18e2892006-01-20 20:34:06 +0000876 PrintLabelName(TagHi, NumberHi);
Jim Laskey063e7652006-01-17 17:31:53 +0000877 O << "-";
Jim Laskeyd18e2892006-01-20 20:34:06 +0000878 PrintLabelName(TagLo, NumberLo);
Jim Laskey063e7652006-01-17 17:31:53 +0000879 O << "\n";
880
881 if (AddressSize == sizeof(int32_t))
882 O << Asm->Data32bitsDirective;
883 else
884 O << Asm->Data64bitsDirective;
885
886 PrintLabelName("set", SetCounter);
887
Jim Laskey52060a02006-01-24 00:49:18 +0000888 ++SetCounter;
Jim Laskey063e7652006-01-17 17:31:53 +0000889 } else {
890 if (AddressSize == sizeof(int32_t))
891 O << Asm->Data32bitsDirective;
892 else
893 O << Asm->Data64bitsDirective;
894
Jim Laskeyd18e2892006-01-20 20:34:06 +0000895 PrintLabelName(TagHi, NumberHi);
Jim Laskey063e7652006-01-17 17:31:53 +0000896 O << "-";
Jim Laskeyd18e2892006-01-20 20:34:06 +0000897 PrintLabelName(TagLo, NumberLo);
Jim Laskey063e7652006-01-17 17:31:53 +0000898 }
899}
900
Jim Laskeyd18e2892006-01-20 20:34:06 +0000901/// NewAbbreviation - Add the abbreviation to the Abbreviation vector.
Jim Laskey063e7652006-01-17 17:31:53 +0000902///
Jim Laskeyd18e2892006-01-20 20:34:06 +0000903unsigned DwarfWriter::NewAbbreviation(DIEAbbrev *Abbrev) {
904 return Abbreviations.insert(*Abbrev);
905}
906
907/// NewString - Add a string to the constant pool and returns a label.
908///
909DWLabel DwarfWriter::NewString(const std::string &String) {
910 unsigned StringID = StringPool.insert(String);
911 return DWLabel("string", StringID);
912}
913
Jim Laskey0420f2a2006-02-22 19:02:11 +0000914/// NewBasicType - Creates a new basic type if necessary, then adds to the
915/// owner.
916/// FIXME - Should never be needed.
917DIE *DwarfWriter::NewBasicType(DIE *Owner, Type *Ty) {
918 DIE *&Slot = TypeToDieMap[Ty];
919 if (Slot) return Slot;
920
921 const char *Name;
922 unsigned Size;
923 unsigned Encoding = 0;
924
925 switch (Ty->getTypeID()) {
926 case Type::UByteTyID:
927 Name = "unsigned char";
928 Size = 1;
929 Encoding = DW_ATE_unsigned_char;
930 break;
931 case Type::SByteTyID:
932 Name = "char";
933 Size = 1;
934 Encoding = DW_ATE_signed_char;
935 break;
936 case Type::UShortTyID:
937 Name = "unsigned short";
938 Size = 2;
939 Encoding = DW_ATE_unsigned;
940 break;
941 case Type::ShortTyID:
942 Name = "short";
943 Size = 2;
944 Encoding = DW_ATE_signed;
945 break;
946 case Type::UIntTyID:
947 Name = "unsigned int";
948 Size = 4;
949 Encoding = DW_ATE_unsigned;
950 break;
951 case Type::IntTyID:
952 Name = "int";
953 Size = 4;
954 Encoding = DW_ATE_signed;
955 break;
956 case Type::ULongTyID:
957 Name = "unsigned long long";
958 Size = 7;
959 Encoding = DW_ATE_unsigned;
960 break;
961 case Type::LongTyID:
962 Name = "long long";
963 Size = 7;
964 Encoding = DW_ATE_signed;
965 break;
966 case Type::FloatTyID:
967 Name = "float";
968 Size = 4;
969 Encoding = DW_ATE_float;
970 break;
971 case Type::DoubleTyID:
972 Name = "double";
973 Size = 8;
974 Encoding = DW_ATE_float;
975 break;
976 default:
977 // FIXME - handle more complex types.
978 Name = "unknown";
979 Size = 1;
980 Encoding = DW_ATE_address;
981 break;
982 }
983
984 // construct the type DIE.
985 Slot = new DIE(DW_TAG_base_type);
986 Slot->AddString(DW_AT_name, DW_FORM_string, Name);
987 Slot->AddUInt (DW_AT_byte_size, 0, Size);
988 Slot->AddUInt (DW_AT_encoding, DW_FORM_data1, Encoding);
989
990 // Add to context owner.
991 Owner->AddChild(Slot);
992
993 return Slot;
994}
995
Jim Laskeyd18e2892006-01-20 20:34:06 +0000996/// NewGlobalType - Make the type visible globally using the given name.
997///
998void DwarfWriter::NewGlobalType(const std::string &Name, DIE *Type) {
Jim Laskey52060a02006-01-24 00:49:18 +0000999 assert(!GlobalTypes[Name] && "Duplicate global type");
Jim Laskeyd18e2892006-01-20 20:34:06 +00001000 GlobalTypes[Name] = Type;
1001}
1002
1003/// NewGlobalEntity - Make the entity visible globally using the given name.
1004///
1005void DwarfWriter::NewGlobalEntity(const std::string &Name, DIE *Entity) {
Jim Laskey52060a02006-01-24 00:49:18 +00001006 assert(!GlobalEntities[Name] && "Duplicate global variable or function");
Jim Laskeyd18e2892006-01-20 20:34:06 +00001007 GlobalEntities[Name] = Entity;
Jim Laskey063e7652006-01-17 17:31:53 +00001008}
1009
Jim Laskeyf4afdd92006-02-23 16:58:18 +00001010/// NewType - Create a new type DIE.
1011///
1012DIE *DwarfWriter::NewType(DIE *Unit, TypeDesc *TyDesc) {
Jim Laskey69906002006-02-24 16:46:40 +00001013 // FIXME - hack to get around NULL types short term.
1014 if (!TyDesc) return NewBasicType(Unit, Type::IntTy);
1015
Jim Laskeyf4afdd92006-02-23 16:58:18 +00001016 // Check for pre-existence.
1017 DIE *&Slot = DescToDieMap[TyDesc];
1018 if (Slot) return Slot;
1019
1020 // Get core information.
1021 const std::string &Name = TyDesc->getName();
1022 // FIXME - handle larger sizes.
1023 unsigned Size = TyDesc->getSize() >> 3;
1024
Jim Laskey434b40b2006-02-23 22:37:30 +00001025 DIE *Ty = NULL;
Jim Laskeyf4afdd92006-02-23 16:58:18 +00001026
Jim Laskey434b40b2006-02-23 22:37:30 +00001027 if (BasicTypeDesc *BasicTy = dyn_cast<BasicTypeDesc>(TyDesc)) {
Jim Laskey69906002006-02-24 16:46:40 +00001028 // Fundamental types like int, float, bool
Jim Laskey434b40b2006-02-23 22:37:30 +00001029 Slot = Ty = new DIE(DW_TAG_base_type);
1030 unsigned Encoding = BasicTy->getEncoding();
1031 Ty->AddUInt (DW_AT_encoding, DW_FORM_data1, Encoding);
Jim Laskey69906002006-02-24 16:46:40 +00001032 } else if (DerivedTypeDesc *DerivedTy = dyn_cast<DerivedTypeDesc>(TyDesc)) {
1033 // Determine which derived type.
1034 unsigned T = 0;
1035 switch (DerivedTy->getTag()) {
1036 case DI_TAG_typedef: T = DW_TAG_typedef; break;
1037 case DI_TAG_pointer: T = DW_TAG_pointer_type; break;
1038 case DI_TAG_reference: T = DW_TAG_reference_type; break;
1039 default: assert( 0 && "Unknown tag on derived type");
1040 }
Jim Laskeyf4afdd92006-02-23 16:58:18 +00001041
Jim Laskey69906002006-02-24 16:46:40 +00001042 // Create specific DIE.
1043 Slot = Ty = new DIE(T);
1044
1045 // Map to main type, void will not have a type.
1046 if (TypeDesc *FromTy = DerivedTy->getFromType()) {
1047 Ty->AddDIEntry(DW_AT_type, DW_FORM_ref4, NewType(Unit, FromTy));
1048 }
Jim Laskeyf4afdd92006-02-23 16:58:18 +00001049 }
Jim Laskey434b40b2006-02-23 22:37:30 +00001050
1051 assert(Ty && "Type not supported yet");
Jim Laskeyf4afdd92006-02-23 16:58:18 +00001052
Jim Laskey69906002006-02-24 16:46:40 +00001053 // Add size if non-zero (derived types don't have a size.)
Jim Laskey434b40b2006-02-23 22:37:30 +00001054 if (Size) Ty->AddUInt(DW_AT_byte_size, 0, Size);
Jim Laskey69906002006-02-24 16:46:40 +00001055 // Add name if not anonymous or intermediate type.
Jim Laskey434b40b2006-02-23 22:37:30 +00001056 if (!Name.empty()) Ty->AddString(DW_AT_name, DW_FORM_string, Name);
Jim Laskey69906002006-02-24 16:46:40 +00001057 // Add source line info if present.
1058 if (CompileUnitDesc *File = TyDesc->getFile()) {
1059 unsigned FileID = DebugInfo->RecordSource(File);
1060 int Line = TyDesc->getLine();
1061 Ty->AddUInt(DW_AT_decl_file, 0, FileID);
1062 Ty->AddUInt(DW_AT_decl_line, 0, Line);
1063 }
Jim Laskey434b40b2006-02-23 22:37:30 +00001064
Jim Laskeyf4afdd92006-02-23 16:58:18 +00001065 // Add to context owner.
Jim Laskey434b40b2006-02-23 22:37:30 +00001066 Unit->AddChild(Ty);
Jim Laskeyf4afdd92006-02-23 16:58:18 +00001067
1068 return Slot;
1069}
1070
1071/// NewCompileUnit - Create new compile unit DIE.
Jim Laskey063e7652006-01-17 17:31:53 +00001072///
Jim Laskey0420f2a2006-02-22 19:02:11 +00001073DIE *DwarfWriter::NewCompileUnit(CompileUnitDesc *CompileUnit) {
1074 // Check for pre-existence.
1075 DIE *&Slot = DescToDieMap[CompileUnit];
1076 if (Slot) return Slot;
1077
1078 DIE *Unit = new DIE(DW_TAG_compile_unit);
Jim Laskey063e7652006-01-17 17:31:53 +00001079 // FIXME - use the correct line set.
Jim Laskey0420f2a2006-02-22 19:02:11 +00001080 Unit->AddLabel (DW_AT_stmt_list, DW_FORM_data4, DWLabel("section_line", 0));
Jim Laskeyd18e2892006-01-20 20:34:06 +00001081 Unit->AddLabel (DW_AT_high_pc, DW_FORM_addr, DWLabel("text_end", 0));
1082 Unit->AddLabel (DW_AT_low_pc, DW_FORM_addr, DWLabel("text_begin", 0));
Jim Laskey86cbdba2006-02-06 15:33:21 +00001083 Unit->AddString(DW_AT_producer, DW_FORM_string, CompileUnit->getProducer());
1084 Unit->AddUInt (DW_AT_language, DW_FORM_data1, CompileUnit->getLanguage());
1085 Unit->AddString(DW_AT_name, DW_FORM_string, CompileUnit->getFileName());
1086 Unit->AddString(DW_AT_comp_dir, DW_FORM_string, CompileUnit->getDirectory());
Jim Laskey0420f2a2006-02-22 19:02:11 +00001087
1088 Slot = Unit;
Jim Laskey063e7652006-01-17 17:31:53 +00001089
Jim Laskeyd18e2892006-01-20 20:34:06 +00001090 return Unit;
Jim Laskey063e7652006-01-17 17:31:53 +00001091}
1092
Jim Laskey0420f2a2006-02-22 19:02:11 +00001093/// NewGlobalVariable - Add a new global variable DIE.
1094///
1095DIE *DwarfWriter::NewGlobalVariable(GlobalVariableDesc *GVD) {
1096 // Check for pre-existence.
1097 DIE *&Slot = DescToDieMap[GVD];
1098 if (Slot) return Slot;
1099
1100 // Get the compile unit context.
1101 CompileUnitDesc *CompileUnit =
1102 static_cast<CompileUnitDesc *>(GVD->getContext());
1103 DIE *Unit = NewCompileUnit(CompileUnit);
1104 // Get the global variable itself.
1105 GlobalVariable *GV = GVD->getGlobalVariable();
1106 // Generate the mangled name.
1107 std::string MangledName = Asm->Mang->getValueName(GV);
1108
1109 // Gather the details (simplify add attribute code.)
1110 const std::string &Name = GVD->getName();
1111 unsigned FileID = DebugInfo->RecordSource(CompileUnit);
1112 unsigned Line = GVD->getLine();
1113
Jim Laskeyf4afdd92006-02-23 16:58:18 +00001114 // Get the global's type.
1115 DIE *Type = NewType(Unit, GVD->getTypeDesc());
1116
1117 // Create the globale variable DIE.
Jim Laskey0420f2a2006-02-22 19:02:11 +00001118 DIE *VariableDie = new DIE(DW_TAG_variable);
1119 VariableDie->AddString (DW_AT_name, DW_FORM_string, Name);
1120 VariableDie->AddUInt (DW_AT_decl_file, 0, FileID);
1121 VariableDie->AddUInt (DW_AT_decl_line, 0, Line);
1122 VariableDie->AddDIEntry (DW_AT_type, DW_FORM_ref4, Type);
1123 VariableDie->AddUInt (DW_AT_external, DW_FORM_flag, 1);
1124 // FIXME - needs to be a proper expression.
1125 VariableDie->AddObjectLabel(DW_AT_location, DW_FORM_block1, MangledName);
1126
1127 // Add to map.
1128 Slot = VariableDie;
1129
1130 // Add to context owner.
1131 Unit->AddChild(VariableDie);
1132
1133 // Expose as global.
1134 NewGlobalEntity(Name, VariableDie);
1135
1136 return VariableDie;
1137}
1138
1139/// NewSubprogram - Add a new subprogram DIE.
1140///
1141DIE *DwarfWriter::NewSubprogram(SubprogramDesc *SPD) {
1142 // Check for pre-existence.
1143 DIE *&Slot = DescToDieMap[SPD];
1144 if (Slot) return Slot;
1145
1146 // Get the compile unit context.
1147 CompileUnitDesc *CompileUnit =
1148 static_cast<CompileUnitDesc *>(SPD->getContext());
1149 DIE *Unit = NewCompileUnit(CompileUnit);
1150
1151 // Gather the details (simplify add attribute code.)
1152 const std::string &Name = SPD->getName();
1153 unsigned FileID = DebugInfo->RecordSource(CompileUnit);
1154 // FIXME - faking the line for the time being.
1155 unsigned Line = 1;
1156
1157 // FIXME - faking the type for the time being.
1158 DIE *Type = NewBasicType(Unit, Type::IntTy);
1159
1160 DIE *SubprogramDie = new DIE(DW_TAG_variable);
1161 SubprogramDie->AddString (DW_AT_name, DW_FORM_string, Name);
1162 SubprogramDie->AddUInt (DW_AT_decl_file, 0, FileID);
1163 SubprogramDie->AddUInt (DW_AT_decl_line, 0, Line);
1164 SubprogramDie->AddDIEntry (DW_AT_type, DW_FORM_ref4, Type);
1165 SubprogramDie->AddUInt (DW_AT_external, DW_FORM_flag, 1);
1166
1167 // Add to map.
1168 Slot = SubprogramDie;
1169
1170 // Add to context owner.
1171 Unit->AddChild(SubprogramDie);
1172
1173 // Expose as global.
1174 NewGlobalEntity(Name, SubprogramDie);
1175
1176 return SubprogramDie;
1177}
1178
Jim Laskey063e7652006-01-17 17:31:53 +00001179/// EmitInitial - Emit initial Dwarf declarations. This is necessary for cc
1180/// tools to recognize the object file contains Dwarf information.
Jim Laskeyb2efb852006-01-04 22:28:25 +00001181///
1182void DwarfWriter::EmitInitial() const {
Jim Laskey063e7652006-01-17 17:31:53 +00001183 // Dwarf sections base addresses.
Jim Laskey0420f2a2006-02-22 19:02:11 +00001184 Asm->SwitchSection(DwarfFrameSection, 0);
1185 EmitLabel("section_frame", 0);
Jim Laskeya7cea6f2006-01-04 13:52:30 +00001186 Asm->SwitchSection(DwarfInfoSection, 0);
Jim Laskey0420f2a2006-02-22 19:02:11 +00001187 EmitLabel("section_info", 0);
Jim Laskeya7cea6f2006-01-04 13:52:30 +00001188 EmitLabel("info", 0);
Jim Laskey0420f2a2006-02-22 19:02:11 +00001189 Asm->SwitchSection(DwarfAbbrevSection, 0);
1190 EmitLabel("section_abbrev", 0);
1191 EmitLabel("abbrev", 0);
1192 Asm->SwitchSection(DwarfARangesSection, 0);
1193 EmitLabel("section_aranges", 0);
1194 Asm->SwitchSection(DwarfMacInfoSection, 0);
1195 EmitLabel("section_macinfo", 0);
Jim Laskeya7cea6f2006-01-04 13:52:30 +00001196 Asm->SwitchSection(DwarfLineSection, 0);
Jim Laskey0420f2a2006-02-22 19:02:11 +00001197 EmitLabel("section_line", 0);
Jim Laskeya7cea6f2006-01-04 13:52:30 +00001198 EmitLabel("line", 0);
Jim Laskey0420f2a2006-02-22 19:02:11 +00001199 Asm->SwitchSection(DwarfLocSection, 0);
1200 EmitLabel("section_loc", 0);
1201 Asm->SwitchSection(DwarfPubNamesSection, 0);
1202 EmitLabel("section_pubnames", 0);
1203 Asm->SwitchSection(DwarfStrSection, 0);
1204 EmitLabel("section_str", 0);
1205 Asm->SwitchSection(DwarfRangesSection, 0);
1206 EmitLabel("section_ranges", 0);
1207
Jim Laskey063e7652006-01-17 17:31:53 +00001208 Asm->SwitchSection(TextSection, 0);
1209 EmitLabel("text_begin", 0);
1210 Asm->SwitchSection(DataSection, 0);
1211 EmitLabel("data_begin", 0);
Jim Laskeya7cea6f2006-01-04 13:52:30 +00001212}
1213
Jim Laskey063e7652006-01-17 17:31:53 +00001214/// EmitDIE - Recusively Emits a debug information entry.
1215///
1216void DwarfWriter::EmitDIE(DIE *Die) const {
1217 // Get the abbreviation for this DIE.
1218 unsigned AbbrevID = Die->getAbbrevID();
1219 const DIEAbbrev &Abbrev = Abbreviations[AbbrevID];
Jim Laskey0d086af2006-02-27 12:43:29 +00001220
1221 O << "\n";
Jim Laskey063e7652006-01-17 17:31:53 +00001222
1223 // Emit the code (index) for the abbreviation.
1224 EmitULEB128Bytes(AbbrevID);
1225 EOL(std::string("Abbrev [" +
1226 utostr(AbbrevID) +
Jim Laskey0d086af2006-02-27 12:43:29 +00001227 "] 0x" + utohexstr(Die->getOffset()) +
1228 ":0x" + utohexstr(Die->getSize()) + " " +
1229 TagString(Abbrev.getTag())));
Jim Laskey063e7652006-01-17 17:31:53 +00001230
1231 const std::vector<DIEValue *> &Values = Die->getValues();
Jim Laskeyd18e2892006-01-20 20:34:06 +00001232 const std::vector<DIEAbbrevData> &AbbrevData = Abbrev.getData();
Jim Laskey063e7652006-01-17 17:31:53 +00001233
1234 // Emit the DIE attribute values.
Jim Laskey52060a02006-01-24 00:49:18 +00001235 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
Jim Laskeyd18e2892006-01-20 20:34:06 +00001236 unsigned Attr = AbbrevData[i].getAttribute();
1237 unsigned Form = AbbrevData[i].getForm();
Jim Laskey063e7652006-01-17 17:31:53 +00001238 assert(Form && "Too many attributes for DIE (check abbreviation)");
1239
1240 switch (Attr) {
1241 case DW_AT_sibling: {
Jim Laskeyda427fa2006-01-27 20:31:25 +00001242 EmitInt32(Die->SiblingOffset());
Jim Laskey063e7652006-01-17 17:31:53 +00001243 break;
1244 }
1245 default: {
1246 // Emit an attribute using the defined form.
1247 Values[i]->EmitValue(*this, Form);
1248 break;
1249 }
1250 }
1251
1252 EOL(AttributeString(Attr));
1253 }
1254
1255 // Emit the DIE children if any.
1256 if (Abbrev.getChildrenFlag() == DW_CHILDREN_yes) {
1257 const std::vector<DIE *> &Children = Die->getChildren();
1258
Jim Laskey52060a02006-01-24 00:49:18 +00001259 for (unsigned j = 0, M = Children.size(); j < M; ++j) {
Jim Laskey063e7652006-01-17 17:31:53 +00001260 // FIXME - handle sibling offsets.
1261 // FIXME - handle all DIE types.
1262 EmitDIE(Children[j]);
1263 }
1264
Jim Laskeyda427fa2006-01-27 20:31:25 +00001265 EmitInt8(0); EOL("End Of Children Mark");
Jim Laskey063e7652006-01-17 17:31:53 +00001266 }
1267}
1268
1269/// SizeAndOffsetDie - Compute the size and offset of a DIE.
1270///
Jim Laskey0420f2a2006-02-22 19:02:11 +00001271unsigned DwarfWriter::SizeAndOffsetDie(DIE *Die, unsigned Offset) {
1272 // Record the abbreviation.
1273 Die->Complete(*this);
1274
Jim Laskey063e7652006-01-17 17:31:53 +00001275 // Get the abbreviation for this DIE.
1276 unsigned AbbrevID = Die->getAbbrevID();
1277 const DIEAbbrev &Abbrev = Abbreviations[AbbrevID];
1278
1279 // Set DIE offset
1280 Die->setOffset(Offset);
1281
1282 // Start the size with the size of abbreviation code.
1283 Offset += SizeULEB128(AbbrevID);
1284
1285 const std::vector<DIEValue *> &Values = Die->getValues();
Jim Laskeyd18e2892006-01-20 20:34:06 +00001286 const std::vector<DIEAbbrevData> &AbbrevData = Abbrev.getData();
Jim Laskey063e7652006-01-17 17:31:53 +00001287
1288 // Emit the DIE attribute values.
Jim Laskey52060a02006-01-24 00:49:18 +00001289 for (unsigned i = 0, N = Values.size(); i < N; ++i) {
Jim Laskey063e7652006-01-17 17:31:53 +00001290 // Size attribute value.
Jim Laskeyd18e2892006-01-20 20:34:06 +00001291 Offset += Values[i]->SizeOf(*this, AbbrevData[i].getForm());
Jim Laskey063e7652006-01-17 17:31:53 +00001292 }
1293
1294 // Emit the DIE children if any.
1295 if (Abbrev.getChildrenFlag() == DW_CHILDREN_yes) {
1296 const std::vector<DIE *> &Children = Die->getChildren();
1297
Jim Laskey52060a02006-01-24 00:49:18 +00001298 for (unsigned j = 0, M = Children.size(); j < M; ++j) {
Jim Laskey063e7652006-01-17 17:31:53 +00001299 // FIXME - handle sibling offsets.
1300 // FIXME - handle all DIE types.
1301 Offset = SizeAndOffsetDie(Children[j], Offset);
1302 }
1303
1304 // End of children marker.
1305 Offset += sizeof(int8_t);
1306 }
1307
1308 Die->setSize(Offset - Die->getOffset());
1309 return Offset;
1310}
1311
1312/// SizeAndOffsets - Compute the size and offset of all the DIEs.
1313///
1314void DwarfWriter::SizeAndOffsets() {
Jim Laskey0d086af2006-02-27 12:43:29 +00001315 unsigned Offset = 0;
Jim Laskey063e7652006-01-17 17:31:53 +00001316
1317 // Process each compile unit.
Jim Laskey52060a02006-01-24 00:49:18 +00001318 for (unsigned i = 0, N = CompileUnits.size(); i < N; ++i) {
Jim Laskey0d086af2006-02-27 12:43:29 +00001319 // Compute size of compile unit header
1320 Offset += sizeof(int32_t) + // Length of Compilation Unit Info
1321 sizeof(int16_t) + // DWARF version number
1322 sizeof(int32_t) + // Offset Into Abbrev. Section
1323 sizeof(int8_t); // Pointer Size (in bytes)
1324
Jim Laskey063e7652006-01-17 17:31:53 +00001325 Offset = SizeAndOffsetDie(CompileUnits[i], Offset);
1326 }
1327}
1328
1329/// EmitDebugInfo - Emit the debug info section.
1330///
1331void DwarfWriter::EmitDebugInfo() const {
1332 // Start debug info section.
1333 Asm->SwitchSection(DwarfInfoSection, 0);
1334
1335 // Get the number of compile units.
1336 unsigned N = CompileUnits.size();
1337
1338 // If there are any compile units.
1339 if (N) {
Jim Laskeyd18e2892006-01-20 20:34:06 +00001340 EmitLabel("info_begin", 0);
Jim Laskey063e7652006-01-17 17:31:53 +00001341
Jim Laskey063e7652006-01-17 17:31:53 +00001342 // Process each compile unit.
Jim Laskey52060a02006-01-24 00:49:18 +00001343 for (unsigned i = 0; i < N; ++i) {
Jim Laskey0d086af2006-02-27 12:43:29 +00001344 // Emit the compile units header.
1345
1346 // Emit size of content not including length itself
1347 unsigned ContentSize = CompileUnits[i]->getSize() +
1348 sizeof(int16_t) + // DWARF version number
1349 sizeof(int32_t) + // Offset Into Abbrev. Section
1350 sizeof(int8_t); // Pointer Size (in bytes)
1351
1352 EmitInt32(ContentSize); EOL("Length of Compilation Unit Info");
1353 EmitInt16(DWARF_VERSION); EOL("DWARF version number");
1354 EmitReference("abbrev_begin", 0); EOL("Offset Into Abbrev. Section");
1355 EmitInt8(AddressSize); EOL("Address Size (in bytes)");
1356
Jim Laskey063e7652006-01-17 17:31:53 +00001357 EmitDIE(CompileUnits[i]);
1358 }
Jim Laskey0d086af2006-02-27 12:43:29 +00001359
Jim Laskeyd18e2892006-01-20 20:34:06 +00001360 EmitLabel("info_end", 0);
Jim Laskey0d086af2006-02-27 12:43:29 +00001361
1362 O << "\n";
Jim Laskey063e7652006-01-17 17:31:53 +00001363 }
1364}
1365
1366/// EmitAbbreviations - Emit the abbreviation section.
1367///
1368void DwarfWriter::EmitAbbreviations() const {
Jim Laskeyd18e2892006-01-20 20:34:06 +00001369 // Check to see if it is worth the effort.
1370 if (!Abbreviations.empty()) {
1371 // Start the debug abbrev section.
1372 Asm->SwitchSection(DwarfAbbrevSection, 0);
Jim Laskey063e7652006-01-17 17:31:53 +00001373
Jim Laskeyd18e2892006-01-20 20:34:06 +00001374 EmitLabel("abbrev_begin", 0);
Jim Laskey063e7652006-01-17 17:31:53 +00001375
Jim Laskeyd18e2892006-01-20 20:34:06 +00001376 // For each abbrevation.
1377 for (unsigned AbbrevID = 1, NAID = Abbreviations.size();
Jim Laskey52060a02006-01-24 00:49:18 +00001378 AbbrevID <= NAID; ++AbbrevID) {
Jim Laskeyd18e2892006-01-20 20:34:06 +00001379 // Get abbreviation data
1380 const DIEAbbrev &Abbrev = Abbreviations[AbbrevID];
Jim Laskey063e7652006-01-17 17:31:53 +00001381
Jim Laskeyd18e2892006-01-20 20:34:06 +00001382 // Emit the abbrevations code (base 1 index.)
1383 EmitULEB128Bytes(AbbrevID); EOL("Abbreviation Code");
Jim Laskey063e7652006-01-17 17:31:53 +00001384
Jim Laskeyd18e2892006-01-20 20:34:06 +00001385 // Emit the abbreviations data.
1386 Abbrev.Emit(*this);
Jim Laskey0d086af2006-02-27 12:43:29 +00001387
1388 O << "\n";
Jim Laskey063e7652006-01-17 17:31:53 +00001389 }
Jim Laskeyd18e2892006-01-20 20:34:06 +00001390
1391 EmitLabel("abbrev_end", 0);
Jim Laskey0d086af2006-02-27 12:43:29 +00001392
1393 O << "\n";
Jim Laskey063e7652006-01-17 17:31:53 +00001394 }
1395}
1396
1397/// EmitDebugLines - Emit source line information.
1398///
1399void DwarfWriter::EmitDebugLines() const {
1400 // Minimum line delta, thus ranging from -10..(255-10).
1401 const int MinLineDelta = -(DW_LNS_fixed_advance_pc + 1);
1402 // Maximum line delta, thus ranging from -10..(255-10).
1403 const int MaxLineDelta = 255 + MinLineDelta;
1404
1405 // Start the dwarf line section.
1406 Asm->SwitchSection(DwarfLineSection, 0);
1407
1408 // Construct the section header.
1409
1410 EmitDifference("line_end", 0, "line_begin", 0);
1411 EOL("Length of Source Line Info");
1412 EmitLabel("line_begin", 0);
1413
Jim Laskeyda427fa2006-01-27 20:31:25 +00001414 EmitInt16(DWARF_VERSION); EOL("DWARF version number");
Jim Laskey063e7652006-01-17 17:31:53 +00001415
1416 EmitDifference("line_prolog_end", 0, "line_prolog_begin", 0);
1417 EOL("Prolog Length");
1418 EmitLabel("line_prolog_begin", 0);
1419
Jim Laskeyda427fa2006-01-27 20:31:25 +00001420 EmitInt8(1); EOL("Minimum Instruction Length");
Jim Laskey063e7652006-01-17 17:31:53 +00001421
Jim Laskeyda427fa2006-01-27 20:31:25 +00001422 EmitInt8(1); EOL("Default is_stmt_start flag");
Jim Laskey063e7652006-01-17 17:31:53 +00001423
Jim Laskeyda427fa2006-01-27 20:31:25 +00001424 EmitInt8(MinLineDelta); EOL("Line Base Value (Special Opcodes)");
Jim Laskey063e7652006-01-17 17:31:53 +00001425
Jim Laskeyda427fa2006-01-27 20:31:25 +00001426 EmitInt8(MaxLineDelta); EOL("Line Range Value (Special Opcodes)");
Jim Laskey063e7652006-01-17 17:31:53 +00001427
Jim Laskeyda427fa2006-01-27 20:31:25 +00001428 EmitInt8(-MinLineDelta); EOL("Special Opcode Base");
Jim Laskey063e7652006-01-17 17:31:53 +00001429
1430 // Line number standard opcode encodings argument count
Jim Laskeyda427fa2006-01-27 20:31:25 +00001431 EmitInt8(0); EOL("DW_LNS_copy arg count");
1432 EmitInt8(1); EOL("DW_LNS_advance_pc arg count");
1433 EmitInt8(1); EOL("DW_LNS_advance_line arg count");
1434 EmitInt8(1); EOL("DW_LNS_set_file arg count");
1435 EmitInt8(1); EOL("DW_LNS_set_column arg count");
1436 EmitInt8(0); EOL("DW_LNS_negate_stmt arg count");
1437 EmitInt8(0); EOL("DW_LNS_set_basic_block arg count");
1438 EmitInt8(0); EOL("DW_LNS_const_add_pc arg count");
1439 EmitInt8(1); EOL("DW_LNS_fixed_advance_pc arg count");
Jim Laskey063e7652006-01-17 17:31:53 +00001440
1441 const UniqueVector<std::string> &Directories = DebugInfo->getDirectories();
1442 const UniqueVector<SourceFileInfo> &SourceFiles = DebugInfo->getSourceFiles();
1443
1444 // Emit directories.
1445 for (unsigned DirectoryID = 1, NDID = Directories.size();
Jim Laskey52060a02006-01-24 00:49:18 +00001446 DirectoryID <= NDID; ++DirectoryID) {
Jim Laskey063e7652006-01-17 17:31:53 +00001447 EmitString(Directories[DirectoryID]); EOL("Directory");
1448 }
Jim Laskeyda427fa2006-01-27 20:31:25 +00001449 EmitInt8(0); EOL("End of directories");
Jim Laskey063e7652006-01-17 17:31:53 +00001450
1451 // Emit files.
1452 for (unsigned SourceID = 1, NSID = SourceFiles.size();
Jim Laskey52060a02006-01-24 00:49:18 +00001453 SourceID <= NSID; ++SourceID) {
Jim Laskey063e7652006-01-17 17:31:53 +00001454 const SourceFileInfo &SourceFile = SourceFiles[SourceID];
1455 EmitString(SourceFile.getName()); EOL("Source");
1456 EmitULEB128Bytes(SourceFile.getDirectoryID()); EOL("Directory #");
1457 EmitULEB128Bytes(0); EOL("Mod date");
1458 EmitULEB128Bytes(0); EOL("File size");
1459 }
Jim Laskeyda427fa2006-01-27 20:31:25 +00001460 EmitInt8(0); EOL("End of files");
Jim Laskey063e7652006-01-17 17:31:53 +00001461
1462 EmitLabel("line_prolog_end", 0);
1463
1464 // Emit line information
1465 const std::vector<SourceLineInfo *> &LineInfos = DebugInfo->getSourceLines();
1466
1467 // Dwarf assumes we start with first line of first source file.
1468 unsigned Source = 1;
1469 unsigned Line = 1;
1470
1471 // Construct rows of the address, source, line, column matrix.
Jim Laskey52060a02006-01-24 00:49:18 +00001472 for (unsigned i = 0, N = LineInfos.size(); i < N; ++i) {
Jim Laskey063e7652006-01-17 17:31:53 +00001473 SourceLineInfo *LineInfo = LineInfos[i];
Jim Laskey0420f2a2006-02-22 19:02:11 +00001474
1475 if (DwarfVerbose) {
1476 unsigned SourceID = LineInfo->getSourceID();
1477 const SourceFileInfo &SourceFile = SourceFiles[SourceID];
1478 unsigned DirectoryID = SourceFile.getDirectoryID();
1479 O << "\t"
1480 << Asm->CommentString << " "
1481 << Directories[DirectoryID]
1482 << SourceFile.getName() << ":"
1483 << LineInfo->getLine() << "\n";
1484 }
Jim Laskey063e7652006-01-17 17:31:53 +00001485
1486 // Define the line address.
Jim Laskeyda427fa2006-01-27 20:31:25 +00001487 EmitInt8(0); EOL("Extended Op");
1488 EmitInt8(4 + 1); EOL("Op size");
1489 EmitInt8(DW_LNE_set_address); EOL("DW_LNE_set_address");
Jim Laskeye719a7c2006-01-18 16:54:26 +00001490 EmitReference("loc", i + 1); EOL("Location label");
Jim Laskey063e7652006-01-17 17:31:53 +00001491
1492 // If change of source, then switch to the new source.
1493 if (Source != LineInfo->getSourceID()) {
1494 Source = LineInfo->getSourceID();
Jim Laskeyda427fa2006-01-27 20:31:25 +00001495 EmitInt8(DW_LNS_set_file); EOL("DW_LNS_set_file");
Jim Laskey063e7652006-01-17 17:31:53 +00001496 EmitULEB128Bytes(0); EOL("New Source");
1497 }
1498
1499 // If change of line.
1500 if (Line != LineInfo->getLine()) {
1501 // Determine offset.
1502 int Offset = LineInfo->getLine() - Line;
1503 int Delta = Offset - MinLineDelta;
1504
1505 // Update line.
1506 Line = LineInfo->getLine();
1507
1508 // If delta is small enough and in range...
1509 if (Delta >= 0 && Delta < (MaxLineDelta - 1)) {
1510 // ... then use fast opcode.
Jim Laskeyda427fa2006-01-27 20:31:25 +00001511 EmitInt8(Delta - MinLineDelta); EOL("Line Delta");
Jim Laskey063e7652006-01-17 17:31:53 +00001512 } else {
1513 // ... otherwise use long hand.
Jim Laskeyda427fa2006-01-27 20:31:25 +00001514 EmitInt8(DW_LNS_advance_line); EOL("DW_LNS_advance_line");
Jim Laskey063e7652006-01-17 17:31:53 +00001515 EmitSLEB128Bytes(Offset); EOL("Line Offset");
Jim Laskeyda427fa2006-01-27 20:31:25 +00001516 EmitInt8(DW_LNS_copy); EOL("DW_LNS_copy");
Jim Laskey063e7652006-01-17 17:31:53 +00001517 }
1518 } else {
1519 // Copy the previous row (different address or source)
Jim Laskeyda427fa2006-01-27 20:31:25 +00001520 EmitInt8(DW_LNS_copy); EOL("DW_LNS_copy");
Jim Laskey063e7652006-01-17 17:31:53 +00001521 }
1522 }
1523
Jim Laskey0420f2a2006-02-22 19:02:11 +00001524 // Define last address.
1525 EmitInt8(0); EOL("Extended Op");
1526 EmitInt8(4 + 1); EOL("Op size");
1527 EmitInt8(DW_LNE_set_address); EOL("DW_LNE_set_address");
1528 EmitReference("text_end", 0); EOL("Location label");
1529
Jim Laskey063e7652006-01-17 17:31:53 +00001530 // Mark end of matrix.
Jim Laskeyda427fa2006-01-27 20:31:25 +00001531 EmitInt8(0); EOL("DW_LNE_end_sequence");
Jim Laskey063e7652006-01-17 17:31:53 +00001532 EmitULEB128Bytes(1); O << "\n";
Jim Laskeyda427fa2006-01-27 20:31:25 +00001533 EmitInt8(1); O << "\n";
Jim Laskey063e7652006-01-17 17:31:53 +00001534
1535 EmitLabel("line_end", 0);
Jim Laskey0d086af2006-02-27 12:43:29 +00001536
1537 O << "\n";
Jim Laskey063e7652006-01-17 17:31:53 +00001538}
Jim Laskey19ef4ef2006-01-17 20:41:40 +00001539
1540/// EmitDebugFrame - Emit visible names into a debug frame section.
1541///
1542void DwarfWriter::EmitDebugFrame() {
Jim Laskeye719a7c2006-01-18 16:54:26 +00001543 // FIXME - Should be per frame
Jim Laskey19ef4ef2006-01-17 20:41:40 +00001544}
1545
1546/// EmitDebugPubNames - Emit visible names into a debug pubnames section.
1547///
1548void DwarfWriter::EmitDebugPubNames() {
Jim Laskeyd18e2892006-01-20 20:34:06 +00001549 // Check to see if it is worth the effort.
1550 if (!GlobalEntities.empty()) {
1551 // Start the dwarf pubnames section.
1552 Asm->SwitchSection(DwarfPubNamesSection, 0);
1553
1554 EmitDifference("pubnames_end", 0, "pubnames_begin", 0);
1555 EOL("Length of Public Names Info");
1556
1557 EmitLabel("pubnames_begin", 0);
1558
Jim Laskeyda427fa2006-01-27 20:31:25 +00001559 EmitInt16(DWARF_VERSION); EOL("DWARF Version");
Jim Laskeyd18e2892006-01-20 20:34:06 +00001560
1561 EmitReference("info_begin", 0); EOL("Offset of Compilation Unit Info");
1562
1563 EmitDifference("info_end", 0, "info_begin", 0);
1564 EOL("Compilation Unit Length");
1565
Jim Laskey52060a02006-01-24 00:49:18 +00001566 for (std::map<std::string, DIE *>::iterator GI = GlobalEntities.begin(),
1567 GE = GlobalEntities.end();
1568 GI != GE; ++GI) {
1569 const std::string &Name = GI->first;
1570 DIE * Entity = GI->second;
Jim Laskeyd18e2892006-01-20 20:34:06 +00001571
Jim Laskeyda427fa2006-01-27 20:31:25 +00001572 EmitInt32(Entity->getOffset()); EOL("DIE offset");
Jim Laskeyd18e2892006-01-20 20:34:06 +00001573 EmitString(Name); EOL("External Name");
1574
1575 }
1576
Jim Laskeyda427fa2006-01-27 20:31:25 +00001577 EmitInt32(0); EOL("End Mark");
Jim Laskeyd18e2892006-01-20 20:34:06 +00001578 EmitLabel("pubnames_end", 0);
Jim Laskey0d086af2006-02-27 12:43:29 +00001579
1580 O << "\n";
Jim Laskeyd18e2892006-01-20 20:34:06 +00001581 }
Jim Laskey19ef4ef2006-01-17 20:41:40 +00001582}
1583
1584/// EmitDebugPubTypes - Emit visible names into a debug pubtypes section.
1585///
1586void DwarfWriter::EmitDebugPubTypes() {
Jim Laskeyd18e2892006-01-20 20:34:06 +00001587 // Check to see if it is worth the effort.
1588 if (!GlobalTypes.empty()) {
1589 // Start the dwarf pubtypes section.
1590 Asm->SwitchSection(DwarfPubTypesSection, 0);
Jim Laskey0d086af2006-02-27 12:43:29 +00001591
1592 O << "\n";
Jim Laskeyd18e2892006-01-20 20:34:06 +00001593 }
Jim Laskey19ef4ef2006-01-17 20:41:40 +00001594}
1595
1596/// EmitDebugStr - Emit visible names into a debug str section.
1597///
1598void DwarfWriter::EmitDebugStr() {
Jim Laskeyd18e2892006-01-20 20:34:06 +00001599 // Check to see if it is worth the effort.
1600 if (!StringPool.empty()) {
1601 // Start the dwarf str section.
1602 Asm->SwitchSection(DwarfStrSection, 0);
1603
1604 // For each of strings in teh string pool.
1605 for (unsigned StringID = 1, N = StringPool.size();
Jim Laskey52060a02006-01-24 00:49:18 +00001606 StringID <= N; ++StringID) {
Jim Laskeyd18e2892006-01-20 20:34:06 +00001607 // Emit a label for reference from debug information entries.
1608 EmitLabel("string", StringID);
1609 // Emit the string itself.
1610 const std::string &String = StringPool[StringID];
1611 EmitString(String); O << "\n";
1612 }
Jim Laskey0d086af2006-02-27 12:43:29 +00001613
1614 O << "\n";
Jim Laskeyd18e2892006-01-20 20:34:06 +00001615 }
Jim Laskey19ef4ef2006-01-17 20:41:40 +00001616}
1617
1618/// EmitDebugLoc - Emit visible names into a debug loc section.
1619///
1620void DwarfWriter::EmitDebugLoc() {
Jim Laskeye719a7c2006-01-18 16:54:26 +00001621 // Start the dwarf loc section.
1622 Asm->SwitchSection(DwarfLocSection, 0);
Jim Laskey0d086af2006-02-27 12:43:29 +00001623
1624 O << "\n";
Jim Laskey19ef4ef2006-01-17 20:41:40 +00001625}
1626
1627/// EmitDebugARanges - Emit visible names into a debug aranges section.
1628///
1629void DwarfWriter::EmitDebugARanges() {
Jim Laskeye719a7c2006-01-18 16:54:26 +00001630 // Start the dwarf aranges section.
1631 Asm->SwitchSection(DwarfARangesSection, 0);
1632
1633 // FIXME - Mock up
1634
1635 // Don't include size of length
Jim Laskeyda427fa2006-01-27 20:31:25 +00001636 EmitInt32(0x1c); EOL("Length of Address Ranges Info");
Jim Laskeye719a7c2006-01-18 16:54:26 +00001637
Jim Laskeyda427fa2006-01-27 20:31:25 +00001638 EmitInt16(DWARF_VERSION); EOL("Dwarf Version");
Jim Laskeye719a7c2006-01-18 16:54:26 +00001639
Jim Laskeyd18e2892006-01-20 20:34:06 +00001640 EmitReference("info_begin", 0); EOL("Offset of Compilation Unit Info");
Jim Laskeye719a7c2006-01-18 16:54:26 +00001641
Jim Laskeyda427fa2006-01-27 20:31:25 +00001642 EmitInt8(AddressSize); EOL("Size of Address");
Jim Laskeye719a7c2006-01-18 16:54:26 +00001643
Jim Laskeyda427fa2006-01-27 20:31:25 +00001644 EmitInt8(0); EOL("Size of Segment Descriptor");
Jim Laskeye719a7c2006-01-18 16:54:26 +00001645
Jim Laskeyda427fa2006-01-27 20:31:25 +00001646 EmitInt16(0); EOL("Pad (1)");
1647 EmitInt16(0); EOL("Pad (2)");
Jim Laskeye719a7c2006-01-18 16:54:26 +00001648
1649 // Range 1
1650 EmitReference("text_begin", 0); EOL("Address");
1651 EmitDifference("text_end", 0, "text_begin", 0); EOL("Length");
1652
Jim Laskeyda427fa2006-01-27 20:31:25 +00001653 EmitInt32(0); EOL("EOM (1)");
1654 EmitInt32(0); EOL("EOM (2)");
Jim Laskey0d086af2006-02-27 12:43:29 +00001655
1656 O << "\n";
Jim Laskey19ef4ef2006-01-17 20:41:40 +00001657}
1658
1659/// EmitDebugRanges - Emit visible names into a debug ranges section.
1660///
1661void DwarfWriter::EmitDebugRanges() {
Jim Laskeye719a7c2006-01-18 16:54:26 +00001662 // Start the dwarf ranges section.
1663 Asm->SwitchSection(DwarfRangesSection, 0);
Jim Laskey0d086af2006-02-27 12:43:29 +00001664
1665 O << "\n";
Jim Laskey19ef4ef2006-01-17 20:41:40 +00001666}
1667
1668/// EmitDebugMacInfo - Emit visible names into a debug macinfo section.
1669///
1670void DwarfWriter::EmitDebugMacInfo() {
Jim Laskeye719a7c2006-01-18 16:54:26 +00001671 // Start the dwarf macinfo section.
1672 Asm->SwitchSection(DwarfMacInfoSection, 0);
Jim Laskey0d086af2006-02-27 12:43:29 +00001673
1674 O << "\n";
Jim Laskey19ef4ef2006-01-17 20:41:40 +00001675}
Jim Laskey063e7652006-01-17 17:31:53 +00001676
Jim Laskey52060a02006-01-24 00:49:18 +00001677/// ConstructCompileUnitDIEs - Create a compile unit DIE for each source and
1678/// header file.
1679void DwarfWriter::ConstructCompileUnitDIEs() {
Jim Laskey86cbdba2006-02-06 15:33:21 +00001680 const UniqueVector<CompileUnitDesc *> CUW = DebugInfo->getCompileUnits();
Jim Laskey6e87c0e2006-01-26 21:22:49 +00001681
1682 for (unsigned i = 1, N = CUW.size(); i <= N; ++i) {
Jim Laskey86cbdba2006-02-06 15:33:21 +00001683 DIE *Unit = NewCompileUnit(CUW[i]);
Jim Laskey52060a02006-01-24 00:49:18 +00001684 CompileUnits.push_back(Unit);
1685 }
1686}
1687
1688/// ConstructGlobalDIEs - Create DIEs for each of the externally visible global
1689/// variables.
1690void DwarfWriter::ConstructGlobalDIEs(Module &M) {
Jim Laskey86cbdba2006-02-06 15:33:21 +00001691 std::vector<GlobalVariableDesc *> GlobalVariables =
Jim Laskey0420f2a2006-02-22 19:02:11 +00001692 DebugInfo->getAnchoredDescriptors<GlobalVariableDesc>(M);
Jim Laskeyb3e789a2006-01-26 20:21:46 +00001693
1694 for (unsigned i = 0, N = GlobalVariables.size(); i < N; ++i) {
Jim Laskey86cbdba2006-02-06 15:33:21 +00001695 GlobalVariableDesc *GVD = GlobalVariables[i];
Jim Laskey0420f2a2006-02-22 19:02:11 +00001696 NewGlobalVariable(GVD);
Jim Laskey52060a02006-01-24 00:49:18 +00001697 }
1698}
1699
Jim Laskey0420f2a2006-02-22 19:02:11 +00001700/// ConstructSubprogramDIEs - Create DIEs for each of the externally visible
1701/// subprograms.
1702void DwarfWriter::ConstructSubprogramDIEs(Module &M) {
1703 std::vector<SubprogramDesc *> Subprograms =
1704 DebugInfo->getAnchoredDescriptors<SubprogramDesc>(M);
1705
1706 for (unsigned i = 0, N = Subprograms.size(); i < N; ++i) {
1707 SubprogramDesc *SPD = Subprograms[i];
1708 NewSubprogram(SPD);
1709 }
1710}
Jim Laskey52060a02006-01-24 00:49:18 +00001711
Jim Laskey063e7652006-01-17 17:31:53 +00001712/// ShouldEmitDwarf - Determine if Dwarf declarations should be made.
Jim Laskeyb2efb852006-01-04 22:28:25 +00001713///
1714bool DwarfWriter::ShouldEmitDwarf() {
1715 // Check if debug info is present.
1716 if (!DebugInfo || !DebugInfo->hasInfo()) return false;
1717
1718 // Make sure initial declarations are made.
1719 if (!didInitial) {
1720 EmitInitial();
1721 didInitial = true;
1722 }
1723
1724 // Okay to emit.
1725 return true;
1726}
1727
Jim Laskey063e7652006-01-17 17:31:53 +00001728//===----------------------------------------------------------------------===//
Jim Laskeyd18e2892006-01-20 20:34:06 +00001729// Main entry points.
Jim Laskey063e7652006-01-17 17:31:53 +00001730//
Jim Laskey52060a02006-01-24 00:49:18 +00001731
1732DwarfWriter::DwarfWriter(std::ostream &OS, AsmPrinter *A)
1733: O(OS)
1734, Asm(A)
1735, DebugInfo(NULL)
1736, didInitial(false)
1737, CompileUnits()
1738, Abbreviations()
1739, GlobalTypes()
1740, GlobalEntities()
1741, StringPool()
Jim Laskey0420f2a2006-02-22 19:02:11 +00001742, DescToDieMap()
1743, TypeToDieMap()
Jim Laskey52060a02006-01-24 00:49:18 +00001744, AddressSize(sizeof(int32_t))
1745, hasLEB128(false)
1746, hasDotLoc(false)
1747, hasDotFile(false)
1748, needsSet(false)
1749, DwarfAbbrevSection(".debug_abbrev")
1750, DwarfInfoSection(".debug_info")
1751, DwarfLineSection(".debug_line")
1752, DwarfFrameSection(".debug_frame")
1753, DwarfPubNamesSection(".debug_pubnames")
1754, DwarfPubTypesSection(".debug_pubtypes")
1755, DwarfStrSection(".debug_str")
1756, DwarfLocSection(".debug_loc")
1757, DwarfARangesSection(".debug_aranges")
1758, DwarfRangesSection(".debug_ranges")
1759, DwarfMacInfoSection(".debug_macinfo")
1760, TextSection(".text")
1761, DataSection(".data")
1762{}
1763DwarfWriter::~DwarfWriter() {
1764 for (unsigned i = 0, N = CompileUnits.size(); i < N; ++i) {
1765 delete CompileUnits[i];
Jim Laskey063e7652006-01-17 17:31:53 +00001766 }
Jim Laskey52060a02006-01-24 00:49:18 +00001767}
Jim Laskey063e7652006-01-17 17:31:53 +00001768
1769/// BeginModule - Emit all Dwarf sections that should come prior to the content.
Jim Laskeyb2efb852006-01-04 22:28:25 +00001770///
Jim Laskey52060a02006-01-24 00:49:18 +00001771void DwarfWriter::BeginModule(Module &M) {
Jim Laskeyb2efb852006-01-04 22:28:25 +00001772 if (!ShouldEmitDwarf()) return;
Jim Laskey063e7652006-01-17 17:31:53 +00001773 EOL("Dwarf Begin Module");
Jim Laskeyb2efb852006-01-04 22:28:25 +00001774}
1775
Jim Laskey063e7652006-01-17 17:31:53 +00001776/// EndModule - Emit all Dwarf sections that should come after the content.
Jim Laskeya7cea6f2006-01-04 13:52:30 +00001777///
Jim Laskey52060a02006-01-24 00:49:18 +00001778void DwarfWriter::EndModule(Module &M) {
Jim Laskeyb2efb852006-01-04 22:28:25 +00001779 if (!ShouldEmitDwarf()) return;
Jim Laskey063e7652006-01-17 17:31:53 +00001780 EOL("Dwarf End Module");
1781
1782 // Standard sections final addresses.
Jim Laskeye719a7c2006-01-18 16:54:26 +00001783 Asm->SwitchSection(TextSection, 0);
Jim Laskey063e7652006-01-17 17:31:53 +00001784 EmitLabel("text_end", 0);
Jim Laskeye719a7c2006-01-18 16:54:26 +00001785 Asm->SwitchSection(DataSection, 0);
Jim Laskey063e7652006-01-17 17:31:53 +00001786 EmitLabel("data_end", 0);
Jim Laskeyd18e2892006-01-20 20:34:06 +00001787
Jim Laskey52060a02006-01-24 00:49:18 +00001788 // Create all the compile unit DIEs.
1789 ConstructCompileUnitDIEs();
1790
1791 // Create DIEs for each of the externally visible global variables.
1792 ConstructGlobalDIEs(M);
Jim Laskey063e7652006-01-17 17:31:53 +00001793
Jim Laskey0420f2a2006-02-22 19:02:11 +00001794 // Create DIEs for each of the externally visible subprograms.
1795 ConstructSubprogramDIEs(M);
1796
Jim Laskey063e7652006-01-17 17:31:53 +00001797 // Compute DIE offsets and sizes.
1798 SizeAndOffsets();
1799
1800 // Emit all the DIEs into a debug info section
1801 EmitDebugInfo();
1802
1803 // Corresponding abbreviations into a abbrev section.
1804 EmitAbbreviations();
1805
1806 // Emit source line correspondence into a debug line section.
1807 EmitDebugLines();
Jim Laskey19ef4ef2006-01-17 20:41:40 +00001808
1809 // Emit info into a debug frame section.
Jim Laskey0d086af2006-02-27 12:43:29 +00001810 // EmitDebugFrame();
Jim Laskey19ef4ef2006-01-17 20:41:40 +00001811
1812 // Emit info into a debug pubnames section.
1813 EmitDebugPubNames();
1814
1815 // Emit info into a debug pubtypes section.
Jim Laskey0d086af2006-02-27 12:43:29 +00001816 // EmitDebugPubTypes();
Jim Laskey19ef4ef2006-01-17 20:41:40 +00001817
1818 // Emit info into a debug str section.
1819 EmitDebugStr();
1820
1821 // Emit info into a debug loc section.
1822 EmitDebugLoc();
1823
1824 // Emit info into a debug aranges section.
1825 EmitDebugARanges();
1826
1827 // Emit info into a debug ranges section.
1828 EmitDebugRanges();
1829
1830 // Emit info into a debug macinfo section.
1831 EmitDebugMacInfo();
Jim Laskeya7cea6f2006-01-04 13:52:30 +00001832}
1833
Jim Laskeye719a7c2006-01-18 16:54:26 +00001834/// BeginFunction - Gather pre-function debug information.
Jim Laskeya7cea6f2006-01-04 13:52:30 +00001835///
Jim Laskey52060a02006-01-24 00:49:18 +00001836void DwarfWriter::BeginFunction(MachineFunction &MF) {
Jim Laskeyb2efb852006-01-04 22:28:25 +00001837 if (!ShouldEmitDwarf()) return;
Jim Laskey063e7652006-01-17 17:31:53 +00001838 EOL("Dwarf Begin Function");
Jim Laskeya7cea6f2006-01-04 13:52:30 +00001839}
1840
Jim Laskeye719a7c2006-01-18 16:54:26 +00001841/// EndFunction - Gather and emit post-function debug information.
Jim Laskeya7cea6f2006-01-04 13:52:30 +00001842///
Jim Laskey52060a02006-01-24 00:49:18 +00001843void DwarfWriter::EndFunction(MachineFunction &MF) {
Jim Laskeyb2efb852006-01-04 22:28:25 +00001844 if (!ShouldEmitDwarf()) return;
Jim Laskey063e7652006-01-17 17:31:53 +00001845 EOL("Dwarf End Function");
Jim Laskeya7cea6f2006-01-04 13:52:30 +00001846}