chromium/v8/test/cctest/test-debug.cc

// Copyright 2012 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
//       copyright notice, this list of conditions and the following
//       disclaimer in the documentation and/or other materials provided
//       with the distribution.
//     * Neither the name of Google Inc. nor the names of its
//       contributors may be used to endorse or promote products derived
//       from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <stdlib.h>

#include "include/v8-extension.h"
#include "include/v8-function.h"
#include "include/v8-json.h"
#include "include/v8-locker.h"
#include "src/api/api-inl.h"
#include "src/base/strings.h"
#include "src/codegen/compilation-cache.h"
#include "src/debug/debug-interface.h"
#include "src/debug/debug-scopes.h"
#include "src/debug/debug.h"
#include "src/deoptimizer/deoptimizer.h"
#include "src/execution/frames-inl.h"
#include "src/execution/microtask-queue.h"
#include "src/objects/objects-inl.h"
#include "src/utils/utils.h"
#include "test/cctest/cctest.h"
#include "test/cctest/heap/heap-utils.h"

DirectHandle;
Handle;
StepInto;  // From StepAction enum
StepNone;  // From StepAction enum
StepOut;   // From StepAction enum
StepOver;  // From StepAction enum

// --- H e l p e r   F u n c t i o n s

// Compile and run the supplied source and return the requested function.
static v8::Local<v8::Function> CompileFunction(v8::Isolate* isolate,
                                               const char* source,
                                               const char* function_name) {}


// Compile and run the supplied source and return the requested function.
static v8::Local<v8::Function> CompileFunction(LocalContext* env,
                                               const char* source,
                                               const char* function_name) {}

// Is there any debug info for the function?
static bool HasBreakInfo(v8::Local<v8::Function> fun) {}

// Set a break point in a function with a position relative to function start,
// and return the associated break point number.
static i::Handle<i::BreakPoint> SetBreakPoint(v8::Local<v8::Function> fun,
                                              int position,
                                              const char* condition = nullptr) {}

static void ClearBreakPoint(i::DirectHandle<i::BreakPoint> break_point) {}

// Change break on exception.
static void ChangeBreakOnException(v8::Isolate* isolate, bool caught,
                                   bool uncaught) {}

// Prepare to step to next break location.
static void PrepareStep(i::StepAction step_action) {}

// This function is in namespace v8::internal to be friend with class
// v8::internal::Debug.
namespace v8 {
namespace internal {

Handle<FixedArray> GetDebuggedFunctions() {}

// Check that the debugger has been fully unloaded.
void CheckDebuggerUnloaded() {}


}  // namespace internal
}  // namespace v8


// Check that the debugger has been fully unloaded.
static void CheckDebuggerUnloaded() {}

// --- D e b u g   E v e n t   H a n d l e r s
// ---
// --- The different tests uses a number of debug event handlers.
// ---

// Debug event handler which counts a number of events.
int break_point_hit_count =;
int break_point_hit_count_deoptimize =;
class DebugEventCounter : public v8::debug::DebugDelegate {};

// Debug event handler which performs a garbage collection.
class DebugEventBreakPointCollectGarbage : public v8::debug::DebugDelegate {};

// Debug event handler which re-issues a debug break and calls the garbage
// collector to have the heap verified.
class DebugEventBreak : public v8::debug::DebugDelegate {};

v8::debug::BreakReasons break_right_now_reasons =;
static void BreakRightNow(v8::Isolate* isolate, void*) {}

// Debug event handler which re-issues a debug break until a limit has been
// reached.
int max_break_point_hit_count =;
bool terminate_after_max_break_point_hit =;
class DebugEventBreakMax : public v8::debug::DebugDelegate {};

// --- T h e   A c t u a l   T e s t s

// Test that the debug info in the VM is in sync with the functions being
// debugged.
TEST(DebugInfo) {}


// Test that a break point can be set at an IC store location.
TEST(BreakPointICStore) {}

// Test that a break point can be set at an IC store location.
TEST(BreakPointCondition) {}

// Test that a break point can be set at an IC load location.
TEST(BreakPointICLoad) {}


// Test that a break point can be set at an IC call location.
TEST(BreakPointICCall) {}


// Test that a break point can be set at an IC call location and survive a GC.
TEST(BreakPointICCallWithGC) {}


// Test that a break point can be set at an IC call location and survive a GC.
TEST(BreakPointConstructCallWithGC) {}


TEST(BreakPointBuiltin) {}

TEST(BreakPointApiIntrinsics) {}

TEST(BreakPointJSBuiltin) {}

TEST(BreakPointBoundBuiltin) {}

TEST(BreakPointConstructorBuiltin) {}

TEST(BreakPointInlinedBuiltin) {}

TEST(BreakPointInlineBoundBuiltin) {}

TEST(BreakPointInlinedConstructorBuiltin) {}

TEST(BreakPointBuiltinConcurrentOpt) {}

TEST(BreakPointBuiltinTFOperator) {}

TEST(BreakPointBuiltinNewContext) {}

void NoOpFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {}

TEST(BreakPointApiFunction) {}

TEST(BreakPointApiConstructor) {}

void GetWrapperCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {}

TEST(BreakPointApiGetter) {}

void SetWrapperCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {}

TEST(BreakPointApiSetter) {}

TEST(BreakPointApiAccessor) {}

TEST(Regress1163547) {}

TEST(BreakPointOnLazyAccessorInNewContexts) {}

TEST(BreakPointInlineApiFunction) {}

// Test that a break point can be set at a return store location.
TEST(BreakPointConditionBuiltin) {}

TEST(BreakPointInlining) {}

static void CallWithBreakPoints(v8::Local<v8::Context> context,
                                v8::Local<v8::Object> recv,
                                v8::Local<v8::Function> f,
                                int break_point_count, int call_count) {}


// Test GC during break point processing.
TEST(GCDuringBreakPointProcessing) {}


// Call the function three times with different garbage collections in between
// and make sure that the break point survives.
static void CallAndGC(v8::Local<v8::Context> context,
                      v8::Local<v8::Object> recv, v8::Local<v8::Function> f) {}


// Test that a break point can be set at a return store location.
TEST(BreakPointSurviveGC) {}

// Test that the debugger statement causes a break.
TEST(DebuggerStatement) {}


// Test setting a breakpoint on the debugger statement.
TEST(DebuggerStatementBreakpoint) {}


// Test that the conditional breakpoints work event if code generation from
// strings is prohibited in the debugee context.
TEST(ConditionalBreakpointWithCodeGenerationDisallowed) {}


// Simple test of the stepping mechanism using only store ICs.
TEST(DebugStepLinear) {}

TEST(DebugCountLinear) {}

// Test of the stepping mechanism for keyed load in a loop.
TEST(DebugStepKeyedLoadLoop) {}


// Test of the stepping mechanism for keyed store in a loop.
TEST(DebugStepKeyedStoreLoop) {}


// Test of the stepping mechanism for named load in a loop.
TEST(DebugStepNamedLoadLoop) {}


static void DoDebugStepNamedStoreLoop(int expected) {}


// Test of the stepping mechanism for named load in a loop.
TEST(DebugStepNamedStoreLoop) {}

// Test the stepping mechanism with different ICs.
TEST(DebugStepLinearMixedICs) {}

TEST(DebugCountLinearMixedICs) {}

TEST(DebugStepDeclarations) {}


TEST(DebugStepLocals) {}


TEST(DebugStepIf) {}


TEST(DebugStepSwitch) {}


TEST(DebugStepWhile) {}


TEST(DebugStepDoWhile) {}


TEST(DebugStepFor) {}


TEST(DebugStepForContinue) {}


TEST(DebugStepForBreak) {}


TEST(DebugStepForIn) {}


TEST(DebugStepWith) {}


TEST(DebugConditional) {}

// Test that step in does not step into native functions.
TEST(DebugStepNatives) {}

TEST(DebugCountNatives) {}

// Test that step in works with function.apply.
TEST(DebugStepFunctionApply) {}

// Test that step in works with function.apply.
TEST(DebugCountFunctionApply) {}

// Test that step in works with function.call.
TEST(DebugStepFunctionCall) {}

TEST(DebugCountFunctionCall) {}

// Test that step in works with Function.call.apply.
TEST(DebugStepFunctionCallApply) {}

TEST(DebugCountFunctionCallApply) {}

// Tests that breakpoint will be hit if it's set in script.
TEST(PauseInScript) {}

int message_callback_count =;

TEST(DebugBreak) {}

class DebugScopingListener : public v8::debug::DebugDelegate {};

TEST(DebugBreakInWrappedScript) {}

static void EmptyHandler(const v8::FunctionCallbackInfo<v8::Value>& info) {}

TEST(DebugScopeIteratorWithFunctionTemplate) {}

TEST(DebugBreakWithoutJS) {}

// Test to ensure that JavaScript code keeps running while the debug break
// through the stack limit flag is set but breaks are disabled.
TEST(DisableBreak) {}

TEST(DisableDebuggerStatement) {}

static const char* kSimpleExtensionSource =;

// http://crbug.com/28933
// Test that debug break is disabled when bootstrapper is active.
TEST(NoBreakWhenBootstrapping) {}

TEST(SetDebugEventListenerOnUninitializedVM) {}

// Test that clearing the debug event listener actually clears all break points
// and related information.
TEST(DebuggerUnload) {}

int event_listener_hit_count =;

// Test for issue http://code.google.com/p/v8/issues/detail?id=289.
// Make sure that DebugGetLoadedScripts doesn't return scripts
// with disposed external source.
class EmptyExternalStringResource : public v8::String::ExternalStringResource {};

TEST(DebugScriptLineEndsAreAscending) {}

static v8::Global<v8::Context> expected_context_global;
static v8::Global<v8::Value> expected_context_data_global;

class ContextCheckEventListener : public v8::debug::DebugDelegate {};

// Test which creates two contexts and sets different embedder data on each.
// Checks that this data is set correctly and that when the debug event
// listener is called the expected context is the one active.
TEST(ContextData) {}

// Test which creates a context and sets embedder data on it. Checks that this
// data is set correctly and that when the debug event listener is called for
// break event in an eval statement the expected context is the one returned by
// Message.GetEventContext.
TEST(EvalContextData) {}

// Debug event listener which counts script compiled events.
class ScriptCompiledDelegate : public v8::debug::DebugDelegate {};

// Tests that after compile event is sent as many times as there are scripts
// compiled.
TEST(AfterCompileEventWhenEventListenerIsReset) {}

// Tests that syntax error event is sent as many times as there are scripts
// with syntax error compiled.
TEST(SyntaxErrorEventOnSyntaxException) {}

class ExceptionEventCounter : public v8::debug::DebugDelegate {};

UNINITIALIZED_TEST(NoBreakOnStackOverflow) {}

// Tests that break event is sent when event listener is reset.
TEST(BreakEventWhenEventListenerIsReset) {}

// Tests that script is reported as compiled when bound to context.
TEST(AfterCompileEventOnBindToContext) {}


// Test that if DebugBreak is forced it is ignored when code from
// debug-delay.js is executed.
TEST(NoDebugBreakInAfterCompileEventListener) {}


// Test that the debug break flag works with function.apply.
TEST(RepeatDebugBreak) {}

// Test that setting the terminate execution flag during debug break processing.
static void TestDebugBreakInLoop(const char* loop_head,
                                 const char** loop_bodies,
                                 const char* loop_tail) {}

static const char* loop_bodies_1[] =;

static const char* loop_bodies_2[] =;

void DebugBreakLoop(const char* loop_header, const char** loop_bodies,
                    const char* loop_footer) {}


TEST(DebugBreakInWhileTrue1) {}


TEST(DebugBreakInWhileTrue2) {}


TEST(DebugBreakInWhileCondition1) {}


TEST(DebugBreakInWhileCondition2) {}


TEST(DebugBreakInDoWhileTrue1) {}


TEST(DebugBreakInDoWhileTrue2) {}


TEST(DebugBreakInDoWhileCondition1) {}


TEST(DebugBreakInDoWhileCondition2) {}


TEST(DebugBreakInFor1) {}


TEST(DebugBreakInFor2) {}


TEST(DebugBreakInForCondition1) {}


TEST(DebugBreakInForCondition2) {}

class DebugBreakInlineListener : public v8::debug::DebugDelegate {};

TEST(DebugBreakInline) {}

static void RunScriptInANewCFrame(const char* source) {}


TEST(Regress131642) {}

class DebugBreakStackTraceListener : public v8::debug::DebugDelegate {};

static void AddDebugBreak(const v8::FunctionCallbackInfo<v8::Value>& info) {}

TEST(DebugBreakStackTrace) {}


v8::base::Semaphore terminate_requested_semaphore(0);
v8::base::Semaphore terminate_fired_semaphore(0);

class DebugBreakTriggerTerminate : public v8::debug::DebugDelegate {};

class TerminationThread : public v8::base::Thread {};


TEST(DebugBreakOffThreadTerminate) {}

class ArchiveRestoreThread : public v8::base::Thread,
                             public v8::debug::DebugDelegate {};

TEST(DebugArchiveRestore) {}

namespace {
class ThreadJustUsingV8Locker : public v8::base::Thread {};
}  // anonymous namespace

UNINITIALIZED_TEST(Bug1511649UnlockerRestoreDebug) {}

class DebugEventExpectNoException : public v8::debug::DebugDelegate {};

static void TryCatchWrappedThrowCallback(
    const v8::FunctionCallbackInfo<v8::Value>& info) {}

TEST(DebugPromiseInterceptedByTryCatch) {}

class NoInterruptsOnDebugEvent : public v8::debug::DebugDelegate {};

TEST(NoInterruptsInDebugListener) {}

TEST(BreakLocationIterator) {}

class DebugStepOverFunctionWithCaughtExceptionListener
    : public v8::debug::DebugDelegate {};

TEST(DebugStepOverFunctionWithCaughtException) {}

bool near_heap_limit_callback_called =;
size_t NearHeapLimitCallback(void* data, size_t current_heap_limit,
                             size_t initial_heap_limit) {}

UNINITIALIZED_TEST(DebugSetOutOfMemoryListener) {}

TEST(DebugCoverage) {}

namespace {
v8::debug::Coverage::ScriptData GetScriptDataAndDeleteCoverage(
    v8::Isolate* isolate) {}
}  // namespace

TEST(DebugCoverageWithCoverageOutOfScope) {}

namespace {
v8::debug::Coverage::FunctionData GetFunctionDataAndDeleteCoverage(
    v8::Isolate* isolate) {}
}  // namespace

TEST(DebugCoverageWithScriptDataOutOfScope) {}

TEST(DebugGetPossibleBreakpointsReturnLocations) {}

TEST(DebugEvaluateNoSideEffect) {}

TEST(DebugEvaluateGlobalSharedCrossOrigin) {}

TEST(DebugEvaluateLocalSharedCrossOrigin) {}

TEST(DebugEvaluateImportMetaInScript) {}

static v8::MaybeLocal<v8::Module> UnexpectedModuleResolveCallback(
    v8::Local<v8::Context> context, v8::Local<v8::String> specifier,
    v8::Local<v8::FixedArray> import_assertions,
    v8::Local<v8::Module> referrer) {}

TEST(DebugEvaluateImportMetaInModule) {}

namespace {
i::MaybeHandle<i::Script> FindScript(
    i::Isolate* isolate, const std::vector<i::Handle<i::Script>>& scripts,
    const char* name) {}
}  // anonymous namespace

UNINITIALIZED_TEST(LoadedAtStartupScripts) {}

TEST(SourceInfo) {}

namespace {
class SetBreakpointOnScriptCompiled : public v8::debug::DebugDelegate {};
}  // anonymous namespace

TEST(Regress517592) {}

namespace {
std::string FromString(v8::Isolate* isolate, v8::Local<v8::String> str) {}
}  // namespace

TEST(GetPrivateFields) {}

TEST(GetPrivateMethodsAndAccessors) {}

TEST(GetPrivateStaticMethodsAndAccessors) {}

TEST(GetPrivateStaticAndInstanceMethodsAndAccessors) {}

TEST(GetPrivateAutoAccessors) {}

namespace {
class SetTerminateOnResumeDelegate : public v8::debug::DebugDelegate {};
}  // anonymous namespace

TEST(TerminateOnResumeAtBreakpoint) {}

namespace {
bool microtask_one_ran =;
static void MicrotaskOne(const v8::FunctionCallbackInfo<v8::Value>& info) {}
}  // namespace

TEST(TerminateOnResumeRunMicrotaskAtBreakpoint) {}

TEST(TerminateOnResumeRunJavaScriptAtBreakpoint) {}

TEST(TerminateOnResumeAtException) {}

TEST(TerminateOnResumeAtBreakOnEntry) {}

TEST(TerminateOnResumeAtBreakOnEntryUserDefinedFunction) {}

TEST(TerminateOnResumeAtUnhandledRejection) {}

namespace {
void RejectPromiseThroughCppInternal(
    const v8::FunctionCallbackInfo<v8::Value>& info, bool silent) {}

void RejectPromiseThroughCpp(const v8::FunctionCallbackInfo<v8::Value>& info) {}

void SilentRejectPromiseThroughCpp(
    const v8::FunctionCallbackInfo<v8::Value>& info) {}

}  // namespace

TEST(TerminateOnResumeAtUnhandledRejectionCppImpl) {}

TEST(NoTerminateOnResumeAtSilentUnhandledRejectionCppImpl) {}

namespace {
static void UnreachableMicrotask(
    const v8::FunctionCallbackInfo<v8::Value>& info) {}
}  // namespace

TEST(TerminateOnResumeFromMicrotask) {}

class FutexInterruptionThread : public v8::base::Thread {};

namespace {
class SemaphoreTriggerOnBreak : public v8::debug::DebugDelegate {};
}  // anonymous namespace

TEST(TerminateOnResumeFromOtherThread) {}

namespace {
class InterruptionBreakRightNow : public v8::base::Thread {};

}  // anonymous namespace

TEST(TerminateOnResumeAtInterruptFromOtherThread) {}

namespace {

class NoopDelegate : public v8::debug::DebugDelegate {};

}  // namespace

TEST(CreateMessageFromOldException) {}

TEST(CreateMessageDoesNotInspectStack) {}

namespace {

class ScopeListener : public v8::debug::DebugDelegate {};

}  // namespace

TEST(ScopeIteratorDoesNotCreateBlocklistForScriptScope) {}

namespace {

class DebugEvaluateListener : public v8::debug::DebugDelegate {};

}  // namespace

// This test checks that the debug-evaluate blocklist logic correctly handles
// scopes created by `ScriptCompiler::CompileFunction`. It creates a function
// scope nested inside an eval scope with the exact same source positions.
// This can confuse the blocklist mechanism if not handled correctly.
TEST(DebugEvaluateInWrappedScript) {}

namespace {

class ConditionListener : public v8::debug::DebugDelegate {};

}  // namespace

TEST(SuccessfulBreakpointConditionEvaluationEvent) {}

// Checks that SyntaxErrors in breakpoint conditions are reported to the
// DebugDelegate.
TEST(FailedBreakpointConditoinEvaluationEvent) {}

class ExceptionCatchPredictionChecker : public v8::debug::DebugDelegate {};

void RunExceptionCatchPredictionTest(bool predict_uncaught, const char* code) {}

class FunctionBlackboxedCheckCounter : public v8::debug::DebugDelegate {};

void RunAndIgnore(v8::Local<v8::Script> script,
                  v8::Local<v8::Context> context) {}

void RunExceptionBlackboxCheckTest(int functions_checked, const char* code) {}

void RunExceptionOptimizedCallstackWalkTest(bool predict_uncaught,
                                            int functions_checked,
                                            const char* code) {}

TEST(CatchPredictionWithLongStar) {}

TEST(CatchPredictionInlineExceptionCaught) {}

TEST(CatchPredictionInlineExceptionUncaught) {}

TEST(CatchPredictionExceptionCaughtAsPromise) {}

TEST(CatchPredictionExceptionCaughtAsPromiseInAsyncFunction) {}

TEST(CatchPredictionExceptionCaughtAsPromiseInCatchingFunction) {}

TEST(CatchPredictionTopLevelEval) {}

TEST(CatchPredictionClosureCapture) {}

TEST(CatchPredictionNestedContext) {}

TEST(CatchPredictionWithContext) {}