LLVM API Documentation
00001 //===- llvm/Transforms/Instrumentation/DebugIR.h - Interface ----*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the interface of the DebugIR pass. For most users, 00011 // including Instrumentation.h and calling createDebugIRPass() is sufficient and 00012 // there is no need to include this file. 00013 // 00014 //===----------------------------------------------------------------------===// 00015 00016 #ifndef LLVM_LIB_TRANSFORMS_INSTRUMENTATION_DEBUGIR_H 00017 #define LLVM_LIB_TRANSFORMS_INSTRUMENTATION_DEBUGIR_H 00018 00019 #include "llvm/Pass.h" 00020 00021 namespace llvm { 00022 00023 class DebugIR : public llvm::ModulePass { 00024 /// If true, write a source file to disk. 00025 bool WriteSourceToDisk; 00026 00027 /// Hide certain (non-essential) debug information (only relevant if 00028 /// createSource is true. 00029 bool HideDebugIntrinsics; 00030 bool HideDebugMetadata; 00031 00032 /// The location of the source file. 00033 std::string Directory; 00034 std::string Filename; 00035 00036 /// True if a temporary file name was generated. 00037 bool GeneratedPath; 00038 00039 /// True if the file name was read from the Module. 00040 bool ParsedPath; 00041 00042 public: 00043 static char ID; 00044 00045 const char *getPassName() const override { return "DebugIR"; } 00046 00047 /// Generate a file on disk to be displayed in a debugger. If Filename and 00048 /// Directory are empty, a temporary path will be generated. 00049 DebugIR(bool HideDebugIntrinsics, bool HideDebugMetadata, 00050 llvm::StringRef Directory, llvm::StringRef Filename) 00051 : ModulePass(ID), WriteSourceToDisk(true), 00052 HideDebugIntrinsics(HideDebugIntrinsics), 00053 HideDebugMetadata(HideDebugMetadata), Directory(Directory), 00054 Filename(Filename), GeneratedPath(false), ParsedPath(false) {} 00055 00056 /// Modify input in-place; do not generate additional files, and do not hide 00057 /// any debug intrinsics/metadata that might be present. 00058 DebugIR() 00059 : ModulePass(ID), WriteSourceToDisk(false), HideDebugIntrinsics(false), 00060 HideDebugMetadata(false), GeneratedPath(false), ParsedPath(false) {} 00061 00062 /// Run pass on M and set Path to the source file path in the output module. 00063 bool runOnModule(llvm::Module &M, std::string &Path); 00064 bool runOnModule(llvm::Module &M) override; 00065 00066 private: 00067 00068 /// Returns the concatenated Directory + Filename, without error checking 00069 std::string getPath(); 00070 00071 /// Attempts to read source information from debug information in M, and if 00072 /// that fails, from M's identifier. Returns true on success, false otherwise. 00073 bool getSourceInfo(const llvm::Module &M); 00074 00075 /// Replace the extension of Filename with NewExtension, and return true if 00076 /// successful. Return false if extension could not be found or Filename is 00077 /// empty. 00078 bool updateExtension(llvm::StringRef NewExtension); 00079 00080 /// Generate a temporary filename and open an fd 00081 void generateFilename(std::unique_ptr<int> &fd); 00082 00083 /// Creates DWARF CU/Subroutine metadata 00084 void createDebugInfo(llvm::Module &M, 00085 std::unique_ptr<llvm::Module> &DisplayM); 00086 00087 /// Returns true if either Directory or Filename is missing, false otherwise. 00088 bool isMissingPath(); 00089 00090 /// Write M to disk, optionally passing in an fd to an open file which is 00091 /// closed by this function after writing. If no fd is specified, a new file 00092 /// is opened, written, and closed. 00093 void writeDebugBitcode(const llvm::Module *M, int *fd = nullptr); 00094 }; 00095 00096 } // llvm namespace 00097 00098 #endif