bool cmpDICU(const DICompileUnit & CU1, const DICompileUnit & CU2) { int cmp = CU1.getDirectory().compare(CU2.getDirectory()); if (cmp == 0) cmp = CU1.getFilename().compare(CU2.getFilename()); return cmp >= 0 ? false : true; }
static bool getLocationInfo(const Value *V, std::string &DisplayName, std::string &Type, unsigned &LineNo, std::string &File, std::string &Dir) { DICompileUnit Unit; DIType TypeD; if (GlobalVariable *GV = dyn_cast<GlobalVariable>(const_cast<Value*>(V))) { Value *DIGV = findDbgGlobalDeclare(GV); if (!DIGV) return false; DIGlobalVariable Var(cast<MDNode>(DIGV)); StringRef D = Var.getDisplayName(); if (!D.empty()) DisplayName = D; LineNo = Var.getLineNumber(); Unit = Var.getCompileUnit(); TypeD = Var.getType(); } else if (Function *F = dyn_cast<Function>(const_cast<Value*>(V))){ Value *DIF = findDbgSubprogramDeclare(F); if (!DIF) return false; DISubprogram Var(cast<MDNode>(DIF)); StringRef D = Var.getDisplayName(); if (!D.empty()) DisplayName = D; LineNo = Var.getLineNumber(); Unit = Var.getCompileUnit(); TypeD = Var.getType(); } else { const DbgDeclareInst *DDI = findDbgDeclare(V); if (!DDI) return false; DIVariable Var(cast<MDNode>(DDI->getVariable())); StringRef D = Var.getName(); if (!D.empty()) DisplayName = D; LineNo = Var.getLineNumber(); Unit = Var.getCompileUnit(); TypeD = Var.getType(); } StringRef T = TypeD.getName(); if (!T.empty()) Type = T; StringRef F = Unit.getFilename(); if (!F.empty()) File = F; StringRef D = Unit.getDirectory(); if (!D.empty()) Dir = D; return true; }
std::string GCOVProfiler::mangleName(DICompileUnit CU, const char *NewStem) { if (NamedMDNode *GCov = M->getNamedMetadata("llvm.gcov")) { for (int i = 0, e = GCov->getNumOperands(); i != e; ++i) { MDNode *N = GCov->getOperand(i); if (N->getNumOperands() != 2) continue; MDString *GCovFile = dyn_cast<MDString>(N->getOperand(0)); MDNode *CompileUnit = dyn_cast<MDNode>(N->getOperand(1)); if (!GCovFile || !CompileUnit) continue; if (CompileUnit == CU) { SmallString<128> Filename = GCovFile->getString(); sys::path::replace_extension(Filename, NewStem); return Filename.str(); } } } SmallString<128> Filename = CU.getFilename(); sys::path::replace_extension(Filename, NewStem); return sys::path::filename(Filename.str()); }
bool getLocationInfo(const Value *V, std::string &DisplayName, std::string &Type, unsigned &LineNo, std::string &File, std::string &Dir) { DICompileUnit Unit; DIType TypeD; if (GlobalVariable *GV = dyn_cast<GlobalVariable>(const_cast<Value*>(V))) { Value *DIGV = findDbgGlobalDeclare(GV); if (!DIGV) return false; DIGlobalVariable Var(cast<MDNode>(DIGV)); if (const char *D = Var.getDisplayName()) DisplayName = D; LineNo = Var.getLineNumber(); Unit = Var.getCompileUnit(); TypeD = Var.getType(); } else { const DbgDeclareInst *DDI = findDbgDeclare(V); if (!DDI) return false; DIVariable Var(cast<MDNode>(DDI->getVariable())); if (const char *D = Var.getName()) DisplayName = D; LineNo = Var.getLineNumber(); Unit = Var.getCompileUnit(); TypeD = Var.getType(); } if (const char *T = TypeD.getName()) Type = T; if (const char *F = Unit.getFilename()) File = F; if (const char *D = Unit.getDirectory()) Dir = D; return true; }
void DIEItem::ShowCompileUnit(DetailsView* detailsView, DICompileUnit cu) { detailsView->Add(_("CompileUnit"), toWxStr(cu.getDirectory()) + _("/") + toWxStr(cu.getFilename())); }