2016-09-06 23:26:08 +00:00
|
|
|
// Copyright 2016 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef V8_V8_INSPECTOR_H_
|
|
|
|
#define V8_V8_INSPECTOR_H_
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <cctype>
|
|
|
|
|
|
|
|
#include <memory>
|
2019-10-30 00:58:34 +00:00
|
|
|
#include <unordered_map>
|
2016-09-06 23:26:08 +00:00
|
|
|
|
2020-04-27 16:29:03 +00:00
|
|
|
#include "v8.h" // NOLINT(build/include_directory)
|
2016-09-06 23:26:08 +00:00
|
|
|
|
|
|
|
namespace v8_inspector {
|
|
|
|
|
|
|
|
namespace protocol {
|
|
|
|
namespace Debugger {
|
|
|
|
namespace API {
|
|
|
|
class SearchMatch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
namespace Runtime {
|
|
|
|
namespace API {
|
|
|
|
class RemoteObject;
|
|
|
|
class StackTrace;
|
2019-09-19 04:48:11 +00:00
|
|
|
class StackTraceId;
|
2016-09-06 23:26:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
namespace Schema {
|
|
|
|
namespace API {
|
|
|
|
class Domain;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace protocol
|
|
|
|
|
2021-04-19 13:23:21 +00:00
|
|
|
class V8_EXPORT V8CommandLineAPIScope {
|
|
|
|
public:
|
|
|
|
V8CommandLineAPIScope(v8::Local<v8::Context>,
|
|
|
|
v8::Local<v8::Object> commandLineAPI,
|
|
|
|
v8::Local<v8::Object> global);
|
|
|
|
~V8CommandLineAPIScope();
|
|
|
|
V8CommandLineAPIScope(const V8CommandLineAPIScope&) = delete;
|
|
|
|
V8CommandLineAPIScope& operator=(const V8CommandLineAPIScope&) = delete;
|
|
|
|
|
|
|
|
private:
|
|
|
|
static void accessorGetterCallback(
|
|
|
|
v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Value>&);
|
|
|
|
static void accessorSetterCallback(v8::Local<v8::Name>, v8::Local<v8::Value>,
|
|
|
|
const v8::PropertyCallbackInfo<void>&);
|
|
|
|
|
|
|
|
v8::Local<v8::Context> m_context;
|
|
|
|
v8::Local<v8::Object> m_commandLineAPI;
|
|
|
|
v8::Local<v8::Object> m_global;
|
|
|
|
v8::Local<v8::Set> m_installedMethods;
|
|
|
|
v8::Local<v8::ArrayBuffer> m_thisReference;
|
|
|
|
};
|
|
|
|
|
2016-09-06 23:26:08 +00:00
|
|
|
class V8_EXPORT StringView {
|
|
|
|
public:
|
|
|
|
StringView() : m_is8Bit(true), m_length(0), m_characters8(nullptr) {}
|
|
|
|
|
2016-09-22 01:47:53 +00:00
|
|
|
StringView(const uint8_t* characters, size_t length)
|
2016-09-06 23:26:08 +00:00
|
|
|
: m_is8Bit(true), m_length(length), m_characters8(characters) {}
|
|
|
|
|
2016-09-22 01:47:53 +00:00
|
|
|
StringView(const uint16_t* characters, size_t length)
|
2016-09-06 23:26:08 +00:00
|
|
|
: m_is8Bit(false), m_length(length), m_characters16(characters) {}
|
|
|
|
|
|
|
|
bool is8Bit() const { return m_is8Bit; }
|
2016-09-22 01:47:53 +00:00
|
|
|
size_t length() const { return m_length; }
|
2016-09-06 23:26:08 +00:00
|
|
|
|
|
|
|
// TODO(dgozman): add DCHECK(m_is8Bit) to accessors once platform can be used
|
|
|
|
// here.
|
|
|
|
const uint8_t* characters8() const { return m_characters8; }
|
|
|
|
const uint16_t* characters16() const { return m_characters16; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_is8Bit;
|
2016-09-22 01:47:53 +00:00
|
|
|
size_t m_length;
|
2016-09-06 23:26:08 +00:00
|
|
|
union {
|
|
|
|
const uint8_t* m_characters8;
|
|
|
|
const uint16_t* m_characters16;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
class V8_EXPORT StringBuffer {
|
|
|
|
public:
|
2018-09-18 08:26:42 +00:00
|
|
|
virtual ~StringBuffer() = default;
|
2020-02-07 23:26:48 +00:00
|
|
|
virtual StringView string() const = 0;
|
2016-09-06 23:26:08 +00:00
|
|
|
// This method copies contents.
|
2020-02-07 23:26:48 +00:00
|
|
|
static std::unique_ptr<StringBuffer> create(StringView);
|
2016-09-06 23:26:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class V8_EXPORT V8ContextInfo {
|
|
|
|
public:
|
|
|
|
V8ContextInfo(v8::Local<v8::Context> context, int contextGroupId,
|
2020-02-07 23:26:48 +00:00
|
|
|
StringView humanReadableName)
|
2016-09-06 23:26:08 +00:00
|
|
|
: context(context),
|
|
|
|
contextGroupId(contextGroupId),
|
|
|
|
humanReadableName(humanReadableName),
|
|
|
|
hasMemoryOnConsole(false) {}
|
|
|
|
|
|
|
|
v8::Local<v8::Context> context;
|
|
|
|
// Each v8::Context is a part of a group. The group id must be non-zero.
|
|
|
|
int contextGroupId;
|
|
|
|
StringView humanReadableName;
|
|
|
|
StringView origin;
|
|
|
|
StringView auxData;
|
|
|
|
bool hasMemoryOnConsole;
|
|
|
|
|
2017-02-11 02:42:17 +00:00
|
|
|
static int executionContextId(v8::Local<v8::Context> context);
|
|
|
|
|
2016-09-06 23:26:08 +00:00
|
|
|
// Disallow copying and allocating this one.
|
|
|
|
enum NotNullTagEnum { NotNullLiteral };
|
|
|
|
void* operator new(size_t) = delete;
|
|
|
|
void* operator new(size_t, NotNullTagEnum, void*) = delete;
|
|
|
|
void* operator new(size_t, void*) = delete;
|
|
|
|
V8ContextInfo(const V8ContextInfo&) = delete;
|
|
|
|
V8ContextInfo& operator=(const V8ContextInfo&) = delete;
|
|
|
|
};
|
|
|
|
|
|
|
|
class V8_EXPORT V8StackTrace {
|
|
|
|
public:
|
2018-05-04 18:10:36 +00:00
|
|
|
virtual StringView firstNonEmptySourceURL() const = 0;
|
2016-09-06 23:26:08 +00:00
|
|
|
virtual bool isEmpty() const = 0;
|
|
|
|
virtual StringView topSourceURL() const = 0;
|
|
|
|
virtual int topLineNumber() const = 0;
|
|
|
|
virtual int topColumnNumber() const = 0;
|
|
|
|
virtual StringView topScriptId() const = 0;
|
2020-12-15 07:27:53 +00:00
|
|
|
virtual int topScriptIdAsInteger() const = 0;
|
2016-09-06 23:26:08 +00:00
|
|
|
virtual StringView topFunctionName() const = 0;
|
|
|
|
|
2018-09-18 08:26:42 +00:00
|
|
|
virtual ~V8StackTrace() = default;
|
2016-09-06 23:26:08 +00:00
|
|
|
virtual std::unique_ptr<protocol::Runtime::API::StackTrace>
|
|
|
|
buildInspectorObject() const = 0;
|
2019-06-26 00:45:46 +00:00
|
|
|
virtual std::unique_ptr<protocol::Runtime::API::StackTrace>
|
|
|
|
buildInspectorObject(int maxAsyncDepth) const = 0;
|
2016-09-06 23:26:08 +00:00
|
|
|
virtual std::unique_ptr<StringBuffer> toString() const = 0;
|
|
|
|
|
|
|
|
// Safe to pass between threads, drops async chain.
|
|
|
|
virtual std::unique_ptr<V8StackTrace> clone() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class V8_EXPORT V8InspectorSession {
|
|
|
|
public:
|
2018-09-18 08:26:42 +00:00
|
|
|
virtual ~V8InspectorSession() = default;
|
2016-09-06 23:26:08 +00:00
|
|
|
|
|
|
|
// Cross-context inspectable values (DOM nodes in different worlds, etc.).
|
|
|
|
class V8_EXPORT Inspectable {
|
|
|
|
public:
|
|
|
|
virtual v8::Local<v8::Value> get(v8::Local<v8::Context>) = 0;
|
2018-09-18 08:26:42 +00:00
|
|
|
virtual ~Inspectable() = default;
|
2016-09-06 23:26:08 +00:00
|
|
|
};
|
|
|
|
virtual void addInspectedObject(std::unique_ptr<Inspectable>) = 0;
|
|
|
|
|
|
|
|
// Dispatching protocol messages.
|
2020-02-07 23:26:48 +00:00
|
|
|
static bool canDispatchMethod(StringView method);
|
|
|
|
virtual void dispatchProtocolMessage(StringView message) = 0;
|
2019-05-02 20:50:38 +00:00
|
|
|
virtual std::vector<uint8_t> state() = 0;
|
2016-09-06 23:26:08 +00:00
|
|
|
virtual std::vector<std::unique_ptr<protocol::Schema::API::Domain>>
|
|
|
|
supportedDomains() = 0;
|
|
|
|
|
2021-04-19 13:23:21 +00:00
|
|
|
virtual v8::Local<v8::Object> createCommandLineAPI(
|
|
|
|
v8::Local<v8::Context> context) = 0;
|
|
|
|
|
2016-09-06 23:26:08 +00:00
|
|
|
// Debugger actions.
|
2020-02-07 23:26:48 +00:00
|
|
|
virtual void schedulePauseOnNextStatement(StringView breakReason,
|
|
|
|
StringView breakDetails) = 0;
|
2016-09-06 23:26:08 +00:00
|
|
|
virtual void cancelPauseOnNextStatement() = 0;
|
2020-02-07 23:26:48 +00:00
|
|
|
virtual void breakProgram(StringView breakReason,
|
|
|
|
StringView breakDetails) = 0;
|
2016-09-06 23:26:08 +00:00
|
|
|
virtual void setSkipAllPauses(bool) = 0;
|
2020-02-03 13:45:06 +00:00
|
|
|
virtual void resume(bool setTerminateOnResume = false) = 0;
|
2016-09-06 23:26:08 +00:00
|
|
|
virtual void stepOver() = 0;
|
|
|
|
virtual std::vector<std::unique_ptr<protocol::Debugger::API::SearchMatch>>
|
2020-02-07 23:26:48 +00:00
|
|
|
searchInTextByLines(StringView text, StringView query, bool caseSensitive,
|
|
|
|
bool isRegex) = 0;
|
2016-09-06 23:26:08 +00:00
|
|
|
|
|
|
|
// Remote objects.
|
2017-12-12 01:39:28 +00:00
|
|
|
virtual std::unique_ptr<protocol::Runtime::API::RemoteObject> wrapObject(
|
2020-02-07 23:26:48 +00:00
|
|
|
v8::Local<v8::Context>, v8::Local<v8::Value>, StringView groupName,
|
2017-12-12 01:39:28 +00:00
|
|
|
bool generatePreview) = 0;
|
|
|
|
|
2016-09-06 23:26:08 +00:00
|
|
|
virtual bool unwrapObject(std::unique_ptr<StringBuffer>* error,
|
2020-02-07 23:26:48 +00:00
|
|
|
StringView objectId, v8::Local<v8::Value>*,
|
2016-09-06 23:26:08 +00:00
|
|
|
v8::Local<v8::Context>*,
|
|
|
|
std::unique_ptr<StringBuffer>* objectGroup) = 0;
|
2020-02-07 23:26:48 +00:00
|
|
|
virtual void releaseObjectGroup(StringView) = 0;
|
|
|
|
virtual void triggerPreciseCoverageDeltaUpdate(StringView occassion) = 0;
|
2016-09-06 23:26:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class V8_EXPORT V8InspectorClient {
|
|
|
|
public:
|
2018-09-18 08:26:42 +00:00
|
|
|
virtual ~V8InspectorClient() = default;
|
2016-09-06 23:26:08 +00:00
|
|
|
|
|
|
|
virtual void runMessageLoopOnPause(int contextGroupId) {}
|
|
|
|
virtual void quitMessageLoopOnPause() {}
|
|
|
|
virtual void runIfWaitingForDebugger(int contextGroupId) {}
|
|
|
|
|
|
|
|
virtual void muteMetrics(int contextGroupId) {}
|
|
|
|
virtual void unmuteMetrics(int contextGroupId) {}
|
|
|
|
|
|
|
|
virtual void beginUserGesture() {}
|
|
|
|
virtual void endUserGesture() {}
|
|
|
|
|
|
|
|
virtual std::unique_ptr<StringBuffer> valueSubtype(v8::Local<v8::Value>) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2020-10-28 11:52:50 +00:00
|
|
|
virtual std::unique_ptr<StringBuffer> descriptionForValueSubtype(
|
|
|
|
v8::Local<v8::Context>, v8::Local<v8::Value>) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-09-06 23:26:08 +00:00
|
|
|
virtual bool formatAccessorsAsProperties(v8::Local<v8::Value>) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
virtual bool isInspectableHeapObject(v8::Local<v8::Object>) { return true; }
|
|
|
|
|
|
|
|
virtual v8::Local<v8::Context> ensureDefaultContextInGroup(
|
|
|
|
int contextGroupId) {
|
|
|
|
return v8::Local<v8::Context>();
|
|
|
|
}
|
|
|
|
virtual void beginEnsureAllContextsInGroup(int contextGroupId) {}
|
|
|
|
virtual void endEnsureAllContextsInGroup(int contextGroupId) {}
|
|
|
|
|
|
|
|
virtual void installAdditionalCommandLineAPI(v8::Local<v8::Context>,
|
|
|
|
v8::Local<v8::Object>) {}
|
2017-01-25 22:23:18 +00:00
|
|
|
virtual void consoleAPIMessage(int contextGroupId,
|
|
|
|
v8::Isolate::MessageErrorLevel level,
|
|
|
|
const StringView& message,
|
|
|
|
const StringView& url, unsigned lineNumber,
|
|
|
|
unsigned columnNumber, V8StackTrace*) {}
|
2016-09-06 23:26:08 +00:00
|
|
|
virtual v8::MaybeLocal<v8::Value> memoryInfo(v8::Isolate*,
|
|
|
|
v8::Local<v8::Context>) {
|
|
|
|
return v8::MaybeLocal<v8::Value>();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void consoleTime(const StringView& title) {}
|
|
|
|
virtual void consoleTimeEnd(const StringView& title) {}
|
|
|
|
virtual void consoleTimeStamp(const StringView& title) {}
|
2017-01-25 22:23:18 +00:00
|
|
|
virtual void consoleClear(int contextGroupId) {}
|
2016-09-06 23:26:08 +00:00
|
|
|
virtual double currentTimeMS() { return 0; }
|
|
|
|
typedef void (*TimerCallback)(void*);
|
|
|
|
virtual void startRepeatingTimer(double, TimerCallback, void* data) {}
|
|
|
|
virtual void cancelTimer(void* data) {}
|
|
|
|
|
|
|
|
// TODO(dgozman): this was added to support service worker shadow page. We
|
|
|
|
// should not connect at all.
|
|
|
|
virtual bool canExecuteScripts(int contextGroupId) { return true; }
|
2017-10-18 18:47:30 +00:00
|
|
|
|
|
|
|
virtual void maxAsyncCallStackDepthChanged(int depth) {}
|
2018-08-09 17:27:00 +00:00
|
|
|
|
|
|
|
virtual std::unique_ptr<StringBuffer> resourceNameToUrl(
|
|
|
|
const StringView& resourceName) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2020-12-22 07:13:23 +00:00
|
|
|
|
|
|
|
// The caller would defer to generating a random 64 bit integer if
|
|
|
|
// this method returns 0.
|
|
|
|
virtual int64_t generateUniqueId() { return 0; }
|
2016-09-06 23:26:08 +00:00
|
|
|
};
|
|
|
|
|
2017-11-22 19:46:33 +00:00
|
|
|
// These stack trace ids are intended to be passed between debuggers and be
|
|
|
|
// resolved later. This allows to track cross-debugger calls and step between
|
|
|
|
// them if a single client connects to multiple debuggers.
|
|
|
|
struct V8_EXPORT V8StackTraceId {
|
|
|
|
uintptr_t id;
|
|
|
|
std::pair<int64_t, int64_t> debugger_id;
|
2019-09-11 23:28:56 +00:00
|
|
|
bool should_pause = false;
|
2017-11-22 19:46:33 +00:00
|
|
|
|
|
|
|
V8StackTraceId();
|
2019-08-22 11:13:36 +00:00
|
|
|
V8StackTraceId(const V8StackTraceId&) = default;
|
2017-11-22 19:46:33 +00:00
|
|
|
V8StackTraceId(uintptr_t id, const std::pair<int64_t, int64_t> debugger_id);
|
2019-09-11 23:28:56 +00:00
|
|
|
V8StackTraceId(uintptr_t id, const std::pair<int64_t, int64_t> debugger_id,
|
|
|
|
bool should_pause);
|
2020-02-07 23:26:48 +00:00
|
|
|
explicit V8StackTraceId(StringView);
|
2019-08-22 11:13:36 +00:00
|
|
|
V8StackTraceId& operator=(const V8StackTraceId&) = default;
|
|
|
|
V8StackTraceId& operator=(V8StackTraceId&&) noexcept = default;
|
2017-11-22 19:46:33 +00:00
|
|
|
~V8StackTraceId() = default;
|
|
|
|
|
|
|
|
bool IsInvalid() const;
|
2019-09-19 04:48:11 +00:00
|
|
|
std::unique_ptr<StringBuffer> ToString();
|
2017-11-22 19:46:33 +00:00
|
|
|
};
|
|
|
|
|
2016-09-06 23:26:08 +00:00
|
|
|
class V8_EXPORT V8Inspector {
|
|
|
|
public:
|
|
|
|
static std::unique_ptr<V8Inspector> create(v8::Isolate*, V8InspectorClient*);
|
2018-09-18 08:26:42 +00:00
|
|
|
virtual ~V8Inspector() = default;
|
2016-09-06 23:26:08 +00:00
|
|
|
|
|
|
|
// Contexts instrumentation.
|
|
|
|
virtual void contextCreated(const V8ContextInfo&) = 0;
|
|
|
|
virtual void contextDestroyed(v8::Local<v8::Context>) = 0;
|
|
|
|
virtual void resetContextGroup(int contextGroupId) = 0;
|
2019-01-17 23:46:34 +00:00
|
|
|
virtual v8::MaybeLocal<v8::Context> contextById(int contextId) = 0;
|
2016-09-06 23:26:08 +00:00
|
|
|
|
|
|
|
// Various instrumentation.
|
|
|
|
virtual void idleStarted() = 0;
|
|
|
|
virtual void idleFinished() = 0;
|
|
|
|
|
|
|
|
// Async stack traces instrumentation.
|
2020-02-07 23:26:48 +00:00
|
|
|
virtual void asyncTaskScheduled(StringView taskName, void* task,
|
2016-09-06 23:26:08 +00:00
|
|
|
bool recurring) = 0;
|
|
|
|
virtual void asyncTaskCanceled(void* task) = 0;
|
|
|
|
virtual void asyncTaskStarted(void* task) = 0;
|
|
|
|
virtual void asyncTaskFinished(void* task) = 0;
|
|
|
|
virtual void allAsyncTasksCanceled() = 0;
|
|
|
|
|
2020-02-07 23:26:48 +00:00
|
|
|
virtual V8StackTraceId storeCurrentStackTrace(StringView description) = 0;
|
2017-11-22 19:46:33 +00:00
|
|
|
virtual void externalAsyncTaskStarted(const V8StackTraceId& parent) = 0;
|
|
|
|
virtual void externalAsyncTaskFinished(const V8StackTraceId& parent) = 0;
|
|
|
|
|
2016-09-06 23:26:08 +00:00
|
|
|
// Exceptions instrumentation.
|
2020-02-07 23:26:48 +00:00
|
|
|
virtual unsigned exceptionThrown(v8::Local<v8::Context>, StringView message,
|
|
|
|
v8::Local<v8::Value> exception,
|
|
|
|
StringView detailedMessage, StringView url,
|
|
|
|
unsigned lineNumber, unsigned columnNumber,
|
|
|
|
std::unique_ptr<V8StackTrace>,
|
|
|
|
int scriptId) = 0;
|
2016-09-06 23:26:08 +00:00
|
|
|
virtual void exceptionRevoked(v8::Local<v8::Context>, unsigned exceptionId,
|
2020-02-07 23:26:48 +00:00
|
|
|
StringView message) = 0;
|
2016-09-06 23:26:08 +00:00
|
|
|
|
|
|
|
// Connection.
|
|
|
|
class V8_EXPORT Channel {
|
|
|
|
public:
|
2018-09-18 08:26:42 +00:00
|
|
|
virtual ~Channel() = default;
|
2016-11-23 00:45:30 +00:00
|
|
|
virtual void sendResponse(int callId,
|
2016-11-29 19:31:05 +00:00
|
|
|
std::unique_ptr<StringBuffer> message) = 0;
|
|
|
|
virtual void sendNotification(std::unique_ptr<StringBuffer> message) = 0;
|
2016-09-06 23:26:08 +00:00
|
|
|
virtual void flushProtocolNotifications() = 0;
|
|
|
|
};
|
2020-02-07 23:26:48 +00:00
|
|
|
virtual std::unique_ptr<V8InspectorSession> connect(int contextGroupId,
|
|
|
|
Channel*,
|
|
|
|
StringView state) = 0;
|
2016-09-06 23:26:08 +00:00
|
|
|
|
|
|
|
// API methods.
|
|
|
|
virtual std::unique_ptr<V8StackTrace> createStackTrace(
|
|
|
|
v8::Local<v8::StackTrace>) = 0;
|
|
|
|
virtual std::unique_ptr<V8StackTrace> captureStackTrace(bool fullStack) = 0;
|
2019-10-30 00:58:34 +00:00
|
|
|
|
|
|
|
// Performance counters.
|
|
|
|
class V8_EXPORT Counters : public std::enable_shared_from_this<Counters> {
|
|
|
|
public:
|
|
|
|
explicit Counters(v8::Isolate* isolate);
|
|
|
|
~Counters();
|
|
|
|
const std::unordered_map<std::string, int>& getCountersMap() const {
|
|
|
|
return m_countersMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static int* getCounterPtr(const char* name);
|
|
|
|
|
|
|
|
v8::Isolate* m_isolate;
|
|
|
|
std::unordered_map<std::string, int> m_countersMap;
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual std::shared_ptr<Counters> enableCounters() = 0;
|
2016-09-06 23:26:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace v8_inspector
|
|
|
|
|
|
|
|
#endif // V8_V8_INSPECTOR_H_
|