• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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_DEBUG_INFO
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 ark::panda_file {
33 class File;
34 }  // namespace ark::panda_file
35 
36 namespace ark {
37 class Class;
38 }  // namespace ark
39 
40 namespace ark::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 * codeAllocator,const std::string & methodName)47     JitDebugWriter(Arch arch, RuntimeInterface *runtime, CodeAllocator *codeAllocator, const std::string &methodName)
48         : codeAllocator_(codeAllocator), methodName_(methodName)
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 *codeAllocator_ {nullptr};
80 
81     const std::string &methodName_;
82     friend class CodeDataProvider;
83     friend class JitCodeDataProvider;
84 };
85 
86 }  // namespace ark::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 } JitActionsT;
93 
94 // NOLINTNEXTLINE(modernize-use-using)
95 typedef struct jit_code_entry JitCodeEntry;
96 struct jit_code_entry {
97     jit_code_entry *nextEntry;
98     jit_code_entry *prevEntry;
99     const char *symfileAddr;
100     uint64_t symfileSize;
101 };
102 
103 // NOLINTNEXTLINE(modernize-use-using, readability-identifier-naming)
104 typedef struct jit_descriptor {
105     uint32_t version;
106     uint32_t actionFlag;
107     jit_code_entry *relevantEntry;
108     jit_code_entry *firstEntry;
109 } jit_descriptor;  // NOLINT(readability-identifier-naming)
110 }
111 
112 #endif  // PANDA_COMPILER_DEBUG_INFO
113 #endif  // COMPILER_TOOLS_DEBUG_JIT_WRITER_H
114