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

Side by Side Diff: src/inspector/wasm-translation.cc

Issue 2536763002: [inspector] [wasm] Implement GetPossibleBreakpoints (Closed)
Patch Set: Rebase Created 4 years 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/inspector/v8-debugger-script.cc ('k') | src/wasm/wasm-objects.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/inspector/wasm-translation.h" 5 #include "src/inspector/wasm-translation.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "src/debug/debug-interface.h" 9 #include "src/debug/debug-interface.h"
10 #include "src/inspector/protocol/Debugger.h" 10 #include "src/inspector/protocol/Debugger.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 loc->line = 0; 95 loc->line = 0;
96 loc->column = 0; 96 loc->column = 0;
97 } 97 }
98 } 98 }
99 99
100 void TranslateBack(TransLocation *loc) { 100 void TranslateBack(TransLocation *loc) {
101 int func_index = GetFunctionIndexFromFakeScriptId(loc->script_id); 101 int func_index = GetFunctionIndexFromFakeScriptId(loc->script_id);
102 const OffsetTable *reverse_table = GetReverseTable(func_index); 102 const OffsetTable *reverse_table = GetReverseTable(func_index);
103 if (!reverse_table) return; 103 if (!reverse_table) return;
104 DCHECK(!reverse_table->empty()); 104 DCHECK(!reverse_table->empty());
105 v8::Isolate *isolate = loc->translation->isolate_;
105 106
106 // Binary search for the given line and column. 107 // Binary search for the given line and column.
107 unsigned left = 0; // inclusive 108 unsigned left = 0; // inclusive
108 unsigned right = static_cast<unsigned>(reverse_table->size()); // exclusive 109 unsigned right = static_cast<unsigned>(reverse_table->size()); // exclusive
109 while (right - left > 1) { 110 while (right - left > 1) {
110 unsigned mid = (left + right) / 2; 111 unsigned mid = (left + right) / 2;
111 auto &entry = (*reverse_table)[mid]; 112 auto &entry = (*reverse_table)[mid];
112 if (std::get<1>(entry) < loc->line || 113 if (std::get<1>(entry) < loc->line ||
113 (std::get<1>(entry) == loc->line && 114 (std::get<1>(entry) == loc->line &&
114 std::get<2>(entry) <= loc->column)) { 115 std::get<2>(entry) <= loc->column)) {
115 left = mid; 116 left = mid;
116 } else { 117 } else {
117 right = mid; 118 right = mid;
118 } 119 }
119 } 120 }
120 121
121 int found_byte_offset = 0; 122 int found_byte_offset = 0;
122 // If we found an exact match, use it. Otherwise check whether the next 123 // If we found an exact match, use it. Otherwise check whether the next
123 // bigger entry is still in the same line. Report that one then. 124 // bigger entry is still in the same line. Report that one then.
125 // Otherwise we might have hit the special case of pointing after the last
126 // line, which is translated to the end of the function (one byte after the
127 // last function byte).
124 if (std::get<1>((*reverse_table)[left]) == loc->line && 128 if (std::get<1>((*reverse_table)[left]) == loc->line &&
125 std::get<2>((*reverse_table)[left]) == loc->column) { 129 std::get<2>((*reverse_table)[left]) == loc->column) {
126 found_byte_offset = std::get<0>((*reverse_table)[left]); 130 found_byte_offset = std::get<0>((*reverse_table)[left]);
127 } else if (left + 1 < reverse_table->size() && 131 } else if (left + 1 < reverse_table->size() &&
128 std::get<1>((*reverse_table)[left + 1]) == loc->line) { 132 std::get<1>((*reverse_table)[left + 1]) == loc->line) {
129 found_byte_offset = std::get<0>((*reverse_table)[left + 1]); 133 found_byte_offset = std::get<0>((*reverse_table)[left + 1]);
134 } else if (left == reverse_table->size() - 1 &&
135 std::get<1>((*reverse_table)[left]) == loc->line - 1 &&
136 loc->column == 0) {
137 std::pair<int, int> func_range =
138 script_.Get(isolate)->GetFunctionRange(func_index);
139 DCHECK_LE(func_range.first, func_range.second);
140 found_byte_offset = func_range.second - func_range.first;
130 } 141 }
131 142
132 v8::Isolate *isolate = loc->translation->isolate_;
133 loc->script_id = String16::fromInteger(script_.Get(isolate)->Id()); 143 loc->script_id = String16::fromInteger(script_.Get(isolate)->Id());
134 loc->line = func_index; 144 loc->line = func_index;
135 loc->column = found_byte_offset; 145 loc->column = found_byte_offset;
136 } 146 }
137 147
138 private: 148 private:
139 String16 GetScriptName(v8::Isolate *isolate) { 149 String16 GetScriptName(v8::Isolate *isolate) {
140 return toProtocolString(script_.Get(isolate)->Name().ToLocalChecked()); 150 return toProtocolString(script_.Get(isolate)->Name().ToLocalChecked());
141 } 151 }
142 152
(...skipping 22 matching lines...) Expand all
165 v8::Local<DebugInterface::WasmScript> script = script_.Get(isolate); 175 v8::Local<DebugInterface::WasmScript> script = script_.Get(isolate);
166 // TODO(clemensh): Generate disassembly lazily when queried by the frontend. 176 // TODO(clemensh): Generate disassembly lazily when queried by the frontend.
167 std::pair<std::string, OffsetTable> disassembly = 177 std::pair<std::string, OffsetTable> disassembly =
168 script->DisassembleFunction(func_idx); 178 script->DisassembleFunction(func_idx);
169 179
170 DCHECK_EQ(0, offset_tables_.count(func_idx)); 180 DCHECK_EQ(0, offset_tables_.count(func_idx));
171 offset_tables_.insert( 181 offset_tables_.insert(
172 std::make_pair(func_idx, std::move(disassembly.second))); 182 std::make_pair(func_idx, std::move(disassembly.second)));
173 String16 source(disassembly.first.data(), disassembly.first.length()); 183 String16 source(disassembly.first.data(), disassembly.first.length());
174 std::unique_ptr<V8DebuggerScript> fake_script = 184 std::unique_ptr<V8DebuggerScript> fake_script =
175 V8DebuggerScript::CreateWasm(isolate, script, fake_script_id, 185 V8DebuggerScript::CreateWasm(isolate, script, translation,
176 std::move(fake_script_url), source); 186 fake_script_id, std::move(fake_script_url),
187 source);
177 188
178 translation->AddFakeScript(fake_script->scriptId(), this); 189 translation->AddFakeScript(fake_script->scriptId(), this);
179 agent->didParseSource(std::move(fake_script), true); 190 agent->didParseSource(std::move(fake_script), true);
180 } 191 }
181 192
182 int GetFunctionIndexFromFakeScriptId(const String16 &fake_script_id) { 193 int GetFunctionIndexFromFakeScriptId(const String16 &fake_script_id) {
183 size_t last_dash_pos = fake_script_id.reverseFind('-'); 194 size_t last_dash_pos = fake_script_id.reverseFind('-');
184 DCHECK_GT(fake_script_id.length(), last_dash_pos); 195 DCHECK_GT(fake_script_id.length(), last_dash_pos);
185 bool ok = true; 196 bool ok = true;
186 int func_index = fake_script_id.substring(last_dash_pos + 1).toInteger(&ok); 197 int func_index = fake_script_id.substring(last_dash_pos + 1).toInteger(&ok);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 *column_number = trans_loc.column; 309 *column_number = trans_loc.column;
299 310
300 return true; 311 return true;
301 } 312 }
302 313
303 void WasmTranslation::AddFakeScript(const String16 &scriptId, 314 void WasmTranslation::AddFakeScript(const String16 &scriptId,
304 TranslatorImpl *translator) { 315 TranslatorImpl *translator) {
305 DCHECK_EQ(0, fake_scripts_.count(scriptId)); 316 DCHECK_EQ(0, fake_scripts_.count(scriptId));
306 fake_scripts_.insert(std::make_pair(scriptId, translator)); 317 fake_scripts_.insert(std::make_pair(scriptId, translator));
307 } 318 }
OLDNEW
« no previous file with comments | « src/inspector/v8-debugger-script.cc ('k') | src/wasm/wasm-objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698