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

Unified Diff: src/inspector/v8-debugger-script.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/inspector/v8-debugger-script.h ('k') | src/inspector/wasm-translation.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/inspector/v8-debugger-script.cc
diff --git a/src/inspector/v8-debugger-script.cc b/src/inspector/v8-debugger-script.cc
index d5a29c38ed74fd62eafb064d154cd26279236e03..7b0bea7b655fe9949de6d7cbe7448aba419e7970 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,32 @@ 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;
+ wasmTranslation->TranslateWasmScriptLocationToProtocolLocation(
+ &translatedScriptId, &lineNumber, &columnNumber);
+ DCHECK_EQ(expectedProtocolScriptId.utf8(), translatedScriptId.utf8());
+ *loc = v8::DebugInterface::Location(lineNumber, columnNumber);
+}
+
class ActualScript : public V8DebuggerScript {
friend class V8DebuggerScript;
@@ -183,9 +210,11 @@ class WasmVirtualScript : public V8DebuggerScript {
public:
WasmVirtualScript(v8::Isolate* isolate,
v8::Local<v8::DebugInterface::WasmScript> script,
- String16 id, String16 url, String16 source)
+ WasmTranslation* translation, String16 id, String16 url,
+ String16 source)
: V8DebuggerScript(isolate, std::move(id), std::move(url)),
- m_script(isolate, script) {
+ m_script(isolate, script),
+ m_wasmTranslation(translation) {
int num_lines = 0;
int last_newline = -1;
size_t next_newline = source.find('\n', last_newline + 1);
@@ -210,10 +239,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:
@@ -223,6 +272,7 @@ class WasmVirtualScript : public V8DebuggerScript {
}
v8::Global<v8::DebugInterface::WasmScript> m_script;
+ WasmTranslation* m_wasmTranslation;
};
} // namespace
@@ -236,11 +286,11 @@ std::unique_ptr<V8DebuggerScript> V8DebuggerScript::Create(
std::unique_ptr<V8DebuggerScript> V8DebuggerScript::CreateWasm(
v8::Isolate* isolate,
- v8::Local<v8::DebugInterface::WasmScript> underlyingScript, String16 id,
- String16 url, String16 source) {
+ v8::Local<v8::DebugInterface::WasmScript> underlyingScript,
+ WasmTranslation* translation, String16 id, String16 url, String16 source) {
return std::unique_ptr<WasmVirtualScript>(
- new WasmVirtualScript(isolate, underlyingScript, std::move(id),
- std::move(url), std::move(source)));
+ new WasmVirtualScript(isolate, underlyingScript, translation,
+ std::move(id), std::move(url), std::move(source)));
}
V8DebuggerScript::~V8DebuggerScript() {}
« no previous file with comments | « src/inspector/v8-debugger-script.h ('k') | src/inspector/wasm-translation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698