Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 1 | //===-- ProgramInfo.cpp - Compute and cache info about a program ----------===// |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2 | // |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 7 | // |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 9 | // |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 10 | // This file implements the ProgramInfo and related classes, by sorting through |
| 11 | // the loaded Module. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "llvm/Debugger/ProgramInfo.h" |
| 16 | #include "llvm/Constants.h" |
Evan Cheng | 0ff39b3 | 2008-06-30 07:31:25 +0000 | [diff] [blame] | 17 | #include "llvm/Analysis/ValueTracking.h" |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 18 | #include "llvm/DerivedTypes.h" |
| 19 | #include "llvm/Intrinsics.h" |
Jim Laskey | 43970fe | 2006-03-23 18:06:46 +0000 | [diff] [blame] | 20 | #include "llvm/IntrinsicInst.h" |
Chris Lattner | 4ab78e0 | 2004-07-29 17:15:38 +0000 | [diff] [blame] | 21 | #include "llvm/Instructions.h" |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 22 | #include "llvm/Module.h" |
| 23 | #include "llvm/Debugger/SourceFile.h" |
| 24 | #include "llvm/Debugger/SourceLanguage.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 25 | #include "llvm/Support/SlowOperationInformer.h" |
| 26 | #include "llvm/ADT/STLExtras.h" |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 27 | using namespace llvm; |
| 28 | |
| 29 | /// getGlobalVariablesUsing - Return all of the global variables which have the |
| 30 | /// specified value in their initializer somewhere. |
| 31 | static void getGlobalVariablesUsing(Value *V, |
| 32 | std::vector<GlobalVariable*> &Found) { |
| 33 | for (Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I) { |
| 34 | if (GlobalVariable *GV = dyn_cast<GlobalVariable>(*I)) |
| 35 | Found.push_back(GV); |
| 36 | else if (Constant *C = dyn_cast<Constant>(*I)) |
| 37 | getGlobalVariablesUsing(C, Found); |
| 38 | } |
| 39 | } |
| 40 | |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 41 | /// getNextStopPoint - Follow the def-use chains of the specified LLVM value, |
| 42 | /// traversing the use chains until we get to a stoppoint. When we do, return |
| 43 | /// the source location of the stoppoint. If we don't find a stoppoint, return |
| 44 | /// null. |
| 45 | static const GlobalVariable *getNextStopPoint(const Value *V, unsigned &LineNo, |
| 46 | unsigned &ColNo) { |
| 47 | // The use-def chains can fork. As such, we pick the lowest numbered one we |
| 48 | // find. |
| 49 | const GlobalVariable *LastDesc = 0; |
| 50 | unsigned LastLineNo = ~0; |
| 51 | unsigned LastColNo = ~0; |
| 52 | |
| 53 | for (Value::use_const_iterator UI = V->use_begin(), E = V->use_end(); |
| 54 | UI != E; ++UI) { |
| 55 | bool ShouldRecurse = true; |
| 56 | if (cast<Instruction>(*UI)->getOpcode() == Instruction::PHI) { |
| 57 | // Infinite loops == bad, ignore PHI nodes. |
| 58 | ShouldRecurse = false; |
| 59 | } else if (const CallInst *CI = dyn_cast<CallInst>(*UI)) { |
Jim Laskey | 43970fe | 2006-03-23 18:06:46 +0000 | [diff] [blame] | 60 | |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 61 | // If we found a stop point, check to see if it is earlier than what we |
| 62 | // already have. If so, remember it. |
Reid Spencer | 3ed469c | 2006-11-02 20:25:50 +0000 | [diff] [blame] | 63 | if (CI->getCalledFunction()) |
Jim Laskey | 43970fe | 2006-03-23 18:06:46 +0000 | [diff] [blame] | 64 | if (const DbgStopPointInst *SPI = dyn_cast<DbgStopPointInst>(CI)) { |
| 65 | unsigned CurLineNo = SPI->getLine(); |
| 66 | unsigned CurColNo = SPI->getColumn(); |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 67 | const GlobalVariable *CurDesc = 0; |
Jim Laskey | 43970fe | 2006-03-23 18:06:46 +0000 | [diff] [blame] | 68 | const Value *Op = SPI->getContext(); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 69 | |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 70 | if ((CurDesc = dyn_cast<GlobalVariable>(Op)) && |
| 71 | (LineNo < LastLineNo || |
| 72 | (LineNo == LastLineNo && ColNo < LastColNo))) { |
| 73 | LastDesc = CurDesc; |
| 74 | LastLineNo = CurLineNo; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 75 | LastColNo = CurColNo; |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 76 | } |
| 77 | ShouldRecurse = false; |
| 78 | } |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | // If this is not a phi node or a stopping point, recursively scan the users |
| 82 | // of this instruction to skip over region.begin's and the like. |
| 83 | if (ShouldRecurse) { |
| 84 | unsigned CurLineNo, CurColNo; |
| 85 | if (const GlobalVariable *GV = getNextStopPoint(*UI, CurLineNo,CurColNo)){ |
| 86 | if (LineNo < LastLineNo || (LineNo == LastLineNo && ColNo < LastColNo)){ |
| 87 | LastDesc = GV; |
| 88 | LastLineNo = CurLineNo; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 89 | LastColNo = CurColNo; |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 90 | } |
| 91 | } |
| 92 | } |
| 93 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 94 | |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 95 | if (LastDesc) { |
| 96 | LineNo = LastLineNo != ~0U ? LastLineNo : 0; |
| 97 | ColNo = LastColNo != ~0U ? LastColNo : 0; |
| 98 | } |
| 99 | return LastDesc; |
| 100 | } |
| 101 | |
| 102 | |
| 103 | //===----------------------------------------------------------------------===// |
| 104 | // SourceFileInfo implementation |
| 105 | // |
| 106 | |
| 107 | SourceFileInfo::SourceFileInfo(const GlobalVariable *Desc, |
| 108 | const SourceLanguage &Lang) |
| 109 | : Language(&Lang), Descriptor(Desc) { |
| 110 | Version = 0; |
| 111 | SourceText = 0; |
| 112 | |
| 113 | if (Desc && Desc->hasInitializer()) |
| 114 | if (ConstantStruct *CS = dyn_cast<ConstantStruct>(Desc->getInitializer())) |
| 115 | if (CS->getNumOperands() > 4) { |
Reid Spencer | b83eb64 | 2006-10-20 07:07:24 +0000 | [diff] [blame] | 116 | if (ConstantInt *CUI = dyn_cast<ConstantInt>(CS->getOperand(1))) |
| 117 | Version = CUI->getZExtValue(); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 118 | |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 119 | if (!GetConstantStringInfo(CS->getOperand(3), BaseName)) |
| 120 | BaseName = ""; |
| 121 | if (!GetConstantStringInfo(CS->getOperand(4), Directory)) |
| 122 | Directory = ""; |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
| 126 | SourceFileInfo::~SourceFileInfo() { |
| 127 | delete SourceText; |
| 128 | } |
| 129 | |
| 130 | SourceFile &SourceFileInfo::getSourceText() const { |
| 131 | // FIXME: this should take into account the source search directories! |
Reid Spencer | 663601c | 2004-12-13 02:59:15 +0000 | [diff] [blame] | 132 | if (SourceText == 0) { // Read the file in if we haven't already. |
| 133 | sys::Path tmpPath; |
| 134 | if (!Directory.empty()) |
Reid Spencer | dd04df0 | 2005-07-07 23:21:43 +0000 | [diff] [blame] | 135 | tmpPath.set(Directory); |
| 136 | tmpPath.appendComponent(BaseName); |
Reid Spencer | c7f0832 | 2005-07-07 18:21:42 +0000 | [diff] [blame] | 137 | if (tmpPath.canRead()) |
Reid Spencer | 663601c | 2004-12-13 02:59:15 +0000 | [diff] [blame] | 138 | SourceText = new SourceFile(tmpPath.toString(), Descriptor); |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 139 | else |
| 140 | SourceText = new SourceFile(BaseName, Descriptor); |
Reid Spencer | 663601c | 2004-12-13 02:59:15 +0000 | [diff] [blame] | 141 | } |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 142 | return *SourceText; |
| 143 | } |
| 144 | |
| 145 | |
| 146 | //===----------------------------------------------------------------------===// |
| 147 | // SourceFunctionInfo implementation |
| 148 | // |
| 149 | SourceFunctionInfo::SourceFunctionInfo(ProgramInfo &PI, |
| 150 | const GlobalVariable *Desc) |
| 151 | : Descriptor(Desc) { |
| 152 | LineNo = ColNo = 0; |
| 153 | if (Desc && Desc->hasInitializer()) |
| 154 | if (ConstantStruct *CS = dyn_cast<ConstantStruct>(Desc->getInitializer())) |
| 155 | if (CS->getNumOperands() > 2) { |
| 156 | // Entry #1 is the file descriptor. |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 157 | if (const GlobalVariable *GV = |
Reid Spencer | 518310c | 2004-07-18 00:44:37 +0000 | [diff] [blame] | 158 | dyn_cast<GlobalVariable>(CS->getOperand(1))) |
| 159 | SourceFile = &PI.getSourceFile(GV); |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 160 | |
| 161 | // Entry #2 is the function name. |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 162 | if (!GetConstantStringInfo(CS->getOperand(2), Name)) |
| 163 | Name = ""; |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | |
| 167 | /// getSourceLocation - This method returns the location of the first stopping |
| 168 | /// point in the function. |
| 169 | void SourceFunctionInfo::getSourceLocation(unsigned &RetLineNo, |
| 170 | unsigned &RetColNo) const { |
| 171 | // If we haven't computed this yet... |
| 172 | if (!LineNo) { |
| 173 | // Look at all of the users of the function descriptor, looking for calls to |
| 174 | // %llvm.dbg.func.start. |
| 175 | for (Value::use_const_iterator UI = Descriptor->use_begin(), |
| 176 | E = Descriptor->use_end(); UI != E; ++UI) |
| 177 | if (const CallInst *CI = dyn_cast<CallInst>(*UI)) |
| 178 | if (const Function *F = CI->getCalledFunction()) |
| 179 | if (F->getIntrinsicID() == Intrinsic::dbg_func_start) { |
| 180 | // We found the start of the function. Check to see if there are |
| 181 | // any stop points on the use-list of the function start. |
| 182 | const GlobalVariable *SD = getNextStopPoint(CI, LineNo, ColNo); |
| 183 | if (SD) { // We found the first stop point! |
| 184 | // This is just a sanity check. |
| 185 | if (getSourceFile().getDescriptor() != SD) |
Chris Lattner | d9ea85a | 2009-08-23 08:43:55 +0000 | [diff] [blame] | 186 | outs() << "WARNING: first line of function is not in the" |
Bill Wendling | bcd2498 | 2006-12-07 20:28:15 +0000 | [diff] [blame] | 187 | << " file that the function descriptor claims it is in.\n"; |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 188 | break; |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | RetLineNo = LineNo; RetColNo = ColNo; |
| 193 | } |
| 194 | |
| 195 | //===----------------------------------------------------------------------===// |
| 196 | // ProgramInfo implementation |
| 197 | // |
| 198 | |
Reid Spencer | 9d88d1a | 2004-12-13 17:01:53 +0000 | [diff] [blame] | 199 | ProgramInfo::ProgramInfo(Module *m) : M(m), ProgramTimeStamp(0,0) { |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 200 | assert(M && "Cannot create program information with a null module!"); |
Reid Spencer | e281259 | 2007-04-08 20:10:14 +0000 | [diff] [blame] | 201 | sys::PathWithStatus ModPath(M->getModuleIdentifier()); |
| 202 | const sys::FileStatus *Stat = ModPath.getFileStatus(); |
Reid Spencer | 8475ec0 | 2007-03-29 19:05:44 +0000 | [diff] [blame] | 203 | if (Stat) |
| 204 | ProgramTimeStamp = Stat->getTimestamp(); |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 205 | |
| 206 | SourceFilesIsComplete = false; |
| 207 | SourceFunctionsIsComplete = false; |
| 208 | } |
| 209 | |
| 210 | ProgramInfo::~ProgramInfo() { |
| 211 | // Delete cached information about source program objects... |
| 212 | for (std::map<const GlobalVariable*, SourceFileInfo*>::iterator |
| 213 | I = SourceFiles.begin(), E = SourceFiles.end(); I != E; ++I) |
| 214 | delete I->second; |
| 215 | for (std::map<const GlobalVariable*, SourceFunctionInfo*>::iterator |
| 216 | I = SourceFunctions.begin(), E = SourceFunctions.end(); I != E; ++I) |
| 217 | delete I->second; |
| 218 | |
| 219 | // Delete the source language caches. |
| 220 | for (unsigned i = 0, e = LanguageCaches.size(); i != e; ++i) |
| 221 | delete LanguageCaches[i].second; |
| 222 | } |
| 223 | |
| 224 | |
| 225 | //===----------------------------------------------------------------------===// |
| 226 | // SourceFileInfo tracking... |
| 227 | // |
| 228 | |
| 229 | /// getSourceFile - Return source file information for the specified source file |
| 230 | /// descriptor object, adding it to the collection as needed. This method |
| 231 | /// always succeeds (is unambiguous), and is always efficient. |
| 232 | /// |
| 233 | const SourceFileInfo & |
| 234 | ProgramInfo::getSourceFile(const GlobalVariable *Desc) { |
| 235 | SourceFileInfo *&Result = SourceFiles[Desc]; |
| 236 | if (Result) return *Result; |
| 237 | |
| 238 | // Figure out what language this source file comes from... |
| 239 | unsigned LangID = 0; // Zero is unknown language |
| 240 | if (Desc && Desc->hasInitializer()) |
| 241 | if (ConstantStruct *CS = dyn_cast<ConstantStruct>(Desc->getInitializer())) |
| 242 | if (CS->getNumOperands() > 2) |
Reid Spencer | b83eb64 | 2006-10-20 07:07:24 +0000 | [diff] [blame] | 243 | if (ConstantInt *CUI = dyn_cast<ConstantInt>(CS->getOperand(2))) |
| 244 | LangID = CUI->getZExtValue(); |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 245 | |
| 246 | const SourceLanguage &Lang = SourceLanguage::get(LangID); |
| 247 | SourceFileInfo *New = Lang.createSourceFileInfo(Desc, *this); |
| 248 | |
| 249 | // FIXME: this should check to see if there is already a Filename/WorkingDir |
| 250 | // pair that matches this one. If so, we shouldn't create the duplicate! |
| 251 | // |
| 252 | SourceFileIndex.insert(std::make_pair(New->getBaseName(), New)); |
| 253 | return *(Result = New); |
| 254 | } |
| 255 | |
| 256 | |
| 257 | /// getSourceFiles - Index all of the source files in the program and return |
| 258 | /// a mapping of it. This information is lazily computed the first time |
| 259 | /// that it is requested. Since this information can take a long time to |
| 260 | /// compute, the user is given a chance to cancel it. If this occurs, an |
| 261 | /// exception is thrown. |
| 262 | const std::map<const GlobalVariable*, SourceFileInfo*> & |
| 263 | ProgramInfo::getSourceFiles(bool RequiresCompleteMap) { |
| 264 | // If we have a fully populated map, or if the client doesn't need one, just |
| 265 | // return what we have. |
| 266 | if (SourceFilesIsComplete || !RequiresCompleteMap) |
| 267 | return SourceFiles; |
| 268 | |
| 269 | // Ok, all of the source file descriptors (compile_unit in dwarf terms), |
| 270 | // should be on the use list of the llvm.dbg.translation_units global. |
| 271 | // |
| 272 | GlobalVariable *Units = |
Owen Anderson | d7f2a6c | 2009-08-05 23:16:16 +0000 | [diff] [blame] | 273 | M->getGlobalVariable("llvm.dbg.translation_units", |
| 274 | StructType::get(M->getContext())); |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 275 | if (Units == 0) |
| 276 | throw "Program contains no debugging information!"; |
| 277 | |
| 278 | std::vector<GlobalVariable*> TranslationUnits; |
| 279 | getGlobalVariablesUsing(Units, TranslationUnits); |
| 280 | |
| 281 | SlowOperationInformer SOI("building source files index"); |
| 282 | |
| 283 | // Loop over all of the translation units found, building the SourceFiles |
| 284 | // mapping. |
| 285 | for (unsigned i = 0, e = TranslationUnits.size(); i != e; ++i) { |
| 286 | getSourceFile(TranslationUnits[i]); |
Chris Lattner | 148f440 | 2006-07-06 22:34:06 +0000 | [diff] [blame] | 287 | if (SOI.progress(i+1, e)) |
| 288 | throw "While building source files index, operation cancelled."; |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | // Ok, if we got this far, then we indexed the whole program. |
| 292 | SourceFilesIsComplete = true; |
| 293 | return SourceFiles; |
| 294 | } |
| 295 | |
| 296 | /// getSourceFile - Look up the file with the specified name. If there is |
| 297 | /// more than one match for the specified filename, prompt the user to pick |
| 298 | /// one. If there is no source file that matches the specified name, throw |
| 299 | /// an exception indicating that we can't find the file. Otherwise, return |
| 300 | /// the file information for that file. |
| 301 | const SourceFileInfo &ProgramInfo::getSourceFile(const std::string &Filename) { |
| 302 | std::multimap<std::string, SourceFileInfo*>::const_iterator Start, End; |
| 303 | getSourceFiles(); |
| 304 | tie(Start, End) = SourceFileIndex.equal_range(Filename); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 305 | |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 306 | if (Start == End) throw "Could not find source file '" + Filename + "'!"; |
| 307 | const SourceFileInfo &SFI = *Start->second; |
| 308 | ++Start; |
| 309 | if (Start == End) return SFI; |
| 310 | |
| 311 | throw "FIXME: Multiple source files with the same name not implemented!"; |
| 312 | } |
| 313 | |
| 314 | |
| 315 | //===----------------------------------------------------------------------===// |
| 316 | // SourceFunctionInfo tracking... |
| 317 | // |
| 318 | |
| 319 | |
| 320 | /// getFunction - Return function information for the specified function |
| 321 | /// descriptor object, adding it to the collection as needed. This method |
| 322 | /// always succeeds (is unambiguous), and is always efficient. |
| 323 | /// |
| 324 | const SourceFunctionInfo & |
| 325 | ProgramInfo::getFunction(const GlobalVariable *Desc) { |
| 326 | SourceFunctionInfo *&Result = SourceFunctions[Desc]; |
| 327 | if (Result) return *Result; |
| 328 | |
| 329 | // Figure out what language this function comes from... |
| 330 | const GlobalVariable *SourceFileDesc = 0; |
| 331 | if (Desc && Desc->hasInitializer()) |
| 332 | if (ConstantStruct *CS = dyn_cast<ConstantStruct>(Desc->getInitializer())) |
| 333 | if (CS->getNumOperands() > 0) |
Reid Spencer | 518310c | 2004-07-18 00:44:37 +0000 | [diff] [blame] | 334 | if (const GlobalVariable *GV = |
| 335 | dyn_cast<GlobalVariable>(CS->getOperand(1))) |
| 336 | SourceFileDesc = GV; |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 337 | |
| 338 | const SourceLanguage &Lang = getSourceFile(SourceFileDesc).getLanguage(); |
| 339 | return *(Result = Lang.createSourceFunctionInfo(Desc, *this)); |
| 340 | } |
| 341 | |
| 342 | |
| 343 | // getSourceFunctions - Index all of the functions in the program and return |
| 344 | // them. This information is lazily computed the first time that it is |
| 345 | // requested. Since this information can take a long time to compute, the user |
| 346 | // is given a chance to cancel it. If this occurs, an exception is thrown. |
| 347 | const std::map<const GlobalVariable*, SourceFunctionInfo*> & |
| 348 | ProgramInfo::getSourceFunctions(bool RequiresCompleteMap) { |
| 349 | if (SourceFunctionsIsComplete || !RequiresCompleteMap) |
| 350 | return SourceFunctions; |
| 351 | |
| 352 | // Ok, all of the source function descriptors (subprogram in dwarf terms), |
| 353 | // should be on the use list of the llvm.dbg.translation_units global. |
| 354 | // |
| 355 | GlobalVariable *Units = |
Owen Anderson | d7f2a6c | 2009-08-05 23:16:16 +0000 | [diff] [blame] | 356 | M->getGlobalVariable("llvm.dbg.globals", StructType::get(M->getContext())); |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 357 | if (Units == 0) |
| 358 | throw "Program contains no debugging information!"; |
| 359 | |
| 360 | std::vector<GlobalVariable*> Functions; |
| 361 | getGlobalVariablesUsing(Units, Functions); |
| 362 | |
| 363 | SlowOperationInformer SOI("building functions index"); |
| 364 | |
| 365 | // Loop over all of the functions found, building the SourceFunctions mapping. |
| 366 | for (unsigned i = 0, e = Functions.size(); i != e; ++i) { |
| 367 | getFunction(Functions[i]); |
Chris Lattner | 148f440 | 2006-07-06 22:34:06 +0000 | [diff] [blame] | 368 | if (SOI.progress(i+1, e)) |
| 369 | throw "While functions index, operation cancelled."; |
Chris Lattner | 2eacf26 | 2004-01-05 05:25:10 +0000 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | // Ok, if we got this far, then we indexed the whole program. |
| 373 | SourceFunctionsIsComplete = true; |
| 374 | return SourceFunctions; |
| 375 | } |