1 /** 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef COMPILER_TOOLS_DEBUG_JIT_WRITER_H 17 #define COMPILER_TOOLS_DEBUG_JIT_WRITER_H 18 19 #ifdef PANDA_COMPILER_CFI 20 21 #include "aot/compiled_method.h" 22 #include "aot/aot_file.h" 23 #include "aot/aot_builder/elf_builder.h" 24 #include "utils/arch.h" 25 #include "utils/arena_containers.h" 26 #include "utils/bit_vector.h" 27 #include "optimizer/ir/runtime_interface.h" 28 #include <string> 29 #include <vector> 30 #include "mem/gc/gc_types.h" 31 32 namespace panda::panda_file { 33 class File; 34 } // namespace panda::panda_file 35 36 namespace panda { 37 class Class; 38 } // namespace panda 39 40 namespace panda::compiler { 41 template <Arch arch, bool is_jit_mode> 42 class ElfBuilder; 43 44 class JitDebugWriter : public ElfWriter { 45 public: 46 // NOLINTNEXTLINE(modernize-pass-by-value) JitDebugWriter(Arch arch,RuntimeInterface * runtime,CodeAllocator * code_allocator,const std::string & method_name)47 JitDebugWriter(Arch arch, RuntimeInterface *runtime, CodeAllocator *code_allocator, const std::string &method_name) 48 : code_allocator_(code_allocator), method_name_(method_name) 49 { 50 SetArch(arch); 51 SetRuntime(runtime); 52 SetEmitDebugInfo(true); 53 } 54 55 JitDebugWriter() = delete; 56 57 bool Write(); 58 59 void Start(); 60 void End(); 61 GetElf()62 Span<uint8_t> GetElf() 63 { 64 return elf_; 65 } 66 GetCode()67 Span<uint8_t> GetCode() 68 { 69 return code_; 70 } 71 72 private: 73 template <Arch arch> 74 bool WriteImpl(); 75 76 private: 77 Span<uint8_t> elf_; 78 Span<uint8_t> code_; 79 CodeAllocator *code_allocator_ {nullptr}; 80 81 const std::string &method_name_; 82 friend class CodeDataProvider; 83 friend class JitCodeDataProvider; 84 }; 85 86 } // namespace panda::compiler 87 88 // Next "C"-code need for enable interaction with gdb 89 // Please read "JIT Compilation Interface" from gdb-documentation for more information 90 extern "C" { 91 // NOLINTNEXTLINE(modernize-use-using) 92 typedef enum { JIT_NOACTION = 0, JIT_REGISTER_FN, JIT_UNREGISTER_FN } jit_actions_t; 93 94 // NOLINTNEXTLINE(modernize-use-using) 95 typedef struct jit_code_entry jit_code_entry; 96 struct jit_code_entry { 97 jit_code_entry *next_entry; 98 jit_code_entry *prev_entry; 99 const char *symfile_addr; 100 uint64_t symfile_size; 101 }; 102 103 // NOLINTNEXTLINE(modernize-use-using) 104 typedef struct jit_descriptor { 105 uint32_t version; 106 uint32_t action_flag; 107 jit_code_entry *relevant_entry; 108 jit_code_entry *first_entry; 109 } jit_descriptor; 110 } 111 112 #endif // PANDA_COMPILER_CFI 113 #endif // COMPILER_TOOLS_DEBUG_JIT_WRITER_H 114