llvm.org GIT mirror llvm / 6da1864
rename files git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33552 91177308-0d34-0410-b5e6-96231b3b80d8 Jim Laskey 13 years ago
4 changed file(s) with 2852 addition(s) and 2850 deletion(s). Raw diff Collapse all Expand all
+0
-1154
include/llvm/CodeGen/MachineDebugInfo.h less more
None //===-- llvm/CodeGen/MachineDebugInfo.h -------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by James M. Laskey and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Collect debug information for a module. This information should be in a
10 // neutral form that can be used by different debugging schemes.
11 //
12 // The organization of information is primarily clustered around the source
13 // compile units. The main exception is source line correspondence where
14 // inlining may interleave code from various compile units.
15 //
16 // The following information can be retrieved from the MachineDebugInfo.
17 //
18 // -- Source directories - Directories are uniqued based on their canonical
19 // string and assigned a sequential numeric ID (base 1.)
20 // -- Source files - Files are also uniqued based on their name and directory
21 // ID. A file ID is sequential number (base 1.)
22 // -- Source line correspondence - A vector of file ID, line#, column# triples.
23 // A DEBUG_LOCATION instruction is generated by the DAG Legalizer
24 // corresponding to each entry in the source line list. This allows a debug
25 // emitter to generate labels referenced by debug information tables.
26 //
27 //===----------------------------------------------------------------------===//
28
29 #ifndef LLVM_CODEGEN_MACHINEDEBUGINFO_H
30 #define LLVM_CODEGEN_MACHINEDEBUGINFO_H
31
32 #include "llvm/Support/Dwarf.h"
33 #include "llvm/Support/DataTypes.h"
34 #include "llvm/ADT/UniqueVector.h"
35 #include "llvm/GlobalValue.h"
36 #include "llvm/Pass.h"
37
38 namespace llvm {
39
40 //===----------------------------------------------------------------------===//
41 // Forward declarations.
42 class Constant;
43 class DebugInfoDesc;
44 class GlobalVariable;
45 class MachineFunction;
46 class MachineMove;
47 class Module;
48 class PointerType;
49 class StructType;
50
51 //===----------------------------------------------------------------------===//
52 // Debug info constants.
53
54 enum {
55 LLVMDebugVersion = (6 << 16), // Current version of debug information.
56 LLVMDebugVersion5 = (5 << 16), // Constant for version 5.
57 LLVMDebugVersion4 = (4 << 16), // Constant for version 4.
58 LLVMDebugVersionMask = 0xffff0000 // Mask for version number.
59 };
60
61 //===----------------------------------------------------------------------===//
62 /// DIVisitor - Subclasses of this class apply steps to each of the fields in
63 /// the supplied DebugInfoDesc.
64 class DIVisitor {
65 public:
66 DIVisitor() {}
67 virtual ~DIVisitor() {}
68
69 /// ApplyToFields - Target the visitor to each field of the debug information
70 /// descriptor.
71 void ApplyToFields(DebugInfoDesc *DD);
72
73 /// Apply - Subclasses override each of these methods to perform the
74 /// appropriate action for the type of field.
75 virtual void Apply(int &Field) = 0;
76 virtual void Apply(unsigned &Field) = 0;
77 virtual void Apply(int64_t &Field) = 0;
78 virtual void Apply(uint64_t &Field) = 0;
79 virtual void Apply(bool &Field) = 0;
80 virtual void Apply(std::string &Field) = 0;
81 virtual void Apply(DebugInfoDesc *&Field) = 0;
82 virtual void Apply(GlobalVariable *&Field) = 0;
83 virtual void Apply(std::vector &Field) = 0;
84 };
85
86 //===----------------------------------------------------------------------===//
87 /// DebugInfoDesc - This class is the base class for debug info descriptors.
88 ///
89 class DebugInfoDesc {
90 private:
91 unsigned Tag; // Content indicator. Dwarf values are
92 // used but that does not limit use to
93 // Dwarf writers.
94
95 protected:
96 DebugInfoDesc(unsigned T) : Tag(T | LLVMDebugVersion) {}
97
98 public:
99 virtual ~DebugInfoDesc() {}
100
101 // Accessors
102 unsigned getTag() const { return Tag & ~LLVMDebugVersionMask; }
103 unsigned getVersion() const { return Tag & LLVMDebugVersionMask; }
104 void setTag(unsigned T) { Tag = T | LLVMDebugVersion; }
105
106 /// TagFromGlobal - Returns the tag number from a debug info descriptor
107 /// GlobalVariable. Return DIIValid if operand is not an unsigned int.
108 static unsigned TagFromGlobal(GlobalVariable *GV);
109
110 /// VersionFromGlobal - Returns the version number from a debug info
111 /// descriptor GlobalVariable. Return DIIValid if operand is not an unsigned
112 /// int.
113 static unsigned VersionFromGlobal(GlobalVariable *GV);
114
115 /// DescFactory - Create an instance of debug info descriptor based on Tag.
116 /// Return NULL if not a recognized Tag.
117 static DebugInfoDesc *DescFactory(unsigned Tag);
118
119 /// getLinkage - get linkage appropriate for this type of descriptor.
120 ///
121 virtual GlobalValue::LinkageTypes getLinkage() const;
122
123 //===--------------------------------------------------------------------===//
124 // Subclasses should supply the following static methods.
125
126 // Implement isa/cast/dyncast.
127 static bool classof(const DebugInfoDesc *) { return true; }
128
129 //===--------------------------------------------------------------------===//
130 // Subclasses should supply the following virtual methods.
131
132 /// ApplyToFields - Target the vistor to the fields of the descriptor.
133 ///
134 virtual void ApplyToFields(DIVisitor *Visitor);
135
136 /// getDescString - Return a string used to compose global names and labels.
137 ///
138 virtual const char *getDescString() const = 0;
139
140 /// getTypeString - Return a string used to label this descriptor's type.
141 ///
142 virtual const char *getTypeString() const = 0;
143
144 #ifndef NDEBUG
145 virtual void dump() = 0;
146 #endif
147 };
148
149 //===----------------------------------------------------------------------===//
150 /// AnchorDesc - Descriptors of this class act as markers for identifying
151 /// descriptors of certain groups.
152 class AnchoredDesc;
153 class AnchorDesc : public DebugInfoDesc {
154 private:
155 unsigned AnchorTag; // Tag number of descriptors anchored
156 // by this object.
157
158 public:
159 AnchorDesc();
160 AnchorDesc(AnchoredDesc *D);
161
162 // Accessors
163 unsigned getAnchorTag() const { return AnchorTag; }
164
165 // Implement isa/cast/dyncast.
166 static bool classof(const AnchorDesc *) { return true; }
167 static bool classof(const DebugInfoDesc *D);
168
169 /// getLinkage - get linkage appropriate for this type of descriptor.
170 ///
171 virtual GlobalValue::LinkageTypes getLinkage() const;
172
173 /// ApplyToFields - Target the visitor to the fields of the AnchorDesc.
174 ///
175 virtual void ApplyToFields(DIVisitor *Visitor);
176
177 /// getDescString - Return a string used to compose global names and labels.
178 ///
179 virtual const char *getDescString() const;
180
181 /// getTypeString - Return a string used to label this descriptor's type.
182 ///
183 virtual const char *getTypeString() const;
184
185 #ifndef NDEBUG
186 virtual void dump();
187 #endif
188 };
189
190 //===----------------------------------------------------------------------===//
191 /// AnchoredDesc - This class manages anchors for a variety of top level
192 /// descriptors.
193 class AnchoredDesc : public DebugInfoDesc {
194 private:
195 DebugInfoDesc *Anchor; // Anchor for all descriptors of the
196 // same type.
197
198 protected:
199
200 AnchoredDesc(unsigned T);
201
202 public:
203 // Accessors.
204 AnchorDesc *getAnchor() const { return static_cast(Anchor); }
205 void setAnchor(AnchorDesc *A) { Anchor = static_cast(A); }
206
207 //===--------------------------------------------------------------------===//
208 // Subclasses should supply the following virtual methods.
209
210 /// getAnchorString - Return a string used to label descriptor's anchor.
211 ///
212 virtual const char *getAnchorString() const = 0;
213
214 /// ApplyToFields - Target the visitor to the fields of the AnchoredDesc.
215 ///
216 virtual void ApplyToFields(DIVisitor *Visitor);
217 };
218
219 //===----------------------------------------------------------------------===//
220 /// CompileUnitDesc - This class packages debug information associated with a
221 /// source/header file.
222 class CompileUnitDesc : public AnchoredDesc {
223 private:
224 unsigned Language; // Language number (ex. DW_LANG_C89.)
225 std::string FileName; // Source file name.
226 std::string Directory; // Source file directory.
227 std::string Producer; // Compiler string.
228
229 public:
230 CompileUnitDesc();
231
232
233 // Accessors
234 unsigned getLanguage() const { return Language; }
235 const std::string &getFileName() const { return FileName; }
236 const std::string &getDirectory() const { return Directory; }
237 const std::string &getProducer() const { return Producer; }
238 void setLanguage(unsigned L) { Language = L; }
239 void setFileName(const std::string &FN) { FileName = FN; }
240 void setDirectory(const std::string &D) { Directory = D; }
241 void setProducer(const std::string &P) { Producer = P; }
242
243 // FIXME - Need translation unit getter/setter.
244
245 // Implement isa/cast/dyncast.
246 static bool classof(const CompileUnitDesc *) { return true; }
247 static bool classof(const DebugInfoDesc *D);
248
249 /// ApplyToFields - Target the visitor to the fields of the CompileUnitDesc.
250 ///
251 virtual void ApplyToFields(DIVisitor *Visitor);
252
253 /// getDescString - Return a string used to compose global names and labels.
254 ///
255 virtual const char *getDescString() const;
256
257 /// getTypeString - Return a string used to label this descriptor's type.
258 ///
259 virtual const char *getTypeString() const;
260
261 /// getAnchorString - Return a string used to label this descriptor's anchor.
262 ///
263 static const char *AnchorString;
264 virtual const char *getAnchorString() const;
265
266 #ifndef NDEBUG
267 virtual void dump();
268 #endif
269 };
270
271 //===----------------------------------------------------------------------===//
272 /// TypeDesc - This class packages debug information associated with a type.
273 ///
274 class TypeDesc : public DebugInfoDesc {
275 private:
276 enum {
277 FlagPrivate = 1 << 0,
278 FlagProtected = 1 << 1
279 };
280 DebugInfoDesc *Context; // Context debug descriptor.
281 std::string Name; // Type name (may be empty.)
282 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
283 unsigned Line; // Defined line# (may be zero.)
284 uint64_t Size; // Type bit size (may be zero.)
285 uint64_t Align; // Type bit alignment (may be zero.)
286 uint64_t Offset; // Type bit offset (may be zero.)
287 unsigned Flags; // Miscellaneous flags.
288
289 public:
290 TypeDesc(unsigned T);
291
292 // Accessors
293 DebugInfoDesc *getContext() const { return Context; }
294 const std::string &getName() const { return Name; }
295 CompileUnitDesc *getFile() const {
296 return static_cast(File);
297 }
298 unsigned getLine() const { return Line; }
299 uint64_t getSize() const { return Size; }
300 uint64_t getAlign() const { return Align; }
301 uint64_t getOffset() const { return Offset; }
302 bool isPrivate() const {
303 return (Flags & FlagPrivate) != 0;
304 }
305 bool isProtected() const {
306 return (Flags & FlagProtected) != 0;
307 }
308 void setContext(DebugInfoDesc *C) { Context = C; }
309 void setName(const std::string &N) { Name = N; }
310 void setFile(CompileUnitDesc *U) {
311 File = static_cast(U);
312 }
313 void setLine(unsigned L) { Line = L; }
314 void setSize(uint64_t S) { Size = S; }
315 void setAlign(uint64_t A) { Align = A; }
316 void setOffset(uint64_t O) { Offset = O; }
317 void setIsPrivate() { Flags |= FlagPrivate; }
318 void setIsProtected() { Flags |= FlagProtected; }
319
320 /// ApplyToFields - Target the visitor to the fields of the TypeDesc.
321 ///
322 virtual void ApplyToFields(DIVisitor *Visitor);
323
324 /// getDescString - Return a string used to compose global names and labels.
325 ///
326 virtual const char *getDescString() const;
327
328 /// getTypeString - Return a string used to label this descriptor's type.
329 ///
330 virtual const char *getTypeString() const;
331
332 #ifndef NDEBUG
333 virtual void dump();
334 #endif
335 };
336
337 //===----------------------------------------------------------------------===//
338 /// BasicTypeDesc - This class packages debug information associated with a
339 /// basic type (eg. int, bool, double.)
340 class BasicTypeDesc : public TypeDesc {
341 private:
342 unsigned Encoding; // Type encoding.
343
344 public:
345 BasicTypeDesc();
346
347 // Accessors
348 unsigned getEncoding() const { return Encoding; }
349 void setEncoding(unsigned E) { Encoding = E; }
350
351 // Implement isa/cast/dyncast.
352 static bool classof(const BasicTypeDesc *) { return true; }
353 static bool classof(const DebugInfoDesc *D);
354
355 /// ApplyToFields - Target the visitor to the fields of the BasicTypeDesc.
356 ///
357 virtual void ApplyToFields(DIVisitor *Visitor);
358
359 /// getDescString - Return a string used to compose global names and labels.
360 ///
361 virtual const char *getDescString() const;
362
363 /// getTypeString - Return a string used to label this descriptor's type.
364 ///
365 virtual const char *getTypeString() const;
366
367 #ifndef NDEBUG
368 virtual void dump();
369 #endif
370 };
371
372
373 //===----------------------------------------------------------------------===//
374 /// DerivedTypeDesc - This class packages debug information associated with a
375 /// derived types (eg., typedef, pointer, reference.)
376 class DerivedTypeDesc : public TypeDesc {
377 private:
378 DebugInfoDesc *FromType; // Type derived from.
379
380 public:
381 DerivedTypeDesc(unsigned T);
382
383 // Accessors
384 TypeDesc *getFromType() const {
385 return static_cast(FromType);
386 }
387 void setFromType(TypeDesc *F) {
388 FromType = static_cast(F);
389 }
390
391 // Implement isa/cast/dyncast.
392 static bool classof(const DerivedTypeDesc *) { return true; }
393 static bool classof(const DebugInfoDesc *D);
394
395 /// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc.
396 ///
397 virtual void ApplyToFields(DIVisitor *Visitor);
398
399 /// getDescString - Return a string used to compose global names and labels.
400 ///
401 virtual const char *getDescString() const;
402
403 /// getTypeString - Return a string used to label this descriptor's type.
404 ///
405 virtual const char *getTypeString() const;
406
407 #ifndef NDEBUG
408 virtual void dump();
409 #endif
410 };
411
412 //===----------------------------------------------------------------------===//
413 /// CompositeTypeDesc - This class packages debug information associated with a
414 /// array/struct types (eg., arrays, struct, union, enums.)
415 class CompositeTypeDesc : public DerivedTypeDesc {
416 private:
417 std::vector Elements;// Information used to compose type.
418
419 public:
420 CompositeTypeDesc(unsigned T);
421
422 // Accessors
423 std::vector &getElements() { return Elements; }
424
425 // Implement isa/cast/dyncast.
426 static bool classof(const CompositeTypeDesc *) { return true; }
427 static bool classof(const DebugInfoDesc *D);
428
429 /// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc.
430 ///
431 virtual void ApplyToFields(DIVisitor *Visitor);
432
433 /// getDescString - Return a string used to compose global names and labels.
434 ///
435 virtual const char *getDescString() const;
436
437 /// getTypeString - Return a string used to label this descriptor's type.
438 ///
439 virtual const char *getTypeString() const;
440
441 #ifndef NDEBUG
442 virtual void dump();
443 #endif
444 };
445
446 //===----------------------------------------------------------------------===//
447 /// SubrangeDesc - This class packages debug information associated with integer
448 /// value ranges.
449 class SubrangeDesc : public DebugInfoDesc {
450 private:
451 int64_t Lo; // Low value of range.
452 int64_t Hi; // High value of range.
453
454 public:
455 SubrangeDesc();
456
457 // Accessors
458 int64_t getLo() const { return Lo; }
459 int64_t getHi() const { return Hi; }
460 void setLo(int64_t L) { Lo = L; }
461 void setHi(int64_t H) { Hi = H; }
462
463 // Implement isa/cast/dyncast.
464 static bool classof(const SubrangeDesc *) { return true; }
465 static bool classof(const DebugInfoDesc *D);
466
467 /// ApplyToFields - Target the visitor to the fields of the SubrangeDesc.
468 ///
469 virtual void ApplyToFields(DIVisitor *Visitor);
470
471 /// getDescString - Return a string used to compose global names and labels.
472 ///
473 virtual const char *getDescString() const;
474
475 /// getTypeString - Return a string used to label this descriptor's type.
476 ///
477 virtual const char *getTypeString() const;
478
479 #ifndef NDEBUG
480 virtual void dump();
481 #endif
482 };
483
484 //===----------------------------------------------------------------------===//
485 /// EnumeratorDesc - This class packages debug information associated with
486 /// named integer constants.
487 class EnumeratorDesc : public DebugInfoDesc {
488 private:
489 std::string Name; // Enumerator name.
490 int64_t Value; // Enumerator value.
491
492 public:
493 EnumeratorDesc();
494
495 // Accessors
496 const std::string &getName() const { return Name; }
497 int64_t getValue() const { return Value; }
498 void setName(const std::string &N) { Name = N; }
499 void setValue(int64_t V) { Value = V; }
500
501 // Implement isa/cast/dyncast.
502 static bool classof(const EnumeratorDesc *) { return true; }
503 static bool classof(const DebugInfoDesc *D);
504
505 /// ApplyToFields - Target the visitor to the fields of the EnumeratorDesc.
506 ///
507 virtual void ApplyToFields(DIVisitor *Visitor);
508
509 /// getDescString - Return a string used to compose global names and labels.
510 ///
511 virtual const char *getDescString() const;
512
513 /// getTypeString - Return a string used to label this descriptor's type.
514 ///
515 virtual const char *getTypeString() const;
516
517 #ifndef NDEBUG
518 virtual void dump();
519 #endif
520 };
521
522 //===----------------------------------------------------------------------===//
523 /// VariableDesc - This class packages debug information associated with a
524 /// subprogram variable.
525 ///
526 class VariableDesc : public DebugInfoDesc {
527 private:
528 DebugInfoDesc *Context; // Context debug descriptor.
529 std::string Name; // Type name (may be empty.)
530 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
531 unsigned Line; // Defined line# (may be zero.)
532 DebugInfoDesc *TyDesc; // Type of variable.
533
534 public:
535 VariableDesc(unsigned T);
536
537 // Accessors
538 DebugInfoDesc *getContext() const { return Context; }
539 const std::string &getName() const { return Name; }
540 CompileUnitDesc *getFile() const {
541 return static_cast(File);
542 }
543 unsigned getLine() const { return Line; }
544 TypeDesc *getType() const {
545 return static_cast(TyDesc);
546 }
547 void setContext(DebugInfoDesc *C) { Context = C; }
548 void setName(const std::string &N) { Name = N; }
549 void setFile(CompileUnitDesc *U) {
550 File = static_cast(U);
551 }
552 void setLine(unsigned L) { Line = L; }
553 void setType(TypeDesc *T) {
554 TyDesc = static_cast(T);
555 }
556
557 // Implement isa/cast/dyncast.
558 static bool classof(const VariableDesc *) { return true; }
559 static bool classof(const DebugInfoDesc *D);
560
561 /// ApplyToFields - Target the visitor to the fields of the VariableDesc.
562 ///
563 virtual void ApplyToFields(DIVisitor *Visitor);
564
565 /// getDescString - Return a string used to compose global names and labels.
566 ///
567 virtual const char *getDescString() const;
568
569 /// getTypeString - Return a string used to label this descriptor's type.
570 ///
571 virtual const char *getTypeString() const;
572
573 #ifndef NDEBUG
574 virtual void dump();
575 #endif
576 };
577
578 //===----------------------------------------------------------------------===//
579 /// GlobalDesc - This class is the base descriptor for global functions and
580 /// variables.
581 class GlobalDesc : public AnchoredDesc {
582 private:
583 DebugInfoDesc *Context; // Context debug descriptor.
584 std::string Name; // Global name.
585 std::string FullName; // Fully qualified name.
586 std::string LinkageName; // Name for binding to MIPS linkage.
587 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
588 unsigned Line; // Defined line# (may be zero.)
589 DebugInfoDesc *TyDesc; // Type debug descriptor.
590 bool IsStatic; // Is the global a static.
591 bool IsDefinition; // Is the global defined in context.
592
593 protected:
594 GlobalDesc(unsigned T);
595
596 public:
597 // Accessors
598 DebugInfoDesc *getContext() const { return Context; }
599 const std::string &getName() const { return Name; }
600 const std::string &getFullName() const { return FullName; }
601 const std::string &getLinkageName() const { return LinkageName; }
602 CompileUnitDesc *getFile() const {
603 return static_cast(File);
604 }
605 unsigned getLine() const { return Line; }
606 TypeDesc *getType() const {
607 return static_cast(TyDesc);
608 }
609 bool isStatic() const { return IsStatic; }
610 bool isDefinition() const { return IsDefinition; }
611 void setContext(DebugInfoDesc *C) { Context = C; }
612 void setName(const std::string &N) { Name = N; }
613 void setFullName(const std::string &N) { FullName = N; }
614 void setLinkageName(const std::string &N) { LinkageName = N; }
615 void setFile(CompileUnitDesc *U) {
616 File = static_cast(U);
617 }
618 void setLine(unsigned L) { Line = L; }
619 void setType(TypeDesc *T) {
620 TyDesc = static_cast(T);
621 }
622 void setIsStatic(bool IS) { IsStatic = IS; }
623 void setIsDefinition(bool ID) { IsDefinition = ID; }
624
625 /// ApplyToFields - Target the visitor to the fields of the GlobalDesc.
626 ///
627 virtual void ApplyToFields(DIVisitor *Visitor);
628 };
629
630 //===----------------------------------------------------------------------===//
631 /// GlobalVariableDesc - This class packages debug information associated with a
632 /// GlobalVariable.
633 class GlobalVariableDesc : public GlobalDesc {
634 private:
635 GlobalVariable *Global; // llvm global.
636
637 public:
638 GlobalVariableDesc();
639
640 // Accessors.
641 GlobalVariable *getGlobalVariable() const { return Global; }
642 void setGlobalVariable(GlobalVariable *GV) { Global = GV; }
643
644 // Implement isa/cast/dyncast.
645 static bool classof(const GlobalVariableDesc *) { return true; }
646 static bool classof(const DebugInfoDesc *D);
647
648 /// ApplyToFields - Target the visitor to the fields of the
649 /// GlobalVariableDesc.
650 virtual void ApplyToFields(DIVisitor *Visitor);
651
652 /// getDescString - Return a string used to compose global names and labels.
653 ///
654 virtual const char *getDescString() const;
655
656 /// getTypeString - Return a string used to label this descriptor's type.
657 ///
658 virtual const char *getTypeString() const;
659
660 /// getAnchorString - Return a string used to label this descriptor's anchor.
661 ///
662 static const char *AnchorString;
663 virtual const char *getAnchorString() const;
664
665 #ifndef NDEBUG
666 virtual void dump();
667 #endif
668 };
669
670 //===----------------------------------------------------------------------===//
671 /// SubprogramDesc - This class packages debug information associated with a
672 /// subprogram/function.
673 class SubprogramDesc : public GlobalDesc {
674 private:
675
676 public:
677 SubprogramDesc();
678
679 // Accessors
680
681 // Implement isa/cast/dyncast.
682 static bool classof(const SubprogramDesc *) { return true; }
683 static bool classof(const DebugInfoDesc *D);
684
685 /// ApplyToFields - Target the visitor to the fields of the SubprogramDesc.
686 ///
687 virtual void ApplyToFields(DIVisitor *Visitor);
688
689 /// getDescString - Return a string used to compose global names and labels.
690 ///
691 virtual const char *getDescString() const;
692
693 /// getTypeString - Return a string used to label this descriptor's type.
694 ///
695 virtual const char *getTypeString() const;
696
697 /// getAnchorString - Return a string used to label this descriptor's anchor.
698 ///
699 static const char *AnchorString;
700 virtual const char *getAnchorString() const;
701
702 #ifndef NDEBUG
703 virtual void dump();
704 #endif
705 };
706
707 //===----------------------------------------------------------------------===//
708 /// BlockDesc - This descriptor groups variables and blocks nested in a block.
709 ///
710 class BlockDesc : public DebugInfoDesc {
711 private:
712 DebugInfoDesc *Context; // Context debug descriptor.
713
714 public:
715 BlockDesc();
716
717 // Accessors
718 DebugInfoDesc *getContext() const { return Context; }
719 void setContext(DebugInfoDesc *C) { Context = C; }
720
721 // Implement isa/cast/dyncast.
722 static bool classof(const BlockDesc *) { return true; }
723 static bool classof(const DebugInfoDesc *D);
724
725 /// ApplyToFields - Target the visitor to the fields of the BlockDesc.
726 ///
727 virtual void ApplyToFields(DIVisitor *Visitor);
728
729 /// getDescString - Return a string used to compose global names and labels.
730 ///
731 virtual const char *getDescString() const;
732
733 /// getTypeString - Return a string used to label this descriptor's type.
734 ///
735 virtual const char *getTypeString() const;
736
737 #ifndef NDEBUG
738 virtual void dump();
739 #endif
740 };
741
742 //===----------------------------------------------------------------------===//
743 /// DIDeserializer - This class is responsible for casting GlobalVariables
744 /// into DebugInfoDesc objects.
745 class DIDeserializer {
746 private:
747 std::map GlobalDescs;
748 // Previously defined gloabls.
749
750 public:
751 DIDeserializer() {}
752 ~DIDeserializer() {}
753
754 /// Deserialize - Reconstitute a GlobalVariable into it's component
755 /// DebugInfoDesc objects.
756 DebugInfoDesc *Deserialize(Value *V);
757 DebugInfoDesc *Deserialize(GlobalVariable *GV);
758 };
759
760 //===----------------------------------------------------------------------===//
761 /// DISerializer - This class is responsible for casting DebugInfoDesc objects
762 /// into GlobalVariables.
763 class DISerializer {
764 private:
765 Module *M; // Definition space module.
766 PointerType *StrPtrTy; // A "sbyte *" type. Created lazily.
767 PointerType *EmptyStructPtrTy; // A "{ }*" type. Created lazily.
768 std::map TagTypes;
769 // Types per Tag. Created lazily.
770 std::map DescGlobals;
771 // Previously defined descriptors.
772 std::map StringCache;
773 // Previously defined strings.
774
775 public:
776 DISerializer()
777 : M(NULL)
778 , StrPtrTy(NULL)
779 , EmptyStructPtrTy(NULL)
780 , TagTypes()
781 , DescGlobals()
782 , StringCache()
783 {}
784 ~DISerializer() {}
785
786 // Accessors
787 Module *getModule() const { return M; };
788 void setModule(Module *module) { M = module; }
789
790 /// getStrPtrType - Return a "sbyte *" type.
791 ///
792 const PointerType *getStrPtrType();
793
794 /// getEmptyStructPtrType - Return a "{ }*" type.
795 ///
796 const PointerType *getEmptyStructPtrType();
797
798 /// getTagType - Return the type describing the specified descriptor (via
799 /// tag.)
800 const StructType *getTagType(DebugInfoDesc *DD);
801
802 /// getString - Construct the string as constant string global.
803 ///
804 Constant *getString(const std::string &String);
805
806 /// Serialize - Recursively cast the specified descriptor into a
807 /// GlobalVariable so that it can be serialized to a .bc or .ll file.
808 GlobalVariable *Serialize(DebugInfoDesc *DD);
809 };
810
811 //===----------------------------------------------------------------------===//
812 /// DIVerifier - This class is responsible for verifying the given network of
813 /// GlobalVariables are valid as DebugInfoDesc objects.
814 class DIVerifier {
815 private:
816 enum {
817 Unknown = 0,
818 Invalid,
819 Valid
820 };
821 std::map Validity;// Tracks prior results.
822 std::map Counts; // Count of fields per Tag type.
823
824 public:
825 DIVerifier()
826 : Validity()
827 , Counts()
828 {}
829 ~DIVerifier() {}
830
831 /// Verify - Return true if the GlobalVariable appears to be a valid
832 /// serialization of a DebugInfoDesc.
833 bool Verify(Value *V);
834 bool Verify(GlobalVariable *GV);
835 };
836
837 //===----------------------------------------------------------------------===//
838 /// SourceLineInfo - This class is used to record source line correspondence.
839 ///
840 class SourceLineInfo {
841 private:
842 unsigned Line; // Source line number.
843 unsigned Column; // Source column.
844 unsigned SourceID; // Source ID number.
845 unsigned LabelID; // Label in code ID number.
846
847 public:
848 SourceLineInfo(unsigned L, unsigned C, unsigned S, unsigned I)
849 : Line(L), Column(C), SourceID(S), LabelID(I) {}
850
851 // Accessors
852 unsigned getLine() const { return Line; }
853 unsigned getColumn() const { return Column; }
854 unsigned getSourceID() const { return SourceID; }
855 unsigned getLabelID() const { return LabelID; }
856 };
857
858 //===----------------------------------------------------------------------===//
859 /// SourceFileInfo - This class is used to track source information.
860 ///
861 class SourceFileInfo {
862 private:
863 unsigned DirectoryID; // Directory ID number.
864 std::string Name; // File name (not including directory.)
865
866 public:
867 SourceFileInfo(unsigned D, const std::string &N) : DirectoryID(D), Name(N) {}
868
869 // Accessors
870 unsigned getDirectoryID() const { return DirectoryID; }
871 const std::string &getName() const { return Name; }
872
873 /// operator== - Used by UniqueVector to locate entry.
874 ///
875 bool operator==(const SourceFileInfo &SI) const {
876 return getDirectoryID() == SI.getDirectoryID() && getName() == SI.getName();
877 }
878
879 /// operator< - Used by UniqueVector to locate entry.
880 ///
881 bool operator<(const SourceFileInfo &SI) const {
882 return getDirectoryID() < SI.getDirectoryID() ||
883 (getDirectoryID() == SI.getDirectoryID() && getName() < SI.getName());
884 }
885 };
886
887 //===----------------------------------------------------------------------===//
888 /// DebugVariable - This class is used to track local variable information.
889 ///
890 class DebugVariable {
891 private:
892 VariableDesc *Desc; // Variable Descriptor.
893 unsigned FrameIndex; // Variable frame index.
894
895 public:
896 DebugVariable(VariableDesc *D, unsigned I)
897 : Desc(D)
898 , FrameIndex(I)
899 {}
900
901 // Accessors.
902 VariableDesc *getDesc() const { return Desc; }
903 unsigned getFrameIndex() const { return FrameIndex; }
904 };
905
906 //===----------------------------------------------------------------------===//
907 /// DebugScope - This class is used to track scope information.
908 ///
909 class DebugScope {
910 private:
911 DebugScope *Parent; // Parent to this scope.
912 DebugInfoDesc *Desc; // Debug info descriptor for scope.
913 // Either subprogram or block.
914 unsigned StartLabelID; // Label ID of the beginning of scope.
915 unsigned EndLabelID; // Label ID of the end of scope.
916 std::vector Scopes; // Scopes defined in scope.
917 std::vector Variables;// Variables declared in scope.
918
919 public:
920 DebugScope(DebugScope *P, DebugInfoDesc *D)
921 : Parent(P)
922 , Desc(D)
923 , StartLabelID(0)
924 , EndLabelID(0)
925 , Scopes()
926 , Variables()
927 {}
928 ~DebugScope();
929
930 // Accessors.
931 DebugScope *getParent() const { return Parent; }
932 DebugInfoDesc *getDesc() const { return Desc; }
933 unsigned getStartLabelID() const { return StartLabelID; }
934 unsigned getEndLabelID() const { return EndLabelID; }
935 std::vector &getScopes() { return Scopes; }
936 std::vector &getVariables() { return Variables; }
937 void setStartLabelID(unsigned S) { StartLabelID = S; }
938 void setEndLabelID(unsigned E) { EndLabelID = E; }
939
940 /// AddScope - Add a scope to the scope.
941 ///
942 void AddScope(DebugScope *S) { Scopes.push_back(S); }
943
944 /// AddVariable - Add a variable to the scope.
945 ///
946 void AddVariable(DebugVariable *V) { Variables.push_back(V); }
947 };
948
949 //===----------------------------------------------------------------------===//
950 /// MachineDebugInfo - This class contains debug information specific to a
951 /// module. Queries can be made by different debugging schemes and reformated
952 /// for specific use.
953 ///
954 class MachineDebugInfo : public ImmutablePass {
955 private:
956 // Use the same deserializer/verifier for the module.
957 DIDeserializer DR;
958 DIVerifier VR;
959
960 // CompileUnits - Uniquing vector for compile units.
961 UniqueVector CompileUnits;
962
963 // Directories - Uniquing vector for directories.
964 UniqueVector Directories;
965
966 // SourceFiles - Uniquing vector for source files.
967 UniqueVector SourceFiles;
968
969 // Lines - List of of source line correspondence.
970 std::vector Lines;
971
972 // LabelIDList - One entry per assigned label. Normally the entry is equal to
973 // the list index(+1). If the entry is zero then the label has been deleted.
974 // Any other value indicates the label has been deleted by is mapped to
975 // another label.
976 std::vector LabelIDList;
977
978 // ScopeMap - Tracks the scopes in the current function.
979 std::map ScopeMap;
980
981 // RootScope - Top level scope for the current function.
982 //
983 DebugScope *RootScope;
984
985 // FrameMoves - List of moves done by a function's prolog. Used to construct
986 // frame maps by debug consumers.
987 std::vector FrameMoves;
988
989 public:
990 MachineDebugInfo();
991 ~MachineDebugInfo();
992
993 /// doInitialization - Initialize the debug state for a new module.
994 ///
995 bool doInitialization();
996
997 /// doFinalization - Tear down the debug state after completion of a module.
998 ///
999 bool doFinalization();
1000
1001 /// BeginFunction - Begin gathering function debug information.
1002 ///
1003 void BeginFunction(MachineFunction *MF);
1004
1005 /// EndFunction - Discard function debug information.
1006 ///
1007 void EndFunction();
1008
1009 /// getDescFor - Convert a Value to a debug information descriptor.
1010 ///
1011 // FIXME - use new Value type when available.
1012 DebugInfoDesc *getDescFor(Value *V);
1013
1014 /// Verify - Verify that a Value is debug information descriptor.
1015 ///
1016 bool Verify(Value *V);
1017
1018 /// AnalyzeModule - Scan the module for global debug information.
1019 ///
1020 void AnalyzeModule(Module &M);
1021
1022 /// hasInfo - Returns true if valid debug info is present.
1023 ///
1024 bool hasInfo() const { return !CompileUnits.empty(); }
1025
1026 /// NextLabelID - Return the next unique label id.
1027 ///
1028 unsigned NextLabelID() {
1029 unsigned ID = LabelIDList.size() + 1;
1030 LabelIDList.push_back(ID);
1031 return ID;
1032 }
1033
1034 /// RecordLabel - Records location information and associates it with a
1035 /// debug label. Returns a unique label ID used to generate a label and
1036 /// provide correspondence to the source line list.
1037 unsigned RecordLabel(unsigned Line, unsigned Column, unsigned Source);
1038
1039 /// InvalidateLabel - Inhibit use of the specified label # from
1040 /// MachineDebugInfo, for example because the code was deleted.
1041 void InvalidateLabel(unsigned LabelID) {
1042 // Remap to zero to indicate deletion.
1043 RemapLabel(LabelID, 0);
1044 }
1045
1046 /// RemapLabel - Indicate that a label has been merged into another.
1047 ///
1048 void RemapLabel(unsigned OldLabelID, unsigned NewLabelID) {
1049 assert(0 < OldLabelID && OldLabelID <= LabelIDList.size() &&
1050 "Old debug label ID out of range.");
1051 assert(NewLabelID <= LabelIDList.size() &&
1052 "New debug label ID out of range.");
1053 LabelIDList[OldLabelID - 1] = NewLabelID;
1054 }
1055
1056 /// MappedLabel - Find out the label's final ID. Zero indicates deletion.
1057 /// ID != Mapped ID indicates that the label was folded into another label.
1058 unsigned MappedLabel(unsigned LabelID) const {
1059 assert(LabelID <= LabelIDList.size() && "Debug label ID out of range.");
1060 return LabelID ? LabelIDList[LabelID - 1] : 0;
1061 }
1062
1063 /// RecordSource - Register a source file with debug info. Returns an source
1064 /// ID.
1065 unsigned RecordSource(const std::string &Directory,
1066 const std::string &Source);
1067 unsigned RecordSource(const CompileUnitDesc *CompileUnit);
1068
1069 /// getDirectories - Return the UniqueVector of std::string representing
1070 /// directories.
1071 const UniqueVector &getDirectories() const {
1072 return Directories;
1073 }
1074
1075 /// getSourceFiles - Return the UniqueVector of source files.
1076 ///
1077 const UniqueVector &getSourceFiles() const {
1078 return SourceFiles;
1079 }
1080
1081 /// getSourceLines - Return a vector of source lines.
1082 ///
1083 const std::vector &getSourceLines() const {
1084 return Lines;
1085 }
1086
1087 // FIXME: nuke this.
1088 void ClearLineInfo() {
1089 Lines.clear();
1090 }
1091
1092 /// SetupCompileUnits - Set up the unique vector of compile units.
1093 ///
1094 void SetupCompileUnits(Module &M);
1095
1096 /// getCompileUnits - Return a vector of debug compile units.
1097 ///
1098 const UniqueVector getCompileUnits() const;
1099
1100 /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
1101 /// named GlobalVariable.
1102 std::vector
1103 getGlobalVariablesUsing(Module &M, const std::string &RootName);
1104
1105 /// getAnchoredDescriptors - Return a vector of anchored debug descriptors.
1106 ///
1107 template std::vector getAnchoredDescriptors(Module &M) {
1108 T Desc;
1109 std::vector Globals =
1110 getGlobalVariablesUsing(M, Desc.getAnchorString());
1111 std::vector AnchoredDescs;
1112 for (unsigned i = 0, N = Globals.size(); i < N; ++i) {
1113 GlobalVariable *GV = Globals[i];
1114
1115 // FIXME - In the short term, changes are too drastic to continue.
1116 if (DebugInfoDesc::TagFromGlobal(GV) == Desc.getTag() &&
1117 DebugInfoDesc::VersionFromGlobal(GV) == LLVMDebugVersion) {
1118 AnchoredDescs.push_back(cast(DR.Deserialize(GV)));
1119 }
1120 }
1121
1122 return AnchoredDescs;
1123 }
1124
1125 /// RecordRegionStart - Indicate the start of a region.
1126 ///
1127 unsigned RecordRegionStart(Value *V);
1128
1129 /// RecordRegionEnd - Indicate the end of a region.
1130 ///
1131 unsigned RecordRegionEnd(Value *V);
1132
1133 /// RecordVariable - Indicate the declaration of a local variable.
1134 ///
1135 void RecordVariable(Value *V, unsigned FrameIndex);
1136
1137 /// getRootScope - Return current functions root scope.
1138 ///
1139 DebugScope *getRootScope() { return RootScope; }
1140
1141 /// getOrCreateScope - Returns the scope associated with the given descriptor.
1142 ///
1143 DebugScope *getOrCreateScope(DebugInfoDesc *ScopeDesc);
1144
1145 /// getFrameMoves - Returns a reference to a list of moves done in the current
1146 /// function's prologue. Used to construct frame maps for debug comsumers.
1147 std::vector &getFrameMoves() { return FrameMoves; }
1148
1149 }; // End class MachineDebugInfo
1150
1151 } // End llvm namespace
1152
1153 #endif
0 //===-- llvm/CodeGen/MachineModuleInfo.h ------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by James M. Laskey and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Collect meta information for a module. This information should be in a
10 // neutral form that can be used by different debugging and exception handling
11 // schemes.
12 //
13 // The organization of information is primarily clustered around the source
14 // compile units. The main exception is source line correspondence where
15 // inlining may interleave code from various compile units.
16 //
17 // The following information can be retrieved from the MachineModuleInfo.
18 //
19 // -- Source directories - Directories are uniqued based on their canonical
20 // string and assigned a sequential numeric ID (base 1.)
21 // -- Source files - Files are also uniqued based on their name and directory
22 // ID. A file ID is sequential number (base 1.)
23 // -- Source line correspondence - A vector of file ID, line#, column# triples.
24 // A DEBUG_LOCATION instruction is generated by the DAG Legalizer
25 // corresponding to each entry in the source line list. This allows a debug
26 // emitter to generate labels referenced by debug information tables.
27 //
28 //===----------------------------------------------------------------------===//
29
30 #ifndef LLVM_CODEGEN_MACHINEMODULEINFO_H
31 #define LLVM_CODEGEN_MACHINEMODULEINFO_H
32
33 #include "llvm/Support/Dwarf.h"
34 #include "llvm/Support/DataTypes.h"
35 #include "llvm/ADT/UniqueVector.h"
36 #include "llvm/GlobalValue.h"
37 #include "llvm/Pass.h"
38
39 namespace llvm {
40
41 //===----------------------------------------------------------------------===//
42 // Forward declarations.
43 class Constant;
44 class DebugInfoDesc;
45 class GlobalVariable;
46 class MachineFunction;
47 class MachineMove;
48 class Module;
49 class PointerType;
50 class StructType;
51
52 //===----------------------------------------------------------------------===//
53 // Debug info constants.
54
55 enum {
56 LLVMDebugVersion = (6 << 16), // Current version of debug information.
57 LLVMDebugVersion5 = (5 << 16), // Constant for version 5.
58 LLVMDebugVersion4 = (4 << 16), // Constant for version 4.
59 LLVMDebugVersionMask = 0xffff0000 // Mask for version number.
60 };
61
62 //===----------------------------------------------------------------------===//
63 /// DIVisitor - Subclasses of this class apply steps to each of the fields in
64 /// the supplied DebugInfoDesc.
65 class DIVisitor {
66 public:
67 DIVisitor() {}
68 virtual ~DIVisitor() {}
69
70 /// ApplyToFields - Target the visitor to each field of the debug information
71 /// descriptor.
72 void ApplyToFields(DebugInfoDesc *DD);
73
74 /// Apply - Subclasses override each of these methods to perform the
75 /// appropriate action for the type of field.
76 virtual void Apply(int &Field) = 0;
77 virtual void Apply(unsigned &Field) = 0;
78 virtual void Apply(int64_t &Field) = 0;
79 virtual void Apply(uint64_t &Field) = 0;
80 virtual void Apply(bool &Field) = 0;
81 virtual void Apply(std::string &Field) = 0;
82 virtual void Apply(DebugInfoDesc *&Field) = 0;
83 virtual void Apply(GlobalVariable *&Field) = 0;
84 virtual void Apply(std::vector &Field) = 0;
85 };
86
87 //===----------------------------------------------------------------------===//
88 /// DebugInfoDesc - This class is the base class for debug info descriptors.
89 ///
90 class DebugInfoDesc {
91 private:
92 unsigned Tag; // Content indicator. Dwarf values are
93 // used but that does not limit use to
94 // Dwarf writers.
95
96 protected:
97 DebugInfoDesc(unsigned T) : Tag(T | LLVMDebugVersion) {}
98
99 public:
100 virtual ~DebugInfoDesc() {}
101
102 // Accessors
103 unsigned getTag() const { return Tag & ~LLVMDebugVersionMask; }
104 unsigned getVersion() const { return Tag & LLVMDebugVersionMask; }
105 void setTag(unsigned T) { Tag = T | LLVMDebugVersion; }
106
107 /// TagFromGlobal - Returns the tag number from a debug info descriptor
108 /// GlobalVariable. Return DIIValid if operand is not an unsigned int.
109 static unsigned TagFromGlobal(GlobalVariable *GV);
110
111 /// VersionFromGlobal - Returns the version number from a debug info
112 /// descriptor GlobalVariable. Return DIIValid if operand is not an unsigned
113 /// int.
114 static unsigned VersionFromGlobal(GlobalVariable *GV);
115
116 /// DescFactory - Create an instance of debug info descriptor based on Tag.
117 /// Return NULL if not a recognized Tag.
118 static DebugInfoDesc *DescFactory(unsigned Tag);
119
120 /// getLinkage - get linkage appropriate for this type of descriptor.
121 ///
122 virtual GlobalValue::LinkageTypes getLinkage() const;
123
124 //===--------------------------------------------------------------------===//
125 // Subclasses should supply the following static methods.
126
127 // Implement isa/cast/dyncast.
128 static bool classof(const DebugInfoDesc *) { return true; }
129
130 //===--------------------------------------------------------------------===//
131 // Subclasses should supply the following virtual methods.
132
133 /// ApplyToFields - Target the vistor to the fields of the descriptor.
134 ///
135 virtual void ApplyToFields(DIVisitor *Visitor);
136
137 /// getDescString - Return a string used to compose global names and labels.
138 ///
139 virtual const char *getDescString() const = 0;
140
141 /// getTypeString - Return a string used to label this descriptor's type.
142 ///
143 virtual const char *getTypeString() const = 0;
144
145 #ifndef NDEBUG
146 virtual void dump() = 0;
147 #endif
148 };
149
150 //===----------------------------------------------------------------------===//
151 /// AnchorDesc - Descriptors of this class act as markers for identifying
152 /// descriptors of certain groups.
153 class AnchoredDesc;
154 class AnchorDesc : public DebugInfoDesc {
155 private:
156 unsigned AnchorTag; // Tag number of descriptors anchored
157 // by this object.
158
159 public:
160 AnchorDesc();
161 AnchorDesc(AnchoredDesc *D);
162
163 // Accessors
164 unsigned getAnchorTag() const { return AnchorTag; }
165
166 // Implement isa/cast/dyncast.
167 static bool classof(const AnchorDesc *) { return true; }
168 static bool classof(const DebugInfoDesc *D);
169
170 /// getLinkage - get linkage appropriate for this type of descriptor.
171 ///
172 virtual GlobalValue::LinkageTypes getLinkage() const;
173
174 /// ApplyToFields - Target the visitor to the fields of the AnchorDesc.
175 ///
176 virtual void ApplyToFields(DIVisitor *Visitor);
177
178 /// getDescString - Return a string used to compose global names and labels.
179 ///
180 virtual const char *getDescString() const;
181
182 /// getTypeString - Return a string used to label this descriptor's type.
183 ///
184 virtual const char *getTypeString() const;
185
186 #ifndef NDEBUG
187 virtual void dump();
188 #endif
189 };
190
191 //===----------------------------------------------------------------------===//
192 /// AnchoredDesc - This class manages anchors for a variety of top level
193 /// descriptors.
194 class AnchoredDesc : public DebugInfoDesc {
195 private:
196 DebugInfoDesc *Anchor; // Anchor for all descriptors of the
197 // same type.
198
199 protected:
200
201 AnchoredDesc(unsigned T);
202
203 public:
204 // Accessors.
205 AnchorDesc *getAnchor() const { return static_cast(Anchor); }
206 void setAnchor(AnchorDesc *A) { Anchor = static_cast(A); }
207
208 //===--------------------------------------------------------------------===//
209 // Subclasses should supply the following virtual methods.
210
211 /// getAnchorString - Return a string used to label descriptor's anchor.
212 ///
213 virtual const char *getAnchorString() const = 0;
214
215 /// ApplyToFields - Target the visitor to the fields of the AnchoredDesc.
216 ///
217 virtual void ApplyToFields(DIVisitor *Visitor);
218 };
219
220 //===----------------------------------------------------------------------===//
221 /// CompileUnitDesc - This class packages debug information associated with a
222 /// source/header file.
223 class CompileUnitDesc : public AnchoredDesc {
224 private:
225 unsigned Language; // Language number (ex. DW_LANG_C89.)
226 std::string FileName; // Source file name.
227 std::string Directory; // Source file directory.
228 std::string Producer; // Compiler string.
229
230 public:
231 CompileUnitDesc();
232
233
234 // Accessors
235 unsigned getLanguage() const { return Language; }
236 const std::string &getFileName() const { return FileName; }
237 const std::string &getDirectory() const { return Directory; }
238 const std::string &getProducer() const { return Producer; }
239 void setLanguage(unsigned L) { Language = L; }
240 void setFileName(const std::string &FN) { FileName = FN; }
241 void setDirectory(const std::string &D) { Directory = D; }
242 void setProducer(const std::string &P) { Producer = P; }
243
244 // FIXME - Need translation unit getter/setter.
245
246 // Implement isa/cast/dyncast.
247 static bool classof(const CompileUnitDesc *) { return true; }
248 static bool classof(const DebugInfoDesc *D);
249
250 /// ApplyToFields - Target the visitor to the fields of the CompileUnitDesc.
251 ///
252 virtual void ApplyToFields(DIVisitor *Visitor);
253
254 /// getDescString - Return a string used to compose global names and labels.
255 ///
256 virtual const char *getDescString() const;
257
258 /// getTypeString - Return a string used to label this descriptor's type.
259 ///
260 virtual const char *getTypeString() const;
261
262 /// getAnchorString - Return a string used to label this descriptor's anchor.
263 ///
264 static const char *AnchorString;
265 virtual const char *getAnchorString() const;
266
267 #ifndef NDEBUG
268 virtual void dump();
269 #endif
270 };
271
272 //===----------------------------------------------------------------------===//
273 /// TypeDesc - This class packages debug information associated with a type.
274 ///
275 class TypeDesc : public DebugInfoDesc {
276 private:
277 enum {
278 FlagPrivate = 1 << 0,
279 FlagProtected = 1 << 1
280 };
281 DebugInfoDesc *Context; // Context debug descriptor.
282 std::string Name; // Type name (may be empty.)
283 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
284 unsigned Line; // Defined line# (may be zero.)
285 uint64_t Size; // Type bit size (may be zero.)
286 uint64_t Align; // Type bit alignment (may be zero.)
287 uint64_t Offset; // Type bit offset (may be zero.)
288 unsigned Flags; // Miscellaneous flags.
289
290 public:
291 TypeDesc(unsigned T);
292
293 // Accessors
294 DebugInfoDesc *getContext() const { return Context; }
295 const std::string &getName() const { return Name; }
296 CompileUnitDesc *getFile() const {
297 return static_cast(File);
298 }
299 unsigned getLine() const { return Line; }
300 uint64_t getSize() const { return Size; }
301 uint64_t getAlign() const { return Align; }
302 uint64_t getOffset() const { return Offset; }
303 bool isPrivate() const {
304 return (Flags & FlagPrivate) != 0;
305 }
306 bool isProtected() const {
307 return (Flags & FlagProtected) != 0;
308 }
309 void setContext(DebugInfoDesc *C) { Context = C; }
310 void setName(const std::string &N) { Name = N; }
311 void setFile(CompileUnitDesc *U) {
312 File = static_cast(U);
313 }
314 void setLine(unsigned L) { Line = L; }
315 void setSize(uint64_t S) { Size = S; }
316 void setAlign(uint64_t A) { Align = A; }
317 void setOffset(uint64_t O) { Offset = O; }
318 void setIsPrivate() { Flags |= FlagPrivate; }
319 void setIsProtected() { Flags |= FlagProtected; }
320
321 /// ApplyToFields - Target the visitor to the fields of the TypeDesc.
322 ///
323 virtual void ApplyToFields(DIVisitor *Visitor);
324
325 /// getDescString - Return a string used to compose global names and labels.
326 ///
327 virtual const char *getDescString() const;
328
329 /// getTypeString - Return a string used to label this descriptor's type.
330 ///
331 virtual const char *getTypeString() const;
332
333 #ifndef NDEBUG
334 virtual void dump();
335 #endif
336 };
337
338 //===----------------------------------------------------------------------===//
339 /// BasicTypeDesc - This class packages debug information associated with a
340 /// basic type (eg. int, bool, double.)
341 class BasicTypeDesc : public TypeDesc {
342 private:
343 unsigned Encoding; // Type encoding.
344
345 public:
346 BasicTypeDesc();
347
348 // Accessors
349 unsigned getEncoding() const { return Encoding; }
350 void setEncoding(unsigned E) { Encoding = E; }
351
352 // Implement isa/cast/dyncast.
353 static bool classof(const BasicTypeDesc *) { return true; }
354 static bool classof(const DebugInfoDesc *D);
355
356 /// ApplyToFields - Target the visitor to the fields of the BasicTypeDesc.
357 ///
358 virtual void ApplyToFields(DIVisitor *Visitor);
359
360 /// getDescString - Return a string used to compose global names and labels.
361 ///
362 virtual const char *getDescString() const;
363
364 /// getTypeString - Return a string used to label this descriptor's type.
365 ///
366 virtual const char *getTypeString() const;
367
368 #ifndef NDEBUG
369 virtual void dump();
370 #endif
371 };
372
373
374 //===----------------------------------------------------------------------===//
375 /// DerivedTypeDesc - This class packages debug information associated with a
376 /// derived types (eg., typedef, pointer, reference.)
377 class DerivedTypeDesc : public TypeDesc {
378 private:
379 DebugInfoDesc *FromType; // Type derived from.
380
381 public:
382 DerivedTypeDesc(unsigned T);
383
384 // Accessors
385 TypeDesc *getFromType() const {
386 return static_cast(FromType);
387 }
388 void setFromType(TypeDesc *F) {
389 FromType = static_cast(F);
390 }
391
392 // Implement isa/cast/dyncast.
393 static bool classof(const DerivedTypeDesc *) { return true; }
394 static bool classof(const DebugInfoDesc *D);
395
396 /// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc.
397 ///
398 virtual void ApplyToFields(DIVisitor *Visitor);
399
400 /// getDescString - Return a string used to compose global names and labels.
401 ///
402 virtual const char *getDescString() const;
403
404 /// getTypeString - Return a string used to label this descriptor's type.
405 ///
406 virtual const char *getTypeString() const;
407
408 #ifndef NDEBUG
409 virtual void dump();
410 #endif
411 };
412
413 //===----------------------------------------------------------------------===//
414 /// CompositeTypeDesc - This class packages debug information associated with a
415 /// array/struct types (eg., arrays, struct, union, enums.)
416 class CompositeTypeDesc : public DerivedTypeDesc {
417 private:
418 std::vector Elements;// Information used to compose type.
419
420 public:
421 CompositeTypeDesc(unsigned T);
422
423 // Accessors
424 std::vector &getElements() { return Elements; }
425
426 // Implement isa/cast/dyncast.
427 static bool classof(const CompositeTypeDesc *) { return true; }
428 static bool classof(const DebugInfoDesc *D);
429
430 /// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc.
431 ///
432 virtual void ApplyToFields(DIVisitor *Visitor);
433
434 /// getDescString - Return a string used to compose global names and labels.
435 ///
436 virtual const char *getDescString() const;
437
438 /// getTypeString - Return a string used to label this descriptor's type.
439 ///
440 virtual const char *getTypeString() const;
441
442 #ifndef NDEBUG
443 virtual void dump();
444 #endif
445 };
446
447 //===----------------------------------------------------------------------===//
448 /// SubrangeDesc - This class packages debug information associated with integer
449 /// value ranges.
450 class SubrangeDesc : public DebugInfoDesc {
451 private:
452 int64_t Lo; // Low value of range.
453 int64_t Hi; // High value of range.
454
455 public:
456 SubrangeDesc();
457
458 // Accessors
459 int64_t getLo() const { return Lo; }
460 int64_t getHi() const { return Hi; }
461 void setLo(int64_t L) { Lo = L; }
462 void setHi(int64_t H) { Hi = H; }
463
464 // Implement isa/cast/dyncast.
465 static bool classof(const SubrangeDesc *) { return true; }
466 static bool classof(const DebugInfoDesc *D);
467
468 /// ApplyToFields - Target the visitor to the fields of the SubrangeDesc.
469 ///
470 virtual void ApplyToFields(DIVisitor *Visitor);
471
472 /// getDescString - Return a string used to compose global names and labels.
473 ///
474 virtual const char *getDescString() const;
475
476 /// getTypeString - Return a string used to label this descriptor's type.
477 ///
478 virtual const char *getTypeString() const;
479
480 #ifndef NDEBUG
481 virtual void dump();
482 #endif
483 };
484
485 //===----------------------------------------------------------------------===//
486 /// EnumeratorDesc - This class packages debug information associated with
487 /// named integer constants.
488 class EnumeratorDesc : public DebugInfoDesc {
489 private:
490 std::string Name; // Enumerator name.
491 int64_t Value; // Enumerator value.
492
493 public:
494 EnumeratorDesc();
495
496 // Accessors
497 const std::string &getName() const { return Name; }
498 int64_t getValue() const { return Value; }
499 void setName(const std::string &N) { Name = N; }
500 void setValue(int64_t V) { Value = V; }
501
502 // Implement isa/cast/dyncast.
503 static bool classof(const EnumeratorDesc *) { return true; }
504 static bool classof(const DebugInfoDesc *D);
505
506 /// ApplyToFields - Target the visitor to the fields of the EnumeratorDesc.
507 ///
508 virtual void ApplyToFields(DIVisitor *Visitor);
509
510 /// getDescString - Return a string used to compose global names and labels.
511 ///
512 virtual const char *getDescString() const;
513
514 /// getTypeString - Return a string used to label this descriptor's type.
515 ///
516 virtual const char *getTypeString() const;
517
518 #ifndef NDEBUG
519 virtual void dump();
520 #endif
521 };
522
523 //===----------------------------------------------------------------------===//
524 /// VariableDesc - This class packages debug information associated with a
525 /// subprogram variable.
526 ///
527 class VariableDesc : public DebugInfoDesc {
528 private:
529 DebugInfoDesc *Context; // Context debug descriptor.
530 std::string Name; // Type name (may be empty.)
531 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
532 unsigned Line; // Defined line# (may be zero.)
533 DebugInfoDesc *TyDesc; // Type of variable.
534
535 public:
536 VariableDesc(unsigned T);
537
538 // Accessors
539 DebugInfoDesc *getContext() const { return Context; }
540 const std::string &getName() const { return Name; }
541 CompileUnitDesc *getFile() const {
542 return static_cast(File);
543 }
544 unsigned getLine() const { return Line; }
545 TypeDesc *getType() const {
546 return static_cast(TyDesc);
547 }
548 void setContext(DebugInfoDesc *C) { Context = C; }
549 void setName(const std::string &N) { Name = N; }
550 void setFile(CompileUnitDesc *U) {
551 File = static_cast(U);
552 }
553 void setLine(unsigned L) { Line = L; }
554 void setType(TypeDesc *T) {
555 TyDesc = static_cast(T);
556 }
557
558 // Implement isa/cast/dyncast.
559 static bool classof(const VariableDesc *) { return true; }
560 static bool classof(const DebugInfoDesc *D);
561
562 /// ApplyToFields - Target the visitor to the fields of the VariableDesc.
563 ///
564 virtual void ApplyToFields(DIVisitor *Visitor);
565
566 /// getDescString - Return a string used to compose global names and labels.
567 ///
568 virtual const char *getDescString() const;
569
570 /// getTypeString - Return a string used to label this descriptor's type.
571 ///
572 virtual const char *getTypeString() const;
573
574 #ifndef NDEBUG
575 virtual void dump();
576 #endif
577 };
578
579 //===----------------------------------------------------------------------===//
580 /// GlobalDesc - This class is the base descriptor for global functions and
581 /// variables.
582 class GlobalDesc : public AnchoredDesc {
583 private:
584 DebugInfoDesc *Context; // Context debug descriptor.
585 std::string Name; // Global name.
586 std::string FullName; // Fully qualified name.
587 std::string LinkageName; // Name for binding to MIPS linkage.
588 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
589 unsigned Line; // Defined line# (may be zero.)
590 DebugInfoDesc *TyDesc; // Type debug descriptor.
591 bool IsStatic; // Is the global a static.
592 bool IsDefinition; // Is the global defined in context.
593
594 protected:
595 GlobalDesc(unsigned T);
596
597 public:
598 // Accessors
599 DebugInfoDesc *getContext() const { return Context; }
600 const std::string &getName() const { return Name; }
601 const std::string &getFullName() const { return FullName; }
602 const std::string &getLinkageName() const { return LinkageName; }
603 CompileUnitDesc *getFile() const {
604 return static_cast(File);
605 }
606 unsigned getLine() const { return Line; }
607 TypeDesc *getType() const {
608 return static_cast(TyDesc);
609 }
610 bool isStatic() const { return IsStatic; }
611 bool isDefinition() const { return IsDefinition; }
612 void setContext(DebugInfoDesc *C) { Context = C; }
613 void setName(const std::string &N) { Name = N; }
614 void setFullName(const std::string &N) { FullName = N; }
615 void setLinkageName(const std::string &N) { LinkageName = N; }
616 void setFile(CompileUnitDesc *U) {
617 File = static_cast(U);
618 }
619 void setLine(unsigned L) { Line = L; }
620 void setType(TypeDesc *T) {
621 TyDesc = static_cast(T);
622 }
623 void setIsStatic(bool IS) { IsStatic = IS; }
624 void setIsDefinition(bool ID) { IsDefinition = ID; }
625
626 /// ApplyToFields - Target the visitor to the fields of the GlobalDesc.
627 ///
628 virtual void ApplyToFields(DIVisitor *Visitor);
629 };
630
631 //===----------------------------------------------------------------------===//
632 /// GlobalVariableDesc - This class packages debug information associated with a
633 /// GlobalVariable.
634 class GlobalVariableDesc : public GlobalDesc {
635 private:
636 GlobalVariable *Global; // llvm global.
637
638 public:
639 GlobalVariableDesc();
640
641 // Accessors.
642 GlobalVariable *getGlobalVariable() const { return Global; }
643 void setGlobalVariable(GlobalVariable *GV) { Global = GV; }
644
645 // Implement isa/cast/dyncast.
646 static bool classof(const GlobalVariableDesc *) { return true; }
647 static bool classof(const DebugInfoDesc *D);
648
649 /// ApplyToFields - Target the visitor to the fields of the
650 /// GlobalVariableDesc.
651 virtual void ApplyToFields(DIVisitor *Visitor);
652
653 /// getDescString - Return a string used to compose global names and labels.
654 ///
655 virtual const char *getDescString() const;
656
657 /// getTypeString - Return a string used to label this descriptor's type.
658 ///
659 virtual const char *getTypeString() const;
660
661 /// getAnchorString - Return a string used to label this descriptor's anchor.
662 ///
663 static const char *AnchorString;
664 virtual const char *getAnchorString() const;
665
666 #ifndef NDEBUG
667 virtual void dump();
668 #endif
669 };
670
671 //===----------------------------------------------------------------------===//
672 /// SubprogramDesc - This class packages debug information associated with a
673 /// subprogram/function.
674 class SubprogramDesc : public GlobalDesc {
675 private:
676
677 public:
678 SubprogramDesc();
679
680 // Accessors
681
682 // Implement isa/cast/dyncast.
683 static bool classof(const SubprogramDesc *) { return true; }
684 static bool classof(const DebugInfoDesc *D);
685
686 /// ApplyToFields - Target the visitor to the fields of the SubprogramDesc.
687 ///
688 virtual void ApplyToFields(DIVisitor *Visitor);
689
690 /// getDescString - Return a string used to compose global names and labels.
691 ///
692 virtual const char *getDescString() const;
693
694 /// getTypeString - Return a string used to label this descriptor's type.
695 ///
696 virtual const char *getTypeString() const;
697
698 /// getAnchorString - Return a string used to label this descriptor's anchor.
699 ///
700 static const char *AnchorString;
701 virtual const char *getAnchorString() const;
702
703 #ifndef NDEBUG
704 virtual void dump();
705 #endif
706 };
707
708 //===----------------------------------------------------------------------===//
709 /// BlockDesc - This descriptor groups variables and blocks nested in a block.
710 ///
711 class BlockDesc : public DebugInfoDesc {
712 private:
713 DebugInfoDesc *Context; // Context debug descriptor.
714
715 public:
716 BlockDesc();
717
718 // Accessors
719 DebugInfoDesc *getContext() const { return Context; }
720 void setContext(DebugInfoDesc *C) { Context = C; }
721
722 // Implement isa/cast/dyncast.
723 static bool classof(const BlockDesc *) { return true; }
724 static bool classof(const DebugInfoDesc *D);
725
726 /// ApplyToFields - Target the visitor to the fields of the BlockDesc.
727 ///
728 virtual void ApplyToFields(DIVisitor *Visitor);
729
730 /// getDescString - Return a string used to compose global names and labels.
731 ///
732 virtual const char *getDescString() const;
733
734 /// getTypeString - Return a string used to label this descriptor's type.
735 ///
736 virtual const char *getTypeString() const;
737
738 #ifndef NDEBUG
739 virtual void dump();
740 #endif
741 };
742
743 //===----------------------------------------------------------------------===//
744 /// DIDeserializer - This class is responsible for casting GlobalVariables
745 /// into DebugInfoDesc objects.
746 class DIDeserializer {
747 private:
748 std::map GlobalDescs;
749 // Previously defined gloabls.
750
751 public:
752 DIDeserializer() {}
753 ~DIDeserializer() {}
754
755 /// Deserialize - Reconstitute a GlobalVariable into it's component
756 /// DebugInfoDesc objects.
757 DebugInfoDesc *Deserialize(Value *V);
758 DebugInfoDesc *Deserialize(GlobalVariable *GV);
759 };
760
761 //===----------------------------------------------------------------------===//
762 /// DISerializer - This class is responsible for casting DebugInfoDesc objects
763 /// into GlobalVariables.
764 class DISerializer {
765 private:
766 Module *M; // Definition space module.
767 PointerType *StrPtrTy; // A "sbyte *" type. Created lazily.
768 PointerType *EmptyStructPtrTy; // A "{ }*" type. Created lazily.
769 std::map TagTypes;
770 // Types per Tag. Created lazily.
771 std::map DescGlobals;
772 // Previously defined descriptors.
773 std::map StringCache;
774 // Previously defined strings.
775
776 public:
777 DISerializer()
778 : M(NULL)
779 , StrPtrTy(NULL)
780 , EmptyStructPtrTy(NULL)
781 , TagTypes()
782 , DescGlobals()
783 , StringCache()
784 {}
785 ~DISerializer() {}
786
787 // Accessors
788 Module *getModule() const { return M; };
789 void setModule(Module *module) { M = module; }
790
791 /// getStrPtrType - Return a "sbyte *" type.
792 ///
793 const PointerType *getStrPtrType();
794
795 /// getEmptyStructPtrType - Return a "{ }*" type.
796 ///
797 const PointerType *getEmptyStructPtrType();
798
799 /// getTagType - Return the type describing the specified descriptor (via
800 /// tag.)
801 const StructType *getTagType(DebugInfoDesc *DD);
802
803 /// getString - Construct the string as constant string global.
804 ///
805 Constant *getString(const std::string &String);
806
807 /// Serialize - Recursively cast the specified descriptor into a
808 /// GlobalVariable so that it can be serialized to a .bc or .ll file.
809 GlobalVariable *Serialize(DebugInfoDesc *DD);
810 };
811
812 //===----------------------------------------------------------------------===//
813 /// DIVerifier - This class is responsible for verifying the given network of
814 /// GlobalVariables are valid as DebugInfoDesc objects.
815 class DIVerifier {
816 private:
817 enum {
818 Unknown = 0,
819 Invalid,
820 Valid
821 };
822 std::map Validity;// Tracks prior results.
823 std::map Counts; // Count of fields per Tag type.
824
825 public:
826 DIVerifier()
827 : Validity()
828 , Counts()
829 {}
830 ~DIVerifier() {}
831
832 /// Verify - Return true if the GlobalVariable appears to be a valid
833 /// serialization of a DebugInfoDesc.
834 bool Verify(Value *V);
835 bool Verify(GlobalVariable *GV);
836 };
837
838 //===----------------------------------------------------------------------===//
839 /// SourceLineInfo - This class is used to record source line correspondence.
840 ///
841 class SourceLineInfo {
842 private:
843 unsigned Line; // Source line number.
844 unsigned Column; // Source column.
845 unsigned SourceID; // Source ID number.
846 unsigned LabelID; // Label in code ID number.
847
848 public:
849 SourceLineInfo(unsigned L, unsigned C, unsigned S, unsigned I)
850 : Line(L), Column(C), SourceID(S), LabelID(I) {}
851
852 // Accessors
853 unsigned getLine() const { return Line; }
854 unsigned getColumn() const { return Column; }
855 unsigned getSourceID() const { return SourceID; }
856 unsigned getLabelID() const { return LabelID; }
857 };
858
859 //===----------------------------------------------------------------------===//
860 /// SourceFileInfo - This class is used to track source information.
861 ///
862 class SourceFileInfo {
863 private:
864 unsigned DirectoryID; // Directory ID number.
865 std::string Name; // File name (not including directory.)
866
867 public:
868 SourceFileInfo(unsigned D, const std::string &N) : DirectoryID(D), Name(N) {}
869
870 // Accessors
871 unsigned getDirectoryID() const { return DirectoryID; }
872 const std::string &getName() const { return Name; }
873
874 /// operator== - Used by UniqueVector to locate entry.
875 ///
876 bool operator==(const SourceFileInfo &SI) const {
877 return getDirectoryID() == SI.getDirectoryID() && getName() == SI.getName();
878 }
879
880 /// operator< - Used by UniqueVector to locate entry.
881 ///
882 bool operator<(const SourceFileInfo &SI) const {
883 return getDirectoryID() < SI.getDirectoryID() ||
884 (getDirectoryID() == SI.getDirectoryID() && getName() < SI.getName());
885 }
886 };
887
888 //===----------------------------------------------------------------------===//
889 /// DebugVariable - This class is used to track local variable information.
890 ///
891 class DebugVariable {
892 private:
893 VariableDesc *Desc; // Variable Descriptor.
894 unsigned FrameIndex; // Variable frame index.
895
896 public:
897 DebugVariable(VariableDesc *D, unsigned I)
898 : Desc(D)
899 , FrameIndex(I)
900 {}
901
902 // Accessors.
903 VariableDesc *getDesc() const { return Desc; }
904 unsigned getFrameIndex() const { return FrameIndex; }
905 };
906
907 //===----------------------------------------------------------------------===//
908 /// DebugScope - This class is used to track scope information.
909 ///
910 class DebugScope {
911 private:
912 DebugScope *Parent; // Parent to this scope.
913 DebugInfoDesc *Desc; // Debug info descriptor for scope.
914 // Either subprogram or block.
915 unsigned StartLabelID; // Label ID of the beginning of scope.
916 unsigned EndLabelID; // Label ID of the end of scope.
917 std::vector Scopes; // Scopes defined in scope.
918 std::vector Variables;// Variables declared in scope.
919
920 public:
921 DebugScope(DebugScope *P, DebugInfoDesc *D)
922 : Parent(P)
923 , Desc(D)
924 , StartLabelID(0)
925 , EndLabelID(0)
926 , Scopes()
927 , Variables()
928 {}
929 ~DebugScope();
930
931 // Accessors.
932 DebugScope *getParent() const { return Parent; }
933 DebugInfoDesc *getDesc() const { return Desc; }
934 unsigned getStartLabelID() const { return StartLabelID; }
935 unsigned getEndLabelID() const { return EndLabelID; }
936 std::vector &getScopes() { return Scopes; }
937 std::vector &getVariables() { return Variables; }
938 void setStartLabelID(unsigned S) { StartLabelID = S; }
939 void setEndLabelID(unsigned E) { EndLabelID = E; }
940
941 /// AddScope - Add a scope to the scope.
942 ///
943 void AddScope(DebugScope *S) { Scopes.push_back(S); }
944
945 /// AddVariable - Add a variable to the scope.
946 ///
947 void AddVariable(DebugVariable *V) { Variables.push_back(V); }
948 };
949
950 //===----------------------------------------------------------------------===//
951 /// MachineModuleInfo - This class contains meta information specific to a
952 /// module. Queries can be made by different debugging and exception handling
953 /// schemes and reformated for specific use.
954 ///
955 class MachineModuleInfo : public ImmutablePass {
956 private:
957 // Use the same deserializer/verifier for the module.
958 DIDeserializer DR;
959 DIVerifier VR;
960
961 // CompileUnits - Uniquing vector for compile units.
962 UniqueVector CompileUnits;
963
964 // Directories - Uniquing vector for directories.
965 UniqueVector Directories;
966
967 // SourceFiles - Uniquing vector for source files.
968 UniqueVector SourceFiles;
969
970 // Lines - List of of source line correspondence.
971 std::vector Lines;
972
973 // LabelIDList - One entry per assigned label. Normally the entry is equal to
974 // the list index(+1). If the entry is zero then the label has been deleted.
975 // Any other value indicates the label has been deleted by is mapped to
976 // another label.
977 std::vector LabelIDList;
978
979 // ScopeMap - Tracks the scopes in the current function.
980 std::map ScopeMap;
981
982 // RootScope - Top level scope for the current function.
983 //
984 DebugScope *RootScope;
985
986 // FrameMoves - List of moves done by a function's prolog. Used to construct
987 // frame maps by debug and exception handling consumers.
988 std::vector FrameMoves;
989
990 public:
991 MachineModuleInfo();
992 ~MachineModuleInfo();
993
994 /// doInitialization - Initialize the state for a new module.
995 ///
996 bool doInitialization();
997
998 /// doFinalization - Tear down the state after completion of a module.
999 ///
1000 bool doFinalization();
1001
1002 /// BeginFunction - Begin gathering function meta information.
1003 ///
1004 void BeginFunction(MachineFunction *MF);
1005
1006 /// EndFunction - Discard function meta information.
1007 ///
1008 void EndFunction();
1009
1010 /// getDescFor - Convert a Value to a debug information descriptor.
1011 ///
1012 // FIXME - use new Value type when available.
1013 DebugInfoDesc *getDescFor(Value *V);
1014
1015 /// Verify - Verify that a Value is debug information descriptor.
1016 ///
1017 bool Verify(Value *V);
1018
1019 /// AnalyzeModule - Scan the module for global debug information.
1020 ///
1021 void AnalyzeModule(Module &M);
1022
1023 /// hasDebugInfo - Returns true if valid debug info is present.
1024 ///
1025 bool hasDebugInfo() const { return !CompileUnits.empty(); }
1026
1027 /// NextLabelID - Return the next unique label id.
1028 ///
1029 unsigned NextLabelID() {
1030 unsigned ID = LabelIDList.size() + 1;
1031 LabelIDList.push_back(ID);
1032 return ID;
1033 }
1034
1035 /// RecordLabel - Records location information and associates it with a
1036 /// label. Returns a unique label ID used to generate a label and
1037 /// provide correspondence to the source line list.
1038 unsigned RecordLabel(unsigned Line, unsigned Column, unsigned Source);
1039
1040 /// InvalidateLabel - Inhibit use of the specified label # from
1041 /// MachineModuleInfo, for example because the code was deleted.
1042 void InvalidateLabel(unsigned LabelID) {
1043 // Remap to zero to indicate deletion.
1044 RemapLabel(LabelID, 0);
1045 }
1046
1047 /// RemapLabel - Indicate that a label has been merged into another.
1048 ///
1049 void RemapLabel(unsigned OldLabelID, unsigned NewLabelID) {
1050 assert(0 < OldLabelID && OldLabelID <= LabelIDList.size() &&
1051 "Old label ID out of range.");
1052 assert(NewLabelID <= LabelIDList.size() &&
1053 "New label ID out of range.");
1054 LabelIDList[OldLabelID - 1] = NewLabelID;
1055 }
1056
1057 /// MappedLabel - Find out the label's final ID. Zero indicates deletion.
1058 /// ID != Mapped ID indicates that the label was folded into another label.
1059 unsigned MappedLabel(unsigned LabelID) const {
1060 assert(LabelID <= LabelIDList.size() && "Debug label ID out of range.");
1061 return LabelID ? LabelIDList[LabelID - 1] : 0;
1062 }
1063
1064 /// RecordSource - Register a source file with debug info. Returns an source
1065 /// ID.
1066 unsigned RecordSource(const std::string &Directory,
1067 const std::string &Source);
1068 unsigned RecordSource(const CompileUnitDesc *CompileUnit);
1069
1070 /// getDirectories - Return the UniqueVector of std::string representing
1071 /// directories.
1072 const UniqueVector &getDirectories() const {
1073 return Directories;
1074 }
1075
1076 /// getSourceFiles - Return the UniqueVector of source files.
1077 ///
1078 const UniqueVector &getSourceFiles() const {
1079 return SourceFiles;
1080 }
1081
1082 /// getSourceLines - Return a vector of source lines.
1083 ///
1084 const std::vector &getSourceLines() const {
1085 return Lines;
1086 }
1087
1088 // FIXME: nuke this.
1089 void ClearLineInfo() {
1090 Lines.clear();
1091 }
1092
1093 /// SetupCompileUnits - Set up the unique vector of compile units.
1094 ///
1095 void SetupCompileUnits(Module &M);
1096
1097 /// getCompileUnits - Return a vector of debug compile units.
1098 ///
1099 const UniqueVector getCompileUnits() const;
1100
1101 /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
1102 /// named GlobalVariable.
1103 std::vector
1104 getGlobalVariablesUsing(Module &M, const std::string &RootName);
1105
1106 /// getAnchoredDescriptors - Return a vector of anchored debug descriptors.
1107 ///
1108 template std::vector getAnchoredDescriptors(Module &M) {
1109 T Desc;
1110 std::vector Globals =
1111 getGlobalVariablesUsing(M, Desc.getAnchorString());
1112 std::vector AnchoredDescs;
1113 for (unsigned i = 0, N = Globals.size(); i < N; ++i) {
1114 GlobalVariable *GV = Globals[i];
1115
1116 // FIXME - In the short term, changes are too drastic to continue.
1117 if (DebugInfoDesc::TagFromGlobal(GV) == Desc.getTag() &&
1118 DebugInfoDesc::VersionFromGlobal(GV) == LLVMDebugVersion) {
1119 AnchoredDescs.push_back(cast(DR.Deserialize(GV)));
1120 }
1121 }
1122
1123 return AnchoredDescs;
1124 }
1125
1126 /// RecordRegionStart - Indicate the start of a region.
1127 ///
1128 unsigned RecordRegionStart(Value *V);
1129
1130 /// RecordRegionEnd - Indicate the end of a region.
1131 ///
1132 unsigned RecordRegionEnd(Value *V);
1133
1134 /// RecordVariable - Indicate the declaration of a local variable.
1135 ///
1136 void RecordVariable(Value *V, unsigned FrameIndex);
1137
1138 /// getRootScope - Return current functions root scope.
1139 ///
1140 DebugScope *getRootScope() { return RootScope; }
1141
1142 /// getOrCreateScope - Returns the scope associated with the given descriptor.
1143 ///
1144 DebugScope *getOrCreateScope(DebugInfoDesc *ScopeDesc);
1145
1146 /// getFrameMoves - Returns a reference to a list of moves done in the current
1147 /// function's prologue. Used to construct frame maps for debug and exception
1148 /// handling comsumers.
1149 std::vector &getFrameMoves() { return FrameMoves; }
1150
1151 }; // End class MachineModuleInfo
1152
1153 } // End llvm namespace
1154
1155 #endif
+0
-1696
lib/CodeGen/MachineDebugInfo.cpp less more
None //===-- llvm/CodeGen/MachineDebugInfo.cpp -----------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by James M. Laskey and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/CodeGen/MachineDebugInfo.h"
10
11 #include "llvm/Constants.h"
12 #include "llvm/CodeGen/MachineFunctionPass.h"
13 #include "llvm/CodeGen/MachineFunction.h"
14 #include "llvm/CodeGen/MachineLocation.h"
15 #include "llvm/Target/TargetInstrInfo.h"
16 #include "llvm/Target/TargetMachine.h"
17 #include "llvm/DerivedTypes.h"
18 #include "llvm/GlobalVariable.h"
19 #include "llvm/Intrinsics.h"
20 #include "llvm/Instructions.h"
21 #include "llvm/Module.h"
22 #include "llvm/Support/Dwarf.h"
23 #include "llvm/Support/Streams.h"
24 using namespace llvm;
25 using namespace llvm::dwarf;
26
27 // Handle the Pass registration stuff necessary to use TargetData's.
28 namespace {
29 RegisterPass X("machinedebuginfo", "Debug Information");
30 }
31
32 //===----------------------------------------------------------------------===//
33
34 /// getGlobalVariablesUsing - Return all of the GlobalVariables which have the
35 /// specified value in their initializer somewhere.
36 static void
37 getGlobalVariablesUsing(Value *V, std::vector &Result) {
38 // Scan though value users.
39 for (Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I) {
40 if (GlobalVariable *GV = dyn_cast(*I)) {
41 // If the user is a GlobalVariable then add to result.
42 Result.push_back(GV);
43 } else if (Constant *C = dyn_cast(*I)) {
44 // If the user is a constant variable then scan its users
45 getGlobalVariablesUsing(C, Result);
46 }
47 }
48 }
49
50 /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
51 /// named GlobalVariable.
52 static std::vector
53 getGlobalVariablesUsing(Module &M, const std::string &RootName) {
54 std::vector Result; // GlobalVariables matching criteria.
55
56 std::vector FieldTypes;
57 FieldTypes.push_back(Type::Int32Ty);
58 FieldTypes.push_back(Type::Int32Ty);
59
60 // Get the GlobalVariable root.
61 GlobalVariable *UseRoot = M.getGlobalVariable(RootName,
62 StructType::get(FieldTypes));
63
64 // If present and linkonce then scan for users.
65 if (UseRoot && UseRoot->hasLinkOnceLinkage()) {
66 getGlobalVariablesUsing(UseRoot, Result);
67 }
68
69 return Result;
70 }
71
72 /// isStringValue - Return true if the given value can be coerced to a string.
73 ///
74 static bool isStringValue(Value *V) {
75 if (GlobalVariable *GV = dyn_cast(V)) {
76 if (GV->hasInitializer() && isa(GV->getInitializer())) {
77 ConstantArray *Init = cast(GV->getInitializer());
78 return Init->isString();
79 }
80 } else if (Constant *C = dyn_cast(V)) {
81 if (GlobalValue *GV = dyn_cast(C))
82 return isStringValue(GV);
83 else if (ConstantExpr *CE = dyn_cast(C)) {
84 if (CE->getOpcode() == Instruction::GetElementPtr) {
85 if (CE->getNumOperands() == 3 &&
86 cast(CE->getOperand(1))->isNullValue() &&
87 isa(CE->getOperand(2))) {
88 return isStringValue(CE->getOperand(0));
89 }
90 }
91 }
92 }
93 return false;
94 }
95
96 /// getGlobalVariable - Return either a direct or cast Global value.
97 ///
98 static GlobalVariable *getGlobalVariable(Value *V) {
99 if (GlobalVariable *GV = dyn_cast(V)) {
100 return GV;
101 } else if (ConstantExpr *CE = dyn_cast(V)) {
102 if (CE->getOpcode() == Instruction::BitCast) {
103 return dyn_cast(CE->getOperand(0));
104 }
105 }
106 return NULL;
107 }
108
109 /// isGlobalVariable - Return true if the given value can be coerced to a
110 /// GlobalVariable.
111 static bool isGlobalVariable(Value *V) {
112 if (isa(V) || isa(V)) {
113 return true;
114 } else if (ConstantExpr *CE = dyn_cast(V)) {
115 if (CE->getOpcode() == Instruction::BitCast) {
116 return isa(CE->getOperand(0));
117 }
118 }
119 return false;
120 }
121
122 /// getUIntOperand - Return ith operand if it is an unsigned integer.
123 ///
124 static ConstantInt *getUIntOperand(GlobalVariable *GV, unsigned i) {
125 // Make sure the GlobalVariable has an initializer.
126 if (!GV->hasInitializer()) return NULL;
127
128 // Get the initializer constant.
129 ConstantStruct *CI = dyn_cast(GV->getInitializer());
130 if (!CI) return NULL;
131
132 // Check if there is at least i + 1 operands.
133 unsigned N = CI->getNumOperands();
134 if (i >= N) return NULL;
135
136 // Check constant.
137 return dyn_cast(CI->getOperand(i));
138 }
139
140 //===----------------------------------------------------------------------===//
141
142 /// ApplyToFields - Target the visitor to each field of the debug information
143 /// descriptor.
144 void DIVisitor::ApplyToFields(DebugInfoDesc *DD) {
145 DD->ApplyToFields(this);
146 }
147
148 //===----------------------------------------------------------------------===//
149 /// DICountVisitor - This DIVisitor counts all the fields in the supplied debug
150 /// the supplied DebugInfoDesc.
151 class DICountVisitor : public DIVisitor {
152 private:
153 unsigned Count; // Running count of fields.
154
155 public:
156 DICountVisitor() : DIVisitor(), Count(0) {}
157
158 // Accessors.
159 unsigned getCount() const { return Count; }
160
161 /// Apply - Count each of the fields.
162 ///
163 virtual void Apply(int &Field) { ++Count; }
164 virtual void Apply(unsigned &Field) { ++Count; }
165 virtual void Apply(int64_t &Field) { ++Count; }
166 virtual void Apply(uint64_t &Field) { ++Count; }
167 virtual void Apply(bool &Field) { ++Count; }
168 virtual void Apply(std::string &Field) { ++Count; }
169 virtual void Apply(DebugInfoDesc *&Field) { ++Count; }
170 virtual void Apply(GlobalVariable *&Field) { ++Count; }
171 virtual void Apply(std::vector &Field) {
172 ++Count;
173 }
174 };
175
176 //===----------------------------------------------------------------------===//
177 /// DIDeserializeVisitor - This DIVisitor deserializes all the fields in the
178 /// supplied DebugInfoDesc.
179 class DIDeserializeVisitor : public DIVisitor {
180 private:
181 DIDeserializer &DR; // Active deserializer.
182 unsigned I; // Current operand index.
183 ConstantStruct *CI; // GlobalVariable constant initializer.
184
185 public:
186 DIDeserializeVisitor(DIDeserializer &D, GlobalVariable *GV)
187 : DIVisitor()
188 , DR(D)
189 , I(0)
190 , CI(cast(GV->getInitializer()))
191 {}
192
193 /// Apply - Set the value of each of the fields.
194 ///
195 virtual void Apply(int &Field) {
196 Constant *C = CI->getOperand(I++);
197 Field = cast(C)->getSExtValue();
198 }
199 virtual void Apply(unsigned &Field) {
200 Constant *C = CI->getOperand(I++);
201 Field = cast(C)->getZExtValue();
202 }
203 virtual void Apply(int64_t &Field) {
204 Constant *C = CI->getOperand(I++);
205 Field = cast(C)->getSExtValue();
206 }
207 virtual void Apply(uint64_t &Field) {
208 Constant *C = CI->getOperand(I++);
209 Field = cast(C)->getZExtValue();
210 }
211 virtual void Apply(bool &Field) {
212 Constant *C = CI->getOperand(I++);
213 Field = cast(C)->getZExtValue();
214 }
215 virtual void Apply(std::string &Field) {
216 Constant *C = CI->getOperand(I++);
217 Field = C->getStringValue();
218 }
219 virtual void Apply(DebugInfoDesc *&Field) {
220 Constant *C = CI->getOperand(I++);
221 Field = DR.Deserialize(C);
222 }
223 virtual void Apply(GlobalVariable *&Field) {
224 Constant *C = CI->getOperand(I++);
225 Field = getGlobalVariable(C);
226 }
227 virtual void Apply(std::vector &Field) {
228 Field.resize(0);
229 Constant *C = CI->getOperand(I++);
230 GlobalVariable *GV = getGlobalVariable(C);
231 if (GV->hasInitializer()) {
232 if (ConstantArray *CA = dyn_cast(GV->getInitializer())) {
233 for (unsigned i = 0, N = CA->getNumOperands(); i < N; ++i) {
234 GlobalVariable *GVE = getGlobalVariable(CA->getOperand(i));
235 DebugInfoDesc *DE = DR.Deserialize(GVE);
236 Field.push_back(DE);
237 }
238 } else if (GV->getInitializer()->isNullValue()) {
239 if (const ArrayType *T =
240 dyn_cast(GV->getType()->getElementType())) {
241 Field.resize(T->getNumElements());
242 }
243 }
244 }
245 }
246 };
247
248 //===----------------------------------------------------------------------===//
249 /// DISerializeVisitor - This DIVisitor serializes all the fields in
250 /// the supplied DebugInfoDesc.
251 class DISerializeVisitor : public DIVisitor {
252 private:
253 DISerializer &SR; // Active serializer.
254 std::vector &Elements; // Element accumulator.
255
256 public:
257 DISerializeVisitor(DISerializer &S, std::vector &E)
258 : DIVisitor()
259 , SR(S)
260 , Elements(E)
261 {}
262
263 /// Apply - Set the value of each of the fields.
264 ///
265 virtual void Apply(int &Field) {
266 Elements.push_back(ConstantInt::get(Type::Int32Ty, int32_t(Field)));
267 }
268 virtual void Apply(unsigned &Field) {
269 Elements.push_back(ConstantInt::get(Type::Int32Ty, uint32_t(Field)));
270 }
271 virtual void Apply(int64_t &Field) {
272 Elements.push_back(ConstantInt::get(Type::Int64Ty, int64_t(Field)));
273 }
274 virtual void Apply(uint64_t &Field) {
275 Elements.push_back(ConstantInt::get(Type::Int64Ty, uint64_t(Field)));
276 }
277 virtual void Apply(bool &Field) {
278 Elements.push_back(ConstantInt::get(Type::Int1Ty, Field));
279 }
280 virtual void Apply(std::string &Field) {
281 Elements.push_back(SR.getString(Field));
282 }
283 virtual void Apply(DebugInfoDesc *&Field) {
284 GlobalVariable *GV = NULL;
285
286 // If non-NULL then convert to global.
287 if (Field) GV = SR.Serialize(Field);
288
289 // FIXME - At some point should use specific type.
290 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
291
292 if (GV) {
293 // Set to pointer to global.
294 Elements.push_back(ConstantExpr::getBitCast(GV, EmptyTy));
295 } else {
296 // Use NULL.
297 Elements.push_back(ConstantPointerNull::get(EmptyTy));
298 }
299 }
300 virtual void Apply(GlobalVariable *&Field) {
301 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
302 if (Field) {
303 Elements.push_back(ConstantExpr::getBitCast(Field, EmptyTy));
304 } else {
305 Elements.push_back(ConstantPointerNull::get(EmptyTy));
306 }
307 }
308 virtual void Apply(std::vector &Field) {
309 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
310 unsigned N = Field.size();
311 ArrayType *AT = ArrayType::get(EmptyTy, N);
312 std::vector ArrayElements;
313
314 for (unsigned i = 0, N = Field.size(); i < N; ++i) {
315 if (DebugInfoDesc *Element = Field[i]) {
316 GlobalVariable *GVE = SR.Serialize(Element);
317 Constant *CE = ConstantExpr::getBitCast(GVE, EmptyTy);
318 ArrayElements.push_back(cast(CE));
319 } else {
320 ArrayElements.push_back(ConstantPointerNull::get(EmptyTy));
321 }
322 }
323
324 Constant *CA = ConstantArray::get(AT, ArrayElements);
325 GlobalVariable *CAGV = new GlobalVariable(AT, true,
326 GlobalValue::InternalLinkage,
327 CA, "llvm.dbg.array",
328 SR.getModule());
329 CAGV->setSection("llvm.metadata");
330 Constant *CAE = ConstantExpr::getBitCast(CAGV, EmptyTy);
331 Elements.push_back(CAE);
332 }
333 };
334
335 //===----------------------------------------------------------------------===//
336 /// DIGetTypesVisitor - This DIVisitor gathers all the field types in
337 /// the supplied DebugInfoDesc.
338 class DIGetTypesVisitor : public DIVisitor {
339 private:
340 DISerializer &SR; // Active serializer.
341 std::vector &Fields; // Type accumulator.
342
343 public:
344 DIGetTypesVisitor(DISerializer &S, std::vector &F)
345 : DIVisitor()
346 , SR(S)
347 , Fields(F)
348 {}
349
350 /// Apply - Set the value of each of the fields.
351 ///
352 virtual void Apply(int &Field) {
353 Fields.push_back(Type::Int32Ty);
354 }
355 virtual void Apply(unsigned &Field) {
356 Fields.push_back(Type::Int32Ty);
357 }
358 virtual void Apply(int64_t &Field) {
359 Fields.push_back(Type::Int64Ty);
360 }
361 virtual void Apply(uint64_t &Field) {
362 Fields.push_back(Type::Int64Ty);
363 }
364 virtual void Apply(bool &Field) {
365 Fields.push_back(Type::Int1Ty);
366 }
367 virtual void Apply(std::string &Field) {
368 Fields.push_back(SR.getStrPtrType());
369 }
370 virtual void Apply(DebugInfoDesc *&Field) {
371 // FIXME - At some point should use specific type.
372 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
373 Fields.push_back(EmptyTy);
374 }
375 virtual void Apply(GlobalVariable *&Field) {
376 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
377 Fields.push_back(EmptyTy);
378 }
379 virtual void Apply(std::vector &Field) {
380 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
381 Fields.push_back(EmptyTy);
382 }
383 };
384
385 //===----------------------------------------------------------------------===//
386 /// DIVerifyVisitor - This DIVisitor verifies all the field types against
387 /// a constant initializer.
388 class DIVerifyVisitor : public DIVisitor {
389 private:
390 DIVerifier &VR; // Active verifier.
391 bool IsValid; // Validity status.
392 unsigned I; // Current operand index.
393 ConstantStruct *CI; // GlobalVariable constant initializer.
394
395 public:
396 DIVerifyVisitor(DIVerifier &V, GlobalVariable *GV)
397 : DIVisitor()
398 , VR(V)
399 , IsValid(true)
400 , I(0)
401 , CI(cast(GV->getInitializer()))
402 {
403 }
404
405 // Accessors.
406 bool isValid() const { return IsValid; }
407
408 /// Apply - Set the value of each of the fields.
409 ///
410 virtual void Apply(int &Field) {
411 Constant *C = CI->getOperand(I++);
412 IsValid = IsValid && isa(C);
413 }
414 virtual void Apply(unsigned &Field) {
415 Constant *C = CI->getOperand(I++);
416 IsValid = IsValid && isa(C);
417 }
418 virtual void Apply(int64_t &Field) {
419 Constant *C = CI->getOperand(I++);
420 IsValid = IsValid && isa(C);
421 }
422 virtual void Apply(uint64_t &Field) {
423 Constant *C = CI->getOperand(I++);
424 IsValid = IsValid && isa(C);
425 }
426 virtual void Apply(bool &Field) {
427 Constant *C = CI->getOperand(I++);
428 IsValid = IsValid && isa(C) && C->getType() == Type::Int1Ty;
429 }
430 virtual void Apply(std::string &Field) {
431 Constant *C = CI->getOperand(I++);
432 IsValid = IsValid &&
433 (!C || isStringValue(C) || C->isNullValue());
434 }
435 virtual void Apply(DebugInfoDesc *&Field) {
436 // FIXME - Prepare the correct descriptor.
437 Constant *C = CI->getOperand(I++);
438 IsValid = IsValid && isGlobalVariable(C);
439 }
440 virtual void Apply(GlobalVariable *&Field) {
441 Constant *C = CI->getOperand(I++);
442 IsValid = IsValid && isGlobalVariable(C);
443 }
444 virtual void Apply(std::vector &Field) {
445 Constant *C = CI->getOperand(I++);
446 IsValid = IsValid && isGlobalVariable(C);
447 if (!IsValid) return;
448
449 GlobalVariable *GV = getGlobalVariable(C);
450 IsValid = IsValid && GV && GV->hasInitializer();
451 if (!IsValid) return;
452
453 ConstantArray *CA = dyn_cast(GV->getInitializer());
454 IsValid = IsValid && CA;
455 if (!IsValid) return;
456
457 for (unsigned i = 0, N = CA->getNumOperands(); IsValid && i < N; ++i) {
458 IsValid = IsValid && isGlobalVariable(CA->getOperand(i));
459 if (!IsValid) return;
460
461 GlobalVariable *GVE = getGlobalVariable(CA->getOperand(i));
462 VR.Verify(GVE);
463 }
464 }
465 };
466
467
468 //===----------------------------------------------------------------------===//
469
470 /// TagFromGlobal - Returns the tag number from a debug info descriptor
471 /// GlobalVariable. Return DIIValid if operand is not an unsigned int.
472 unsigned DebugInfoDesc::TagFromGlobal(GlobalVariable *GV) {
473 ConstantInt *C = getUIntOperand(GV, 0);
474 return C ? ((unsigned)C->getZExtValue() & ~LLVMDebugVersionMask) :
475 (unsigned)DW_TAG_invalid;
476 }
477
478 /// VersionFromGlobal - Returns the version number from a debug info
479 /// descriptor GlobalVariable. Return DIIValid if operand is not an unsigned
480 /// int.
481 unsigned DebugInfoDesc::VersionFromGlobal(GlobalVariable *GV) {
482 ConstantInt *C = getUIntOperand(GV, 0);
483 return C ? ((unsigned)C->getZExtValue() & LLVMDebugVersionMask) :
484 (unsigned)DW_TAG_invalid;
485 }
486
487 /// DescFactory - Create an instance of debug info descriptor based on Tag.
488 /// Return NULL if not a recognized Tag.
489 DebugInfoDesc *DebugInfoDesc::DescFactory(unsigned Tag) {
490 switch (Tag) {
491 case DW_TAG_anchor: return new AnchorDesc();
492 case DW_TAG_compile_unit: return new CompileUnitDesc();
493 case DW_TAG_variable: return new GlobalVariableDesc();
494 case DW_TAG_subprogram: return new SubprogramDesc();
495 case DW_TAG_lexical_block: return new BlockDesc();
496 case DW_TAG_base_type: return new BasicTypeDesc();
497 case DW_TAG_typedef:
498 case DW_TAG_pointer_type:
499 case DW_TAG_reference_type:
500 case DW_TAG_const_type:
501 case DW_TAG_volatile_type:
502 case DW_TAG_restrict_type:
503 case DW_TAG_member:
504 case DW_TAG_inheritance: return new DerivedTypeDesc(Tag);
505 case DW_TAG_array_type:
506 case DW_TAG_structure_type:
507 case DW_TAG_union_type:
508 case DW_TAG_enumeration_type:
509 case DW_TAG_vector_type:
510 case DW_TAG_subroutine_type: return new CompositeTypeDesc(Tag);
511 case DW_TAG_subrange_type: return new SubrangeDesc();
512 case DW_TAG_enumerator: return new EnumeratorDesc();
513 case DW_TAG_return_variable:
514 case DW_TAG_arg_variable:
515 case DW_TAG_auto_variable: return new VariableDesc(Tag);
516 default: break;
517 }
518 return NULL;
519 }
520
521 /// getLinkage - get linkage appropriate for this type of descriptor.
522 ///
523 GlobalValue::LinkageTypes DebugInfoDesc::getLinkage() const {
524 return GlobalValue::InternalLinkage;
525 }
526
527 /// ApplyToFields - Target the vistor to the fields of the descriptor.
528 ///
529 void DebugInfoDesc::ApplyToFields(DIVisitor *Visitor) {
530 Visitor->Apply(Tag);
531 }
532
533 //===----------------------------------------------------------------------===//
534
535 AnchorDesc::AnchorDesc()
536 : DebugInfoDesc(DW_TAG_anchor)
537 , AnchorTag(0)
538 {}
539 AnchorDesc::AnchorDesc(AnchoredDesc *D)
540 : DebugInfoDesc(DW_TAG_anchor)
541 , AnchorTag(D->getTag())
542 {}
543
544 // Implement isa/cast/dyncast.
545 bool AnchorDesc::classof(const DebugInfoDesc *D) {
546 return D->getTag() == DW_TAG_anchor;
547 }
548
549 /// getLinkage - get linkage appropriate for this type of descriptor.
550 ///
551 GlobalValue::LinkageTypes AnchorDesc::getLinkage() const {
552 return GlobalValue::LinkOnceLinkage;
553 }
554
555 /// ApplyToFields - Target the visitor to the fields of the TransUnitDesc.
556 ///
557 void AnchorDesc::ApplyToFields(DIVisitor *Visitor) {
558 DebugInfoDesc::ApplyToFields(Visitor);
559
560 Visitor->Apply(AnchorTag);
561 }
562
563 /// getDescString - Return a string used to compose global names and labels. A
564 /// A global variable name needs to be defined for each debug descriptor that is
565 /// anchored. NOTE: that each global variable named here also needs to be added
566 /// to the list of names left external in the internalizer.
567 /// ExternalNames.insert("llvm.dbg.compile_units");
568 /// ExternalNames.insert("llvm.dbg.global_variables");
569 /// ExternalNames.insert("llvm.dbg.subprograms");
570 const char *AnchorDesc::getDescString() const {
571 switch (AnchorTag) {
572 case DW_TAG_compile_unit: return CompileUnitDesc::AnchorString;
573 case DW_TAG_variable: return GlobalVariableDesc::AnchorString;
574 case DW_TAG_subprogram: return SubprogramDesc::AnchorString;
575 default: break;
576 }
577
578 assert(0 && "Tag does not have a case for anchor string");
579 return "";
580 }
581
582 /// getTypeString - Return a string used to label this descriptors type.
583 ///
584 const char *AnchorDesc::getTypeString() const {
585 return "llvm.dbg.anchor.type";
586 }
587
588 #ifndef NDEBUG
589 void AnchorDesc::dump() {
590 cerr << getDescString() << " "
591 << "Version(" << getVersion() << "), "
592 << "Tag(" << getTag() << "), "
593 << "AnchorTag(" << AnchorTag << ")\n";
594 }
595 #endif
596
597 //===----------------------------------------------------------------------===//
598
599 AnchoredDesc::AnchoredDesc(unsigned T)
600 : DebugInfoDesc(T)
601 , Anchor(NULL)
602 {}
603
604 /// ApplyToFields - Target the visitor to the fields of the AnchoredDesc.
605 ///
606 void AnchoredDesc::ApplyToFields(DIVisitor *Visitor) {
607 DebugInfoDesc::ApplyToFields(Visitor);
608
609 Visitor->Apply(Anchor);
610 }
611
612 //===----------------------------------------------------------------------===//
613
614 CompileUnitDesc::CompileUnitDesc()
615 : AnchoredDesc(DW_TAG_compile_unit)
616 , Language(0)
617 , FileName("")
618 , Directory("")
619 , Producer("")
620 {}
621
622 // Implement isa/cast/dyncast.
623 bool CompileUnitDesc::classof(const DebugInfoDesc *D) {
624 return D->getTag() == DW_TAG_compile_unit;
625 }
626
627 /// ApplyToFields - Target the visitor to the fields of the CompileUnitDesc.
628 ///
629 void CompileUnitDesc::ApplyToFields(DIVisitor *Visitor) {
630 AnchoredDesc::ApplyToFields(Visitor);
631
632 // Handle cases out of sync with compiler.
633 if (getVersion() == 0) {
634 unsigned DebugVersion;
635 Visitor->Apply(DebugVersion);
636 }
637
638 Visitor->Apply(Language);
639 Visitor->Apply(FileName);
640 Visitor->Apply(Directory);
641 Visitor->Apply(Producer);
642 }
643
644 /// getDescString - Return a string used to compose global names and labels.
645 ///
646 const char *CompileUnitDesc::getDescString() const {
647 return "llvm.dbg.compile_unit";
648 }
649
650 /// getTypeString - Return a string used to label this descriptors type.
651 ///
652 const char *CompileUnitDesc::getTypeString() const {
653 return "llvm.dbg.compile_unit.type";
654 }
655
656 /// getAnchorString - Return a string used to label this descriptor's anchor.
657 ///
658 const char *CompileUnitDesc::AnchorString = "llvm.dbg.compile_units";
659 const char *CompileUnitDesc::getAnchorString() const {
660 return AnchorString;
661 }
662
663 #ifndef NDEBUG
664 void CompileUnitDesc::dump() {
665 cerr << getDescString() << " "
666 << "Version(" << getVersion() << "), "
667 << "Tag(" << getTag() << "), "
668 << "Anchor(" << getAnchor() << "), "
669 << "Language(" << Language << "), "
670 << "FileName(\"" << FileName << "\"), "
671 << "Directory(\"" << Directory << "\"), "
672 << "Producer(\"" << Producer << "\")\n";
673 }
674 #endif
675
676 //===----------------------------------------------------------------------===//
677
678 TypeDesc::TypeDesc(unsigned T)
679 : DebugInfoDesc(T)
680 , Context(NULL)
681 , Name("")
682 , File(NULL)
683 , Line(0)
684 , Size(0)
685 , Align(0)
686 , Offset(0)
687 , Flags(0)
688 {}
689
690 /// ApplyToFields - Target the visitor to the fields of the TypeDesc.
691 ///
692 void TypeDesc::ApplyToFields(DIVisitor *Visitor) {
693 DebugInfoDesc::ApplyToFields(Visitor);
694
695 Visitor->Apply(Context);
696 Visitor->Apply(Name);
697 Visitor->Apply(File);
698 Visitor->Apply(Line);
699 Visitor->Apply(Size);
700 Visitor->Apply(Align);
701 Visitor->Apply(Offset);
702 if (getVersion() > LLVMDebugVersion4) Visitor->Apply(Flags);
703 }
704
705 /// getDescString - Return a string used to compose global names and labels.
706 ///
707 const char *TypeDesc::getDescString() const {
708 return "llvm.dbg.type";
709 }
710
711 /// getTypeString - Return a string used to label this descriptor's type.
712 ///
713 const char *TypeDesc::getTypeString() const {
714 return "llvm.dbg.type.type";
715 }
716
717 #ifndef NDEBUG
718 void TypeDesc::dump() {
719 cerr << getDescString() << " "
720 << "Version(" << getVersion() << "), "
721 << "Tag(" << getTag() << "), "
722 << "Context(" << Context << "), "
723 << "Name(\"" << Name << "\"), "
724 << "File(" << File << "), "
725 << "Line(" << Line << "), "
726 << "Size(" << Size << "), "
727 << "Align(" << Align << "), "
728 << "Offset(" << Offset << "), "
729 << "Flags(" << Flags << ")\n";
730 }
731 #endif
732
733 //===----------------------------------------------------------------------===//
734
735 BasicTypeDesc::BasicTypeDesc()
736 : TypeDesc(DW_TAG_base_type)
737 , Encoding(0)
738 {}
739
740 // Implement isa/cast/dyncast.
741 bool BasicTypeDesc::classof(const DebugInfoDesc *D) {
742 return D->getTag() == DW_TAG_base_type;
743 }
744
745 /// ApplyToFields - Target the visitor to the fields of the BasicTypeDesc.
746 ///
747 void BasicTypeDesc::ApplyToFields(DIVisitor *Visitor) {
748 TypeDesc::ApplyToFields(Visitor);
749
750 Visitor->Apply(Encoding);
751 }
752
753 /// getDescString - Return a string used to compose global names and labels.
754 ///
755 const char *BasicTypeDesc::getDescString() const {
756 return "llvm.dbg.basictype";
757 }
758
759 /// getTypeString - Return a string used to label this descriptor's type.
760 ///
761 const char *BasicTypeDesc::getTypeString() const {
762 return "llvm.dbg.basictype.type";
763 }
764
765 #ifndef NDEBUG
766 void BasicTypeDesc::dump() {
767 cerr << getDescString() << " "
768 << "Version(" << getVersion() << "), "
769 << "Tag(" << getTag() << "), "
770 << "Context(" << getContext() << "), "
771 << "Name(\"" << getName() << "\"), "
772 << "Size(" << getSize() << "), "
773 << "Encoding(" << Encoding << ")\n";
774 }
775 #endif
776
777 //===----------------------------------------------------------------------===//
778
779 DerivedTypeDesc::DerivedTypeDesc(unsigned T)
780 : TypeDesc(T)
781 , FromType(NULL)
782 {}
783
784 // Implement isa/cast/dyncast.
785 bool DerivedTypeDesc::classof(const DebugInfoDesc *D) {
786 unsigned T = D->getTag();
787 switch (T) {
788 case DW_TAG_typedef:
789 case DW_TAG_pointer_type:
790 case DW_TAG_reference_type:
791 case DW_TAG_const_type:
792 case DW_TAG_volatile_type:
793 case DW_TAG_restrict_type:
794 case DW_TAG_member:
795 case DW_TAG_inheritance:
796 return true;
797 default: break;
798 }
799 return false;
800 }
801
802 /// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc.
803 ///
804 void DerivedTypeDesc::ApplyToFields(DIVisitor *Visitor) {
805 TypeDesc::ApplyToFields(Visitor);
806
807 Visitor->Apply(FromType);
808 }
809
810 /// getDescString - Return a string used to compose global names and labels.
811 ///
812 const char *DerivedTypeDesc::getDescString() const {
813 return "llvm.dbg.derivedtype";
814 }
815
816 /// getTypeString - Return a string used to label this descriptor's type.
817 ///
818 const char *DerivedTypeDesc::getTypeString() const {
819 return "llvm.dbg.derivedtype.type";
820 }
821
822 #ifndef NDEBUG
823 void DerivedTypeDesc::dump() {
824 cerr << getDescString() << " "
825 << "Version(" << getVersion() << "), "
826 << "Tag(" << getTag() << "), "
827 << "Context(" << getContext() << "), "
828 << "Name(\"" << getName() << "\"), "
829 << "Size(" << getSize() << "), "
830 << "File(" << getFile() << "), "
831 << "Line(" << getLine() << "), "
832 << "FromType(" << FromType << ")\n";
833 }
834 #endif
835
836 //===----------------------------------------------------------------------===//
837
838 CompositeTypeDesc::CompositeTypeDesc(unsigned T)
839 : DerivedTypeDesc(T)
840 , Elements()
841 {}
842
843 // Implement isa/cast/dyncast.
844 bool CompositeTypeDesc::classof(const DebugInfoDesc *D) {
845 unsigned T = D->getTag();
846 switch (T) {
847 case DW_TAG_array_type:
848 case DW_TAG_structure_type:
849 case DW_TAG_union_type:
850 case DW_TAG_enumeration_type:
851 case DW_TAG_vector_type:
852 case DW_TAG_subroutine_type:
853 return true;
854 default: break;
855 }
856 return false;
857 }
858
859 /// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc.
860 ///
861 void CompositeTypeDesc::ApplyToFields(DIVisitor *Visitor) {
862 DerivedTypeDesc::ApplyToFields(Visitor);
863
864 Visitor->Apply(Elements);
865 }
866
867 /// getDescString - Return a string used to compose global names and labels.
868 ///
869 const char *CompositeTypeDesc::getDescString() const {
870 return "llvm.dbg.compositetype";
871 }
872
873 /// getTypeString - Return a string used to label this descriptor's type.
874 ///
875 const char *CompositeTypeDesc::getTypeString() const {
876 return "llvm.dbg.compositetype.type";
877 }
878
879 #ifndef NDEBUG
880 void CompositeTypeDesc::dump() {
881 cerr << getDescString() << " "
882 << "Version(" << getVersion() << "), "
883 << "Tag(" << getTag() << "), "
884 << "Context(" << getContext() << "), "
885 << "Name(\"" << getName() << "\"), "
886 << "Size(" << getSize() << "), "
887 << "File(" << getFile() << "), "
888 << "Line(" << getLine() << "), "
889 << "FromType(" << getFromType() << "), "
890 << "Elements.size(" << Elements.size() << ")\n";
891 }
892 #endif
893
894 //===----------------------------------------------------------------------===//
895
896 SubrangeDesc::SubrangeDesc()
897 : DebugInfoDesc(DW_TAG_subrange_type)
898 , Lo(0)
899 , Hi(0)
900 {}
901
902 // Implement isa/cast/dyncast.
903 bool SubrangeDesc::classof(const DebugInfoDesc *D) {
904 return D->getTag() == DW_TAG_subrange_type;
905 }
906
907 /// ApplyToFields - Target the visitor to the fields of the SubrangeDesc.
908 ///
909 void SubrangeDesc::ApplyToFields(DIVisitor *Visitor) {
910 DebugInfoDesc::ApplyToFields(Visitor);
911
912 Visitor->Apply(Lo);
913 Visitor->Apply(Hi);
914 }
915
916 /// getDescString - Return a string used to compose global names and labels.
917 ///
918 const char *SubrangeDesc::getDescString() const {
919 return "llvm.dbg.subrange";
920 }
921
922 /// getTypeString - Return a string used to label this descriptor's type.
923 ///
924 const char *SubrangeDesc::getTypeString() const {
925 return "llvm.dbg.subrange.type";
926 }
927
928 #ifndef NDEBUG
929 void SubrangeDesc::dump() {
930 cerr << getDescString() << " "
931 << "Version(" << getVersion() << "), "
932 << "Tag(" << getTag() << "), "
933 << "Lo(" << Lo << "), "
934 << "Hi(" << Hi << ")\n";
935 }
936 #endif
937
938 //===----------------------------------------------------------------------===//
939
940 EnumeratorDesc::EnumeratorDesc()
941 : DebugInfoDesc(DW_TAG_enumerator)
942 , Name("")
943 , Value(0)
944 {}
945
946 // Implement isa/cast/dyncast.
947 bool EnumeratorDesc::classof(const DebugInfoDesc *D) {
948 return D->getTag() == DW_TAG_enumerator;
949 }
950
951 /// ApplyToFields - Target the visitor to the fields of the EnumeratorDesc.
952 ///
953 void EnumeratorDesc::ApplyToFields(DIVisitor *Visitor) {
954 DebugInfoDesc::ApplyToFields(Visitor);
955
956 Visitor->Apply(Name);
957 Visitor->Apply(Value);
958 }
959
960 /// getDescString - Return a string used to compose global names and labels.
961 ///
962 const char *EnumeratorDesc::getDescString() const {
963 return "llvm.dbg.enumerator";
964 }
965
966 /// getTypeString - Return a string used to label this descriptor's type.
967 ///
968 const char *EnumeratorDesc::getTypeString() const {
969 return "llvm.dbg.enumerator.type";
970 }
971
972 #ifndef NDEBUG
973 void EnumeratorDesc::dump() {
974 cerr << getDescString() << " "
975 << "Version(" << getVersion() << "), "
976 << "Tag(" << getTag() << "), "
977 << "Name(" << Name << "), "
978 << "Value(" << Value << ")\n";
979 }
980 #endif
981
982 //===----------------------------------------------------------------------===//
983
984 VariableDesc::VariableDesc(unsigned T)
985 : DebugInfoDesc(T)
986 , Context(NULL)
987 , Name("")
988 , File(NULL)
989 , Line(0)
990 , TyDesc(0)
991 {}
992
993 // Implement isa/cast/dyncast.
994 bool VariableDesc::classof(const DebugInfoDesc *D) {
995 unsigned T = D->getTag();
996 switch (T) {
997 case DW_TAG_auto_variable:
998 case DW_TAG_arg_variable:
999 case DW_TAG_return_variable:
1000 return true;
1001 default: break;
1002 }
1003 return false;
1004 }
1005
1006 /// ApplyToFields - Target the visitor to the fields of the VariableDesc.
1007 ///
1008 void VariableDesc::ApplyToFields(DIVisitor *Visitor) {
1009 DebugInfoDesc::ApplyToFields(Visitor);
1010
1011 Visitor->Apply(Context);
1012 Visitor->Apply(Name);
1013 Visitor->Apply(File);
1014 Visitor->Apply(Line);
1015 Visitor->Apply(TyDesc);
1016 }
1017
1018 /// getDescString - Return a string used to compose global names and labels.
1019 ///
1020 const char *VariableDesc::getDescString() const {
1021 return "llvm.dbg.variable";
1022 }
1023
1024 /// getTypeString - Return a string used to label this descriptor's type.
1025 ///
1026 const char *VariableDesc::getTypeString() const {
1027 return "llvm.dbg.variable.type";
1028 }
1029
1030 #ifndef NDEBUG
1031 void VariableDesc::dump() {
1032 cerr << getDescString() << " "
1033 << "Version(" << getVersion() << "), "
1034 << "Tag(" << getTag() << "), "
1035 << "Context(" << Context << "), "
1036 << "Name(\"" << Name << "\"), "
1037 << "File(" << File << "), "
1038 << "Line(" << Line << "), "
1039 << "TyDesc(" << TyDesc << ")\n";
1040 }
1041 #endif
1042
1043 //===----------------------------------------------------------------------===//
1044
1045 GlobalDesc::GlobalDesc(unsigned T)
1046 : AnchoredDesc(T)
1047 , Context(0)
1048 , Name("")
1049 , FullName("")
1050 , LinkageName("")
1051 , File(NULL)
1052 , Line(0)
1053 , TyDesc(NULL)
1054 , IsStatic(false)
1055 , IsDefinition(false)
1056 {}
1057
1058 /// ApplyToFields - Target the visitor to the fields of the global.
1059 ///
1060 void GlobalDesc::ApplyToFields(DIVisitor *Visitor) {
1061 AnchoredDesc::ApplyToFields(Visitor);
1062
1063 Visitor->Apply(Context);
1064 Visitor->Apply(Name);
1065 Visitor->Apply(FullName);
1066 Visitor->Apply(LinkageName);
1067 Visitor->Apply(File);
1068 Visitor->Apply(Line);
1069 Visitor->Apply(TyDesc);
1070 Visitor->Apply(IsStatic);
1071 Visitor->Apply(IsDefinition);
1072 }
1073
1074 //===----------------------------------------------------------------------===//
1075
1076 GlobalVariableDesc::GlobalVariableDesc()
1077 : GlobalDesc(DW_TAG_variable)
1078 , Global(NULL)
1079 {}
1080
1081 // Implement isa/cast/dyncast.
1082 bool GlobalVariableDesc::classof(const DebugInfoDesc *D) {
1083 return D->getTag() == DW_TAG_variable;
1084 }
1085
1086 /// ApplyToFields - Target the visitor to the fields of the GlobalVariableDesc.
1087 ///
1088 void GlobalVariableDesc::ApplyToFields(DIVisitor *Visitor) {
1089 GlobalDesc::ApplyToFields(Visitor);
1090
1091 Visitor->Apply(Global);
1092 }
1093
1094 /// getDescString - Return a string used to compose global names and labels.
1095 ///
1096 const char *GlobalVariableDesc::getDescString() const {
1097 return "llvm.dbg.global_variable";
1098 }
1099
1100 /// getTypeString - Return a string used to label this descriptors type.
1101 ///
1102 const char *GlobalVariableDesc::getTypeString() const {
1103 return "llvm.dbg.global_variable.type";
1104 }
1105
1106 /// getAnchorString - Return a string used to label this descriptor's anchor.
1107 ///
1108 const char *GlobalVariableDesc::AnchorString = "llvm.dbg.global_variables";
1109 const char *GlobalVariableDesc::getAnchorString() const {
1110 return AnchorString;
1111 }
1112
1113 #ifndef NDEBUG
1114 void GlobalVariableDesc::dump() {
1115 cerr << getDescString() << " "
1116 << "Version(" << getVersion() << "), "
1117 << "Tag(" << getTag() << "), "
1118 << "Anchor(" << getAnchor() << "), "
1119 << "Name(\"" << getName() << "\"), "
1120 << "FullName(\"" << getFullName() << "\"), "
1121 << "LinkageName(\"" << getLinkageName() << "\"), "
1122 << "File(" << getFile() << "),"
1123 << "Line(" << getLine() << "),"
1124 << "Type(" << getType() << "), "
1125 << "IsStatic(" << (isStatic() ? "true" : "false") << "), "
1126 << "IsDefinition(" << (isDefinition() ? "true" : "false") << "), "
1127 << "Global(" << Global << ")\n";
1128 }
1129 #endif
1130
1131 //===----------------------------------------------------------------------===//
1132
1133 SubprogramDesc::SubprogramDesc()
1134 : GlobalDesc(DW_TAG_subprogram)
1135 {}
1136
1137 // Implement isa/cast/dyncast.
1138 bool SubprogramDesc::classof(const DebugInfoDesc *D) {
1139 return D->getTag() == DW_TAG_subprogram;
1140 }
1141
1142 /// ApplyToFields - Target the visitor to the fields of the
1143 /// SubprogramDesc.
1144 void SubprogramDesc::ApplyToFields(DIVisitor *Visitor) {
1145 GlobalDesc::ApplyToFields(Visitor);
1146 }
1147
1148 /// getDescString - Return a string used to compose global names and labels.
1149 ///
1150 const char *SubprogramDesc::getDescString() const {
1151 return "llvm.dbg.subprogram";
1152 }
1153
1154 /// getTypeString - Return a string used to label this descriptors type.
1155 ///
1156 const char *SubprogramDesc::getTypeString() const {
1157 return "llvm.dbg.subprogram.type";
1158 }
1159
1160 /// getAnchorString - Return a string used to label this descriptor's anchor.
1161 ///
1162 const char *SubprogramDesc::AnchorString = "llvm.dbg.subprograms";
1163 const char *SubprogramDesc::getAnchorString() const {
1164 return AnchorString;
1165 }
1166
1167 #ifndef NDEBUG
1168 void SubprogramDesc::dump() {
1169 cerr << getDescString() << " "
1170 << "Version(" << getVersion() << "), "
1171 << "Tag(" << getTag() << "), "
1172 << "Anchor(" << getAnchor() << "), "
1173 << "Name(\"" << getName() << "\"), "
1174 << "FullName(\"" << getFullName() << "\"), "
1175 << "LinkageName(\"" << getLinkageName() << "\"), "
1176 << "File(" << getFile() << "),"
1177 << "Line(" << getLine() << "),"
1178 << "Type(" << getType() << "), "
1179 << "IsStatic(" << (isStatic() ? "true" : "false") << "), "
1180 << "IsDefinition(" << (isDefinition() ? "true" : "false") << ")\n";
1181 }
1182 #endif
1183
1184 //===----------------------------------------------------------------------===//
1185
1186 BlockDesc::BlockDesc()
1187 : DebugInfoDesc(DW_TAG_lexical_block)
1188 , Context(NULL)
1189 {}
1190
1191 // Implement isa/cast/dyncast.
1192 bool BlockDesc::classof(const DebugInfoDesc *D) {
1193 return D->getTag() == DW_TAG_lexical_block;
1194 }
1195
1196 /// ApplyToFields - Target the visitor to the fields of the BlockDesc.
1197 ///
1198 void BlockDesc::ApplyToFields(DIVisitor *Visitor) {
1199 DebugInfoDesc::ApplyToFields(Visitor);
1200
1201 Visitor->Apply(Context);
1202 }
1203
1204 /// getDescString - Return a string used to compose global names and labels.
1205 ///
1206 const char *BlockDesc::getDescString() const {
1207 return "llvm.dbg.block";
1208 }
1209
1210 /// getTypeString - Return a string used to label this descriptors type.
1211 ///
1212 const char *BlockDesc::getTypeString() const {
1213 return "llvm.dbg.block.type";
1214 }
1215
1216 #ifndef NDEBUG
1217 void BlockDesc::dump() {
1218 cerr << getDescString() << " "
1219 << "Version(" << getVersion() << "), "
1220 << "Tag(" << getTag() << "),"
1221 << "Context(" << Context << ")\n";
1222 }
1223 #endif
1224
1225 //===----------------------------------------------------------------------===//
1226
1227 DebugInfoDesc *DIDeserializer::Deserialize(Value *V) {
1228 return Deserialize(getGlobalVariable(V));
1229 }
1230 DebugInfoDesc *DIDeserializer::Deserialize(GlobalVariable *GV) {
1231 // Handle NULL.
1232 if (!GV) return NULL;
1233
1234 // Check to see if it has been already deserialized.
1235 DebugInfoDesc *&Slot = GlobalDescs[GV];
1236 if (Slot) return Slot;
1237
1238 // Get the Tag from the global.
1239 unsigned Tag = DebugInfoDesc::TagFromGlobal(GV);
1240
1241 // Create an empty instance of the correct sort.
1242 Slot = DebugInfoDesc::DescFactory(Tag);
1243
1244 // If not a user defined descriptor.
1245 if (Slot) {
1246 // Deserialize the fields.
1247 DIDeserializeVisitor DRAM(*this, GV);
1248 DRAM.ApplyToFields(Slot);
1249 }
1250
1251 return Slot;
1252 }
1253
1254 //===----------------------------------------------------------------------===//
1255
1256 /// getStrPtrType - Return a "sbyte *" type.
1257 ///
1258 const PointerType *DISerializer::getStrPtrType() {
1259 // If not already defined.
1260 if (!StrPtrTy) {
1261 // Construct the pointer to signed bytes.
1262 StrPtrTy = PointerType::get(Type::Int8Ty);
1263 }
1264
1265 return StrPtrTy;
1266 }
1267
1268 /// getEmptyStructPtrType - Return a "{ }*" type.
1269 ///
1270 const PointerType *DISerializer::getEmptyStructPtrType() {
1271 // If not already defined.
1272 if (!EmptyStructPtrTy) {
1273 // Construct the empty structure type.
1274 const StructType *EmptyStructTy =
1275 StructType::get(std::vector());
1276 // Construct the pointer to empty structure type.
1277 EmptyStructPtrTy = PointerType::get(EmptyStructTy);
1278 }
1279
1280 return EmptyStructPtrTy;
1281 }
1282
1283 /// getTagType - Return the type describing the specified descriptor (via tag.)
1284 ///
1285 const StructType *DISerializer::getTagType(DebugInfoDesc *DD) {
1286 // Attempt to get the previously defined type.
1287 StructType *&Ty = TagTypes[DD->getTag()];
1288
1289 // If not already defined.
1290 if (!Ty) {
1291 // Set up fields vector.
1292 std::vector Fields;
1293 // Get types of fields.
1294 DIGetTypesVisitor GTAM(*this, Fields);
1295 GTAM.ApplyToFields(DD);
1296
1297 // Construct structured type.
1298 Ty = StructType::get(Fields);
1299
1300 // Register type name with module.
1301 M->addTypeName(DD->getTypeString(), Ty);
1302 }
1303
1304 return Ty;
1305 }
1306
1307 /// getString - Construct the string as constant string global.
1308 ///
1309 Constant *DISerializer::getString(const std::string &String) {
1310 // Check string cache for previous edition.
1311 Constant *&Slot = StringCache[String];
1312 // Return Constant if previously defined.
1313 if (Slot) return Slot;
1314 // If empty string then use a sbyte* null instead.
1315 if (String.empty()) {
1316 Slot = ConstantPointerNull::get(getStrPtrType());
1317 } else {
1318 // Construct string as an llvm constant.
1319 Constant *ConstStr = ConstantArray::get(String);
1320 // Otherwise create and return a new string global.
1321 GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true,
1322 GlobalVariable::InternalLinkage,
1323 ConstStr, "str", M);
1324 StrGV->setSection("llvm.metadata");
1325 // Convert to generic string pointer.
1326 Slot = ConstantExpr::getBitCast(StrGV, getStrPtrType());
1327 }
1328 return Slot;
1329
1330 }
1331
1332 /// Serialize - Recursively cast the specified descriptor into a GlobalVariable
1333 /// so that it can be serialized to a .bc or .ll file.
1334 GlobalVariable *DISerializer::Serialize(DebugInfoDesc *DD) {
1335 // Check if the DebugInfoDesc is already in the map.
1336 GlobalVariable *&Slot = DescGlobals[DD];
1337
1338 // See if DebugInfoDesc exists, if so return prior GlobalVariable.
1339 if (Slot) return Slot;
1340
1341 // Get the type associated with the Tag.
1342 const StructType *Ty = getTagType(DD);
1343
1344 // Create the GlobalVariable early to prevent infinite recursion.
1345 GlobalVariable *GV = new GlobalVariable(Ty, true, DD->getLinkage(),
1346 NULL, DD->getDescString(), M);
1347 GV->setSection("llvm.metadata");
1348
1349 // Insert new GlobalVariable in DescGlobals map.
1350 Slot = GV;
1351
1352 // Set up elements vector
1353 std::vector Elements;
1354 // Add fields.
1355 DISerializeVisitor SRAM(*this, Elements);
1356 SRAM.ApplyToFields(DD);
1357
1358 // Set the globals initializer.
1359 GV->setInitializer(ConstantStruct::get(Ty, Elements));
1360
1361 return GV;
1362 }
1363
1364 //===----------------------------------------------------------------------===//
1365
1366 /// Verify - Return true if the GlobalVariable appears to be a valid
1367 /// serialization of a DebugInfoDesc.
1368 bool DIVerifier::Verify(Value *V) {
1369 return !V || Verify(getGlobalVariable(V));
1370 }