Flutter Engine
The Flutter Engine
disassembler.h
Go to the documentation of this file.
1// Copyright (c) 2011, 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_COMPILER_ASSEMBLER_DISASSEMBLER_H_
6#define RUNTIME_VM_COMPILER_ASSEMBLER_DISASSEMBLER_H_
7
8#include "vm/allocation.h"
9#include "vm/globals.h"
10#include "vm/log.h"
11#include "vm/object.h"
12
13#if !defined(DART_PRECOMPILED_RUNTIME)
15#endif // !defined(DART_PRECOMPILED_RUNTIME)
16
17namespace dart {
18
19// Forward declaration.
20class CodeComments;
21class JSONArray;
22class MemoryRegion;
23
24// Disassembly formatter interface, which consumes the
25// disassembled instructions in any desired form.
27 public:
30
31 // Consume the decoded instruction at the given pc.
32 virtual void ConsumeInstruction(char* hex_buffer,
33 intptr_t hex_size,
34 char* human_buffer,
35 intptr_t human_size,
36 Object* object,
37 uword pc) = 0;
38
39 // Print a formatted message.
40 virtual void Print(const char* format, ...) PRINTF_ATTRIBUTE(2, 3) = 0;
41};
42
43// Basic disassembly formatter that outputs the disassembled instruction
44// to stdout.
46 public:
49
50 virtual void ConsumeInstruction(char* hex_buffer,
51 intptr_t hex_size,
52 char* human_buffer,
53 intptr_t human_size,
54 Object* object,
55 uword pc);
56
57 virtual void Print(const char* format, ...) PRINTF_ATTRIBUTE(2, 3);
58
59 private:
62};
63
64#if !defined(PRODUCT)
65// Disassemble into a JSONStream.
67 public:
68 explicit DisassembleToJSONStream(const JSONArray& jsarr)
69 : DisassemblyFormatter(), jsarr_(jsarr) {}
71
72 virtual void ConsumeInstruction(char* hex_buffer,
73 intptr_t hex_size,
74 char* human_buffer,
75 intptr_t human_size,
76 Object* object,
77 uword pc);
78
79 virtual void Print(const char* format, ...) PRINTF_ATTRIBUTE(2, 3);
80
81 private:
82 const JSONArray& jsarr_;
85};
86#endif // !defined(PRODUCT)
87
88#if !defined(PRODUCT) || defined(FORCE_INCLUDE_DISASSEMBLER)
89// Basic disassembly formatter that outputs the disassembled instruction
90// to a memory buffer. This is only intended for test writing.
92 public:
95 buffer_(buffer),
96 remaining_(length),
97 overflowed_(false) {}
99
100 virtual void ConsumeInstruction(char* hex_buffer,
101 intptr_t hex_size,
102 char* human_buffer,
103 intptr_t human_size,
104 Object* object,
105 uword pc);
106
107 virtual void Print(const char* format, ...) PRINTF_ATTRIBUTE(2, 3);
108
109 private:
110 char* buffer_;
111 int remaining_;
112 bool overflowed_;
115};
116#endif
117
118// Disassemble instructions.
119class Disassembler : public AllStatic {
120 public:
121 // Disassemble instructions between start and end.
122 // (The assumption is that start is at a valid instruction).
123 // Return true if all instructions were successfully decoded, false otherwise.
124 static void Disassemble(uword start,
125 uword end,
126 DisassemblyFormatter* formatter,
127 const Code& code,
128 const CodeComments* comments = nullptr);
129
130 static void Disassemble(uword start,
131 uword end,
132 DisassemblyFormatter* formatter) {
133 Disassemble(start, end, formatter, Code::Handle());
134 }
135
136 static void Disassemble(uword start,
137 uword end,
138 DisassemblyFormatter* formatter,
139 const CodeComments* comments) {
140 Disassemble(start, end, formatter, Code::Handle(), comments);
141 }
142
143 static void Disassemble(uword start, uword end, const Code& code) {
144#if !defined(PRODUCT) || defined(FORCE_INCLUDE_DISASSEMBLER)
145 DisassembleToStdout stdout_formatter;
146 LogBlock lb;
147 if (!code.IsNull()) {
148 Disassemble(start, end, &stdout_formatter, code, &code.comments());
149 } else {
150 Disassemble(start, end, &stdout_formatter, code);
151 }
152#else
153 UNREACHABLE();
154#endif
155 }
156
157 static void Disassemble(uword start, uword end) {
158#if !defined(PRODUCT) || defined(FORCE_INCLUDE_DISASSEMBLER)
159 DisassembleToStdout stdout_formatter;
160 LogBlock lb;
161 Disassemble(start, end, &stdout_formatter);
162#else
163 UNREACHABLE();
164#endif
165 }
166
167 static void Disassemble(uword start,
168 uword end,
169 char* buffer,
170 uintptr_t buffer_size) {
171#if !defined(PRODUCT) || defined(FORCE_INCLUDE_DISASSEMBLER)
172 DisassembleToMemory memory_formatter(buffer, buffer_size);
173 LogBlock lb;
174 Disassemble(start, end, &memory_formatter);
175#else
176 UNREACHABLE();
177#endif
178 }
179
180 // Decodes one instruction.
181 // Writes a hexadecimal representation into the hex_buffer and a
182 // human-readable representation into the human_buffer.
183 // Writes the length of the decoded instruction in bytes in out_instr_len.
184 static void DecodeInstruction(char* hex_buffer,
185 intptr_t hex_size,
186 char* human_buffer,
187 intptr_t human_size,
188 int* out_instr_len,
189 const Code& code,
190 Object** object,
191 uword pc);
192
193 static void DisassembleCode(const Function& function,
194 const Code& code,
195 bool optimized);
196
197 static void DisassembleStub(const char* name, const Code& code);
198
199 private:
200 static void DisassembleCodeHelper(const char* function_fullname,
201 const char* function_info,
202 const Code& code,
203 bool optimized);
204
205 static constexpr int kHexadecimalBufferSize = 32;
206 static constexpr int kUserReadableBufferSize = 256;
207};
208
209} // namespace dart
210
211#endif // RUNTIME_VM_COMPILER_ASSEMBLER_DISASSEMBLER_H_
static uint32_t buffer_size(uint32_t offset, uint32_t maxAlignment)
#define UNREACHABLE()
Definition: assert.h:248
DisassembleToJSONStream(const JSONArray &jsarr)
Definition: disassembler.h:68
DisassembleToMemory(char *buffer, uintptr_t length)
Definition: disassembler.h:93
virtual void ConsumeInstruction(char *hex_buffer, intptr_t hex_size, char *human_buffer, intptr_t human_size, Object *object, uword pc)
static void Disassemble(uword start, uword end, DisassemblyFormatter *formatter)
Definition: disassembler.h:130
static void Disassemble(uword start, uword end, const Code &code)
Definition: disassembler.h:143
static void Disassemble(uword start, uword end, char *buffer, uintptr_t buffer_size)
Definition: disassembler.h:167
static void Disassemble(uword start, uword end, DisassemblyFormatter *formatter, const CodeComments *comments)
Definition: disassembler.h:136
static void Disassemble(uword start, uword end)
Definition: disassembler.h:157
static void DecodeInstruction(char *hex_buffer, intptr_t hex_size, char *human_buffer, intptr_t human_size, int *out_instr_len, const Code &code, Object **object, uword pc)
virtual void ConsumeInstruction(char *hex_buffer, intptr_t hex_size, char *human_buffer, intptr_t human_size, Object *object, uword pc)=0
virtual void Print(const char *format,...) PRINTF_ATTRIBUTE(2
static Object & Handle()
Definition: object.h:407
glong glong end
uint32_t uint32_t * format
Dart_NativeFunction function
Definition: fuchsia.cc:51
size_t length
Definition: dart_vm.cc:33
const char *const name
uintptr_t uword
Definition: globals.h:501
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
#define PRINTF_ATTRIBUTE(string_index, first_to_check)
Definition: globals.h:697
#define DISALLOW_ALLOCATION()
Definition: globals.h:604
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: globals.h:581