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