1 //===-- llvm/CodeGen/MachineDebugInfo.cpp -----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by James M. Laskey and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/CodeGen/MachineDebugInfo.h"
12 #include "llvm/Constants.h"
13 #include "llvm/CodeGen/MachineLocation.h"
14 #include "llvm/DerivedTypes.h"
15 #include "llvm/GlobalVariable.h"
16 #include "llvm/Intrinsics.h"
17 #include "llvm/Instructions.h"
18 #include "llvm/Module.h"
19 #include "llvm/Support/Dwarf.h"
24 using namespace llvm::dwarf;
26 // Handle the Pass registration stuff necessary to use TargetData's.
28 RegisterPass<MachineDebugInfo> X("machinedebuginfo", "Debug Information");
31 //===----------------------------------------------------------------------===//
33 /// getGlobalVariablesUsing - Return all of the GlobalVariables which have the
34 /// specified value in their initializer somewhere.
36 getGlobalVariablesUsing(Value *V, std::vector<GlobalVariable*> &Result) {
37 // Scan though value users.
38 for (Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I) {
39 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(*I)) {
40 // If the user is a GlobalVariable then add to result.
42 } else if (Constant *C = dyn_cast<Constant>(*I)) {
43 // If the user is a constant variable then scan its users
44 getGlobalVariablesUsing(C, Result);
49 /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
50 /// named GlobalVariable.
51 static std::vector<GlobalVariable*>
52 getGlobalVariablesUsing(Module &M, const std::string &RootName) {
53 std::vector<GlobalVariable*> Result; // GlobalVariables matching criteria.
55 std::vector<const Type*> FieldTypes;
56 FieldTypes.push_back(Type::UIntTy);
57 FieldTypes.push_back(Type::UIntTy);
59 // Get the GlobalVariable root.
60 GlobalVariable *UseRoot = M.getGlobalVariable(RootName,
61 StructType::get(FieldTypes));
63 // If present and linkonce then scan for users.
64 if (UseRoot && UseRoot->hasLinkOnceLinkage()) {
65 getGlobalVariablesUsing(UseRoot, Result);
71 /// isStringValue - Return true if the given value can be coerced to a string.
73 static bool isStringValue(Value *V) {
74 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
75 if (GV->hasInitializer() && isa<ConstantArray>(GV->getInitializer())) {
76 ConstantArray *Init = cast<ConstantArray>(GV->getInitializer());
77 return Init->isString();
79 } else if (Constant *C = dyn_cast<Constant>(V)) {
80 if (GlobalValue *GV = dyn_cast<GlobalValue>(C))
81 return isStringValue(GV);
82 else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
83 if (CE->getOpcode() == Instruction::GetElementPtr) {
84 if (CE->getNumOperands() == 3 &&
85 cast<Constant>(CE->getOperand(1))->isNullValue() &&
86 isa<ConstantInt>(CE->getOperand(2))) {
87 return isStringValue(CE->getOperand(0));
95 /// getGlobalVariable - Return either a direct or cast Global value.
97 static GlobalVariable *getGlobalVariable(Value *V) {
98 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
100 } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
101 if (CE->getOpcode() == Instruction::Cast) {
102 return dyn_cast<GlobalVariable>(CE->getOperand(0));
108 /// isGlobalVariable - Return true if the given value can be coerced to a
110 static bool isGlobalVariable(Value *V) {
111 if (isa<GlobalVariable>(V) || isa<ConstantPointerNull>(V)) {
113 } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
114 if (CE->getOpcode() == Instruction::Cast) {
115 return isa<GlobalVariable>(CE->getOperand(0));
121 /// getUIntOperand - Return ith operand if it is an unsigned integer.
123 static ConstantUInt *getUIntOperand(GlobalVariable *GV, unsigned i) {
124 // Make sure the GlobalVariable has an initializer.
125 if (!GV->hasInitializer()) return NULL;
127 // Get the initializer constant.
128 ConstantStruct *CI = dyn_cast<ConstantStruct>(GV->getInitializer());
129 if (!CI) return NULL;
131 // Check if there is at least i + 1 operands.
132 unsigned N = CI->getNumOperands();
133 if (i >= N) return NULL;
136 return dyn_cast<ConstantUInt>(CI->getOperand(i));
138 //===----------------------------------------------------------------------===//
140 /// ApplyToFields - Target the visitor to each field of the debug information
142 void DIVisitor::ApplyToFields(DebugInfoDesc *DD) {
143 DD->ApplyToFields(this);
146 //===----------------------------------------------------------------------===//
147 /// DICountVisitor - This DIVisitor counts all the fields in the supplied debug
148 /// the supplied DebugInfoDesc.
149 class DICountVisitor : public DIVisitor {
151 unsigned Count; // Running count of fields.
154 DICountVisitor() : DIVisitor(), Count(0) {}
157 unsigned getCount() const { return Count; }
159 /// Apply - Count each of the fields.
161 virtual void Apply(int &Field) { ++Count; }
162 virtual void Apply(unsigned &Field) { ++Count; }
163 virtual void Apply(int64_t &Field) { ++Count; }
164 virtual void Apply(uint64_t &Field) { ++Count; }
165 virtual void Apply(bool &Field) { ++Count; }
166 virtual void Apply(std::string &Field) { ++Count; }
167 virtual void Apply(DebugInfoDesc *&Field) { ++Count; }
168 virtual void Apply(GlobalVariable *&Field) { ++Count; }
169 virtual void Apply(std::vector<DebugInfoDesc *> &Field) {
174 //===----------------------------------------------------------------------===//
175 /// DIDeserializeVisitor - This DIVisitor deserializes all the fields in the
176 /// supplied DebugInfoDesc.
177 class DIDeserializeVisitor : public DIVisitor {
179 DIDeserializer &DR; // Active deserializer.
180 unsigned I; // Current operand index.
181 ConstantStruct *CI; // GlobalVariable constant initializer.
184 DIDeserializeVisitor(DIDeserializer &D, GlobalVariable *GV)
188 , CI(cast<ConstantStruct>(GV->getInitializer()))
191 /// Apply - Set the value of each of the fields.
193 virtual void Apply(int &Field) {
194 Constant *C = CI->getOperand(I++);
195 Field = cast<ConstantSInt>(C)->getValue();
197 virtual void Apply(unsigned &Field) {
198 Constant *C = CI->getOperand(I++);
199 Field = cast<ConstantUInt>(C)->getValue();
201 virtual void Apply(int64_t &Field) {
202 Constant *C = CI->getOperand(I++);
203 Field = cast<ConstantSInt>(C)->getValue();
205 virtual void Apply(uint64_t &Field) {
206 Constant *C = CI->getOperand(I++);
207 Field = cast<ConstantUInt>(C)->getValue();
209 virtual void Apply(bool &Field) {
210 Constant *C = CI->getOperand(I++);
211 Field = cast<ConstantBool>(C)->getValue();
213 virtual void Apply(std::string &Field) {
214 Constant *C = CI->getOperand(I++);
215 Field = C->getStringValue();
217 virtual void Apply(DebugInfoDesc *&Field) {
218 Constant *C = CI->getOperand(I++);
219 Field = DR.Deserialize(C);
221 virtual void Apply(GlobalVariable *&Field) {
222 Constant *C = CI->getOperand(I++);
223 Field = getGlobalVariable(C);
225 virtual void Apply(std::vector<DebugInfoDesc *> &Field) {
226 Constant *C = CI->getOperand(I++);
227 GlobalVariable *GV = getGlobalVariable(C);
229 // Have to be able to deal with the empty array case (zero initializer)
230 if (!GV->hasInitializer()) return;
231 if (ConstantArray *CA = dyn_cast<ConstantArray>(GV->getInitializer())) {
232 for (unsigned i = 0, N = CA->getNumOperands(); i < N; ++i) {
233 GlobalVariable *GVE = getGlobalVariable(CA->getOperand(i));
234 DebugInfoDesc *DE = DR.Deserialize(GVE);
241 //===----------------------------------------------------------------------===//
242 /// DISerializeVisitor - This DIVisitor serializes all the fields in
243 /// the supplied DebugInfoDesc.
244 class DISerializeVisitor : public DIVisitor {
246 DISerializer &SR; // Active serializer.
247 std::vector<Constant*> &Elements; // Element accumulator.
250 DISerializeVisitor(DISerializer &S, std::vector<Constant*> &E)
256 /// Apply - Set the value of each of the fields.
258 virtual void Apply(int &Field) {
259 Elements.push_back(ConstantSInt::get(Type::IntTy, Field));
261 virtual void Apply(unsigned &Field) {
262 Elements.push_back(ConstantUInt::get(Type::UIntTy, Field));
264 virtual void Apply(int64_t &Field) {
265 Elements.push_back(ConstantSInt::get(Type::IntTy, Field));
267 virtual void Apply(uint64_t &Field) {
268 Elements.push_back(ConstantUInt::get(Type::UIntTy, Field));
270 virtual void Apply(bool &Field) {
271 Elements.push_back(ConstantBool::get(Field));
273 virtual void Apply(std::string &Field) {
274 Elements.push_back(SR.getString(Field));
276 virtual void Apply(DebugInfoDesc *&Field) {
277 GlobalVariable *GV = NULL;
279 // If non-NULL then convert to global.
280 if (Field) GV = SR.Serialize(Field);
282 // FIXME - At some point should use specific type.
283 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
286 // Set to pointer to global.
287 Elements.push_back(ConstantExpr::getCast(GV, EmptyTy));
290 Elements.push_back(ConstantPointerNull::get(EmptyTy));
293 virtual void Apply(GlobalVariable *&Field) {
294 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
296 Elements.push_back(ConstantExpr::getCast(Field, EmptyTy));
298 Elements.push_back(ConstantPointerNull::get(EmptyTy));
301 virtual void Apply(std::vector<DebugInfoDesc *> &Field) {
302 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
303 unsigned N = Field.size();
304 ArrayType *AT = ArrayType::get(EmptyTy, N);
305 std::vector<Constant *> ArrayElements;
307 for (unsigned i = 0, N = Field.size(); i < N; ++i) {
308 GlobalVariable *GVE = SR.Serialize(Field[i]);
309 Constant *CE = ConstantExpr::getCast(GVE, EmptyTy);
310 ArrayElements.push_back(cast<Constant>(CE));
313 Constant *CA = ConstantArray::get(AT, ArrayElements);
314 GlobalVariable *CAGV = new GlobalVariable(AT, true,
315 GlobalValue::InternalLinkage,
316 CA, "llvm.dbg.array",
318 CAGV->setSection("llvm.metadata");
319 Constant *CAE = ConstantExpr::getCast(CAGV, EmptyTy);
320 Elements.push_back(CAE);
324 //===----------------------------------------------------------------------===//
325 /// DIGetTypesVisitor - This DIVisitor gathers all the field types in
326 /// the supplied DebugInfoDesc.
327 class DIGetTypesVisitor : public DIVisitor {
329 DISerializer &SR; // Active serializer.
330 std::vector<const Type*> &Fields; // Type accumulator.
333 DIGetTypesVisitor(DISerializer &S, std::vector<const Type*> &F)
339 /// Apply - Set the value of each of the fields.
341 virtual void Apply(int &Field) {
342 Fields.push_back(Type::IntTy);
344 virtual void Apply(unsigned &Field) {
345 Fields.push_back(Type::UIntTy);
347 virtual void Apply(int64_t &Field) {
348 Fields.push_back(Type::IntTy);
350 virtual void Apply(uint64_t &Field) {
351 Fields.push_back(Type::UIntTy);
353 virtual void Apply(bool &Field) {
354 Fields.push_back(Type::BoolTy);
356 virtual void Apply(std::string &Field) {
357 Fields.push_back(SR.getStrPtrType());
359 virtual void Apply(DebugInfoDesc *&Field) {
360 // FIXME - At some point should use specific type.
361 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
362 Fields.push_back(EmptyTy);
364 virtual void Apply(GlobalVariable *&Field) {
365 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
366 Fields.push_back(EmptyTy);
368 virtual void Apply(std::vector<DebugInfoDesc *> &Field) {
369 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
370 Fields.push_back(EmptyTy);
374 //===----------------------------------------------------------------------===//
375 /// DIVerifyVisitor - This DIVisitor verifies all the field types against
376 /// a constant initializer.
377 class DIVerifyVisitor : public DIVisitor {
379 DIVerifier &VR; // Active verifier.
380 bool IsValid; // Validity status.
381 unsigned I; // Current operand index.
382 ConstantStruct *CI; // GlobalVariable constant initializer.
385 DIVerifyVisitor(DIVerifier &V, GlobalVariable *GV)
390 , CI(cast<ConstantStruct>(GV->getInitializer()))
395 bool isValid() const { return IsValid; }
397 /// Apply - Set the value of each of the fields.
399 virtual void Apply(int &Field) {
400 Constant *C = CI->getOperand(I++);
401 IsValid = IsValid && isa<ConstantInt>(C);
403 virtual void Apply(unsigned &Field) {
404 Constant *C = CI->getOperand(I++);
405 IsValid = IsValid && isa<ConstantInt>(C);
407 virtual void Apply(int64_t &Field) {
408 Constant *C = CI->getOperand(I++);
409 IsValid = IsValid && isa<ConstantInt>(C);
411 virtual void Apply(uint64_t &Field) {
412 Constant *C = CI->getOperand(I++);
413 IsValid = IsValid && isa<ConstantInt>(C);
415 virtual void Apply(bool &Field) {
416 Constant *C = CI->getOperand(I++);
417 IsValid = IsValid && isa<ConstantBool>(C);
419 virtual void Apply(std::string &Field) {
420 Constant *C = CI->getOperand(I++);
421 IsValid = IsValid && (!C || isStringValue(C));
423 virtual void Apply(DebugInfoDesc *&Field) {
424 // FIXME - Prepare the correct descriptor.
425 Constant *C = CI->getOperand(I++);
426 IsValid = IsValid && isGlobalVariable(C);
428 virtual void Apply(GlobalVariable *&Field) {
429 Constant *C = CI->getOperand(I++);
430 IsValid = IsValid && isGlobalVariable(C);
432 virtual void Apply(std::vector<DebugInfoDesc *> &Field) {
433 Constant *C = CI->getOperand(I++);
434 IsValid = IsValid && isGlobalVariable(C);
435 if (!IsValid) return;
437 GlobalVariable *GV = getGlobalVariable(C);
438 IsValid = IsValid && GV && GV->hasInitializer();
439 if (!IsValid) return;
441 ConstantArray *CA = dyn_cast<ConstantArray>(GV->getInitializer());
442 IsValid = IsValid && CA;
443 if (!IsValid) return;
445 for (unsigned i = 0, N = CA->getNumOperands(); IsValid && i < N; ++i) {
446 IsValid = IsValid && isGlobalVariable(CA->getOperand(i));
447 if (!IsValid) return;
449 GlobalVariable *GVE = getGlobalVariable(CA->getOperand(i));
456 //===----------------------------------------------------------------------===//
458 /// TagFromGlobal - Returns the Tag number from a debug info descriptor
460 unsigned DebugInfoDesc::TagFromGlobal(GlobalVariable *GV) {
461 ConstantUInt *C = getUIntOperand(GV, 0);
462 return C ? (unsigned)C->getValue() : (unsigned)DW_TAG_invalid;
465 /// DescFactory - Create an instance of debug info descriptor based on Tag.
466 /// Return NULL if not a recognized Tag.
467 DebugInfoDesc *DebugInfoDesc::DescFactory(unsigned Tag) {
469 case DW_TAG_anchor: return new AnchorDesc();
470 case DW_TAG_compile_unit: return new CompileUnitDesc();
471 case DW_TAG_variable: return new GlobalVariableDesc();
472 case DW_TAG_subprogram: return new SubprogramDesc();
473 case DW_TAG_lexical_block: return new BlockDesc();
474 case DW_TAG_base_type: return new BasicTypeDesc();
476 case DW_TAG_pointer_type:
477 case DW_TAG_reference_type:
478 case DW_TAG_const_type:
479 case DW_TAG_volatile_type:
480 case DW_TAG_restrict_type:
481 case DW_TAG_member: return new DerivedTypeDesc(Tag);
482 case DW_TAG_array_type:
483 case DW_TAG_structure_type:
484 case DW_TAG_union_type:
485 case DW_TAG_enumeration_type: return new CompositeTypeDesc(Tag);
486 case DW_TAG_subrange_type: return new SubrangeDesc();
487 case DW_TAG_enumerator: return new EnumeratorDesc();
488 case DW_TAG_return_variable:
489 case DW_TAG_arg_variable:
490 case DW_TAG_auto_variable: return new VariableDesc(Tag);
496 /// getLinkage - get linkage appropriate for this type of descriptor.
498 GlobalValue::LinkageTypes DebugInfoDesc::getLinkage() const {
499 return GlobalValue::InternalLinkage;
502 /// ApplyToFields - Target the vistor to the fields of the descriptor.
504 void DebugInfoDesc::ApplyToFields(DIVisitor *Visitor) {
508 //===----------------------------------------------------------------------===//
510 AnchorDesc::AnchorDesc()
511 : DebugInfoDesc(DW_TAG_anchor)
514 AnchorDesc::AnchorDesc(AnchoredDesc *D)
515 : DebugInfoDesc(DW_TAG_anchor)
516 , AnchorTag(D->getTag())
519 // Implement isa/cast/dyncast.
520 bool AnchorDesc::classof(const DebugInfoDesc *D) {
521 return D->getTag() == DW_TAG_anchor;
524 /// getLinkage - get linkage appropriate for this type of descriptor.
526 GlobalValue::LinkageTypes AnchorDesc::getLinkage() const {
527 return GlobalValue::LinkOnceLinkage;
530 /// ApplyToFields - Target the visitor to the fields of the TransUnitDesc.
532 void AnchorDesc::ApplyToFields(DIVisitor *Visitor) {
533 DebugInfoDesc::ApplyToFields(Visitor);
535 Visitor->Apply(AnchorTag);
538 /// getDescString - Return a string used to compose global names and labels. A
539 /// A global variable name needs to be defined for each debug descriptor that is
540 /// anchored. NOTE: that each global variable named here also needs to be added
541 /// to the list of names left external in the internalizer.
542 /// ExternalNames.insert("llvm.dbg.compile_units");
543 /// ExternalNames.insert("llvm.dbg.global_variables");
544 /// ExternalNames.insert("llvm.dbg.subprograms");
545 const char *AnchorDesc::getDescString() const {
547 case DW_TAG_compile_unit: return CompileUnitDesc::AnchorString;
548 case DW_TAG_variable: return GlobalVariableDesc::AnchorString;
549 case DW_TAG_subprogram: return SubprogramDesc::AnchorString;
553 assert(0 && "Tag does not have a case for anchor string");
557 /// getTypeString - Return a string used to label this descriptors type.
559 const char *AnchorDesc::getTypeString() const {
560 return "llvm.dbg.anchor.type";
564 void AnchorDesc::dump() {
565 std::cerr << getDescString() << " "
566 << "Tag(" << getTag() << "), "
567 << "AnchorTag(" << AnchorTag << ")\n";
571 //===----------------------------------------------------------------------===//
573 AnchoredDesc::AnchoredDesc(unsigned T)
578 /// ApplyToFields - Target the visitor to the fields of the AnchoredDesc.
580 void AnchoredDesc::ApplyToFields(DIVisitor *Visitor) {
581 DebugInfoDesc::ApplyToFields(Visitor);
583 Visitor->Apply((DebugInfoDesc *&)Anchor);
586 //===----------------------------------------------------------------------===//
588 CompileUnitDesc::CompileUnitDesc()
589 : AnchoredDesc(DW_TAG_compile_unit)
590 , DebugVersion(LLVMDebugVersion)
597 // Implement isa/cast/dyncast.
598 bool CompileUnitDesc::classof(const DebugInfoDesc *D) {
599 return D->getTag() == DW_TAG_compile_unit;
602 /// DebugVersionFromGlobal - Returns the version number from a compile unit
604 unsigned CompileUnitDesc::DebugVersionFromGlobal(GlobalVariable *GV) {
605 ConstantUInt *C = getUIntOperand(GV, 2);
606 return C ? (unsigned)C->getValue() : (unsigned)DW_TAG_invalid;
609 /// ApplyToFields - Target the visitor to the fields of the CompileUnitDesc.
611 void CompileUnitDesc::ApplyToFields(DIVisitor *Visitor) {
612 AnchoredDesc::ApplyToFields(Visitor);
614 Visitor->Apply(DebugVersion);
615 Visitor->Apply(Language);
616 Visitor->Apply(FileName);
617 Visitor->Apply(Directory);
618 Visitor->Apply(Producer);
621 /// getDescString - Return a string used to compose global names and labels.
623 const char *CompileUnitDesc::getDescString() const {
624 return "llvm.dbg.compile_unit";
627 /// getTypeString - Return a string used to label this descriptors type.
629 const char *CompileUnitDesc::getTypeString() const {
630 return "llvm.dbg.compile_unit.type";
633 /// getAnchorString - Return a string used to label this descriptor's anchor.
635 const char *CompileUnitDesc::AnchorString = "llvm.dbg.compile_units";
636 const char *CompileUnitDesc::getAnchorString() const {
641 void CompileUnitDesc::dump() {
642 std::cerr << getDescString() << " "
643 << "Tag(" << getTag() << "), "
644 << "Anchor(" << getAnchor() << "), "
645 << "DebugVersion(" << DebugVersion << "), "
646 << "Language(" << Language << "), "
647 << "FileName(\"" << FileName << "\"), "
648 << "Directory(\"" << Directory << "\"), "
649 << "Producer(\"" << Producer << "\")\n";
653 //===----------------------------------------------------------------------===//
655 TypeDesc::TypeDesc(unsigned T)
666 /// ApplyToFields - Target the visitor to the fields of the TypeDesc.
668 void TypeDesc::ApplyToFields(DIVisitor *Visitor) {
669 DebugInfoDesc::ApplyToFields(Visitor);
671 Visitor->Apply(Context);
672 Visitor->Apply(Name);
673 Visitor->Apply((DebugInfoDesc *&)File);
674 Visitor->Apply(Line);
675 Visitor->Apply(Size);
676 Visitor->Apply(Align);
677 Visitor->Apply(Offset);
680 /// getDescString - Return a string used to compose global names and labels.
682 const char *TypeDesc::getDescString() const {
683 return "llvm.dbg.type";
686 /// getTypeString - Return a string used to label this descriptor's type.
688 const char *TypeDesc::getTypeString() const {
689 return "llvm.dbg.type.type";
693 void TypeDesc::dump() {
694 std::cerr << getDescString() << " "
695 << "Tag(" << getTag() << "), "
696 << "Context(" << Context << "), "
697 << "Name(\"" << Name << "\"), "
698 << "File(" << File << "), "
699 << "Line(" << Line << "), "
700 << "Size(" << Size << "), "
701 << "Align(" << Align << "), "
702 << "Offset(" << Offset << ")\n";
706 //===----------------------------------------------------------------------===//
708 BasicTypeDesc::BasicTypeDesc()
709 : TypeDesc(DW_TAG_base_type)
713 // Implement isa/cast/dyncast.
714 bool BasicTypeDesc::classof(const DebugInfoDesc *D) {
715 return D->getTag() == DW_TAG_base_type;
718 /// ApplyToFields - Target the visitor to the fields of the BasicTypeDesc.
720 void BasicTypeDesc::ApplyToFields(DIVisitor *Visitor) {
721 TypeDesc::ApplyToFields(Visitor);
723 Visitor->Apply(Encoding);
726 /// getDescString - Return a string used to compose global names and labels.
728 const char *BasicTypeDesc::getDescString() const {
729 return "llvm.dbg.basictype";
732 /// getTypeString - Return a string used to label this descriptor's type.
734 const char *BasicTypeDesc::getTypeString() const {
735 return "llvm.dbg.basictype.type";
739 void BasicTypeDesc::dump() {
740 std::cerr << getDescString() << " "
741 << "Tag(" << getTag() << "), "
742 << "Context(" << getContext() << "), "
743 << "Name(\"" << getName() << "\"), "
744 << "Size(" << getSize() << "), "
745 << "Encoding(" << Encoding << ")\n";
749 //===----------------------------------------------------------------------===//
751 DerivedTypeDesc::DerivedTypeDesc(unsigned T)
756 // Implement isa/cast/dyncast.
757 bool DerivedTypeDesc::classof(const DebugInfoDesc *D) {
758 unsigned T = D->getTag();
761 case DW_TAG_pointer_type:
762 case DW_TAG_reference_type:
763 case DW_TAG_const_type:
764 case DW_TAG_volatile_type:
765 case DW_TAG_restrict_type:
773 /// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc.
775 void DerivedTypeDesc::ApplyToFields(DIVisitor *Visitor) {
776 TypeDesc::ApplyToFields(Visitor);
778 Visitor->Apply((DebugInfoDesc *&)FromType);
781 /// getDescString - Return a string used to compose global names and labels.
783 const char *DerivedTypeDesc::getDescString() const {
784 return "llvm.dbg.derivedtype";
787 /// getTypeString - Return a string used to label this descriptor's type.
789 const char *DerivedTypeDesc::getTypeString() const {
790 return "llvm.dbg.derivedtype.type";
794 void DerivedTypeDesc::dump() {
795 std::cerr << getDescString() << " "
796 << "Tag(" << getTag() << "), "
797 << "Context(" << getContext() << "), "
798 << "Name(\"" << getName() << "\"), "
799 << "Size(" << getSize() << "), "
800 << "File(" << getFile() << "), "
801 << "Line(" << getLine() << "), "
802 << "FromType(" << FromType << ")\n";
806 //===----------------------------------------------------------------------===//
808 CompositeTypeDesc::CompositeTypeDesc(unsigned T)
813 // Implement isa/cast/dyncast.
814 bool CompositeTypeDesc::classof(const DebugInfoDesc *D) {
815 unsigned T = D->getTag();
817 case DW_TAG_array_type:
818 case DW_TAG_structure_type:
819 case DW_TAG_union_type:
820 case DW_TAG_enumeration_type:
827 /// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc.
829 void CompositeTypeDesc::ApplyToFields(DIVisitor *Visitor) {
830 DerivedTypeDesc::ApplyToFields(Visitor);
832 Visitor->Apply(Elements);
835 /// getDescString - Return a string used to compose global names and labels.
837 const char *CompositeTypeDesc::getDescString() const {
838 return "llvm.dbg.compositetype";
841 /// getTypeString - Return a string used to label this descriptor's type.
843 const char *CompositeTypeDesc::getTypeString() const {
844 return "llvm.dbg.compositetype.type";
848 void CompositeTypeDesc::dump() {
849 std::cerr << getDescString() << " "
850 << "Tag(" << getTag() << "), "
851 << "Context(" << getContext() << "), "
852 << "Name(\"" << getName() << "\"), "
853 << "Size(" << getSize() << "), "
854 << "File(" << getFile() << "), "
855 << "Line(" << getLine() << "), "
856 << "FromType(" << getFromType() << "), "
857 << "Elements.size(" << Elements.size() << ")\n";
861 //===----------------------------------------------------------------------===//
863 SubrangeDesc::SubrangeDesc()
864 : DebugInfoDesc(DW_TAG_subrange_type)
869 // Implement isa/cast/dyncast.
870 bool SubrangeDesc::classof(const DebugInfoDesc *D) {
871 return D->getTag() == DW_TAG_subrange_type;
874 /// ApplyToFields - Target the visitor to the fields of the SubrangeDesc.
876 void SubrangeDesc::ApplyToFields(DIVisitor *Visitor) {
877 DebugInfoDesc::ApplyToFields(Visitor);
883 /// getDescString - Return a string used to compose global names and labels.
885 const char *SubrangeDesc::getDescString() const {
886 return "llvm.dbg.subrange";
889 /// getTypeString - Return a string used to label this descriptor's type.
891 const char *SubrangeDesc::getTypeString() const {
892 return "llvm.dbg.subrange.type";
896 void SubrangeDesc::dump() {
897 std::cerr << getDescString() << " "
898 << "Tag(" << getTag() << "), "
899 << "Lo(" << Lo << "), "
900 << "Hi(" << Hi << ")\n";
904 //===----------------------------------------------------------------------===//
906 EnumeratorDesc::EnumeratorDesc()
907 : DebugInfoDesc(DW_TAG_enumerator)
912 // Implement isa/cast/dyncast.
913 bool EnumeratorDesc::classof(const DebugInfoDesc *D) {
914 return D->getTag() == DW_TAG_enumerator;
917 /// ApplyToFields - Target the visitor to the fields of the EnumeratorDesc.
919 void EnumeratorDesc::ApplyToFields(DIVisitor *Visitor) {
920 DebugInfoDesc::ApplyToFields(Visitor);
922 Visitor->Apply(Name);
923 Visitor->Apply(Value);
926 /// getDescString - Return a string used to compose global names and labels.
928 const char *EnumeratorDesc::getDescString() const {
929 return "llvm.dbg.enumerator";
932 /// getTypeString - Return a string used to label this descriptor's type.
934 const char *EnumeratorDesc::getTypeString() const {
935 return "llvm.dbg.enumerator.type";
939 void EnumeratorDesc::dump() {
940 std::cerr << getDescString() << " "
941 << "Tag(" << getTag() << "), "
942 << "Name(" << Name << "), "
943 << "Value(" << Value << ")\n";
947 //===----------------------------------------------------------------------===//
949 VariableDesc::VariableDesc(unsigned T)
958 // Implement isa/cast/dyncast.
959 bool VariableDesc::classof(const DebugInfoDesc *D) {
960 unsigned T = D->getTag();
962 case DW_TAG_auto_variable:
963 case DW_TAG_arg_variable:
964 case DW_TAG_return_variable:
971 /// ApplyToFields - Target the visitor to the fields of the VariableDesc.
973 void VariableDesc::ApplyToFields(DIVisitor *Visitor) {
974 DebugInfoDesc::ApplyToFields(Visitor);
976 Visitor->Apply(Context);
977 Visitor->Apply(Name);
978 Visitor->Apply((DebugInfoDesc *&)File);
979 Visitor->Apply(Line);
980 Visitor->Apply((DebugInfoDesc *&)TyDesc);
983 /// getDescString - Return a string used to compose global names and labels.
985 const char *VariableDesc::getDescString() const {
986 return "llvm.dbg.variable";
989 /// getTypeString - Return a string used to label this descriptor's type.
991 const char *VariableDesc::getTypeString() const {
992 return "llvm.dbg.variable.type";
996 void VariableDesc::dump() {
997 std::cerr << getDescString() << " "
998 << "Tag(" << getTag() << "), "
999 << "Context(" << Context << "), "
1000 << "Name(\"" << Name << "\"), "
1001 << "File(" << File << "), "
1002 << "Line(" << Line << "), "
1003 << "TyDesc(" << TyDesc << ")\n";
1007 //===----------------------------------------------------------------------===//
1009 GlobalDesc::GlobalDesc(unsigned T)
1017 , IsDefinition(false)
1020 /// ApplyToFields - Target the visitor to the fields of the global.
1022 void GlobalDesc::ApplyToFields(DIVisitor *Visitor) {
1023 AnchoredDesc::ApplyToFields(Visitor);
1025 Visitor->Apply(Context);
1026 Visitor->Apply(Name);
1027 Visitor->Apply((DebugInfoDesc *&)File);
1028 Visitor->Apply(Line);
1029 Visitor->Apply((DebugInfoDesc *&)TyDesc);
1030 Visitor->Apply(IsStatic);
1031 Visitor->Apply(IsDefinition);
1034 //===----------------------------------------------------------------------===//
1036 GlobalVariableDesc::GlobalVariableDesc()
1037 : GlobalDesc(DW_TAG_variable)
1041 // Implement isa/cast/dyncast.
1042 bool GlobalVariableDesc::classof(const DebugInfoDesc *D) {
1043 return D->getTag() == DW_TAG_variable;
1046 /// ApplyToFields - Target the visitor to the fields of the GlobalVariableDesc.
1048 void GlobalVariableDesc::ApplyToFields(DIVisitor *Visitor) {
1049 GlobalDesc::ApplyToFields(Visitor);
1051 Visitor->Apply(Global);
1054 /// getDescString - Return a string used to compose global names and labels.
1056 const char *GlobalVariableDesc::getDescString() const {
1057 return "llvm.dbg.global_variable";
1060 /// getTypeString - Return a string used to label this descriptors type.
1062 const char *GlobalVariableDesc::getTypeString() const {
1063 return "llvm.dbg.global_variable.type";
1066 /// getAnchorString - Return a string used to label this descriptor's anchor.
1068 const char *GlobalVariableDesc::AnchorString = "llvm.dbg.global_variables";
1069 const char *GlobalVariableDesc::getAnchorString() const {
1070 return AnchorString;
1074 void GlobalVariableDesc::dump() {
1075 std::cerr << getDescString() << " "
1076 << "Tag(" << getTag() << "), "
1077 << "Anchor(" << getAnchor() << "), "
1078 << "Name(\"" << getName() << "\"), "
1079 << "File(" << getFile() << "),"
1080 << "Line(" << getLine() << "),"
1081 << "Type(\"" << getType() << "\"), "
1082 << "IsStatic(" << (isStatic() ? "true" : "false") << "), "
1083 << "IsDefinition(" << (isDefinition() ? "true" : "false") << "), "
1084 << "Global(" << Global << ")\n";
1088 //===----------------------------------------------------------------------===//
1090 SubprogramDesc::SubprogramDesc()
1091 : GlobalDesc(DW_TAG_subprogram)
1094 // Implement isa/cast/dyncast.
1095 bool SubprogramDesc::classof(const DebugInfoDesc *D) {
1096 return D->getTag() == DW_TAG_subprogram;
1099 /// ApplyToFields - Target the visitor to the fields of the
1101 void SubprogramDesc::ApplyToFields(DIVisitor *Visitor) {
1102 GlobalDesc::ApplyToFields(Visitor);
1105 /// getDescString - Return a string used to compose global names and labels.
1107 const char *SubprogramDesc::getDescString() const {
1108 return "llvm.dbg.subprogram";
1111 /// getTypeString - Return a string used to label this descriptors type.
1113 const char *SubprogramDesc::getTypeString() const {
1114 return "llvm.dbg.subprogram.type";
1117 /// getAnchorString - Return a string used to label this descriptor's anchor.
1119 const char *SubprogramDesc::AnchorString = "llvm.dbg.subprograms";
1120 const char *SubprogramDesc::getAnchorString() const {
1121 return AnchorString;
1125 void SubprogramDesc::dump() {
1126 std::cerr << getDescString() << " "
1127 << "Tag(" << getTag() << "), "
1128 << "Anchor(" << getAnchor() << "), "
1129 << "Name(\"" << getName() << "\"), "
1130 << "File(" << getFile() << "),"
1131 << "Line(" << getLine() << "),"
1132 << "Type(\"" << getType() << "\"), "
1133 << "IsStatic(" << (isStatic() ? "true" : "false") << "), "
1134 << "IsDefinition(" << (isDefinition() ? "true" : "false") << ")\n";
1138 //===----------------------------------------------------------------------===//
1140 BlockDesc::BlockDesc()
1141 : DebugInfoDesc(DW_TAG_lexical_block)
1145 // Implement isa/cast/dyncast.
1146 bool BlockDesc::classof(const DebugInfoDesc *D) {
1147 return D->getTag() == DW_TAG_lexical_block;
1150 /// ApplyToFields - Target the visitor to the fields of the BlockDesc.
1152 void BlockDesc::ApplyToFields(DIVisitor *Visitor) {
1153 DebugInfoDesc::ApplyToFields(Visitor);
1155 Visitor->Apply(Context);
1158 /// getDescString - Return a string used to compose global names and labels.
1160 const char *BlockDesc::getDescString() const {
1161 return "llvm.dbg.block";
1164 /// getTypeString - Return a string used to label this descriptors type.
1166 const char *BlockDesc::getTypeString() const {
1167 return "llvm.dbg.block.type";
1171 void BlockDesc::dump() {
1172 std::cerr << getDescString() << " "
1173 << "Tag(" << getTag() << "),"
1174 << "Context(" << Context << ")\n";
1178 //===----------------------------------------------------------------------===//
1180 DebugInfoDesc *DIDeserializer::Deserialize(Value *V) {
1181 return Deserialize(getGlobalVariable(V));
1183 DebugInfoDesc *DIDeserializer::Deserialize(GlobalVariable *GV) {
1185 if (!GV) return NULL;
1187 // Check to see if it has been already deserialized.
1188 DebugInfoDesc *&Slot = GlobalDescs[GV];
1189 if (Slot) return Slot;
1191 // Get the Tag from the global.
1192 unsigned Tag = DebugInfoDesc::TagFromGlobal(GV);
1194 // Get the debug version if a compile unit.
1195 if (Tag == DW_TAG_compile_unit) {
1196 DebugVersion = CompileUnitDesc::DebugVersionFromGlobal(GV);
1199 // Create an empty instance of the correct sort.
1200 Slot = DebugInfoDesc::DescFactory(Tag);
1202 // If not a user defined descriptor.
1204 // Deserialize the fields.
1205 DIDeserializeVisitor DRAM(*this, GV);
1206 DRAM.ApplyToFields(Slot);
1212 //===----------------------------------------------------------------------===//
1214 /// getStrPtrType - Return a "sbyte *" type.
1216 const PointerType *DISerializer::getStrPtrType() {
1217 // If not already defined.
1219 // Construct the pointer to signed bytes.
1220 StrPtrTy = PointerType::get(Type::SByteTy);
1226 /// getEmptyStructPtrType - Return a "{ }*" type.
1228 const PointerType *DISerializer::getEmptyStructPtrType() {
1229 // If not already defined.
1230 if (!EmptyStructPtrTy) {
1231 // Construct the empty structure type.
1232 const StructType *EmptyStructTy =
1233 StructType::get(std::vector<const Type*>());
1234 // Construct the pointer to empty structure type.
1235 EmptyStructPtrTy = PointerType::get(EmptyStructTy);
1238 return EmptyStructPtrTy;
1241 /// getTagType - Return the type describing the specified descriptor (via tag.)
1243 const StructType *DISerializer::getTagType(DebugInfoDesc *DD) {
1244 // Attempt to get the previously defined type.
1245 StructType *&Ty = TagTypes[DD->getTag()];
1247 // If not already defined.
1249 // Set up fields vector.
1250 std::vector<const Type*> Fields;
1251 // Get types of fields.
1252 DIGetTypesVisitor GTAM(*this, Fields);
1253 GTAM.ApplyToFields(DD);
1255 // Construct structured type.
1256 Ty = StructType::get(Fields);
1258 // Register type name with module.
1259 M->addTypeName(DD->getTypeString(), Ty);
1265 /// getString - Construct the string as constant string global.
1267 Constant *DISerializer::getString(const std::string &String) {
1268 // Check string cache for previous edition.
1269 Constant *&Slot = StringCache[String];
1270 // Return Constant if previously defined.
1271 if (Slot) return Slot;
1272 // If empty string then use a sbyte* null instead.
1273 if (String.empty()) {
1274 Slot = ConstantPointerNull::get(getStrPtrType());
1276 // Construct string as an llvm constant.
1277 Constant *ConstStr = ConstantArray::get(String);
1278 // Otherwise create and return a new string global.
1279 GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true,
1280 GlobalVariable::InternalLinkage,
1281 ConstStr, "str", M);
1282 StrGV->setSection("llvm.metadata");
1283 // Convert to generic string pointer.
1284 Slot = ConstantExpr::getCast(StrGV, getStrPtrType());
1290 /// Serialize - Recursively cast the specified descriptor into a GlobalVariable
1291 /// so that it can be serialized to a .bc or .ll file.
1292 GlobalVariable *DISerializer::Serialize(DebugInfoDesc *DD) {
1293 // Check if the DebugInfoDesc is already in the map.
1294 GlobalVariable *&Slot = DescGlobals[DD];
1296 // See if DebugInfoDesc exists, if so return prior GlobalVariable.
1297 if (Slot) return Slot;
1299 // Get the type associated with the Tag.
1300 const StructType *Ty = getTagType(DD);
1302 // Create the GlobalVariable early to prevent infinite recursion.
1303 GlobalVariable *GV = new GlobalVariable(Ty, true, DD->getLinkage(),
1304 NULL, DD->getDescString(), M);
1305 GV->setSection("llvm.metadata");
1307 // Insert new GlobalVariable in DescGlobals map.
1310 // Set up elements vector
1311 std::vector<Constant*> Elements;
1313 DISerializeVisitor SRAM(*this, Elements);
1314 SRAM.ApplyToFields(DD);
1316 // Set the globals initializer.
1317 GV->setInitializer(ConstantStruct::get(Ty, Elements));
1322 //===----------------------------------------------------------------------===//
1324 /// Verify - Return true if the GlobalVariable appears to be a valid
1325 /// serialization of a DebugInfoDesc.
1326 bool DIVerifier::Verify(Value *V) {
1327 return !V || Verify(getGlobalVariable(V));
1329 bool DIVerifier::Verify(GlobalVariable *GV) {
1331 if (!GV) return true;
1333 // Check prior validity.
1334 unsigned &ValiditySlot = Validity[GV];
1336 // If visited before then use old state.
1337 if (ValiditySlot) return ValiditySlot == Valid;
1339 // Assume validity for the time being (recursion.)
1340 ValiditySlot = Valid;
1342 // Make sure the global is internal or link once (anchor.)
1343 if (GV->getLinkage() != GlobalValue::InternalLinkage &&
1344 GV->getLinkage() != GlobalValue::LinkOnceLinkage) {
1345 ValiditySlot = Invalid;
1350 unsigned Tag = DebugInfoDesc::TagFromGlobal(GV);
1352 // Check for user defined descriptors.
1353 if (Tag == DW_TAG_invalid) return true;
1355 // If a compile unit we need the debug version.
1356 if (Tag == DW_TAG_compile_unit) {
1357 DebugVersion = CompileUnitDesc::DebugVersionFromGlobal(GV);
1358 // FIXME - In the short term, changes are too drastic to continue.
1359 if (DebugVersion != LLVMDebugVersion) {
1360 ValiditySlot = Invalid;
1365 // Construct an empty DebugInfoDesc.
1366 DebugInfoDesc *DD = DebugInfoDesc::DescFactory(Tag);
1368 // Allow for user defined descriptors.
1369 if (!DD) return true;
1371 // Get the initializer constant.
1372 ConstantStruct *CI = cast<ConstantStruct>(GV->getInitializer());
1374 // Get the operand count.
1375 unsigned N = CI->getNumOperands();
1377 // Get the field count.
1378 unsigned &CountSlot = Counts[Tag];
1380 // Check the operand count to the field count
1381 DICountVisitor CTAM;
1382 CTAM.ApplyToFields(DD);
1383 CountSlot = CTAM.getCount();
1386 // Field count must be at most equal operand count.
1387 if (CountSlot > N) {
1389 ValiditySlot = Invalid;
1393 // Check each field for valid type.
1394 DIVerifyVisitor VRAM(*this, GV);
1395 VRAM.ApplyToFields(DD);
1397 // Release empty DebugInfoDesc.
1400 // If fields are not valid.
1401 if (!VRAM.isValid()) {
1402 ValiditySlot = Invalid;
1409 //===----------------------------------------------------------------------===//
1411 DebugScope::~DebugScope() {
1412 for (unsigned i = 0, N = Scopes.size(); i < N; ++i) delete Scopes[i];
1413 for (unsigned j = 0, M = Variables.size(); j < M; ++j) delete Variables[j];
1416 //===----------------------------------------------------------------------===//
1418 MachineDebugInfo::MachineDebugInfo()
1430 MachineDebugInfo::~MachineDebugInfo() {
1434 /// doInitialization - Initialize the debug state for a new module.
1436 bool MachineDebugInfo::doInitialization() {
1440 /// doFinalization - Tear down the debug state after completion of a module.
1442 bool MachineDebugInfo::doFinalization() {
1446 /// BeginFunction - Begin gathering function debug information.
1448 void MachineDebugInfo::BeginFunction(MachineFunction *MF) {
1452 /// MachineDebugInfo::EndFunction - Discard function debug information.
1454 void MachineDebugInfo::EndFunction() {
1455 // Clean up scope information.
1462 // Clean up frame info.
1463 for (unsigned i = 0, N = FrameMoves.size(); i < N; ++i) delete FrameMoves[i];
1467 /// getDescFor - Convert a Value to a debug information descriptor.
1469 // FIXME - use new Value type when available.
1470 DebugInfoDesc *MachineDebugInfo::getDescFor(Value *V) {
1471 return DR.Deserialize(V);
1474 /// Verify - Verify that a Value is debug information descriptor.
1476 bool MachineDebugInfo::Verify(Value *V) {
1477 return VR.Verify(V);
1480 /// AnalyzeModule - Scan the module for global debug information.
1482 void MachineDebugInfo::AnalyzeModule(Module &M) {
1483 SetupCompileUnits(M);
1486 /// SetupCompileUnits - Set up the unique vector of compile units.
1488 void MachineDebugInfo::SetupCompileUnits(Module &M) {
1489 std::vector<CompileUnitDesc *>CU = getAnchoredDescriptors<CompileUnitDesc>(M);
1491 for (unsigned i = 0, N = CU.size(); i < N; i++) {
1492 CompileUnits.insert(CU[i]);
1496 /// getCompileUnits - Return a vector of debug compile units.
1498 const UniqueVector<CompileUnitDesc *> MachineDebugInfo::getCompileUnits()const{
1499 return CompileUnits;
1502 /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
1503 /// named GlobalVariable.
1504 std::vector<GlobalVariable*>
1505 MachineDebugInfo::getGlobalVariablesUsing(Module &M,
1506 const std::string &RootName) {
1507 return ::getGlobalVariablesUsing(M, RootName);
1510 /// RecordLabel - Records location information and associates it with a
1511 /// debug label. Returns a unique label ID used to generate a label and
1512 /// provide correspondence to the source line list.
1513 unsigned MachineDebugInfo::RecordLabel(unsigned Line, unsigned Column,
1515 unsigned ID = NextLabelID();
1516 Lines.push_back(new SourceLineInfo(Line, Column, Source, ID));
1520 /// RecordSource - Register a source file with debug info. Returns an source
1522 unsigned MachineDebugInfo::RecordSource(const std::string &Directory,
1523 const std::string &Source) {
1524 unsigned DirectoryID = Directories.insert(Directory);
1525 return SourceFiles.insert(SourceFileInfo(DirectoryID, Source));
1527 unsigned MachineDebugInfo::RecordSource(const CompileUnitDesc *CompileUnit) {
1528 return RecordSource(CompileUnit->getDirectory(),
1529 CompileUnit->getFileName());
1532 /// RecordRegionStart - Indicate the start of a region.
1534 unsigned MachineDebugInfo::RecordRegionStart(Value *V) {
1535 // FIXME - need to be able to handle split scopes because of bb cloning.
1536 DebugInfoDesc *ScopeDesc = DR.Deserialize(V);
1537 DebugScope *Scope = getOrCreateScope(ScopeDesc);
1538 unsigned ID = NextLabelID();
1539 if (!Scope->getStartLabelID()) Scope->setStartLabelID(ID);
1543 /// RecordRegionEnd - Indicate the end of a region.
1545 unsigned MachineDebugInfo::RecordRegionEnd(Value *V) {
1546 // FIXME - need to be able to handle split scopes because of bb cloning.
1547 DebugInfoDesc *ScopeDesc = DR.Deserialize(V);
1548 DebugScope *Scope = getOrCreateScope(ScopeDesc);
1549 unsigned ID = NextLabelID();
1550 Scope->setEndLabelID(ID);
1554 /// RecordVariable - Indicate the declaration of a local variable.
1556 void MachineDebugInfo::RecordVariable(Value *V, unsigned FrameIndex) {
1557 VariableDesc *VD = cast<VariableDesc>(DR.Deserialize(V));
1558 DebugScope *Scope = getOrCreateScope(VD->getContext());
1559 DebugVariable *DV = new DebugVariable(VD, FrameIndex);
1560 Scope->AddVariable(DV);
1563 /// getOrCreateScope - Returns the scope associated with the given descriptor.
1565 DebugScope *MachineDebugInfo::getOrCreateScope(DebugInfoDesc *ScopeDesc) {
1566 DebugScope *&Slot = ScopeMap[ScopeDesc];
1568 // FIXME - breaks down when the context is an inlined function.
1569 DebugInfoDesc *ParentDesc = NULL;
1570 if (BlockDesc *Block = dyn_cast<BlockDesc>(ScopeDesc)) {
1571 ParentDesc = Block->getContext();
1573 DebugScope *Parent = ParentDesc ? getOrCreateScope(ParentDesc) : NULL;
1574 Slot = new DebugScope(Parent, ScopeDesc);
1576 Parent->AddScope(Slot);
1577 } else if (RootScope) {
1578 // FIXME - Add inlined function scopes to the root so we can delete
1579 // them later. Long term, handle inlined functions properly.
1580 RootScope->AddScope(Slot);
1582 // First function is top level function.