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

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

Issue 2069823003: [wasm] Enable wasm frame inspection for debugging (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@split-wasm-debug
Patch Set: address yang's comments Created 4 years, 6 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
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(WasmDebugInfo *debug_info) { 27 ByteArray *GetOrCreateFunctionOffsetTable(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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 int hash = 0; 89 int hash = 0;
89 Handle<SeqOneByteString> wasm_bytes(GetWasmBytes(*wasm), isolate); 90 Handle<SeqOneByteString> wasm_bytes(GetWasmBytes(*wasm), isolate);
90 { 91 {
91 DisallowHeapAllocation no_gc; 92 DisallowHeapAllocation no_gc;
92 hash = StringHasher::HashSequentialString( 93 hash = StringHasher::HashSequentialString(
93 wasm_bytes->GetChars(), wasm_bytes->length(), kZeroHashSeed); 94 wasm_bytes->GetChars(), wasm_bytes->length(), kZeroHashSeed);
94 } 95 }
95 Handle<Object> hash_obj = factory->NewNumberFromInt(hash, TENURED); 96 Handle<Object> hash_obj = factory->NewNumberFromInt(hash, TENURED);
96 arr->set(kWasmDebugInfoWasmBytesHash, *hash_obj); 97 arr->set(kWasmDebugInfoWasmBytesHash, *hash_obj);
97 98
99 int num_functions = wasm::GetNumberOfFunctions(*wasm);
100 Handle<FixedArray> functionScripts =
101 factory->NewFixedArray(num_functions, TENURED);
102 arr->set(kWasmDebugInfoFunctionScripts, *functionScripts);
103
98 return Handle<WasmDebugInfo>::cast(arr); 104 return Handle<WasmDebugInfo>::cast(arr);
99 } 105 }
100 106
101 bool WasmDebugInfo::IsDebugInfo(Object *object) { 107 bool WasmDebugInfo::IsDebugInfo(Object *object) {
102 if (!object->IsFixedArray()) return false; 108 if (!object->IsFixedArray()) return false;
103 FixedArray *arr = FixedArray::cast(object); 109 FixedArray *arr = FixedArray::cast(object);
104 Isolate *isolate = arr->GetIsolate(); 110 Isolate *isolate = arr->GetIsolate();
105 return arr->length() == kWasmDebugInfoNumEntries && 111 return arr->length() == kWasmDebugInfoNumEntries &&
106 IsWasmObject(arr->get(kWasmDebugInfoWasmObj)) && 112 IsWasmObject(arr->get(kWasmDebugInfoWasmObj)) &&
107 arr->get(kWasmDebugInfoWasmBytesHash)->IsNumber() && 113 arr->get(kWasmDebugInfoWasmBytesHash)->IsNumber() &&
108 (arr->get(kWasmDebugInfoFunctionByteOffsets)->IsUndefined(isolate) || 114 (arr->get(kWasmDebugInfoFunctionByteOffsets)->IsUndefined(isolate) ||
109 arr->get(kWasmDebugInfoFunctionByteOffsets)->IsByteArray()); 115 arr->get(kWasmDebugInfoFunctionByteOffsets)->IsByteArray()) &&
116 (arr->get(kWasmDebugInfoFunctionScripts)->IsUndefined(isolate) ||
117 arr->get(kWasmDebugInfoFunctionScripts)->IsFixedArray());
110 } 118 }
111 119
112 WasmDebugInfo *WasmDebugInfo::cast(Object *object) { 120 WasmDebugInfo *WasmDebugInfo::cast(Object *object) {
113 DCHECK(IsDebugInfo(object)); 121 DCHECK(IsDebugInfo(object));
114 return reinterpret_cast<WasmDebugInfo *>(object); 122 return reinterpret_cast<WasmDebugInfo *>(object);
115 } 123 }
116 124
117 JSObject *WasmDebugInfo::wasm_object() { 125 JSObject *WasmDebugInfo::wasm_object() {
118 return JSObject::cast(get(kWasmDebugInfoWasmObj)); 126 return JSObject::cast(get(kWasmDebugInfoWasmObj));
119 } 127 }
120 128
129 Script *WasmDebugInfo::GetFunctionScript(int func_index) {
130 Isolate *isolate = GetIsolate();
131 FixedArray *scripts = FixedArray::cast(get(kWasmDebugInfoFunctionScripts));
132 DCHECK(func_index >= 0 && func_index < scripts->length());
133 Object *script_or_undef = scripts->get(func_index);
134 if (!script_or_undef->IsUndefined(isolate)) {
135 return Script::cast(script_or_undef);
136 }
137
138 JSObject *wasm0 = wasm_object();
139 Handle<JSObject> wasm(wasm0, isolate);
140
141 Handle<Script> script =
142 isolate->factory()->NewScript(isolate->factory()->empty_string());
143 scripts->set(func_index, *script);
144
145 script->set_type(Script::TYPE_WASM);
146
147 Handle<ByteArray> offset_arr(GetOrCreateFunctionOffsetTable(this), isolate);
148 int func_bytes_len = offset_arr->get_int(2 * func_index + 1);
ahaas 2016/06/17 07:25:44 I think it could be a good idea to add a wrapper f
Clemens Hammacher 2016/06/17 14:01:46 Done. This now calls GetFunctionOffsetAndLength.
149 Handle<FixedArray> line_ends = isolate->factory()->NewFixedArray(1, TENURED);
150 line_ends->set(0, Smi::FromInt(func_bytes_len));
151 line_ends->set_map(isolate->heap()->fixed_cow_array_map());
152 script->set_line_ends(*line_ends);
153
154 int hash = 0;
155 get(kWasmDebugInfoWasmBytesHash)->ToInt32(&hash);
156
157 // TODO(clemensh): Register this new script at the debugger.
158 USE(hash);
159
160 return *script;
161 }
162
121 bool WasmDebugInfo::SetBreakPoint(int byte_offset) { 163 bool WasmDebugInfo::SetBreakPoint(int byte_offset) {
122 // TODO(clemensh): Implement this. 164 // TODO(clemensh): Implement this.
123 return false; 165 return false;
124 } 166 }
125 167
126 Handle<String> WasmDebugInfo::DisassembleFunction(int func_index) { 168 Handle<String> WasmDebugInfo::DisassembleFunction(int func_index) {
127 std::ostringstream disassembly_os; 169 std::ostringstream disassembly_os;
128 170
129 { 171 {
130 DisallowHeapAllocation no_gc; 172 DisallowHeapAllocation no_gc;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 int idx = 0; 217 int idx = 0;
176 for (std::tuple<uint32_t, int, int> elem : offset_table_vec) { 218 for (std::tuple<uint32_t, int, int> elem : offset_table_vec) {
177 offset_table->set(idx++, Smi::FromInt(std::get<0>(elem))); 219 offset_table->set(idx++, Smi::FromInt(std::get<0>(elem)));
178 offset_table->set(idx++, Smi::FromInt(std::get<1>(elem))); 220 offset_table->set(idx++, Smi::FromInt(std::get<1>(elem)));
179 offset_table->set(idx++, Smi::FromInt(std::get<2>(elem))); 221 offset_table->set(idx++, Smi::FromInt(std::get<2>(elem)));
180 } 222 }
181 DCHECK_EQ(idx, offset_table->length()); 223 DCHECK_EQ(idx, offset_table->length());
182 224
183 return offset_table; 225 return offset_table;
184 } 226 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698