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

Unified Diff: src/inspector/wasm-translation.cc

Issue 2655653003: [inspector] Expose GetPossibleBreakpoints for wasm (Closed)
Patch Set: Introduce Init method and clang-format wasm-translation.cc Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/inspector/v8-debugger-script.cc ('k') | src/runtime/runtime-debug.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/inspector/wasm-translation.cc
diff --git a/src/inspector/wasm-translation.cc b/src/inspector/wasm-translation.cc
index 825341e122d06ec0efa9377d5c53da77a8df93b2..c545b9b6853324de04ee3783820f2a1f45529f22 100644
--- a/src/inspector/wasm-translation.cc
+++ b/src/inspector/wasm-translation.cc
@@ -21,11 +21,11 @@ using namespace v8;
class WasmTranslation::TranslatorImpl {
public:
struct TransLocation {
- WasmTranslation *translation;
+ WasmTranslation* translation;
String16 script_id;
int line;
int column;
- TransLocation(WasmTranslation *translation, String16 script_id, int line,
+ TransLocation(WasmTranslation* translation, String16 script_id, int line,
int column)
: translation(translation),
script_id(script_id),
@@ -33,8 +33,9 @@ class WasmTranslation::TranslatorImpl {
column(column) {}
};
- virtual void Translate(TransLocation *loc) = 0;
- virtual void TranslateBack(TransLocation *loc) = 0;
+ virtual void Init(Isolate*, WasmTranslation*, V8DebuggerAgentImpl*) = 0;
+ virtual void Translate(TransLocation*) = 0;
+ virtual void TranslateBack(TransLocation*) = 0;
class RawTranslator;
class DisassemblingTranslator;
@@ -43,8 +44,9 @@ class WasmTranslation::TranslatorImpl {
class WasmTranslation::TranslatorImpl::RawTranslator
: public WasmTranslation::TranslatorImpl {
public:
- void Translate(TransLocation *loc) {}
- void TranslateBack(TransLocation *loc) {}
+ void Init(Isolate*, WasmTranslation*, V8DebuggerAgentImpl*) {}
+ void Translate(TransLocation*) {}
+ void TranslateBack(TransLocation*) {}
};
class WasmTranslation::TranslatorImpl::DisassemblingTranslator
@@ -52,11 +54,13 @@ class WasmTranslation::TranslatorImpl::DisassemblingTranslator
using OffsetTable = debug::WasmDisassembly::OffsetTable;
public:
- DisassemblingTranslator(Isolate *isolate, Local<debug::WasmScript> script,
- WasmTranslation *translation,
- V8DebuggerAgentImpl *agent)
- : script_(isolate, script) {
+ DisassemblingTranslator(Isolate* isolate, Local<debug::WasmScript> script)
+ : script_(isolate, script) {}
+
+ void Init(Isolate* isolate, WasmTranslation* translation,
+ V8DebuggerAgentImpl* agent) override {
// Register fake scripts for each function in this wasm module/script.
+ Handle<debug::WasmScript> script = script_.Get(isolate);
int num_functions = script->NumFunctions();
int num_imported_functions = script->NumImportedFunctions();
DCHECK_LE(0, num_imported_functions);
@@ -69,8 +73,8 @@ class WasmTranslation::TranslatorImpl::DisassemblingTranslator
}
}
- void Translate(TransLocation *loc) {
- const OffsetTable &offset_table = GetOffsetTable(loc);
+ void Translate(TransLocation* loc) override {
+ const OffsetTable& offset_table = GetOffsetTable(loc);
DCHECK(!offset_table.empty());
uint32_t byte_offset = static_cast<uint32_t>(loc->column);
@@ -96,18 +100,19 @@ class WasmTranslation::TranslatorImpl::DisassemblingTranslator
}
}
- void TranslateBack(TransLocation *loc) {
+ void TranslateBack(TransLocation* loc) override {
int func_index = GetFunctionIndexFromFakeScriptId(loc->script_id);
- const OffsetTable *reverse_table = GetReverseTable(func_index);
+ const OffsetTable* reverse_table = GetReverseTable(func_index);
if (!reverse_table) return;
DCHECK(!reverse_table->empty());
+ v8::Isolate* isolate = loc->translation->isolate_;
// Binary search for the given line and column.
unsigned left = 0; // inclusive
unsigned right = static_cast<unsigned>(reverse_table->size()); // exclusive
while (right - left > 1) {
unsigned mid = (left + right) / 2;
- auto &entry = (*reverse_table)[mid];
+ auto& entry = (*reverse_table)[mid];
if (entry.line < loc->line ||
(entry.line == loc->line && entry.column <= loc->column)) {
left = mid;
@@ -119,22 +124,31 @@ class WasmTranslation::TranslatorImpl::DisassemblingTranslator
int found_byte_offset = 0;
// If we found an exact match, use it. Otherwise check whether the next
// bigger entry is still in the same line. Report that one then.
+ // Otherwise we might have hit the special case of pointing after the last
+ // line, which is translated to the end of the function (one byte after the
+ // last function byte).
if ((*reverse_table)[left].line == loc->line &&
(*reverse_table)[left].column == loc->column) {
found_byte_offset = (*reverse_table)[left].byte_offset;
} else if (left + 1 < reverse_table->size() &&
(*reverse_table)[left + 1].line == loc->line) {
found_byte_offset = (*reverse_table)[left + 1].byte_offset;
+ } else if (left == reverse_table->size() - 1 &&
+ (*reverse_table)[left].line == loc->line - 1 &&
+ loc->column == 0) {
+ std::pair<int, int> func_range =
+ script_.Get(isolate)->GetFunctionRange(func_index);
+ DCHECK_LE(func_range.first, func_range.second);
+ found_byte_offset = func_range.second - func_range.first;
}
- v8::Isolate *isolate = loc->translation->isolate_;
loc->script_id = String16::fromInteger(script_.Get(isolate)->Id());
loc->line = func_index;
loc->column = found_byte_offset;
}
private:
- String16 GetFakeScriptUrl(v8::Isolate *isolate, int func_index) {
+ String16 GetFakeScriptUrl(v8::Isolate* isolate, int func_index) {
Local<debug::WasmScript> script = script_.Get(isolate);
String16 script_name = toProtocolString(script->Name().ToLocalChecked());
int numFunctions = script->NumFunctions();
@@ -157,13 +171,13 @@ class WasmTranslation::TranslatorImpl::DisassemblingTranslator
String16 GetFakeScriptId(const String16 script_id, int func_index) {
return String16::concat(script_id, '-', String16::fromInteger(func_index));
}
- String16 GetFakeScriptId(const TransLocation *loc) {
+ String16 GetFakeScriptId(const TransLocation* loc) {
return GetFakeScriptId(loc->script_id, loc->line);
}
- void AddFakeScript(v8::Isolate *isolate, const String16 &underlyingScriptId,
- int func_idx, WasmTranslation *translation,
- V8DebuggerAgentImpl *agent) {
+ void AddFakeScript(v8::Isolate* isolate, const String16& underlyingScriptId,
+ int func_idx, WasmTranslation* translation,
+ V8DebuggerAgentImpl* agent) {
String16 fake_script_id = GetFakeScriptId(underlyingScriptId, func_idx);
String16 fake_script_url = GetFakeScriptUrl(isolate, func_idx);
@@ -177,14 +191,15 @@ class WasmTranslation::TranslatorImpl::DisassemblingTranslator
String16 source(disassembly.disassembly.data(),
disassembly.disassembly.length());
std::unique_ptr<V8DebuggerScript> fake_script =
- V8DebuggerScript::CreateWasm(isolate, script, fake_script_id,
- std::move(fake_script_url), source);
+ V8DebuggerScript::CreateWasm(isolate, translation, script,
+ fake_script_id, std::move(fake_script_url),
+ source);
translation->AddFakeScript(fake_script->scriptId(), this);
agent->didParseSource(std::move(fake_script), true);
}
- int GetFunctionIndexFromFakeScriptId(const String16 &fake_script_id) {
+ int GetFunctionIndexFromFakeScriptId(const String16& fake_script_id) {
size_t last_dash_pos = fake_script_id.reverseFind('-');
DCHECK_GT(fake_script_id.length(), last_dash_pos);
bool ok = true;
@@ -193,7 +208,7 @@ class WasmTranslation::TranslatorImpl::DisassemblingTranslator
return func_index;
}
- const OffsetTable &GetOffsetTable(const TransLocation *loc) {
+ const OffsetTable& GetOffsetTable(const TransLocation* loc) {
int func_index = loc->line;
auto it = offset_tables_.find(func_index);
// TODO(clemensh): Once we load disassembly lazily, the offset table
@@ -202,7 +217,7 @@ class WasmTranslation::TranslatorImpl::DisassemblingTranslator
return it->second;
}
- const OffsetTable *GetReverseTable(int func_index) {
+ const OffsetTable* GetReverseTable(int func_index) {
auto it = reverse_tables_.find(func_index);
if (it != reverse_tables_.end()) return &it->second;
@@ -233,27 +248,29 @@ class WasmTranslation::TranslatorImpl::DisassemblingTranslator
std::unordered_map<int, const OffsetTable> reverse_tables_;
};
-WasmTranslation::WasmTranslation(v8::Isolate *isolate)
+WasmTranslation::WasmTranslation(v8::Isolate* isolate)
: isolate_(isolate), mode_(Disassemble) {}
WasmTranslation::~WasmTranslation() { Clear(); }
void WasmTranslation::AddScript(Local<debug::WasmScript> script,
- V8DebuggerAgentImpl *agent) {
- int script_id = script->Id();
- DCHECK_EQ(0, wasm_translators_.count(script_id));
+ V8DebuggerAgentImpl* agent) {
std::unique_ptr<TranslatorImpl> impl;
switch (mode_) {
case Raw:
impl.reset(new TranslatorImpl::RawTranslator());
break;
case Disassemble:
- impl.reset(new TranslatorImpl::DisassemblingTranslator(isolate_, script,
- this, agent));
+ impl.reset(new TranslatorImpl::DisassemblingTranslator(isolate_, script));
break;
}
DCHECK(impl);
- wasm_translators_.insert(std::make_pair(script_id, std::move(impl)));
+ auto inserted =
+ wasm_translators_.insert(std::make_pair(script->Id(), std::move(impl)));
+ // Check that no mapping for this script id existed before.
+ DCHECK(inserted.second);
+ // impl has been moved, use the returned iterator to call Init.
+ inserted.first->second->Init(isolate_, this, agent);
}
void WasmTranslation::Clear() {
@@ -263,7 +280,7 @@ void WasmTranslation::Clear() {
// Translation "forward" (to artificial scripts).
bool WasmTranslation::TranslateWasmScriptLocationToProtocolLocation(
- String16 *script_id, int *line_number, int *column_number) {
+ String16* script_id, int* line_number, int* column_number) {
DCHECK(script_id && line_number && column_number);
bool ok = true;
int script_id_int = script_id->toInteger(&ok);
@@ -271,7 +288,7 @@ bool WasmTranslation::TranslateWasmScriptLocationToProtocolLocation(
auto it = wasm_translators_.find(script_id_int);
if (it == wasm_translators_.end()) return false;
- TranslatorImpl *translator = it->second.get();
+ TranslatorImpl* translator = it->second.get();
TranslatorImpl::TransLocation trans_loc(this, std::move(*script_id),
*line_number, *column_number);
@@ -286,10 +303,10 @@ bool WasmTranslation::TranslateWasmScriptLocationToProtocolLocation(
// Translation "backward" (from artificial to real scripts).
bool WasmTranslation::TranslateProtocolLocationToWasmScriptLocation(
- String16 *script_id, int *line_number, int *column_number) {
+ String16* script_id, int* line_number, int* column_number) {
auto it = fake_scripts_.find(*script_id);
if (it == fake_scripts_.end()) return false;
- TranslatorImpl *translator = it->second;
+ TranslatorImpl* translator = it->second;
TranslatorImpl::TransLocation trans_loc(this, std::move(*script_id),
*line_number, *column_number);
@@ -302,8 +319,8 @@ bool WasmTranslation::TranslateProtocolLocationToWasmScriptLocation(
return true;
}
-void WasmTranslation::AddFakeScript(const String16 &scriptId,
- TranslatorImpl *translator) {
+void WasmTranslation::AddFakeScript(const String16& scriptId,
+ TranslatorImpl* translator) {
DCHECK_EQ(0, fake_scripts_.count(scriptId));
fake_scripts_.insert(std::make_pair(scriptId, translator));
}
« no previous file with comments | « src/inspector/v8-debugger-script.cc ('k') | src/runtime/runtime-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698