LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DebugIR.h
Go to the documentation of this file.
1 //===- llvm/Transforms/Instrumentation/DebugIR.h - Interface ----*- C++ -*-===//
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 // 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.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_DEBUGIR_H
17 #define LLVM_TRANSFORMS_INSTRUMENTATION_DEBUGIR_H
18 
19 #include "llvm/ADT/OwningPtr.h"
20 #include "llvm/Pass.h"
21 
22 namespace llvm {
23 
24 class DebugIR : public llvm::ModulePass {
25  /// If true, write a source file to disk.
26  bool WriteSourceToDisk;
27 
28  /// Hide certain (non-essential) debug information (only relevant if
29  /// createSource is true.
30  bool HideDebugIntrinsics;
31  bool HideDebugMetadata;
32 
33  /// The location of the source file.
34  std::string Directory;
35  std::string Filename;
36 
37  /// True if a temporary file name was generated.
38  bool GeneratedPath;
39 
40  /// True if the file name was read from the Module.
41  bool ParsedPath;
42 
43 public:
44  static char ID;
45 
46  const char *getPassName() const { return "DebugIR"; }
47 
48  /// Generate a file on disk to be displayed in a debugger. If Filename and
49  /// Directory are empty, a temporary path will be generated.
50  DebugIR(bool HideDebugIntrinsics, bool HideDebugMetadata,
51  llvm::StringRef Directory, llvm::StringRef Filename)
52  : ModulePass(ID), WriteSourceToDisk(true),
53  HideDebugIntrinsics(HideDebugIntrinsics),
54  HideDebugMetadata(HideDebugMetadata), Directory(Directory),
55  Filename(Filename), GeneratedPath(false), ParsedPath(false) {}
56 
57  /// Modify input in-place; do not generate additional files, and do not hide
58  /// any debug intrinsics/metadata that might be present.
60  : ModulePass(ID), WriteSourceToDisk(false), HideDebugIntrinsics(false),
61  HideDebugMetadata(false), GeneratedPath(false), ParsedPath(false) {}
62 
63  /// Run pass on M and set Path to the source file path in the output module.
64  bool runOnModule(llvm::Module &M, std::string &Path);
65  bool runOnModule(llvm::Module &M);
66 
67 private:
68 
69  /// Returns the concatenated Directory + Filename, without error checking
70  std::string getPath();
71 
72  /// Attempts to read source information from debug information in M, and if
73  /// that fails, from M's identifier. Returns true on success, false otherwise.
74  bool getSourceInfo(const llvm::Module &M);
75 
76  /// Replace the extension of Filename with NewExtension, and return true if
77  /// successful. Return false if extension could not be found or Filename is
78  /// empty.
79  bool updateExtension(llvm::StringRef NewExtension);
80 
81  /// Generate a temporary filename and open an fd
82  void generateFilename(llvm::OwningPtr<int> &fd);
83 
84  /// Creates DWARF CU/Subroutine metadata
85  void createDebugInfo(llvm::Module &M,
87 
88  /// Returns true if either Directory or Filename is missing, false otherwise.
89  bool isMissingPath();
90 
91  /// Write M to disk, optionally passing in an fd to an open file which is
92  /// closed by this function after writing. If no fd is specified, a new file
93  /// is opened, written, and closed.
94  void writeDebugBitcode(const llvm::Module *M, int *fd = 0);
95 };
96 
97 } // llvm namespace
98 
99 #endif // LLVM_TRANSFORMS_INSTRUMENTATION_DEBUGIR_H
const char * getPassName() const
Definition: DebugIR.h:46
The main container class for the LLVM Intermediate Representation.
Definition: Module.h:112
#define false
Definition: ConvertUTF.c:64
#define true
Definition: ConvertUTF.c:65
bool runOnModule(llvm::Module &M, std::string &Path)
Run pass on M and set Path to the source file path in the output module.
Definition: DebugIR.cpp:600
static char ID
Definition: DebugIR.h:44
DebugIR(bool HideDebugIntrinsics, bool HideDebugMetadata, llvm::StringRef Directory, llvm::StringRef Filename)
Definition: DebugIR.h:50