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/DerivedTypes.h"
14 #include "llvm/GlobalVariable.h"
15 #include "llvm/Intrinsics.h"
16 #include "llvm/Instructions.h"
17 #include "llvm/Module.h"
18 #include "llvm/Support/Dwarf.h"
24 // Handle the Pass registration stuff necessary to use TargetData's.
26 RegisterPass<MachineDebugInfo> X("machinedebuginfo", "Debug Information");
29 //===----------------------------------------------------------------------===//
31 /// getGlobalVariablesUsing - Return all of the GlobalVariables which have the
32 /// specified value in their initializer somewhere.
34 getGlobalVariablesUsing(Value *V, std::vector<GlobalVariable*> &Result) {
35 // Scan though value users.
36 for (Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I) {
37 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(*I)) {
38 // If the user is a GlobalVariable then add to result.
40 } else if (Constant *C = dyn_cast<Constant>(*I)) {
41 // If the user is a constant variable then scan its users
42 getGlobalVariablesUsing(C, Result);
47 /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
48 /// named GlobalVariable.
49 static std::vector<GlobalVariable*>
50 getGlobalVariablesUsing(Module &M, const std::string &RootName) {
51 std::vector<GlobalVariable*> Result; // GlobalVariables matching criteria.
53 // Get the GlobalVariable root.
54 GlobalVariable *UseRoot = M.getGlobalVariable(RootName,
55 StructType::get(std::vector<const Type*>()));
57 // If present and linkonce then scan for users.
58 if (UseRoot && UseRoot->hasLinkOnceLinkage()) {
59 getGlobalVariablesUsing(UseRoot, Result);
65 /// getStringValue - Turn an LLVM constant pointer that eventually points to a
66 /// global into a string value. Return an empty string if we can't do it.
68 static const std::string getStringValue(Value *V, unsigned Offset = 0) {
69 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
70 if (GV->hasInitializer() && isa<ConstantArray>(GV->getInitializer())) {
71 ConstantArray *Init = cast<ConstantArray>(GV->getInitializer());
72 if (Init->isString()) {
73 std::string Result = Init->getAsString();
74 if (Offset < Result.size()) {
75 // If we are pointing INTO The string, erase the beginning...
76 Result.erase(Result.begin(), Result.begin()+Offset);
78 // Take off the null terminator, and any string fragments after it.
79 std::string::size_type NullPos = Result.find_first_of((char)0);
80 if (NullPos != std::string::npos)
81 Result.erase(Result.begin()+NullPos, Result.end());
86 } else if (Constant *C = dyn_cast<Constant>(V)) {
87 if (GlobalValue *GV = dyn_cast<GlobalValue>(C))
88 return getStringValue(GV, Offset);
89 else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
90 if (CE->getOpcode() == Instruction::GetElementPtr) {
91 // Turn a gep into the specified offset.
92 if (CE->getNumOperands() == 3 &&
93 cast<Constant>(CE->getOperand(1))->isNullValue() &&
94 isa<ConstantInt>(CE->getOperand(2))) {
95 return getStringValue(CE->getOperand(0),
96 Offset+cast<ConstantInt>(CE->getOperand(2))->getRawValue());
104 /// isStringValue - Return true if the given value can be coerced to a string.
106 static bool isStringValue(Value *V) {
107 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
108 if (GV->hasInitializer() && isa<ConstantArray>(GV->getInitializer())) {
109 ConstantArray *Init = cast<ConstantArray>(GV->getInitializer());
110 return Init->isString();
112 } else if (Constant *C = dyn_cast<Constant>(V)) {
113 if (GlobalValue *GV = dyn_cast<GlobalValue>(C))
114 return isStringValue(GV);
115 else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
116 if (CE->getOpcode() == Instruction::GetElementPtr) {
117 if (CE->getNumOperands() == 3 &&
118 cast<Constant>(CE->getOperand(1))->isNullValue() &&
119 isa<ConstantInt>(CE->getOperand(2))) {
120 return isStringValue(CE->getOperand(0));
128 /// getGlobalValue - Return either a direct or cast Global value.
130 static GlobalVariable *getGlobalValue(Value *V) {
131 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
133 } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
134 if (CE->getOpcode() == Instruction::Cast) {
135 return dyn_cast<GlobalVariable>(CE->getOperand(0));
141 /// isGlobalValue - Return true if the given value can be coerced to a
143 static bool isGlobalValue(Value *V) {
144 if (isa<GlobalVariable>(V) || isa<ConstantPointerNull>(V)) {
146 } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
147 if (CE->getOpcode() == Instruction::Cast) {
148 return isa<GlobalVariable>(CE->getOperand(0));
154 /// isUIntOperand - Return true if the ith operand is an unsigned integer.
156 static bool isUIntOperand(GlobalVariable *GV, unsigned i) {
157 // Make sure the GlobalVariable has an initializer.
158 if (!GV->hasInitializer()) return false;
160 // Get the initializer constant.
161 ConstantStruct *CI = dyn_cast<ConstantStruct>(GV->getInitializer());
162 if (!CI) return false;
164 // Check if there is at least i + 1 operands.
165 unsigned N = CI->getNumOperands();
166 if (i >= N) return false;
169 return isa<ConstantUInt>(CI->getOperand(i));
172 //===----------------------------------------------------------------------===//
174 /// TagFromGlobal - Returns the Tag number from a debug info descriptor
176 unsigned DebugInfoDesc::TagFromGlobal(GlobalVariable *GV, bool Checking) {
177 if (Checking && !isUIntOperand(GV, 0)) return DIInvalid;
178 ConstantStruct *CI = cast<ConstantStruct>(GV->getInitializer());
179 Constant *C = CI->getOperand(0);
180 return cast<ConstantUInt>(C)->getValue();
183 /// DescFactory - Create an instance of debug info descriptor based on Tag.
184 /// Return NULL if not a recognized Tag.
185 DebugInfoDesc *DebugInfoDesc::DescFactory(unsigned Tag) {
187 case DI_TAG_compile_unit: return new CompileUnitDesc();
188 case DI_TAG_global_variable: return new GlobalVariableDesc();
189 case DI_TAG_subprogram: return new SubprogramDesc();
195 //===----------------------------------------------------------------------===//
197 /// ApplyToFields - Target the manager to each field of the debug information
199 void DIApplyManager::ApplyToFields(DebugInfoDesc *DD) {
200 DD->ApplyToFields(this);
203 //===----------------------------------------------------------------------===//
204 /// DICountAppMgr - This DIApplyManager counts all the fields in the supplied
205 /// debug the supplied DebugInfoDesc.
206 class DICountAppMgr : public DIApplyManager {
208 unsigned Count; // Running count of fields.
211 DICountAppMgr() : DIApplyManager(), Count(1) {}
214 unsigned getCount() const { return Count; }
216 /// Apply - Count each of the fields.
218 virtual void Apply(int &Field) { ++Count; }
219 virtual void Apply(unsigned &Field) { ++Count; }
220 virtual void Apply(bool &Field) { ++Count; }
221 virtual void Apply(std::string &Field) { ++Count; }
222 virtual void Apply(DebugInfoDesc *&Field) { ++Count; }
223 virtual void Apply(GlobalVariable *&Field) { ++Count; }
226 //===----------------------------------------------------------------------===//
227 /// DIDeserializeAppMgr - This DIApplyManager deserializes all the fields in
228 /// the supplied DebugInfoDesc.
229 class DIDeserializeAppMgr : public DIApplyManager {
231 DIDeserializer &DR; // Active deserializer.
232 unsigned I; // Current operand index.
233 ConstantStruct *CI; // GlobalVariable constant initializer.
236 DIDeserializeAppMgr(DIDeserializer &D, GlobalVariable *GV)
240 , CI(cast<ConstantStruct>(GV->getInitializer()))
243 /// Apply - Set the value of each of the fields.
245 virtual void Apply(int &Field) {
246 Constant *C = CI->getOperand(I++);
247 Field = cast<ConstantSInt>(C)->getValue();
249 virtual void Apply(unsigned &Field) {
250 Constant *C = CI->getOperand(I++);
251 Field = cast<ConstantUInt>(C)->getValue();
253 virtual void Apply(bool &Field) {
254 Constant *C = CI->getOperand(I++);
255 Field = cast<ConstantBool>(C)->getValue();
257 virtual void Apply(std::string &Field) {
258 Constant *C = CI->getOperand(I++);
259 Field = getStringValue(C);
261 virtual void Apply(DebugInfoDesc *&Field) {
262 Constant *C = CI->getOperand(I++);
263 Field = DR.Deserialize(C);
265 virtual void Apply(GlobalVariable *&Field) {
266 Constant *C = CI->getOperand(I++);
267 Field = getGlobalValue(C);
271 //===----------------------------------------------------------------------===//
272 /// DISerializeAppMgr - This DIApplyManager serializes all the fields in
273 /// the supplied DebugInfoDesc.
274 class DISerializeAppMgr : public DIApplyManager {
276 DISerializer &SR; // Active serializer.
277 std::vector<Constant*> &Elements; // Element accumulator.
280 DISerializeAppMgr(DISerializer &S, std::vector<Constant*> &E)
286 /// Apply - Set the value of each of the fields.
288 virtual void Apply(int &Field) {
289 Elements.push_back(ConstantUInt::get(Type::IntTy, Field));
291 virtual void Apply(unsigned &Field) {
292 Elements.push_back(ConstantUInt::get(Type::UIntTy, Field));
294 virtual void Apply(bool &Field) {
295 Elements.push_back(ConstantBool::get(Field));
297 virtual void Apply(std::string &Field) {
298 Elements.push_back(SR.getString(Field));
300 virtual void Apply(DebugInfoDesc *&Field) {
301 GlobalVariable *GV = NULL;
303 // If non-NULL the convert to global.
304 if (Field) GV = SR.Serialize(Field);
306 // FIXME - At some point should use specific type.
307 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
310 // Set to pointer to global.
311 Elements.push_back(ConstantExpr::getCast(GV, EmptyTy));
314 Elements.push_back(ConstantPointerNull::get(EmptyTy));
317 virtual void Apply(GlobalVariable *&Field) {
318 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
319 Elements.push_back(ConstantExpr::getCast(Field, EmptyTy));
323 //===----------------------------------------------------------------------===//
324 /// DIGetTypesAppMgr - This DIApplyManager gathers all the field types in
325 /// the supplied DebugInfoDesc.
326 class DIGetTypesAppMgr : public DIApplyManager {
328 DISerializer &SR; // Active serializer.
329 std::vector<const Type*> &Fields; // Type accumulator.
332 DIGetTypesAppMgr(DISerializer &S, std::vector<const Type*> &F)
338 /// Apply - Set the value of each of the fields.
340 virtual void Apply(int &Field) {
341 Fields.push_back(Type::IntTy);
343 virtual void Apply(unsigned &Field) {
344 Fields.push_back(Type::UIntTy);
346 virtual void Apply(bool &Field) {
347 Fields.push_back(Type::BoolTy);
349 virtual void Apply(std::string &Field) {
350 Fields.push_back(SR.getStrPtrType());
352 virtual void Apply(DebugInfoDesc *&Field) {
353 // FIXME - At some point should use specific type.
354 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
355 Fields.push_back(EmptyTy);
357 virtual void Apply(GlobalVariable *&Field) {
358 const PointerType *EmptyTy = SR.getEmptyStructPtrType();
359 Fields.push_back(EmptyTy);
363 //===----------------------------------------------------------------------===//
364 /// DIVerifyAppMgr - This DIApplyManager verifies all the field types against
365 /// a constant initializer.
366 class DIVerifyAppMgr : public DIApplyManager {
368 DIVerifier &VR; // Active verifier.
369 bool IsValid; // Validity status.
370 unsigned I; // Current operand index.
371 ConstantStruct *CI; // GlobalVariable constant initializer.
374 DIVerifyAppMgr(DIVerifier &V, GlobalVariable *GV)
379 , CI(cast<ConstantStruct>(GV->getInitializer()))
384 bool isValid() const { return IsValid; }
386 /// Apply - Set the value of each of the fields.
388 virtual void Apply(int &Field) {
389 Constant *C = CI->getOperand(I++);
390 IsValid = IsValid && isa<ConstantInt>(C);
392 virtual void Apply(unsigned &Field) {
393 Constant *C = CI->getOperand(I++);
394 IsValid = IsValid && isa<ConstantInt>(C);
396 virtual void Apply(bool &Field) {
397 Constant *C = CI->getOperand(I++);
398 IsValid = IsValid && isa<ConstantBool>(C);
400 virtual void Apply(std::string &Field) {
401 Constant *C = CI->getOperand(I++);
402 IsValid = IsValid && isStringValue(C);
404 virtual void Apply(DebugInfoDesc *&Field) {
405 // FIXME - Prepare the correct descriptor.
406 Constant *C = CI->getOperand(I++);
407 IsValid = IsValid && isGlobalValue(C);
409 virtual void Apply(GlobalVariable *&Field) {
410 Constant *C = CI->getOperand(I++);
411 IsValid = IsValid && isGlobalValue(C);
415 //===----------------------------------------------------------------------===//
417 /// DebugVersionFromGlobal - Returns the version number from a compile unit
419 unsigned CompileUnitDesc::DebugVersionFromGlobal(GlobalVariable *GV,
421 if (Checking && !isUIntOperand(GV, 1)) return DIInvalid;
422 ConstantStruct *CI = cast<ConstantStruct>(GV->getInitializer());
423 Constant *C = CI->getOperand(1);
424 return cast<ConstantUInt>(C)->getValue();
427 /// ApplyToFields - Target the apply manager to the fields of the
429 void CompileUnitDesc::ApplyToFields(DIApplyManager *Mgr) {
430 Mgr->Apply(DebugVersion);
431 Mgr->Apply(Language);
432 Mgr->Apply(FileName);
433 Mgr->Apply(Directory);
434 Mgr->Apply(Producer);
435 Mgr->Apply(TransUnit);
438 /// TypeString - Return a string used to compose globalnames and labels.
440 const char *CompileUnitDesc::TypeString() const {
441 return "compile_unit";
445 void CompileUnitDesc::dump() {
446 std::cerr << TypeString() << " "
447 << "Tag(" << getTag() << "), "
448 << "Language(" << Language << "), "
449 << "FileName(\"" << FileName << "\"), "
450 << "Directory(\"" << Directory << "\"), "
451 << "Producer(\"" << Producer << "\")\n";
455 //===----------------------------------------------------------------------===//
457 /// ApplyToFields - Target the apply manager to the fields of the
458 /// GlobalVariableDesc.
459 void GlobalVariableDesc::ApplyToFields(DIApplyManager *Mgr) {
462 Mgr->Apply(TransUnit);
464 Mgr->Apply(IsStatic);
465 Mgr->Apply(IsDefinition);
469 /// TypeString - Return a string used to compose globalnames and labels.
471 const char *GlobalVariableDesc::TypeString() const {
472 return "global_variable";
476 void GlobalVariableDesc::dump() {
477 std::cerr << TypeString() << " "
478 << "Tag(" << getTag() << "), "
479 << "Name(\"" << Name << "\"), "
480 << "Type(" << TyDesc << "), "
481 << "IsStatic(" << (IsStatic ? "true" : "false") << "), "
482 << "IsDefinition(" << (IsDefinition ? "true" : "false") << "), "
483 << "Global(" << Global << ")\n";
487 //===----------------------------------------------------------------------===//
489 /// ApplyToFields - Target the apply manager to the fields of the
491 void SubprogramDesc::ApplyToFields(DIApplyManager *Mgr) {
494 Mgr->Apply(TransUnit);
496 Mgr->Apply(IsStatic);
497 Mgr->Apply(IsDefinition);
499 // FIXME - Temp variable until restructured.
504 /// TypeString - Return a string used to compose globalnames and labels.
506 const char *SubprogramDesc::TypeString() const {
511 void SubprogramDesc::dump() {
512 std::cerr << TypeString() << " "
513 << "Tag(" << getTag() << "), "
514 << "Name(\"" << Name << "\"), "
515 << "Type(" << TyDesc << "), "
516 << "IsStatic(" << (IsStatic ? "true" : "false") << "), "
517 << "IsDefinition(" << (IsDefinition ? "true" : "false") << ")\n";
521 //===----------------------------------------------------------------------===//
523 DebugInfoDesc *DIDeserializer::Deserialize(Value *V) {
524 return Deserialize(cast<GlobalVariable>(V));
526 DebugInfoDesc *DIDeserializer::Deserialize(GlobalVariable *GV) {
527 // Check to see if it has been already deserialized.
528 DebugInfoDesc *&Slot = GlobalDescs[GV];
529 if (Slot) return Slot;
531 // Get the Tag from the global.
532 unsigned Tag = DebugInfoDesc::TagFromGlobal(GV);
534 // Get the debug version if a compile unit.
535 if (Tag == DI_TAG_compile_unit) {
536 DebugVersion = CompileUnitDesc::DebugVersionFromGlobal(GV);
539 // Create an empty instance of the correct sort.
540 Slot = DebugInfoDesc::DescFactory(Tag);
541 assert(Slot && "Unknown Tag");
543 // Deserialize the fields.
544 DIDeserializeAppMgr DRAM(*this, GV);
545 DRAM.ApplyToFields(Slot);
550 //===----------------------------------------------------------------------===//
552 /// getStrPtrType - Return a "sbyte *" type.
554 const PointerType *DISerializer::getStrPtrType() {
555 // If not already defined.
557 // Construct the pointer to signed bytes.
558 StrPtrTy = PointerType::get(Type::SByteTy);
564 /// getEmptyStructPtrType - Return a "{ }*" type.
566 const PointerType *DISerializer::getEmptyStructPtrType() {
567 // If not already defined.
568 if (!EmptyStructPtrTy) {
569 // Construct the empty structure type.
570 const StructType *EmptyStructTy =
571 StructType::get(std::vector<const Type*>());
572 // Construct the pointer to empty structure type.
573 EmptyStructPtrTy = PointerType::get(EmptyStructTy);
576 return EmptyStructPtrTy;
579 /// getTagType - Return the type describing the specified descriptor (via tag.)
581 const StructType *DISerializer::getTagType(DebugInfoDesc *DD) {
582 // Attempt to get the previously defined type.
583 StructType *&Ty = TagTypes[DD->getTag()];
585 // If not already defined.
587 // Get descriptor type name.
588 const char *TS = DD->TypeString();
590 // Set up fields vector.
591 std::vector<const Type*> Fields;
593 Fields.push_back(Type::UIntTy);
594 // Get types of remaining fields.
595 DIGetTypesAppMgr GTAM(*this, Fields);
596 GTAM.ApplyToFields(DD);
598 // Construct structured type.
599 Ty = StructType::get(Fields);
601 // Construct a name for the type.
602 const std::string Name = std::string("lldb.") + DD->TypeString() + ".type";
604 // Register type name with module.
605 M->addTypeName(Name, Ty);
611 /// getString - Construct the string as constant string global.
613 GlobalVariable *DISerializer::getString(const std::string &String) {
614 // Check string cache for previous edition.
615 GlobalVariable *&Slot = StringCache[String];
616 // return GlobalVariable if previously defined.
617 if (Slot) return Slot;
618 // Construct strings as an llvm constant.
619 Constant *ConstStr = ConstantArray::get(String);
620 // Otherwise create and return a new string global.
621 return Slot = new GlobalVariable(ConstStr->getType(), true,
622 GlobalVariable::InternalLinkage,
626 /// Serialize - Recursively cast the specified descriptor into a GlobalVariable
627 /// so that it can be serialized to a .bc or .ll file.
628 GlobalVariable *DISerializer::Serialize(DebugInfoDesc *DD) {
629 // Check if the DebugInfoDesc is already in the map.
630 GlobalVariable *&Slot = DescGlobals[DD];
632 // See if DebugInfoDesc exists, if so return prior GlobalVariable.
633 if (Slot) return Slot;
635 // Get DebugInfoDesc type Tag.
636 unsigned Tag = DD->getTag();
639 const std::string Name = std::string("lldb.") +
642 // Get the type associated with the Tag.
643 const StructType *Ty = getTagType(DD);
645 // Create the GlobalVariable early to prevent infinite recursion.
646 GlobalVariable *GV = new GlobalVariable(Ty, true,
647 GlobalValue::InternalLinkage,
650 // Insert new GlobalVariable in DescGlobals map.
653 // Set up elements vector
654 std::vector<Constant*> Elements;
656 Elements.push_back(ConstantUInt::get(Type::UIntTy, Tag));
657 // Add remaining fields.
658 DISerializeAppMgr SRAM(*this, Elements);
659 SRAM.ApplyToFields(DD);
661 // Set the globals initializer.
662 GV->setInitializer(ConstantStruct::get(Ty, Elements));
667 //===----------------------------------------------------------------------===//
669 /// markVisited - Return true if the GlobalVariable hase been "seen" before.
670 /// Mark visited otherwise.
671 bool DIVerifier::markVisited(GlobalVariable *GV) {
672 // Check if the GlobalVariable is already in the Visited set.
673 std::set<GlobalVariable *>::iterator VI = Visited.lower_bound(GV);
675 // See if GlobalVariable exists.
676 bool Exists = VI != Visited.end() && *VI == GV;
679 if (!Exists) Visited.insert(VI, GV);
684 /// Verify - Return true if the GlobalVariable appears to be a valid
685 /// serialization of a DebugInfoDesc.
686 bool DIVerifier::Verify(GlobalVariable *GV) {
687 // Check if seen before.
688 if (markVisited(GV)) return true;
691 unsigned Tag = DebugInfoDesc::TagFromGlobal(GV, true);
692 if (Tag == DIInvalid) return false;
694 // If a compile unit we need the debug version.
695 if (Tag == DI_TAG_compile_unit) {
696 DebugVersion = CompileUnitDesc::DebugVersionFromGlobal(GV, true);
697 if (DebugVersion == DIInvalid) return false;
700 // Construct an empty DebugInfoDesc.
701 DebugInfoDesc *DD = DebugInfoDesc::DescFactory(Tag);
702 if (!DD) return false;
704 // Get the initializer constant.
705 ConstantStruct *CI = cast<ConstantStruct>(GV->getInitializer());
707 // Get the operand count.
708 unsigned N = CI->getNumOperands();
710 // Get the field count.
711 unsigned &Slot = Counts[Tag];
713 // Check the operand count to the field count
715 CTAM.ApplyToFields(DD);
716 Slot = CTAM.getCount();
719 // Field count must equal operand count.
725 // Check each field for valid type.
726 DIVerifyAppMgr VRAM(*this, GV);
727 VRAM.ApplyToFields(DD);
729 // Release empty DebugInfoDesc.
732 // Return result of field tests.
733 return VRAM.isValid();
736 //===----------------------------------------------------------------------===//
739 MachineDebugInfo::MachineDebugInfo()
750 MachineDebugInfo::~MachineDebugInfo() {
754 /// doInitialization - Initialize the debug state for a new module.
756 bool MachineDebugInfo::doInitialization() {
760 /// doFinalization - Tear down the debug state after completion of a module.
762 bool MachineDebugInfo::doFinalization() {
766 /// AnalyzeModule - Scan the module for global debug information.
768 void MachineDebugInfo::AnalyzeModule(Module &M) {
771 SetupCompileUnits(M);
774 /// SetupCompileUnits - Set up the unique vector of compile units.
776 void MachineDebugInfo::SetupCompileUnits(Module &M) {
779 // Get vector of all debug compile units.
780 std::vector<GlobalVariable*> Globals =
781 getGlobalVariablesUsing(M, "llvm.dbg.translation_units");
783 // Scan all compile unit globals.
784 for (unsigned i = 0, N = Globals.size(); i < N; ++i) {
785 // Add compile unit to result.
787 static_cast<CompileUnitDesc *>(DR.Deserialize(Globals[i])));
791 /// getCompileUnits - Return a vector of debug compile units.
793 const UniqueVector<CompileUnitDesc *> MachineDebugInfo::getCompileUnits()const{
797 /// getGlobalVariables - Return a vector of debug GlobalVariables.
799 std::vector<GlobalVariableDesc *>
800 MachineDebugInfo::getGlobalVariables(Module &M) {
803 // Get vector of all debug global objects.
804 std::vector<GlobalVariable*> Globals =
805 getGlobalVariablesUsing(M, "llvm.dbg.globals");
807 // Accumulation of GlobalVariables.
808 std::vector<GlobalVariableDesc *> GlobalVariables;
811 for (unsigned i = 0, N = Globals.size(); i < N; ++i) {
812 GlobalVariable *GV = Globals[i];
813 if (DebugInfoDesc::TagFromGlobal(GV, true) == DI_TAG_global_variable) {
814 GlobalVariableDesc *GVD =
815 static_cast<GlobalVariableDesc *>(DR.Deserialize(GV));
816 GlobalVariables.push_back(GVD);
820 return GlobalVariables;