| 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/Support/DataTypes.h" | 19 #include "llvm/Support/DataTypes.h" |
| 19 #include "llvm/System/Path.h" | 20 #include <string> |
| 20 #include <map> | 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 { |
|
Jeffrey Yasskin
2009/07/08 00:40:45
We'll want to give this a default constructor that
Reid Kleckner
2009/07/08 01:35:05
On 2009/07/08 00:40:45, Jeffrey Yasskin wrote:
> W
| |
| 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; |
| 63 | |
| 64 DebugInfo() : FnStart(0), FnEnd(0), EhStart(0), EhEnd(0) {} | |
| 36 }; | 65 }; |
| 37 | 66 |
| 67 typedef DenseMap< const Function*, std::pair<std::string, jit_code_entry*> > | |
| 68 RegisteredFunctionsMap; | |
| 38 | 69 |
| 39 /// 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. |
| 40 /// 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 |
| 41 /// 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, |
| 42 /// 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 |
| 43 /// RegisterFunction method. The method will then do whatever is necessary to | 74 /// RegisterFunction method. The method will then do whatever is necessary to |
| 44 /// inform the debugger about the JITed function. | 75 /// inform the debugger about the JITed function. |
| 45 class JITDebugRegisterer { | 76 class JITDebugRegisterer { |
| 46 | 77 |
| 47 TargetMachine &TM; | 78 TargetMachine &TM; |
| 48 | 79 |
| 49 /// 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 |
| 50 /// temporary files. Used for cleanup. | 81 /// temporary files. Used for cleanup. |
| 51 std::map<const Function*, sys::Path> FnMap; | 82 RegisteredFunctionsMap FnMap; |
| 52 | 83 |
| 53 /// 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 |
| 54 /// | 85 /// contains the ELF. |
| 55 sys::Path TmpDir; | 86 std::string MakeELF(const Function *F, DebugInfo &I); |
|
Jeffrey Yasskin
2009/07/08 00:40:45
Make this const, I think.
Reid Kleckner
2009/07/08 01:35:05
On 2009/07/08 00:40:45, Jeffrey Yasskin wrote:
> M
| |
| 56 | 87 |
| 57 /// MakeFilename - Make a filename in the system's temporary directory for | 88 public: |
| 58 /// the ELF. | |
| 59 sys::Path MakeFilename(const Function *F, uint8_t *FnStart); | |
| 60 | |
| 61 public: | |
| 62 JITDebugRegisterer(TargetMachine &tm); | 89 JITDebugRegisterer(TargetMachine &tm); |
| 63 | 90 |
| 64 /// ~JITDebugRegisterer - Cleans up all temporary files. | 91 /// ~JITDebugRegisterer - Unregisters all code and frees symbol files. |
| 65 /// | 92 /// |
| 66 ~JITDebugRegisterer(); | 93 ~JITDebugRegisterer(); |
| 67 | 94 |
| 68 /// RegisterFunction - Register debug info for the given function with an | 95 /// RegisterFunction - Register debug info for the given function with an |
| 69 /// attached debugger. Currently this creates a temporary ELF file, which | 96 /// attached debugger. Clients must call UnregisterFunction on all |
| 70 /// needs to be cleaned up later. In order to not leak these temporary | 97 /// registered functions before deleting them to free the associated symbol |
| 71 /// files, clients must call UnregisterFunction before deleting the function. | 98 /// file and unregister it from the debugger. |
| 72 void RegisterFunction(const Function *F, DebugInfo &I); | 99 void RegisterFunction(const Function *F, DebugInfo &I); |
| 73 | 100 |
| 74 /// UnregisterFunction - Unregister the debug info for the given function | 101 /// UnregisterFunction - Unregister the debug info for the given function |
| 75 /// from the debugger and delete any temporary files. | 102 /// from the debugger and free associated memory. |
| 76 void UnregisterFunction(const Function *F); | 103 void UnregisterFunction(const Function *F); |
| 77 | 104 |
| 78 private: | 105 private: |
| 79 /// _UnregisterFunction - Unregister the debug info for the given function | 106 /// UnregisterFunctionInternal - Unregister the debug info for the given |
| 80 /// from the debugger and delete any temporary files. The private version of | 107 /// function from the debugger and delete any temporary files. The private |
| 81 /// this method does not remove the function from FnMap so that it can be | 108 /// version of this method does not remove the function from FnMap so that it |
| 82 /// called from the destructor. | 109 /// can be called while iterating over FnMap. |
| 83 void _UnregisterFunction(const Function *F); | 110 void UnregisterFunctionInternal(RegisteredFunctionsMap::iterator I); |
| 84 | 111 |
| 85 }; | 112 }; |
| 86 | 113 |
| 87 } // end namespace llvm | 114 } // end namespace llvm |
| 88 | 115 |
| 89 #endif // LLVM_EXECUTION_ENGINE_JIT_DEBUGREGISTERER_H | 116 #endif // LLVM_EXECUTION_ENGINE_JIT_DEBUGREGISTERER_H |
| LEFT | RIGHT |