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

Unified Diff: src/inspector/v8-debugger-script.cc

Issue 2536763002: [inspector] [wasm] Implement GetPossibleBreakpoints (Closed)
Patch Set: Rebase Created 4 years, 1 month 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
Index: src/inspector/v8-debugger-script.cc
diff --git a/src/inspector/v8-debugger-script.cc b/src/inspector/v8-debugger-script.cc
index fc2ed02cb44cf884ddf9511d2266a8c521118869..b80a73f93ad135aaf6e76678997ea1d7152fbf23 100644
--- a/src/inspector/v8-debugger-script.cc
+++ b/src/inspector/v8-debugger-script.cc
@@ -5,6 +5,7 @@
#include "src/inspector/v8-debugger-script.h"
#include "src/inspector/string-util.h"
+#include "src/inspector/wasm-translation.h"
namespace v8_inspector {
@@ -68,6 +69,36 @@ String16 calculateHash(const String16& str) {
return hash.toString();
}
+void TranslateProtocolLocationToV8Location(WasmTranslation* wasmTranslation,
+ v8::DebugInterface::Location* loc,
+ const String16& scriptId,
+ const String16& expectedV8ScriptId) {
+ if (loc->IsEmpty()) return;
+ int lineNumber = loc->GetLineNumber();
+ int columnNumber = loc->GetColumnNumber();
+ String16 translatedScriptId = scriptId;
+ wasmTranslation->TranslateProtocolLocationToWasmScriptLocation(
+ &translatedScriptId, &lineNumber, &columnNumber);
+ DCHECK_EQ(expectedV8ScriptId.utf8(), translatedScriptId.utf8());
+ *loc = v8::DebugInterface::Location(lineNumber, columnNumber);
+}
+
+void TranslateV8LocationToProtocolLocation(
+ WasmTranslation* wasmTranslation, v8::DebugInterface::Location* loc,
+ const String16& scriptId, const String16& expectedProtocolScriptId) {
+ int lineNumber = loc->GetLineNumber();
+ int columnNumber = loc->GetColumnNumber();
+ String16 translatedScriptId = scriptId;
+ // This call should never trigger a new fake script to be created, so passing
+ // -1 as contextGroupId is fine. A DCHECK in the wasm translation will fail
+ // whenever this contextGroupId is used to find the corrensponding debugger
+ // agent.
+ wasmTranslation->TranslateWasmScriptLocationToProtocolLocation(
+ &translatedScriptId, &lineNumber, &columnNumber, -1);
+ DCHECK_EQ(expectedProtocolScriptId.utf8(), translatedScriptId.utf8());
+ *loc = v8::DebugInterface::Location(lineNumber, columnNumber);
+}
+
class ActualScript : public V8DebuggerScript {
friend class V8DebuggerScript;
@@ -123,10 +154,12 @@ class WasmVirtualScript : public V8DebuggerScript {
friend class V8DebuggerScript;
public:
- WasmVirtualScript(v8::Local<v8::DebugInterface::Script> script, String16 id,
- String16 url, String16 source)
+ WasmVirtualScript(v8::Local<v8::DebugInterface::Script> script,
+ WasmTranslation* translation, String16 id, String16 url,
+ String16 source)
: V8DebuggerScript(script->GetIsolate(), std::move(id), std::move(url)),
- m_script(script->GetIsolate(), script) {
+ m_script(script->GetIsolate(), script),
+ m_wasmTranslation(translation) {
m_source = std::move(source);
}
@@ -140,10 +173,30 @@ class WasmVirtualScript : public V8DebuggerScript {
const v8::DebugInterface::Location& start,
const v8::DebugInterface::Location& end,
std::vector<v8::DebugInterface::Location>* locations) override {
- // TODO(clemensh): Returning false produces the protocol error "Internal
- // error". Implement and fix expected output of
- // wasm-get-breakable-locations.js.
- return false;
+ v8::HandleScope scope(m_isolate);
+ v8::Local<v8::DebugInterface::Script> script = m_script.Get(m_isolate);
+ String16 v8ScriptId = String16::fromInteger(script->Id());
+
+ v8::DebugInterface::Location translatedStart = start;
+ TranslateProtocolLocationToV8Location(m_wasmTranslation, &translatedStart,
+ scriptId(), v8ScriptId);
+
+ v8::DebugInterface::Location translatedEnd = end;
+ TranslateProtocolLocationToV8Location(m_wasmTranslation, &translatedEnd,
+ scriptId(), v8ScriptId);
+ if (translatedEnd.IsEmpty()) {
+ // Stop before the start of the next function.
+ translatedEnd =
+ v8::DebugInterface::Location(translatedStart.GetLineNumber() + 1, 0);
+ }
+
+ bool success = script->GetPossibleBreakpoints(translatedStart,
+ translatedEnd, locations);
+ for (v8::DebugInterface::Location& loc : *locations) {
+ TranslateV8LocationToProtocolLocation(m_wasmTranslation, &loc, v8ScriptId,
+ scriptId());
+ }
+ return success;
}
private:
@@ -153,6 +206,7 @@ class WasmVirtualScript : public V8DebuggerScript {
}
v8::Global<v8::DebugInterface::Script> m_script;
+ WasmTranslation* m_wasmTranslation;
};
} // namespace
@@ -224,7 +278,8 @@ std::unique_ptr<V8DebuggerScript> V8DebuggerScript::Create(
}
std::unique_ptr<V8DebuggerScript> V8DebuggerScript::CreateWasm(
- v8::Local<v8::DebugInterface::Script> script, String16 id, String16 url,
+ v8::Local<v8::DebugInterface::Script> script,
+ WasmTranslation* wasmTranslation, String16 id, String16 url,
String16 source) {
int num_lines = 0;
int last_newline = -1;
@@ -236,8 +291,9 @@ std::unique_ptr<V8DebuggerScript> V8DebuggerScript::CreateWasm(
}
int m_endLine = num_lines;
int m_endColumn = static_cast<int>(source.length()) - last_newline - 1;
- return std::unique_ptr<WasmVirtualScript>(new WasmVirtualScript(
- script, std::move(id), std::move(url), std::move(source)));
+ return std::unique_ptr<WasmVirtualScript>(
+ new WasmVirtualScript(script, wasmTranslation, std::move(id),
+ std::move(url), std::move(source)));
}
V8DebuggerScript::~V8DebuggerScript() {}

Powered by Google App Engine
This is Rietveld 408576698