[LLVM][Alignment] Introduce Alignment In Attributes
[llvm-core.git] / tools / opt / BreakpointPrinter.cpp
bloba57a8c43c264d73f3804354c487e6b54b684b180
1 //===- BreakpointPrinter.cpp - Breakpoint location printer ----------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// Breakpoint location printer.
11 ///
12 //===----------------------------------------------------------------------===//
13 #include "BreakpointPrinter.h"
14 #include "llvm/ADT/StringSet.h"
15 #include "llvm/IR/DebugInfo.h"
16 #include "llvm/IR/Module.h"
17 #include "llvm/Pass.h"
18 #include "llvm/Support/raw_ostream.h"
20 using namespace llvm;
22 namespace {
24 struct BreakpointPrinter : public ModulePass {
25 raw_ostream &Out;
26 static char ID;
28 BreakpointPrinter(raw_ostream &out) : ModulePass(ID), Out(out) {}
30 void getContextName(const DIScope *Context, std::string &N) {
31 if (auto *NS = dyn_cast<DINamespace>(Context)) {
32 if (!NS->getName().empty()) {
33 getContextName(NS->getScope(), N);
34 N = N + NS->getName().str() + "::";
36 } else if (auto *TY = dyn_cast<DIType>(Context)) {
37 if (!TY->getName().empty()) {
38 getContextName(TY->getScope(), N);
39 N = N + TY->getName().str() + "::";
44 bool runOnModule(Module &M) override {
45 StringSet<> Processed;
46 if (NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.sp"))
47 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
48 std::string Name;
49 auto *SP = cast_or_null<DISubprogram>(NMD->getOperand(i));
50 if (!SP)
51 continue;
52 getContextName(SP->getScope(), Name);
53 Name = Name + SP->getName().str();
54 if (!Name.empty() && Processed.insert(Name).second) {
55 Out << Name << "\n";
58 return false;
61 void getAnalysisUsage(AnalysisUsage &AU) const override {
62 AU.setPreservesAll();
66 char BreakpointPrinter::ID = 0;
69 ModulePass *llvm::createBreakpointPrinter(raw_ostream &out) {
70 return new BreakpointPrinter(out);