1 //===- llvm/Transforms/Instrumentation/DebugIR.h - Interface ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the interface of the DebugIR pass. For most users,
11 // including Instrumentation.h and calling createDebugIRPass() is sufficient and
12 // there is no need to include this file.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_DEBUGIR_H
17 #define LLVM_TRANSFORMS_INSTRUMENTATION_DEBUGIR_H
19 #include "llvm/Pass.h"
23 class DebugIR : public llvm::ModulePass {
24 /// If true, write a source file to disk.
25 bool WriteSourceToDisk;
27 /// Hide certain (non-essential) debug information (only relevant if
28 /// createSource is true.
29 bool HideDebugIntrinsics;
30 bool HideDebugMetadata;
32 /// The location of the source file.
33 std::string Directory;
36 /// True if a temporary file name was generated.
39 /// True if the file name was read from the Module.
45 const char *getPassName() const override { return "DebugIR"; }
47 /// Generate a file on disk to be displayed in a debugger. If Filename and
48 /// Directory are empty, a temporary path will be generated.
49 DebugIR(bool HideDebugIntrinsics, bool HideDebugMetadata,
50 llvm::StringRef Directory, llvm::StringRef Filename)
51 : ModulePass(ID), WriteSourceToDisk(true),
52 HideDebugIntrinsics(HideDebugIntrinsics),
53 HideDebugMetadata(HideDebugMetadata), Directory(Directory),
54 Filename(Filename), GeneratedPath(false), ParsedPath(false) {}
56 /// Modify input in-place; do not generate additional files, and do not hide
57 /// any debug intrinsics/metadata that might be present.
59 : ModulePass(ID), WriteSourceToDisk(false), HideDebugIntrinsics(false),
60 HideDebugMetadata(false), GeneratedPath(false), ParsedPath(false) {}
62 /// Run pass on M and set Path to the source file path in the output module.
63 bool runOnModule(llvm::Module &M, std::string &Path);
64 bool runOnModule(llvm::Module &M) override;
68 /// Returns the concatenated Directory + Filename, without error checking
69 std::string getPath();
71 /// Attempts to read source information from debug information in M, and if
72 /// that fails, from M's identifier. Returns true on success, false otherwise.
73 bool getSourceInfo(const llvm::Module &M);
75 /// Replace the extension of Filename with NewExtension, and return true if
76 /// successful. Return false if extension could not be found or Filename is
78 bool updateExtension(llvm::StringRef NewExtension);
80 /// Generate a temporary filename and open an fd
81 void generateFilename(std::unique_ptr<int> &fd);
83 /// Creates DWARF CU/Subroutine metadata
84 void createDebugInfo(llvm::Module &M,
85 std::unique_ptr<llvm::Module> &DisplayM);
87 /// Returns true if either Directory or Filename is missing, false otherwise.
90 /// Write M to disk, optionally passing in an fd to an open file which is
91 /// closed by this function after writing. If no fd is specified, a new file
92 /// is opened, written, and closed.
93 void writeDebugBitcode(const llvm::Module *M, int *fd = nullptr);
98 #endif // LLVM_TRANSFORMS_INSTRUMENTATION_DEBUGIR_H