Skip to content

Commit

Permalink
add setBlackboxedRanges message type
Browse files Browse the repository at this point in the history
Summary:
Implement `Debugger.setBlackboxedRanges` that in the next diff would save a list of all the ranges that stepping into would trigger a subsequent step.
In the next diff it is also used in filtering out frames in stack traces coming from these ranges.

Even though this would land as part of the stack, if this is implemented on it's own, responding to `Debugger.setBlackboxedRanges` with:
```
sendResponseToClient(m::makeErrorResponse(
      req.id,
      m::ErrorCode::MethodNotFound,
      "setBlackboxedRanges is not implemented yet")
```
Does not affect the UX in any way.

Reviewed By: dannysu, huntie

Differential Revision: D62762751

fbshipit-source-id: 0430e8e0460c47ec6b05f014e736720c08c60085
  • Loading branch information
vzaidman authored and facebook-github-bot committed Oct 15, 2024
1 parent 379c024 commit 63289a8
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 3 deletions.
3 changes: 3 additions & 0 deletions API/hermes/cdp/CDPAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,9 @@ void CDPAgentImpl::DomainAgentsImpl::handleCommand(
} else if (method == "stepOver") {
debuggerAgent_->stepOver(
static_cast<m::debugger::StepOverRequest &>(*command));
} else if (method == "setBlackboxedRanges") {
debuggerAgent_->setBlackboxedRanges(
static_cast<m::debugger::SetBlackboxedRangesRequest &>(*command));
} else if (method == "setPauseOnExceptions") {
debuggerAgent_->setPauseOnExceptions(
static_cast<m::debugger::SetPauseOnExceptionsRequest &>(*command));
Expand Down
8 changes: 8 additions & 0 deletions API/hermes/cdp/DebuggerDomainAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,14 @@ void DebuggerDomainAgent::stepOver(const m::debugger::StepOverRequest &req) {
sendResponseToClient(m::makeOkResponse(req.id));
}

void DebuggerDomainAgent::setBlackboxedRanges(
const m::debugger::SetBlackboxedRangesRequest &req) {
sendResponseToClient(m::makeErrorResponse(
req.id,
m::ErrorCode::MethodNotFound,
"setBlackboxedRanges is not implemented yet"));
}

void DebuggerDomainAgent::setPauseOnExceptions(
const m::debugger::SetPauseOnExceptionsRequest &req) {
if (!checkDebuggerEnabled(req)) {
Expand Down
3 changes: 3 additions & 0 deletions API/hermes/cdp/DebuggerDomainAgent.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ class DebuggerDomainAgent : public DomainAgent {
/// Handles Debugger.stepOver request
void stepOver(const m::debugger::StepOverRequest &req);

/// Handles Debugger.setBlackboxedRanges request
void setBlackboxedRanges(const m::debugger::SetBlackboxedRangesRequest &req);

/// Handles Debugger.setPauseOnExceptions
void setPauseOnExceptions(
const m::debugger::SetPauseOnExceptionsRequest &req);
Expand Down
66 changes: 65 additions & 1 deletion API/hermes/cdp/MessageTypes.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Meta Platforms, Inc. and affiliates. All Rights Reserved.
// @generated SignedSource<<da57bd95099acd0d931a2ed451676ff8>>
// @generated SignedSource<<c5d806e6bc7d2a1f696a1cf32e7e06cb>>

#include "MessageTypes.h"

Expand Down Expand Up @@ -97,6 +97,8 @@ std::unique_ptr<Request> Request::fromJson(const std::string &str) {
{"Debugger.pause", tryMake<debugger::PauseRequest>},
{"Debugger.removeBreakpoint", tryMake<debugger::RemoveBreakpointRequest>},
{"Debugger.resume", tryMake<debugger::ResumeRequest>},
{"Debugger.setBlackboxedRanges",
tryMake<debugger::SetBlackboxedRangesRequest>},
{"Debugger.setBreakpoint", tryMake<debugger::SetBreakpointRequest>},
{"Debugger.setBreakpointByUrl",
tryMake<debugger::SetBreakpointByUrlRequest>},
Expand Down Expand Up @@ -422,6 +424,23 @@ JSONValue *debugger::CallFrame::toJsonVal(JSONFactory &factory) const {
return factory.newObject(props.begin(), props.end());
}

std::unique_ptr<debugger::ScriptPosition> debugger::ScriptPosition::tryMake(
const JSONObject *obj) {
std::unique_ptr<debugger::ScriptPosition> type =
std::make_unique<debugger::ScriptPosition>();
TRY_ASSIGN(type->lineNumber, obj, "lineNumber");
TRY_ASSIGN(type->columnNumber, obj, "columnNumber");
return type;
}

JSONValue *debugger::ScriptPosition::toJsonVal(JSONFactory &factory) const {
llvh::SmallVector<JSONFactory::Prop, 2> props;

put(props, "lineNumber", lineNumber, factory);
put(props, "columnNumber", columnNumber, factory);
return factory.newObject(props.begin(), props.end());
}

std::unique_ptr<heapProfiler::SamplingHeapProfileNode>
heapProfiler::SamplingHeapProfileNode::tryMake(const JSONObject *obj) {
std::unique_ptr<heapProfiler::SamplingHeapProfileNode> type =
Expand Down Expand Up @@ -869,6 +888,51 @@ void debugger::ResumeRequest::accept(RequestHandler &handler) const {
handler.handle(*this);
}

debugger::SetBlackboxedRangesRequest::SetBlackboxedRangesRequest()
: Request("Debugger.setBlackboxedRanges") {}

std::unique_ptr<debugger::SetBlackboxedRangesRequest>
debugger::SetBlackboxedRangesRequest::tryMake(const JSONObject *obj) {
std::unique_ptr<debugger::SetBlackboxedRangesRequest> req =
std::make_unique<debugger::SetBlackboxedRangesRequest>();
TRY_ASSIGN(req->id, obj, "id");
TRY_ASSIGN(req->method, obj, "method");

JSONValue *v = obj->get("params");
if (v == nullptr) {
return nullptr;
}
auto convertResult = valueFromJson<JSONObject *>(v);
if (!convertResult) {
return nullptr;
}
auto *params = *convertResult;
TRY_ASSIGN(req->scriptId, params, "scriptId");
TRY_ASSIGN(req->positions, params, "positions");
return req;
}

JSONValue *debugger::SetBlackboxedRangesRequest::toJsonVal(
JSONFactory &factory) const {
llvh::SmallVector<JSONFactory::Prop, 2> paramsProps;
put(paramsProps, "scriptId", scriptId, factory);
put(paramsProps, "positions", positions, factory);

llvh::SmallVector<JSONFactory::Prop, 1> props;
put(props, "id", id, factory);
put(props, "method", method, factory);
put(props,
"params",
factory.newObject(paramsProps.begin(), paramsProps.end()),
factory);
return factory.newObject(props.begin(), props.end());
}

void debugger::SetBlackboxedRangesRequest::accept(
RequestHandler &handler) const {
handler.handle(*this);
}

debugger::SetBreakpointRequest::SetBreakpointRequest()
: Request("Debugger.setBreakpoint") {}

Expand Down
31 changes: 30 additions & 1 deletion API/hermes/cdp/MessageTypes.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Meta Platforms, Inc. and affiliates. All Rights Reserved.
// @generated SignedSource<<cedec18119ebdcfb5d5e9616cf9b28bd>>
// @generated SignedSource<<c0e78c8bc8eb1a38a58038991c7b0fdf>>

#pragma once

Expand Down Expand Up @@ -36,6 +36,8 @@ struct ResumeRequest;
struct ResumedNotification;
struct Scope;
struct ScriptParsedNotification;
struct ScriptPosition;
struct SetBlackboxedRangesRequest;
struct SetBreakpointByUrlRequest;
struct SetBreakpointByUrlResponse;
struct SetBreakpointRequest;
Expand Down Expand Up @@ -132,6 +134,7 @@ struct RequestHandler {
virtual void handle(const debugger::PauseRequest &req) = 0;
virtual void handle(const debugger::RemoveBreakpointRequest &req) = 0;
virtual void handle(const debugger::ResumeRequest &req) = 0;
virtual void handle(const debugger::SetBlackboxedRangesRequest &req) = 0;
virtual void handle(const debugger::SetBreakpointRequest &req) = 0;
virtual void handle(const debugger::SetBreakpointByUrlRequest &req) = 0;
virtual void handle(const debugger::SetBreakpointsActiveRequest &req) = 0;
Expand Down Expand Up @@ -177,6 +180,7 @@ struct NoopRequestHandler : public RequestHandler {
void handle(const debugger::PauseRequest &req) override {}
void handle(const debugger::RemoveBreakpointRequest &req) override {}
void handle(const debugger::ResumeRequest &req) override {}
void handle(const debugger::SetBlackboxedRangesRequest &req) override {}
void handle(const debugger::SetBreakpointRequest &req) override {}
void handle(const debugger::SetBreakpointByUrlRequest &req) override {}
void handle(const debugger::SetBreakpointsActiveRequest &req) override {}
Expand Down Expand Up @@ -401,6 +405,19 @@ struct debugger::CallFrame : public Serializable {
std::optional<runtime::RemoteObject> returnValue;
};

struct debugger::ScriptPosition : public Serializable {
ScriptPosition() = default;
ScriptPosition(ScriptPosition &&) = default;
ScriptPosition(const ScriptPosition &) = delete;
static std::unique_ptr<ScriptPosition> tryMake(const JSONObject *obj);
JSONValue *toJsonVal(JSONFactory &factory) const override;
ScriptPosition &operator=(const ScriptPosition &) = delete;
ScriptPosition &operator=(ScriptPosition &&) = default;

long long lineNumber{};
long long columnNumber{};
};

struct heapProfiler::SamplingHeapProfileNode : public Serializable {
SamplingHeapProfileNode() = default;
SamplingHeapProfileNode(SamplingHeapProfileNode &&) = default;
Expand Down Expand Up @@ -635,6 +652,18 @@ struct debugger::ResumeRequest : public Request {
std::optional<bool> terminateOnResume;
};

struct debugger::SetBlackboxedRangesRequest : public Request {
SetBlackboxedRangesRequest();
static std::unique_ptr<SetBlackboxedRangesRequest> tryMake(
const JSONObject *obj);

JSONValue *toJsonVal(JSONFactory &factory) const override;
void accept(RequestHandler &handler) const override;

runtime::ScriptId scriptId{};
std::vector<debugger::ScriptPosition> positions;
};

struct debugger::SetBreakpointRequest : public Request {
SetBreakpointRequest();
static std::unique_ptr<SetBreakpointRequest> tryMake(const JSONObject *obj);
Expand Down
1 change: 1 addition & 0 deletions API/hermes/cdp/tools/message_types.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Debugger.setPauseOnExceptions
Debugger.stepInto
Debugger.stepOut
Debugger.stepOver
Debugger.setBlackboxedRanges
HeapProfiler.addHeapSnapshotChunk
HeapProfiler.collectGarbage
HeapProfiler.reportHeapSnapshotProgress
Expand Down
2 changes: 1 addition & 1 deletion API/hermes/cdp/tools/run_msggen
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ yarn build

node bin/index.js \
--ignore-experimental \
--include-experimental=Runtime.inspectRequested.executionContextId,Runtime.getProperties.generatePreview,Runtime.getProperties.accessorPropertiesOnly,Runtime.evaluate.generatePreview,Runtime.callFunctionOn.generatePreview,Debugger.evaluateOnCallFrame.generatePreview,Runtime.RemoteObject.preview,Runtime.RemoteObject.customPreview,Runtime.CustomPreview,Runtime.EntryPreview,Runtime.ObjectPreview,Runtime.PropertyPreview,Runtime.getHeapUsage \
--include-experimental=Debugger.ScriptPosition,Debugger.setBlackboxedRanges,Runtime.inspectRequested.executionContextId,Runtime.getProperties.generatePreview,Runtime.getProperties.accessorPropertiesOnly,Runtime.evaluate.generatePreview,Runtime.callFunctionOn.generatePreview,Debugger.evaluateOnCallFrame.generatePreview,Runtime.RemoteObject.preview,Runtime.RemoteObject.customPreview,Runtime.CustomPreview,Runtime.EntryPreview,Runtime.ObjectPreview,Runtime.PropertyPreview,Runtime.getHeapUsage \
--roots "${MSGTYPES_PATH}" \
"${HEADER_PATH}" "${CPP_PATH}"

Expand Down

0 comments on commit 63289a8

Please sign in to comment.