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

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

Issue 2063013004: [wasm] Disassemble wasm code from script (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@wasm-frame-inspection
Patch Set: remove unimplemented wasm SetBreakPoint method 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/ast-decoder.cc ('k') | test/mjsunit/wasm/debug-disassembly.js » ('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"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 113
114 WasmDebugInfo *WasmDebugInfo::cast(Object *object) { 114 WasmDebugInfo *WasmDebugInfo::cast(Object *object) {
115 DCHECK(IsDebugInfo(object)); 115 DCHECK(IsDebugInfo(object));
116 return reinterpret_cast<WasmDebugInfo *>(object); 116 return reinterpret_cast<WasmDebugInfo *>(object);
117 } 117 }
118 118
119 JSObject *WasmDebugInfo::wasm_object() { 119 JSObject *WasmDebugInfo::wasm_object() {
120 return JSObject::cast(get(kWasmDebugInfoWasmObj)); 120 return JSObject::cast(get(kWasmDebugInfoWasmObj));
121 } 121 }
122 122
123 bool WasmDebugInfo::SetBreakPoint(int byte_offset) {
124 // TODO(clemensh): Implement this.
125 return false;
126 }
127
128 Script *WasmDebugInfo::GetFunctionScript(Handle<WasmDebugInfo> debug_info, 123 Script *WasmDebugInfo::GetFunctionScript(Handle<WasmDebugInfo> debug_info,
129 int func_index) { 124 int func_index) {
130 Isolate *isolate = debug_info->GetIsolate(); 125 Isolate *isolate = debug_info->GetIsolate();
131 Object *scripts_obj = debug_info->get(kWasmDebugInfoFunctionScripts); 126 Object *scripts_obj = debug_info->get(kWasmDebugInfoFunctionScripts);
132 Handle<FixedArray> scripts; 127 Handle<FixedArray> scripts;
133 if (scripts_obj->IsUndefined(isolate)) { 128 if (scripts_obj->IsUndefined(isolate)) {
134 int num_functions = wasm::GetNumberOfFunctions(debug_info->wasm_object()); 129 int num_functions = wasm::GetNumberOfFunctions(debug_info->wasm_object());
135 scripts = isolate->factory()->NewFixedArray(num_functions, TENURED); 130 scripts = isolate->factory()->NewFixedArray(num_functions, TENURED);
136 debug_info->set(kWasmDebugInfoFunctionScripts, *scripts); 131 debug_info->set(kWasmDebugInfoFunctionScripts, *scripts);
137 } else { 132 } else {
138 scripts = handle(FixedArray::cast(scripts_obj), isolate); 133 scripts = handle(FixedArray::cast(scripts_obj), isolate);
139 } 134 }
140 135
141 DCHECK(func_index >= 0 && func_index < scripts->length()); 136 DCHECK(func_index >= 0 && func_index < scripts->length());
142 Object *script_or_undef = scripts->get(func_index); 137 Object *script_or_undef = scripts->get(func_index);
143 if (!script_or_undef->IsUndefined(isolate)) { 138 if (!script_or_undef->IsUndefined(isolate)) {
144 return Script::cast(script_or_undef); 139 return Script::cast(script_or_undef);
145 } 140 }
146 141
147 Handle<Script> script = 142 Handle<Script> script =
148 isolate->factory()->NewScript(isolate->factory()->empty_string()); 143 isolate->factory()->NewScript(isolate->factory()->empty_string());
149 scripts->set(func_index, *script); 144 scripts->set(func_index, *script);
150 145
151 script->set_type(Script::TYPE_WASM); 146 script->set_type(Script::TYPE_WASM);
147 script->set_wasm_object(debug_info->wasm_object());
148 script->set_wasm_function_index(func_index);
149
150 int hash = 0;
151 debug_info->get(kWasmDebugInfoWasmBytesHash)->ToInt32(&hash);
152 char buffer[32];
153 SNPrintF(ArrayVector(buffer), "wasm://%08x/%d", hash, func_index);
154 Handle<String> source_url =
155 isolate->factory()->NewStringFromAsciiChecked(buffer, TENURED);
156 script->set_source_url(*source_url);
152 157
153 int func_bytes_len = 158 int func_bytes_len =
154 GetFunctionOffsetAndLength(debug_info, func_index).second; 159 GetFunctionOffsetAndLength(debug_info, func_index).second;
155 Handle<FixedArray> line_ends = isolate->factory()->NewFixedArray(1, TENURED); 160 Handle<FixedArray> line_ends = isolate->factory()->NewFixedArray(1, TENURED);
156 line_ends->set(0, Smi::FromInt(func_bytes_len)); 161 line_ends->set(0, Smi::FromInt(func_bytes_len));
157 line_ends->set_map(isolate->heap()->fixed_cow_array_map()); 162 line_ends->set_map(isolate->heap()->fixed_cow_array_map());
158 script->set_line_ends(*line_ends); 163 script->set_line_ends(*line_ends);
159 164
160 // TODO(clemensh): Register this new script at the debugger. 165 isolate->debug()->OnAfterCompile(script);
161 166
162 return *script; 167 return *script;
163 } 168 }
164 169
165 Handle<String> WasmDebugInfo::DisassembleFunction( 170 Handle<String> WasmDebugInfo::DisassembleFunction(
166 Handle<WasmDebugInfo> debug_info, int func_index) { 171 Handle<WasmDebugInfo> debug_info, int func_index) {
167 std::ostringstream disassembly_os; 172 std::ostringstream disassembly_os;
168 173
169 { 174 {
170 Vector<const uint8_t> bytes_vec = GetFunctionBytes(debug_info, func_index); 175 Vector<const uint8_t> bytes_vec = GetFunctionBytes(debug_info, func_index);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 int idx = 0; 221 int idx = 0;
217 for (std::tuple<uint32_t, int, int> elem : offset_table_vec) { 222 for (std::tuple<uint32_t, int, int> elem : offset_table_vec) {
218 offset_table->set(idx++, Smi::FromInt(std::get<0>(elem))); 223 offset_table->set(idx++, Smi::FromInt(std::get<0>(elem)));
219 offset_table->set(idx++, Smi::FromInt(std::get<1>(elem))); 224 offset_table->set(idx++, Smi::FromInt(std::get<1>(elem)));
220 offset_table->set(idx++, Smi::FromInt(std::get<2>(elem))); 225 offset_table->set(idx++, Smi::FromInt(std::get<2>(elem)));
221 } 226 }
222 DCHECK_EQ(idx, offset_table->length()); 227 DCHECK_EQ(idx, offset_table->length());
223 228
224 return offset_table; 229 return offset_table;
225 } 230 }
OLDNEW
« no previous file with comments | « src/wasm/ast-decoder.cc ('k') | test/mjsunit/wasm/debug-disassembly.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698