| LEFT | RIGHT |
| 1 //===-- JITDebugRegisterer.h - Register debug symbols for JIT -------------===// | 1 //===-- JITDebugRegisterer.h - Register debug symbols for JIT -------------===// |
| 2 // | 2 // |
| 3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // This file defines a JITDebugRegisterer object that is used by the JIT to | 10 // This file defines a JITDebugRegisterer object that is used by the JIT to |
| 11 // register debug info with debuggers like GDB. | 11 // register debug info with debuggers like GDB. |
| 12 // | 12 // |
| 13 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
| 14 | 14 |
| 15 #ifndef LLVM_EXECUTION_ENGINE_JIT_DEBUGREGISTERER_H | 15 #ifndef LLVM_EXECUTION_ENGINE_JIT_DEBUGREGISTERER_H |
| 16 #define LLVM_EXECUTION_ENGINE_JIT_DEBUGREGISTERER_H | 16 #define LLVM_EXECUTION_ENGINE_JIT_DEBUGREGISTERER_H |
| 17 | 17 |
| 18 #include "llvm/ADT/DenseMap.h" | 18 #include "llvm/ADT/DenseMap.h" |
| 19 #include "llvm/Support/DataTypes.h" | 19 #include "llvm/Support/DataTypes.h" |
| 20 #include "llvm/System/Path.h" | 20 #include <string> |
| 21 |
| 22 // This must be kept in sync with gdb/gdb/jit.h . |
| 23 extern "C" { |
| 24 |
| 25 typedef enum { |
| 26 JIT_NOACTION = 0, |
| 27 JIT_REGISTER_FN, |
| 28 JIT_UNREGISTER_FN |
| 29 } jit_actions_t; |
| 30 |
| 31 struct jit_code_entry { |
| 32 struct jit_code_entry *next_entry; |
| 33 struct jit_code_entry *prev_entry; |
| 34 const char *symfile_addr; |
| 35 uint64_t symfile_size; |
| 36 }; |
| 37 |
| 38 struct jit_descriptor { |
| 39 uint32_t version; |
| 40 // This should be jit_actions_t, but we want to be specific about the |
| 41 // bit-width. |
| 42 uint32_t action_flag; |
| 43 struct jit_code_entry *relevant_entry; |
| 44 struct jit_code_entry *first_entry; |
| 45 }; |
| 46 |
| 47 } |
| 21 | 48 |
| 22 namespace llvm { | 49 namespace llvm { |
| 23 | 50 |
| 24 struct ELFSection; | 51 struct ELFSection; |
| 25 class Function; | 52 class Function; |
| 26 class TargetMachine; | 53 class TargetMachine; |
| 27 | 54 |
| 28 | 55 |
| 29 /// This class encapsulates information we want to send to the debugger. | 56 /// This class encapsulates information we want to send to the debugger. |
| 30 /// | 57 /// |
| 31 struct DebugInfo { | 58 struct DebugInfo { |
| 32 uint8_t *FnStart; | 59 uint8_t *FnStart; |
| 33 uint8_t *FnEnd; | 60 uint8_t *FnEnd; |
| 34 uint8_t *EhStart; | 61 uint8_t *EhStart; |
| 35 uint8_t *EhEnd; | 62 uint8_t *EhEnd; |
| 36 | 63 |
| 37 DebugInfo() : FnStart(0), FnEnd(0), EhStart(0), EhEnd(0) {} | 64 DebugInfo() : FnStart(0), FnEnd(0), EhStart(0), EhEnd(0) {} |
| 38 }; | 65 }; |
| 39 | 66 |
| 67 typedef DenseMap< const Function*, std::pair<std::string, jit_code_entry*> > |
| 68 RegisteredFunctionsMap; |
| 40 | 69 |
| 41 /// This class registers debug info for JITed code with an attached debugger. | 70 /// This class registers debug info for JITed code with an attached debugger. |
| 42 /// Without proper debug info, GDB can't do things like source level debugging | 71 /// Without proper debug info, GDB can't do things like source level debugging |
| 43 /// or even produce a proper stack trace on linux-x86_64. To use this class, | 72 /// or even produce a proper stack trace on linux-x86_64. To use this class, |
| 44 /// whenever a function is JITed, create a DebugInfo struct and pass it to the | 73 /// whenever a function is JITed, create a DebugInfo struct and pass it to the |
| 45 /// RegisterFunction method. The method will then do whatever is necessary to | 74 /// RegisterFunction method. The method will then do whatever is necessary to |
| 46 /// inform the debugger about the JITed function. | 75 /// inform the debugger about the JITed function. |
| 47 class JITDebugRegisterer { | 76 class JITDebugRegisterer { |
| 48 | 77 |
| 49 TargetMachine &TM; | 78 TargetMachine &TM; |
| 50 | 79 |
| 51 /// FnMap - A map of functions that have been registered to the associated | 80 /// FnMap - A map of functions that have been registered to the associated |
| 52 /// temporary files. Used for cleanup. | 81 /// temporary files. Used for cleanup. |
| 53 DenseMap<const Function*, sys::Path> FnMap; | 82 RegisteredFunctionsMap FnMap; |
| 54 | 83 |
| 55 /// TmpDir - The temporary directory where all our symbol files are stored. | 84 /// MakeELF - Builds the ELF file in memory and returns a std::string that |
| 56 /// | 85 /// contains the ELF. |
| 57 const sys::Path TmpDir; | 86 std::string MakeELF(const Function *F, DebugInfo &I); |
| 58 | 87 |
| 59 /// MakeFilename - Make a filename in the system's temporary directory for | 88 public: |
| 60 /// the ELF. | |
| 61 sys::Path MakeFilename(const Function *F, uint8_t *FnStart); | |
| 62 | |
| 63 public: | |
| 64 JITDebugRegisterer(TargetMachine &tm); | 89 JITDebugRegisterer(TargetMachine &tm); |
| 65 | 90 |
| 66 /// ~JITDebugRegisterer - Cleans up all temporary files. | 91 /// ~JITDebugRegisterer - Unregisters all code and frees symbol files. |
| 67 /// | 92 /// |
| 68 ~JITDebugRegisterer(); | 93 ~JITDebugRegisterer(); |
| 69 | 94 |
| 70 /// RegisterFunction - Register debug info for the given function with an | 95 /// RegisterFunction - Register debug info for the given function with an |
| 71 /// attached debugger. Currently this creates a temporary ELF file, which | 96 /// attached debugger. Clients must call UnregisterFunction on all |
| 72 /// needs to be cleaned up later. In order to not leak these temporary | 97 /// registered functions before deleting them to free the associated symbol |
| 73 /// files, clients must call UnregisterFunction before deleting the function. | 98 /// file and unregister it from the debugger. |
| 74 void RegisterFunction(const Function *F, DebugInfo &I); | 99 void RegisterFunction(const Function *F, DebugInfo &I); |
| 75 | 100 |
| 76 /// UnregisterFunction - Unregister the debug info for the given function | 101 /// UnregisterFunction - Unregister the debug info for the given function |
| 77 /// from the debugger and delete any temporary files. | 102 /// from the debugger and free associated memory. |
| 78 void UnregisterFunction(const Function *F); | 103 void UnregisterFunction(const Function *F); |
| 79 | 104 |
| 80 private: | 105 private: |
| 81 /// UnregisterFunctionInternal - Unregister the debug info for the given | 106 /// UnregisterFunctionInternal - Unregister the debug info for the given |
| 82 /// function from the debugger and delete any temporary files. The private | 107 /// function from the debugger and delete any temporary files. The private |
| 83 /// version of this method does not remove the function from FnMap so that it | 108 /// version of this method does not remove the function from FnMap so that it |
| 84 /// can be called while iterating over FnMap. | 109 /// can be called while iterating over FnMap. |
| 85 void UnregisterFunctionInternal( | 110 void UnregisterFunctionInternal(RegisteredFunctionsMap::iterator I); |
| 86 DenseMap<const Function*, sys::Path>::iterator I); | |
| 87 | 111 |
| 88 }; | 112 }; |
| 89 | 113 |
| 90 } // end namespace llvm | 114 } // end namespace llvm |
| 91 | 115 |
| 92 #endif // LLVM_EXECUTION_ENGINE_JIT_DEBUGREGISTERER_H | 116 #endif // LLVM_EXECUTION_ENGINE_JIT_DEBUGREGISTERER_H |
| LEFT | RIGHT |