Remove the default clause from a fully-covering switch
[llvm-core.git] / tools / opt / BreakpointPrinter.cpp
blobe5614ed061e3a05909d386baa398612f9249d5d7
1 //===- BreakpointPrinter.cpp - Breakpoint location printer ----------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief Breakpoint location printer.
12 ///
13 //===----------------------------------------------------------------------===//
14 #include "BreakpointPrinter.h"
15 #include "llvm/ADT/StringSet.h"
16 #include "llvm/IR/DebugInfo.h"
17 #include "llvm/IR/Module.h"
18 #include "llvm/Pass.h"
19 #include "llvm/Support/raw_ostream.h"
21 using namespace llvm;
23 namespace {
25 struct BreakpointPrinter : public ModulePass {
26 raw_ostream &Out;
27 static char ID;
29 BreakpointPrinter(raw_ostream &out) : ModulePass(ID), Out(out) {}
31 void getContextName(const DIScope *Context, std::string &N) {
32 if (auto *NS = dyn_cast<DINamespace>(Context)) {
33 if (!NS->getName().empty()) {
34 getContextName(NS->getScope(), N);
35 N = N + NS->getName().str() + "::";
37 } else if (auto *TY = dyn_cast<DIType>(Context)) {
38 if (!TY->getName().empty()) {
39 getContextName(TY->getScope().resolve(), N);
40 N = N + TY->getName().str() + "::";
45 bool runOnModule(Module &M) override {
46 StringSet<> Processed;
47 if (NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.sp"))
48 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
49 std::string Name;
50 auto *SP = cast_or_null<DISubprogram>(NMD->getOperand(i));
51 if (!SP)
52 continue;
53 getContextName(SP->getScope().resolve(), Name);
54 Name = Name + SP->getName().str();
55 if (!Name.empty() && Processed.insert(Name).second) {
56 Out << Name << "\n";
59 return false;
62 void getAnalysisUsage(AnalysisUsage &AU) const override {
63 AU.setPreservesAll();
67 char BreakpointPrinter::ID = 0;
70 ModulePass *llvm::createBreakpointPrinter(raw_ostream &out) {
71 return new BreakpointPrinter(out);