// 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_DEBUG_DEBUG_INTERFACE_H_ #define V8_DEBUG_DEBUG_INTERFACE_H_ #include #include "include/v8-inspector.h" #include "include/v8-util.h" #include "include/v8.h" #include "src/common/globals.h" #include "src/debug/interface-types.h" namespace v8 { namespace internal { struct CoverageBlock; struct CoverageFunction; struct CoverageScript; struct TypeProfileEntry; struct TypeProfileScript; class Coverage; class PostponeInterruptsScope; class Script; class TypeProfile; } // namespace internal namespace debug { void SetContextId(Local context, int id); int GetContextId(Local context); void SetInspector(Isolate* isolate, v8_inspector::V8Inspector*); v8_inspector::V8Inspector* GetInspector(Isolate* isolate); // Schedule a debugger break to happen when function is called inside given // isolate. V8_EXPORT_PRIVATE void SetBreakOnNextFunctionCall(Isolate* isolate); // Remove scheduled debugger break in given isolate if it has not // happened yet. V8_EXPORT_PRIVATE void ClearBreakOnNextFunctionCall(Isolate* isolate); /** * Returns array of internal properties specific to the value type. Result has * the following format: [, ,...,, ]. Result array * will be allocated in the current context. */ MaybeLocal GetInternalProperties(Isolate* isolate, Local value); /** * Returns array of private fields specific to the value type. Result has * the following format: [, ,...,, ]. Result array * will be allocated in the current context. */ V8_EXPORT_PRIVATE MaybeLocal GetPrivateFields(Local context, Local value); /** * Forwards to v8::Object::CreationContext, but with special handling for * JSGlobalProxy objects. */ Local GetCreationContext(Local value); enum ExceptionBreakState { NoBreakOnException = 0, BreakOnUncaughtException = 1, BreakOnAnyException = 2 }; /** * Defines if VM will pause on exceptions or not. * If BreakOnAnyExceptions is set then VM will pause on caught and uncaught * exception, if BreakOnUncaughtException is set then VM will pause only on * uncaught exception, otherwise VM won't stop on any exception. */ void ChangeBreakOnException(Isolate* isolate, ExceptionBreakState state); void RemoveBreakpoint(Isolate* isolate, BreakpointId id); void SetBreakPointsActive(Isolate* isolate, bool is_active); enum StepAction { StepOut = 0, // Step out of the current function. StepNext = 1, // Step to the next statement in the current function. StepIn = 2 // Step into new functions invoked or the next statement // in the current function. }; void PrepareStep(Isolate* isolate, StepAction action); void ClearStepping(Isolate* isolate); V8_EXPORT_PRIVATE void BreakRightNow(Isolate* isolate); bool AllFramesOnStackAreBlackboxed(Isolate* isolate); class Script; struct LiveEditResult { enum Status { OK, COMPILE_ERROR, BLOCKED_BY_RUNNING_GENERATOR, BLOCKED_BY_FUNCTION_ABOVE_BREAK_FRAME, BLOCKED_BY_FUNCTION_BELOW_NON_DROPPABLE_FRAME, BLOCKED_BY_ACTIVE_FUNCTION, BLOCKED_BY_NEW_TARGET_IN_RESTART_FRAME, FRAME_RESTART_IS_NOT_SUPPORTED }; Status status = OK; bool stack_changed = false; // Available only for OK. v8::Local script; // Fields below are available only for COMPILE_ERROR. v8::Local message; int line_number = -1; int column_number = -1; }; /** * Native wrapper around v8::internal::Script object. */ class V8_EXPORT_PRIVATE Script { public: v8::Isolate* GetIsolate() const; ScriptOriginOptions OriginOptions() const; bool WasCompiled() const; bool IsEmbedded() const; int Id() const; int LineOffset() const; int ColumnOffset() const; std::vector LineEnds() const; MaybeLocal Name() const; MaybeLocal SourceURL() const; MaybeLocal SourceMappingURL() const; Maybe ContextId() const; MaybeLocal Source() const; bool IsWasm() const; bool IsModule() const; bool GetPossibleBreakpoints( const debug::Location& start, const debug::Location& end, bool restrict_to_function, std::vector* locations) const; int GetSourceOffset(const debug::Location& location) const; v8::debug::Location GetSourceLocation(int offset) const; bool SetScriptSource(v8::Local newSource, bool preview, LiveEditResult* result) const; bool SetBreakpoint(v8::Local condition, debug::Location* location, BreakpointId* id) const; bool SetBreakpointOnScriptEntry(BreakpointId* id) const; }; // Specialization for wasm Scripts. class WasmScript : public Script { public: static WasmScript* Cast(Script* script); int NumFunctions() const; int NumImportedFunctions() const; MemorySpan Bytecode() const; std::pair GetFunctionRange(int function_index) const; debug::WasmDisassembly DisassembleFunction(int function_index) const; uint32_t GetFunctionHash(int function_index); }; V8_EXPORT_PRIVATE void GetLoadedScripts( Isolate* isolate, PersistentValueVector