Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: src/wasm/wasm-debug.cc

Issue 2109093003: [wasm] Enable wasm frame inspection for debugging (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/wasm/wasm-debug.h ('k') | src/wasm/wasm-module.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/wasm/wasm-debug.h" 5 #include "src/wasm/wasm-debug.h"
6 6
7 #include "src/assert-scope.h" 7 #include "src/assert-scope.h"
8 #include "src/debug/debug.h" 8 #include "src/debug/debug.h"
9 #include "src/factory.h" 9 #include "src/factory.h"
10 #include "src/isolate.h" 10 #include "src/isolate.h"
11 #include "src/wasm/module-decoder.h" 11 #include "src/wasm/module-decoder.h"
12 #include "src/wasm/wasm-module.h" 12 #include "src/wasm/wasm-module.h"
13 13
14 using namespace v8::internal; 14 using namespace v8::internal;
15 using namespace v8::internal::wasm; 15 using namespace v8::internal::wasm;
16 16
17 namespace { 17 namespace {
18 18
19 enum { 19 enum {
20 kWasmDebugInfoWasmObj, 20 kWasmDebugInfoWasmObj,
21 kWasmDebugInfoWasmBytesHash, 21 kWasmDebugInfoWasmBytesHash,
22 kWasmDebugInfoFunctionByteOffsets, 22 kWasmDebugInfoFunctionByteOffsets,
23 kWasmDebugInfoFunctionScripts,
23 kWasmDebugInfoNumEntries 24 kWasmDebugInfoNumEntries
24 }; 25 };
25 26
26 ByteArray *GetOrCreateFunctionOffsetTable(Handle<WasmDebugInfo> debug_info) { 27 ByteArray *GetOrCreateFunctionOffsetTable(Handle<WasmDebugInfo> debug_info) {
27 Object *offset_table = debug_info->get(kWasmDebugInfoFunctionByteOffsets); 28 Object *offset_table = debug_info->get(kWasmDebugInfoFunctionByteOffsets);
28 Isolate *isolate = debug_info->GetIsolate(); 29 Isolate *isolate = debug_info->GetIsolate();
29 if (!offset_table->IsUndefined(isolate)) return ByteArray::cast(offset_table); 30 if (!offset_table->IsUndefined(isolate)) return ByteArray::cast(offset_table);
30 31
31 FunctionOffsetsResult function_offsets; 32 FunctionOffsetsResult function_offsets;
32 { 33 {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 99 }
99 100
100 bool WasmDebugInfo::IsDebugInfo(Object *object) { 101 bool WasmDebugInfo::IsDebugInfo(Object *object) {
101 if (!object->IsFixedArray()) return false; 102 if (!object->IsFixedArray()) return false;
102 FixedArray *arr = FixedArray::cast(object); 103 FixedArray *arr = FixedArray::cast(object);
103 Isolate *isolate = arr->GetIsolate(); 104 Isolate *isolate = arr->GetIsolate();
104 return arr->length() == kWasmDebugInfoNumEntries && 105 return arr->length() == kWasmDebugInfoNumEntries &&
105 IsWasmObject(arr->get(kWasmDebugInfoWasmObj)) && 106 IsWasmObject(arr->get(kWasmDebugInfoWasmObj)) &&
106 arr->get(kWasmDebugInfoWasmBytesHash)->IsNumber() && 107 arr->get(kWasmDebugInfoWasmBytesHash)->IsNumber() &&
107 (arr->get(kWasmDebugInfoFunctionByteOffsets)->IsUndefined(isolate) || 108 (arr->get(kWasmDebugInfoFunctionByteOffsets)->IsUndefined(isolate) ||
108 arr->get(kWasmDebugInfoFunctionByteOffsets)->IsByteArray()); 109 arr->get(kWasmDebugInfoFunctionByteOffsets)->IsByteArray()) &&
110 (arr->get(kWasmDebugInfoFunctionScripts)->IsUndefined(isolate) ||
111 arr->get(kWasmDebugInfoFunctionScripts)->IsFixedArray());
109 } 112 }
110 113
111 WasmDebugInfo *WasmDebugInfo::cast(Object *object) { 114 WasmDebugInfo *WasmDebugInfo::cast(Object *object) {
112 DCHECK(IsDebugInfo(object)); 115 DCHECK(IsDebugInfo(object));
113 return reinterpret_cast<WasmDebugInfo *>(object); 116 return reinterpret_cast<WasmDebugInfo *>(object);
114 } 117 }
115 118
116 JSObject *WasmDebugInfo::wasm_object() { 119 JSObject *WasmDebugInfo::wasm_object() {
117 return JSObject::cast(get(kWasmDebugInfoWasmObj)); 120 return JSObject::cast(get(kWasmDebugInfoWasmObj));
118 } 121 }
119 122
120 bool WasmDebugInfo::SetBreakPoint(int byte_offset) { 123 bool WasmDebugInfo::SetBreakPoint(int byte_offset) {
121 // TODO(clemensh): Implement this. 124 // TODO(clemensh): Implement this.
122 return false; 125 return false;
123 } 126 }
124 127
128 Script *WasmDebugInfo::GetFunctionScript(Handle<WasmDebugInfo> debug_info,
129 int func_index) {
130 Isolate *isolate = debug_info->GetIsolate();
131 Object *scripts_obj = debug_info->get(kWasmDebugInfoFunctionScripts);
132 Handle<FixedArray> scripts;
133 if (scripts_obj->IsUndefined(isolate)) {
134 int num_functions = wasm::GetNumberOfFunctions(debug_info->wasm_object());
135 scripts = isolate->factory()->NewFixedArray(num_functions, TENURED);
136 debug_info->set(kWasmDebugInfoFunctionScripts, *scripts);
137 } else {
138 scripts = handle(FixedArray::cast(scripts_obj), isolate);
139 }
140
141 DCHECK(func_index >= 0 && func_index < scripts->length());
142 Object *script_or_undef = scripts->get(func_index);
143 if (!script_or_undef->IsUndefined(isolate)) {
144 return Script::cast(script_or_undef);
145 }
146
147 Handle<Script> script =
148 isolate->factory()->NewScript(isolate->factory()->empty_string());
149 scripts->set(func_index, *script);
150
151 script->set_type(Script::TYPE_WASM);
152
153 int func_bytes_len =
154 GetFunctionOffsetAndLength(debug_info, func_index).second;
155 Handle<FixedArray> line_ends = isolate->factory()->NewFixedArray(1, TENURED);
156 line_ends->set(0, Smi::FromInt(func_bytes_len));
157 line_ends->set_map(isolate->heap()->fixed_cow_array_map());
158 script->set_line_ends(*line_ends);
159
160 // TODO(clemensh): Register this new script at the debugger.
161
162 return *script;
163 }
164
125 Handle<String> WasmDebugInfo::DisassembleFunction( 165 Handle<String> WasmDebugInfo::DisassembleFunction(
126 Handle<WasmDebugInfo> debug_info, int func_index) { 166 Handle<WasmDebugInfo> debug_info, int func_index) {
127 std::ostringstream disassembly_os; 167 std::ostringstream disassembly_os;
128 168
129 { 169 {
130 Vector<const uint8_t> bytes_vec = GetFunctionBytes(debug_info, func_index); 170 Vector<const uint8_t> bytes_vec = GetFunctionBytes(debug_info, func_index);
131 DisallowHeapAllocation no_gc; 171 DisallowHeapAllocation no_gc;
132 172
133 base::AccountingAllocator allocator; 173 base::AccountingAllocator allocator;
134 bool ok = PrintAst( 174 bool ok = PrintAst(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 int idx = 0; 216 int idx = 0;
177 for (std::tuple<uint32_t, int, int> elem : offset_table_vec) { 217 for (std::tuple<uint32_t, int, int> elem : offset_table_vec) {
178 offset_table->set(idx++, Smi::FromInt(std::get<0>(elem))); 218 offset_table->set(idx++, Smi::FromInt(std::get<0>(elem)));
179 offset_table->set(idx++, Smi::FromInt(std::get<1>(elem))); 219 offset_table->set(idx++, Smi::FromInt(std::get<1>(elem)));
180 offset_table->set(idx++, Smi::FromInt(std::get<2>(elem))); 220 offset_table->set(idx++, Smi::FromInt(std::get<2>(elem)));
181 } 221 }
182 DCHECK_EQ(idx, offset_table->length()); 222 DCHECK_EQ(idx, offset_table->length());
183 223
184 return offset_table; 224 return offset_table;
185 } 225 }
OLDNEW
« no previous file with comments | « src/wasm/wasm-debug.h ('k') | src/wasm/wasm-module.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698