Commit bc0ca547 authored by Philip Pfaffe's avatar Philip Pfaffe Committed by V8 LUCI CQ

Add a wasm disassembly API to cdp

Thic CL adds a CDP API skeleton that will be used to disassemble WASM
modules using V8's new disassembler.

Bug: v8:12917, chromium:1325626
Change-Id: I4ca81aca923e9716653cd90367e5fad319483aae
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3721381Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Philip Pfaffe <pfaffe@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81809}
parent 0460e63f
......@@ -244,6 +244,40 @@ domain Debugger
# Wasm bytecode.
optional binary bytecode
experimental type WasmDisassemblyChunk extends object
properties
# The next chunk of disassembled lines.
array of string lines
# The bytecode offsets describing the start of each line.
array of integer bytecodeOffsets
experimental command disassembleWasmModule
parameters
# Id of the script to disassemble
Runtime.ScriptId scriptId
returns
# For large modules, return a stream from which additional chunks of
# disassembly can be read successively.
optional string streamId
# The total number of lines in the disassembly text.
integer totalNumberOfLines
# The offsets of all function bodies plus one additional entry pointing
# one by past the end of the last function.
array of integer functionBodyOffsets
# The first chunk of disassembly.
WasmDisassemblyChunk chunk
# Disassemble the next chunk of lines for the module corresponding to the
# stream. If disassembly is complete, this API will invalidate the streamId
# and return an empty chunk. Any subsequent calls for the now invalid stream
# will return errors.
experimental command nextWasmDisassemblyChunk
parameters
string streamId
returns
# The next chunk of disassembly.
WasmDisassemblyChunk chunk
# This command is deprecated. Use getScriptSource instead.
deprecated command getWasmBytecode
parameters
......
......@@ -5,6 +5,7 @@
#include "src/inspector/v8-debugger-agent-impl.h"
#include <algorithm>
#include <memory>
#include "../../third_party/inspector_protocol/crdtp/json.h"
#include "include/v8-context.h"
......@@ -1130,6 +1131,41 @@ Response V8DebuggerAgentImpl::getScriptSource(
#endif // V8_ENABLE_WEBASSEMBLY
return Response::Success();
}
Response V8DebuggerAgentImpl::disassembleWasmModule(
const String16& in_scriptId, Maybe<String16>* out_streamId,
int* out_totalNumberOfLines,
std::unique_ptr<protocol::Array<int>>* out_functionBodyOffsets,
std::unique_ptr<protocol::Debugger::WasmDisassemblyChunk>* out_chunk) {
#if V8_ENABLE_WEBASSEMBLY
std::vector<String16> lines{{"a", "b", "c"}};
std::vector<int> lineOffsets{{0, 4, 8}};
*out_functionBodyOffsets = std::make_unique<protocol::Array<int>>();
*out_chunk =
protocol::Debugger::WasmDisassemblyChunk::create()
.setBytecodeOffsets(
std::make_unique<protocol::Array<int>>(std::move(lineOffsets)))
.setLines(
std::make_unique<protocol::Array<String16>>(std::move(lines)))
.build();
*out_totalNumberOfLines = 3;
return Response::Success();
#else
return Response::ServerError("WebAssembly is disabled");
#endif // V8_ENABLE_WEBASSEMBLY
}
Response V8DebuggerAgentImpl::nextWasmDisassemblyChunk(
const String16& in_streamId,
std::unique_ptr<protocol::Debugger::WasmDisassemblyChunk>* out_chunk) {
#if V8_ENABLE_WEBASSEMBLY
*out_chunk = protocol::Debugger::WasmDisassemblyChunk::create()
.setBytecodeOffsets(std::make_unique<protocol::Array<int>>())
.setLines(std::make_unique<protocol::Array<String16>>())
.build();
return Response::Success();
#else
return Response::ServerError("WebAssembly is disabled");
#endif // V8_ENABLE_WEBASSEMBLY
}
Response V8DebuggerAgentImpl::getWasmBytecode(const String16& scriptId,
protocol::Binary* bytecode) {
......
......@@ -98,6 +98,16 @@ class V8DebuggerAgentImpl : public protocol::Debugger::Backend {
Maybe<protocol::Runtime::StackTraceId>* asyncStackTraceId) override;
Response getScriptSource(const String16& scriptId, String16* scriptSource,
Maybe<protocol::Binary>* bytecode) override;
Response disassembleWasmModule(
const String16& in_scriptId, Maybe<String16>* out_streamId,
int* out_totalNumberOfLines,
std::unique_ptr<protocol::Array<int>>* out_functionBodyOffsets,
std::unique_ptr<protocol::Debugger::WasmDisassemblyChunk>* out_chunk)
override;
Response nextWasmDisassemblyChunk(
const String16& in_streamId,
std::unique_ptr<protocol::Debugger::WasmDisassemblyChunk>* out_chunk)
override;
Response getWasmBytecode(const String16& scriptId,
protocol::Binary* bytecode) override;
Response pause() override;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment