| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 // Copyright (c) 2017, the Dart project authors.  Please see the AUTHORS file | 
|  | 2 // for details. All rights reserved. Use of this source code is governed by a | 
|  | 3 // BSD-style license that can be found in the LICENSE file. | 
|  | 4 | 
|  | 5 #ifndef RUNTIME_VM_DWARF_H_ | 
|  | 6 #define RUNTIME_VM_DWARF_H_ | 
|  | 7 | 
|  | 8 #include "vm/allocation.h" | 
|  | 9 #include "vm/hash_map.h" | 
|  | 10 #include "vm/object.h" | 
|  | 11 #include "vm/zone.h" | 
|  | 12 | 
|  | 13 namespace dart { | 
|  | 14 | 
|  | 15 #ifdef DART_PRECOMPILER | 
|  | 16 | 
|  | 17 class InliningNode; | 
|  | 18 | 
|  | 19 struct ScriptIndexPair { | 
|  | 20   // Typedefs needed for the DirectChainedHashMap template. | 
|  | 21   typedef const Script* Key; | 
|  | 22   typedef intptr_t Value; | 
|  | 23   typedef ScriptIndexPair Pair; | 
|  | 24 | 
|  | 25   static Key KeyOf(Pair kv) { return kv.script_; } | 
|  | 26 | 
|  | 27   static Value ValueOf(Pair kv) { return kv.index_; } | 
|  | 28 | 
|  | 29   static inline intptr_t Hashcode(Key key) { | 
|  | 30     return String::Handle(key->url()).Hash(); | 
|  | 31   } | 
|  | 32 | 
|  | 33   static inline bool IsKeyEqual(Pair pair, Key key) { | 
|  | 34     return pair.script_->raw() == key->raw(); | 
|  | 35   } | 
|  | 36 | 
|  | 37   ScriptIndexPair(const Script* s, intptr_t index) | 
|  | 38       : script_(s), index_(index) {} | 
|  | 39 | 
|  | 40   ScriptIndexPair() : script_(NULL), index_(-1) {} | 
|  | 41 | 
|  | 42   void Print() const; | 
|  | 43 | 
|  | 44   const Script* script_; | 
|  | 45   intptr_t index_; | 
|  | 46 }; | 
|  | 47 | 
|  | 48 typedef DirectChainedHashMap<ScriptIndexPair> ScriptIndexMap; | 
|  | 49 | 
|  | 50 struct FunctionIndexPair { | 
|  | 51   // Typedefs needed for the DirectChainedHashMap template. | 
|  | 52   typedef const Function* Key; | 
|  | 53   typedef intptr_t Value; | 
|  | 54   typedef FunctionIndexPair Pair; | 
|  | 55 | 
|  | 56   static Key KeyOf(Pair kv) { return kv.function_; } | 
|  | 57 | 
|  | 58   static Value ValueOf(Pair kv) { return kv.index_; } | 
|  | 59 | 
|  | 60   static inline intptr_t Hashcode(Key key) { return key->token_pos().value(); } | 
|  | 61 | 
|  | 62   static inline bool IsKeyEqual(Pair pair, Key key) { | 
|  | 63     return pair.function_->raw() == key->raw(); | 
|  | 64   } | 
|  | 65 | 
|  | 66   FunctionIndexPair(const Function* f, intptr_t index) | 
|  | 67       : function_(f), index_(index) {} | 
|  | 68 | 
|  | 69   FunctionIndexPair() : function_(NULL), index_(-1) {} | 
|  | 70 | 
|  | 71   void Print() const; | 
|  | 72 | 
|  | 73   const Function* function_; | 
|  | 74   intptr_t index_; | 
|  | 75 }; | 
|  | 76 | 
|  | 77 typedef DirectChainedHashMap<FunctionIndexPair> FunctionIndexMap; | 
|  | 78 | 
|  | 79 struct CodeIndexPair { | 
|  | 80   // Typedefs needed for the DirectChainedHashMap template. | 
|  | 81   typedef const Code* Key; | 
|  | 82   typedef intptr_t Value; | 
|  | 83   typedef CodeIndexPair Pair; | 
|  | 84 | 
|  | 85   static Key KeyOf(Pair kv) { return kv.code_; } | 
|  | 86 | 
|  | 87   static Value ValueOf(Pair kv) { return kv.index_; } | 
|  | 88 | 
|  | 89   static inline intptr_t Hashcode(Key key) { | 
|  | 90     // Code objects are always allocated in old space, so they don't move. | 
|  | 91     return key->PayloadStart(); | 
|  | 92   } | 
|  | 93 | 
|  | 94   static inline bool IsKeyEqual(Pair pair, Key key) { | 
|  | 95     return pair.code_->raw() == key->raw(); | 
|  | 96   } | 
|  | 97 | 
|  | 98   CodeIndexPair(const Code* c, intptr_t index) : code_(c), index_(index) {} | 
|  | 99 | 
|  | 100   CodeIndexPair() : code_(NULL), index_(-1) {} | 
|  | 101 | 
|  | 102   void Print() const; | 
|  | 103 | 
|  | 104   const Code* code_; | 
|  | 105   intptr_t index_; | 
|  | 106 }; | 
|  | 107 | 
|  | 108 typedef DirectChainedHashMap<CodeIndexPair> CodeIndexMap; | 
|  | 109 | 
|  | 110 class Dwarf : public ZoneAllocated { | 
|  | 111  public: | 
|  | 112   Dwarf(Zone* zone, WriteStream* stream); | 
|  | 113 | 
|  | 114   intptr_t AddCode(const Code& code); | 
|  | 115   intptr_t AddFunction(const Function& function); | 
|  | 116   intptr_t AddScript(const Script& script); | 
|  | 117   intptr_t LookupFunction(const Function& function); | 
|  | 118   intptr_t LookupScript(const Script& script); | 
|  | 119 | 
|  | 120   void Write() { | 
|  | 121     WriteAbbreviations(); | 
|  | 122     WriteCompilationUnit(); | 
|  | 123     WriteLines(); | 
|  | 124   } | 
|  | 125 | 
|  | 126  private: | 
|  | 127   static const intptr_t DW_TAG_compile_unit = 0x11; | 
|  | 128   static const intptr_t DW_TAG_inlined_subroutine = 0x1d; | 
|  | 129   static const intptr_t DW_TAG_subprogram = 0x2e; | 
|  | 130 | 
|  | 131   static const intptr_t DW_CHILDREN_no = 0x0; | 
|  | 132   static const intptr_t DW_CHILDREN_yes = 0x1; | 
|  | 133 | 
|  | 134   static const intptr_t DW_AT_sibling = 0x1; | 
|  | 135   static const intptr_t DW_AT_name = 0x3; | 
|  | 136   static const intptr_t DW_AT_stmt_list = 0x10; | 
|  | 137   static const intptr_t DW_AT_low_pc = 0x11; | 
|  | 138   static const intptr_t DW_AT_high_pc = 0x12; | 
|  | 139   static const intptr_t DW_AT_comp_dir = 0x1b; | 
|  | 140   static const intptr_t DW_AT_inline = 0x20; | 
|  | 141   static const intptr_t DW_AT_producer = 0x25; | 
|  | 142   static const intptr_t DW_AT_abstract_origin = 0x31; | 
|  | 143   static const intptr_t DW_AT_decl_column = 0x39; | 
|  | 144   static const intptr_t DW_AT_decl_file = 0x3a; | 
|  | 145   static const intptr_t DW_AT_decl_line = 0x3b; | 
|  | 146   static const intptr_t DW_AT_call_column = 0x57; | 
|  | 147   static const intptr_t DW_AT_call_file = 0x58; | 
|  | 148   static const intptr_t DW_AT_call_line = 0x59; | 
|  | 149 | 
|  | 150   static const intptr_t DW_FORM_addr = 0x01; | 
|  | 151   static const intptr_t DW_FORM_string = 0x08; | 
|  | 152   static const intptr_t DW_FORM_udata = 0x0f; | 
|  | 153   static const intptr_t DW_FORM_ref4 = 0x13; | 
|  | 154   static const intptr_t DW_FORM_ref_udata = 0x15; | 
|  | 155   static const intptr_t DW_FORM_sec_offset = 0x17; | 
|  | 156 | 
|  | 157   static const intptr_t DW_INL_not_inlined = 0x0; | 
|  | 158   static const intptr_t DW_INL_inlined = 0x1; | 
|  | 159 | 
|  | 160   static const intptr_t DW_LNS_copy = 0x1; | 
|  | 161   static const intptr_t DW_LNS_advance_pc = 0x2; | 
|  | 162   static const intptr_t DW_LNS_advance_line = 0x3; | 
|  | 163   static const intptr_t DW_LNS_set_file = 0x4; | 
|  | 164 | 
|  | 165   static const intptr_t DW_LNE_end_sequence = 0x01; | 
|  | 166   static const intptr_t DW_LNE_set_address = 0x02; | 
|  | 167 | 
|  | 168   enum { | 
|  | 169     kCompilationUnit = 1, | 
|  | 170     kAbstractFunction, | 
|  | 171     kConcreteFunction, | 
|  | 172     kInlinedFunction, | 
|  | 173   }; | 
|  | 174 | 
|  | 175   void Print(const char* format, ...); | 
|  | 176   void sleb128(intptr_t value) { Print(".sleb128 %" Pd "\n", value); } | 
|  | 177   void uleb128(uintptr_t value) { Print(".uleb128 %" Pd "\n", value); } | 
|  | 178   void u1(uint8_t value) { Print(".byte %" Pd "\n", value); } | 
|  | 179   void u2(uint16_t value) { Print(".2byte %" Pd "\n", value); } | 
|  | 180   void u4(uint32_t value) { Print(".4byte %" Pd "\n", value); } | 
|  | 181 | 
|  | 182   void WriteAbbreviations(); | 
|  | 183   void WriteCompilationUnit(); | 
|  | 184   void WriteAbstractFunctions(); | 
|  | 185   void WriteConcreteFunctions(); | 
|  | 186   InliningNode* ExpandInliningTree(const Code& code); | 
|  | 187   void WriteInliningNode(InliningNode* node, | 
|  | 188                          intptr_t root_code_index, | 
|  | 189                          const Script& parent_script); | 
|  | 190   void WriteLines(); | 
|  | 191 | 
|  | 192   Zone* const zone_; | 
|  | 193   WriteStream* stream_; | 
|  | 194   ZoneGrowableArray<const Code*> codes_; | 
|  | 195   CodeIndexMap code_to_index_; | 
|  | 196   ZoneGrowableArray<const Function*> functions_; | 
|  | 197   FunctionIndexMap function_to_index_; | 
|  | 198   ZoneGrowableArray<const Script*> scripts_; | 
|  | 199   ScriptIndexMap script_to_index_; | 
|  | 200   intptr_t temp_; | 
|  | 201 }; | 
|  | 202 | 
|  | 203 #endif  // DART_PRECOMPILER | 
|  | 204 | 
|  | 205 }  // namespace dart | 
|  | 206 | 
|  | 207 #endif  // RUNTIME_VM_DWARF_H_ | 
| OLD | NEW | 
|---|