Beispiel #1
0
void DebugInfoFinder::processScope(DIScope Scope) {
  if (Scope.isType()) {
    DIType Ty(Scope);
    processType(Ty);
    return;
  }
  if (Scope.isCompileUnit()) {
    addCompileUnit(DICompileUnit(Scope));
    return;
  }
  if (Scope.isSubprogram()) {
    processSubprogram(DISubprogram(Scope));
    return;
  }
  if (!addScope(Scope))
    return;
  if (Scope.isLexicalBlock()) {
    DILexicalBlock LB(Scope);
    processScope(LB.getContext());
  } else if (Scope.isLexicalBlockFile()) {
    DILexicalBlockFile LBF = DILexicalBlockFile(Scope);
    processScope(LBF.getScope());
  } else if (Scope.isNameSpace()) {
    DINameSpace NS(Scope);
    processScope(NS.getContext());
  }
}
Beispiel #2
0
void DIEItem::ShowContext(DetailsView* detailsView, DIScope scope) {
  // TODO: Fill out these cases.
  if (scope.isCompileUnit()) {
    DICompileUnit diCompileUnit(scope);
    detailsView->Add(_("ContextType"), _("DICompileUnit"));
    detailsView->Add(_("Context"),
        toWxStr(diCompileUnit.getDirectory()) + _("/") +
        toWxStr(diCompileUnit.getFilename()));
  } else if (scope.isFile()) {
    DIFile diFile(scope);
    detailsView->Add(_("ContextType"), _("DIFile"));
    detailsView->Add(_("Context"),
        toWxStr(diFile.getDirectory()) + _("/") +
        toWxStr(diFile.getFilename()));
  } else if (scope.isNameSpace()) {
    DINameSpace diNameSpace(scope);
    detailsView->Add(_("ContextType"), _("DINameSpace"));
    detailsView->Add(_("Context"), diNameSpace.getName());
  } else if (scope.isSubprogram()) {
    DISubprogram diSubprogram(scope);
    detailsView->Add(_("ContextType"), _("DISubprogram"));
    detailsView->Add(_("Context"), diSubprogram.getName());
  } else if (scope.isLexicalBlock()) {
    detailsView->Add(_("ContextType"), _("DILexicalBlock"));
    // TODO: Implement context name.
    detailsView->Add(_("Context"), _("?{}"));
  } else if (scope.isType()) {
    detailsView->Add(_("ContextType"), _("DIType"));
    detailsView->Add(_("Context"), DITypeToString(DIType(scope)));
  } else {
    detailsView->Add(_("Context"), _("??? [Unknown]"));
  }
}
Beispiel #3
0
/// processLexicalBlock
void DebugInfoFinder::processLexicalBlock(DILexicalBlock LB) {
  DIScope Context = LB.getContext();
  if (Context.isLexicalBlock())
    return processLexicalBlock(DILexicalBlock(Context));
  else
    return processSubprogram(DISubprogram(Context));
}
// Print source location of function, and display name,
// falls back to printing the module's location and the function's LLVM name.
static void printLocation(const llvm::Function *F) {
  unsigned MDDebugKind = F->getParent()->getMDKindID("dbg");
  if (MDDebugKind) {
    // Try to find the function's name and location
    for (Function::const_iterator I=F->begin(),E=F->end();
         I != E; ++I) {
      if (const TerminatorInst *T = I->getTerminator()) {
        if (MDNode *N = T->getMetadata(MDDebugKind)) {
          DILocation Loc(N);
          DIScope Scope = Loc.getScope();
          while (Scope.isLexicalBlock()) {
            DILexicalBlock LB(Scope.getNode());
            Scope = LB.getContext();
          }
          if (Scope.isSubprogram()) {
            DISubprogram SP(Scope.getNode());
            errs() << /*Loc.getDirectory() << "/" << */Loc.getFilename()
              << ": in function '"
              << SP.getDisplayName()
              << "': ";
            return;
          }
        }
      }
    }
  }
  // Fallback to printing module location and function name
  printLocation(F->getParent());
  errs() << "in function '" << F->getName() << "': ";
}
// Print instruction location, falls back to printing function location,
// (and LLVM instruction if specified).
void printLocation(const llvm::Instruction *I, bool fallback) {
  const BasicBlock *BB = I->getParent();
  bool approx = false;
  BasicBlock::const_iterator It = I;
  do {
    BasicBlock::const_iterator ItB = BB->begin();
    while (It != ItB) {
      if (MDNode *N = It->getMetadata("dbg")) {
        DILocation Loc(N);
        errs() << /*Loc.getDirectory() << "/" <<*/ Loc.getFilename()
          << ":" << Loc.getLineNumber();
        if (unsigned Col = Loc.getColumnNumber()) {
          errs() << ":" << Col;
        }
        if (approx)
          errs() << "(?)";
        errs() << ": ";
        DIScope Scope = Loc.getScope();
        while (Scope.isLexicalBlock()) {
          DILexicalBlock LB(Scope.getNode());
          Scope = LB.getContext();
        }
        if (Scope.isSubprogram()) {
          DISubprogram SP(Scope.getNode());
          errs() << "in function '" << SP.getDisplayName() << "': ";
        }
        return;
      }
      approx = true;
      --It;
    }
    BB = BB->getUniquePredecessor();
    if (BB)
      It = BB->end();
  } while (BB);
  printLocation(I->getParent()->getParent());
  if (fallback)
    errs() << *I << ":\n";
}