2012-01-24 16:36:55 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2008-08-22 13:33:59 +00:00
|
|
|
// 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>
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "include/v8-extension.h"
|
|
|
|
#include "include/v8-function.h"
|
2021-06-22 13:27:00 +00:00
|
|
|
#include "include/v8-json.h"
|
2016-10-19 02:00:21 +00:00
|
|
|
#include "include/v8-locker.h"
|
2018-07-23 11:42:37 +00:00
|
|
|
#include "src/api/api-inl.h"
|
2021-06-22 13:27:00 +00:00
|
|
|
#include "src/base/strings.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/codegen/compilation-cache.h"
|
2016-10-19 02:00:21 +00:00
|
|
|
#include "src/debug/debug-interface.h"
|
2022-10-18 04:52:25 +00:00
|
|
|
#include "src/debug/debug-scopes.h"
|
2015-07-31 11:07:50 +00:00
|
|
|
#include "src/debug/debug.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/deoptimizer/deoptimizer.h"
|
2022-10-18 04:52:25 +00:00
|
|
|
#include "src/execution/frames-inl.h"
|
2020-02-03 13:45:06 +00:00
|
|
|
#include "src/execution/microtask-queue.h"
|
2017-02-23 11:46:29 +00:00
|
|
|
#include "src/objects/objects-inl.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/utils/utils.h"
|
|
|
|
#include "test/cctest/cctest.h"
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
using ::v8::internal::Handle;
|
2021-06-01 08:32:39 +00:00
|
|
|
using ::v8::internal::StepInto; // From StepAction enum
|
2018-06-03 05:09:41 +00:00
|
|
|
using ::v8::internal::StepNone; // From StepAction enum
|
2021-06-01 08:32:39 +00:00
|
|
|
using ::v8::internal::StepOut; // From StepAction enum
|
|
|
|
using ::v8::internal::StepOver; // From StepAction enum
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// --- H e l p e r F u n c t i o n s
|
|
|
|
|
2015-11-19 13:45:42 +00:00
|
|
|
// Compile and run the supplied source and return the requested function.
|
|
|
|
static v8::Local<v8::Function> CompileFunction(v8::Isolate* isolate,
|
2008-08-22 13:33:59 +00:00
|
|
|
const char* source,
|
|
|
|
const char* function_name) {
|
2015-11-19 13:45:42 +00:00
|
|
|
CompileRunChecked(isolate, source);
|
|
|
|
v8::Local<v8::String> name = v8_str(isolate, function_name);
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
v8::MaybeLocal<v8::Value> maybe_function =
|
|
|
|
context->Global()->Get(context, name);
|
|
|
|
return v8::Local<v8::Function>::Cast(maybe_function.ToLocalChecked());
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
2009-05-05 09:38:45 +00:00
|
|
|
|
|
|
|
// Compile and run the supplied source and return the requested function.
|
2018-06-03 05:09:41 +00:00
|
|
|
static v8::Local<v8::Function> CompileFunction(LocalContext* env,
|
2013-11-22 12:43:17 +00:00
|
|
|
const char* source,
|
2009-05-05 09:38:45 +00:00
|
|
|
const char* function_name) {
|
2018-06-03 05:09:41 +00:00
|
|
|
return CompileFunction((*env)->GetIsolate(), source, function_name);
|
2017-03-10 07:06:25 +00:00
|
|
|
}
|
2009-05-05 09:38:45 +00:00
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
// Is there any debug info for the function?
|
2017-05-31 14:26:58 +00:00
|
|
|
static bool HasBreakInfo(v8::Local<v8::Function> fun) {
|
2015-10-23 12:26:49 +00:00
|
|
|
Handle<v8::internal::JSFunction> f =
|
|
|
|
Handle<v8::internal::JSFunction>::cast(v8::Utils::OpenHandle(*fun));
|
2018-06-23 09:05:50 +00:00
|
|
|
Handle<v8::internal::SharedFunctionInfo> shared(f->shared(), f->GetIsolate());
|
2017-05-31 14:26:58 +00:00
|
|
|
return shared->HasBreakInfo();
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 15:58:57 +00:00
|
|
|
// 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,
|
2018-02-26 09:20:45 +00:00
|
|
|
const char* condition = nullptr) {
|
2018-02-22 15:58:57 +00:00
|
|
|
i::Handle<i::JSFunction> function =
|
|
|
|
i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*fun));
|
2018-03-15 17:46:11 +00:00
|
|
|
position += function->shared().StartPosition();
|
2018-02-22 15:58:57 +00:00
|
|
|
static int break_point_index = 0;
|
|
|
|
i::Isolate* isolate = function->GetIsolate();
|
2018-02-26 09:20:45 +00:00
|
|
|
i::Handle<i::String> condition_string =
|
|
|
|
condition ? isolate->factory()->NewStringFromAsciiChecked(condition)
|
|
|
|
: isolate->factory()->empty_string();
|
2018-02-22 15:58:57 +00:00
|
|
|
i::Debug* debug = isolate->debug();
|
2018-02-26 09:20:45 +00:00
|
|
|
i::Handle<i::BreakPoint> break_point =
|
|
|
|
isolate->factory()->NewBreakPoint(++break_point_index, condition_string);
|
2018-02-22 15:58:57 +00:00
|
|
|
|
2019-04-29 20:24:35 +00:00
|
|
|
debug->SetBreakpoint(handle(function->shared(), isolate), break_point,
|
|
|
|
&position);
|
2018-02-22 15:58:57 +00:00
|
|
|
return break_point;
|
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
|
2018-02-22 15:58:57 +00:00
|
|
|
static void ClearBreakPoint(i::Handle<i::BreakPoint> break_point) {
|
|
|
|
v8::internal::Isolate* isolate = CcTest::i_isolate();
|
|
|
|
v8::internal::Debug* debug = isolate->debug();
|
|
|
|
debug->ClearBreakPoint(break_point);
|
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Change break on exception.
|
2021-04-30 16:19:52 +00:00
|
|
|
static void ChangeBreakOnException(v8::Isolate* isolate, bool caught,
|
|
|
|
bool uncaught) {
|
|
|
|
v8::internal::Debug* debug =
|
|
|
|
reinterpret_cast<v8::internal::Isolate*>(isolate)->debug();
|
2022-11-09 06:40:29 +00:00
|
|
|
debug->ChangeBreakOnException(v8::internal::BreakCaughtException, caught);
|
2011-03-18 20:35:07 +00:00
|
|
|
debug->ChangeBreakOnException(v8::internal::BreakUncaughtException, uncaught);
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare to step to next break location.
|
2018-06-03 05:09:41 +00:00
|
|
|
static void PrepareStep(i::StepAction step_action) {
|
2013-09-19 09:17:13 +00:00
|
|
|
v8::internal::Debug* debug = CcTest::i_isolate()->debug();
|
2015-12-18 10:33:25 +00:00
|
|
|
debug->PrepareStep(step_action);
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This function is in namespace v8::internal to be friend with class
|
|
|
|
// v8::internal::Debug.
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Collect the currently debugged functions.
|
|
|
|
Handle<FixedArray> GetDebuggedFunctions() {
|
2013-09-19 09:17:13 +00:00
|
|
|
Debug* debug = CcTest::i_isolate()->debug();
|
2011-03-18 20:35:07 +00:00
|
|
|
|
|
|
|
v8::internal::DebugInfoListNode* node = debug->debug_info_list_;
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Find the number of debugged functions.
|
|
|
|
int count = 0;
|
|
|
|
while (node) {
|
|
|
|
count++;
|
|
|
|
node = node->next();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate array for the debugged functions
|
|
|
|
Handle<FixedArray> debugged_functions =
|
2013-09-19 09:17:13 +00:00
|
|
|
CcTest::i_isolate()->factory()->NewFixedArray(count);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Run through the debug info objects and collect all functions.
|
|
|
|
count = 0;
|
|
|
|
while (node) {
|
|
|
|
debugged_functions->set(count++, *node->debug_info());
|
|
|
|
node = node->next();
|
|
|
|
}
|
|
|
|
|
|
|
|
return debugged_functions;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-13 12:50:47 +00:00
|
|
|
// Check that the debugger has been fully unloaded.
|
2017-08-16 05:41:03 +00:00
|
|
|
void CheckDebuggerUnloaded() {
|
2009-02-13 12:36:58 +00:00
|
|
|
// Check that the debugger context is cleared and that there is no debug
|
|
|
|
// information stored for the debugger.
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(!CcTest::i_isolate()->debug()->debug_info_list_);
|
2009-02-13 12:36:58 +00:00
|
|
|
|
|
|
|
// Collect garbage to ensure weak handles are cleared.
|
2022-12-13 18:25:02 +00:00
|
|
|
i::DisableConservativeStackScanningScopeForTesting no_stack_scanning(
|
|
|
|
CcTest::heap());
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2018-09-14 14:15:31 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2009-02-13 12:36:58 +00:00
|
|
|
|
2017-04-18 12:46:39 +00:00
|
|
|
// Iterate the heap and check that there are no debugger related objects left.
|
2019-06-13 10:51:22 +00:00
|
|
|
HeapObjectIterator iterator(CcTest::heap());
|
2019-05-31 10:59:12 +00:00
|
|
|
for (HeapObject obj = iterator.Next(); !obj.is_null();
|
|
|
|
obj = iterator.Next()) {
|
2009-02-13 12:36:58 +00:00
|
|
|
CHECK(!obj.IsDebugInfo());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-01 22:46:54 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2009-02-13 12:36:58 +00:00
|
|
|
|
|
|
|
// Check that the debugger has been fully unloaded.
|
2017-08-16 05:41:03 +00:00
|
|
|
static void CheckDebuggerUnloaded() { v8::internal::CheckDebuggerUnloaded(); }
|
2009-02-13 12:36:58 +00:00
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
// --- 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.
|
|
|
|
// ---
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
// Debug event handler which counts a number of events.
|
2008-08-22 13:33:59 +00:00
|
|
|
int break_point_hit_count = 0;
|
2011-07-05 13:21:29 +00:00
|
|
|
int break_point_hit_count_deoptimize = 0;
|
2018-06-03 05:09:41 +00:00
|
|
|
class DebugEventCounter : public v8::debug::DebugDelegate {
|
|
|
|
public:
|
2021-11-23 09:14:18 +00:00
|
|
|
void BreakProgramRequested(v8::Local<v8::Context>,
|
|
|
|
const std::vector<v8::debug::BreakpointId>&,
|
2021-12-02 09:26:01 +00:00
|
|
|
v8::debug::BreakReasons break_reasons) override {
|
2008-08-22 13:33:59 +00:00
|
|
|
break_point_hit_count++;
|
2011-07-05 13:21:29 +00:00
|
|
|
// Perform a full deoptimization when the specified number of
|
|
|
|
// breaks have been hit.
|
|
|
|
if (break_point_hit_count == break_point_hit_count_deoptimize) {
|
2018-06-03 05:09:41 +00:00
|
|
|
i::Deoptimizer::DeoptimizeAll(CcTest::i_isolate());
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
2018-06-03 05:09:41 +00:00
|
|
|
if (step_action_ != StepNone) PrepareStep(step_action_);
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
2008-12-11 08:03:24 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
void set_step_action(i::StepAction step_action) {
|
|
|
|
step_action_ = step_action;
|
2008-12-11 08:03:24 +00:00
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
private:
|
|
|
|
i::StepAction step_action_ = StepNone;
|
2008-08-22 13:33:59 +00:00
|
|
|
};
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
// Debug event handler which performs a garbage collection.
|
2018-06-03 05:09:41 +00:00
|
|
|
class DebugEventBreakPointCollectGarbage : public v8::debug::DebugDelegate {
|
|
|
|
public:
|
2021-11-23 09:14:18 +00:00
|
|
|
void BreakProgramRequested(v8::Local<v8::Context>,
|
|
|
|
const std::vector<v8::debug::BreakpointId>&,
|
2021-12-02 09:26:01 +00:00
|
|
|
v8::debug::BreakReasons break_reasons) override {
|
2018-06-03 05:09:41 +00:00
|
|
|
// Perform a garbage collection when break point is hit and continue. Based
|
|
|
|
// on the number of break points hit either scavenge or mark compact
|
|
|
|
// collector is used.
|
2008-08-22 13:33:59 +00:00
|
|
|
break_point_hit_count++;
|
|
|
|
if (break_point_hit_count % 2 == 0) {
|
|
|
|
// Scavenge.
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(v8::internal::NEW_SPACE);
|
2008-08-22 13:33:59 +00:00
|
|
|
} else {
|
2010-08-27 07:08:03 +00:00
|
|
|
// Mark sweep compact.
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-03 05:09:41 +00:00
|
|
|
};
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Debug event handler which re-issues a debug break and calls the garbage
|
|
|
|
// collector to have the heap verified.
|
2018-06-03 05:09:41 +00:00
|
|
|
class DebugEventBreak : public v8::debug::DebugDelegate {
|
|
|
|
public:
|
2021-11-23 09:14:18 +00:00
|
|
|
void BreakProgramRequested(v8::Local<v8::Context>,
|
|
|
|
const std::vector<v8::debug::BreakpointId>&,
|
2021-12-02 09:26:01 +00:00
|
|
|
v8::debug::BreakReasons break_reasons) override {
|
2008-08-22 13:33:59 +00:00
|
|
|
// Count the number of breaks.
|
|
|
|
break_point_hit_count++;
|
|
|
|
|
|
|
|
// Run the garbage collector to enforce heap verification if option
|
|
|
|
// --verify-heap is set.
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(v8::internal::NEW_SPACE);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Set the break flag again to come back here as soon as possible.
|
[inspector] use interrupt for pause only as last resort
With this CL we use interrupt for pause in two cases:
- when we process Debugger.pause on interruption,
- when we would like to break as soon as possible after OOM.
In all other cases, e.g. for async step into we use break
on function call by calling StepIn debugger action.
In mentioned cases we should not actually use interrupt as well:
- Debugger.pause in this case scheduled using interrupt and we
may just break right now without requesting another interrupt,
unfortunately blink side is not ready,
- we should use more reliable way to break right after near OOM
callback, otherwise we can get this callback, increase limit,
request break on next interrupt, before interrupt get another
huge memory allocation and crash.
There are couple advantages:
- we get much better break locations for async stepping
(see inspector tests expectations),
- we can remove DEBUG_BREAK interruption
(it should speedup blackboxing with async tasks, see
removed todo in debug.cc for details)
- it is required preparation step for async step out,
(see https://chromium-review.googlesource.com/c/v8/v8/+/1054618)
Bug: v8:7753
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Iabd7627dbffa9a0eab1736064caf589d02591926
Reviewed-on: https://chromium-review.googlesource.com/1054155
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53439}
2018-05-29 14:54:08 +00:00
|
|
|
v8::debug::SetBreakOnNextFunctionCall(CcTest::isolate());
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
2018-06-03 05:09:41 +00:00
|
|
|
};
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2023-01-04 10:35:31 +00:00
|
|
|
v8::debug::BreakReasons break_right_now_reasons = {};
|
[inspector] use interrupt for pause only as last resort
With this CL we use interrupt for pause in two cases:
- when we process Debugger.pause on interruption,
- when we would like to break as soon as possible after OOM.
In all other cases, e.g. for async step into we use break
on function call by calling StepIn debugger action.
In mentioned cases we should not actually use interrupt as well:
- Debugger.pause in this case scheduled using interrupt and we
may just break right now without requesting another interrupt,
unfortunately blink side is not ready,
- we should use more reliable way to break right after near OOM
callback, otherwise we can get this callback, increase limit,
request break on next interrupt, before interrupt get another
huge memory allocation and crash.
There are couple advantages:
- we get much better break locations for async stepping
(see inspector tests expectations),
- we can remove DEBUG_BREAK interruption
(it should speedup blackboxing with async tasks, see
removed todo in debug.cc for details)
- it is required preparation step for async step out,
(see https://chromium-review.googlesource.com/c/v8/v8/+/1054618)
Bug: v8:7753
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Iabd7627dbffa9a0eab1736064caf589d02591926
Reviewed-on: https://chromium-review.googlesource.com/1054155
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53439}
2018-05-29 14:54:08 +00:00
|
|
|
static void BreakRightNow(v8::Isolate* isolate, void*) {
|
2023-01-04 10:35:31 +00:00
|
|
|
v8::debug::BreakRightNow(isolate, break_right_now_reasons);
|
[inspector] use interrupt for pause only as last resort
With this CL we use interrupt for pause in two cases:
- when we process Debugger.pause on interruption,
- when we would like to break as soon as possible after OOM.
In all other cases, e.g. for async step into we use break
on function call by calling StepIn debugger action.
In mentioned cases we should not actually use interrupt as well:
- Debugger.pause in this case scheduled using interrupt and we
may just break right now without requesting another interrupt,
unfortunately blink side is not ready,
- we should use more reliable way to break right after near OOM
callback, otherwise we can get this callback, increase limit,
request break on next interrupt, before interrupt get another
huge memory allocation and crash.
There are couple advantages:
- we get much better break locations for async stepping
(see inspector tests expectations),
- we can remove DEBUG_BREAK interruption
(it should speedup blackboxing with async tasks, see
removed todo in debug.cc for details)
- it is required preparation step for async step out,
(see https://chromium-review.googlesource.com/c/v8/v8/+/1054618)
Bug: v8:7753
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Iabd7627dbffa9a0eab1736064caf589d02591926
Reviewed-on: https://chromium-review.googlesource.com/1054155
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53439}
2018-05-29 14:54:08 +00:00
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2009-11-05 13:59:40 +00:00
|
|
|
// Debug event handler which re-issues a debug break until a limit has been
|
|
|
|
// reached.
|
|
|
|
int max_break_point_hit_count = 0;
|
2010-11-04 15:43:12 +00:00
|
|
|
bool terminate_after_max_break_point_hit = false;
|
2018-06-03 05:09:41 +00:00
|
|
|
class DebugEventBreakMax : public v8::debug::DebugDelegate {
|
|
|
|
public:
|
2021-11-23 09:14:18 +00:00
|
|
|
void BreakProgramRequested(v8::Local<v8::Context>,
|
|
|
|
const std::vector<v8::debug::BreakpointId>&,
|
2021-12-02 09:26:01 +00:00
|
|
|
v8::debug::BreakReasons break_reasons) override {
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Isolate* v8_isolate = CcTest::isolate();
|
|
|
|
v8::internal::Isolate* isolate = CcTest::i_isolate();
|
2010-11-04 15:43:12 +00:00
|
|
|
if (break_point_hit_count < max_break_point_hit_count) {
|
|
|
|
// Count the number of breaks.
|
|
|
|
break_point_hit_count++;
|
2009-11-05 13:59:40 +00:00
|
|
|
|
2010-11-04 15:43:12 +00:00
|
|
|
// Set the break flag again to come back here as soon as possible.
|
[inspector] use interrupt for pause only as last resort
With this CL we use interrupt for pause in two cases:
- when we process Debugger.pause on interruption,
- when we would like to break as soon as possible after OOM.
In all other cases, e.g. for async step into we use break
on function call by calling StepIn debugger action.
In mentioned cases we should not actually use interrupt as well:
- Debugger.pause in this case scheduled using interrupt and we
may just break right now without requesting another interrupt,
unfortunately blink side is not ready,
- we should use more reliable way to break right after near OOM
callback, otherwise we can get this callback, increase limit,
request break on next interrupt, before interrupt get another
huge memory allocation and crash.
There are couple advantages:
- we get much better break locations for async stepping
(see inspector tests expectations),
- we can remove DEBUG_BREAK interruption
(it should speedup blackboxing with async tasks, see
removed todo in debug.cc for details)
- it is required preparation step for async step out,
(see https://chromium-review.googlesource.com/c/v8/v8/+/1054618)
Bug: v8:7753
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Iabd7627dbffa9a0eab1736064caf589d02591926
Reviewed-on: https://chromium-review.googlesource.com/1054155
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53439}
2018-05-29 14:54:08 +00:00
|
|
|
v8_isolate->RequestInterrupt(BreakRightNow, nullptr);
|
2011-07-05 13:21:29 +00:00
|
|
|
|
2010-11-04 15:43:12 +00:00
|
|
|
} else if (terminate_after_max_break_point_hit) {
|
|
|
|
// Terminate execution after the last break if requested.
|
2015-11-19 13:45:42 +00:00
|
|
|
v8_isolate->TerminateExecution();
|
2010-11-04 15:43:12 +00:00
|
|
|
}
|
2011-07-05 13:21:29 +00:00
|
|
|
|
|
|
|
// Perform a full deoptimization when the specified number of
|
|
|
|
// breaks have been hit.
|
|
|
|
if (break_point_hit_count == break_point_hit_count_deoptimize) {
|
2013-03-18 13:57:49 +00:00
|
|
|
i::Deoptimizer::DeoptimizeAll(isolate);
|
2011-07-05 13:21:29 +00:00
|
|
|
}
|
2009-11-05 13:59:40 +00:00
|
|
|
}
|
2018-06-03 05:09:41 +00:00
|
|
|
};
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// --- 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) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2008-08-22 13:33:59 +00:00
|
|
|
// Create a couple of functions for the test.
|
|
|
|
v8::Local<v8::Function> foo =
|
|
|
|
CompileFunction(&env, "function foo(){}", "foo");
|
|
|
|
v8::Local<v8::Function> bar =
|
|
|
|
CompileFunction(&env, "function bar(){}", "bar");
|
|
|
|
// Initially no functions are debugged.
|
|
|
|
CHECK_EQ(0, v8::internal::GetDebuggedFunctions()->length());
|
2017-05-31 14:26:58 +00:00
|
|
|
CHECK(!HasBreakInfo(foo));
|
|
|
|
CHECK(!HasBreakInfo(bar));
|
2015-12-02 12:47:16 +00:00
|
|
|
EnableDebugger(env->GetIsolate());
|
2008-08-22 13:33:59 +00:00
|
|
|
// One function (foo) is debugged.
|
2018-02-26 09:20:45 +00:00
|
|
|
i::Handle<i::BreakPoint> bp1 = SetBreakPoint(foo, 0);
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(1, v8::internal::GetDebuggedFunctions()->length());
|
2017-05-31 14:26:58 +00:00
|
|
|
CHECK(HasBreakInfo(foo));
|
|
|
|
CHECK(!HasBreakInfo(bar));
|
2008-08-22 13:33:59 +00:00
|
|
|
// Two functions are debugged.
|
2018-02-26 09:20:45 +00:00
|
|
|
i::Handle<i::BreakPoint> bp2 = SetBreakPoint(bar, 0);
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(2, v8::internal::GetDebuggedFunctions()->length());
|
2017-05-31 14:26:58 +00:00
|
|
|
CHECK(HasBreakInfo(foo));
|
|
|
|
CHECK(HasBreakInfo(bar));
|
2008-08-22 13:33:59 +00:00
|
|
|
// One function (bar) is debugged.
|
|
|
|
ClearBreakPoint(bp1);
|
|
|
|
CHECK_EQ(1, v8::internal::GetDebuggedFunctions()->length());
|
2017-05-31 14:26:58 +00:00
|
|
|
CHECK(!HasBreakInfo(foo));
|
|
|
|
CHECK(HasBreakInfo(bar));
|
2008-08-22 13:33:59 +00:00
|
|
|
// No functions are debugged.
|
|
|
|
ClearBreakPoint(bp2);
|
2015-12-02 12:47:16 +00:00
|
|
|
DisableDebugger(env->GetIsolate());
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(0, v8::internal::GetDebuggedFunctions()->length());
|
2017-05-31 14:26:58 +00:00
|
|
|
CHECK(!HasBreakInfo(foo));
|
|
|
|
CHECK(!HasBreakInfo(bar));
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test that a break point can be set at an IC store location.
|
|
|
|
TEST(BreakPointICStore) {
|
|
|
|
break_point_hit_count = 0;
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2009-02-13 12:36:58 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Function> foo =
|
|
|
|
CompileFunction(&env, "function foo(){bar=0;}", "foo");
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Run without breakpoints.
|
2018-06-03 05:09:41 +00:00
|
|
|
foo->Call(env.local(), env->Global(), 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run with breakpoint
|
2018-02-26 09:20:45 +00:00
|
|
|
i::Handle<i::BreakPoint> bp = SetBreakPoint(foo, 0);
|
2018-06-03 05:09:41 +00:00
|
|
|
foo->Call(env.local(), env->Global(), 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
2018-06-03 05:09:41 +00:00
|
|
|
foo->Call(env.local(), env->Global(), 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
2018-06-03 05:09:41 +00:00
|
|
|
foo->Call(env.local(), env->Global(), 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 15:58:57 +00:00
|
|
|
// Test that a break point can be set at an IC store location.
|
|
|
|
TEST(BreakPointCondition) {
|
|
|
|
break_point_hit_count = 0;
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2018-02-22 15:58:57 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2018-02-22 15:58:57 +00:00
|
|
|
CompileRun("var a = false");
|
|
|
|
v8::Local<v8::Function> foo =
|
|
|
|
CompileFunction(&env, "function foo() { return 1 }", "foo");
|
|
|
|
// Run without breakpoints.
|
|
|
|
CompileRun("foo()");
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run with breakpoint
|
|
|
|
i::Handle<i::BreakPoint> bp = SetBreakPoint(foo, 0, "a == true");
|
|
|
|
CompileRun("foo()");
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
CompileRun("a = true");
|
|
|
|
CompileRun("foo()");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
CompileRun("foo()");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2018-02-22 15:58:57 +00:00
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Test that a break point can be set at an IC load location.
|
|
|
|
TEST(BreakPointICLoad) {
|
|
|
|
break_point_hit_count = 0;
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2015-11-19 13:45:42 +00:00
|
|
|
|
|
|
|
CompileRunChecked(env->GetIsolate(), "bar=1");
|
|
|
|
v8::Local<v8::Function> foo =
|
|
|
|
CompileFunction(&env, "function foo(){var x=bar;}", "foo");
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Run without breakpoints.
|
2018-06-03 05:09:41 +00:00
|
|
|
foo->Call(env.local(), env->Global(), 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
// Run with breakpoint.
|
2018-02-26 09:20:45 +00:00
|
|
|
i::Handle<i::BreakPoint> bp = SetBreakPoint(foo, 0);
|
2018-06-03 05:09:41 +00:00
|
|
|
foo->Call(env.local(), env->Global(), 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
2018-06-03 05:09:41 +00:00
|
|
|
foo->Call(env.local(), env->Global(), 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
2018-06-03 05:09:41 +00:00
|
|
|
foo->Call(env.local(), env->Global(), 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test that a break point can be set at an IC call location.
|
|
|
|
TEST(BreakPointICCall) {
|
|
|
|
break_point_hit_count = 0;
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2015-11-19 13:45:42 +00:00
|
|
|
CompileRunChecked(env->GetIsolate(), "function bar(){}");
|
|
|
|
v8::Local<v8::Function> foo =
|
|
|
|
CompileFunction(&env, "function foo(){bar();}", "foo");
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Run without breakpoints.
|
2018-06-03 05:09:41 +00:00
|
|
|
foo->Call(env.local(), env->Global(), 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
// Run with breakpoint
|
2018-02-26 09:20:45 +00:00
|
|
|
i::Handle<i::BreakPoint> bp = SetBreakPoint(foo, 0);
|
2018-06-03 05:09:41 +00:00
|
|
|
foo->Call(env.local(), env->Global(), 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
2018-06-03 05:09:41 +00:00
|
|
|
foo->Call(env.local(), env->Global(), 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
2018-06-03 05:09:41 +00:00
|
|
|
foo->Call(env.local(), env->Global(), 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 05:57:02 +00:00
|
|
|
// Test that a break point can be set at an IC call location and survive a GC.
|
|
|
|
TEST(BreakPointICCallWithGC) {
|
|
|
|
break_point_hit_count = 0;
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventBreakPointCollectGarbage delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2015-11-19 13:45:42 +00:00
|
|
|
CompileRunChecked(env->GetIsolate(), "function bar(){return 1;}");
|
|
|
|
v8::Local<v8::Function> foo =
|
|
|
|
CompileFunction(&env, "function foo(){return bar();}", "foo");
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2010-08-25 05:57:02 +00:00
|
|
|
|
|
|
|
// Run without breakpoints.
|
2017-10-13 16:33:03 +00:00
|
|
|
CHECK_EQ(1, foo->Call(context, env->Global(), 0, nullptr)
|
2015-11-19 13:45:42 +00:00
|
|
|
.ToLocalChecked()
|
|
|
|
->Int32Value(context)
|
|
|
|
.FromJust());
|
2010-08-27 07:08:03 +00:00
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
2018-02-26 09:20:45 +00:00
|
|
|
i::Handle<i::BreakPoint> bp = SetBreakPoint(foo, 0);
|
2017-10-13 16:33:03 +00:00
|
|
|
CHECK_EQ(1, foo->Call(context, env->Global(), 0, nullptr)
|
2015-11-19 13:45:42 +00:00
|
|
|
.ToLocalChecked()
|
|
|
|
->Int32Value(context)
|
|
|
|
.FromJust());
|
2010-08-27 07:08:03 +00:00
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
2017-10-13 16:33:03 +00:00
|
|
|
CHECK_EQ(1, foo->Call(context, env->Global(), 0, nullptr)
|
2015-11-19 13:45:42 +00:00
|
|
|
.ToLocalChecked()
|
|
|
|
->Int32Value(context)
|
|
|
|
.FromJust());
|
2010-08-27 07:08:03 +00:00
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2010-08-27 07:08:03 +00:00
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2010-08-27 07:08:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test that a break point can be set at an IC call location and survive a GC.
|
|
|
|
TEST(BreakPointConstructCallWithGC) {
|
|
|
|
break_point_hit_count = 0;
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventBreakPointCollectGarbage delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2015-11-19 13:45:42 +00:00
|
|
|
CompileRunChecked(env->GetIsolate(), "function bar(){ this.x = 1;}");
|
|
|
|
v8::Local<v8::Function> foo =
|
|
|
|
CompileFunction(&env, "function foo(){return new bar(1).x;}", "foo");
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2010-08-27 07:08:03 +00:00
|
|
|
|
|
|
|
// Run without breakpoints.
|
2017-10-13 16:33:03 +00:00
|
|
|
CHECK_EQ(1, foo->Call(context, env->Global(), 0, nullptr)
|
2015-11-19 13:45:42 +00:00
|
|
|
.ToLocalChecked()
|
|
|
|
->Int32Value(context)
|
|
|
|
.FromJust());
|
2010-08-25 05:57:02 +00:00
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
2018-02-26 09:20:45 +00:00
|
|
|
i::Handle<i::BreakPoint> bp = SetBreakPoint(foo, 0);
|
2017-10-13 16:33:03 +00:00
|
|
|
CHECK_EQ(1, foo->Call(context, env->Global(), 0, nullptr)
|
2015-11-19 13:45:42 +00:00
|
|
|
.ToLocalChecked()
|
|
|
|
->Int32Value(context)
|
|
|
|
.FromJust());
|
2010-08-25 05:57:02 +00:00
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
2017-10-13 16:33:03 +00:00
|
|
|
CHECK_EQ(1, foo->Call(context, env->Global(), 0, nullptr)
|
2015-11-19 13:45:42 +00:00
|
|
|
.ToLocalChecked()
|
|
|
|
->Int32Value(context)
|
|
|
|
.FromJust());
|
2010-08-25 05:57:02 +00:00
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2010-08-25 05:57:02 +00:00
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2010-08-25 05:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-07 17:09:19 +00:00
|
|
|
TEST(BreakPointBuiltin) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2018-02-07 17:09:19 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2018-02-07 17:09:19 +00:00
|
|
|
|
2018-03-08 14:07:39 +00:00
|
|
|
v8::Local<v8::Function> builtin;
|
|
|
|
i::Handle<i::BreakPoint> bp;
|
|
|
|
|
2018-02-08 11:58:37 +00:00
|
|
|
// === Test simple builtin ===
|
2018-02-22 15:19:22 +00:00
|
|
|
break_point_hit_count = 0;
|
2018-03-08 14:07:39 +00:00
|
|
|
builtin = CompileRun("String.prototype.repeat").As<v8::Function>();
|
2018-02-07 17:09:19 +00:00
|
|
|
|
2018-02-08 11:58:37 +00:00
|
|
|
// Run with breakpoint.
|
2019-08-09 06:01:57 +00:00
|
|
|
bp = SetBreakPoint(builtin, 0, "this != 1");
|
2018-03-08 14:07:39 +00:00
|
|
|
ExpectString("'b'.repeat(10)", "bbbbbbbbbb");
|
2018-02-07 17:09:19 +00:00
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
2018-03-08 14:07:39 +00:00
|
|
|
ExpectString("'b'.repeat(10)", "bbbbbbbbbb");
|
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
2018-02-07 17:09:19 +00:00
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
2018-03-08 14:07:39 +00:00
|
|
|
ExpectString("'b'.repeat(10)", "bbbbbbbbbb");
|
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2018-03-08 16:38:37 +00:00
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
2019-06-28 08:08:48 +00:00
|
|
|
TEST(BreakPointApiIntrinsics) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
|
|
|
|
|
|
|
v8::Local<v8::Function> builtin;
|
|
|
|
|
|
|
|
// === Test that using API-exposed functions won't trigger breakpoints ===
|
|
|
|
{
|
|
|
|
v8::Local<v8::Function> weakmap_get =
|
|
|
|
CompileRun("WeakMap.prototype.get").As<v8::Function>();
|
|
|
|
SetBreakPoint(weakmap_get, 0);
|
|
|
|
v8::Local<v8::Function> weakmap_set =
|
|
|
|
CompileRun("WeakMap.prototype.set").As<v8::Function>();
|
|
|
|
SetBreakPoint(weakmap_set, 0);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
CompileRun("var w = new WeakMap(); w.set(w, 1); w.get(w);");
|
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
|
|
|
break_point_hit_count = 0;
|
2021-09-14 19:08:03 +00:00
|
|
|
v8::Local<v8::debug::EphemeronTable> weakmap =
|
|
|
|
v8::debug::EphemeronTable::New(env->GetIsolate());
|
|
|
|
v8::Local<v8::Object> key = v8::Object::New(env->GetIsolate());
|
|
|
|
CHECK(!weakmap->Set(env->GetIsolate(), key, v8_num(1)).IsEmpty());
|
|
|
|
CHECK(!weakmap->Get(env->GetIsolate(), key).IsEmpty());
|
2019-06-28 08:08:48 +00:00
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
v8::Local<v8::Function> object_to_string =
|
|
|
|
CompileRun("Object.prototype.toString").As<v8::Function>();
|
|
|
|
SetBreakPoint(object_to_string, 0);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
CompileRun("var o = {}; o.toString();");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
v8::Local<v8::Object> object = v8::Object::New(env->GetIsolate());
|
|
|
|
CHECK(!object->ObjectProtoToString(env.local()).IsEmpty());
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
v8::Local<v8::Function> map_set =
|
|
|
|
CompileRun("Map.prototype.set").As<v8::Function>();
|
|
|
|
v8::Local<v8::Function> map_get =
|
|
|
|
CompileRun("Map.prototype.get").As<v8::Function>();
|
|
|
|
v8::Local<v8::Function> map_has =
|
|
|
|
CompileRun("Map.prototype.has").As<v8::Function>();
|
|
|
|
v8::Local<v8::Function> map_delete =
|
|
|
|
CompileRun("Map.prototype.delete").As<v8::Function>();
|
|
|
|
SetBreakPoint(map_set, 0);
|
|
|
|
SetBreakPoint(map_get, 0);
|
|
|
|
SetBreakPoint(map_has, 0);
|
|
|
|
SetBreakPoint(map_delete, 0);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
CompileRun(
|
|
|
|
"var m = new Map(); m.set(m, 1); m.get(m); m.has(m); m.delete(m);");
|
|
|
|
CHECK_EQ(4, break_point_hit_count);
|
|
|
|
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
v8::Local<v8::Map> map = v8::Map::New(env->GetIsolate());
|
|
|
|
CHECK(!map->Set(env.local(), map, v8_num(1)).IsEmpty());
|
|
|
|
CHECK(!map->Get(env.local(), map).IsEmpty());
|
|
|
|
CHECK(map->Has(env.local(), map).FromJust());
|
|
|
|
CHECK(map->Delete(env.local(), map).FromJust());
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
v8::Local<v8::Function> set_add =
|
|
|
|
CompileRun("Set.prototype.add").As<v8::Function>();
|
|
|
|
v8::Local<v8::Function> set_get =
|
|
|
|
CompileRun("Set.prototype.has").As<v8::Function>();
|
|
|
|
v8::Local<v8::Function> set_delete =
|
|
|
|
CompileRun("Set.prototype.delete").As<v8::Function>();
|
|
|
|
SetBreakPoint(set_add, 0);
|
|
|
|
SetBreakPoint(set_get, 0);
|
|
|
|
SetBreakPoint(set_delete, 0);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
CompileRun("var s = new Set(); s.add(s); s.has(s); s.delete(s);");
|
|
|
|
CHECK_EQ(3, break_point_hit_count);
|
|
|
|
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
v8::Local<v8::Set> set = v8::Set::New(env->GetIsolate());
|
|
|
|
CHECK(!set->Add(env.local(), set).IsEmpty());
|
|
|
|
CHECK(set->Has(env.local(), set).FromJust());
|
|
|
|
CHECK(set->Delete(env.local(), set).FromJust());
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
2018-03-08 16:38:37 +00:00
|
|
|
TEST(BreakPointJSBuiltin) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2018-03-08 16:38:37 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2018-03-08 16:38:37 +00:00
|
|
|
|
|
|
|
v8::Local<v8::Function> builtin;
|
|
|
|
i::Handle<i::BreakPoint> bp;
|
|
|
|
|
2018-03-08 14:07:39 +00:00
|
|
|
// === Test JS builtin ===
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
builtin = CompileRun("Array.prototype.sort").As<v8::Function>();
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
bp = SetBreakPoint(builtin, 0);
|
|
|
|
CompileRun("[1,2,3].sort()");
|
2018-02-07 17:09:19 +00:00
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
2018-03-08 14:07:39 +00:00
|
|
|
CompileRun("[1,2,3].sort()");
|
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
CompileRun("[1,2,3].sort()");
|
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2018-03-08 16:38:37 +00:00
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BreakPointBoundBuiltin) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2018-03-08 16:38:37 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2018-03-08 16:38:37 +00:00
|
|
|
|
|
|
|
v8::Local<v8::Function> builtin;
|
|
|
|
i::Handle<i::BreakPoint> bp;
|
|
|
|
|
2018-02-22 15:19:22 +00:00
|
|
|
// === Test bound function from a builtin ===
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
builtin = CompileRun(
|
|
|
|
"var boundrepeat = String.prototype.repeat.bind('a');"
|
|
|
|
"String.prototype.repeat")
|
|
|
|
.As<v8::Function>();
|
2018-03-08 14:07:39 +00:00
|
|
|
ExpectString("boundrepeat(10)", "aaaaaaaaaa");
|
2018-02-22 15:19:22 +00:00
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
bp = SetBreakPoint(builtin, 0);
|
2018-03-08 14:07:39 +00:00
|
|
|
ExpectString("boundrepeat(10)", "aaaaaaaaaa");
|
2018-02-22 15:19:22 +00:00
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
2018-03-08 14:07:39 +00:00
|
|
|
ExpectString("boundrepeat(10)", "aaaaaaaaaa");
|
2018-02-22 15:19:22 +00:00
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2018-03-08 16:38:37 +00:00
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BreakPointConstructorBuiltin) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2018-03-08 16:38:37 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2018-03-08 16:38:37 +00:00
|
|
|
|
|
|
|
v8::Local<v8::Function> builtin;
|
|
|
|
i::Handle<i::BreakPoint> bp;
|
|
|
|
|
2018-03-22 13:20:25 +00:00
|
|
|
// === Test Promise constructor ===
|
2018-02-22 15:19:22 +00:00
|
|
|
break_point_hit_count = 0;
|
|
|
|
builtin = CompileRun("Promise").As<v8::Function>();
|
2018-03-08 14:07:39 +00:00
|
|
|
ExpectString("(new Promise(()=>{})).toString()", "[object Promise]");
|
2018-02-22 15:19:22 +00:00
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
2019-08-09 06:01:57 +00:00
|
|
|
bp = SetBreakPoint(builtin, 0, "this != 1");
|
2018-03-08 14:07:39 +00:00
|
|
|
ExpectString("(new Promise(()=>{})).toString()", "[object Promise]");
|
2018-02-22 15:19:22 +00:00
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
2018-03-08 14:07:39 +00:00
|
|
|
ExpectString("(new Promise(()=>{})).toString()", "[object Promise]");
|
2018-02-22 15:19:22 +00:00
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
2018-03-22 13:20:25 +00:00
|
|
|
// === Test Object constructor ===
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
builtin = CompileRun("Object").As<v8::Function>();
|
|
|
|
CompileRun("new Object()");
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
bp = SetBreakPoint(builtin, 0);
|
|
|
|
CompileRun("new Object()");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
CompileRun("new Object()");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
// === Test Number constructor ===
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
builtin = CompileRun("Number").As<v8::Function>();
|
|
|
|
CompileRun("new Number()");
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
bp = SetBreakPoint(builtin, 0);
|
|
|
|
CompileRun("new Number()");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
CompileRun("new Number()");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2018-03-08 16:38:37 +00:00
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BreakPointInlinedBuiltin) {
|
2022-09-15 11:04:11 +00:00
|
|
|
i::v8_flags.allow_natives_syntax = true;
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2018-03-08 16:38:37 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2018-03-08 16:38:37 +00:00
|
|
|
|
|
|
|
v8::Local<v8::Function> builtin;
|
|
|
|
i::Handle<i::BreakPoint> bp;
|
|
|
|
|
2018-02-08 11:58:37 +00:00
|
|
|
// === Test inlined builtin ===
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
builtin = CompileRun("Math.sin").As<v8::Function>();
|
|
|
|
CompileRun("function test(x) { return 1 + Math.sin(x) }");
|
|
|
|
CompileRun(
|
2019-04-30 11:04:41 +00:00
|
|
|
"%PrepareFunctionForOptimization(test);"
|
2018-02-08 11:58:37 +00:00
|
|
|
"test(0.5); test(0.6);"
|
|
|
|
"%OptimizeFunctionOnNextCall(test); test(0.7);");
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
2019-08-09 06:01:57 +00:00
|
|
|
bp = SetBreakPoint(builtin, 0, "this != 1");
|
2018-02-08 11:58:37 +00:00
|
|
|
CompileRun("Math.sin(0.1);");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
CompileRun("test(0.2);");
|
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
|
|
|
// Re-optimize.
|
2019-04-30 11:04:41 +00:00
|
|
|
CompileRun(
|
|
|
|
"%PrepareFunctionForOptimization(test);"
|
|
|
|
"%OptimizeFunctionOnNextCall(test);");
|
2018-03-08 14:07:39 +00:00
|
|
|
ExpectBoolean("test(0.3) < 2", true);
|
2018-02-08 11:58:37 +00:00
|
|
|
CHECK_EQ(3, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
CompileRun("test(0.3);");
|
|
|
|
CHECK_EQ(3, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2018-03-08 16:38:37 +00:00
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BreakPointInlineBoundBuiltin) {
|
2022-09-15 11:04:11 +00:00
|
|
|
i::v8_flags.allow_natives_syntax = true;
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2018-03-08 16:38:37 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2018-03-08 16:38:37 +00:00
|
|
|
|
|
|
|
v8::Local<v8::Function> builtin;
|
|
|
|
i::Handle<i::BreakPoint> bp;
|
|
|
|
|
2018-02-22 15:19:22 +00:00
|
|
|
// === Test inlined bound builtin ===
|
|
|
|
break_point_hit_count = 0;
|
2018-03-08 16:38:37 +00:00
|
|
|
|
|
|
|
builtin = CompileRun(
|
|
|
|
"var boundrepeat = String.prototype.repeat.bind('a');"
|
|
|
|
"String.prototype.repeat")
|
|
|
|
.As<v8::Function>();
|
2018-02-22 15:19:22 +00:00
|
|
|
CompileRun("function test(x) { return 'a' + boundrepeat(x) }");
|
|
|
|
CompileRun(
|
2019-04-30 11:04:41 +00:00
|
|
|
"%PrepareFunctionForOptimization(test);"
|
2018-02-22 15:19:22 +00:00
|
|
|
"test(4); test(5);"
|
|
|
|
"%OptimizeFunctionOnNextCall(test); test(6);");
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
2019-08-09 06:01:57 +00:00
|
|
|
bp = SetBreakPoint(builtin, 0, "this != 1");
|
2018-02-22 15:19:22 +00:00
|
|
|
CompileRun("'a'.repeat(2);");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
CompileRun("test(7);");
|
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
|
|
|
// Re-optimize.
|
2019-04-30 11:04:41 +00:00
|
|
|
CompileRun(
|
|
|
|
"%PrepareFunctionForOptimization(f);"
|
|
|
|
"%OptimizeFunctionOnNextCall(test);");
|
2018-02-22 15:19:22 +00:00
|
|
|
CompileRun("test(8);");
|
|
|
|
CHECK_EQ(3, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
CompileRun("test(9);");
|
|
|
|
CHECK_EQ(3, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2018-03-08 16:38:37 +00:00
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BreakPointInlinedConstructorBuiltin) {
|
2022-09-15 11:04:11 +00:00
|
|
|
i::v8_flags.allow_natives_syntax = true;
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2018-03-08 16:38:37 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2018-03-08 16:38:37 +00:00
|
|
|
|
|
|
|
v8::Local<v8::Function> builtin;
|
|
|
|
i::Handle<i::BreakPoint> bp;
|
|
|
|
|
2018-02-22 15:19:22 +00:00
|
|
|
// === Test inlined constructor builtin (regular construct builtin) ===
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
builtin = CompileRun("Promise").As<v8::Function>();
|
|
|
|
CompileRun("function test(x) { return new Promise(()=>x); }");
|
|
|
|
CompileRun(
|
2019-04-30 11:04:41 +00:00
|
|
|
"%PrepareFunctionForOptimization(test);"
|
2018-02-22 15:19:22 +00:00
|
|
|
"test(4); test(5);"
|
|
|
|
"%OptimizeFunctionOnNextCall(test); test(6);");
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
2019-08-09 06:01:57 +00:00
|
|
|
bp = SetBreakPoint(builtin, 0, "this != 1");
|
2018-03-08 14:07:39 +00:00
|
|
|
CompileRun("new Promise(()=>{});");
|
2018-02-22 15:19:22 +00:00
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
CompileRun("test(7);");
|
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
|
|
|
// Re-optimize.
|
2019-04-30 11:04:41 +00:00
|
|
|
CompileRun(
|
|
|
|
"%PrepareFunctionForOptimization(f);"
|
|
|
|
"%OptimizeFunctionOnNextCall(test);");
|
2018-02-22 15:19:22 +00:00
|
|
|
CompileRun("test(8);");
|
|
|
|
CHECK_EQ(3, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
CompileRun("test(9);");
|
|
|
|
CHECK_EQ(3, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2018-03-08 16:38:37 +00:00
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BreakPointBuiltinConcurrentOpt) {
|
2022-09-15 11:04:11 +00:00
|
|
|
i::v8_flags.allow_natives_syntax = true;
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2018-03-08 16:38:37 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2018-03-08 16:38:37 +00:00
|
|
|
|
|
|
|
v8::Local<v8::Function> builtin;
|
|
|
|
i::Handle<i::BreakPoint> bp;
|
|
|
|
|
2018-02-14 13:53:13 +00:00
|
|
|
// === Test concurrent optimization ===
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
builtin = CompileRun("Math.sin").As<v8::Function>();
|
|
|
|
CompileRun("function test(x) { return 1 + Math.sin(x) }");
|
|
|
|
CompileRun(
|
2019-04-30 11:04:41 +00:00
|
|
|
"%PrepareFunctionForOptimization(test);"
|
2018-02-14 13:53:13 +00:00
|
|
|
"test(0.5); test(0.6);"
|
2021-08-10 08:33:17 +00:00
|
|
|
"%DisableOptimizationFinalization();"
|
|
|
|
"%OptimizeFunctionOnNextCall(test, 'concurrent');"
|
|
|
|
"test(0.7);");
|
2018-02-14 13:53:13 +00:00
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
bp = SetBreakPoint(builtin, 0);
|
|
|
|
// Have the concurrent compile job finish now.
|
|
|
|
CompileRun(
|
2021-08-10 08:33:17 +00:00
|
|
|
"%FinalizeOptimization();"
|
|
|
|
"%GetOptimizationStatus(test);");
|
2018-02-14 13:53:13 +00:00
|
|
|
CompileRun("test(0.2);");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
CompileRun("test(0.3);");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2018-03-08 16:38:37 +00:00
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BreakPointBuiltinTFOperator) {
|
2022-09-15 11:04:11 +00:00
|
|
|
i::v8_flags.allow_natives_syntax = true;
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2018-03-08 16:38:37 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2018-03-08 16:38:37 +00:00
|
|
|
|
|
|
|
v8::Local<v8::Function> builtin;
|
|
|
|
i::Handle<i::BreakPoint> bp;
|
|
|
|
|
2018-02-14 13:53:13 +00:00
|
|
|
// === Test builtin represented as operator ===
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
builtin = CompileRun("String.prototype.indexOf").As<v8::Function>();
|
|
|
|
CompileRun("function test(x) { return 1 + 'foo'.indexOf(x) }");
|
|
|
|
CompileRun(
|
2019-04-30 11:04:41 +00:00
|
|
|
"%PrepareFunctionForOptimization(f);"
|
2018-02-14 13:53:13 +00:00
|
|
|
"test('a'); test('b');"
|
|
|
|
"%OptimizeFunctionOnNextCall(test); test('c');");
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
bp = SetBreakPoint(builtin, 0);
|
|
|
|
CompileRun("'bar'.indexOf('x');");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
CompileRun("test('d');");
|
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
|
|
|
// Re-optimize.
|
2019-04-30 11:04:41 +00:00
|
|
|
CompileRun(
|
|
|
|
"%PrepareFunctionForOptimization(f);"
|
|
|
|
"%OptimizeFunctionOnNextCall(test);");
|
2018-02-14 13:53:13 +00:00
|
|
|
CompileRun("test('e');");
|
|
|
|
CHECK_EQ(3, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
CompileRun("test('f');");
|
|
|
|
CHECK_EQ(3, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2018-03-08 16:38:37 +00:00
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BreakPointBuiltinNewContext) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2018-03-08 16:38:37 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2018-03-08 16:38:37 +00:00
|
|
|
|
|
|
|
v8::Local<v8::Function> builtin;
|
|
|
|
i::Handle<i::BreakPoint> bp;
|
|
|
|
|
2018-03-08 14:07:39 +00:00
|
|
|
// === Test builtin from a new context ===
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
builtin = CompileRun("String.prototype.repeat").As<v8::Function>();
|
|
|
|
CompileRun("'a'.repeat(10)");
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
// Set breakpoint.
|
|
|
|
bp = SetBreakPoint(builtin, 0);
|
|
|
|
|
|
|
|
{
|
|
|
|
// Create and use new context after breakpoint has been set.
|
|
|
|
v8::HandleScope handle_scope(env->GetIsolate());
|
|
|
|
v8::Local<v8::Context> new_context = v8::Context::New(env->GetIsolate());
|
|
|
|
v8::Context::Scope context_scope(new_context);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
CompileRun("'b'.repeat(10)");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
CompileRun("'b'.repeat(10)");
|
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
CompileRun("'b'.repeat(10)");
|
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
}
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2018-03-08 14:07:39 +00:00
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
2018-03-09 08:46:47 +00:00
|
|
|
void NoOpFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
|
|
args.GetReturnValue().Set(v8_num(2));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BreakPointApiFunction) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2018-03-09 08:46:47 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2018-03-09 08:46:47 +00:00
|
|
|
|
|
|
|
i::Handle<i::BreakPoint> bp;
|
|
|
|
|
|
|
|
v8::Local<v8::FunctionTemplate> function_template =
|
|
|
|
v8::FunctionTemplate::New(env->GetIsolate(), NoOpFunctionCallback);
|
|
|
|
|
|
|
|
v8::Local<v8::Function> function =
|
2018-06-03 05:09:41 +00:00
|
|
|
function_template->GetFunction(env.local()).ToLocalChecked();
|
2018-03-09 08:46:47 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
env->Global()->Set(env.local(), v8_str("f"), function).ToChecked();
|
2018-03-09 08:46:47 +00:00
|
|
|
|
|
|
|
// === Test simple builtin ===
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
2019-08-09 06:01:57 +00:00
|
|
|
bp = SetBreakPoint(function, 0, "this != 1");
|
2018-03-09 08:46:47 +00:00
|
|
|
ExpectInt32("f()", 2);
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
ExpectInt32("f()", 2);
|
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
2019-08-23 06:45:31 +00:00
|
|
|
// Direct call through API does not trigger breakpoint.
|
2019-08-09 06:01:57 +00:00
|
|
|
function->Call(env.local(), v8::Undefined(env->GetIsolate()), 0, nullptr)
|
|
|
|
.ToLocalChecked();
|
2019-08-23 06:45:31 +00:00
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
2019-08-09 06:01:57 +00:00
|
|
|
|
2018-03-09 08:46:47 +00:00
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
ExpectInt32("f()", 2);
|
2019-08-23 06:45:31 +00:00
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
2019-08-09 06:01:57 +00:00
|
|
|
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BreakPointApiConstructor) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
|
|
|
|
|
|
|
i::Handle<i::BreakPoint> bp;
|
|
|
|
|
|
|
|
v8::Local<v8::FunctionTemplate> function_template =
|
|
|
|
v8::FunctionTemplate::New(env->GetIsolate(), NoOpFunctionCallback);
|
|
|
|
|
|
|
|
v8::Local<v8::Function> function =
|
|
|
|
function_template->GetFunction(env.local()).ToLocalChecked();
|
|
|
|
|
|
|
|
env->Global()->Set(env.local(), v8_str("f"), function).ToChecked();
|
|
|
|
|
|
|
|
// === Test simple builtin ===
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
bp = SetBreakPoint(function, 0, "this != 1");
|
|
|
|
CompileRun("new f()");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
CompileRun("new f()");
|
2018-03-09 08:46:47 +00:00
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
2019-08-23 06:45:31 +00:00
|
|
|
// Direct call through API does not trigger breakpoint.
|
2019-08-09 06:01:57 +00:00
|
|
|
function->NewInstance(env.local()).ToLocalChecked();
|
2019-08-23 06:45:31 +00:00
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
2019-08-09 06:01:57 +00:00
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
CompileRun("new f()");
|
2019-08-23 06:45:31 +00:00
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
2019-08-09 06:01:57 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2018-03-09 08:46:47 +00:00
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
2018-03-27 19:18:36 +00:00
|
|
|
void GetWrapperCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
|
|
args.GetReturnValue().Set(
|
|
|
|
args[0]
|
|
|
|
.As<v8::Object>()
|
|
|
|
->Get(args.GetIsolate()->GetCurrentContext(), args[1])
|
|
|
|
.ToLocalChecked());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BreakPointApiGetter) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2018-03-27 19:18:36 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2018-03-27 19:18:36 +00:00
|
|
|
|
|
|
|
i::Handle<i::BreakPoint> bp;
|
|
|
|
|
|
|
|
v8::Local<v8::FunctionTemplate> function_template =
|
|
|
|
v8::FunctionTemplate::New(env->GetIsolate(), NoOpFunctionCallback);
|
|
|
|
v8::Local<v8::FunctionTemplate> get_template =
|
|
|
|
v8::FunctionTemplate::New(env->GetIsolate(), GetWrapperCallback);
|
|
|
|
|
|
|
|
v8::Local<v8::Function> function =
|
2018-06-03 05:09:41 +00:00
|
|
|
function_template->GetFunction(env.local()).ToLocalChecked();
|
2018-03-27 19:18:36 +00:00
|
|
|
v8::Local<v8::Function> get =
|
2018-06-03 05:09:41 +00:00
|
|
|
get_template->GetFunction(env.local()).ToLocalChecked();
|
2018-03-27 19:18:36 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
env->Global()->Set(env.local(), v8_str("f"), function).ToChecked();
|
|
|
|
env->Global()->Set(env.local(), v8_str("get_wrapper"), get).ToChecked();
|
2018-03-27 19:18:36 +00:00
|
|
|
CompileRun(
|
|
|
|
"var o = {};"
|
|
|
|
"Object.defineProperty(o, 'f', { get: f, enumerable: true });");
|
|
|
|
|
|
|
|
// === Test API builtin as getter ===
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
bp = SetBreakPoint(function, 0);
|
|
|
|
CompileRun("get_wrapper(o, 'f')");
|
2019-08-23 06:45:31 +00:00
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
2018-03-27 19:18:36 +00:00
|
|
|
|
|
|
|
CompileRun("o.f");
|
2019-08-23 06:45:31 +00:00
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
2018-03-27 19:18:36 +00:00
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
CompileRun("get_wrapper(o, 'f', 2)");
|
2019-08-23 06:45:31 +00:00
|
|
|
CompileRun("o.f");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
2018-03-27 19:18:36 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2018-03-27 19:18:36 +00:00
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetWrapperCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
|
|
CHECK(args[0]
|
|
|
|
.As<v8::Object>()
|
|
|
|
->Set(args.GetIsolate()->GetCurrentContext(), args[1], args[2])
|
|
|
|
.FromJust());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BreakPointApiSetter) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2018-03-27 19:18:36 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2018-03-27 19:18:36 +00:00
|
|
|
|
|
|
|
i::Handle<i::BreakPoint> bp;
|
|
|
|
|
|
|
|
v8::Local<v8::FunctionTemplate> function_template =
|
|
|
|
v8::FunctionTemplate::New(env->GetIsolate(), NoOpFunctionCallback);
|
|
|
|
v8::Local<v8::FunctionTemplate> set_template =
|
|
|
|
v8::FunctionTemplate::New(env->GetIsolate(), SetWrapperCallback);
|
|
|
|
|
|
|
|
v8::Local<v8::Function> function =
|
2018-06-03 05:09:41 +00:00
|
|
|
function_template->GetFunction(env.local()).ToLocalChecked();
|
2018-03-27 19:18:36 +00:00
|
|
|
v8::Local<v8::Function> set =
|
2018-06-03 05:09:41 +00:00
|
|
|
set_template->GetFunction(env.local()).ToLocalChecked();
|
2018-03-27 19:18:36 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
env->Global()->Set(env.local(), v8_str("f"), function).ToChecked();
|
|
|
|
env->Global()->Set(env.local(), v8_str("set_wrapper"), set).ToChecked();
|
2018-03-27 19:18:36 +00:00
|
|
|
|
|
|
|
CompileRun(
|
|
|
|
"var o = {};"
|
|
|
|
"Object.defineProperty(o, 'f', { set: f, enumerable: true });");
|
|
|
|
|
|
|
|
// === Test API builtin as setter ===
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
bp = SetBreakPoint(function, 0);
|
|
|
|
|
|
|
|
CompileRun("o.f = 3");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
CompileRun("set_wrapper(o, 'f', 2)");
|
2019-08-23 06:45:31 +00:00
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
2018-03-27 19:18:36 +00:00
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
CompileRun("o.f = 3");
|
2019-08-23 06:45:31 +00:00
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
2018-03-27 19:18:36 +00:00
|
|
|
|
|
|
|
// === Test API builtin as setter, with condition ===
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
bp = SetBreakPoint(function, 0, "arguments[0] == 3");
|
|
|
|
CompileRun("set_wrapper(o, 'f', 2)");
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
CompileRun("set_wrapper(o, 'f', 3)");
|
2019-08-23 06:45:31 +00:00
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
2018-03-27 19:18:36 +00:00
|
|
|
|
|
|
|
CompileRun("o.f = 3");
|
2019-08-23 06:45:31 +00:00
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
2018-03-27 19:18:36 +00:00
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
CompileRun("set_wrapper(o, 'f', 2)");
|
2019-08-23 06:45:31 +00:00
|
|
|
CompileRun("o.f = 3");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
2018-03-27 19:18:36 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2018-03-27 19:18:36 +00:00
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BreakPointApiAccessor) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2018-03-27 19:18:36 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2018-03-27 19:18:36 +00:00
|
|
|
|
|
|
|
i::Handle<i::BreakPoint> bp;
|
|
|
|
|
|
|
|
// Create 'foo' class, with a hidden property.
|
|
|
|
v8::Local<v8::ObjectTemplate> obj_template =
|
|
|
|
v8::ObjectTemplate::New(env->GetIsolate());
|
|
|
|
v8::Local<v8::FunctionTemplate> accessor_template =
|
|
|
|
v8::FunctionTemplate::New(env->GetIsolate(), NoOpFunctionCallback);
|
|
|
|
obj_template->SetAccessorProperty(v8_str("f"), accessor_template,
|
|
|
|
accessor_template);
|
|
|
|
v8::Local<v8::Object> obj =
|
2018-06-03 05:09:41 +00:00
|
|
|
obj_template->NewInstance(env.local()).ToLocalChecked();
|
|
|
|
env->Global()->Set(env.local(), v8_str("o"), obj).ToChecked();
|
2018-03-27 19:18:36 +00:00
|
|
|
|
|
|
|
v8::Local<v8::Function> function =
|
|
|
|
CompileRun("Object.getOwnPropertyDescriptor(o, 'f').set")
|
|
|
|
.As<v8::Function>();
|
|
|
|
|
|
|
|
// === Test API accessor ===
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
|
|
|
|
CompileRun("function get_loop() { for (var i = 0; i < 10; i++) o.f }");
|
|
|
|
CompileRun("function set_loop() { for (var i = 0; i < 10; i++) o.f = 2 }");
|
|
|
|
|
|
|
|
CompileRun("get_loop(); set_loop();"); // Initialize ICs.
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
bp = SetBreakPoint(function, 0);
|
|
|
|
|
|
|
|
CompileRun("o.f = 3");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
CompileRun("o.f");
|
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
|
|
|
CompileRun("for (var i = 0; i < 10; i++) o.f");
|
|
|
|
CHECK_EQ(12, break_point_hit_count);
|
|
|
|
|
|
|
|
CompileRun("get_loop();");
|
|
|
|
CHECK_EQ(22, break_point_hit_count);
|
|
|
|
|
|
|
|
CompileRun("for (var i = 0; i < 10; i++) o.f = 2");
|
|
|
|
CHECK_EQ(32, break_point_hit_count);
|
|
|
|
|
|
|
|
CompileRun("set_loop();");
|
|
|
|
CHECK_EQ(42, break_point_hit_count);
|
|
|
|
|
2019-04-12 11:26:02 +00:00
|
|
|
// Test that the break point also works when we install the function
|
|
|
|
// template on a new property (with a fresh AccessorPair instance).
|
|
|
|
v8::Local<v8::ObjectTemplate> baz_template =
|
|
|
|
v8::ObjectTemplate::New(env->GetIsolate());
|
|
|
|
baz_template->SetAccessorProperty(v8_str("g"), accessor_template,
|
|
|
|
accessor_template);
|
|
|
|
v8::Local<v8::Object> baz =
|
|
|
|
baz_template->NewInstance(env.local()).ToLocalChecked();
|
|
|
|
env->Global()->Set(env.local(), v8_str("b"), baz).ToChecked();
|
|
|
|
|
|
|
|
CompileRun("b.g = 4");
|
|
|
|
CHECK_EQ(43, break_point_hit_count);
|
|
|
|
|
|
|
|
CompileRun("b.g");
|
|
|
|
CHECK_EQ(44, break_point_hit_count);
|
|
|
|
|
2018-03-27 19:18:36 +00:00
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
CompileRun("o.f = 3");
|
|
|
|
CompileRun("o.f");
|
2019-04-12 11:26:02 +00:00
|
|
|
CHECK_EQ(44, break_point_hit_count);
|
2018-03-27 19:18:36 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2018-03-27 19:18:36 +00:00
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
[debug] Instantiate accessors only once.
When retrieving an API accessor function (i.e. either the getter or the
setter) for which the lazy accessor mechanism is used (i.e. where the
actual JSFunction is created lazily and only the FunctionTemplateInfo)
is around, we thus far created a fresh JSFunction every time the
accessor function is requested, but that's observably wrong behavior,
since the accessors are JavaScript objects with identity. We currently
rely on the instantiation cache to guarantee identity, but there's no
reason why we couldn't instead just put the instantiated JSFunction into
the AccessorPair.
Fixing this to only instantiate the lazy accessor pair only once, upon
first time it's requested, coincidentally also simplifies (and fixes)
the API accessor breakpoint machinery. This was previously lacking
support for walking dictionary prototype objects and forcibly
instantiating the lazy accessor pairs with break points. However, all
this magic in the debugger is no longer necessary when we ensure that
the lazy accessor pair component is generally only instantiated once.
Bug: v8:178, v8:7596, chromium:986063, chromium:496666
Change-Id: I41d28378010716c96c8ecf7c3f1247765f8bc669
Fixed: chromium:1163547
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2731527
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73163}
2021-03-03 07:30:08 +00:00
|
|
|
TEST(Regress1163547) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
|
|
|
|
|
|
|
i::Handle<i::BreakPoint> bp;
|
|
|
|
|
|
|
|
auto constructor_tmpl = v8::FunctionTemplate::New(env->GetIsolate());
|
|
|
|
auto prototype_tmpl = constructor_tmpl->PrototypeTemplate();
|
|
|
|
auto accessor_tmpl =
|
|
|
|
v8::FunctionTemplate::New(env->GetIsolate(), NoOpFunctionCallback);
|
|
|
|
prototype_tmpl->SetAccessorProperty(v8_str("f"), accessor_tmpl);
|
|
|
|
|
|
|
|
auto constructor =
|
|
|
|
constructor_tmpl->GetFunction(env.local()).ToLocalChecked();
|
|
|
|
env->Global()->Set(env.local(), v8_str("C"), constructor).ToChecked();
|
|
|
|
|
|
|
|
CompileRun("o = new C();");
|
|
|
|
v8::Local<v8::Function> function =
|
|
|
|
CompileRun("Object.getOwnPropertyDescriptor(C.prototype, 'f').get")
|
|
|
|
.As<v8::Function>();
|
|
|
|
|
|
|
|
// === Test API accessor ===
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
|
|
|
|
// At this point, the C.prototype - which holds the "f" accessor - is in
|
|
|
|
// dictionary mode.
|
|
|
|
auto constructor_fun =
|
|
|
|
Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*constructor));
|
|
|
|
CHECK(!i::JSObject::cast(constructor_fun->prototype()).HasFastProperties());
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
bp = SetBreakPoint(function, 0);
|
|
|
|
|
|
|
|
CompileRun("o.f");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
2022-11-03 09:36:04 +00:00
|
|
|
TEST(BreakPointOnLazyAccessorInNewContexts) {
|
|
|
|
// Check that breakpoints on a lazy accessor still get hit after creating new
|
|
|
|
// contexts.
|
|
|
|
// Regression test for parts of http://crbug.com/1368554.
|
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
|
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(isolate, &delegate);
|
|
|
|
|
|
|
|
auto accessor_tmpl = v8::FunctionTemplate::New(isolate, NoOpFunctionCallback);
|
|
|
|
accessor_tmpl->SetClassName(v8_str("get f"));
|
|
|
|
auto object_tmpl = v8::ObjectTemplate::New(isolate);
|
|
|
|
object_tmpl->SetAccessorProperty(v8_str("f"), accessor_tmpl);
|
|
|
|
|
|
|
|
{
|
|
|
|
v8::Local<v8::Context> context1 = v8::Context::New(isolate);
|
|
|
|
context1->Global()
|
|
|
|
->Set(context1, v8_str("o"),
|
|
|
|
object_tmpl->NewInstance(context1).ToLocalChecked())
|
|
|
|
.ToChecked();
|
|
|
|
v8::Context::Scope context_scope(context1);
|
|
|
|
|
|
|
|
// 1. Set the breakpoint
|
|
|
|
v8::Local<v8::Function> function =
|
|
|
|
CompileRun(context1, "Object.getOwnPropertyDescriptor(o, 'f').get")
|
|
|
|
.ToLocalChecked()
|
|
|
|
.As<v8::Function>();
|
|
|
|
SetBreakPoint(function, 0);
|
|
|
|
|
|
|
|
// 2. Run and check that we hit the breakpoint
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
CompileRun(context1, "o.f");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// Create a second context and check that we also hit the breakpoint
|
|
|
|
// without setting it again.
|
|
|
|
v8::Local<v8::Context> context2 = v8::Context::New(isolate);
|
|
|
|
context2->Global()
|
|
|
|
->Set(context2, v8_str("o"),
|
|
|
|
object_tmpl->NewInstance(context2).ToLocalChecked())
|
|
|
|
.ToChecked();
|
|
|
|
v8::Context::Scope context_scope(context2);
|
|
|
|
|
|
|
|
CompileRun(context2, "o.f");
|
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// Create a third context, but this time we use a global template instead
|
|
|
|
// and let the bootstrapper initialize "o" instead.
|
|
|
|
auto global_tmpl = v8::ObjectTemplate::New(isolate);
|
|
|
|
global_tmpl->Set(v8_str("o"), object_tmpl);
|
|
|
|
v8::Local<v8::Context> context3 =
|
|
|
|
v8::Context::New(isolate, nullptr, global_tmpl);
|
|
|
|
v8::Context::Scope context_scope(context3);
|
|
|
|
|
|
|
|
CompileRun(context3, "o.f");
|
|
|
|
CHECK_EQ(3, break_point_hit_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::debug::SetDebugDelegate(isolate, nullptr);
|
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
2018-03-09 08:46:47 +00:00
|
|
|
TEST(BreakPointInlineApiFunction) {
|
2022-09-15 11:04:11 +00:00
|
|
|
i::v8_flags.allow_natives_syntax = true;
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2018-03-09 08:46:47 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2018-03-09 08:46:47 +00:00
|
|
|
|
|
|
|
i::Handle<i::BreakPoint> bp;
|
|
|
|
|
|
|
|
v8::Local<v8::FunctionTemplate> function_template =
|
|
|
|
v8::FunctionTemplate::New(env->GetIsolate(), NoOpFunctionCallback);
|
|
|
|
|
|
|
|
v8::Local<v8::Function> function =
|
2018-06-03 05:09:41 +00:00
|
|
|
function_template->GetFunction(env.local()).ToLocalChecked();
|
2018-03-09 08:46:47 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
env->Global()->Set(env.local(), v8_str("f"), function).ToChecked();
|
2019-04-30 11:04:41 +00:00
|
|
|
CompileRun(
|
|
|
|
"function g() { return 1 + f(); };"
|
|
|
|
"%PrepareFunctionForOptimization(g);");
|
2018-03-09 08:46:47 +00:00
|
|
|
|
|
|
|
// === Test simple builtin ===
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
bp = SetBreakPoint(function, 0);
|
|
|
|
ExpectInt32("g()", 3);
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
ExpectInt32("g()", 3);
|
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
|
|
|
CompileRun("%OptimizeFunctionOnNextCall(g)");
|
|
|
|
ExpectInt32("g()", 3);
|
|
|
|
CHECK_EQ(3, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
ExpectInt32("g()", 3);
|
|
|
|
CHECK_EQ(3, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2018-03-09 08:46:47 +00:00
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
2018-03-08 14:07:39 +00:00
|
|
|
// Test that a break point can be set at a return store location.
|
|
|
|
TEST(BreakPointConditionBuiltin) {
|
2022-09-15 11:04:11 +00:00
|
|
|
i::v8_flags.allow_natives_syntax = true;
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2018-03-08 14:07:39 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2018-03-08 14:07:39 +00:00
|
|
|
v8::Local<v8::Function> builtin;
|
|
|
|
i::Handle<i::BreakPoint> bp;
|
|
|
|
|
|
|
|
// === Test global variable ===
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
builtin = CompileRun("String.prototype.repeat").As<v8::Function>();
|
|
|
|
CompileRun("var condition = false");
|
|
|
|
CompileRun("'a'.repeat(10)");
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
bp = SetBreakPoint(builtin, 0, "condition == true");
|
|
|
|
CompileRun("'b'.repeat(10)");
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
CompileRun("condition = true");
|
|
|
|
CompileRun("'b'.repeat(10)");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
CompileRun("'b'.repeat(10)");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
2018-03-12 06:31:30 +00:00
|
|
|
// === Test arguments ===
|
2018-03-08 14:07:39 +00:00
|
|
|
break_point_hit_count = 0;
|
|
|
|
builtin = CompileRun("String.prototype.repeat").As<v8::Function>();
|
2018-03-12 06:31:30 +00:00
|
|
|
CompileRun("function f(x) { return 'a'.repeat(x * 2); }");
|
2018-03-08 14:07:39 +00:00
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
2018-03-12 06:31:30 +00:00
|
|
|
bp = SetBreakPoint(builtin, 0, "arguments[0] == 20");
|
|
|
|
ExpectString("f(5)", "aaaaaaaaaa");
|
2018-03-08 14:07:39 +00:00
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
2018-03-12 06:31:30 +00:00
|
|
|
ExpectString("f(10)", "aaaaaaaaaaaaaaaaaaaa");
|
2018-03-08 14:07:39 +00:00
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
2018-03-12 06:31:30 +00:00
|
|
|
ExpectString("f(10)", "aaaaaaaaaaaaaaaaaaaa");
|
2018-03-08 14:07:39 +00:00
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
2018-03-12 06:31:30 +00:00
|
|
|
// === Test adapted arguments ===
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
builtin = CompileRun("String.prototype.repeat").As<v8::Function>();
|
|
|
|
CompileRun("function f(x) { return 'a'.repeat(x * 2, x); }");
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
bp = SetBreakPoint(builtin, 0,
|
|
|
|
"arguments[1] == 10 && arguments[2] == undefined");
|
|
|
|
ExpectString("f(5)", "aaaaaaaaaa");
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
ExpectString("f(10)", "aaaaaaaaaaaaaaaaaaaa");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
ExpectString("f(10)", "aaaaaaaaaaaaaaaaaaaa");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
2018-03-21 10:18:02 +00:00
|
|
|
// === Test var-arg builtins ===
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
builtin = CompileRun("String.fromCharCode").As<v8::Function>();
|
|
|
|
CompileRun("function f() { return String.fromCharCode(1, 2, 3); }");
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
bp = SetBreakPoint(builtin, 0, "arguments.length == 3 && arguments[1] == 2");
|
|
|
|
CompileRun("f(1, 2, 3)");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
CompileRun("f(1, 2, 3)");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
// === Test rest arguments ===
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
builtin = CompileRun("String.fromCharCode").As<v8::Function>();
|
|
|
|
CompileRun("function f(...args) { return String.fromCharCode(...args); }");
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
bp = SetBreakPoint(builtin, 0, "arguments.length == 3 && arguments[1] == 2");
|
|
|
|
CompileRun("f(1, 2, 3)");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
CompileRun("f(1, 3, 3)");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
CompileRun("f(1, 2, 3)");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
2018-03-12 06:31:30 +00:00
|
|
|
// === Test receiver ===
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
builtin = CompileRun("String.prototype.repeat").As<v8::Function>();
|
|
|
|
CompileRun("function f(x) { return x.repeat(10); }");
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
bp = SetBreakPoint(builtin, 0, "this == 'a'");
|
|
|
|
ExpectString("f('b')", "bbbbbbbbbb");
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
ExpectString("f('a')", "aaaaaaaaaa");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
ExpectString("f('a')", "aaaaaaaaaa");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
2018-03-08 14:07:39 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2018-02-08 11:58:37 +00:00
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BreakPointInlining) {
|
2022-09-15 11:04:11 +00:00
|
|
|
i::v8_flags.allow_natives_syntax = true;
|
2018-02-08 11:58:37 +00:00
|
|
|
break_point_hit_count = 0;
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2018-02-08 11:58:37 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2018-02-08 11:58:37 +00:00
|
|
|
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
v8::Local<v8::Function> inlinee =
|
|
|
|
CompileRun("function f(x) { return x*2; } f").As<v8::Function>();
|
|
|
|
CompileRun("function test(x) { return 1 + f(x) }");
|
|
|
|
CompileRun(
|
2019-04-30 11:04:41 +00:00
|
|
|
"%PrepareFunctionForOptimization(test);"
|
2018-02-08 11:58:37 +00:00
|
|
|
"test(0.5); test(0.6);"
|
|
|
|
"%OptimizeFunctionOnNextCall(test); test(0.7);");
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
2018-02-26 09:20:45 +00:00
|
|
|
i::Handle<i::BreakPoint> bp = SetBreakPoint(inlinee, 0);
|
2018-02-08 11:58:37 +00:00
|
|
|
CompileRun("f(0.1);");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
CompileRun("test(0.2);");
|
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
|
|
|
// Re-optimize.
|
2019-04-30 11:04:41 +00:00
|
|
|
CompileRun(
|
|
|
|
"%PrepareFunctionForOptimization(test);"
|
|
|
|
"%OptimizeFunctionOnNextCall(test);");
|
2018-02-08 11:58:37 +00:00
|
|
|
CompileRun("test(0.3);");
|
|
|
|
CHECK_EQ(3, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
CompileRun("test(0.3);");
|
|
|
|
CHECK_EQ(3, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2018-02-07 17:09:19 +00:00
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2015-11-19 13:45:42 +00:00
|
|
|
static void CallWithBreakPoints(v8::Local<v8::Context> context,
|
|
|
|
v8::Local<v8::Object> recv,
|
2008-08-22 13:33:59 +00:00
|
|
|
v8::Local<v8::Function> f,
|
2015-11-19 13:45:42 +00:00
|
|
|
int break_point_count, int call_count) {
|
2008-08-22 13:33:59 +00:00
|
|
|
break_point_hit_count = 0;
|
|
|
|
for (int i = 0; i < call_count; i++) {
|
2017-10-13 16:33:03 +00:00
|
|
|
f->Call(context, recv, 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ((i + 1) * break_point_count, break_point_hit_count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
// Test GC during break point processing.
|
|
|
|
TEST(GCDuringBreakPointProcessing) {
|
|
|
|
break_point_hit_count = 0;
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventBreakPointCollectGarbage delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2008-08-22 13:33:59 +00:00
|
|
|
v8::Local<v8::Function> foo;
|
|
|
|
|
|
|
|
// Test IC store break point with garbage collection.
|
|
|
|
foo = CompileFunction(&env, "function foo(){bar=0;}", "foo");
|
|
|
|
SetBreakPoint(foo, 0);
|
2015-11-19 13:45:42 +00:00
|
|
|
CallWithBreakPoints(context, env->Global(), foo, 1, 10);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Test IC load break point with garbage collection.
|
|
|
|
foo = CompileFunction(&env, "bar=1;function foo(){var x=bar;}", "foo");
|
|
|
|
SetBreakPoint(foo, 0);
|
2015-11-19 13:45:42 +00:00
|
|
|
CallWithBreakPoints(context, env->Global(), foo, 1, 10);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Test IC call break point with garbage collection.
|
|
|
|
foo = CompileFunction(&env, "function bar(){};function foo(){bar();}", "foo");
|
|
|
|
SetBreakPoint(foo, 0);
|
2015-11-19 13:45:42 +00:00
|
|
|
CallWithBreakPoints(context, env->Global(), foo, 1, 10);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Test return break point with garbage collection.
|
|
|
|
foo = CompileFunction(&env, "function foo(){}", "foo");
|
|
|
|
SetBreakPoint(foo, 0);
|
2015-11-19 13:45:42 +00:00
|
|
|
CallWithBreakPoints(context, env->Global(), foo, 1, 25);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2010-06-08 12:04:49 +00:00
|
|
|
// Test debug break slot break point with garbage collection.
|
|
|
|
foo = CompileFunction(&env, "function foo(){var a;}", "foo");
|
|
|
|
SetBreakPoint(foo, 0);
|
2015-11-19 13:45:42 +00:00
|
|
|
CallWithBreakPoints(context, env->Global(), foo, 1, 25);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Call the function three times with different garbage collections in between
|
|
|
|
// and make sure that the break point survives.
|
2015-11-19 13:45:42 +00:00
|
|
|
static void CallAndGC(v8::Local<v8::Context> context,
|
|
|
|
v8::Local<v8::Object> recv, v8::Local<v8::Function> f) {
|
2008-08-22 13:33:59 +00:00
|
|
|
break_point_hit_count = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
// Call function.
|
2017-10-13 16:33:03 +00:00
|
|
|
f->Call(context, recv, 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(1 + i * 3, break_point_hit_count);
|
|
|
|
|
|
|
|
// Scavenge and call function.
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(v8::internal::NEW_SPACE);
|
2017-10-13 16:33:03 +00:00
|
|
|
f->Call(context, recv, 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(2 + i * 3, break_point_hit_count);
|
|
|
|
|
|
|
|
// Mark sweep (and perhaps compact) and call function.
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2017-10-13 16:33:03 +00:00
|
|
|
f->Call(context, recv, 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(3 + i * 3, break_point_hit_count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Test that a break point can be set at a return store location.
|
|
|
|
TEST(BreakPointSurviveGC) {
|
2008-08-22 13:33:59 +00:00
|
|
|
break_point_hit_count = 0;
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2008-08-22 13:33:59 +00:00
|
|
|
v8::Local<v8::Function> foo;
|
|
|
|
|
|
|
|
// Test IC store break point with garbage collection.
|
2010-08-05 13:38:27 +00:00
|
|
|
{
|
2012-01-24 16:36:55 +00:00
|
|
|
CompileFunction(&env, "function foo(){}", "foo");
|
2010-08-05 13:38:27 +00:00
|
|
|
foo = CompileFunction(&env, "function foo(){bar=0;}", "foo");
|
|
|
|
SetBreakPoint(foo, 0);
|
|
|
|
}
|
2015-11-19 13:45:42 +00:00
|
|
|
CallAndGC(context, env->Global(), foo);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Test IC load break point with garbage collection.
|
2010-08-05 13:38:27 +00:00
|
|
|
{
|
2012-01-24 16:36:55 +00:00
|
|
|
CompileFunction(&env, "function foo(){}", "foo");
|
2010-08-05 13:38:27 +00:00
|
|
|
foo = CompileFunction(&env, "bar=1;function foo(){var x=bar;}", "foo");
|
|
|
|
SetBreakPoint(foo, 0);
|
|
|
|
}
|
2015-11-19 13:45:42 +00:00
|
|
|
CallAndGC(context, env->Global(), foo);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Test IC call break point with garbage collection.
|
2010-08-05 13:38:27 +00:00
|
|
|
{
|
2012-01-24 16:36:55 +00:00
|
|
|
CompileFunction(&env, "function foo(){}", "foo");
|
2010-08-05 13:38:27 +00:00
|
|
|
foo = CompileFunction(&env,
|
|
|
|
"function bar(){};function foo(){bar();}",
|
|
|
|
"foo");
|
|
|
|
SetBreakPoint(foo, 0);
|
|
|
|
}
|
2015-11-19 13:45:42 +00:00
|
|
|
CallAndGC(context, env->Global(), foo);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Test return break point with garbage collection.
|
2010-08-05 13:38:27 +00:00
|
|
|
{
|
2012-01-24 16:36:55 +00:00
|
|
|
CompileFunction(&env, "function foo(){}", "foo");
|
2010-08-05 13:38:27 +00:00
|
|
|
foo = CompileFunction(&env, "function foo(){}", "foo");
|
|
|
|
SetBreakPoint(foo, 0);
|
|
|
|
}
|
2015-11-19 13:45:42 +00:00
|
|
|
CallAndGC(context, env->Global(), foo);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2010-08-05 13:38:27 +00:00
|
|
|
// Test non IC break point with garbage collection.
|
|
|
|
{
|
2012-01-24 16:36:55 +00:00
|
|
|
CompileFunction(&env, "function foo(){}", "foo");
|
2010-08-05 13:38:27 +00:00
|
|
|
foo = CompileFunction(&env, "function foo(){var bar=0;}", "foo");
|
|
|
|
SetBreakPoint(foo, 0);
|
|
|
|
}
|
2015-11-19 13:45:42 +00:00
|
|
|
CallAndGC(context, env->Global(), foo);
|
2010-08-05 13:38:27 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that the debugger statement causes a break.
|
|
|
|
TEST(DebuggerStatement) {
|
|
|
|
break_point_hit_count = 0;
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
|
|
|
v8::Local<v8::Context> context = env.local();
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Script::Compile(context,
|
|
|
|
v8_str(env->GetIsolate(), "function bar(){debugger}"))
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Run(context)
|
|
|
|
.ToLocalChecked();
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Script::Compile(
|
2015-11-19 13:45:42 +00:00
|
|
|
context, v8_str(env->GetIsolate(), "function foo(){debugger;debugger;}"))
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Run(context)
|
|
|
|
.ToLocalChecked();
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
|
2015-11-19 13:45:42 +00:00
|
|
|
env->Global()
|
|
|
|
->Get(context, v8_str(env->GetIsolate(), "foo"))
|
|
|
|
.ToLocalChecked());
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast(
|
2015-11-19 13:45:42 +00:00
|
|
|
env->Global()
|
|
|
|
->Get(context, v8_str(env->GetIsolate(), "bar"))
|
|
|
|
.ToLocalChecked());
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Run function with debugger statement
|
2017-10-13 16:33:03 +00:00
|
|
|
bar->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run function with two debugger statement
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(3, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-01 11:48:45 +00:00
|
|
|
// Test setting a breakpoint on the debugger statement.
|
2010-01-29 12:41:11 +00:00
|
|
|
TEST(DebuggerStatementBreakpoint) {
|
|
|
|
break_point_hit_count = 0;
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Script::Compile(context,
|
|
|
|
v8_str(env->GetIsolate(), "function foo(){debugger;}"))
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Run(context)
|
|
|
|
.ToLocalChecked();
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
|
2015-11-19 13:45:42 +00:00
|
|
|
env->Global()
|
|
|
|
->Get(context, v8_str(env->GetIsolate(), "foo"))
|
|
|
|
.ToLocalChecked());
|
2010-01-29 12:41:11 +00:00
|
|
|
|
2015-07-06 11:15:52 +00:00
|
|
|
// The debugger statement triggers breakpoint hit
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2010-01-29 12:41:11 +00:00
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
2018-02-26 09:20:45 +00:00
|
|
|
i::Handle<i::BreakPoint> bp = SetBreakPoint(foo, 0);
|
2010-01-29 12:41:11 +00:00
|
|
|
|
|
|
|
// Set breakpoint does not duplicate hits
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2010-01-29 12:41:11 +00:00
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
|
|
|
ClearBreakPoint(bp);
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2010-01-29 12:41:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-15 10:15:25 +00:00
|
|
|
// Test that the conditional breakpoints work event if code generation from
|
|
|
|
// strings is prohibited in the debugee context.
|
|
|
|
TEST(ConditionalBreakpointWithCodeGenerationDisallowed) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2012-10-15 10:15:25 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2012-10-15 10:15:25 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2012-10-15 10:15:25 +00:00
|
|
|
v8::Local<v8::Function> foo = CompileFunction(&env,
|
|
|
|
"function foo(x) {\n"
|
|
|
|
" var s = 'String value2';\n"
|
|
|
|
" return s + x;\n"
|
|
|
|
"}",
|
|
|
|
"foo");
|
|
|
|
|
|
|
|
// Set conditional breakpoint with condition 'true'.
|
2018-02-26 09:20:45 +00:00
|
|
|
SetBreakPoint(foo, 4, "true");
|
2012-10-15 10:15:25 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
break_point_hit_count = 0;
|
2012-10-15 10:15:25 +00:00
|
|
|
env->AllowCodeGenerationFromStrings(false);
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2018-06-03 05:09:41 +00:00
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
2012-10-15 10:15:25 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2012-10-15 10:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
// Simple test of the stepping mechanism using only store ICs.
|
|
|
|
TEST(DebugStepLinear) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Create a function for testing stepping.
|
|
|
|
v8::Local<v8::Function> foo = CompileFunction(&env,
|
|
|
|
"function foo(){a=1;b=1;c=1;}",
|
|
|
|
"foo");
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Run foo to allow it to get optimized.
|
|
|
|
CompileRun("a=0; b=0; c=0; foo();");
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
// Register a debug event listener which steps and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter run_step;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &run_step);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2015-06-16 07:11:11 +00:00
|
|
|
SetBreakPoint(foo, 3);
|
|
|
|
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2008-08-22 13:33:59 +00:00
|
|
|
break_point_hit_count = 0;
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// With stepping all break locations are hit.
|
|
|
|
CHECK_EQ(4, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Register a debug event listener which just counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2009-02-13 12:36:58 +00:00
|
|
|
SetBreakPoint(foo, 3);
|
2008-08-22 13:33:59 +00:00
|
|
|
break_point_hit_count = 0;
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Without stepping only active break points are hit.
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-21 14:48:54 +00:00
|
|
|
// Test of the stepping mechanism for keyed load in a loop.
|
|
|
|
TEST(DebugStepKeyedLoadLoop) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2009-04-21 14:48:54 +00:00
|
|
|
|
2010-06-08 12:04:49 +00:00
|
|
|
// Register a debug event listener which steps and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter run_step;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &run_step);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
2009-04-21 14:48:54 +00:00
|
|
|
// Create a function for testing stepping of keyed load. The statement 'y=1'
|
|
|
|
// is there to have more than one breakable statement in the loop, TODO(315).
|
|
|
|
v8::Local<v8::Function> foo = CompileFunction(
|
|
|
|
&env,
|
|
|
|
"function foo(a) {\n"
|
|
|
|
" var x;\n"
|
|
|
|
" var len = a.length;\n"
|
|
|
|
" for (var i = 0; i < len; i++) {\n"
|
|
|
|
" y = 1;\n"
|
|
|
|
" x = a[i];\n"
|
|
|
|
" }\n"
|
2010-12-07 11:31:57 +00:00
|
|
|
"}\n"
|
|
|
|
"y=0\n",
|
2009-04-21 14:48:54 +00:00
|
|
|
"foo");
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2009-04-21 14:48:54 +00:00
|
|
|
// Create array [0,1,2,3,4,5,6,7,8,9]
|
2013-11-28 08:21:26 +00:00
|
|
|
v8::Local<v8::Array> a = v8::Array::New(env->GetIsolate(), 10);
|
2009-04-21 14:48:54 +00:00
|
|
|
for (int i = 0; i < 10; i++) {
|
2015-11-19 13:45:42 +00:00
|
|
|
CHECK(a->Set(context, v8::Number::New(env->GetIsolate(), i),
|
|
|
|
v8::Number::New(env->GetIsolate(), i))
|
|
|
|
.FromJust());
|
2009-04-21 14:48:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Call function without any break points to ensure inlining is in place.
|
|
|
|
const int kArgc = 1;
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> args[kArgc] = {a};
|
|
|
|
foo->Call(context, env->Global(), kArgc, args).ToLocalChecked();
|
2009-04-21 14:48:54 +00:00
|
|
|
|
2012-01-13 13:09:52 +00:00
|
|
|
// Set up break point and step through the function.
|
2009-04-21 14:48:54 +00:00
|
|
|
SetBreakPoint(foo, 3);
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepOver);
|
2009-04-21 14:48:54 +00:00
|
|
|
break_point_hit_count = 0;
|
2015-11-19 13:45:42 +00:00
|
|
|
foo->Call(context, env->Global(), kArgc, args).ToLocalChecked();
|
2009-04-21 14:48:54 +00:00
|
|
|
|
|
|
|
// With stepping all break locations are hit.
|
2016-03-11 12:02:37 +00:00
|
|
|
CHECK_EQ(44, break_point_hit_count);
|
2009-04-21 14:48:54 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2009-04-21 14:48:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-12 11:24:13 +00:00
|
|
|
// Test of the stepping mechanism for keyed store in a loop.
|
|
|
|
TEST(DebugStepKeyedStoreLoop) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2009-06-12 11:24:13 +00:00
|
|
|
|
2010-06-08 12:04:49 +00:00
|
|
|
// Register a debug event listener which steps and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter run_step;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &run_step);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
2009-06-12 11:24:13 +00:00
|
|
|
// Create a function for testing stepping of keyed store. The statement 'y=1'
|
|
|
|
// is there to have more than one breakable statement in the loop, TODO(315).
|
|
|
|
v8::Local<v8::Function> foo = CompileFunction(
|
|
|
|
&env,
|
|
|
|
"function foo(a) {\n"
|
|
|
|
" var len = a.length;\n"
|
|
|
|
" for (var i = 0; i < len; i++) {\n"
|
|
|
|
" y = 1;\n"
|
|
|
|
" a[i] = 42;\n"
|
|
|
|
" }\n"
|
2010-12-07 11:31:57 +00:00
|
|
|
"}\n"
|
|
|
|
"y=0\n",
|
2009-06-12 11:24:13 +00:00
|
|
|
"foo");
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2009-06-12 11:24:13 +00:00
|
|
|
// Create array [0,1,2,3,4,5,6,7,8,9]
|
2013-11-28 08:21:26 +00:00
|
|
|
v8::Local<v8::Array> a = v8::Array::New(env->GetIsolate(), 10);
|
2009-06-12 11:24:13 +00:00
|
|
|
for (int i = 0; i < 10; i++) {
|
2015-11-19 13:45:42 +00:00
|
|
|
CHECK(a->Set(context, v8::Number::New(env->GetIsolate(), i),
|
|
|
|
v8::Number::New(env->GetIsolate(), i))
|
|
|
|
.FromJust());
|
2009-06-12 11:24:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Call function without any break points to ensure inlining is in place.
|
|
|
|
const int kArgc = 1;
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> args[kArgc] = {a};
|
|
|
|
foo->Call(context, env->Global(), kArgc, args).ToLocalChecked();
|
2009-06-12 11:24:13 +00:00
|
|
|
|
2012-01-13 13:09:52 +00:00
|
|
|
// Set up break point and step through the function.
|
2009-06-12 11:24:13 +00:00
|
|
|
SetBreakPoint(foo, 3);
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepOver);
|
2009-06-12 11:24:13 +00:00
|
|
|
break_point_hit_count = 0;
|
2015-11-19 13:45:42 +00:00
|
|
|
foo->Call(context, env->Global(), kArgc, args).ToLocalChecked();
|
2009-06-12 11:24:13 +00:00
|
|
|
|
|
|
|
// With stepping all break locations are hit.
|
2016-03-11 12:02:37 +00:00
|
|
|
CHECK_EQ(44, break_point_hit_count);
|
2009-06-12 11:24:13 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2009-06-12 11:24:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-06 10:50:22 +00:00
|
|
|
// Test of the stepping mechanism for named load in a loop.
|
|
|
|
TEST(DebugStepNamedLoadLoop) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2010-05-06 10:50:22 +00:00
|
|
|
|
2010-06-08 12:04:49 +00:00
|
|
|
// Register a debug event listener which steps and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter run_step;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &run_step);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2010-05-06 10:50:22 +00:00
|
|
|
// Create a function for testing stepping of named load.
|
|
|
|
v8::Local<v8::Function> foo = CompileFunction(
|
|
|
|
&env,
|
|
|
|
"function foo() {\n"
|
|
|
|
" var a = [];\n"
|
|
|
|
" var s = \"\";\n"
|
|
|
|
" for (var i = 0; i < 10; i++) {\n"
|
|
|
|
" var v = new V(i, i + 1);\n"
|
|
|
|
" v.y;\n"
|
|
|
|
" a.length;\n" // Special case: array length.
|
|
|
|
" s.length;\n" // Special case: string length.
|
|
|
|
" }\n"
|
|
|
|
"}\n"
|
|
|
|
"function V(x, y) {\n"
|
|
|
|
" this.x = x;\n"
|
|
|
|
" this.y = y;\n"
|
|
|
|
"}\n",
|
|
|
|
"foo");
|
|
|
|
|
|
|
|
// Call function without any break points to ensure inlining is in place.
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2010-05-06 10:50:22 +00:00
|
|
|
|
2012-01-13 13:09:52 +00:00
|
|
|
// Set up break point and step through the function.
|
2010-05-06 10:50:22 +00:00
|
|
|
SetBreakPoint(foo, 4);
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepOver);
|
2010-05-06 10:50:22 +00:00
|
|
|
break_point_hit_count = 0;
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2010-05-06 10:50:22 +00:00
|
|
|
|
|
|
|
// With stepping all break locations are hit.
|
2016-03-11 12:02:37 +00:00
|
|
|
CHECK_EQ(65, break_point_hit_count);
|
2010-05-06 10:50:22 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2010-05-06 10:50:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
static void DoDebugStepNamedStoreLoop(int expected) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2010-08-17 11:06:12 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Register a debug event listener which steps and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter run_step;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &run_step);
|
2010-08-17 11:06:12 +00:00
|
|
|
|
|
|
|
// Create a function for testing stepping of named store.
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2010-08-17 11:06:12 +00:00
|
|
|
v8::Local<v8::Function> foo = CompileFunction(
|
|
|
|
&env,
|
|
|
|
"function foo() {\n"
|
|
|
|
" var a = {a:1};\n"
|
|
|
|
" for (var i = 0; i < 10; i++) {\n"
|
|
|
|
" a.a = 2\n"
|
|
|
|
" }\n"
|
|
|
|
"}\n",
|
|
|
|
"foo");
|
|
|
|
|
|
|
|
// Call function without any break points to ensure inlining is in place.
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2010-08-17 11:06:12 +00:00
|
|
|
|
2012-01-13 13:09:52 +00:00
|
|
|
// Set up break point and step through the function.
|
2010-08-17 11:06:12 +00:00
|
|
|
SetBreakPoint(foo, 3);
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepOver);
|
2010-08-17 11:06:12 +00:00
|
|
|
break_point_hit_count = 0;
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2010-08-17 11:06:12 +00:00
|
|
|
|
|
|
|
// With stepping all expected break locations are hit.
|
|
|
|
CHECK_EQ(expected, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2010-08-17 11:06:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test of the stepping mechanism for named load in a loop.
|
2016-03-11 12:02:37 +00:00
|
|
|
TEST(DebugStepNamedStoreLoop) { DoDebugStepNamedStoreLoop(34); }
|
2010-08-17 11:06:12 +00:00
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
// Test the stepping mechanism with different ICs.
|
|
|
|
TEST(DebugStepLinearMixedICs) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2010-06-08 12:04:49 +00:00
|
|
|
// Register a debug event listener which steps and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter run_step;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &run_step);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2008-08-22 13:33:59 +00:00
|
|
|
// Create a function for testing stepping.
|
|
|
|
v8::Local<v8::Function> foo = CompileFunction(&env,
|
|
|
|
"function bar() {};"
|
|
|
|
"function foo() {"
|
|
|
|
" var x;"
|
|
|
|
" var index='name';"
|
|
|
|
" var y = {};"
|
|
|
|
" a=1;b=2;x=a;y[index]=3;x=y[index];bar();}", "foo");
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Run functions to allow them to get optimized.
|
|
|
|
CompileRun("a=0; b=0; bar(); foo();");
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
SetBreakPoint(foo, 0);
|
|
|
|
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2008-08-22 13:33:59 +00:00
|
|
|
break_point_hit_count = 0;
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2009-09-14 06:57:24 +00:00
|
|
|
// With stepping all break locations are hit.
|
2016-03-01 12:47:27 +00:00
|
|
|
CHECK_EQ(10, break_point_hit_count);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Register a debug event listener which just counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2009-02-13 12:36:58 +00:00
|
|
|
SetBreakPoint(foo, 0);
|
2008-08-22 13:33:59 +00:00
|
|
|
break_point_hit_count = 0;
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Without stepping only active break points are hit.
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-08 12:04:49 +00:00
|
|
|
TEST(DebugStepDeclarations) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2010-06-08 12:04:49 +00:00
|
|
|
|
|
|
|
// Register a debug event listener which steps and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter run_step;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &run_step);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2010-12-07 11:31:57 +00:00
|
|
|
// Create a function for testing stepping. Run it to allow it to get
|
|
|
|
// optimized.
|
2010-06-08 12:04:49 +00:00
|
|
|
const char* src = "function foo() { "
|
|
|
|
" var a;"
|
|
|
|
" var b = 1;"
|
|
|
|
" var c = foo;"
|
|
|
|
" var d = Math.floor;"
|
|
|
|
" var e = b + d(1.2);"
|
2010-12-07 11:31:57 +00:00
|
|
|
"}"
|
|
|
|
"foo()";
|
2010-06-08 12:04:49 +00:00
|
|
|
v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2010-06-08 12:04:49 +00:00
|
|
|
SetBreakPoint(foo, 0);
|
|
|
|
|
|
|
|
// Stepping through the declarations.
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2010-06-08 12:04:49 +00:00
|
|
|
break_point_hit_count = 0;
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2016-03-01 12:47:27 +00:00
|
|
|
CHECK_EQ(5, break_point_hit_count);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
|
|
|
// Get rid of the debug event listener.
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2010-06-08 12:04:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DebugStepLocals) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2010-06-08 12:04:49 +00:00
|
|
|
|
|
|
|
// Register a debug event listener which steps and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter run_step;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &run_step);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2010-12-07 11:31:57 +00:00
|
|
|
// Create a function for testing stepping. Run it to allow it to get
|
|
|
|
// optimized.
|
2010-06-08 12:04:49 +00:00
|
|
|
const char* src = "function foo() { "
|
|
|
|
" var a,b;"
|
|
|
|
" a = 1;"
|
|
|
|
" b = a + 2;"
|
|
|
|
" b = 1 + 2 + 3;"
|
|
|
|
" a = Math.floor(b);"
|
2010-12-07 11:31:57 +00:00
|
|
|
"}"
|
|
|
|
"foo()";
|
2010-06-08 12:04:49 +00:00
|
|
|
v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2010-06-08 12:04:49 +00:00
|
|
|
SetBreakPoint(foo, 0);
|
|
|
|
|
|
|
|
// Stepping through the declarations.
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2010-06-08 12:04:49 +00:00
|
|
|
break_point_hit_count = 0;
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2016-03-01 12:47:27 +00:00
|
|
|
CHECK_EQ(5, break_point_hit_count);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
|
|
|
// Get rid of the debug event listener.
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2010-06-08 12:04:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
TEST(DebugStepIf) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-09-26 08:21:48 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Register a debug event listener which steps and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter run_step;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &run_step);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2010-12-07 11:31:57 +00:00
|
|
|
// Create a function for testing stepping. Run it to allow it to get
|
|
|
|
// optimized.
|
2008-08-22 13:33:59 +00:00
|
|
|
const int argc = 1;
|
|
|
|
const char* src = "function foo(x) { "
|
|
|
|
" a = 1;"
|
|
|
|
" if (x) {"
|
|
|
|
" b = 1;"
|
|
|
|
" } else {"
|
|
|
|
" c = 1;"
|
|
|
|
" d = 1;"
|
|
|
|
" }"
|
2010-12-07 11:31:57 +00:00
|
|
|
"}"
|
|
|
|
"a=0; b=0; c=0; d=0; foo()";
|
2008-08-22 13:33:59 +00:00
|
|
|
v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
|
|
|
|
SetBreakPoint(foo, 0);
|
|
|
|
|
|
|
|
// Stepping through the true part.
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2008-08-22 13:33:59 +00:00
|
|
|
break_point_hit_count = 0;
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> argv_true[argc] = {v8::True(isolate)};
|
|
|
|
foo->Call(context, env->Global(), argc, argv_true).ToLocalChecked();
|
2010-06-08 12:04:49 +00:00
|
|
|
CHECK_EQ(4, break_point_hit_count);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Stepping through the false part.
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2008-08-22 13:33:59 +00:00
|
|
|
break_point_hit_count = 0;
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> argv_false[argc] = {v8::False(isolate)};
|
|
|
|
foo->Call(context, env->Global(), argc, argv_false).ToLocalChecked();
|
2010-06-08 12:04:49 +00:00
|
|
|
CHECK_EQ(5, break_point_hit_count);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Get rid of the debug event listener.
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DebugStepSwitch) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2014-01-03 14:31:17 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Register a debug event listener which steps and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter run_step;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &run_step);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2010-12-07 11:31:57 +00:00
|
|
|
// Create a function for testing stepping. Run it to allow it to get
|
|
|
|
// optimized.
|
2008-08-22 13:33:59 +00:00
|
|
|
const int argc = 1;
|
|
|
|
const char* src = "function foo(x) { "
|
|
|
|
" a = 1;"
|
|
|
|
" switch (x) {"
|
|
|
|
" case 1:"
|
|
|
|
" b = 1;"
|
|
|
|
" case 2:"
|
|
|
|
" c = 1;"
|
|
|
|
" break;"
|
|
|
|
" case 3:"
|
|
|
|
" d = 1;"
|
|
|
|
" e = 1;"
|
2010-06-08 12:04:49 +00:00
|
|
|
" f = 1;"
|
2008-08-22 13:33:59 +00:00
|
|
|
" break;"
|
|
|
|
" }"
|
2010-12-07 11:31:57 +00:00
|
|
|
"}"
|
|
|
|
"a=0; b=0; c=0; d=0; e=0; f=0; foo()";
|
2008-08-22 13:33:59 +00:00
|
|
|
v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
|
|
|
|
SetBreakPoint(foo, 0);
|
|
|
|
|
|
|
|
// One case with fall-through.
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2008-08-22 13:33:59 +00:00
|
|
|
break_point_hit_count = 0;
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> argv_1[argc] = {v8::Number::New(isolate, 1)};
|
|
|
|
foo->Call(context, env->Global(), argc, argv_1).ToLocalChecked();
|
2010-06-08 12:04:49 +00:00
|
|
|
CHECK_EQ(6, break_point_hit_count);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Another case.
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2008-08-22 13:33:59 +00:00
|
|
|
break_point_hit_count = 0;
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> argv_2[argc] = {v8::Number::New(isolate, 2)};
|
|
|
|
foo->Call(context, env->Global(), argc, argv_2).ToLocalChecked();
|
2010-06-08 12:04:49 +00:00
|
|
|
CHECK_EQ(5, break_point_hit_count);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Last case.
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2008-08-22 13:33:59 +00:00
|
|
|
break_point_hit_count = 0;
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> argv_3[argc] = {v8::Number::New(isolate, 3)};
|
|
|
|
foo->Call(context, env->Global(), argc, argv_3).ToLocalChecked();
|
2010-06-08 12:04:49 +00:00
|
|
|
CHECK_EQ(7, break_point_hit_count);
|
|
|
|
|
|
|
|
// Get rid of the debug event listener.
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2010-06-08 12:04:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DebugStepWhile) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2014-01-03 14:31:17 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
|
|
|
// Register a debug event listener which steps and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter run_step;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &run_step);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2010-12-07 11:31:57 +00:00
|
|
|
// Create a function for testing stepping. Run it to allow it to get
|
|
|
|
// optimized.
|
2010-06-08 12:04:49 +00:00
|
|
|
const int argc = 1;
|
|
|
|
const char* src = "function foo(x) { "
|
|
|
|
" var a = 0;"
|
|
|
|
" while (a < x) {"
|
|
|
|
" a++;"
|
|
|
|
" }"
|
2010-12-07 11:31:57 +00:00
|
|
|
"}"
|
|
|
|
"foo()";
|
2010-06-08 12:04:49 +00:00
|
|
|
v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
|
|
|
|
SetBreakPoint(foo, 8); // "var a = 0;"
|
|
|
|
|
2014-06-25 12:42:28 +00:00
|
|
|
// Looping 0 times. We still should break at the while-condition once.
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2014-06-25 12:42:28 +00:00
|
|
|
break_point_hit_count = 0;
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> argv_0[argc] = {v8::Number::New(isolate, 0)};
|
|
|
|
foo->Call(context, env->Global(), argc, argv_0).ToLocalChecked();
|
2014-06-25 12:42:28 +00:00
|
|
|
CHECK_EQ(3, break_point_hit_count);
|
|
|
|
|
2010-06-08 12:04:49 +00:00
|
|
|
// Looping 10 times.
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2010-06-08 12:04:49 +00:00
|
|
|
break_point_hit_count = 0;
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> argv_10[argc] = {v8::Number::New(isolate, 10)};
|
|
|
|
foo->Call(context, env->Global(), argc, argv_10).ToLocalChecked();
|
2014-06-25 12:42:28 +00:00
|
|
|
CHECK_EQ(23, break_point_hit_count);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
|
|
|
// Looping 100 times.
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2010-06-08 12:04:49 +00:00
|
|
|
break_point_hit_count = 0;
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> argv_100[argc] = {v8::Number::New(isolate, 100)};
|
|
|
|
foo->Call(context, env->Global(), argc, argv_100).ToLocalChecked();
|
2014-06-25 12:42:28 +00:00
|
|
|
CHECK_EQ(203, break_point_hit_count);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
|
|
|
// Get rid of the debug event listener.
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2010-06-08 12:04:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DebugStepDoWhile) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2014-01-03 14:31:17 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
|
|
|
// Register a debug event listener which steps and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter run_step;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &run_step);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2010-12-07 11:31:57 +00:00
|
|
|
// Create a function for testing stepping. Run it to allow it to get
|
|
|
|
// optimized.
|
2010-06-08 12:04:49 +00:00
|
|
|
const int argc = 1;
|
|
|
|
const char* src = "function foo(x) { "
|
|
|
|
" var a = 0;"
|
|
|
|
" do {"
|
|
|
|
" a++;"
|
|
|
|
" } while (a < x)"
|
2010-12-07 11:31:57 +00:00
|
|
|
"}"
|
|
|
|
"foo()";
|
2010-06-08 12:04:49 +00:00
|
|
|
v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
|
|
|
|
SetBreakPoint(foo, 8); // "var a = 0;"
|
|
|
|
|
2015-07-06 11:15:52 +00:00
|
|
|
// Looping 0 times.
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2015-07-06 11:15:52 +00:00
|
|
|
break_point_hit_count = 0;
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> argv_0[argc] = {v8::Number::New(isolate, 0)};
|
|
|
|
foo->Call(context, env->Global(), argc, argv_0).ToLocalChecked();
|
2015-07-06 11:15:52 +00:00
|
|
|
CHECK_EQ(4, break_point_hit_count);
|
|
|
|
|
2010-06-08 12:04:49 +00:00
|
|
|
// Looping 10 times.
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2010-06-08 12:04:49 +00:00
|
|
|
break_point_hit_count = 0;
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> argv_10[argc] = {v8::Number::New(isolate, 10)};
|
|
|
|
foo->Call(context, env->Global(), argc, argv_10).ToLocalChecked();
|
2010-06-08 12:04:49 +00:00
|
|
|
CHECK_EQ(22, break_point_hit_count);
|
|
|
|
|
|
|
|
// Looping 100 times.
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2010-06-08 12:04:49 +00:00
|
|
|
break_point_hit_count = 0;
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> argv_100[argc] = {v8::Number::New(isolate, 100)};
|
|
|
|
foo->Call(context, env->Global(), argc, argv_100).ToLocalChecked();
|
2010-06-08 12:04:49 +00:00
|
|
|
CHECK_EQ(202, break_point_hit_count);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Get rid of the debug event listener.
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DebugStepFor) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2014-01-03 14:31:17 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Register a debug event listener which steps and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter run_step;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &run_step);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2010-12-07 11:31:57 +00:00
|
|
|
// Create a function for testing stepping. Run it to allow it to get
|
|
|
|
// optimized.
|
2008-08-22 13:33:59 +00:00
|
|
|
const int argc = 1;
|
|
|
|
const char* src = "function foo(x) { "
|
|
|
|
" a = 1;"
|
|
|
|
" for (i = 0; i < x; i++) {"
|
|
|
|
" b = 1;"
|
|
|
|
" }"
|
2010-12-07 11:31:57 +00:00
|
|
|
"}"
|
|
|
|
"a=0; b=0; i=0; foo()";
|
2008-08-22 13:33:59 +00:00
|
|
|
v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
SetBreakPoint(foo, 8); // "a = 1;"
|
|
|
|
|
2015-07-06 11:15:52 +00:00
|
|
|
// Looping 0 times.
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2015-07-06 11:15:52 +00:00
|
|
|
break_point_hit_count = 0;
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> argv_0[argc] = {v8::Number::New(isolate, 0)};
|
|
|
|
foo->Call(context, env->Global(), argc, argv_0).ToLocalChecked();
|
2015-07-06 11:15:52 +00:00
|
|
|
CHECK_EQ(4, break_point_hit_count);
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
// Looping 10 times.
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2008-08-22 13:33:59 +00:00
|
|
|
break_point_hit_count = 0;
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> argv_10[argc] = {v8::Number::New(isolate, 10)};
|
|
|
|
foo->Call(context, env->Global(), argc, argv_10).ToLocalChecked();
|
2015-07-06 11:15:52 +00:00
|
|
|
CHECK_EQ(34, break_point_hit_count);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Looping 100 times.
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2008-08-22 13:33:59 +00:00
|
|
|
break_point_hit_count = 0;
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> argv_100[argc] = {v8::Number::New(isolate, 100)};
|
|
|
|
foo->Call(context, env->Global(), argc, argv_100).ToLocalChecked();
|
2015-07-06 11:15:52 +00:00
|
|
|
CHECK_EQ(304, break_point_hit_count);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Get rid of the debug event listener.
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-08 12:04:49 +00:00
|
|
|
TEST(DebugStepForContinue) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2014-01-03 14:31:17 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
|
|
|
// Register a debug event listener which steps and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter run_step;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &run_step);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2010-12-07 11:31:57 +00:00
|
|
|
// Create a function for testing stepping. Run it to allow it to get
|
|
|
|
// optimized.
|
2010-06-08 12:04:49 +00:00
|
|
|
const int argc = 1;
|
|
|
|
const char* src = "function foo(x) { "
|
|
|
|
" var a = 0;"
|
|
|
|
" var b = 0;"
|
|
|
|
" var c = 0;"
|
|
|
|
" for (var i = 0; i < x; i++) {"
|
|
|
|
" a++;"
|
|
|
|
" if (a % 2 == 0) continue;"
|
|
|
|
" b++;"
|
|
|
|
" c++;"
|
|
|
|
" }"
|
|
|
|
" return b;"
|
2010-12-07 11:31:57 +00:00
|
|
|
"}"
|
|
|
|
"foo()";
|
2010-06-08 12:04:49 +00:00
|
|
|
v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> result;
|
2010-06-08 12:04:49 +00:00
|
|
|
SetBreakPoint(foo, 8); // "var a = 0;"
|
|
|
|
|
|
|
|
// Each loop generates 4 or 5 steps depending on whether a is equal.
|
|
|
|
|
|
|
|
// Looping 10 times.
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2010-06-08 12:04:49 +00:00
|
|
|
break_point_hit_count = 0;
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> argv_10[argc] = {v8::Number::New(isolate, 10)};
|
|
|
|
result = foo->Call(context, env->Global(), argc, argv_10).ToLocalChecked();
|
|
|
|
CHECK_EQ(5, result->Int32Value(context).FromJust());
|
2016-03-11 12:02:37 +00:00
|
|
|
CHECK_EQ(62, break_point_hit_count);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
|
|
|
// Looping 100 times.
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2010-06-08 12:04:49 +00:00
|
|
|
break_point_hit_count = 0;
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> argv_100[argc] = {v8::Number::New(isolate, 100)};
|
|
|
|
result = foo->Call(context, env->Global(), argc, argv_100).ToLocalChecked();
|
|
|
|
CHECK_EQ(50, result->Int32Value(context).FromJust());
|
2016-03-11 12:02:37 +00:00
|
|
|
CHECK_EQ(557, break_point_hit_count);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
|
|
|
// Get rid of the debug event listener.
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2010-06-08 12:04:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DebugStepForBreak) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2014-01-03 14:31:17 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
|
|
|
// Register a debug event listener which steps and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter run_step;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &run_step);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2010-12-07 11:31:57 +00:00
|
|
|
// Create a function for testing stepping. Run it to allow it to get
|
|
|
|
// optimized.
|
2010-06-08 12:04:49 +00:00
|
|
|
const int argc = 1;
|
|
|
|
const char* src = "function foo(x) { "
|
|
|
|
" var a = 0;"
|
|
|
|
" var b = 0;"
|
|
|
|
" var c = 0;"
|
|
|
|
" for (var i = 0; i < 1000; i++) {"
|
|
|
|
" a++;"
|
|
|
|
" if (a == x) break;"
|
|
|
|
" b++;"
|
|
|
|
" c++;"
|
|
|
|
" }"
|
|
|
|
" return b;"
|
2010-12-07 11:31:57 +00:00
|
|
|
"}"
|
|
|
|
"foo()";
|
2010-06-08 12:04:49 +00:00
|
|
|
v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> result;
|
2010-06-08 12:04:49 +00:00
|
|
|
SetBreakPoint(foo, 8); // "var a = 0;"
|
|
|
|
|
|
|
|
// Each loop generates 5 steps except for the last (when break is executed)
|
|
|
|
// which only generates 4.
|
|
|
|
|
|
|
|
// Looping 10 times.
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2010-06-08 12:04:49 +00:00
|
|
|
break_point_hit_count = 0;
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> argv_10[argc] = {v8::Number::New(isolate, 10)};
|
|
|
|
result = foo->Call(context, env->Global(), argc, argv_10).ToLocalChecked();
|
|
|
|
CHECK_EQ(9, result->Int32Value(context).FromJust());
|
2016-03-11 12:02:37 +00:00
|
|
|
CHECK_EQ(64, break_point_hit_count);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
|
|
|
// Looping 100 times.
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2010-06-08 12:04:49 +00:00
|
|
|
break_point_hit_count = 0;
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> argv_100[argc] = {v8::Number::New(isolate, 100)};
|
|
|
|
result = foo->Call(context, env->Global(), argc, argv_100).ToLocalChecked();
|
|
|
|
CHECK_EQ(99, result->Int32Value(context).FromJust());
|
2016-03-11 12:02:37 +00:00
|
|
|
CHECK_EQ(604, break_point_hit_count);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
|
|
|
// Get rid of the debug event listener.
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2010-06-08 12:04:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DebugStepForIn) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2010-06-08 12:04:49 +00:00
|
|
|
|
|
|
|
// Register a debug event listener which steps and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter run_step;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &run_step);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2010-12-07 11:31:57 +00:00
|
|
|
// Create a function for testing stepping. Run it to allow it to get
|
|
|
|
// optimized.
|
2010-06-08 12:04:49 +00:00
|
|
|
v8::Local<v8::Function> foo;
|
|
|
|
const char* src_1 = "function foo() { "
|
|
|
|
" var a = [1, 2];"
|
|
|
|
" for (x in a) {"
|
|
|
|
" b = 0;"
|
|
|
|
" }"
|
2010-12-07 11:31:57 +00:00
|
|
|
"}"
|
|
|
|
"foo()";
|
2010-06-08 12:04:49 +00:00
|
|
|
foo = CompileFunction(&env, src_1, "foo");
|
|
|
|
SetBreakPoint(foo, 0); // "var a = ..."
|
|
|
|
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2010-06-08 12:04:49 +00:00
|
|
|
break_point_hit_count = 0;
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2014-11-12 08:25:59 +00:00
|
|
|
CHECK_EQ(8, break_point_hit_count);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Create a function for testing stepping. Run it to allow it to get
|
|
|
|
// optimized.
|
2010-06-08 12:04:49 +00:00
|
|
|
const char* src_2 = "function foo() { "
|
|
|
|
" var a = {a:[1, 2, 3]};"
|
|
|
|
" for (x in a.a) {"
|
|
|
|
" b = 0;"
|
|
|
|
" }"
|
2010-12-07 11:31:57 +00:00
|
|
|
"}"
|
|
|
|
"foo()";
|
2010-06-08 12:04:49 +00:00
|
|
|
foo = CompileFunction(&env, src_2, "foo");
|
|
|
|
SetBreakPoint(foo, 0); // "var a = ..."
|
|
|
|
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2010-06-08 12:04:49 +00:00
|
|
|
break_point_hit_count = 0;
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2014-11-12 08:25:59 +00:00
|
|
|
CHECK_EQ(10, break_point_hit_count);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
|
|
|
// Get rid of the debug event listener.
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2010-06-08 12:04:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DebugStepWith) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2010-06-08 12:04:49 +00:00
|
|
|
|
|
|
|
// Register a debug event listener which steps and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter run_step;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &run_step);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2010-12-07 11:31:57 +00:00
|
|
|
// Create a function for testing stepping. Run it to allow it to get
|
|
|
|
// optimized.
|
2010-06-08 12:04:49 +00:00
|
|
|
const char* src = "function foo(x) { "
|
|
|
|
" var a = {};"
|
|
|
|
" with (a) {}"
|
|
|
|
" with (b) {}"
|
2010-12-07 11:31:57 +00:00
|
|
|
"}"
|
|
|
|
"foo()";
|
2015-11-19 13:45:42 +00:00
|
|
|
CHECK(env->Global()
|
|
|
|
->Set(context, v8_str(env->GetIsolate(), "b"),
|
|
|
|
v8::Object::New(env->GetIsolate()))
|
|
|
|
.FromJust());
|
2010-06-08 12:04:49 +00:00
|
|
|
v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> result;
|
2010-06-08 12:04:49 +00:00
|
|
|
SetBreakPoint(foo, 8); // "var a = {};"
|
|
|
|
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2010-06-08 12:04:49 +00:00
|
|
|
break_point_hit_count = 0;
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2010-06-08 12:04:49 +00:00
|
|
|
CHECK_EQ(4, break_point_hit_count);
|
|
|
|
|
|
|
|
// Get rid of the debug event listener.
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2010-06-08 12:04:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DebugConditional) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-09-26 08:21:48 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
|
|
|
// Register a debug event listener which steps and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter run_step;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &run_step);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2010-12-07 11:31:57 +00:00
|
|
|
// Create a function for testing stepping. Run it to allow it to get
|
|
|
|
// optimized.
|
2016-03-15 11:00:29 +00:00
|
|
|
const char* src =
|
|
|
|
"function foo(x) { "
|
|
|
|
" return x ? 1 : 2;"
|
|
|
|
"}"
|
|
|
|
"foo()";
|
2010-06-08 12:04:49 +00:00
|
|
|
v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
|
|
|
|
SetBreakPoint(foo, 0); // "var a;"
|
|
|
|
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2010-06-08 12:04:49 +00:00
|
|
|
break_point_hit_count = 0;
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2016-03-15 11:00:29 +00:00
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2010-06-08 12:04:49 +00:00
|
|
|
break_point_hit_count = 0;
|
|
|
|
const int argc = 1;
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> argv_true[argc] = {v8::True(isolate)};
|
|
|
|
foo->Call(context, env->Global(), argc, argv_true).ToLocalChecked();
|
2016-03-15 11:00:29 +00:00
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
2010-06-08 12:04:49 +00:00
|
|
|
|
|
|
|
// Get rid of the debug event listener.
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that step in does not step into native functions.
|
|
|
|
TEST(DebugStepNatives) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Create a function for testing stepping.
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Function> foo =
|
|
|
|
CompileFunction(&env, "function foo(){debugger;Math.sin(1);}", "foo");
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Register a debug event listener which steps and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter run_step;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &run_step);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2008-08-22 13:33:59 +00:00
|
|
|
break_point_hit_count = 0;
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// With stepping all break locations are hit.
|
|
|
|
CHECK_EQ(3, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Register a debug event listener which just counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
break_point_hit_count = 0;
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Without stepping only active break points are hit.
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
2009-04-07 09:54:53 +00:00
|
|
|
// Test that step in works with function.apply.
|
|
|
|
TEST(DebugStepFunctionApply) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2009-04-07 09:54:53 +00:00
|
|
|
|
|
|
|
// Create a function for testing stepping.
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Function> foo =
|
|
|
|
CompileFunction(&env,
|
|
|
|
"function bar(x, y, z) { if (x == 1) { a = y; b = z; } }"
|
|
|
|
"function foo(){ debugger; bar.apply(this, [1,2,3]); }",
|
|
|
|
"foo");
|
2009-04-07 09:54:53 +00:00
|
|
|
|
|
|
|
// Register a debug event listener which steps and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter run_step;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &run_step);
|
2009-04-07 09:54:53 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2009-04-07 09:54:53 +00:00
|
|
|
break_point_hit_count = 0;
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2009-04-07 09:54:53 +00:00
|
|
|
|
|
|
|
// With stepping all break locations are hit.
|
2010-06-08 12:04:49 +00:00
|
|
|
CHECK_EQ(7, break_point_hit_count);
|
2009-04-07 09:54:53 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2009-04-07 09:54:53 +00:00
|
|
|
|
|
|
|
// Register a debug event listener which just counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2009-04-07 09:54:53 +00:00
|
|
|
|
|
|
|
break_point_hit_count = 0;
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2009-04-07 09:54:53 +00:00
|
|
|
|
|
|
|
// Without stepping only the debugger statement is hit.
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2009-04-07 09:54:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-07 12:11:43 +00:00
|
|
|
// Test that step in works with function.call.
|
|
|
|
TEST(DebugStepFunctionCall) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-09-26 08:21:48 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2009-04-07 12:11:43 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2009-04-07 12:11:43 +00:00
|
|
|
// Create a function for testing stepping.
|
|
|
|
v8::Local<v8::Function> foo = CompileFunction(
|
|
|
|
&env,
|
|
|
|
"function bar(x, y, z) { if (x == 1) { a = y; b = z; } }"
|
|
|
|
"function foo(a){ debugger;"
|
|
|
|
" if (a) {"
|
|
|
|
" bar.call(this, 1, 2, 3);"
|
|
|
|
" } else {"
|
|
|
|
" bar.call(this, 0);"
|
|
|
|
" }"
|
|
|
|
"}",
|
|
|
|
"foo");
|
|
|
|
|
|
|
|
// Register a debug event listener which steps and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter run_step;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &run_step);
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2009-04-07 12:11:43 +00:00
|
|
|
|
|
|
|
// Check stepping where the if condition in bar is false.
|
|
|
|
break_point_hit_count = 0;
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2010-06-08 12:04:49 +00:00
|
|
|
CHECK_EQ(6, break_point_hit_count);
|
2009-04-07 12:11:43 +00:00
|
|
|
|
|
|
|
// Check stepping where the if condition in bar is true.
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
const int argc = 1;
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> argv[argc] = {v8::True(isolate)};
|
|
|
|
foo->Call(context, env->Global(), argc, argv).ToLocalChecked();
|
2010-06-08 12:04:49 +00:00
|
|
|
CHECK_EQ(8, break_point_hit_count);
|
2009-04-07 12:11:43 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2009-04-07 12:11:43 +00:00
|
|
|
|
|
|
|
// Register a debug event listener which just counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2009-04-07 12:11:43 +00:00
|
|
|
|
|
|
|
break_point_hit_count = 0;
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2009-04-07 12:11:43 +00:00
|
|
|
|
|
|
|
// Without stepping only the debugger statement is hit.
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(isolate, nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2009-04-07 12:11:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-16 11:09:50 +00:00
|
|
|
// Test that step in works with Function.call.apply.
|
|
|
|
TEST(DebugStepFunctionCallApply) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2015-06-16 11:09:50 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2015-06-16 11:09:50 +00:00
|
|
|
// Create a function for testing stepping.
|
|
|
|
v8::Local<v8::Function> foo =
|
|
|
|
CompileFunction(&env,
|
|
|
|
"function bar() { }"
|
|
|
|
"function foo(){ debugger;"
|
|
|
|
" Function.call.apply(bar);"
|
|
|
|
" Function.call.apply(Function.call, "
|
|
|
|
"[Function.call, bar]);"
|
|
|
|
"}",
|
|
|
|
"foo");
|
|
|
|
|
|
|
|
// Register a debug event listener which steps and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter run_step;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &run_step);
|
2021-06-01 08:32:39 +00:00
|
|
|
run_step.set_step_action(StepInto);
|
2015-06-16 11:09:50 +00:00
|
|
|
|
|
|
|
break_point_hit_count = 0;
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2015-11-26 14:12:04 +00:00
|
|
|
CHECK_EQ(6, break_point_hit_count);
|
2015-06-16 11:09:50 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2015-06-16 11:09:50 +00:00
|
|
|
|
|
|
|
// Register a debug event listener which just counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2015-06-16 11:09:50 +00:00
|
|
|
|
|
|
|
break_point_hit_count = 0;
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2015-06-16 11:09:50 +00:00
|
|
|
|
|
|
|
// Without stepping only the debugger statement is hit.
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(isolate, nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2015-06-16 11:09:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-13 14:04:08 +00:00
|
|
|
// Tests that breakpoint will be hit if it's set in script.
|
|
|
|
TEST(PauseInScript) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2018-02-26 09:20:45 +00:00
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(env->GetIsolate());
|
2009-11-13 14:04:08 +00:00
|
|
|
|
|
|
|
// Register a debug event listener which counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter event_counter;
|
2018-07-05 17:55:17 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &event_counter);
|
2009-11-13 14:04:08 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2009-11-13 14:04:08 +00:00
|
|
|
// Create a script that returns a function.
|
|
|
|
const char* src = "(function (evt) {})";
|
|
|
|
const char* script_name = "StepInHandlerTest";
|
|
|
|
|
2021-01-12 11:54:50 +00:00
|
|
|
v8::ScriptOrigin origin(env->GetIsolate(),
|
|
|
|
v8_str(env->GetIsolate(), script_name));
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Script> script =
|
|
|
|
v8::Script::Compile(context, v8_str(env->GetIsolate(), src), &origin)
|
|
|
|
.ToLocalChecked();
|
2016-12-07 11:44:00 +00:00
|
|
|
|
|
|
|
// Set breakpoint in the script.
|
2018-02-26 09:20:45 +00:00
|
|
|
i::Handle<i::Script> i_script(
|
2018-06-23 09:05:50 +00:00
|
|
|
i::Script::cast(v8::Utils::OpenHandle(*script)->shared().script()),
|
|
|
|
isolate);
|
2018-03-22 12:12:28 +00:00
|
|
|
i::Handle<i::String> condition = isolate->factory()->empty_string();
|
|
|
|
int position = 0;
|
|
|
|
int id;
|
|
|
|
isolate->debug()->SetBreakPointForScript(i_script, condition, &position, &id);
|
2016-12-07 11:44:00 +00:00
|
|
|
break_point_hit_count = 0;
|
|
|
|
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> r = script->Run(context).ToLocalChecked();
|
2009-11-13 14:04:08 +00:00
|
|
|
|
|
|
|
CHECK(r->IsFunction());
|
2009-11-13 15:05:50 +00:00
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
2009-11-13 14:04:08 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
// Get rid of the debug delegate.
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
int message_callback_count = 0;
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
TEST(DebugBreak) {
|
2022-09-15 11:04:11 +00:00
|
|
|
i::v8_flags.stress_compaction = false;
|
2012-10-12 11:41:14 +00:00
|
|
|
#ifdef VERIFY_HEAP
|
2022-09-15 11:04:11 +00:00
|
|
|
i::v8_flags.verify_heap = true;
|
2012-10-12 11:41:14 +00:00
|
|
|
#endif
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2014-01-03 14:31:17 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Register a debug event listener which sets the break flag and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventBreak delegate;
|
|
|
|
v8::debug::SetDebugDelegate(isolate, &delegate);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2008-08-22 13:33:59 +00:00
|
|
|
// Create a function for testing stepping.
|
|
|
|
const char* src = "function f0() {}"
|
|
|
|
"function f1(x1) {}"
|
|
|
|
"function f2(x1,x2) {}"
|
|
|
|
"function f3(x1,x2,x3) {}";
|
|
|
|
v8::Local<v8::Function> f0 = CompileFunction(&env, src, "f0");
|
|
|
|
v8::Local<v8::Function> f1 = CompileFunction(&env, src, "f1");
|
|
|
|
v8::Local<v8::Function> f2 = CompileFunction(&env, src, "f2");
|
|
|
|
v8::Local<v8::Function> f3 = CompileFunction(&env, src, "f3");
|
|
|
|
|
|
|
|
// Call the function to make sure it is compiled.
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Value> argv[] = {
|
|
|
|
v8::Number::New(isolate, 1), v8::Number::New(isolate, 1),
|
|
|
|
v8::Number::New(isolate, 1), v8::Number::New(isolate, 1)};
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Call all functions to make sure that they are compiled.
|
2017-10-13 16:33:03 +00:00
|
|
|
f0->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
|
|
|
f1->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
|
|
|
f2->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
|
|
|
f3->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Set the debug break flag.
|
[inspector] use interrupt for pause only as last resort
With this CL we use interrupt for pause in two cases:
- when we process Debugger.pause on interruption,
- when we would like to break as soon as possible after OOM.
In all other cases, e.g. for async step into we use break
on function call by calling StepIn debugger action.
In mentioned cases we should not actually use interrupt as well:
- Debugger.pause in this case scheduled using interrupt and we
may just break right now without requesting another interrupt,
unfortunately blink side is not ready,
- we should use more reliable way to break right after near OOM
callback, otherwise we can get this callback, increase limit,
request break on next interrupt, before interrupt get another
huge memory allocation and crash.
There are couple advantages:
- we get much better break locations for async stepping
(see inspector tests expectations),
- we can remove DEBUG_BREAK interruption
(it should speedup blackboxing with async tasks, see
removed todo in debug.cc for details)
- it is required preparation step for async step out,
(see https://chromium-review.googlesource.com/c/v8/v8/+/1054618)
Bug: v8:7753
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Iabd7627dbffa9a0eab1736064caf589d02591926
Reviewed-on: https://chromium-review.googlesource.com/1054155
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53439}
2018-05-29 14:54:08 +00:00
|
|
|
v8::debug::SetBreakOnNextFunctionCall(env->GetIsolate());
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Call all functions with different argument count.
|
|
|
|
break_point_hit_count = 0;
|
2014-08-26 09:19:24 +00:00
|
|
|
for (unsigned int i = 0; i < arraysize(argv); i++) {
|
2015-11-19 13:45:42 +00:00
|
|
|
f0->Call(context, env->Global(), i, argv).ToLocalChecked();
|
|
|
|
f1->Call(context, env->Global(), i, argv).ToLocalChecked();
|
|
|
|
f2->Call(context, env->Global(), i, argv).ToLocalChecked();
|
|
|
|
f3->Call(context, env->Global(), i, argv).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// One break for each function called.
|
2017-10-18 09:06:55 +00:00
|
|
|
CHECK_EQ(4 * arraysize(argv), break_point_hit_count);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Get rid of the debug event listener.
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
class DebugScopingListener : public v8::debug::DebugDelegate {
|
|
|
|
public:
|
2020-02-03 13:45:06 +00:00
|
|
|
void ExceptionThrown(v8::Local<v8::Context> paused_context,
|
|
|
|
v8::Local<v8::Value> exception,
|
|
|
|
v8::Local<v8::Value> promise, bool is_uncaught,
|
|
|
|
v8::debug::ExceptionType exception_type) override {
|
|
|
|
break_count_++;
|
2018-06-03 05:09:41 +00:00
|
|
|
auto stack_traces =
|
|
|
|
v8::debug::StackTraceIterator::Create(CcTest::isolate());
|
|
|
|
v8::debug::Location location = stack_traces->GetSourceLocation();
|
|
|
|
CHECK_EQ(26, location.GetColumnNumber());
|
|
|
|
CHECK_EQ(0, location.GetLineNumber());
|
|
|
|
|
|
|
|
auto scopes = stack_traces->GetScopeIterator();
|
|
|
|
CHECK_EQ(v8::debug::ScopeIterator::ScopeTypeWith, scopes->GetType());
|
|
|
|
CHECK_EQ(20, scopes->GetStartLocation().GetColumnNumber());
|
|
|
|
CHECK_EQ(31, scopes->GetEndLocation().GetColumnNumber());
|
|
|
|
|
|
|
|
scopes->Advance();
|
|
|
|
CHECK_EQ(v8::debug::ScopeIterator::ScopeTypeLocal, scopes->GetType());
|
|
|
|
CHECK_EQ(0, scopes->GetStartLocation().GetColumnNumber());
|
|
|
|
CHECK_EQ(68, scopes->GetEndLocation().GetColumnNumber());
|
|
|
|
|
|
|
|
scopes->Advance();
|
|
|
|
CHECK_EQ(v8::debug::ScopeIterator::ScopeTypeGlobal, scopes->GetType());
|
|
|
|
|
|
|
|
scopes->Advance();
|
|
|
|
CHECK(scopes->Done());
|
|
|
|
}
|
2020-02-03 13:45:06 +00:00
|
|
|
unsigned break_count() const { return break_count_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned break_count_ = 0;
|
2018-06-03 05:09:41 +00:00
|
|
|
};
|
2017-12-18 08:10:06 +00:00
|
|
|
|
|
|
|
TEST(DebugBreakInWrappedScript) {
|
2022-09-15 11:04:11 +00:00
|
|
|
i::v8_flags.stress_compaction = false;
|
2017-12-18 08:10:06 +00:00
|
|
|
#ifdef VERIFY_HEAP
|
2022-09-15 11:04:11 +00:00
|
|
|
i::v8_flags.verify_heap = true;
|
2017-12-18 08:10:06 +00:00
|
|
|
#endif
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2017-12-18 08:10:06 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
|
|
|
|
// Register a debug event listener which sets the break flag and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugScopingListener delegate;
|
|
|
|
v8::debug::SetDebugDelegate(isolate, &delegate);
|
2017-12-18 08:10:06 +00:00
|
|
|
|
|
|
|
static const char* source =
|
|
|
|
// 0 1 2 3 4 5 6 7
|
|
|
|
"try { with({o : []}){ o[0](); } } catch (e) { return e.toString(); }";
|
|
|
|
static const char* expect = "TypeError: o[0] is not a function";
|
|
|
|
|
|
|
|
// For this test, we want to break on uncaught exceptions:
|
2021-04-30 16:19:52 +00:00
|
|
|
ChangeBreakOnException(isolate, true, true);
|
2017-12-18 08:10:06 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
v8::ScriptCompiler::Source script_source(v8_str(source));
|
|
|
|
v8::Local<v8::Function> fun =
|
2021-10-26 13:36:11 +00:00
|
|
|
v8::ScriptCompiler::CompileFunction(env.local(), &script_source)
|
2017-12-18 08:10:06 +00:00
|
|
|
.ToLocalChecked();
|
|
|
|
v8::Local<v8::Value> result =
|
2018-06-03 05:09:41 +00:00
|
|
|
fun->Call(env.local(), env->Global(), 0, nullptr).ToLocalChecked();
|
2017-12-18 08:10:06 +00:00
|
|
|
CHECK(result->IsString());
|
|
|
|
CHECK(v8::Local<v8::String>::Cast(result)
|
2018-06-03 05:09:41 +00:00
|
|
|
->Equals(env.local(), v8_str(expect))
|
2017-12-18 08:10:06 +00:00
|
|
|
.FromJust());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get rid of the debug event listener.
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2020-02-03 13:45:06 +00:00
|
|
|
CHECK_EQ(1, delegate.break_count());
|
2017-12-18 08:10:06 +00:00
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
2018-10-22 09:25:04 +00:00
|
|
|
static void EmptyHandler(const v8::FunctionCallbackInfo<v8::Value>& args) {}
|
|
|
|
|
|
|
|
TEST(DebugScopeIteratorWithFunctionTemplate) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope handle_scope(env->GetIsolate());
|
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
EnableDebugger(isolate);
|
|
|
|
v8::Local<v8::Function> func =
|
|
|
|
v8::Function::New(env.local(), EmptyHandler).ToLocalChecked();
|
|
|
|
std::unique_ptr<v8::debug::ScopeIterator> iterator =
|
|
|
|
v8::debug::ScopeIterator::CreateForFunction(isolate, func);
|
|
|
|
CHECK(iterator->Done());
|
|
|
|
DisableDebugger(isolate);
|
|
|
|
}
|
|
|
|
|
2017-11-29 14:00:16 +00:00
|
|
|
TEST(DebugBreakWithoutJS) {
|
2022-09-15 11:04:11 +00:00
|
|
|
i::v8_flags.stress_compaction = false;
|
2017-11-29 14:00:16 +00:00
|
|
|
#ifdef VERIFY_HEAP
|
2022-09-15 11:04:11 +00:00
|
|
|
i::v8_flags.verify_heap = true;
|
2017-11-29 14:00:16 +00:00
|
|
|
#endif
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2017-11-29 14:00:16 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2017-11-29 14:00:16 +00:00
|
|
|
|
|
|
|
// Register a debug event listener which sets the break flag and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventBreak delegate;
|
|
|
|
v8::debug::SetDebugDelegate(isolate, &delegate);
|
2017-11-29 14:00:16 +00:00
|
|
|
|
|
|
|
// Set the debug break flag.
|
[inspector] use interrupt for pause only as last resort
With this CL we use interrupt for pause in two cases:
- when we process Debugger.pause on interruption,
- when we would like to break as soon as possible after OOM.
In all other cases, e.g. for async step into we use break
on function call by calling StepIn debugger action.
In mentioned cases we should not actually use interrupt as well:
- Debugger.pause in this case scheduled using interrupt and we
may just break right now without requesting another interrupt,
unfortunately blink side is not ready,
- we should use more reliable way to break right after near OOM
callback, otherwise we can get this callback, increase limit,
request break on next interrupt, before interrupt get another
huge memory allocation and crash.
There are couple advantages:
- we get much better break locations for async stepping
(see inspector tests expectations),
- we can remove DEBUG_BREAK interruption
(it should speedup blackboxing with async tasks, see
removed todo in debug.cc for details)
- it is required preparation step for async step out,
(see https://chromium-review.googlesource.com/c/v8/v8/+/1054618)
Bug: v8:7753
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Iabd7627dbffa9a0eab1736064caf589d02591926
Reviewed-on: https://chromium-review.googlesource.com/1054155
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53439}
2018-05-29 14:54:08 +00:00
|
|
|
v8::debug::SetBreakOnNextFunctionCall(env->GetIsolate());
|
2017-11-29 14:00:16 +00:00
|
|
|
|
|
|
|
v8::Local<v8::String> json = v8_str("[1]");
|
|
|
|
v8::Local<v8::Value> parsed = v8::JSON::Parse(context, json).ToLocalChecked();
|
|
|
|
CHECK(v8::JSON::Stringify(context, parsed)
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Equals(context, json)
|
|
|
|
.FromJust());
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
CompileRun("");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
// Get rid of the debug event listener.
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-11-29 14:00:16 +00:00
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// 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) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Register a debug event listener which sets the break flag and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2008-08-22 13:33:59 +00:00
|
|
|
// Create a function for testing stepping.
|
|
|
|
const char* src = "function f() {g()};function g(){i=0; while(i<10){i++}}";
|
|
|
|
v8::Local<v8::Function> f = CompileFunction(&env, src, "f");
|
|
|
|
|
2014-08-20 11:04:05 +00:00
|
|
|
// Set, test and cancel debug break.
|
[inspector] use interrupt for pause only as last resort
With this CL we use interrupt for pause in two cases:
- when we process Debugger.pause on interruption,
- when we would like to break as soon as possible after OOM.
In all other cases, e.g. for async step into we use break
on function call by calling StepIn debugger action.
In mentioned cases we should not actually use interrupt as well:
- Debugger.pause in this case scheduled using interrupt and we
may just break right now without requesting another interrupt,
unfortunately blink side is not ready,
- we should use more reliable way to break right after near OOM
callback, otherwise we can get this callback, increase limit,
request break on next interrupt, before interrupt get another
huge memory allocation and crash.
There are couple advantages:
- we get much better break locations for async stepping
(see inspector tests expectations),
- we can remove DEBUG_BREAK interruption
(it should speedup blackboxing with async tasks, see
removed todo in debug.cc for details)
- it is required preparation step for async step out,
(see https://chromium-review.googlesource.com/c/v8/v8/+/1054618)
Bug: v8:7753
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Iabd7627dbffa9a0eab1736064caf589d02591926
Reviewed-on: https://chromium-review.googlesource.com/1054155
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53439}
2018-05-29 14:54:08 +00:00
|
|
|
v8::debug::SetBreakOnNextFunctionCall(env->GetIsolate());
|
|
|
|
v8::debug::ClearBreakOnNextFunctionCall(env->GetIsolate());
|
2014-08-20 11:04:05 +00:00
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
// Set the debug break flag.
|
[inspector] use interrupt for pause only as last resort
With this CL we use interrupt for pause in two cases:
- when we process Debugger.pause on interruption,
- when we would like to break as soon as possible after OOM.
In all other cases, e.g. for async step into we use break
on function call by calling StepIn debugger action.
In mentioned cases we should not actually use interrupt as well:
- Debugger.pause in this case scheduled using interrupt and we
may just break right now without requesting another interrupt,
unfortunately blink side is not ready,
- we should use more reliable way to break right after near OOM
callback, otherwise we can get this callback, increase limit,
request break on next interrupt, before interrupt get another
huge memory allocation and crash.
There are couple advantages:
- we get much better break locations for async stepping
(see inspector tests expectations),
- we can remove DEBUG_BREAK interruption
(it should speedup blackboxing with async tasks, see
removed todo in debug.cc for details)
- it is required preparation step for async step out,
(see https://chromium-review.googlesource.com/c/v8/v8/+/1054618)
Bug: v8:7753
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Iabd7627dbffa9a0eab1736064caf589d02591926
Reviewed-on: https://chromium-review.googlesource.com/1054155
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53439}
2018-05-29 14:54:08 +00:00
|
|
|
v8::debug::SetBreakOnNextFunctionCall(env->GetIsolate());
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Call all functions with different argument count.
|
|
|
|
break_point_hit_count = 0;
|
2017-10-13 16:33:03 +00:00
|
|
|
f->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
{
|
[inspector] use interrupt for pause only as last resort
With this CL we use interrupt for pause in two cases:
- when we process Debugger.pause on interruption,
- when we would like to break as soon as possible after OOM.
In all other cases, e.g. for async step into we use break
on function call by calling StepIn debugger action.
In mentioned cases we should not actually use interrupt as well:
- Debugger.pause in this case scheduled using interrupt and we
may just break right now without requesting another interrupt,
unfortunately blink side is not ready,
- we should use more reliable way to break right after near OOM
callback, otherwise we can get this callback, increase limit,
request break on next interrupt, before interrupt get another
huge memory allocation and crash.
There are couple advantages:
- we get much better break locations for async stepping
(see inspector tests expectations),
- we can remove DEBUG_BREAK interruption
(it should speedup blackboxing with async tasks, see
removed todo in debug.cc for details)
- it is required preparation step for async step out,
(see https://chromium-review.googlesource.com/c/v8/v8/+/1054618)
Bug: v8:7753
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Iabd7627dbffa9a0eab1736064caf589d02591926
Reviewed-on: https://chromium-review.googlesource.com/1054155
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53439}
2018-05-29 14:54:08 +00:00
|
|
|
v8::debug::SetBreakOnNextFunctionCall(env->GetIsolate());
|
2013-09-03 06:59:01 +00:00
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(env->GetIsolate());
|
2016-12-19 10:44:34 +00:00
|
|
|
v8::internal::DisableBreak disable_break(isolate->debug());
|
2017-10-13 16:33:03 +00:00
|
|
|
f->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
}
|
|
|
|
|
2017-10-13 16:33:03 +00:00
|
|
|
f->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
|
|
|
// Get rid of the debug event listener.
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
2016-02-12 20:55:10 +00:00
|
|
|
TEST(DisableDebuggerStatement) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2016-02-12 20:55:10 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
|
|
|
// Register a debug event listener which sets the break flag and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
|
|
|
|
2016-02-12 20:55:10 +00:00
|
|
|
CompileRun("debugger;");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
// Check that we ignore debugger statement when breakpoints aren't active.
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(env->GetIsolate());
|
|
|
|
isolate->debug()->set_break_points_active(false);
|
|
|
|
CompileRun("debugger;");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
2018-06-03 05:09:41 +00:00
|
|
|
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2016-02-12 20:55:10 +00:00
|
|
|
}
|
|
|
|
|
2009-12-15 09:17:15 +00:00
|
|
|
static const char* kSimpleExtensionSource =
|
|
|
|
"(function Foo() {"
|
|
|
|
" return 4;"
|
|
|
|
"})() ";
|
|
|
|
|
|
|
|
// http://crbug.com/28933
|
|
|
|
// Test that debug break is disabled when bootstrapper is active.
|
|
|
|
TEST(NoBreakWhenBootstrapping) {
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
2013-05-08 07:45:16 +00:00
|
|
|
v8::HandleScope scope(isolate);
|
2009-12-15 09:17:15 +00:00
|
|
|
|
|
|
|
// Register a debug event listener which sets the break flag and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(isolate, &delegate);
|
2009-12-15 09:17:15 +00:00
|
|
|
|
|
|
|
// Set the debug break flag.
|
[inspector] use interrupt for pause only as last resort
With this CL we use interrupt for pause in two cases:
- when we process Debugger.pause on interruption,
- when we would like to break as soon as possible after OOM.
In all other cases, e.g. for async step into we use break
on function call by calling StepIn debugger action.
In mentioned cases we should not actually use interrupt as well:
- Debugger.pause in this case scheduled using interrupt and we
may just break right now without requesting another interrupt,
unfortunately blink side is not ready,
- we should use more reliable way to break right after near OOM
callback, otherwise we can get this callback, increase limit,
request break on next interrupt, before interrupt get another
huge memory allocation and crash.
There are couple advantages:
- we get much better break locations for async stepping
(see inspector tests expectations),
- we can remove DEBUG_BREAK interruption
(it should speedup blackboxing with async tasks, see
removed todo in debug.cc for details)
- it is required preparation step for async step out,
(see https://chromium-review.googlesource.com/c/v8/v8/+/1054618)
Bug: v8:7753
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Iabd7627dbffa9a0eab1736064caf589d02591926
Reviewed-on: https://chromium-review.googlesource.com/1054155
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53439}
2018-05-29 14:54:08 +00:00
|
|
|
v8::debug::SetBreakOnNextFunctionCall(isolate);
|
2009-12-15 09:17:15 +00:00
|
|
|
break_point_hit_count = 0;
|
|
|
|
{
|
|
|
|
// Create a context with an extension to make sure that some JavaScript
|
|
|
|
// code is executed during bootstrapping.
|
2019-09-10 10:12:00 +00:00
|
|
|
v8::RegisterExtension(
|
|
|
|
std::make_unique<v8::Extension>("simpletest", kSimpleExtensionSource));
|
2009-12-15 09:17:15 +00:00
|
|
|
const char* extension_names[] = { "simpletest" };
|
|
|
|
v8::ExtensionConfiguration extensions(1, extension_names);
|
2013-05-08 07:45:16 +00:00
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
v8::Context::New(isolate, &extensions);
|
2009-12-15 09:17:15 +00:00
|
|
|
}
|
2017-08-02 08:23:36 +00:00
|
|
|
// Check that no DebugBreak events occurred during the context creation.
|
2009-12-15 09:17:15 +00:00
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
2009-12-15 09:34:00 +00:00
|
|
|
|
2009-12-15 09:17:15 +00:00
|
|
|
// Get rid of the debug event listener.
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(isolate, nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2009-12-15 09:17:15 +00:00
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
TEST(SetDebugEventListenerOnUninitializedVM) {
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
EnableDebugger(CcTest::isolate());
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
// Test that clearing the debug event listener actually clears all break points
|
|
|
|
// and related information.
|
|
|
|
TEST(DebuggerUnload) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope handle_scope(env->GetIsolate());
|
|
|
|
// Check debugger is unloaded before it is used.
|
|
|
|
CheckDebuggerUnloaded();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
// Set a debug event listener.
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
|
|
|
v8::Local<v8::Context> context = env.local();
|
|
|
|
{
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
// Create a couple of functions for the test.
|
|
|
|
v8::Local<v8::Function> foo =
|
|
|
|
CompileFunction(&env, "function foo(){x=1}", "foo");
|
|
|
|
v8::Local<v8::Function> bar =
|
|
|
|
CompileFunction(&env, "function bar(){y=2}", "bar");
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
// Set some break points.
|
|
|
|
SetBreakPoint(foo, 0);
|
|
|
|
SetBreakPoint(foo, 4);
|
|
|
|
SetBreakPoint(bar, 0);
|
|
|
|
SetBreakPoint(bar, 4);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
// Make sure that the break points are there.
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
bar->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
|
|
|
CHECK_EQ(4, break_point_hit_count);
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
2018-06-03 05:09:41 +00:00
|
|
|
|
|
|
|
// Remove the debug event listener without clearing breakpoints. Do this
|
|
|
|
// outside a handle scope.
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
|
|
|
CheckDebuggerUnloaded();
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
int event_listener_hit_count = 0;
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
// 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 {
|
|
|
|
public:
|
|
|
|
EmptyExternalStringResource() { empty_[0] = 0; }
|
2018-09-18 08:31:21 +00:00
|
|
|
~EmptyExternalStringResource() override = default;
|
2018-09-14 15:34:02 +00:00
|
|
|
size_t length() const override { return empty_.length(); }
|
2019-04-29 11:06:49 +00:00
|
|
|
const uint16_t* data() const override { return empty_.begin(); }
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
private:
|
2021-06-17 15:43:55 +00:00
|
|
|
::v8::base::EmbeddedVector<uint16_t, 1> empty_;
|
2018-06-03 05:09:41 +00:00
|
|
|
};
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
TEST(DebugScriptLineEndsAreAscending) {
|
|
|
|
LocalContext env;
|
2014-01-08 06:53:31 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
// Compile a test script.
|
2021-09-27 08:19:16 +00:00
|
|
|
v8::Local<v8::String> script_source = v8_str(isolate,
|
|
|
|
"function f() {\n"
|
|
|
|
" debugger;\n"
|
|
|
|
"}\n");
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2021-01-12 11:54:50 +00:00
|
|
|
v8::ScriptOrigin origin1 = v8::ScriptOrigin(isolate, v8_str(isolate, "name"));
|
2021-09-27 08:19:16 +00:00
|
|
|
v8::Local<v8::Script> script =
|
|
|
|
v8::Script::Compile(env.local(), script_source, &origin1)
|
|
|
|
.ToLocalChecked();
|
|
|
|
USE(script);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
Handle<v8::internal::FixedArray> instances;
|
|
|
|
{
|
|
|
|
v8::internal::Debug* debug = CcTest::i_isolate()->debug();
|
|
|
|
instances = debug->GetLoadedScripts();
|
|
|
|
}
|
2016-05-24 06:40:06 +00:00
|
|
|
|
|
|
|
CHECK_GT(instances->length(), 0);
|
|
|
|
for (int i = 0; i < instances->length(); i++) {
|
2021-09-27 08:19:16 +00:00
|
|
|
Handle<v8::internal::Script> new_script = Handle<v8::internal::Script>(
|
2018-06-26 10:14:12 +00:00
|
|
|
v8::internal::Script::cast(instances->get(i)), CcTest::i_isolate());
|
2016-05-24 06:40:06 +00:00
|
|
|
|
2021-09-27 08:19:16 +00:00
|
|
|
v8::internal::Script::InitLineEnds(CcTest::i_isolate(), new_script);
|
2018-11-25 02:24:43 +00:00
|
|
|
v8::internal::FixedArray ends =
|
2021-09-27 08:19:16 +00:00
|
|
|
v8::internal::FixedArray::cast(new_script->line_ends());
|
2016-05-24 06:40:06 +00:00
|
|
|
CHECK_GT(ends.length(), 0);
|
|
|
|
|
|
|
|
int prev_end = -1;
|
|
|
|
for (int j = 0; j < ends.length(); j++) {
|
2017-07-10 12:58:27 +00:00
|
|
|
const int curr_end = v8::internal::Smi::ToInt(ends.get(j));
|
2016-05-24 06:40:06 +00:00
|
|
|
CHECK_GT(curr_end, prev_end);
|
|
|
|
prev_end = curr_end;
|
|
|
|
}
|
|
|
|
}
|
2009-03-27 11:22:52 +00:00
|
|
|
}
|
2009-04-21 07:22:06 +00:00
|
|
|
|
2015-11-19 13:45:42 +00:00
|
|
|
static v8::Local<v8::Context> expected_context;
|
|
|
|
static v8::Local<v8::Value> expected_context_data;
|
2009-05-05 09:38:45 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
class ContextCheckEventListener : public v8::debug::DebugDelegate {
|
|
|
|
public:
|
2021-11-23 09:14:18 +00:00
|
|
|
void BreakProgramRequested(
|
|
|
|
v8::Local<v8::Context> paused_context,
|
|
|
|
const std::vector<v8::debug::BreakpointId>& inspector_break_points_hit,
|
2021-12-02 09:26:01 +00:00
|
|
|
v8::debug::BreakReasons break_reasons) override {
|
2018-06-03 05:09:41 +00:00
|
|
|
CheckContext();
|
|
|
|
}
|
|
|
|
void ScriptCompiled(v8::Local<v8::debug::Script> script, bool is_live_edited,
|
|
|
|
bool has_compile_error) override {
|
|
|
|
CheckContext();
|
|
|
|
}
|
|
|
|
void ExceptionThrown(v8::Local<v8::Context> paused_context,
|
|
|
|
v8::Local<v8::Value> exception,
|
2018-09-28 15:05:45 +00:00
|
|
|
v8::Local<v8::Value> promise, bool is_uncaught,
|
|
|
|
v8::debug::ExceptionType) override {
|
2018-06-03 05:09:41 +00:00
|
|
|
CheckContext();
|
|
|
|
}
|
|
|
|
bool IsFunctionBlackboxed(v8::Local<v8::debug::Script> script,
|
|
|
|
const v8::debug::Location& start,
|
|
|
|
const v8::debug::Location& end) override {
|
|
|
|
CheckContext();
|
|
|
|
return false;
|
|
|
|
}
|
2009-05-05 09:38:45 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
private:
|
|
|
|
void CheckContext() {
|
|
|
|
v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext();
|
|
|
|
CHECK(context == expected_context);
|
|
|
|
CHECK(context->GetEmbedderData(0)->StrictEquals(expected_context_data));
|
|
|
|
event_listener_hit_count++;
|
|
|
|
}
|
|
|
|
};
|
2009-05-05 09:38:45 +00:00
|
|
|
|
|
|
|
// Test which creates two contexts and sets different embedder data on each.
|
2016-11-24 10:43:00 +00:00
|
|
|
// Checks that this data is set correctly and that when the debug event
|
|
|
|
// listener is called the expected context is the one active.
|
2009-05-05 09:38:45 +00:00
|
|
|
TEST(ContextData) {
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
2013-05-02 20:18:42 +00:00
|
|
|
v8::HandleScope scope(isolate);
|
2009-05-05 09:38:45 +00:00
|
|
|
|
|
|
|
// Create two contexts.
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Context> context_1;
|
|
|
|
v8::Local<v8::Context> context_2;
|
|
|
|
v8::Local<v8::ObjectTemplate> global_template =
|
|
|
|
v8::Local<v8::ObjectTemplate>();
|
|
|
|
v8::Local<v8::Value> global_object = v8::Local<v8::Value>();
|
2017-10-13 16:33:03 +00:00
|
|
|
context_1 =
|
|
|
|
v8::Context::New(isolate, nullptr, global_template, global_object);
|
|
|
|
context_2 =
|
|
|
|
v8::Context::New(isolate, nullptr, global_template, global_object);
|
2009-05-05 09:38:45 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
ContextCheckEventListener delegate;
|
|
|
|
v8::debug::SetDebugDelegate(isolate, &delegate);
|
2013-07-05 13:33:20 +00:00
|
|
|
|
2009-05-05 09:38:45 +00:00
|
|
|
// Default data value is undefined.
|
2018-03-08 11:40:04 +00:00
|
|
|
CHECK_EQ(0, context_1->GetNumberOfEmbedderDataFields());
|
|
|
|
CHECK_EQ(0, context_2->GetNumberOfEmbedderDataFields());
|
2009-05-05 09:38:45 +00:00
|
|
|
|
|
|
|
// Set and check different data values.
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::String> data_1 = v8_str(isolate, "1");
|
|
|
|
v8::Local<v8::String> data_2 = v8_str(isolate, "2");
|
2013-01-14 13:41:08 +00:00
|
|
|
context_1->SetEmbedderData(0, data_1);
|
|
|
|
context_2->SetEmbedderData(0, data_2);
|
|
|
|
CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1));
|
|
|
|
CHECK(context_2->GetEmbedderData(0)->StrictEquals(data_2));
|
2009-05-05 09:38:45 +00:00
|
|
|
|
|
|
|
// Simple test function which causes a break.
|
2009-05-05 10:15:05 +00:00
|
|
|
const char* source = "function f() { debugger; }";
|
2009-05-05 09:38:45 +00:00
|
|
|
|
|
|
|
// Enter and run function in the first context.
|
|
|
|
{
|
|
|
|
v8::Context::Scope context_scope(context_1);
|
2013-05-08 07:45:16 +00:00
|
|
|
expected_context = context_1;
|
2009-05-05 09:38:45 +00:00
|
|
|
expected_context_data = data_1;
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Local<v8::Function> f = CompileFunction(isolate, source, "f");
|
2017-10-13 16:33:03 +00:00
|
|
|
f->Call(context_1, context_1->Global(), 0, nullptr).ToLocalChecked();
|
2009-05-05 09:38:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Enter and run function in the second context.
|
|
|
|
{
|
|
|
|
v8::Context::Scope context_scope(context_2);
|
2013-05-08 07:45:16 +00:00
|
|
|
expected_context = context_2;
|
2018-06-03 05:09:41 +00:00
|
|
|
expected_context_data = data_2;
|
|
|
|
v8::Local<v8::Function> f = CompileFunction(isolate, source, "f");
|
|
|
|
f->Call(context_2, context_2->Global(), 0, nullptr).ToLocalChecked();
|
|
|
|
}
|
2009-05-29 08:42:02 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
// Two times compile event and two times break event.
|
|
|
|
CHECK_GT(event_listener_hit_count, 3);
|
2009-05-29 08:42:02 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(isolate, nullptr);
|
|
|
|
CheckDebuggerUnloaded();
|
2009-05-29 08:42:02 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 10:43:00 +00:00
|
|
|
// 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) {
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2009-05-29 08:42:02 +00:00
|
|
|
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Context> context_1;
|
|
|
|
v8::Local<v8::ObjectTemplate> global_template =
|
|
|
|
v8::Local<v8::ObjectTemplate>();
|
2017-10-13 16:33:03 +00:00
|
|
|
context_1 = v8::Context::New(CcTest::isolate(), nullptr, global_template);
|
2009-05-20 07:28:42 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
ContextCheckEventListener delegate;
|
|
|
|
v8::debug::SetDebugDelegate(CcTest::isolate(), &delegate);
|
2013-07-05 13:33:20 +00:00
|
|
|
|
2018-03-08 11:40:04 +00:00
|
|
|
// Contexts initially do not have embedder data fields.
|
|
|
|
CHECK_EQ(0, context_1->GetNumberOfEmbedderDataFields());
|
2009-05-20 07:28:42 +00:00
|
|
|
|
|
|
|
// Set and check a data value.
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::String> data_1 = v8_str(CcTest::isolate(), "1");
|
2013-01-14 13:41:08 +00:00
|
|
|
context_1->SetEmbedderData(0, data_1);
|
|
|
|
CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1));
|
2009-05-20 07:28:42 +00:00
|
|
|
|
|
|
|
// Simple test function with eval that causes a break.
|
|
|
|
const char* source = "function f() { eval('debugger;'); }";
|
|
|
|
|
|
|
|
// Enter and run function in the context.
|
|
|
|
{
|
|
|
|
v8::Context::Scope context_scope(context_1);
|
2013-06-13 09:27:09 +00:00
|
|
|
expected_context = context_1;
|
2009-05-20 07:28:42 +00:00
|
|
|
expected_context_data = data_1;
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Local<v8::Function> f = CompileFunction(CcTest::isolate(), source, "f");
|
2017-10-13 16:33:03 +00:00
|
|
|
f->Call(context_1, context_1->Global(), 0, nullptr).ToLocalChecked();
|
2009-05-20 07:28:42 +00:00
|
|
|
}
|
2013-07-05 13:33:20 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(CcTest::isolate(), nullptr);
|
2009-05-20 07:28:42 +00:00
|
|
|
|
|
|
|
// One time compile event and one time break event.
|
2016-11-24 10:43:00 +00:00
|
|
|
CHECK_GT(event_listener_hit_count, 2);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2009-05-20 07:28:42 +00:00
|
|
|
}
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
// Debug event listener which counts script compiled events.
|
|
|
|
class ScriptCompiledDelegate : public v8::debug::DebugDelegate {
|
|
|
|
public:
|
|
|
|
void ScriptCompiled(v8::Local<v8::debug::Script>, bool,
|
|
|
|
bool has_compile_error) override {
|
|
|
|
if (!has_compile_error) {
|
|
|
|
after_compile_event_count++;
|
|
|
|
} else {
|
|
|
|
compile_error_event_count++;
|
|
|
|
}
|
2009-05-25 07:51:04 +00:00
|
|
|
}
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
int after_compile_event_count = 0;
|
|
|
|
int compile_error_event_count = 0;
|
|
|
|
};
|
2009-05-25 07:51:04 +00:00
|
|
|
|
|
|
|
// Tests that after compile event is sent as many times as there are scripts
|
|
|
|
// compiled.
|
2016-11-24 10:43:00 +00:00
|
|
|
TEST(AfterCompileEventWhenEventListenerIsReset) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2009-05-25 07:51:04 +00:00
|
|
|
const char* script = "var a=1";
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
ScriptCompiledDelegate delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Script::Compile(context, v8_str(env->GetIsolate(), script))
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Run(context)
|
|
|
|
.ToLocalChecked();
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2009-05-25 07:51:04 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
[inspector] use interrupt for pause only as last resort
With this CL we use interrupt for pause in two cases:
- when we process Debugger.pause on interruption,
- when we would like to break as soon as possible after OOM.
In all other cases, e.g. for async step into we use break
on function call by calling StepIn debugger action.
In mentioned cases we should not actually use interrupt as well:
- Debugger.pause in this case scheduled using interrupt and we
may just break right now without requesting another interrupt,
unfortunately blink side is not ready,
- we should use more reliable way to break right after near OOM
callback, otherwise we can get this callback, increase limit,
request break on next interrupt, before interrupt get another
huge memory allocation and crash.
There are couple advantages:
- we get much better break locations for async stepping
(see inspector tests expectations),
- we can remove DEBUG_BREAK interruption
(it should speedup blackboxing with async tasks, see
removed todo in debug.cc for details)
- it is required preparation step for async step out,
(see https://chromium-review.googlesource.com/c/v8/v8/+/1054618)
Bug: v8:7753
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Iabd7627dbffa9a0eab1736064caf589d02591926
Reviewed-on: https://chromium-review.googlesource.com/1054155
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53439}
2018-05-29 14:54:08 +00:00
|
|
|
v8::debug::SetBreakOnNextFunctionCall(env->GetIsolate());
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Script::Compile(context, v8_str(env->GetIsolate(), script))
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Run(context)
|
|
|
|
.ToLocalChecked();
|
2009-05-25 07:51:04 +00:00
|
|
|
|
2017-10-13 16:33:03 +00:00
|
|
|
// Setting listener to nullptr should cause debugger unload.
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2009-05-25 07:51:04 +00:00
|
|
|
|
|
|
|
// Compilation cache should be disabled when debugger is active.
|
2018-06-03 05:09:41 +00:00
|
|
|
CHECK_EQ(2, delegate.after_compile_event_count);
|
2009-05-25 07:51:04 +00:00
|
|
|
}
|
|
|
|
|
2014-06-26 16:03:52 +00:00
|
|
|
// Tests that syntax error event is sent as many times as there are scripts
|
|
|
|
// with syntax error compiled.
|
2016-11-24 10:43:00 +00:00
|
|
|
TEST(SyntaxErrorEventOnSyntaxException) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2014-06-26 16:03:52 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
|
|
|
// For this test, we want to break on uncaught exceptions:
|
2021-04-30 16:19:52 +00:00
|
|
|
ChangeBreakOnException(env->GetIsolate(), false, true);
|
2014-06-26 16:03:52 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
ScriptCompiledDelegate delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
|
|
|
v8::Local<v8::Context> context = env.local();
|
2014-06-26 16:03:52 +00:00
|
|
|
|
|
|
|
// Check initial state.
|
2018-06-03 05:09:41 +00:00
|
|
|
CHECK_EQ(0, delegate.compile_error_event_count);
|
2014-06-26 16:03:52 +00:00
|
|
|
|
|
|
|
// Throws SyntaxError: Unexpected end of input
|
2015-11-19 13:45:42 +00:00
|
|
|
CHECK(
|
|
|
|
v8::Script::Compile(context, v8_str(env->GetIsolate(), "+++")).IsEmpty());
|
2018-06-03 05:09:41 +00:00
|
|
|
CHECK_EQ(1, delegate.compile_error_event_count);
|
2014-06-26 16:03:52 +00:00
|
|
|
|
2015-11-19 13:45:42 +00:00
|
|
|
CHECK(v8::Script::Compile(context, v8_str(env->GetIsolate(), "/sel\\/: \\"))
|
|
|
|
.IsEmpty());
|
2018-06-03 05:09:41 +00:00
|
|
|
CHECK_EQ(2, delegate.compile_error_event_count);
|
2014-06-26 16:03:52 +00:00
|
|
|
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Script> script =
|
|
|
|
v8::Script::Compile(context,
|
|
|
|
v8_str(env->GetIsolate(), "JSON.parse('1234:')"))
|
|
|
|
.ToLocalChecked();
|
2018-06-03 05:09:41 +00:00
|
|
|
CHECK_EQ(2, delegate.compile_error_event_count);
|
2015-11-19 13:45:42 +00:00
|
|
|
CHECK(script->Run(context).IsEmpty());
|
2018-06-03 05:09:41 +00:00
|
|
|
CHECK_EQ(3, delegate.compile_error_event_count);
|
2014-06-26 16:03:52 +00:00
|
|
|
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Script::Compile(context,
|
|
|
|
v8_str(env->GetIsolate(), "new RegExp('/\\/\\\\');"))
|
|
|
|
.ToLocalChecked();
|
2018-06-03 05:09:41 +00:00
|
|
|
CHECK_EQ(3, delegate.compile_error_event_count);
|
2014-06-26 16:03:52 +00:00
|
|
|
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Script::Compile(context, v8_str(env->GetIsolate(), "throw 1;"))
|
|
|
|
.ToLocalChecked();
|
2018-06-03 05:09:41 +00:00
|
|
|
CHECK_EQ(3, delegate.compile_error_event_count);
|
2014-06-26 16:03:52 +00:00
|
|
|
}
|
|
|
|
|
2019-08-26 13:31:22 +00:00
|
|
|
class ExceptionEventCounter : public v8::debug::DebugDelegate {
|
|
|
|
public:
|
|
|
|
void ExceptionThrown(v8::Local<v8::Context> paused_context,
|
|
|
|
v8::Local<v8::Value> exception,
|
|
|
|
v8::Local<v8::Value> promise, bool is_uncaught,
|
|
|
|
v8::debug::ExceptionType) override {
|
|
|
|
exception_event_count++;
|
|
|
|
}
|
|
|
|
int exception_event_count = 0;
|
|
|
|
};
|
|
|
|
|
2021-04-30 16:19:52 +00:00
|
|
|
UNINITIALIZED_TEST(NoBreakOnStackOverflow) {
|
2022-09-15 11:04:11 +00:00
|
|
|
// We must set v8_flags.stack_size before initializing the isolate.
|
|
|
|
i::v8_flags.stack_size = 100;
|
2021-04-30 16:19:52 +00:00
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
|
|
|
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
|
|
|
isolate->Enter();
|
|
|
|
{
|
|
|
|
LocalContext env(isolate);
|
|
|
|
v8::HandleScope scope(isolate);
|
2019-08-26 13:31:22 +00:00
|
|
|
|
2021-04-30 16:19:52 +00:00
|
|
|
ChangeBreakOnException(isolate, true, true);
|
2019-08-26 13:31:22 +00:00
|
|
|
|
2021-04-30 16:19:52 +00:00
|
|
|
ExceptionEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(isolate, &delegate);
|
|
|
|
CHECK_EQ(0, delegate.exception_event_count);
|
2019-08-26 13:31:22 +00:00
|
|
|
|
2021-04-30 16:19:52 +00:00
|
|
|
CompileRun(
|
|
|
|
"function f() { return f(); }"
|
|
|
|
"try { f() } catch {}");
|
2019-08-26 13:31:22 +00:00
|
|
|
|
2021-04-30 16:19:52 +00:00
|
|
|
CHECK_EQ(0, delegate.exception_event_count);
|
|
|
|
}
|
|
|
|
isolate->Exit();
|
|
|
|
isolate->Dispose();
|
2019-08-26 13:31:22 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 10:43:00 +00:00
|
|
|
// Tests that break event is sent when event listener is reset.
|
|
|
|
TEST(BreakEventWhenEventListenerIsReset) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2009-05-25 07:51:04 +00:00
|
|
|
const char* script = "function f() {};";
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
ScriptCompiledDelegate delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Script::Compile(context, v8_str(env->GetIsolate(), script))
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Run(context)
|
|
|
|
.ToLocalChecked();
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2009-05-25 07:51:04 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
[inspector] use interrupt for pause only as last resort
With this CL we use interrupt for pause in two cases:
- when we process Debugger.pause on interruption,
- when we would like to break as soon as possible after OOM.
In all other cases, e.g. for async step into we use break
on function call by calling StepIn debugger action.
In mentioned cases we should not actually use interrupt as well:
- Debugger.pause in this case scheduled using interrupt and we
may just break right now without requesting another interrupt,
unfortunately blink side is not ready,
- we should use more reliable way to break right after near OOM
callback, otherwise we can get this callback, increase limit,
request break on next interrupt, before interrupt get another
huge memory allocation and crash.
There are couple advantages:
- we get much better break locations for async stepping
(see inspector tests expectations),
- we can remove DEBUG_BREAK interruption
(it should speedup blackboxing with async tasks, see
removed todo in debug.cc for details)
- it is required preparation step for async step out,
(see https://chromium-review.googlesource.com/c/v8/v8/+/1054618)
Bug: v8:7753
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Iabd7627dbffa9a0eab1736064caf589d02591926
Reviewed-on: https://chromium-review.googlesource.com/1054155
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53439}
2018-05-29 14:54:08 +00:00
|
|
|
v8::debug::SetBreakOnNextFunctionCall(env->GetIsolate());
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
|
2015-11-19 13:45:42 +00:00
|
|
|
env->Global()
|
|
|
|
->Get(context, v8_str(env->GetIsolate(), "f"))
|
|
|
|
.ToLocalChecked());
|
2017-10-13 16:33:03 +00:00
|
|
|
f->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2009-05-25 07:51:04 +00:00
|
|
|
|
2017-10-13 16:33:03 +00:00
|
|
|
// Setting event listener to nullptr should cause debugger unload.
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2009-05-25 07:51:04 +00:00
|
|
|
|
|
|
|
// Compilation cache should be disabled when debugger is active.
|
2018-06-03 05:09:41 +00:00
|
|
|
CHECK_EQ(1, delegate.after_compile_event_count);
|
2009-05-25 07:51:04 +00:00
|
|
|
}
|
2009-06-22 11:56:36 +00:00
|
|
|
|
2018-04-17 17:46:34 +00:00
|
|
|
// Tests that script is reported as compiled when bound to context.
|
|
|
|
TEST(AfterCompileEventOnBindToContext) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2018-04-17 17:46:34 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
ScriptCompiledDelegate delegate;
|
|
|
|
v8::debug::SetDebugDelegate(isolate, &delegate);
|
2018-04-17 17:46:34 +00:00
|
|
|
|
|
|
|
v8::ScriptCompiler::Source script_source(
|
2020-03-09 10:41:45 +00:00
|
|
|
v8::String::NewFromUtf8Literal(isolate, "var a=1"));
|
2018-04-17 17:46:34 +00:00
|
|
|
|
|
|
|
v8::Local<v8::UnboundScript> unbound =
|
|
|
|
v8::ScriptCompiler::CompileUnboundScript(isolate, &script_source)
|
|
|
|
.ToLocalChecked();
|
2018-06-03 05:09:41 +00:00
|
|
|
CHECK_EQ(delegate.after_compile_event_count, 0);
|
2018-04-17 17:46:34 +00:00
|
|
|
|
|
|
|
unbound->BindToCurrentContext();
|
2018-06-03 05:09:41 +00:00
|
|
|
CHECK_EQ(delegate.after_compile_event_count, 1);
|
|
|
|
v8::debug::SetDebugDelegate(isolate, nullptr);
|
2009-07-24 06:14:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test that if DebugBreak is forced it is ignored when code from
|
2009-07-24 07:39:53 +00:00
|
|
|
// debug-delay.js is executed.
|
2016-11-24 10:43:00 +00:00
|
|
|
TEST(NoDebugBreakInAfterCompileEventListener) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2009-07-24 06:14:23 +00:00
|
|
|
|
|
|
|
// Register a debug event listener which sets the break flag and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2009-07-24 06:14:23 +00:00
|
|
|
|
|
|
|
// Set the debug break flag.
|
[inspector] use interrupt for pause only as last resort
With this CL we use interrupt for pause in two cases:
- when we process Debugger.pause on interruption,
- when we would like to break as soon as possible after OOM.
In all other cases, e.g. for async step into we use break
on function call by calling StepIn debugger action.
In mentioned cases we should not actually use interrupt as well:
- Debugger.pause in this case scheduled using interrupt and we
may just break right now without requesting another interrupt,
unfortunately blink side is not ready,
- we should use more reliable way to break right after near OOM
callback, otherwise we can get this callback, increase limit,
request break on next interrupt, before interrupt get another
huge memory allocation and crash.
There are couple advantages:
- we get much better break locations for async stepping
(see inspector tests expectations),
- we can remove DEBUG_BREAK interruption
(it should speedup blackboxing with async tasks, see
removed todo in debug.cc for details)
- it is required preparation step for async step out,
(see https://chromium-review.googlesource.com/c/v8/v8/+/1054618)
Bug: v8:7753
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Iabd7627dbffa9a0eab1736064caf589d02591926
Reviewed-on: https://chromium-review.googlesource.com/1054155
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53439}
2018-05-29 14:54:08 +00:00
|
|
|
v8::debug::SetBreakOnNextFunctionCall(env->GetIsolate());
|
2009-07-24 06:14:23 +00:00
|
|
|
|
|
|
|
// Create a function for testing stepping.
|
|
|
|
const char* src = "function f() { eval('var x = 10;'); } ";
|
|
|
|
v8::Local<v8::Function> f = CompileFunction(&env, src, "f");
|
|
|
|
|
|
|
|
// There should be only one break event.
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
// Set the debug break flag again.
|
[inspector] use interrupt for pause only as last resort
With this CL we use interrupt for pause in two cases:
- when we process Debugger.pause on interruption,
- when we would like to break as soon as possible after OOM.
In all other cases, e.g. for async step into we use break
on function call by calling StepIn debugger action.
In mentioned cases we should not actually use interrupt as well:
- Debugger.pause in this case scheduled using interrupt and we
may just break right now without requesting another interrupt,
unfortunately blink side is not ready,
- we should use more reliable way to break right after near OOM
callback, otherwise we can get this callback, increase limit,
request break on next interrupt, before interrupt get another
huge memory allocation and crash.
There are couple advantages:
- we get much better break locations for async stepping
(see inspector tests expectations),
- we can remove DEBUG_BREAK interruption
(it should speedup blackboxing with async tasks, see
removed todo in debug.cc for details)
- it is required preparation step for async step out,
(see https://chromium-review.googlesource.com/c/v8/v8/+/1054618)
Bug: v8:7753
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Iabd7627dbffa9a0eab1736064caf589d02591926
Reviewed-on: https://chromium-review.googlesource.com/1054155
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53439}
2018-05-29 14:54:08 +00:00
|
|
|
v8::debug::SetBreakOnNextFunctionCall(env->GetIsolate());
|
2017-10-13 16:33:03 +00:00
|
|
|
f->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2009-07-24 06:14:23 +00:00
|
|
|
// There should be one more break event when the script is evaluated in 'f'.
|
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
2016-11-24 10:43:00 +00:00
|
|
|
// Get rid of the debug event listener.
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2009-07-24 06:14:23 +00:00
|
|
|
}
|
2009-08-17 14:26:48 +00:00
|
|
|
|
|
|
|
|
2009-11-05 13:59:40 +00:00
|
|
|
// Test that the debug break flag works with function.apply.
|
2020-04-29 09:52:25 +00:00
|
|
|
TEST(RepeatDebugBreak) {
|
|
|
|
// Test that we can repeatedly set a break without JS execution continuing.
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2009-11-05 13:59:40 +00:00
|
|
|
|
|
|
|
// Create a function for testing breaking in apply.
|
2020-04-29 09:52:25 +00:00
|
|
|
v8::Local<v8::Function> foo =
|
|
|
|
CompileFunction(&env, "function foo() {}", "foo");
|
2009-11-05 13:59:40 +00:00
|
|
|
|
2020-04-29 09:52:25 +00:00
|
|
|
// Register a debug delegate which repeatedly sets a break and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventBreakMax delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2009-11-05 13:59:40 +00:00
|
|
|
|
|
|
|
// Set the debug break flag before calling the code using function.apply.
|
[inspector] use interrupt for pause only as last resort
With this CL we use interrupt for pause in two cases:
- when we process Debugger.pause on interruption,
- when we would like to break as soon as possible after OOM.
In all other cases, e.g. for async step into we use break
on function call by calling StepIn debugger action.
In mentioned cases we should not actually use interrupt as well:
- Debugger.pause in this case scheduled using interrupt and we
may just break right now without requesting another interrupt,
unfortunately blink side is not ready,
- we should use more reliable way to break right after near OOM
callback, otherwise we can get this callback, increase limit,
request break on next interrupt, before interrupt get another
huge memory allocation and crash.
There are couple advantages:
- we get much better break locations for async stepping
(see inspector tests expectations),
- we can remove DEBUG_BREAK interruption
(it should speedup blackboxing with async tasks, see
removed todo in debug.cc for details)
- it is required preparation step for async step out,
(see https://chromium-review.googlesource.com/c/v8/v8/+/1054618)
Bug: v8:7753
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Iabd7627dbffa9a0eab1736064caf589d02591926
Reviewed-on: https://chromium-review.googlesource.com/1054155
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53439}
2018-05-29 14:54:08 +00:00
|
|
|
v8::debug::SetBreakOnNextFunctionCall(env->GetIsolate());
|
2009-11-05 13:59:40 +00:00
|
|
|
|
2020-04-29 09:52:25 +00:00
|
|
|
// Trigger a break by calling into foo().
|
2009-11-05 13:59:40 +00:00
|
|
|
break_point_hit_count = 0;
|
2020-04-29 09:52:25 +00:00
|
|
|
max_break_point_hit_count = 10000;
|
2017-10-13 16:33:03 +00:00
|
|
|
foo->Call(context, env->Global(), 0, nullptr).ToLocalChecked();
|
2009-11-05 13:59:40 +00:00
|
|
|
|
|
|
|
// When keeping the debug break several break will happen.
|
2020-04-29 09:52:25 +00:00
|
|
|
CHECK_EQ(break_point_hit_count, max_break_point_hit_count);
|
2009-11-05 13:59:40 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2010-04-28 11:59:43 +00:00
|
|
|
}
|
2010-05-20 17:15:46 +00:00
|
|
|
|
2010-11-04 15:43:12 +00:00
|
|
|
// Test that setting the terminate execution flag during debug break processing.
|
2010-11-19 12:08:52 +00:00
|
|
|
static void TestDebugBreakInLoop(const char* loop_head,
|
|
|
|
const char** loop_bodies,
|
|
|
|
const char* loop_tail) {
|
2015-07-30 09:11:24 +00:00
|
|
|
// Receive 10 breaks for each test and then terminate JavaScript execution.
|
|
|
|
static const int kBreaksPerTest = 10;
|
2011-07-05 13:21:29 +00:00
|
|
|
|
2017-10-13 16:33:03 +00:00
|
|
|
for (int i = 0; loop_bodies[i] != nullptr; i++) {
|
2011-07-05 13:21:29 +00:00
|
|
|
// Perform a lazy deoptimization after various numbers of breaks
|
|
|
|
// have been hit.
|
2015-07-30 09:11:24 +00:00
|
|
|
|
2021-06-17 15:43:55 +00:00
|
|
|
v8::base::EmbeddedVector<char, 1024> buffer;
|
2021-06-22 13:27:00 +00:00
|
|
|
v8::base::SNPrintF(buffer, "function f() {%s%s%s}", loop_head,
|
|
|
|
loop_bodies[i], loop_tail);
|
2015-07-30 09:11:24 +00:00
|
|
|
|
2019-04-29 11:06:49 +00:00
|
|
|
i::PrintF("%s\n", buffer.begin());
|
2015-07-30 09:11:24 +00:00
|
|
|
|
|
|
|
for (int j = 0; j < 3; j++) {
|
2011-07-05 13:21:29 +00:00
|
|
|
break_point_hit_count_deoptimize = j;
|
2015-07-30 09:11:24 +00:00
|
|
|
if (j == 2) {
|
2011-07-05 13:21:29 +00:00
|
|
|
break_point_hit_count_deoptimize = kBreaksPerTest;
|
|
|
|
}
|
2010-11-19 12:08:52 +00:00
|
|
|
|
2011-07-05 13:21:29 +00:00
|
|
|
break_point_hit_count = 0;
|
|
|
|
max_break_point_hit_count = kBreaksPerTest;
|
|
|
|
terminate_after_max_break_point_hit = true;
|
2010-11-19 12:08:52 +00:00
|
|
|
|
2011-07-05 13:21:29 +00:00
|
|
|
// Function with infinite loop.
|
2019-04-29 11:06:49 +00:00
|
|
|
CompileRun(buffer.begin());
|
2010-11-19 12:08:52 +00:00
|
|
|
|
2011-07-05 13:21:29 +00:00
|
|
|
// Set the debug break to enter the debugger as soon as possible.
|
[inspector] use interrupt for pause only as last resort
With this CL we use interrupt for pause in two cases:
- when we process Debugger.pause on interruption,
- when we would like to break as soon as possible after OOM.
In all other cases, e.g. for async step into we use break
on function call by calling StepIn debugger action.
In mentioned cases we should not actually use interrupt as well:
- Debugger.pause in this case scheduled using interrupt and we
may just break right now without requesting another interrupt,
unfortunately blink side is not ready,
- we should use more reliable way to break right after near OOM
callback, otherwise we can get this callback, increase limit,
request break on next interrupt, before interrupt get another
huge memory allocation and crash.
There are couple advantages:
- we get much better break locations for async stepping
(see inspector tests expectations),
- we can remove DEBUG_BREAK interruption
(it should speedup blackboxing with async tasks, see
removed todo in debug.cc for details)
- it is required preparation step for async step out,
(see https://chromium-review.googlesource.com/c/v8/v8/+/1054618)
Bug: v8:7753
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Iabd7627dbffa9a0eab1736064caf589d02591926
Reviewed-on: https://chromium-review.googlesource.com/1054155
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53439}
2018-05-29 14:54:08 +00:00
|
|
|
v8::debug::SetBreakOnNextFunctionCall(CcTest::isolate());
|
2010-11-19 12:08:52 +00:00
|
|
|
|
2011-07-05 13:21:29 +00:00
|
|
|
// Call function with infinite loop.
|
|
|
|
CompileRun("f();");
|
|
|
|
CHECK_EQ(kBreaksPerTest, break_point_hit_count);
|
2010-11-19 12:08:52 +00:00
|
|
|
|
2015-11-19 13:45:42 +00:00
|
|
|
CHECK(!CcTest::isolate()->IsExecutionTerminating());
|
2011-07-05 13:21:29 +00:00
|
|
|
}
|
2010-11-19 12:08:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-30 09:11:24 +00:00
|
|
|
static const char* loop_bodies_1[] = {"",
|
|
|
|
"g()",
|
|
|
|
"if (a == 0) { g() }",
|
|
|
|
"if (a == 1) { g() }",
|
|
|
|
"if (a == 0) { g() } else { h() }",
|
|
|
|
"if (a == 0) { continue }",
|
2017-10-13 16:33:03 +00:00
|
|
|
nullptr};
|
2015-07-30 09:11:24 +00:00
|
|
|
|
|
|
|
static const char* loop_bodies_2[] = {
|
|
|
|
"if (a == 1) { continue }",
|
|
|
|
"switch (a) { case 1: g(); }",
|
|
|
|
"switch (a) { case 1: continue; }",
|
|
|
|
"switch (a) { case 1: g(); break; default: h() }",
|
|
|
|
"switch (a) { case 1: continue; break; default: h() }",
|
2017-10-13 16:33:03 +00:00
|
|
|
nullptr};
|
2015-07-30 09:11:24 +00:00
|
|
|
|
|
|
|
void DebugBreakLoop(const char* loop_header, const char** loop_bodies,
|
|
|
|
const char* loop_footer) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2010-11-04 15:43:12 +00:00
|
|
|
|
2020-04-29 09:52:25 +00:00
|
|
|
// Register a debug delegate which repeatedly sets the break flag and counts.
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventBreakMax delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2010-11-04 15:43:12 +00:00
|
|
|
|
2015-07-30 09:11:24 +00:00
|
|
|
CompileRun(
|
|
|
|
"var a = 1;\n"
|
|
|
|
"function g() { }\n"
|
|
|
|
"function h() { }");
|
2010-11-04 15:43:12 +00:00
|
|
|
|
2015-07-30 09:11:24 +00:00
|
|
|
TestDebugBreakInLoop(loop_header, loop_bodies, loop_footer);
|
2010-11-04 15:43:12 +00:00
|
|
|
|
2023-01-04 10:35:31 +00:00
|
|
|
// Also test with "Scheduled" break reason.
|
|
|
|
break_right_now_reasons =
|
|
|
|
v8::debug::BreakReasons{v8::debug::BreakReason::kScheduled};
|
|
|
|
TestDebugBreakInLoop(loop_header, loop_bodies, loop_footer);
|
|
|
|
break_right_now_reasons = v8::debug::BreakReasons{};
|
|
|
|
|
2010-11-04 15:43:12 +00:00
|
|
|
// Get rid of the debug event listener.
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2017-08-16 05:41:03 +00:00
|
|
|
CheckDebuggerUnloaded();
|
2010-11-04 15:43:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-30 09:11:24 +00:00
|
|
|
TEST(DebugBreakInWhileTrue1) {
|
|
|
|
DebugBreakLoop("while (true) {", loop_bodies_1, "}");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DebugBreakInWhileTrue2) {
|
|
|
|
DebugBreakLoop("while (true) {", loop_bodies_2, "}");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DebugBreakInWhileCondition1) {
|
|
|
|
DebugBreakLoop("while (a == 1) {", loop_bodies_1, "}");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DebugBreakInWhileCondition2) {
|
|
|
|
DebugBreakLoop("while (a == 1) {", loop_bodies_2, "}");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DebugBreakInDoWhileTrue1) {
|
|
|
|
DebugBreakLoop("do {", loop_bodies_1, "} while (true)");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DebugBreakInDoWhileTrue2) {
|
|
|
|
DebugBreakLoop("do {", loop_bodies_2, "} while (true)");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DebugBreakInDoWhileCondition1) {
|
|
|
|
DebugBreakLoop("do {", loop_bodies_1, "} while (a == 1)");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DebugBreakInDoWhileCondition2) {
|
|
|
|
DebugBreakLoop("do {", loop_bodies_2, "} while (a == 1)");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DebugBreakInFor1) { DebugBreakLoop("for (;;) {", loop_bodies_1, "}"); }
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DebugBreakInFor2) { DebugBreakLoop("for (;;) {", loop_bodies_2, "}"); }
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DebugBreakInForCondition1) {
|
|
|
|
DebugBreakLoop("for (;a == 1;) {", loop_bodies_1, "}");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DebugBreakInForCondition2) {
|
|
|
|
DebugBreakLoop("for (;a == 1;) {", loop_bodies_2, "}");
|
|
|
|
}
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
class DebugBreakInlineListener : public v8::debug::DebugDelegate {
|
|
|
|
public:
|
2021-11-23 09:14:18 +00:00
|
|
|
void BreakProgramRequested(
|
|
|
|
v8::Local<v8::Context> paused_context,
|
|
|
|
const std::vector<v8::debug::BreakpointId>& inspector_break_points_hit,
|
2021-12-02 09:26:01 +00:00
|
|
|
v8::debug::BreakReasons break_reasons) override {
|
2018-06-03 05:09:41 +00:00
|
|
|
int expected_frame_count = 4;
|
2019-04-30 11:04:41 +00:00
|
|
|
int expected_line_number[] = {1, 4, 7, 13};
|
2018-06-03 05:09:41 +00:00
|
|
|
|
|
|
|
int frame_count = 0;
|
|
|
|
auto iterator = v8::debug::StackTraceIterator::Create(CcTest::isolate());
|
|
|
|
for (; !iterator->Done(); iterator->Advance(), ++frame_count) {
|
|
|
|
v8::debug::Location loc = iterator->GetSourceLocation();
|
|
|
|
CHECK_EQ(expected_line_number[frame_count], loc.GetLineNumber());
|
|
|
|
}
|
|
|
|
CHECK_EQ(frame_count, expected_frame_count);
|
2012-01-30 13:07:01 +00:00
|
|
|
}
|
2018-06-03 05:09:41 +00:00
|
|
|
};
|
2012-01-30 13:07:01 +00:00
|
|
|
|
|
|
|
TEST(DebugBreakInline) {
|
2022-09-15 11:04:11 +00:00
|
|
|
i::v8_flags.allow_natives_syntax = true;
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::Local<v8::Context> context = env.local();
|
2012-01-30 13:07:01 +00:00
|
|
|
const char* source =
|
2019-04-30 11:04:41 +00:00
|
|
|
"function debug(b) { \n"
|
|
|
|
" if (b) debugger; \n"
|
|
|
|
"} \n"
|
|
|
|
"function f(b) { \n"
|
|
|
|
" debug(b) \n"
|
|
|
|
"}; \n"
|
|
|
|
"function g(b) { \n"
|
|
|
|
" f(b); \n"
|
|
|
|
"}; \n"
|
|
|
|
"%PrepareFunctionForOptimization(g); \n"
|
|
|
|
"g(false); \n"
|
|
|
|
"g(false); \n"
|
|
|
|
"%OptimizeFunctionOnNextCall(g); \n"
|
2012-01-30 13:07:01 +00:00
|
|
|
"g(true);";
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugBreakInlineListener delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
|
|
|
v8::Local<v8::Script> inline_script =
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Script::Compile(context, v8_str(env->GetIsolate(), source))
|
|
|
|
.ToLocalChecked();
|
|
|
|
inline_script->Run(context).ToLocalChecked();
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2012-01-30 13:07:01 +00:00
|
|
|
}
|
|
|
|
|
2012-07-09 15:18:08 +00:00
|
|
|
static void RunScriptInANewCFrame(const char* source) {
|
2015-05-28 12:49:31 +00:00
|
|
|
v8::TryCatch try_catch(CcTest::isolate());
|
2012-07-09 15:18:08 +00:00
|
|
|
CompileRun(source);
|
|
|
|
CHECK(try_catch.HasCaught());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(Regress131642) {
|
|
|
|
// Bug description:
|
2021-06-01 08:32:39 +00:00
|
|
|
// When doing StepOver through the first script, the debugger is not reset
|
2012-07-09 15:18:08 +00:00
|
|
|
// after exiting through exception. A flawed implementation enabling the
|
|
|
|
// debugger to step into Array.prototype.forEach breaks inside the callback
|
|
|
|
// for forEach in the second script under the assumption that we are in a
|
|
|
|
// recursive call. In an attempt to step out, we crawl the stack using the
|
|
|
|
// recorded frame pointer from the first script and fail when not finding it
|
|
|
|
// on the stack.
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventCounter delegate;
|
2021-06-01 08:32:39 +00:00
|
|
|
delegate.set_step_action(StepOver);
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2012-07-09 15:18:08 +00:00
|
|
|
|
|
|
|
// We step through the first script. It exits through an exception. We run
|
|
|
|
// this inside a new frame to record a different FP than the second script
|
|
|
|
// would expect.
|
|
|
|
const char* script_1 = "debugger; throw new Error();";
|
|
|
|
RunScriptInANewCFrame(script_1);
|
|
|
|
|
|
|
|
// The second script uses forEach.
|
|
|
|
const char* script_2 = "[0].forEach(function() { });";
|
|
|
|
CompileRun(script_2);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2012-07-09 15:18:08 +00:00
|
|
|
}
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
class DebugBreakStackTraceListener : public v8::debug::DebugDelegate {
|
|
|
|
public:
|
2021-11-23 09:14:18 +00:00
|
|
|
void BreakProgramRequested(
|
|
|
|
v8::Local<v8::Context> paused_context,
|
|
|
|
const std::vector<v8::debug::BreakpointId>& inspector_break_points_hit,
|
2021-12-02 09:26:01 +00:00
|
|
|
v8::debug::BreakReasons break_reasons) override {
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::StackTrace::CurrentStackTrace(CcTest::isolate(), 10);
|
|
|
|
}
|
|
|
|
};
|
2014-04-28 12:08:17 +00:00
|
|
|
|
|
|
|
static void AddDebugBreak(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
[inspector] use interrupt for pause only as last resort
With this CL we use interrupt for pause in two cases:
- when we process Debugger.pause on interruption,
- when we would like to break as soon as possible after OOM.
In all other cases, e.g. for async step into we use break
on function call by calling StepIn debugger action.
In mentioned cases we should not actually use interrupt as well:
- Debugger.pause in this case scheduled using interrupt and we
may just break right now without requesting another interrupt,
unfortunately blink side is not ready,
- we should use more reliable way to break right after near OOM
callback, otherwise we can get this callback, increase limit,
request break on next interrupt, before interrupt get another
huge memory allocation and crash.
There are couple advantages:
- we get much better break locations for async stepping
(see inspector tests expectations),
- we can remove DEBUG_BREAK interruption
(it should speedup blackboxing with async tasks, see
removed todo in debug.cc for details)
- it is required preparation step for async step out,
(see https://chromium-review.googlesource.com/c/v8/v8/+/1054618)
Bug: v8:7753
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Iabd7627dbffa9a0eab1736064caf589d02591926
Reviewed-on: https://chromium-review.googlesource.com/1054155
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53439}
2018-05-29 14:54:08 +00:00
|
|
|
v8::debug::SetBreakOnNextFunctionCall(args.GetIsolate());
|
2014-04-28 12:08:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DebugBreakStackTrace) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2014-04-28 12:08:17 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugBreakStackTraceListener delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
|
|
|
v8::Local<v8::Context> context = env.local();
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::FunctionTemplate> add_debug_break_template =
|
2014-04-28 12:08:17 +00:00
|
|
|
v8::FunctionTemplate::New(env->GetIsolate(), AddDebugBreak);
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::Function> add_debug_break =
|
|
|
|
add_debug_break_template->GetFunction(context).ToLocalChecked();
|
|
|
|
CHECK(env->Global()
|
|
|
|
->Set(context, v8_str("add_debug_break"), add_debug_break)
|
|
|
|
.FromJust());
|
2014-04-28 12:08:17 +00:00
|
|
|
|
|
|
|
CompileRun("(function loop() {"
|
|
|
|
" for (var j = 0; j < 1000; j++) {"
|
|
|
|
" for (var i = 0; i < 1000; i++) {"
|
|
|
|
" if (i == 999) add_debug_break();"
|
|
|
|
" }"
|
|
|
|
" }"
|
|
|
|
"})()");
|
|
|
|
}
|
2014-06-02 12:07:37 +00:00
|
|
|
|
|
|
|
|
2014-06-30 13:25:46 +00:00
|
|
|
v8::base::Semaphore terminate_requested_semaphore(0);
|
|
|
|
v8::base::Semaphore terminate_fired_semaphore(0);
|
2014-06-02 12:07:37 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
class DebugBreakTriggerTerminate : public v8::debug::DebugDelegate {
|
|
|
|
public:
|
2021-11-23 09:14:18 +00:00
|
|
|
void BreakProgramRequested(
|
|
|
|
v8::Local<v8::Context> paused_context,
|
|
|
|
const std::vector<v8::debug::BreakpointId>& inspector_break_points_hit,
|
2021-12-02 09:26:01 +00:00
|
|
|
v8::debug::BreakReasons break_reasons) override {
|
2018-06-03 05:09:41 +00:00
|
|
|
if (terminate_already_fired_) return;
|
|
|
|
terminate_requested_semaphore.Signal();
|
|
|
|
// Wait for at most 2 seconds for the terminate request.
|
|
|
|
CHECK(
|
|
|
|
terminate_fired_semaphore.WaitFor(v8::base::TimeDelta::FromSeconds(2)));
|
|
|
|
terminate_already_fired_ = true;
|
|
|
|
}
|
2014-06-02 12:07:37 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
private:
|
|
|
|
bool terminate_already_fired_ = false;
|
|
|
|
};
|
2014-06-02 12:07:37 +00:00
|
|
|
|
2014-06-30 13:25:46 +00:00
|
|
|
class TerminationThread : public v8::base::Thread {
|
2014-06-02 12:07:37 +00:00
|
|
|
public:
|
2014-08-12 13:33:35 +00:00
|
|
|
explicit TerminationThread(v8::Isolate* isolate)
|
|
|
|
: Thread(Options("terminator")), isolate_(isolate) {}
|
2014-06-02 12:07:37 +00:00
|
|
|
|
2018-09-14 15:34:02 +00:00
|
|
|
void Run() override {
|
2014-06-02 12:07:37 +00:00
|
|
|
terminate_requested_semaphore.Wait();
|
2015-11-19 13:45:42 +00:00
|
|
|
isolate_->TerminateExecution();
|
2014-06-02 12:07:37 +00:00
|
|
|
terminate_fired_semaphore.Signal();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
v8::Isolate* isolate_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DebugBreakOffThreadTerminate) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2014-06-02 12:07:37 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugBreakTriggerTerminate delegate;
|
|
|
|
v8::debug::SetDebugDelegate(isolate, &delegate);
|
2014-06-02 12:07:37 +00:00
|
|
|
TerminationThread terminator(isolate);
|
2019-07-29 13:09:02 +00:00
|
|
|
CHECK(terminator.Start());
|
2015-05-28 12:49:31 +00:00
|
|
|
v8::TryCatch try_catch(env->GetIsolate());
|
[inspector] use interrupt for pause only as last resort
With this CL we use interrupt for pause in two cases:
- when we process Debugger.pause on interruption,
- when we would like to break as soon as possible after OOM.
In all other cases, e.g. for async step into we use break
on function call by calling StepIn debugger action.
In mentioned cases we should not actually use interrupt as well:
- Debugger.pause in this case scheduled using interrupt and we
may just break right now without requesting another interrupt,
unfortunately blink side is not ready,
- we should use more reliable way to break right after near OOM
callback, otherwise we can get this callback, increase limit,
request break on next interrupt, before interrupt get another
huge memory allocation and crash.
There are couple advantages:
- we get much better break locations for async stepping
(see inspector tests expectations),
- we can remove DEBUG_BREAK interruption
(it should speedup blackboxing with async tasks, see
removed todo in debug.cc for details)
- it is required preparation step for async step out,
(see https://chromium-review.googlesource.com/c/v8/v8/+/1054618)
Bug: v8:7753
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Iabd7627dbffa9a0eab1736064caf589d02591926
Reviewed-on: https://chromium-review.googlesource.com/1054155
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53439}
2018-05-29 14:54:08 +00:00
|
|
|
env->GetIsolate()->RequestInterrupt(BreakRightNow, nullptr);
|
2014-06-02 12:07:37 +00:00
|
|
|
CompileRun("while (true);");
|
2014-07-08 06:57:17 +00:00
|
|
|
CHECK(try_catch.HasTerminated());
|
2014-06-02 12:07:37 +00:00
|
|
|
}
|
2014-09-30 15:29:08 +00:00
|
|
|
|
2018-08-02 20:08:35 +00:00
|
|
|
class ArchiveRestoreThread : public v8::base::Thread,
|
|
|
|
public v8::debug::DebugDelegate {
|
|
|
|
public:
|
|
|
|
ArchiveRestoreThread(v8::Isolate* isolate, int spawn_count)
|
|
|
|
: Thread(Options("ArchiveRestoreThread")),
|
|
|
|
isolate_(isolate),
|
|
|
|
debug_(reinterpret_cast<i::Isolate*>(isolate_)->debug()),
|
|
|
|
spawn_count_(spawn_count),
|
|
|
|
break_count_(0) {}
|
|
|
|
|
2018-09-14 15:34:02 +00:00
|
|
|
void Run() override {
|
[debug] Restore StepNext on correct frame for RestoreDebug
When an Isolate in a multi-threaded environment is being debugged
and a thread does a Step Over (StepNext internally) one-shot
breaks are created in the code at the stack frame where the
StepNext occurred. However, if the stepped-over statement had
a function call and the called function (or some function that
it called) unlocked the Isolate (via a C++ function call) and
another thread then locked the Isolate, an ArchiveDebug would
be done which would save the fact that a StepNext is active and
the call frame depth of the StepNext. The one-shot breaks would
then be cleared to avoid stopping the now running thread.
When the original thread that did the StepNext relocks the Isolate,
a RestoreDebug is done which, seeing that a StepNext was active
calls PrepareDebug which assumes that the StepNext must be for
the current JS frame which is usually correct, but not in this
case. This results in the StepNext break actually occurring in the
function that called the C++ function not in the function where
the StepNext was originally done. In addition, the function where
the break now happens must necessarily be deoptimized if
optimized, and debug code and a source map table created if one
doesn't already exists though this is largely invisible to the
user.
Occasionally, a crash/core dump also occurs because the stack
guard is restored after the debugging environment is restored in
the RestoreThread code which can prevent the compiler from being
called to generate the source map table (for the incorrect
function) since the stack guard is another thread's stack guard,
and so might appear that the stack guard has been gone past so
the compiler is not called, resulting in there being no source
map table. But PrepareStep ends up calling the BreakIterator
(via the DebugInfo constructor) which assumes there is a source
map table so we get a crash.
The fix is to have PrepareStep to skip to the frame where the
StepNext was done before doing its thing. Since the only
PrepareStepcaller that requires a frame other than the current
frame, is RestoreDebug, a target frame parameter was added to
PrepareStep that's set by RestoreDebug and defaults to -1
indicating to use the current frame for all other callers.
While this made the order of the debug environment and stack
guard no longer cause an obvious problem, it still felt wrong
to defer restoration of the stack guard until after something
as potentially complex as PrepareStep might be called, so the
order of RestoreDebug and RestoreStackGuard calls were reversed.
Bug: v8:10902
Change-Id: I174e254e72414c827e113aec142f1d329ebe73d8
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2405932
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70152}
2020-09-24 14:51:17 +00:00
|
|
|
{
|
|
|
|
v8::Locker locker(isolate_);
|
|
|
|
v8::Isolate::Scope i_scope(isolate_);
|
|
|
|
|
|
|
|
v8::HandleScope scope(isolate_);
|
|
|
|
v8::Local<v8::Context> context = v8::Context::New(isolate_);
|
|
|
|
v8::Context::Scope context_scope(context);
|
|
|
|
auto callback = [](const v8::FunctionCallbackInfo<v8::Value>& info) {
|
|
|
|
v8::Local<v8::Value> value = info.Data();
|
|
|
|
CHECK(value->IsExternal());
|
|
|
|
auto art = static_cast<ArchiveRestoreThread*>(
|
|
|
|
v8::Local<v8::External>::Cast(value)->Value());
|
|
|
|
art->MaybeSpawnChildThread();
|
|
|
|
};
|
|
|
|
v8::Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(
|
|
|
|
isolate_, callback, v8::External::New(isolate_, this));
|
|
|
|
CHECK(context->Global()
|
|
|
|
->Set(context, v8_str("maybeSpawnChildThread"),
|
|
|
|
fun->GetFunction(context).ToLocalChecked())
|
|
|
|
.FromJust());
|
|
|
|
|
|
|
|
v8::Local<v8::Function> test =
|
|
|
|
CompileFunction(isolate_,
|
|
|
|
"function test(n) {\n"
|
|
|
|
" debugger;\n"
|
|
|
|
" nest();\n"
|
|
|
|
" middle();\n"
|
|
|
|
" return n + 1;\n"
|
|
|
|
" function middle() {\n"
|
|
|
|
" debugger;\n"
|
|
|
|
" nest();\n"
|
|
|
|
" Date.now();\n"
|
|
|
|
" }\n"
|
|
|
|
" function nest() {\n"
|
|
|
|
" maybeSpawnChildThread();\n"
|
|
|
|
" }\n"
|
|
|
|
"}\n",
|
|
|
|
"test");
|
2018-08-02 20:08:35 +00:00
|
|
|
|
[debug] Restore StepNext on correct frame for RestoreDebug
When an Isolate in a multi-threaded environment is being debugged
and a thread does a Step Over (StepNext internally) one-shot
breaks are created in the code at the stack frame where the
StepNext occurred. However, if the stepped-over statement had
a function call and the called function (or some function that
it called) unlocked the Isolate (via a C++ function call) and
another thread then locked the Isolate, an ArchiveDebug would
be done which would save the fact that a StepNext is active and
the call frame depth of the StepNext. The one-shot breaks would
then be cleared to avoid stopping the now running thread.
When the original thread that did the StepNext relocks the Isolate,
a RestoreDebug is done which, seeing that a StepNext was active
calls PrepareDebug which assumes that the StepNext must be for
the current JS frame which is usually correct, but not in this
case. This results in the StepNext break actually occurring in the
function that called the C++ function not in the function where
the StepNext was originally done. In addition, the function where
the break now happens must necessarily be deoptimized if
optimized, and debug code and a source map table created if one
doesn't already exists though this is largely invisible to the
user.
Occasionally, a crash/core dump also occurs because the stack
guard is restored after the debugging environment is restored in
the RestoreThread code which can prevent the compiler from being
called to generate the source map table (for the incorrect
function) since the stack guard is another thread's stack guard,
and so might appear that the stack guard has been gone past so
the compiler is not called, resulting in there being no source
map table. But PrepareStep ends up calling the BreakIterator
(via the DebugInfo constructor) which assumes there is a source
map table so we get a crash.
The fix is to have PrepareStep to skip to the frame where the
StepNext was done before doing its thing. Since the only
PrepareStepcaller that requires a frame other than the current
frame, is RestoreDebug, a target frame parameter was added to
PrepareStep that's set by RestoreDebug and defaults to -1
indicating to use the current frame for all other callers.
While this made the order of the debug environment and stack
guard no longer cause an obvious problem, it still felt wrong
to defer restoration of the stack guard until after something
as potentially complex as PrepareStep might be called, so the
order of RestoreDebug and RestoreStackGuard calls were reversed.
Bug: v8:10902
Change-Id: I174e254e72414c827e113aec142f1d329ebe73d8
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2405932
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70152}
2020-09-24 14:51:17 +00:00
|
|
|
debug_->SetDebugDelegate(this);
|
|
|
|
v8::internal::DisableBreak enable_break(debug_, false);
|
2018-08-02 20:08:35 +00:00
|
|
|
|
[debug] Restore StepNext on correct frame for RestoreDebug
When an Isolate in a multi-threaded environment is being debugged
and a thread does a Step Over (StepNext internally) one-shot
breaks are created in the code at the stack frame where the
StepNext occurred. However, if the stepped-over statement had
a function call and the called function (or some function that
it called) unlocked the Isolate (via a C++ function call) and
another thread then locked the Isolate, an ArchiveDebug would
be done which would save the fact that a StepNext is active and
the call frame depth of the StepNext. The one-shot breaks would
then be cleared to avoid stopping the now running thread.
When the original thread that did the StepNext relocks the Isolate,
a RestoreDebug is done which, seeing that a StepNext was active
calls PrepareDebug which assumes that the StepNext must be for
the current JS frame which is usually correct, but not in this
case. This results in the StepNext break actually occurring in the
function that called the C++ function not in the function where
the StepNext was originally done. In addition, the function where
the break now happens must necessarily be deoptimized if
optimized, and debug code and a source map table created if one
doesn't already exists though this is largely invisible to the
user.
Occasionally, a crash/core dump also occurs because the stack
guard is restored after the debugging environment is restored in
the RestoreThread code which can prevent the compiler from being
called to generate the source map table (for the incorrect
function) since the stack guard is another thread's stack guard,
and so might appear that the stack guard has been gone past so
the compiler is not called, resulting in there being no source
map table. But PrepareStep ends up calling the BreakIterator
(via the DebugInfo constructor) which assumes there is a source
map table so we get a crash.
The fix is to have PrepareStep to skip to the frame where the
StepNext was done before doing its thing. Since the only
PrepareStepcaller that requires a frame other than the current
frame, is RestoreDebug, a target frame parameter was added to
PrepareStep that's set by RestoreDebug and defaults to -1
indicating to use the current frame for all other callers.
While this made the order of the debug environment and stack
guard no longer cause an obvious problem, it still felt wrong
to defer restoration of the stack guard until after something
as potentially complex as PrepareStep might be called, so the
order of RestoreDebug and RestoreStackGuard calls were reversed.
Bug: v8:10902
Change-Id: I174e254e72414c827e113aec142f1d329ebe73d8
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2405932
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70152}
2020-09-24 14:51:17 +00:00
|
|
|
v8::Local<v8::Value> args[1] = {v8::Integer::New(isolate_, spawn_count_)};
|
2018-08-02 20:08:35 +00:00
|
|
|
|
[debug] Restore StepNext on correct frame for RestoreDebug
When an Isolate in a multi-threaded environment is being debugged
and a thread does a Step Over (StepNext internally) one-shot
breaks are created in the code at the stack frame where the
StepNext occurred. However, if the stepped-over statement had
a function call and the called function (or some function that
it called) unlocked the Isolate (via a C++ function call) and
another thread then locked the Isolate, an ArchiveDebug would
be done which would save the fact that a StepNext is active and
the call frame depth of the StepNext. The one-shot breaks would
then be cleared to avoid stopping the now running thread.
When the original thread that did the StepNext relocks the Isolate,
a RestoreDebug is done which, seeing that a StepNext was active
calls PrepareDebug which assumes that the StepNext must be for
the current JS frame which is usually correct, but not in this
case. This results in the StepNext break actually occurring in the
function that called the C++ function not in the function where
the StepNext was originally done. In addition, the function where
the break now happens must necessarily be deoptimized if
optimized, and debug code and a source map table created if one
doesn't already exists though this is largely invisible to the
user.
Occasionally, a crash/core dump also occurs because the stack
guard is restored after the debugging environment is restored in
the RestoreThread code which can prevent the compiler from being
called to generate the source map table (for the incorrect
function) since the stack guard is another thread's stack guard,
and so might appear that the stack guard has been gone past so
the compiler is not called, resulting in there being no source
map table. But PrepareStep ends up calling the BreakIterator
(via the DebugInfo constructor) which assumes there is a source
map table so we get a crash.
The fix is to have PrepareStep to skip to the frame where the
StepNext was done before doing its thing. Since the only
PrepareStepcaller that requires a frame other than the current
frame, is RestoreDebug, a target frame parameter was added to
PrepareStep that's set by RestoreDebug and defaults to -1
indicating to use the current frame for all other callers.
While this made the order of the debug environment and stack
guard no longer cause an obvious problem, it still felt wrong
to defer restoration of the stack guard until after something
as potentially complex as PrepareStep might be called, so the
order of RestoreDebug and RestoreStackGuard calls were reversed.
Bug: v8:10902
Change-Id: I174e254e72414c827e113aec142f1d329ebe73d8
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2405932
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70152}
2020-09-24 14:51:17 +00:00
|
|
|
int result = test->Call(context, context->Global(), 1, args)
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Int32Value(context)
|
|
|
|
.FromJust();
|
2018-08-02 20:08:35 +00:00
|
|
|
|
[debug] Restore StepNext on correct frame for RestoreDebug
When an Isolate in a multi-threaded environment is being debugged
and a thread does a Step Over (StepNext internally) one-shot
breaks are created in the code at the stack frame where the
StepNext occurred. However, if the stepped-over statement had
a function call and the called function (or some function that
it called) unlocked the Isolate (via a C++ function call) and
another thread then locked the Isolate, an ArchiveDebug would
be done which would save the fact that a StepNext is active and
the call frame depth of the StepNext. The one-shot breaks would
then be cleared to avoid stopping the now running thread.
When the original thread that did the StepNext relocks the Isolate,
a RestoreDebug is done which, seeing that a StepNext was active
calls PrepareDebug which assumes that the StepNext must be for
the current JS frame which is usually correct, but not in this
case. This results in the StepNext break actually occurring in the
function that called the C++ function not in the function where
the StepNext was originally done. In addition, the function where
the break now happens must necessarily be deoptimized if
optimized, and debug code and a source map table created if one
doesn't already exists though this is largely invisible to the
user.
Occasionally, a crash/core dump also occurs because the stack
guard is restored after the debugging environment is restored in
the RestoreThread code which can prevent the compiler from being
called to generate the source map table (for the incorrect
function) since the stack guard is another thread's stack guard,
and so might appear that the stack guard has been gone past so
the compiler is not called, resulting in there being no source
map table. But PrepareStep ends up calling the BreakIterator
(via the DebugInfo constructor) which assumes there is a source
map table so we get a crash.
The fix is to have PrepareStep to skip to the frame where the
StepNext was done before doing its thing. Since the only
PrepareStepcaller that requires a frame other than the current
frame, is RestoreDebug, a target frame parameter was added to
PrepareStep that's set by RestoreDebug and defaults to -1
indicating to use the current frame for all other callers.
While this made the order of the debug environment and stack
guard no longer cause an obvious problem, it still felt wrong
to defer restoration of the stack guard until after something
as potentially complex as PrepareStep might be called, so the
order of RestoreDebug and RestoreStackGuard calls were reversed.
Bug: v8:10902
Change-Id: I174e254e72414c827e113aec142f1d329ebe73d8
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2405932
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70152}
2020-09-24 14:51:17 +00:00
|
|
|
// Verify that test(spawn_count_) returned spawn_count_ + 1.
|
|
|
|
CHECK_EQ(spawn_count_ + 1, result);
|
|
|
|
}
|
2018-08-02 20:08:35 +00:00
|
|
|
}
|
|
|
|
|
2021-11-23 09:14:18 +00:00
|
|
|
void BreakProgramRequested(v8::Local<v8::Context> context,
|
|
|
|
const std::vector<v8::debug::BreakpointId>&,
|
2021-12-02 09:26:01 +00:00
|
|
|
v8::debug::BreakReasons break_reasons) override {
|
2018-08-02 20:08:35 +00:00
|
|
|
auto stack_traces = v8::debug::StackTraceIterator::Create(isolate_);
|
|
|
|
if (!stack_traces->Done()) {
|
|
|
|
v8::debug::Location location = stack_traces->GetSourceLocation();
|
|
|
|
|
|
|
|
i::PrintF("ArchiveRestoreThread #%d hit breakpoint at line %d\n",
|
|
|
|
spawn_count_, location.GetLineNumber());
|
|
|
|
|
[debug] Restore StepNext on correct frame for RestoreDebug
When an Isolate in a multi-threaded environment is being debugged
and a thread does a Step Over (StepNext internally) one-shot
breaks are created in the code at the stack frame where the
StepNext occurred. However, if the stepped-over statement had
a function call and the called function (or some function that
it called) unlocked the Isolate (via a C++ function call) and
another thread then locked the Isolate, an ArchiveDebug would
be done which would save the fact that a StepNext is active and
the call frame depth of the StepNext. The one-shot breaks would
then be cleared to avoid stopping the now running thread.
When the original thread that did the StepNext relocks the Isolate,
a RestoreDebug is done which, seeing that a StepNext was active
calls PrepareDebug which assumes that the StepNext must be for
the current JS frame which is usually correct, but not in this
case. This results in the StepNext break actually occurring in the
function that called the C++ function not in the function where
the StepNext was originally done. In addition, the function where
the break now happens must necessarily be deoptimized if
optimized, and debug code and a source map table created if one
doesn't already exists though this is largely invisible to the
user.
Occasionally, a crash/core dump also occurs because the stack
guard is restored after the debugging environment is restored in
the RestoreThread code which can prevent the compiler from being
called to generate the source map table (for the incorrect
function) since the stack guard is another thread's stack guard,
and so might appear that the stack guard has been gone past so
the compiler is not called, resulting in there being no source
map table. But PrepareStep ends up calling the BreakIterator
(via the DebugInfo constructor) which assumes there is a source
map table so we get a crash.
The fix is to have PrepareStep to skip to the frame where the
StepNext was done before doing its thing. Since the only
PrepareStepcaller that requires a frame other than the current
frame, is RestoreDebug, a target frame parameter was added to
PrepareStep that's set by RestoreDebug and defaults to -1
indicating to use the current frame for all other callers.
While this made the order of the debug environment and stack
guard no longer cause an obvious problem, it still felt wrong
to defer restoration of the stack guard until after something
as potentially complex as PrepareStep might be called, so the
order of RestoreDebug and RestoreStackGuard calls were reversed.
Bug: v8:10902
Change-Id: I174e254e72414c827e113aec142f1d329ebe73d8
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2405932
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70152}
2020-09-24 14:51:17 +00:00
|
|
|
const int expectedLineNumber[] = {1, 2, 3, 6, 4};
|
|
|
|
CHECK_EQ(expectedLineNumber[break_count_], location.GetLineNumber());
|
|
|
|
switch (break_count_) {
|
|
|
|
case 0: // debugger;
|
|
|
|
case 1: // nest();
|
|
|
|
case 2: // middle();
|
2018-08-02 20:08:35 +00:00
|
|
|
|
|
|
|
// Attempt to stop on the next line after the first debugger
|
|
|
|
// statement. If debug->{Archive,Restore}Debug() improperly reset
|
|
|
|
// thread-local debug information, the debugger will fail to stop
|
|
|
|
// before the test function returns.
|
2021-06-01 08:32:39 +00:00
|
|
|
debug_->PrepareStep(StepOver);
|
2018-08-02 20:08:35 +00:00
|
|
|
|
|
|
|
// Spawning threads while handling the current breakpoint verifies
|
|
|
|
// that the parent thread correctly archived and restored the
|
|
|
|
// state necessary to stop on the next line. If not, then control
|
|
|
|
// will simply continue past the `return n + 1` statement.
|
[debug] Restore StepNext on correct frame for RestoreDebug
When an Isolate in a multi-threaded environment is being debugged
and a thread does a Step Over (StepNext internally) one-shot
breaks are created in the code at the stack frame where the
StepNext occurred. However, if the stepped-over statement had
a function call and the called function (or some function that
it called) unlocked the Isolate (via a C++ function call) and
another thread then locked the Isolate, an ArchiveDebug would
be done which would save the fact that a StepNext is active and
the call frame depth of the StepNext. The one-shot breaks would
then be cleared to avoid stopping the now running thread.
When the original thread that did the StepNext relocks the Isolate,
a RestoreDebug is done which, seeing that a StepNext was active
calls PrepareDebug which assumes that the StepNext must be for
the current JS frame which is usually correct, but not in this
case. This results in the StepNext break actually occurring in the
function that called the C++ function not in the function where
the StepNext was originally done. In addition, the function where
the break now happens must necessarily be deoptimized if
optimized, and debug code and a source map table created if one
doesn't already exists though this is largely invisible to the
user.
Occasionally, a crash/core dump also occurs because the stack
guard is restored after the debugging environment is restored in
the RestoreThread code which can prevent the compiler from being
called to generate the source map table (for the incorrect
function) since the stack guard is another thread's stack guard,
and so might appear that the stack guard has been gone past so
the compiler is not called, resulting in there being no source
map table. But PrepareStep ends up calling the BreakIterator
(via the DebugInfo constructor) which assumes there is a source
map table so we get a crash.
The fix is to have PrepareStep to skip to the frame where the
StepNext was done before doing its thing. Since the only
PrepareStepcaller that requires a frame other than the current
frame, is RestoreDebug, a target frame parameter was added to
PrepareStep that's set by RestoreDebug and defaults to -1
indicating to use the current frame for all other callers.
While this made the order of the debug environment and stack
guard no longer cause an obvious problem, it still felt wrong
to defer restoration of the stack guard until after something
as potentially complex as PrepareStep might be called, so the
order of RestoreDebug and RestoreStackGuard calls were reversed.
Bug: v8:10902
Change-Id: I174e254e72414c827e113aec142f1d329ebe73d8
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2405932
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70152}
2020-09-24 14:51:17 +00:00
|
|
|
//
|
|
|
|
// A real world multi-threading app would probably never unlock the
|
|
|
|
// Isolate at a break point as that adds a thread switch point while
|
|
|
|
// debugging where none existed in the application and a
|
|
|
|
// multi-threaded should be able to count on not thread switching
|
|
|
|
// over a certain range of instructions.
|
2018-08-02 20:08:35 +00:00
|
|
|
MaybeSpawnChildThread();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
[debug] Restore StepNext on correct frame for RestoreDebug
When an Isolate in a multi-threaded environment is being debugged
and a thread does a Step Over (StepNext internally) one-shot
breaks are created in the code at the stack frame where the
StepNext occurred. However, if the stepped-over statement had
a function call and the called function (or some function that
it called) unlocked the Isolate (via a C++ function call) and
another thread then locked the Isolate, an ArchiveDebug would
be done which would save the fact that a StepNext is active and
the call frame depth of the StepNext. The one-shot breaks would
then be cleared to avoid stopping the now running thread.
When the original thread that did the StepNext relocks the Isolate,
a RestoreDebug is done which, seeing that a StepNext was active
calls PrepareDebug which assumes that the StepNext must be for
the current JS frame which is usually correct, but not in this
case. This results in the StepNext break actually occurring in the
function that called the C++ function not in the function where
the StepNext was originally done. In addition, the function where
the break now happens must necessarily be deoptimized if
optimized, and debug code and a source map table created if one
doesn't already exists though this is largely invisible to the
user.
Occasionally, a crash/core dump also occurs because the stack
guard is restored after the debugging environment is restored in
the RestoreThread code which can prevent the compiler from being
called to generate the source map table (for the incorrect
function) since the stack guard is another thread's stack guard,
and so might appear that the stack guard has been gone past so
the compiler is not called, resulting in there being no source
map table. But PrepareStep ends up calling the BreakIterator
(via the DebugInfo constructor) which assumes there is a source
map table so we get a crash.
The fix is to have PrepareStep to skip to the frame where the
StepNext was done before doing its thing. Since the only
PrepareStepcaller that requires a frame other than the current
frame, is RestoreDebug, a target frame parameter was added to
PrepareStep that's set by RestoreDebug and defaults to -1
indicating to use the current frame for all other callers.
While this made the order of the debug environment and stack
guard no longer cause an obvious problem, it still felt wrong
to defer restoration of the stack guard until after something
as potentially complex as PrepareStep might be called, so the
order of RestoreDebug and RestoreStackGuard calls were reversed.
Bug: v8:10902
Change-Id: I174e254e72414c827e113aec142f1d329ebe73d8
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2405932
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70152}
2020-09-24 14:51:17 +00:00
|
|
|
case 3: // debugger; in middle();
|
|
|
|
// Attempt to stop on the next line after the first debugger
|
|
|
|
// statement. If debug->{Archive,Restore}Debug() improperly reset
|
|
|
|
// thread-local debug information, the debugger will fail to stop
|
|
|
|
// before the test function returns.
|
|
|
|
debug_->PrepareStep(StepOut);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4: // return n + 1;
|
2018-08-02 20:08:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
CHECK(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
++break_count_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MaybeSpawnChildThread() {
|
|
|
|
if (spawn_count_ > 1) {
|
|
|
|
v8::Unlocker unlocker(isolate_);
|
|
|
|
|
|
|
|
// Spawn a thread that spawns a thread that spawns a thread (and so
|
|
|
|
// on) so that the ThreadManager is forced to archive and restore
|
|
|
|
// the current thread.
|
|
|
|
ArchiveRestoreThread child(isolate_, spawn_count_ - 1);
|
2019-07-29 13:09:02 +00:00
|
|
|
CHECK(child.Start());
|
2018-08-02 20:08:35 +00:00
|
|
|
child.Join();
|
|
|
|
|
|
|
|
// The child thread sets itself as the debug delegate, so we need to
|
|
|
|
// usurp it after the child finishes, or else future breakpoints
|
|
|
|
// will be delegated to a destroyed ArchiveRestoreThread object.
|
|
|
|
debug_->SetDebugDelegate(this);
|
|
|
|
|
|
|
|
// This is the most important check in this test, since
|
|
|
|
// child.GetBreakCount() will return 1 if the debugger fails to stop
|
[debug] Restore StepNext on correct frame for RestoreDebug
When an Isolate in a multi-threaded environment is being debugged
and a thread does a Step Over (StepNext internally) one-shot
breaks are created in the code at the stack frame where the
StepNext occurred. However, if the stepped-over statement had
a function call and the called function (or some function that
it called) unlocked the Isolate (via a C++ function call) and
another thread then locked the Isolate, an ArchiveDebug would
be done which would save the fact that a StepNext is active and
the call frame depth of the StepNext. The one-shot breaks would
then be cleared to avoid stopping the now running thread.
When the original thread that did the StepNext relocks the Isolate,
a RestoreDebug is done which, seeing that a StepNext was active
calls PrepareDebug which assumes that the StepNext must be for
the current JS frame which is usually correct, but not in this
case. This results in the StepNext break actually occurring in the
function that called the C++ function not in the function where
the StepNext was originally done. In addition, the function where
the break now happens must necessarily be deoptimized if
optimized, and debug code and a source map table created if one
doesn't already exists though this is largely invisible to the
user.
Occasionally, a crash/core dump also occurs because the stack
guard is restored after the debugging environment is restored in
the RestoreThread code which can prevent the compiler from being
called to generate the source map table (for the incorrect
function) since the stack guard is another thread's stack guard,
and so might appear that the stack guard has been gone past so
the compiler is not called, resulting in there being no source
map table. But PrepareStep ends up calling the BreakIterator
(via the DebugInfo constructor) which assumes there is a source
map table so we get a crash.
The fix is to have PrepareStep to skip to the frame where the
StepNext was done before doing its thing. Since the only
PrepareStepcaller that requires a frame other than the current
frame, is RestoreDebug, a target frame parameter was added to
PrepareStep that's set by RestoreDebug and defaults to -1
indicating to use the current frame for all other callers.
While this made the order of the debug environment and stack
guard no longer cause an obvious problem, it still felt wrong
to defer restoration of the stack guard until after something
as potentially complex as PrepareStep might be called, so the
order of RestoreDebug and RestoreStackGuard calls were reversed.
Bug: v8:10902
Change-Id: I174e254e72414c827e113aec142f1d329ebe73d8
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2405932
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70152}
2020-09-24 14:51:17 +00:00
|
|
|
// on the `next()` line after the grandchild thread returns.
|
|
|
|
CHECK_EQ(child.GetBreakCount(), 5);
|
2023-01-19 12:43:10 +00:00
|
|
|
|
|
|
|
// This test on purpose unlocks the isolate without exiting and
|
|
|
|
// re-entering. It must however update the stack start, which would have
|
|
|
|
// been done automatically if the isolate was properly re-entered.
|
|
|
|
reinterpret_cast<i::Isolate*>(isolate_)->heap()->SetStackStart(
|
|
|
|
v8::base::Stack::GetStackStart());
|
2018-08-02 20:08:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetBreakCount() { return break_count_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
v8::Isolate* isolate_;
|
|
|
|
v8::internal::Debug* debug_;
|
|
|
|
const int spawn_count_;
|
|
|
|
int break_count_;
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(DebugArchiveRestore) {
|
[debug] Restore StepNext on correct frame for RestoreDebug
When an Isolate in a multi-threaded environment is being debugged
and a thread does a Step Over (StepNext internally) one-shot
breaks are created in the code at the stack frame where the
StepNext occurred. However, if the stepped-over statement had
a function call and the called function (or some function that
it called) unlocked the Isolate (via a C++ function call) and
another thread then locked the Isolate, an ArchiveDebug would
be done which would save the fact that a StepNext is active and
the call frame depth of the StepNext. The one-shot breaks would
then be cleared to avoid stopping the now running thread.
When the original thread that did the StepNext relocks the Isolate,
a RestoreDebug is done which, seeing that a StepNext was active
calls PrepareDebug which assumes that the StepNext must be for
the current JS frame which is usually correct, but not in this
case. This results in the StepNext break actually occurring in the
function that called the C++ function not in the function where
the StepNext was originally done. In addition, the function where
the break now happens must necessarily be deoptimized if
optimized, and debug code and a source map table created if one
doesn't already exists though this is largely invisible to the
user.
Occasionally, a crash/core dump also occurs because the stack
guard is restored after the debugging environment is restored in
the RestoreThread code which can prevent the compiler from being
called to generate the source map table (for the incorrect
function) since the stack guard is another thread's stack guard,
and so might appear that the stack guard has been gone past so
the compiler is not called, resulting in there being no source
map table. But PrepareStep ends up calling the BreakIterator
(via the DebugInfo constructor) which assumes there is a source
map table so we get a crash.
The fix is to have PrepareStep to skip to the frame where the
StepNext was done before doing its thing. Since the only
PrepareStepcaller that requires a frame other than the current
frame, is RestoreDebug, a target frame parameter was added to
PrepareStep that's set by RestoreDebug and defaults to -1
indicating to use the current frame for all other callers.
While this made the order of the debug environment and stack
guard no longer cause an obvious problem, it still felt wrong
to defer restoration of the stack guard until after something
as potentially complex as PrepareStep might be called, so the
order of RestoreDebug and RestoreStackGuard calls were reversed.
Bug: v8:10902
Change-Id: I174e254e72414c827e113aec142f1d329ebe73d8
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2405932
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70152}
2020-09-24 14:51:17 +00:00
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
2018-08-02 20:08:35 +00:00
|
|
|
|
[debug] Restore StepNext on correct frame for RestoreDebug
When an Isolate in a multi-threaded environment is being debugged
and a thread does a Step Over (StepNext internally) one-shot
breaks are created in the code at the stack frame where the
StepNext occurred. However, if the stepped-over statement had
a function call and the called function (or some function that
it called) unlocked the Isolate (via a C++ function call) and
another thread then locked the Isolate, an ArchiveDebug would
be done which would save the fact that a StepNext is active and
the call frame depth of the StepNext. The one-shot breaks would
then be cleared to avoid stopping the now running thread.
When the original thread that did the StepNext relocks the Isolate,
a RestoreDebug is done which, seeing that a StepNext was active
calls PrepareDebug which assumes that the StepNext must be for
the current JS frame which is usually correct, but not in this
case. This results in the StepNext break actually occurring in the
function that called the C++ function not in the function where
the StepNext was originally done. In addition, the function where
the break now happens must necessarily be deoptimized if
optimized, and debug code and a source map table created if one
doesn't already exists though this is largely invisible to the
user.
Occasionally, a crash/core dump also occurs because the stack
guard is restored after the debugging environment is restored in
the RestoreThread code which can prevent the compiler from being
called to generate the source map table (for the incorrect
function) since the stack guard is another thread's stack guard,
and so might appear that the stack guard has been gone past so
the compiler is not called, resulting in there being no source
map table. But PrepareStep ends up calling the BreakIterator
(via the DebugInfo constructor) which assumes there is a source
map table so we get a crash.
The fix is to have PrepareStep to skip to the frame where the
StepNext was done before doing its thing. Since the only
PrepareStepcaller that requires a frame other than the current
frame, is RestoreDebug, a target frame parameter was added to
PrepareStep that's set by RestoreDebug and defaults to -1
indicating to use the current frame for all other callers.
While this made the order of the debug environment and stack
guard no longer cause an obvious problem, it still felt wrong
to defer restoration of the stack guard until after something
as potentially complex as PrepareStep might be called, so the
order of RestoreDebug and RestoreStackGuard calls were reversed.
Bug: v8:10902
Change-Id: I174e254e72414c827e113aec142f1d329ebe73d8
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2405932
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70152}
2020-09-24 14:51:17 +00:00
|
|
|
ArchiveRestoreThread thread(isolate, 4);
|
2018-08-02 20:08:35 +00:00
|
|
|
// Instead of calling thread.Start() and thread.Join() here, we call
|
|
|
|
// thread.Run() directly, to make sure we exercise archive/restore
|
|
|
|
// logic on the *current* thread as well as other threads.
|
|
|
|
thread.Run();
|
[debug] Restore StepNext on correct frame for RestoreDebug
When an Isolate in a multi-threaded environment is being debugged
and a thread does a Step Over (StepNext internally) one-shot
breaks are created in the code at the stack frame where the
StepNext occurred. However, if the stepped-over statement had
a function call and the called function (or some function that
it called) unlocked the Isolate (via a C++ function call) and
another thread then locked the Isolate, an ArchiveDebug would
be done which would save the fact that a StepNext is active and
the call frame depth of the StepNext. The one-shot breaks would
then be cleared to avoid stopping the now running thread.
When the original thread that did the StepNext relocks the Isolate,
a RestoreDebug is done which, seeing that a StepNext was active
calls PrepareDebug which assumes that the StepNext must be for
the current JS frame which is usually correct, but not in this
case. This results in the StepNext break actually occurring in the
function that called the C++ function not in the function where
the StepNext was originally done. In addition, the function where
the break now happens must necessarily be deoptimized if
optimized, and debug code and a source map table created if one
doesn't already exists though this is largely invisible to the
user.
Occasionally, a crash/core dump also occurs because the stack
guard is restored after the debugging environment is restored in
the RestoreThread code which can prevent the compiler from being
called to generate the source map table (for the incorrect
function) since the stack guard is another thread's stack guard,
and so might appear that the stack guard has been gone past so
the compiler is not called, resulting in there being no source
map table. But PrepareStep ends up calling the BreakIterator
(via the DebugInfo constructor) which assumes there is a source
map table so we get a crash.
The fix is to have PrepareStep to skip to the frame where the
StepNext was done before doing its thing. Since the only
PrepareStepcaller that requires a frame other than the current
frame, is RestoreDebug, a target frame parameter was added to
PrepareStep that's set by RestoreDebug and defaults to -1
indicating to use the current frame for all other callers.
While this made the order of the debug environment and stack
guard no longer cause an obvious problem, it still felt wrong
to defer restoration of the stack guard until after something
as potentially complex as PrepareStep might be called, so the
order of RestoreDebug and RestoreStackGuard calls were reversed.
Bug: v8:10902
Change-Id: I174e254e72414c827e113aec142f1d329ebe73d8
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2405932
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70152}
2020-09-24 14:51:17 +00:00
|
|
|
CHECK_EQ(thread.GetBreakCount(), 5);
|
2018-08-02 20:08:35 +00:00
|
|
|
}
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
class DebugEventExpectNoException : public v8::debug::DebugDelegate {
|
|
|
|
public:
|
|
|
|
void ExceptionThrown(v8::Local<v8::Context> paused_context,
|
|
|
|
v8::Local<v8::Value> exception,
|
2018-09-28 15:05:45 +00:00
|
|
|
v8::Local<v8::Value> promise, bool is_uncaught,
|
|
|
|
v8::debug::ExceptionType) override {
|
2018-06-03 05:09:41 +00:00
|
|
|
CHECK(false);
|
|
|
|
}
|
|
|
|
};
|
2014-09-30 15:29:08 +00:00
|
|
|
|
|
|
|
static void TryCatchWrappedThrowCallback(
|
|
|
|
const v8::FunctionCallbackInfo<v8::Value>& args) {
|
2015-05-28 12:49:31 +00:00
|
|
|
v8::TryCatch try_catch(args.GetIsolate());
|
2014-09-30 15:29:08 +00:00
|
|
|
CompileRun("throw 'rejection';");
|
|
|
|
CHECK(try_catch.HasCaught());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DebugPromiseInterceptedByTryCatch) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2014-09-30 15:29:08 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugEventExpectNoException delegate;
|
|
|
|
v8::debug::SetDebugDelegate(isolate, &delegate);
|
|
|
|
v8::Local<v8::Context> context = env.local();
|
2021-04-30 16:19:52 +00:00
|
|
|
ChangeBreakOnException(isolate, false, true);
|
2014-09-30 15:29:08 +00:00
|
|
|
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::Local<v8::FunctionTemplate> fun =
|
2014-09-30 15:29:08 +00:00
|
|
|
v8::FunctionTemplate::New(isolate, TryCatchWrappedThrowCallback);
|
2015-11-19 13:45:42 +00:00
|
|
|
CHECK(env->Global()
|
|
|
|
->Set(context, v8_str("fun"),
|
|
|
|
fun->GetFunction(context).ToLocalChecked())
|
|
|
|
.FromJust());
|
2014-09-30 15:29:08 +00:00
|
|
|
|
|
|
|
CompileRun("var p = new Promise(function(res, rej) { fun(); res(); });");
|
|
|
|
CompileRun(
|
|
|
|
"var r;"
|
2016-05-11 01:00:23 +00:00
|
|
|
"p.then(function() { r = 'resolved'; },"
|
|
|
|
" function() { r = 'rejected'; });");
|
2015-11-19 13:45:42 +00:00
|
|
|
CHECK(CompileRun("r")->Equals(context, v8_str("resolved")).FromJust());
|
2014-09-30 15:29:08 +00:00
|
|
|
}
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
class NoInterruptsOnDebugEvent : public v8::debug::DebugDelegate {
|
|
|
|
public:
|
|
|
|
void ScriptCompiled(v8::Local<v8::debug::Script> script, bool is_live_edited,
|
|
|
|
bool has_compile_error) override {
|
|
|
|
++after_compile_handler_depth_;
|
|
|
|
// Do not allow nested AfterCompile events.
|
|
|
|
CHECK_LE(after_compile_handler_depth_, 1);
|
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
|
|
|
v8::Isolate::AllowJavascriptExecutionScope allow_script(isolate);
|
|
|
|
isolate->RequestInterrupt(&HandleInterrupt, this);
|
|
|
|
CompileRun("function foo() {}; foo();");
|
|
|
|
--after_compile_handler_depth_;
|
|
|
|
}
|
2014-09-30 15:29:08 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
private:
|
|
|
|
static void HandleInterrupt(v8::Isolate* isolate, void* data) {
|
|
|
|
NoInterruptsOnDebugEvent* d = static_cast<NoInterruptsOnDebugEvent*>(data);
|
|
|
|
CHECK_EQ(0, d->after_compile_handler_depth_);
|
|
|
|
}
|
2015-08-31 22:32:46 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
int after_compile_handler_depth_ = 0;
|
|
|
|
};
|
2015-08-31 22:32:46 +00:00
|
|
|
|
|
|
|
TEST(NoInterruptsInDebugListener) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope handle_scope(env->GetIsolate());
|
|
|
|
NoInterruptsOnDebugEvent delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
2015-08-31 22:32:46 +00:00
|
|
|
CompileRun("void(0);");
|
|
|
|
}
|
2016-02-11 15:17:59 +00:00
|
|
|
|
|
|
|
TEST(BreakLocationIterator) {
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2016-02-11 15:17:59 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
|
|
|
|
v8::Local<v8::Value> result = CompileRun(
|
|
|
|
"function f() {\n"
|
|
|
|
" debugger; \n"
|
|
|
|
" f(); \n"
|
|
|
|
" debugger; \n"
|
|
|
|
"} \n"
|
|
|
|
"f");
|
|
|
|
Handle<i::Object> function_obj = v8::Utils::OpenHandle(*result);
|
|
|
|
Handle<i::JSFunction> function = Handle<i::JSFunction>::cast(function_obj);
|
2018-06-23 09:05:50 +00:00
|
|
|
Handle<i::SharedFunctionInfo> shared(function->shared(), i_isolate);
|
2016-02-11 15:17:59 +00:00
|
|
|
|
|
|
|
EnableDebugger(isolate);
|
2017-05-31 14:26:58 +00:00
|
|
|
CHECK(i_isolate->debug()->EnsureBreakInfo(shared));
|
2018-04-05 02:01:34 +00:00
|
|
|
i_isolate->debug()->PrepareFunctionForDebugExecution(shared);
|
2016-02-11 15:17:59 +00:00
|
|
|
|
2018-06-23 09:05:50 +00:00
|
|
|
Handle<i::DebugInfo> debug_info(shared->GetDebugInfo(), i_isolate);
|
2016-08-12 06:06:31 +00:00
|
|
|
|
|
|
|
{
|
2017-08-16 05:41:03 +00:00
|
|
|
i::BreakIterator iterator(debug_info);
|
|
|
|
CHECK(iterator.GetBreakLocation().IsDebuggerStatement());
|
|
|
|
CHECK_EQ(17, iterator.GetBreakLocation().position());
|
|
|
|
iterator.Next();
|
|
|
|
CHECK(iterator.GetBreakLocation().IsDebugBreakSlot());
|
|
|
|
CHECK_EQ(32, iterator.GetBreakLocation().position());
|
|
|
|
iterator.Next();
|
|
|
|
CHECK(iterator.GetBreakLocation().IsCall());
|
|
|
|
CHECK_EQ(32, iterator.GetBreakLocation().position());
|
|
|
|
iterator.Next();
|
|
|
|
CHECK(iterator.GetBreakLocation().IsDebuggerStatement());
|
|
|
|
CHECK_EQ(47, iterator.GetBreakLocation().position());
|
|
|
|
iterator.Next();
|
|
|
|
CHECK(iterator.GetBreakLocation().IsReturn());
|
|
|
|
CHECK_EQ(60, iterator.GetBreakLocation().position());
|
|
|
|
iterator.Next();
|
|
|
|
CHECK(iterator.Done());
|
2016-08-12 06:06:31 +00:00
|
|
|
}
|
|
|
|
|
2016-02-11 15:17:59 +00:00
|
|
|
DisableDebugger(isolate);
|
|
|
|
}
|
2016-03-30 11:04:17 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
class DebugStepOverFunctionWithCaughtExceptionListener
|
|
|
|
: public v8::debug::DebugDelegate {
|
|
|
|
public:
|
2021-11-23 09:14:18 +00:00
|
|
|
void BreakProgramRequested(
|
|
|
|
v8::Local<v8::Context> paused_context,
|
|
|
|
const std::vector<v8::debug::BreakpointId>& inspector_break_points_hit,
|
2021-12-02 09:26:01 +00:00
|
|
|
v8::debug::BreakReasons break_reasons) override {
|
2018-06-03 05:09:41 +00:00
|
|
|
++break_point_hit_count;
|
|
|
|
if (break_point_hit_count >= 3) return;
|
2021-06-01 08:32:39 +00:00
|
|
|
PrepareStep(StepOver);
|
2018-06-03 05:09:41 +00:00
|
|
|
}
|
|
|
|
int break_point_hit_count = 0;
|
|
|
|
};
|
2016-04-19 15:28:49 +00:00
|
|
|
|
|
|
|
TEST(DebugStepOverFunctionWithCaughtException) {
|
2022-09-15 11:04:11 +00:00
|
|
|
i::v8_flags.allow_natives_syntax = true;
|
2016-04-19 15:28:49 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
LocalContext env;
|
2016-04-19 15:28:49 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2018-06-03 05:09:41 +00:00
|
|
|
DebugStepOverFunctionWithCaughtExceptionListener delegate;
|
|
|
|
v8::debug::SetDebugDelegate(isolate, &delegate);
|
2016-04-19 15:28:49 +00:00
|
|
|
|
|
|
|
CompileRun(
|
|
|
|
"function foo() {\n"
|
|
|
|
" try { throw new Error(); } catch (e) {}\n"
|
|
|
|
"}\n"
|
|
|
|
"debugger;\n"
|
|
|
|
"foo();\n"
|
|
|
|
"foo();\n");
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
|
|
|
CHECK_EQ(3, delegate.break_point_hit_count);
|
2016-04-19 15:28:49 +00:00
|
|
|
}
|
2017-01-11 13:20:53 +00:00
|
|
|
|
2018-03-26 11:33:00 +00:00
|
|
|
bool near_heap_limit_callback_called = false;
|
|
|
|
size_t NearHeapLimitCallback(void* data, size_t current_heap_limit,
|
|
|
|
size_t initial_heap_limit) {
|
|
|
|
near_heap_limit_callback_called = true;
|
|
|
|
return initial_heap_limit + 10u * i::MB;
|
2017-01-11 13:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UNINITIALIZED_TEST(DebugSetOutOfMemoryListener) {
|
2022-09-15 11:04:11 +00:00
|
|
|
i::v8_flags.stress_concurrent_allocation = false;
|
2017-01-11 13:20:53 +00:00
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
2019-06-05 21:08:15 +00:00
|
|
|
create_params.constraints.set_max_old_generation_size_in_bytes(10 * i::MB);
|
2017-01-11 13:20:53 +00:00
|
|
|
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
{
|
|
|
|
v8::Isolate::Scope i_scope(isolate);
|
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
LocalContext context(isolate);
|
2018-03-26 11:33:00 +00:00
|
|
|
isolate->AddNearHeapLimitCallback(NearHeapLimitCallback, nullptr);
|
|
|
|
CHECK(!near_heap_limit_callback_called);
|
2017-01-11 13:20:53 +00:00
|
|
|
// The following allocation fails unless the out-of-memory callback
|
|
|
|
// increases the heap limit.
|
2019-02-14 13:01:52 +00:00
|
|
|
int length = 10 * i::MB / i::kTaggedSize;
|
2019-03-11 19:04:02 +00:00
|
|
|
i_isolate->factory()->NewFixedArray(length, i::AllocationType::kOld);
|
2018-03-26 11:33:00 +00:00
|
|
|
CHECK(near_heap_limit_callback_called);
|
|
|
|
isolate->RemoveNearHeapLimitCallback(NearHeapLimitCallback, 0);
|
2017-01-11 13:20:53 +00:00
|
|
|
}
|
|
|
|
isolate->Dispose();
|
|
|
|
}
|
2017-02-16 08:36:12 +00:00
|
|
|
|
|
|
|
TEST(DebugCoverage) {
|
2022-09-15 11:04:11 +00:00
|
|
|
i::v8_flags.always_turbofan = false;
|
2017-02-16 08:36:12 +00:00
|
|
|
LocalContext env;
|
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2019-02-26 13:24:51 +00:00
|
|
|
v8::debug::Coverage::SelectMode(isolate,
|
|
|
|
v8::debug::CoverageMode::kPreciseCount);
|
2017-02-16 08:36:12 +00:00
|
|
|
v8::Local<v8::String> source = v8_str(
|
|
|
|
"function f() {\n"
|
|
|
|
"}\n"
|
|
|
|
"f();\n"
|
|
|
|
"f();");
|
|
|
|
CompileRun(source);
|
2017-03-23 17:23:17 +00:00
|
|
|
v8::debug::Coverage coverage = v8::debug::Coverage::CollectPrecise(isolate);
|
2017-02-16 08:36:12 +00:00
|
|
|
CHECK_EQ(1u, coverage.ScriptCount());
|
2017-02-22 10:21:57 +00:00
|
|
|
v8::debug::Coverage::ScriptData script_data = coverage.GetScriptData(0);
|
|
|
|
v8::Local<v8::debug::Script> script = script_data.GetScript();
|
2017-02-16 08:36:12 +00:00
|
|
|
CHECK(script->Source()
|
2022-03-04 08:41:49 +00:00
|
|
|
->JavaScriptCode()
|
2017-02-16 08:36:12 +00:00
|
|
|
.ToLocalChecked()
|
|
|
|
->Equals(env.local(), source)
|
|
|
|
.FromMaybe(false));
|
|
|
|
|
2017-02-22 10:21:57 +00:00
|
|
|
CHECK_EQ(2u, script_data.FunctionCount());
|
|
|
|
v8::debug::Coverage::FunctionData function_data =
|
|
|
|
script_data.GetFunctionData(0);
|
2017-03-08 07:23:21 +00:00
|
|
|
v8::debug::Location start =
|
|
|
|
script->GetSourceLocation(function_data.StartOffset());
|
|
|
|
v8::debug::Location end =
|
|
|
|
script->GetSourceLocation(function_data.EndOffset());
|
|
|
|
CHECK_EQ(0, start.GetLineNumber());
|
|
|
|
CHECK_EQ(0, start.GetColumnNumber());
|
|
|
|
CHECK_EQ(3, end.GetLineNumber());
|
|
|
|
CHECK_EQ(4, end.GetColumnNumber());
|
2017-02-22 10:21:57 +00:00
|
|
|
CHECK_EQ(1, function_data.Count());
|
|
|
|
|
|
|
|
function_data = script_data.GetFunctionData(1);
|
2017-03-08 07:23:21 +00:00
|
|
|
start = script->GetSourceLocation(function_data.StartOffset());
|
|
|
|
end = script->GetSourceLocation(function_data.EndOffset());
|
|
|
|
CHECK_EQ(0, start.GetLineNumber());
|
|
|
|
CHECK_EQ(0, start.GetColumnNumber());
|
|
|
|
CHECK_EQ(1, end.GetLineNumber());
|
|
|
|
CHECK_EQ(1, end.GetColumnNumber());
|
2017-02-22 10:21:57 +00:00
|
|
|
CHECK_EQ(2, function_data.Count());
|
2017-02-16 08:36:12 +00:00
|
|
|
}
|
2017-03-10 17:18:08 +00:00
|
|
|
|
2017-09-09 17:14:57 +00:00
|
|
|
namespace {
|
|
|
|
v8::debug::Coverage::ScriptData GetScriptDataAndDeleteCoverage(
|
|
|
|
v8::Isolate* isolate) {
|
|
|
|
v8::debug::Coverage coverage = v8::debug::Coverage::CollectPrecise(isolate);
|
|
|
|
CHECK_EQ(1u, coverage.ScriptCount());
|
|
|
|
return coverage.GetScriptData(0);
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TEST(DebugCoverageWithCoverageOutOfScope) {
|
2022-09-15 11:04:11 +00:00
|
|
|
i::v8_flags.always_turbofan = false;
|
2017-09-09 17:14:57 +00:00
|
|
|
LocalContext env;
|
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2019-02-26 13:24:51 +00:00
|
|
|
v8::debug::Coverage::SelectMode(isolate,
|
|
|
|
v8::debug::CoverageMode::kPreciseCount);
|
2017-09-09 17:14:57 +00:00
|
|
|
v8::Local<v8::String> source = v8_str(
|
|
|
|
"function f() {\n"
|
|
|
|
"}\n"
|
|
|
|
"f();\n"
|
|
|
|
"f();");
|
|
|
|
CompileRun(source);
|
|
|
|
v8::debug::Coverage::ScriptData script_data =
|
|
|
|
GetScriptDataAndDeleteCoverage(isolate);
|
|
|
|
v8::Local<v8::debug::Script> script = script_data.GetScript();
|
|
|
|
CHECK(script->Source()
|
2022-03-04 08:41:49 +00:00
|
|
|
->JavaScriptCode()
|
2017-09-09 17:14:57 +00:00
|
|
|
.ToLocalChecked()
|
|
|
|
->Equals(env.local(), source)
|
|
|
|
.FromMaybe(false));
|
|
|
|
|
|
|
|
CHECK_EQ(2u, script_data.FunctionCount());
|
|
|
|
v8::debug::Coverage::FunctionData function_data =
|
|
|
|
script_data.GetFunctionData(0);
|
|
|
|
|
|
|
|
CHECK_EQ(0, function_data.StartOffset());
|
|
|
|
CHECK_EQ(26, function_data.EndOffset());
|
|
|
|
|
|
|
|
v8::debug::Location start =
|
|
|
|
script->GetSourceLocation(function_data.StartOffset());
|
|
|
|
v8::debug::Location end =
|
|
|
|
script->GetSourceLocation(function_data.EndOffset());
|
|
|
|
CHECK_EQ(0, start.GetLineNumber());
|
|
|
|
CHECK_EQ(0, start.GetColumnNumber());
|
|
|
|
CHECK_EQ(3, end.GetLineNumber());
|
|
|
|
CHECK_EQ(4, end.GetColumnNumber());
|
|
|
|
CHECK_EQ(1, function_data.Count());
|
|
|
|
|
|
|
|
function_data = script_data.GetFunctionData(1);
|
|
|
|
start = script->GetSourceLocation(function_data.StartOffset());
|
|
|
|
end = script->GetSourceLocation(function_data.EndOffset());
|
|
|
|
|
|
|
|
CHECK_EQ(0, function_data.StartOffset());
|
|
|
|
CHECK_EQ(16, function_data.EndOffset());
|
|
|
|
|
|
|
|
CHECK_EQ(0, start.GetLineNumber());
|
|
|
|
CHECK_EQ(0, start.GetColumnNumber());
|
|
|
|
CHECK_EQ(1, end.GetLineNumber());
|
|
|
|
CHECK_EQ(1, end.GetColumnNumber());
|
|
|
|
CHECK_EQ(2, function_data.Count());
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
v8::debug::Coverage::FunctionData GetFunctionDataAndDeleteCoverage(
|
|
|
|
v8::Isolate* isolate) {
|
|
|
|
v8::debug::Coverage coverage = v8::debug::Coverage::CollectPrecise(isolate);
|
|
|
|
CHECK_EQ(1u, coverage.ScriptCount());
|
|
|
|
|
|
|
|
v8::debug::Coverage::ScriptData script_data = coverage.GetScriptData(0);
|
|
|
|
|
|
|
|
CHECK_EQ(2u, script_data.FunctionCount());
|
|
|
|
v8::debug::Coverage::FunctionData function_data =
|
|
|
|
script_data.GetFunctionData(0);
|
|
|
|
CHECK_EQ(1, function_data.Count());
|
|
|
|
CHECK_EQ(0, function_data.StartOffset());
|
|
|
|
CHECK_EQ(26, function_data.EndOffset());
|
|
|
|
return function_data;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TEST(DebugCoverageWithScriptDataOutOfScope) {
|
2022-09-15 11:04:11 +00:00
|
|
|
i::v8_flags.always_turbofan = false;
|
2017-09-09 17:14:57 +00:00
|
|
|
LocalContext env;
|
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2019-02-26 13:24:51 +00:00
|
|
|
v8::debug::Coverage::SelectMode(isolate,
|
|
|
|
v8::debug::CoverageMode::kPreciseCount);
|
2017-09-09 17:14:57 +00:00
|
|
|
v8::Local<v8::String> source = v8_str(
|
|
|
|
"function f() {\n"
|
|
|
|
"}\n"
|
|
|
|
"f();\n"
|
|
|
|
"f();");
|
|
|
|
CompileRun(source);
|
|
|
|
|
|
|
|
v8::debug::Coverage::FunctionData function_data =
|
|
|
|
GetFunctionDataAndDeleteCoverage(isolate);
|
|
|
|
CHECK_EQ(1, function_data.Count());
|
|
|
|
CHECK_EQ(0, function_data.StartOffset());
|
|
|
|
CHECK_EQ(26, function_data.EndOffset());
|
|
|
|
}
|
|
|
|
|
2017-03-10 17:18:08 +00:00
|
|
|
TEST(BuiltinsExceptionPrediction) {
|
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
2017-11-17 09:15:36 +00:00
|
|
|
i::Isolate* iisolate = CcTest::i_isolate();
|
2017-03-10 17:18:08 +00:00
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
v8::Context::New(isolate);
|
|
|
|
|
2017-11-17 09:15:36 +00:00
|
|
|
i::Builtins* builtins = iisolate->builtins();
|
2017-03-10 17:18:08 +00:00
|
|
|
bool fail = false;
|
2021-06-14 09:18:22 +00:00
|
|
|
for (i::Builtin builtin = i::Builtins::kFirst; builtin <= i::Builtins::kLast;
|
|
|
|
++builtin) {
|
2023-01-17 13:39:32 +00:00
|
|
|
i::Code code = builtins->code(builtin);
|
2021-06-14 09:18:22 +00:00
|
|
|
if (code.kind() != i::CodeKind::BUILTIN) continue;
|
|
|
|
auto prediction = code.GetBuiltinCatchPrediction();
|
2017-05-23 09:06:51 +00:00
|
|
|
USE(prediction);
|
2017-03-10 17:18:08 +00:00
|
|
|
}
|
|
|
|
CHECK(!fail);
|
|
|
|
}
|
[debugger] tuned StepNext and StepOut at return position
Proposed behaviour:
- StepNext at return position go into next function call (no changes with current behavior, but implemented in v8::Debug instead of hack on inspector side);
- StepOut at return position go into next non-current function call.
We need this to have better stepping in cases with native functions, blackboxed functions and/or different embedder calls (e.g. event listeners).
New behavior could be illustrated with two examples (for more see stepping-with-natives-and-frameworks test):
- let's assume that we've blackboxed callAll function, this function just takes its arguments and call one after another:
var foo = () => 1;
callAll(foo, foo, () => 2);
If we break inside of first call of function foo. Then on..
..StepNext - we're able to reach second call of function foo,
..StepOut - we're able to reach () => 2 call.
- let's consider case with native function:
[1,2,3].map(x => x * 2)
If we break inside of first callback call, then with StepNext we can iterate through all calls of callback, with StepOut we go to next statement after .map call.
Implementation details:
- when we request break we schedule step-in function call for any step action at return position and for step-in at any position,
- when we request StepOut at return position - we mark current function as needed-to-be-ignored inside of PrepareStepIn(function) call,
- when we request StepOut at not return position - we set break at return position and ask debugger to just repeat last step action on next stepping-related break.
Design doc: https://docs.google.com/document/d/1ihXHOIhP_q-fJCA0e2EiXz_Zr3B08KMjaPifcaqZ60Q/edit
BUG=v8:6118,chromium:583193
R=dgozman@chromium.org,yangguo@chromium.org
Review-Url: https://codereview.chromium.org/2758483002
Cr-Commit-Position: refs/heads/master@{#44028}
2017-03-22 14:16:18 +00:00
|
|
|
|
|
|
|
TEST(DebugGetPossibleBreakpointsReturnLocations) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
v8::Local<v8::String> source = v8_str(
|
|
|
|
"function fib(x) {\n"
|
|
|
|
" if (x < 0) return;\n"
|
|
|
|
" if (x === 0) return 1;\n"
|
|
|
|
" if (x === 1) return fib(0);\n"
|
|
|
|
" return x > 2 ? fib(x - 1) + fib(x - 2) : fib(1) + fib(0);\n"
|
|
|
|
"}");
|
|
|
|
CompileRun(source);
|
2022-06-09 07:45:35 +00:00
|
|
|
std::vector<v8::Global<v8::debug::Script>> scripts;
|
[debugger] tuned StepNext and StepOut at return position
Proposed behaviour:
- StepNext at return position go into next function call (no changes with current behavior, but implemented in v8::Debug instead of hack on inspector side);
- StepOut at return position go into next non-current function call.
We need this to have better stepping in cases with native functions, blackboxed functions and/or different embedder calls (e.g. event listeners).
New behavior could be illustrated with two examples (for more see stepping-with-natives-and-frameworks test):
- let's assume that we've blackboxed callAll function, this function just takes its arguments and call one after another:
var foo = () => 1;
callAll(foo, foo, () => 2);
If we break inside of first call of function foo. Then on..
..StepNext - we're able to reach second call of function foo,
..StepOut - we're able to reach () => 2 call.
- let's consider case with native function:
[1,2,3].map(x => x * 2)
If we break inside of first callback call, then with StepNext we can iterate through all calls of callback, with StepOut we go to next statement after .map call.
Implementation details:
- when we request break we schedule step-in function call for any step action at return position and for step-in at any position,
- when we request StepOut at return position - we mark current function as needed-to-be-ignored inside of PrepareStepIn(function) call,
- when we request StepOut at not return position - we set break at return position and ask debugger to just repeat last step action on next stepping-related break.
Design doc: https://docs.google.com/document/d/1ihXHOIhP_q-fJCA0e2EiXz_Zr3B08KMjaPifcaqZ60Q/edit
BUG=v8:6118,chromium:583193
R=dgozman@chromium.org,yangguo@chromium.org
Review-Url: https://codereview.chromium.org/2758483002
Cr-Commit-Position: refs/heads/master@{#44028}
2017-03-22 14:16:18 +00:00
|
|
|
v8::debug::GetLoadedScripts(isolate, scripts);
|
2022-06-09 07:45:35 +00:00
|
|
|
CHECK_EQ(scripts.size(), 1);
|
[debugger] tuned StepNext and StepOut at return position
Proposed behaviour:
- StepNext at return position go into next function call (no changes with current behavior, but implemented in v8::Debug instead of hack on inspector side);
- StepOut at return position go into next non-current function call.
We need this to have better stepping in cases with native functions, blackboxed functions and/or different embedder calls (e.g. event listeners).
New behavior could be illustrated with two examples (for more see stepping-with-natives-and-frameworks test):
- let's assume that we've blackboxed callAll function, this function just takes its arguments and call one after another:
var foo = () => 1;
callAll(foo, foo, () => 2);
If we break inside of first call of function foo. Then on..
..StepNext - we're able to reach second call of function foo,
..StepOut - we're able to reach () => 2 call.
- let's consider case with native function:
[1,2,3].map(x => x * 2)
If we break inside of first callback call, then with StepNext we can iterate through all calls of callback, with StepOut we go to next statement after .map call.
Implementation details:
- when we request break we schedule step-in function call for any step action at return position and for step-in at any position,
- when we request StepOut at return position - we mark current function as needed-to-be-ignored inside of PrepareStepIn(function) call,
- when we request StepOut at not return position - we set break at return position and ask debugger to just repeat last step action on next stepping-related break.
Design doc: https://docs.google.com/document/d/1ihXHOIhP_q-fJCA0e2EiXz_Zr3B08KMjaPifcaqZ60Q/edit
BUG=v8:6118,chromium:583193
R=dgozman@chromium.org,yangguo@chromium.org
Review-Url: https://codereview.chromium.org/2758483002
Cr-Commit-Position: refs/heads/master@{#44028}
2017-03-22 14:16:18 +00:00
|
|
|
std::vector<v8::debug::BreakLocation> locations;
|
2022-06-09 07:45:35 +00:00
|
|
|
CHECK(scripts[0].Get(isolate)->GetPossibleBreakpoints(
|
[debugger] tuned StepNext and StepOut at return position
Proposed behaviour:
- StepNext at return position go into next function call (no changes with current behavior, but implemented in v8::Debug instead of hack on inspector side);
- StepOut at return position go into next non-current function call.
We need this to have better stepping in cases with native functions, blackboxed functions and/or different embedder calls (e.g. event listeners).
New behavior could be illustrated with two examples (for more see stepping-with-natives-and-frameworks test):
- let's assume that we've blackboxed callAll function, this function just takes its arguments and call one after another:
var foo = () => 1;
callAll(foo, foo, () => 2);
If we break inside of first call of function foo. Then on..
..StepNext - we're able to reach second call of function foo,
..StepOut - we're able to reach () => 2 call.
- let's consider case with native function:
[1,2,3].map(x => x * 2)
If we break inside of first callback call, then with StepNext we can iterate through all calls of callback, with StepOut we go to next statement after .map call.
Implementation details:
- when we request break we schedule step-in function call for any step action at return position and for step-in at any position,
- when we request StepOut at return position - we mark current function as needed-to-be-ignored inside of PrepareStepIn(function) call,
- when we request StepOut at not return position - we set break at return position and ask debugger to just repeat last step action on next stepping-related break.
Design doc: https://docs.google.com/document/d/1ihXHOIhP_q-fJCA0e2EiXz_Zr3B08KMjaPifcaqZ60Q/edit
BUG=v8:6118,chromium:583193
R=dgozman@chromium.org,yangguo@chromium.org
Review-Url: https://codereview.chromium.org/2758483002
Cr-Commit-Position: refs/heads/master@{#44028}
2017-03-22 14:16:18 +00:00
|
|
|
v8::debug::Location(0, 17), v8::debug::Location(), true, &locations));
|
|
|
|
int returns_count = 0;
|
|
|
|
for (size_t i = 0; i < locations.size(); ++i) {
|
|
|
|
if (locations[i].type() == v8::debug::kReturnBreakLocation) {
|
|
|
|
++returns_count;
|
|
|
|
}
|
|
|
|
}
|
2017-08-10 07:54:33 +00:00
|
|
|
// With Ignition we generate one return location per return statement,
|
|
|
|
// each has line = 5, column = 0 as statement position.
|
2017-10-18 09:06:55 +00:00
|
|
|
CHECK_EQ(returns_count, 4);
|
[debugger] tuned StepNext and StepOut at return position
Proposed behaviour:
- StepNext at return position go into next function call (no changes with current behavior, but implemented in v8::Debug instead of hack on inspector side);
- StepOut at return position go into next non-current function call.
We need this to have better stepping in cases with native functions, blackboxed functions and/or different embedder calls (e.g. event listeners).
New behavior could be illustrated with two examples (for more see stepping-with-natives-and-frameworks test):
- let's assume that we've blackboxed callAll function, this function just takes its arguments and call one after another:
var foo = () => 1;
callAll(foo, foo, () => 2);
If we break inside of first call of function foo. Then on..
..StepNext - we're able to reach second call of function foo,
..StepOut - we're able to reach () => 2 call.
- let's consider case with native function:
[1,2,3].map(x => x * 2)
If we break inside of first callback call, then with StepNext we can iterate through all calls of callback, with StepOut we go to next statement after .map call.
Implementation details:
- when we request break we schedule step-in function call for any step action at return position and for step-in at any position,
- when we request StepOut at return position - we mark current function as needed-to-be-ignored inside of PrepareStepIn(function) call,
- when we request StepOut at not return position - we set break at return position and ask debugger to just repeat last step action on next stepping-related break.
Design doc: https://docs.google.com/document/d/1ihXHOIhP_q-fJCA0e2EiXz_Zr3B08KMjaPifcaqZ60Q/edit
BUG=v8:6118,chromium:583193
R=dgozman@chromium.org,yangguo@chromium.org
Review-Url: https://codereview.chromium.org/2758483002
Cr-Commit-Position: refs/heads/master@{#44028}
2017-03-22 14:16:18 +00:00
|
|
|
}
|
2017-04-24 13:21:50 +00:00
|
|
|
|
|
|
|
TEST(DebugEvaluateNoSideEffect) {
|
|
|
|
LocalContext env;
|
2018-02-07 17:09:19 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
EnableDebugger(env->GetIsolate());
|
2017-04-24 13:21:50 +00:00
|
|
|
i::Isolate* isolate = CcTest::i_isolate();
|
2017-09-28 09:28:16 +00:00
|
|
|
std::vector<i::Handle<i::JSFunction>> all_functions;
|
2017-04-24 13:21:50 +00:00
|
|
|
{
|
2019-06-13 10:51:22 +00:00
|
|
|
i::HeapObjectIterator iterator(isolate->heap());
|
2019-05-31 10:59:12 +00:00
|
|
|
for (i::HeapObject obj = iterator.Next(); !obj.is_null();
|
|
|
|
obj = iterator.Next()) {
|
2017-04-24 13:21:50 +00:00
|
|
|
if (!obj.IsJSFunction()) continue;
|
2018-12-08 02:59:17 +00:00
|
|
|
i::JSFunction fun = i::JSFunction::cast(obj);
|
2018-06-26 10:14:12 +00:00
|
|
|
all_functions.emplace_back(fun, isolate);
|
2017-04-24 13:21:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Perform side effect check on all built-in functions. The side effect check
|
|
|
|
// itself contains additional sanity checks.
|
2017-09-28 09:28:16 +00:00
|
|
|
for (i::Handle<i::JSFunction> fun : all_functions) {
|
2017-04-24 13:21:50 +00:00
|
|
|
bool failed = false;
|
2018-04-05 02:01:34 +00:00
|
|
|
isolate->debug()->StartSideEffectCheckMode();
|
2018-04-11 06:03:52 +00:00
|
|
|
failed = !isolate->debug()->PerformSideEffectCheck(
|
|
|
|
fun, v8::Utils::OpenHandle(*env->Global()));
|
2018-04-05 02:01:34 +00:00
|
|
|
isolate->debug()->StopSideEffectCheckMode();
|
2017-04-24 13:21:50 +00:00
|
|
|
if (failed) isolate->clear_pending_exception();
|
|
|
|
}
|
2018-02-07 17:09:19 +00:00
|
|
|
DisableDebugger(env->GetIsolate());
|
2017-04-24 13:21:50 +00:00
|
|
|
}
|
2018-07-05 20:34:14 +00:00
|
|
|
|
2022-03-22 08:21:03 +00:00
|
|
|
TEST(DebugEvaluateGlobalSharedCrossOrigin) {
|
2022-03-21 13:31:57 +00:00
|
|
|
LocalContext env;
|
2022-03-22 08:21:03 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
v8::TryCatch tryCatch(isolate);
|
2022-03-21 13:31:57 +00:00
|
|
|
tryCatch.SetCaptureMessage(true);
|
2022-03-22 08:21:03 +00:00
|
|
|
v8::MaybeLocal<v8::Value> result =
|
|
|
|
v8::debug::EvaluateGlobal(isolate, v8_str(isolate, "throw new Error()"),
|
|
|
|
v8::debug::EvaluateGlobalMode::kDefault);
|
|
|
|
CHECK(result.IsEmpty());
|
2022-03-21 13:31:57 +00:00
|
|
|
CHECK(tryCatch.HasCaught());
|
|
|
|
CHECK(tryCatch.Message()->IsSharedCrossOrigin());
|
|
|
|
}
|
|
|
|
|
2022-03-22 08:21:03 +00:00
|
|
|
TEST(DebugEvaluateLocalSharedCrossOrigin) {
|
|
|
|
struct BreakProgramDelegate : public v8::debug::DebugDelegate {
|
|
|
|
void BreakProgramRequested(v8::Local<v8::Context> context,
|
|
|
|
std::vector<v8::debug::BreakpointId> const&,
|
|
|
|
v8::debug::BreakReasons) final {
|
|
|
|
v8::Isolate* isolate = context->GetIsolate();
|
|
|
|
v8::TryCatch tryCatch(isolate);
|
|
|
|
tryCatch.SetCaptureMessage(true);
|
|
|
|
std::unique_ptr<v8::debug::StackTraceIterator> it =
|
|
|
|
v8::debug::StackTraceIterator::Create(isolate);
|
|
|
|
v8::MaybeLocal<v8::Value> result =
|
|
|
|
it->Evaluate(v8_str(isolate, "throw new Error()"), false);
|
|
|
|
CHECK(result.IsEmpty());
|
|
|
|
CHECK(tryCatch.HasCaught());
|
|
|
|
CHECK(tryCatch.Message()->IsSharedCrossOrigin());
|
|
|
|
}
|
|
|
|
} delegate;
|
|
|
|
LocalContext env;
|
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
v8::debug::SetDebugDelegate(isolate, &delegate);
|
|
|
|
v8::Script::Compile(env.local(), v8_str(isolate, "debugger;"))
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Run(env.local())
|
|
|
|
.ToLocalChecked();
|
|
|
|
v8::debug::SetDebugDelegate(isolate, nullptr);
|
|
|
|
}
|
|
|
|
|
2018-07-05 20:34:14 +00:00
|
|
|
namespace {
|
|
|
|
i::MaybeHandle<i::Script> FindScript(
|
|
|
|
i::Isolate* isolate, const std::vector<i::Handle<i::Script>>& scripts,
|
|
|
|
const char* name) {
|
|
|
|
Handle<i::String> i_name =
|
|
|
|
isolate->factory()->NewStringFromAsciiChecked(name);
|
|
|
|
for (const auto& script : scripts) {
|
|
|
|
if (!script->name().IsString()) continue;
|
|
|
|
if (i_name->Equals(i::String::cast(script->name()))) return script;
|
|
|
|
}
|
|
|
|
return i::MaybeHandle<i::Script>();
|
|
|
|
}
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
UNINITIALIZED_TEST(LoadedAtStartupScripts) {
|
2022-09-15 11:04:11 +00:00
|
|
|
i::v8_flags.expose_gc = true;
|
2018-07-05 20:34:14 +00:00
|
|
|
|
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
|
|
|
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
{
|
|
|
|
v8::Isolate::Scope i_scope(isolate);
|
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
LocalContext context(isolate);
|
|
|
|
|
|
|
|
std::vector<i::Handle<i::Script>> scripts;
|
2020-11-24 14:07:00 +00:00
|
|
|
CompileWithOrigin(v8_str("function foo(){}"), v8_str("normal.js"), false);
|
2018-07-05 20:34:14 +00:00
|
|
|
std::unordered_map<int, int> count_by_type;
|
|
|
|
{
|
2020-11-20 16:57:36 +00:00
|
|
|
i::DisallowGarbageCollection no_gc;
|
2018-07-05 20:34:14 +00:00
|
|
|
i::Script::Iterator iterator(i_isolate);
|
2018-12-17 12:49:34 +00:00
|
|
|
for (i::Script script = iterator.Next(); !script.is_null();
|
|
|
|
script = iterator.Next()) {
|
2018-07-05 20:34:14 +00:00
|
|
|
if (script.type() == i::Script::TYPE_NATIVE &&
|
|
|
|
script.name().IsUndefined(i_isolate)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
++count_by_type[script.type()];
|
|
|
|
scripts.emplace_back(script, i_isolate);
|
|
|
|
}
|
|
|
|
}
|
2019-01-07 05:08:08 +00:00
|
|
|
CHECK_EQ(count_by_type[i::Script::TYPE_NATIVE], 0);
|
2019-10-02 07:28:07 +00:00
|
|
|
CHECK_EQ(count_by_type[i::Script::TYPE_EXTENSION], 1);
|
2018-07-05 20:34:14 +00:00
|
|
|
CHECK_EQ(count_by_type[i::Script::TYPE_NORMAL], 1);
|
2021-03-15 13:28:34 +00:00
|
|
|
#if V8_ENABLE_WEBASSEMBLY
|
2018-07-05 20:34:14 +00:00
|
|
|
CHECK_EQ(count_by_type[i::Script::TYPE_WASM], 0);
|
2021-03-15 13:28:34 +00:00
|
|
|
#endif // V8_ENABLE_WEBASSEMBLY
|
2018-07-05 20:34:14 +00:00
|
|
|
CHECK_EQ(count_by_type[i::Script::TYPE_INSPECTOR], 0);
|
|
|
|
|
|
|
|
i::Handle<i::Script> gc_script =
|
|
|
|
FindScript(i_isolate, scripts, "v8/gc").ToHandleChecked();
|
|
|
|
CHECK_EQ(gc_script->type(), i::Script::TYPE_EXTENSION);
|
|
|
|
|
|
|
|
i::Handle<i::Script> normal_script =
|
|
|
|
FindScript(i_isolate, scripts, "normal.js").ToHandleChecked();
|
|
|
|
CHECK_EQ(normal_script->type(), i::Script::TYPE_NORMAL);
|
|
|
|
}
|
|
|
|
isolate->Dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SourceInfo) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
const char* source =
|
|
|
|
"//\n"
|
|
|
|
"function a() { b(); };\n"
|
|
|
|
"function b() {\n"
|
|
|
|
" c(true);\n"
|
|
|
|
"};\n"
|
|
|
|
" function c(x) {\n"
|
|
|
|
" if (x) {\n"
|
|
|
|
" return 1;\n"
|
|
|
|
" } else {\n"
|
|
|
|
" return 1;\n"
|
|
|
|
" }\n"
|
|
|
|
" };\n"
|
|
|
|
"function d(x) {\n"
|
|
|
|
" x = 1 ;\n"
|
|
|
|
" x = 2 ;\n"
|
|
|
|
" x = 3 ;\n"
|
|
|
|
" x = 4 ;\n"
|
|
|
|
" x = 5 ;\n"
|
|
|
|
" x = 6 ;\n"
|
|
|
|
" x = 7 ;\n"
|
|
|
|
" x = 8 ;\n"
|
|
|
|
" x = 9 ;\n"
|
|
|
|
" x = 10;\n"
|
|
|
|
" x = 11;\n"
|
|
|
|
" x = 12;\n"
|
|
|
|
" x = 13;\n"
|
|
|
|
" x = 14;\n"
|
|
|
|
" x = 15;\n"
|
|
|
|
"}\n";
|
|
|
|
v8::Local<v8::Script> v8_script =
|
|
|
|
v8::Script::Compile(env.local(), v8_str(source)).ToLocalChecked();
|
|
|
|
i::Handle<i::Script> i_script(
|
|
|
|
i::Script::cast(v8::Utils::OpenHandle(*v8_script)->shared().script()),
|
|
|
|
CcTest::i_isolate());
|
|
|
|
v8::Local<v8::debug::Script> script =
|
|
|
|
v8::ToApiHandle<v8::debug::Script>(i_script);
|
|
|
|
|
|
|
|
// Test that when running through source positions the position, line and
|
|
|
|
// column progresses as expected.
|
|
|
|
v8::debug::Location prev_location = script->GetSourceLocation(0);
|
|
|
|
CHECK_EQ(prev_location.GetLineNumber(), 0);
|
|
|
|
CHECK_EQ(prev_location.GetColumnNumber(), 0);
|
|
|
|
for (int offset = 1; offset < 100; ++offset) {
|
|
|
|
v8::debug::Location location = script->GetSourceLocation(offset);
|
|
|
|
if (prev_location.GetLineNumber() == location.GetLineNumber()) {
|
|
|
|
CHECK_EQ(location.GetColumnNumber(), prev_location.GetColumnNumber() + 1);
|
|
|
|
} else {
|
|
|
|
CHECK_EQ(location.GetLineNumber(), prev_location.GetLineNumber() + 1);
|
|
|
|
CHECK_EQ(location.GetColumnNumber(), 0);
|
|
|
|
}
|
|
|
|
prev_location = location;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Every line of d() is the same length. Verify we can loop through all
|
|
|
|
// positions and find the right line # for each.
|
|
|
|
// The position of the first line of d(), i.e. "x = 1 ;".
|
|
|
|
const int start_line_d = 13;
|
|
|
|
const int start_code_d =
|
|
|
|
static_cast<int>(strstr(source, " x = 1 ;") - source);
|
|
|
|
const int num_lines_d = 15;
|
|
|
|
const int line_length_d = 10;
|
|
|
|
int p = start_code_d;
|
|
|
|
for (int line = 0; line < num_lines_d; ++line) {
|
|
|
|
for (int column = 0; column < line_length_d; ++column) {
|
|
|
|
v8::debug::Location location = script->GetSourceLocation(p);
|
|
|
|
CHECK_EQ(location.GetLineNumber(), start_line_d + line);
|
|
|
|
CHECK_EQ(location.GetColumnNumber(), column);
|
|
|
|
++p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-27 15:26:16 +00:00
|
|
|
// Test first position.
|
2018-07-05 20:34:14 +00:00
|
|
|
CHECK_EQ(script->GetSourceLocation(0).GetLineNumber(), 0);
|
|
|
|
CHECK_EQ(script->GetSourceLocation(0).GetColumnNumber(), 0);
|
|
|
|
|
2022-05-27 15:26:16 +00:00
|
|
|
// Test second position.
|
2018-07-05 20:34:14 +00:00
|
|
|
CHECK_EQ(script->GetSourceLocation(1).GetLineNumber(), 0);
|
|
|
|
CHECK_EQ(script->GetSourceLocation(1).GetColumnNumber(), 1);
|
|
|
|
|
2022-05-27 15:26:16 +00:00
|
|
|
// Test first position in function a().
|
2018-07-05 20:34:14 +00:00
|
|
|
const int start_a =
|
|
|
|
static_cast<int>(strstr(source, "function a") - source) + 10;
|
|
|
|
CHECK_EQ(script->GetSourceLocation(start_a).GetLineNumber(), 1);
|
|
|
|
CHECK_EQ(script->GetSourceLocation(start_a).GetColumnNumber(), 10);
|
|
|
|
|
2022-05-27 15:26:16 +00:00
|
|
|
// Test first position in function b().
|
2018-07-05 20:34:14 +00:00
|
|
|
const int start_b =
|
|
|
|
static_cast<int>(strstr(source, "function b") - source) + 13;
|
|
|
|
CHECK_EQ(script->GetSourceLocation(start_b).GetLineNumber(), 2);
|
|
|
|
CHECK_EQ(script->GetSourceLocation(start_b).GetColumnNumber(), 13);
|
|
|
|
|
2022-05-27 15:26:16 +00:00
|
|
|
// Test first position in function c().
|
2018-07-05 20:34:14 +00:00
|
|
|
const int start_c =
|
|
|
|
static_cast<int>(strstr(source, "function c") - source) + 10;
|
|
|
|
CHECK_EQ(script->GetSourceLocation(start_c).GetLineNumber(), 5);
|
|
|
|
CHECK_EQ(script->GetSourceLocation(start_c).GetColumnNumber(), 12);
|
|
|
|
|
2022-05-27 15:26:16 +00:00
|
|
|
// Test first position in function d().
|
2018-07-05 20:34:14 +00:00
|
|
|
const int start_d =
|
|
|
|
static_cast<int>(strstr(source, "function d") - source) + 10;
|
|
|
|
CHECK_EQ(script->GetSourceLocation(start_d).GetLineNumber(), 12);
|
|
|
|
CHECK_EQ(script->GetSourceLocation(start_d).GetColumnNumber(), 10);
|
|
|
|
|
|
|
|
// Test offsets.
|
2022-04-29 11:07:01 +00:00
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(1, 10)),
|
|
|
|
v8::Just(start_a));
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(2, 13)),
|
|
|
|
v8::Just(start_b));
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(3, 0)),
|
|
|
|
v8::Just(start_b + 5));
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(3, 2)),
|
|
|
|
v8::Just(start_b + 7));
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(4, 0)),
|
|
|
|
v8::Just(start_b + 16));
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(5, 12)),
|
|
|
|
v8::Just(start_c));
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(6, 0)),
|
|
|
|
v8::Just(start_c + 6));
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(7, 0)),
|
|
|
|
v8::Just(start_c + 19));
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(8, 0)),
|
|
|
|
v8::Just(start_c + 35));
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(9, 0)),
|
|
|
|
v8::Just(start_c + 48));
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(10, 0)),
|
|
|
|
v8::Just(start_c + 64));
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(11, 0)),
|
|
|
|
v8::Just(start_c + 70));
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(12, 10)),
|
|
|
|
v8::Just(start_d));
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(13, 0)),
|
|
|
|
v8::Just(start_d + 6));
|
2018-07-05 20:34:14 +00:00
|
|
|
for (int i = 1; i <= num_lines_d; ++i) {
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(start_line_d + i, 0)),
|
2022-04-29 11:07:01 +00:00
|
|
|
v8::Just(6 + (i * line_length_d) + start_d));
|
2018-07-05 20:34:14 +00:00
|
|
|
}
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(start_line_d + 17, 0)),
|
2022-04-29 11:07:01 +00:00
|
|
|
v8::Nothing<int>());
|
2018-07-05 20:34:14 +00:00
|
|
|
|
|
|
|
// Make sure invalid inputs work properly.
|
|
|
|
const int last_position = static_cast<int>(strlen(source)) - 1;
|
|
|
|
CHECK_EQ(script->GetSourceLocation(-1).GetLineNumber(), 0);
|
|
|
|
CHECK_EQ(script->GetSourceLocation(last_position + 2).GetLineNumber(),
|
|
|
|
i::kNoSourcePosition);
|
|
|
|
|
|
|
|
// Test last position.
|
|
|
|
CHECK_EQ(script->GetSourceLocation(last_position).GetLineNumber(), 28);
|
|
|
|
CHECK_EQ(script->GetSourceLocation(last_position).GetColumnNumber(), 1);
|
|
|
|
CHECK_EQ(script->GetSourceLocation(last_position + 1).GetLineNumber(), 29);
|
|
|
|
CHECK_EQ(script->GetSourceLocation(last_position + 1).GetColumnNumber(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class SetBreakpointOnScriptCompiled : public v8::debug::DebugDelegate {
|
|
|
|
public:
|
|
|
|
void ScriptCompiled(v8::Local<v8::debug::Script> script, bool is_live_edited,
|
|
|
|
bool has_compile_error) override {
|
|
|
|
v8::Local<v8::String> name;
|
|
|
|
if (!script->SourceURL().ToLocal(&name)) return;
|
|
|
|
v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext();
|
|
|
|
if (!name->Equals(context, v8_str("test")).FromJust()) return;
|
|
|
|
CHECK(!has_compile_error);
|
|
|
|
v8::debug::Location loc(1, 2);
|
|
|
|
CHECK(script->SetBreakpoint(v8_str(""), &loc, &id_));
|
|
|
|
CHECK_EQ(loc.GetLineNumber(), 1);
|
|
|
|
CHECK_EQ(loc.GetColumnNumber(), 10);
|
|
|
|
}
|
|
|
|
|
2021-11-23 09:14:18 +00:00
|
|
|
void BreakProgramRequested(
|
|
|
|
v8::Local<v8::Context> paused_context,
|
|
|
|
const std::vector<v8::debug::BreakpointId>& inspector_break_points_hit,
|
2021-12-02 09:26:01 +00:00
|
|
|
v8::debug::BreakReasons break_reasons) override {
|
2018-07-05 20:34:14 +00:00
|
|
|
++break_count_;
|
|
|
|
CHECK_EQ(inspector_break_points_hit[0], id_);
|
|
|
|
}
|
|
|
|
|
|
|
|
int break_count() const { return break_count_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
int break_count_ = 0;
|
|
|
|
v8::debug::BreakpointId id_;
|
|
|
|
};
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
TEST(Regress517592) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope handle_scope(env->GetIsolate());
|
|
|
|
SetBreakpointOnScriptCompiled delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
|
|
|
CompileRun(
|
|
|
|
v8_str("eval('var foo = function foo() {\\n' +\n"
|
|
|
|
"' var a = 1;\\n' +\n"
|
|
|
|
"'}\\n' +\n"
|
|
|
|
"'//@ sourceURL=test')"));
|
|
|
|
CHECK_EQ(delegate.break_count(), 0);
|
|
|
|
CompileRun(v8_str("foo()"));
|
|
|
|
CHECK_EQ(delegate.break_count(), 1);
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
|
|
|
}
|
2019-02-26 22:09:31 +00:00
|
|
|
|
2019-12-04 19:02:02 +00:00
|
|
|
namespace {
|
|
|
|
std::string FromString(v8::Isolate* isolate, v8::Local<v8::String> str) {
|
|
|
|
v8::String::Utf8Value utf8(isolate, str);
|
|
|
|
return std::string(*utf8);
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2019-02-26 22:09:31 +00:00
|
|
|
TEST(GetPrivateFields) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::Isolate* v8_isolate = CcTest::isolate();
|
|
|
|
v8::HandleScope scope(v8_isolate);
|
|
|
|
v8::Local<v8::Context> context = env.local();
|
|
|
|
v8::Local<v8::String> source = v8_str(
|
|
|
|
"var X = class {\n"
|
2019-12-04 19:02:02 +00:00
|
|
|
" #field_number = 1;\n"
|
|
|
|
" #field_function = function() {};\n"
|
2019-02-26 22:09:31 +00:00
|
|
|
"}\n"
|
|
|
|
"var x = new X()");
|
|
|
|
CompileRun(source);
|
|
|
|
v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(
|
|
|
|
env->Global()
|
|
|
|
->Get(context, v8_str(env->GetIsolate(), "x"))
|
|
|
|
.ToLocalChecked());
|
2019-12-04 19:02:02 +00:00
|
|
|
std::vector<v8::Local<v8::Value>> names;
|
|
|
|
std::vector<v8::Local<v8::Value>> values;
|
|
|
|
CHECK(v8::debug::GetPrivateMembers(context, object, &names, &values));
|
|
|
|
|
|
|
|
CHECK_EQ(names.size(), 2);
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
v8::Local<v8::Value> name = names[i];
|
|
|
|
v8::Local<v8::Value> value = values[i];
|
|
|
|
CHECK(name->IsString());
|
|
|
|
std::string name_str = FromString(v8_isolate, name.As<v8::String>());
|
|
|
|
if (name_str == "#field_number") {
|
|
|
|
CHECK(value->Equals(context, v8_num(1)).FromJust());
|
|
|
|
} else {
|
|
|
|
CHECK_EQ(name_str, "#field_function");
|
|
|
|
CHECK(value->IsFunction());
|
|
|
|
}
|
2019-02-26 22:09:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
source = v8_str(
|
|
|
|
"var Y = class {\n"
|
2019-12-04 19:02:02 +00:00
|
|
|
" #base_field_number = 2;\n"
|
2019-02-26 22:09:31 +00:00
|
|
|
"}\n"
|
|
|
|
"var X = class extends Y{\n"
|
2019-12-04 19:02:02 +00:00
|
|
|
" #field_number = 1;\n"
|
|
|
|
" #field_function = function() {};\n"
|
2019-02-26 22:09:31 +00:00
|
|
|
"}\n"
|
|
|
|
"var x = new X()");
|
|
|
|
CompileRun(source);
|
2019-12-04 19:02:02 +00:00
|
|
|
names.clear();
|
|
|
|
values.clear();
|
2019-02-26 22:09:31 +00:00
|
|
|
object = v8::Local<v8::Object>::Cast(
|
|
|
|
env->Global()
|
|
|
|
->Get(context, v8_str(env->GetIsolate(), "x"))
|
|
|
|
.ToLocalChecked());
|
2019-12-04 19:02:02 +00:00
|
|
|
CHECK(v8::debug::GetPrivateMembers(context, object, &names, &values));
|
|
|
|
|
|
|
|
CHECK_EQ(names.size(), 3);
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
v8::Local<v8::Value> name = names[i];
|
|
|
|
v8::Local<v8::Value> value = values[i];
|
|
|
|
std::string name_str = FromString(v8_isolate, name.As<v8::String>());
|
|
|
|
if (name_str == "#base_field_number") {
|
|
|
|
CHECK(value->Equals(context, v8_num(2)).FromJust());
|
|
|
|
} else if (name_str == "#field_number") {
|
|
|
|
CHECK(value->Equals(context, v8_num(1)).FromJust());
|
|
|
|
} else {
|
|
|
|
CHECK_EQ(name_str, "#field_function");
|
|
|
|
CHECK(value->IsFunction());
|
|
|
|
}
|
2019-02-26 22:09:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
source = v8_str(
|
|
|
|
"var Y = class {\n"
|
|
|
|
" constructor() {"
|
|
|
|
" return new Proxy({}, {});"
|
|
|
|
" }"
|
|
|
|
"}\n"
|
|
|
|
"var X = class extends Y{\n"
|
2019-12-04 19:02:02 +00:00
|
|
|
" #field_number = 1;\n"
|
|
|
|
" #field_function = function() {};\n"
|
2019-02-26 22:09:31 +00:00
|
|
|
"}\n"
|
|
|
|
"var x = new X()");
|
|
|
|
CompileRun(source);
|
2019-12-04 19:02:02 +00:00
|
|
|
names.clear();
|
|
|
|
values.clear();
|
2019-02-26 22:09:31 +00:00
|
|
|
object = v8::Local<v8::Object>::Cast(
|
|
|
|
env->Global()
|
|
|
|
->Get(context, v8_str(env->GetIsolate(), "x"))
|
|
|
|
.ToLocalChecked());
|
2019-12-04 19:02:02 +00:00
|
|
|
CHECK(v8::debug::GetPrivateMembers(context, object, &names, &values));
|
|
|
|
|
|
|
|
CHECK_EQ(names.size(), 2);
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
v8::Local<v8::Value> name = names[i];
|
|
|
|
v8::Local<v8::Value> value = values[i];
|
|
|
|
CHECK(name->IsString());
|
|
|
|
std::string name_str = FromString(v8_isolate, name.As<v8::String>());
|
|
|
|
if (name_str == "#field_number") {
|
|
|
|
CHECK(value->Equals(context, v8_num(1)).FromJust());
|
|
|
|
} else {
|
|
|
|
CHECK_EQ(name_str, "#field_function");
|
|
|
|
CHECK(value->IsFunction());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(GetPrivateMethodsAndAccessors) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::Isolate* v8_isolate = CcTest::isolate();
|
|
|
|
v8::HandleScope scope(v8_isolate);
|
|
|
|
v8::Local<v8::Context> context = env.local();
|
|
|
|
|
|
|
|
v8::Local<v8::String> source = v8_str(
|
|
|
|
"var X = class {\n"
|
|
|
|
" #method() { }\n"
|
|
|
|
" get #accessor() { }\n"
|
|
|
|
" set #accessor(val) { }\n"
|
|
|
|
" get #readOnly() { }\n"
|
|
|
|
" set #writeOnly(val) { }\n"
|
|
|
|
"}\n"
|
|
|
|
"var x = new X()");
|
|
|
|
CompileRun(source);
|
|
|
|
v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(
|
|
|
|
env->Global()
|
|
|
|
->Get(context, v8_str(env->GetIsolate(), "x"))
|
|
|
|
.ToLocalChecked());
|
|
|
|
std::vector<v8::Local<v8::Value>> names;
|
|
|
|
std::vector<v8::Local<v8::Value>> values;
|
|
|
|
CHECK(v8::debug::GetPrivateMembers(context, object, &names, &values));
|
|
|
|
|
|
|
|
CHECK_EQ(names.size(), 4);
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
v8::Local<v8::Value> name = names[i];
|
|
|
|
v8::Local<v8::Value> value = values[i];
|
|
|
|
CHECK(name->IsString());
|
|
|
|
std::string name_str = FromString(v8_isolate, name.As<v8::String>());
|
|
|
|
if (name_str == "#method") {
|
|
|
|
CHECK(value->IsFunction());
|
|
|
|
} else {
|
|
|
|
CHECK(v8::debug::AccessorPair::IsAccessorPair(value));
|
|
|
|
v8::Local<v8::debug::AccessorPair> accessors =
|
|
|
|
value.As<v8::debug::AccessorPair>();
|
|
|
|
if (name_str == "#accessor") {
|
|
|
|
CHECK(accessors->getter()->IsFunction());
|
|
|
|
CHECK(accessors->setter()->IsFunction());
|
|
|
|
} else if (name_str == "#readOnly") {
|
|
|
|
CHECK(accessors->getter()->IsFunction());
|
|
|
|
CHECK(accessors->setter()->IsNull());
|
|
|
|
} else {
|
|
|
|
CHECK_EQ(name_str, "#writeOnly");
|
|
|
|
CHECK(accessors->getter()->IsNull());
|
|
|
|
CHECK(accessors->setter()->IsFunction());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
source = v8_str(
|
|
|
|
"var Y = class {\n"
|
|
|
|
" #method() {}\n"
|
|
|
|
" get #accessor() {}\n"
|
|
|
|
" set #accessor(val) {};\n"
|
|
|
|
"}\n"
|
|
|
|
"var X = class extends Y{\n"
|
|
|
|
" get #readOnly() {}\n"
|
|
|
|
" set #writeOnly(val) {};\n"
|
|
|
|
"}\n"
|
|
|
|
"var x = new X()");
|
|
|
|
CompileRun(source);
|
|
|
|
names.clear();
|
|
|
|
values.clear();
|
|
|
|
object = v8::Local<v8::Object>::Cast(
|
|
|
|
env->Global()
|
|
|
|
->Get(context, v8_str(env->GetIsolate(), "x"))
|
|
|
|
.ToLocalChecked());
|
|
|
|
CHECK(v8::debug::GetPrivateMembers(context, object, &names, &values));
|
|
|
|
|
|
|
|
CHECK_EQ(names.size(), 4);
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
v8::Local<v8::Value> name = names[i];
|
|
|
|
v8::Local<v8::Value> value = values[i];
|
|
|
|
CHECK(name->IsString());
|
|
|
|
std::string name_str = FromString(v8_isolate, name.As<v8::String>());
|
|
|
|
if (name_str == "#method") {
|
|
|
|
CHECK(value->IsFunction());
|
|
|
|
} else {
|
|
|
|
CHECK(v8::debug::AccessorPair::IsAccessorPair(value));
|
|
|
|
v8::Local<v8::debug::AccessorPair> accessors =
|
|
|
|
value.As<v8::debug::AccessorPair>();
|
|
|
|
if (name_str == "#accessor") {
|
|
|
|
CHECK(accessors->getter()->IsFunction());
|
|
|
|
CHECK(accessors->setter()->IsFunction());
|
|
|
|
} else if (name_str == "#readOnly") {
|
|
|
|
CHECK(accessors->getter()->IsFunction());
|
|
|
|
CHECK(accessors->setter()->IsNull());
|
|
|
|
} else {
|
|
|
|
CHECK_EQ(name_str, "#writeOnly");
|
|
|
|
CHECK(accessors->getter()->IsNull());
|
|
|
|
CHECK(accessors->setter()->IsFunction());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
source = v8_str(
|
|
|
|
"var Y = class {\n"
|
|
|
|
" constructor() {"
|
|
|
|
" return new Proxy({}, {});"
|
|
|
|
" }"
|
|
|
|
"}\n"
|
|
|
|
"var X = class extends Y{\n"
|
|
|
|
" #method() {}\n"
|
|
|
|
" get #accessor() {}\n"
|
|
|
|
" set #accessor(val) {};\n"
|
|
|
|
"}\n"
|
|
|
|
"var x = new X()");
|
|
|
|
CompileRun(source);
|
|
|
|
names.clear();
|
|
|
|
values.clear();
|
|
|
|
object = v8::Local<v8::Object>::Cast(
|
|
|
|
env->Global()
|
|
|
|
->Get(context, v8_str(env->GetIsolate(), "x"))
|
|
|
|
.ToLocalChecked());
|
|
|
|
CHECK(v8::debug::GetPrivateMembers(context, object, &names, &values));
|
|
|
|
|
|
|
|
CHECK_EQ(names.size(), 2);
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
v8::Local<v8::Value> name = names[i];
|
|
|
|
v8::Local<v8::Value> value = values[i];
|
|
|
|
CHECK(name->IsString());
|
|
|
|
std::string name_str = FromString(v8_isolate, name.As<v8::String>());
|
|
|
|
if (name_str == "#method") {
|
|
|
|
CHECK(value->IsFunction());
|
|
|
|
} else {
|
|
|
|
CHECK_EQ(name_str, "#accessor");
|
|
|
|
CHECK(v8::debug::AccessorPair::IsAccessorPair(value));
|
|
|
|
v8::Local<v8::debug::AccessorPair> accessors =
|
|
|
|
value.As<v8::debug::AccessorPair>();
|
|
|
|
CHECK(accessors->getter()->IsFunction());
|
|
|
|
CHECK(accessors->setter()->IsFunction());
|
|
|
|
}
|
2019-02-26 22:09:31 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-03 13:45:06 +00:00
|
|
|
|
2020-03-06 14:44:50 +00:00
|
|
|
TEST(GetPrivateStaticMethodsAndAccessors) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::Isolate* v8_isolate = CcTest::isolate();
|
|
|
|
v8::HandleScope scope(v8_isolate);
|
|
|
|
v8::Local<v8::Context> context = env.local();
|
|
|
|
|
|
|
|
v8::Local<v8::String> source = v8_str(
|
|
|
|
"var X = class {\n"
|
|
|
|
" static #staticMethod() { }\n"
|
|
|
|
" static get #staticAccessor() { }\n"
|
|
|
|
" static set #staticAccessor(val) { }\n"
|
|
|
|
" static get #staticReadOnly() { }\n"
|
|
|
|
" static set #staticWriteOnly(val) { }\n"
|
|
|
|
"}\n");
|
|
|
|
CompileRun(source);
|
|
|
|
v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(
|
|
|
|
env->Global()
|
|
|
|
->Get(context, v8_str(env->GetIsolate(), "X"))
|
|
|
|
.ToLocalChecked());
|
|
|
|
std::vector<v8::Local<v8::Value>> names;
|
|
|
|
std::vector<v8::Local<v8::Value>> values;
|
|
|
|
CHECK(v8::debug::GetPrivateMembers(context, object, &names, &values));
|
|
|
|
|
|
|
|
CHECK_EQ(names.size(), 4);
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
v8::Local<v8::Value> name = names[i];
|
|
|
|
v8::Local<v8::Value> value = values[i];
|
|
|
|
CHECK(name->IsString());
|
|
|
|
std::string name_str = FromString(v8_isolate, name.As<v8::String>());
|
|
|
|
if (name_str == "#staticMethod") {
|
|
|
|
CHECK(value->IsFunction());
|
|
|
|
} else {
|
|
|
|
CHECK(v8::debug::AccessorPair::IsAccessorPair(value));
|
|
|
|
v8::Local<v8::debug::AccessorPair> accessors =
|
|
|
|
value.As<v8::debug::AccessorPair>();
|
|
|
|
if (name_str == "#staticAccessor") {
|
|
|
|
CHECK(accessors->getter()->IsFunction());
|
|
|
|
CHECK(accessors->setter()->IsFunction());
|
|
|
|
} else if (name_str == "#staticReadOnly") {
|
|
|
|
CHECK(accessors->getter()->IsFunction());
|
|
|
|
CHECK(accessors->setter()->IsNull());
|
|
|
|
} else {
|
|
|
|
CHECK_EQ(name_str, "#staticWriteOnly");
|
|
|
|
CHECK(accessors->getter()->IsNull());
|
|
|
|
CHECK(accessors->setter()->IsFunction());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(GetPrivateStaticAndInstanceMethodsAndAccessors) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::Isolate* v8_isolate = CcTest::isolate();
|
|
|
|
v8::HandleScope scope(v8_isolate);
|
|
|
|
v8::Local<v8::Context> context = env.local();
|
|
|
|
|
|
|
|
v8::Local<v8::String> source = v8_str(
|
|
|
|
"var X = class {\n"
|
|
|
|
" static #staticMethod() { }\n"
|
|
|
|
" static get #staticAccessor() { }\n"
|
|
|
|
" static set #staticAccessor(val) { }\n"
|
|
|
|
" static get #staticReadOnly() { }\n"
|
|
|
|
" static set #staticWriteOnly(val) { }\n"
|
|
|
|
" #method() { }\n"
|
|
|
|
" get #accessor() { }\n"
|
|
|
|
" set #accessor(val) { }\n"
|
|
|
|
" get #readOnly() { }\n"
|
|
|
|
" set #writeOnly(val) { }\n"
|
|
|
|
"}\n"
|
|
|
|
"var x = new X()\n");
|
|
|
|
CompileRun(source);
|
|
|
|
v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(
|
|
|
|
env->Global()
|
|
|
|
->Get(context, v8_str(env->GetIsolate(), "X"))
|
|
|
|
.ToLocalChecked());
|
|
|
|
std::vector<v8::Local<v8::Value>> names;
|
|
|
|
std::vector<v8::Local<v8::Value>> values;
|
|
|
|
CHECK(v8::debug::GetPrivateMembers(context, object, &names, &values));
|
|
|
|
|
|
|
|
CHECK_EQ(names.size(), 4);
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
v8::Local<v8::Value> name = names[i];
|
|
|
|
v8::Local<v8::Value> value = values[i];
|
|
|
|
CHECK(name->IsString());
|
|
|
|
std::string name_str = FromString(v8_isolate, name.As<v8::String>());
|
|
|
|
if (name_str == "#staticMethod") {
|
|
|
|
CHECK(value->IsFunction());
|
|
|
|
} else {
|
|
|
|
CHECK(v8::debug::AccessorPair::IsAccessorPair(value));
|
|
|
|
v8::Local<v8::debug::AccessorPair> accessors =
|
|
|
|
value.As<v8::debug::AccessorPair>();
|
|
|
|
if (name_str == "#staticAccessor") {
|
|
|
|
CHECK(accessors->getter()->IsFunction());
|
|
|
|
CHECK(accessors->setter()->IsFunction());
|
|
|
|
} else if (name_str == "#staticReadOnly") {
|
|
|
|
CHECK(accessors->getter()->IsFunction());
|
|
|
|
CHECK(accessors->setter()->IsNull());
|
|
|
|
} else {
|
|
|
|
CHECK_EQ(name_str, "#staticWriteOnly");
|
|
|
|
CHECK(accessors->getter()->IsNull());
|
|
|
|
CHECK(accessors->setter()->IsFunction());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
names.clear();
|
|
|
|
values.clear();
|
|
|
|
object = v8::Local<v8::Object>::Cast(
|
|
|
|
env->Global()
|
|
|
|
->Get(context, v8_str(env->GetIsolate(), "x"))
|
|
|
|
.ToLocalChecked());
|
|
|
|
CHECK(v8::debug::GetPrivateMembers(context, object, &names, &values));
|
|
|
|
|
|
|
|
CHECK_EQ(names.size(), 4);
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
v8::Local<v8::Value> name = names[i];
|
|
|
|
v8::Local<v8::Value> value = values[i];
|
|
|
|
CHECK(name->IsString());
|
|
|
|
std::string name_str = FromString(v8_isolate, name.As<v8::String>());
|
|
|
|
if (name_str == "#method") {
|
|
|
|
CHECK(value->IsFunction());
|
|
|
|
} else {
|
|
|
|
CHECK(v8::debug::AccessorPair::IsAccessorPair(value));
|
|
|
|
v8::Local<v8::debug::AccessorPair> accessors =
|
|
|
|
value.As<v8::debug::AccessorPair>();
|
|
|
|
if (name_str == "#accessor") {
|
|
|
|
CHECK(accessors->getter()->IsFunction());
|
|
|
|
CHECK(accessors->setter()->IsFunction());
|
|
|
|
} else if (name_str == "#readOnly") {
|
|
|
|
CHECK(accessors->getter()->IsFunction());
|
|
|
|
CHECK(accessors->setter()->IsNull());
|
|
|
|
} else {
|
|
|
|
CHECK_EQ(name_str, "#writeOnly");
|
|
|
|
CHECK(accessors->getter()->IsNull());
|
|
|
|
CHECK(accessors->setter()->IsFunction());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-03 13:45:06 +00:00
|
|
|
namespace {
|
|
|
|
class SetTerminateOnResumeDelegate : public v8::debug::DebugDelegate {
|
|
|
|
public:
|
|
|
|
enum Options {
|
|
|
|
kNone,
|
|
|
|
kPerformMicrotaskCheckpointAtBreakpoint,
|
|
|
|
kRunJavaScriptAtBreakpoint
|
|
|
|
};
|
|
|
|
explicit SetTerminateOnResumeDelegate(Options options = kNone)
|
|
|
|
: options_(options) {}
|
2021-11-23 09:14:18 +00:00
|
|
|
void BreakProgramRequested(
|
|
|
|
v8::Local<v8::Context> paused_context,
|
|
|
|
const std::vector<v8::debug::BreakpointId>& inspector_break_points_hit,
|
2021-12-02 09:26:01 +00:00
|
|
|
v8::debug::BreakReasons break_reasons) override {
|
2020-02-03 13:45:06 +00:00
|
|
|
break_count_++;
|
|
|
|
v8::Isolate* isolate = paused_context->GetIsolate();
|
|
|
|
v8::debug::SetTerminateOnResume(isolate);
|
|
|
|
if (options_ == kPerformMicrotaskCheckpointAtBreakpoint) {
|
|
|
|
v8::MicrotasksScope::PerformCheckpoint(isolate);
|
|
|
|
}
|
|
|
|
if (options_ == kRunJavaScriptAtBreakpoint) {
|
|
|
|
CompileRun("globalVariable = globalVariable + 1");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExceptionThrown(v8::Local<v8::Context> paused_context,
|
|
|
|
v8::Local<v8::Value> exception,
|
|
|
|
v8::Local<v8::Value> promise, bool is_uncaught,
|
|
|
|
v8::debug::ExceptionType exception_type) override {
|
|
|
|
exception_thrown_count_++;
|
|
|
|
v8::debug::SetTerminateOnResume(paused_context->GetIsolate());
|
|
|
|
}
|
|
|
|
|
|
|
|
int break_count() const { return break_count_; }
|
|
|
|
int exception_thrown_count() const { return exception_thrown_count_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
int break_count_ = 0;
|
|
|
|
int exception_thrown_count_ = 0;
|
|
|
|
Options options_;
|
|
|
|
};
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
TEST(TerminateOnResumeAtBreakpoint) {
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
SetTerminateOnResumeDelegate delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
|
|
|
v8::Local<v8::Context> context = env.local();
|
|
|
|
{
|
|
|
|
v8::TryCatch try_catch(env->GetIsolate());
|
|
|
|
// If the delegate doesn't request termination on resume from breakpoint,
|
|
|
|
// foo diverges.
|
|
|
|
v8::Script::Compile(
|
|
|
|
context,
|
|
|
|
v8_str(env->GetIsolate(), "function foo(){debugger; while(true){}}"))
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Run(context)
|
|
|
|
.ToLocalChecked();
|
|
|
|
v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
|
|
|
|
env->Global()
|
|
|
|
->Get(context, v8_str(env->GetIsolate(), "foo"))
|
|
|
|
.ToLocalChecked());
|
|
|
|
|
|
|
|
v8::MaybeLocal<v8::Value> val =
|
|
|
|
foo->Call(context, env->Global(), 0, nullptr);
|
|
|
|
CHECK(val.IsEmpty());
|
|
|
|
CHECK(try_catch.HasTerminated());
|
|
|
|
CHECK_EQ(delegate.break_count(), 1);
|
|
|
|
}
|
|
|
|
// Exiting the TryCatch brought the isolate back to a state where JavaScript
|
|
|
|
// can be executed.
|
|
|
|
ExpectInt32("1 + 1", 2);
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
bool microtask_one_ran = false;
|
|
|
|
static void MicrotaskOne(const v8::FunctionCallbackInfo<v8::Value>& info) {
|
|
|
|
CHECK(v8::MicrotasksScope::IsRunningMicrotasks(info.GetIsolate()));
|
|
|
|
v8::HandleScope scope(info.GetIsolate());
|
2022-10-13 14:59:47 +00:00
|
|
|
v8::MicrotasksScope microtasks(info.GetIsolate()->GetCurrentContext(),
|
2020-02-03 13:45:06 +00:00
|
|
|
v8::MicrotasksScope::kDoNotRunMicrotasks);
|
|
|
|
ExpectInt32("1 + 1", 2);
|
|
|
|
microtask_one_ran = true;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TEST(TerminateOnResumeRunMicrotaskAtBreakpoint) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
SetTerminateOnResumeDelegate delegate(
|
|
|
|
SetTerminateOnResumeDelegate::kPerformMicrotaskCheckpointAtBreakpoint);
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
|
|
|
v8::Local<v8::Context> context = env.local();
|
|
|
|
{
|
|
|
|
v8::TryCatch try_catch(env->GetIsolate());
|
|
|
|
// Enqueue a microtask that gets run while we are paused at the breakpoint.
|
|
|
|
env->GetIsolate()->EnqueueMicrotask(
|
|
|
|
v8::Function::New(env.local(), MicrotaskOne).ToLocalChecked());
|
|
|
|
|
|
|
|
// If the delegate doesn't request termination on resume from breakpoint,
|
|
|
|
// foo diverges.
|
|
|
|
v8::Script::Compile(
|
|
|
|
context,
|
|
|
|
v8_str(env->GetIsolate(), "function foo(){debugger; while(true){}}"))
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Run(context)
|
|
|
|
.ToLocalChecked();
|
|
|
|
v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
|
|
|
|
env->Global()
|
|
|
|
->Get(context, v8_str(env->GetIsolate(), "foo"))
|
|
|
|
.ToLocalChecked());
|
|
|
|
|
|
|
|
v8::MaybeLocal<v8::Value> val =
|
|
|
|
foo->Call(context, env->Global(), 0, nullptr);
|
|
|
|
CHECK(val.IsEmpty());
|
|
|
|
CHECK(try_catch.HasTerminated());
|
|
|
|
CHECK_EQ(delegate.break_count(), 1);
|
|
|
|
CHECK(microtask_one_ran);
|
|
|
|
}
|
|
|
|
// Exiting the TryCatch brought the isolate back to a state where JavaScript
|
|
|
|
// can be executed.
|
|
|
|
ExpectInt32("1 + 1", 2);
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TerminateOnResumeRunJavaScriptAtBreakpoint) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
CompileRun("var globalVariable = 0;");
|
|
|
|
SetTerminateOnResumeDelegate delegate(
|
|
|
|
SetTerminateOnResumeDelegate::kRunJavaScriptAtBreakpoint);
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
|
|
|
v8::Local<v8::Context> context = env.local();
|
|
|
|
{
|
|
|
|
v8::TryCatch try_catch(env->GetIsolate());
|
|
|
|
// If the delegate doesn't request termination on resume from breakpoint,
|
|
|
|
// foo diverges.
|
|
|
|
v8::Script::Compile(
|
|
|
|
context,
|
|
|
|
v8_str(env->GetIsolate(), "function foo(){debugger; while(true){}}"))
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Run(context)
|
|
|
|
.ToLocalChecked();
|
|
|
|
v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
|
|
|
|
env->Global()
|
|
|
|
->Get(context, v8_str(env->GetIsolate(), "foo"))
|
|
|
|
.ToLocalChecked());
|
|
|
|
|
|
|
|
v8::MaybeLocal<v8::Value> val =
|
|
|
|
foo->Call(context, env->Global(), 0, nullptr);
|
|
|
|
CHECK(val.IsEmpty());
|
|
|
|
CHECK(try_catch.HasTerminated());
|
|
|
|
CHECK_EQ(delegate.break_count(), 1);
|
|
|
|
}
|
|
|
|
// Exiting the TryCatch brought the isolate back to a state where JavaScript
|
|
|
|
// can be executed.
|
|
|
|
ExpectInt32("1 + 1", 2);
|
|
|
|
ExpectInt32("globalVariable", 1);
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TerminateOnResumeAtException) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2021-04-30 16:19:52 +00:00
|
|
|
ChangeBreakOnException(env->GetIsolate(), true, true);
|
2020-02-03 13:45:06 +00:00
|
|
|
SetTerminateOnResumeDelegate delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
|
|
|
v8::Local<v8::Context> context = env.local();
|
|
|
|
{
|
|
|
|
v8::TryCatch try_catch(env->GetIsolate());
|
|
|
|
const char* source = "throw new Error(); while(true){};";
|
|
|
|
|
|
|
|
v8::ScriptCompiler::Source script_source(v8_str(source));
|
|
|
|
v8::Local<v8::Function> foo =
|
2021-10-26 13:36:11 +00:00
|
|
|
v8::ScriptCompiler::CompileFunction(env.local(), &script_source)
|
2020-02-03 13:45:06 +00:00
|
|
|
.ToLocalChecked();
|
|
|
|
|
|
|
|
v8::MaybeLocal<v8::Value> val =
|
|
|
|
foo->Call(context, env->Global(), 0, nullptr);
|
|
|
|
CHECK(val.IsEmpty());
|
|
|
|
CHECK(try_catch.HasTerminated());
|
|
|
|
CHECK_EQ(delegate.break_count(), 0);
|
|
|
|
CHECK_EQ(delegate.exception_thrown_count(), 1);
|
|
|
|
}
|
|
|
|
// Exiting the TryCatch brought the isolate back to a state where JavaScript
|
|
|
|
// can be executed.
|
|
|
|
ExpectInt32("1 + 1", 2);
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TerminateOnResumeAtBreakOnEntry) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
SetTerminateOnResumeDelegate delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
|
|
|
{
|
|
|
|
v8::TryCatch try_catch(env->GetIsolate());
|
|
|
|
v8::Local<v8::Function> builtin =
|
|
|
|
CompileRun("String.prototype.repeat").As<v8::Function>();
|
|
|
|
SetBreakPoint(builtin, 0);
|
|
|
|
v8::Local<v8::Value> val = CompileRun("'b'.repeat(10)");
|
|
|
|
CHECK_EQ(delegate.break_count(), 1);
|
|
|
|
CHECK(val.IsEmpty());
|
|
|
|
CHECK(try_catch.HasTerminated());
|
|
|
|
CHECK_EQ(delegate.exception_thrown_count(), 0);
|
|
|
|
}
|
|
|
|
// Exiting the TryCatch brought the isolate back to a state where JavaScript
|
|
|
|
// can be executed.
|
|
|
|
ExpectInt32("1 + 1", 2);
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TerminateOnResumeAtBreakOnEntryUserDefinedFunction) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
SetTerminateOnResumeDelegate delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
|
|
|
{
|
|
|
|
v8::TryCatch try_catch(env->GetIsolate());
|
|
|
|
v8::Local<v8::Function> foo =
|
|
|
|
CompileFunction(&env, "function foo(b) { while (b > 0) {} }", "foo");
|
|
|
|
|
|
|
|
// Run without breakpoints to compile source to bytecode.
|
|
|
|
CompileRun("foo(-1)");
|
|
|
|
CHECK_EQ(delegate.break_count(), 0);
|
|
|
|
|
|
|
|
SetBreakPoint(foo, 0);
|
|
|
|
v8::Local<v8::Value> val = CompileRun("foo(1)");
|
|
|
|
CHECK_EQ(delegate.break_count(), 1);
|
|
|
|
CHECK(val.IsEmpty());
|
|
|
|
CHECK(try_catch.HasTerminated());
|
|
|
|
CHECK_EQ(delegate.exception_thrown_count(), 0);
|
|
|
|
}
|
|
|
|
// Exiting the TryCatch brought the isolate back to a state where JavaScript
|
|
|
|
// can be executed.
|
|
|
|
ExpectInt32("1 + 1", 2);
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TerminateOnResumeAtUnhandledRejection) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2021-04-30 16:19:52 +00:00
|
|
|
ChangeBreakOnException(env->GetIsolate(), true, true);
|
2020-02-03 13:45:06 +00:00
|
|
|
SetTerminateOnResumeDelegate delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
|
|
|
v8::Local<v8::Context> context = env.local();
|
|
|
|
{
|
|
|
|
v8::TryCatch try_catch(env->GetIsolate());
|
|
|
|
v8::Local<v8::Function> foo = CompileFunction(
|
|
|
|
&env, "async function foo() { Promise.reject(); while(true) {} }",
|
|
|
|
"foo");
|
|
|
|
|
|
|
|
v8::MaybeLocal<v8::Value> val =
|
|
|
|
foo->Call(context, env->Global(), 0, nullptr);
|
|
|
|
CHECK(val.IsEmpty());
|
|
|
|
CHECK(try_catch.HasTerminated());
|
|
|
|
CHECK_EQ(delegate.break_count(), 0);
|
|
|
|
CHECK_EQ(delegate.exception_thrown_count(), 1);
|
|
|
|
}
|
|
|
|
// Exiting the TryCatch brought the isolate back to a state where JavaScript
|
|
|
|
// can be executed.
|
|
|
|
ExpectInt32("1 + 1", 2);
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
void RejectPromiseThroughCpp(const v8::FunctionCallbackInfo<v8::Value>& info) {
|
|
|
|
auto data = reinterpret_cast<std::pair<v8::Isolate*, LocalContext*>*>(
|
|
|
|
info.Data().As<v8::External>()->Value());
|
|
|
|
|
|
|
|
v8::Local<v8::String> value1 =
|
2020-03-09 10:41:45 +00:00
|
|
|
v8::String::NewFromUtf8Literal(data->first, "foo");
|
2020-02-03 13:45:06 +00:00
|
|
|
|
|
|
|
v8::Local<v8::Promise::Resolver> resolver =
|
|
|
|
v8::Promise::Resolver::New(data->second->local()).ToLocalChecked();
|
|
|
|
v8::Local<v8::Promise> promise = resolver->GetPromise();
|
|
|
|
CHECK_EQ(promise->State(), v8::Promise::PromiseState::kPending);
|
|
|
|
|
|
|
|
resolver->Reject(data->second->local(), value1).ToChecked();
|
|
|
|
CHECK_EQ(promise->State(), v8::Promise::PromiseState::kRejected);
|
|
|
|
// CHECK_EQ(*v8::Utils::OpenHandle(*promise->Result()),
|
|
|
|
// i::ReadOnlyRoots(CcTest::i_isolate()).exception());
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TEST(TerminateOnResumeAtUnhandledRejectionCppImpl) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2021-04-30 16:19:52 +00:00
|
|
|
ChangeBreakOnException(isolate, true, true);
|
2020-02-03 13:45:06 +00:00
|
|
|
SetTerminateOnResumeDelegate delegate;
|
|
|
|
auto data = std::make_pair(isolate, &env);
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
|
|
|
{
|
2022-05-27 15:26:16 +00:00
|
|
|
// We want to trigger a breakpoint upon Promise rejection, but we will only
|
2020-02-03 13:45:06 +00:00
|
|
|
// get the callback if there is at least one JavaScript frame in the stack.
|
|
|
|
v8::Local<v8::Function> func =
|
|
|
|
v8::Function::New(env.local(), RejectPromiseThroughCpp,
|
|
|
|
v8::External::New(isolate, &data))
|
|
|
|
.ToLocalChecked();
|
|
|
|
CHECK(env->Global()
|
|
|
|
->Set(env.local(), v8_str("RejectPromiseThroughCpp"), func)
|
|
|
|
.FromJust());
|
|
|
|
|
|
|
|
CompileRun("RejectPromiseThroughCpp(); while (true) {}");
|
|
|
|
CHECK_EQ(delegate.break_count(), 0);
|
|
|
|
CHECK_EQ(delegate.exception_thrown_count(), 1);
|
|
|
|
}
|
|
|
|
ExpectInt32("1 + 1", 2);
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
static void UnreachableMicrotask(
|
|
|
|
const v8::FunctionCallbackInfo<v8::Value>& info) {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TEST(TerminateOnResumeFromMicrotask) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
SetTerminateOnResumeDelegate delegate(
|
|
|
|
SetTerminateOnResumeDelegate::kPerformMicrotaskCheckpointAtBreakpoint);
|
2021-04-30 16:19:52 +00:00
|
|
|
ChangeBreakOnException(env->GetIsolate(), true, true);
|
2020-02-03 13:45:06 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
|
|
|
{
|
|
|
|
v8::TryCatch try_catch(env->GetIsolate());
|
|
|
|
// Enqueue a microtask that gets run while we are paused at the breakpoint.
|
|
|
|
v8::Local<v8::Function> foo = CompileFunction(
|
|
|
|
&env, "function foo(){ Promise.reject(); while (true) {} }", "foo");
|
|
|
|
env->GetIsolate()->EnqueueMicrotask(foo);
|
|
|
|
env->GetIsolate()->EnqueueMicrotask(
|
|
|
|
v8::Function::New(env.local(), UnreachableMicrotask).ToLocalChecked());
|
|
|
|
|
|
|
|
CHECK_EQ(2,
|
|
|
|
CcTest::i_isolate()->native_context()->microtask_queue()->size());
|
|
|
|
|
|
|
|
v8::MicrotasksScope::PerformCheckpoint(env->GetIsolate());
|
|
|
|
|
|
|
|
CHECK_EQ(0,
|
|
|
|
CcTest::i_isolate()->native_context()->microtask_queue()->size());
|
|
|
|
|
|
|
|
CHECK(try_catch.HasTerminated());
|
|
|
|
CHECK_EQ(delegate.break_count(), 0);
|
|
|
|
CHECK_EQ(delegate.exception_thrown_count(), 1);
|
|
|
|
}
|
|
|
|
ExpectInt32("1 + 1", 2);
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
class FutexInterruptionThread : public v8::base::Thread {
|
|
|
|
public:
|
2021-03-08 16:56:17 +00:00
|
|
|
FutexInterruptionThread(v8::Isolate* isolate, v8::base::Semaphore* enter,
|
|
|
|
v8::base::Semaphore* exit)
|
2020-02-03 13:45:06 +00:00
|
|
|
: Thread(Options("FutexInterruptionThread")),
|
|
|
|
isolate_(isolate),
|
2021-03-08 16:56:17 +00:00
|
|
|
enter_(enter),
|
|
|
|
exit_(exit) {}
|
2020-02-03 13:45:06 +00:00
|
|
|
|
|
|
|
void Run() override {
|
2021-03-08 16:56:17 +00:00
|
|
|
enter_->Wait();
|
2020-02-03 13:45:06 +00:00
|
|
|
v8::debug::SetTerminateOnResume(isolate_);
|
2021-03-08 16:56:17 +00:00
|
|
|
exit_->Signal();
|
2020-02-03 13:45:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
v8::Isolate* isolate_;
|
2021-03-08 16:56:17 +00:00
|
|
|
v8::base::Semaphore* enter_;
|
|
|
|
v8::base::Semaphore* exit_;
|
2020-02-03 13:45:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class SemaphoreTriggerOnBreak : public v8::debug::DebugDelegate {
|
|
|
|
public:
|
2021-03-08 16:56:17 +00:00
|
|
|
SemaphoreTriggerOnBreak() : enter_(0), exit_(0) {}
|
2021-11-23 09:14:18 +00:00
|
|
|
void BreakProgramRequested(
|
|
|
|
v8::Local<v8::Context> paused_context,
|
|
|
|
const std::vector<v8::debug::BreakpointId>& inspector_break_points_hit,
|
2021-12-02 09:26:01 +00:00
|
|
|
v8::debug::BreakReasons break_reasons) override {
|
2020-02-03 13:45:06 +00:00
|
|
|
break_count_++;
|
2021-03-08 16:56:17 +00:00
|
|
|
enter_.Signal();
|
|
|
|
exit_.Wait();
|
2020-02-03 13:45:06 +00:00
|
|
|
}
|
|
|
|
|
2021-03-08 16:56:17 +00:00
|
|
|
v8::base::Semaphore* enter() { return &enter_; }
|
|
|
|
v8::base::Semaphore* exit() { return &exit_; }
|
2020-02-03 13:45:06 +00:00
|
|
|
int break_count() const { return break_count_; }
|
|
|
|
|
|
|
|
private:
|
2021-03-08 16:56:17 +00:00
|
|
|
v8::base::Semaphore enter_;
|
|
|
|
v8::base::Semaphore exit_;
|
2020-02-03 13:45:06 +00:00
|
|
|
int break_count_ = 0;
|
|
|
|
};
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
TEST(TerminateOnResumeFromOtherThread) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2021-04-30 16:19:52 +00:00
|
|
|
ChangeBreakOnException(env->GetIsolate(), true, true);
|
2020-02-03 13:45:06 +00:00
|
|
|
|
|
|
|
SemaphoreTriggerOnBreak delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
|
|
|
|
2021-03-08 16:56:17 +00:00
|
|
|
FutexInterruptionThread timeout_thread(env->GetIsolate(), delegate.enter(),
|
|
|
|
delegate.exit());
|
2020-02-03 13:45:06 +00:00
|
|
|
CHECK(timeout_thread.Start());
|
|
|
|
|
|
|
|
v8::Local<v8::Context> context = env.local();
|
|
|
|
{
|
|
|
|
v8::TryCatch try_catch(env->GetIsolate());
|
|
|
|
const char* source = "debugger; while(true){};";
|
|
|
|
|
|
|
|
v8::ScriptCompiler::Source script_source(v8_str(source));
|
|
|
|
v8::Local<v8::Function> foo =
|
2021-10-26 13:36:11 +00:00
|
|
|
v8::ScriptCompiler::CompileFunction(env.local(), &script_source)
|
2020-02-03 13:45:06 +00:00
|
|
|
.ToLocalChecked();
|
|
|
|
|
|
|
|
v8::MaybeLocal<v8::Value> val =
|
|
|
|
foo->Call(context, env->Global(), 0, nullptr);
|
|
|
|
CHECK(val.IsEmpty());
|
|
|
|
CHECK(try_catch.HasTerminated());
|
|
|
|
CHECK_EQ(delegate.break_count(), 1);
|
|
|
|
}
|
|
|
|
// Exiting the TryCatch brought the isolate back to a state where JavaScript
|
|
|
|
// can be executed.
|
|
|
|
ExpectInt32("1 + 1", 2);
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class InterruptionBreakRightNow : public v8::base::Thread {
|
|
|
|
public:
|
|
|
|
explicit InterruptionBreakRightNow(v8::Isolate* isolate)
|
2021-03-08 16:56:17 +00:00
|
|
|
: Thread(Options("InterruptionBreakRightNow")), isolate_(isolate) {}
|
2020-02-03 13:45:06 +00:00
|
|
|
|
|
|
|
void Run() override {
|
|
|
|
// Wait a bit before terminating.
|
|
|
|
v8::base::OS::Sleep(v8::base::TimeDelta::FromMilliseconds(100));
|
|
|
|
isolate_->RequestInterrupt(BreakRightNow, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static void BreakRightNow(v8::Isolate* isolate, void* data) {
|
|
|
|
v8::debug::BreakRightNow(isolate);
|
|
|
|
}
|
|
|
|
v8::Isolate* isolate_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
TEST(TerminateOnResumeAtInterruptFromOtherThread) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2021-04-30 16:19:52 +00:00
|
|
|
ChangeBreakOnException(env->GetIsolate(), true, true);
|
2020-02-03 13:45:06 +00:00
|
|
|
|
|
|
|
SetTerminateOnResumeDelegate delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
|
|
|
|
|
|
|
InterruptionBreakRightNow timeout_thread(env->GetIsolate());
|
|
|
|
|
|
|
|
v8::Local<v8::Context> context = env.local();
|
|
|
|
{
|
|
|
|
v8::TryCatch try_catch(env->GetIsolate());
|
|
|
|
const char* source = "while(true){}";
|
|
|
|
|
|
|
|
v8::ScriptCompiler::Source script_source(v8_str(source));
|
|
|
|
v8::Local<v8::Function> foo =
|
2021-10-26 13:36:11 +00:00
|
|
|
v8::ScriptCompiler::CompileFunction(env.local(), &script_source)
|
2020-02-03 13:45:06 +00:00
|
|
|
.ToLocalChecked();
|
|
|
|
|
|
|
|
CHECK(timeout_thread.Start());
|
|
|
|
v8::MaybeLocal<v8::Value> val =
|
|
|
|
foo->Call(context, env->Global(), 0, nullptr);
|
|
|
|
CHECK(val.IsEmpty());
|
|
|
|
CHECK(try_catch.HasTerminated());
|
|
|
|
CHECK_EQ(delegate.break_count(), 1);
|
|
|
|
}
|
|
|
|
// Exiting the TryCatch brought the isolate back to a state where JavaScript
|
|
|
|
// can be executed.
|
|
|
|
ExpectInt32("1 + 1", 2);
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
2021-11-09 10:26:25 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class NoopDelegate : public v8::debug::DebugDelegate {};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Tests that the Isolate::Pop/Push leaves an empty stack for `await` when
|
|
|
|
// the Debugger is active but the AsyncEventDelegate is not set.
|
|
|
|
// Regression test for https://crbug.com/1225905
|
|
|
|
TEST(AwaitCleansUpGlobalPromiseStack) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
|
|
|
|
|
|
|
NoopDelegate delegate;
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
|
|
|
|
v8::debug::SetAsyncEventDelegate(env->GetIsolate(), nullptr);
|
|
|
|
|
|
|
|
v8::Local<v8::String> source = v8_str(
|
|
|
|
"(async () => {\n"
|
|
|
|
" await Promise.resolve();\n"
|
|
|
|
"})();\n");
|
|
|
|
CompileRun(source);
|
|
|
|
|
2022-03-24 07:24:23 +00:00
|
|
|
CHECK(CcTest::i_isolate()->IsPromiseStackEmpty());
|
2021-11-09 10:26:25 +00:00
|
|
|
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
2022-01-11 11:49:58 +00:00
|
|
|
|
|
|
|
TEST(CreateMessageFromOldException) {
|
|
|
|
LocalContext context;
|
|
|
|
v8::HandleScope scope(context->GetIsolate());
|
|
|
|
|
|
|
|
context->GetIsolate()->SetCaptureStackTraceForUncaughtExceptions(true);
|
|
|
|
|
|
|
|
v8::Local<v8::Value> error;
|
|
|
|
{
|
|
|
|
v8::TryCatch try_catch(context->GetIsolate());
|
|
|
|
CompileRun(R"javascript(
|
|
|
|
function f1() {
|
|
|
|
throw new Error('error in f1');
|
|
|
|
};
|
|
|
|
f1();
|
|
|
|
)javascript");
|
|
|
|
CHECK(try_catch.HasCaught());
|
|
|
|
|
|
|
|
error = try_catch.Exception();
|
|
|
|
}
|
|
|
|
CHECK(error->IsObject());
|
|
|
|
|
|
|
|
v8::Local<v8::Message> message =
|
|
|
|
v8::debug::CreateMessageFromException(context->GetIsolate(), error);
|
|
|
|
CHECK(!message.IsEmpty());
|
|
|
|
CHECK_EQ(3, message->GetLineNumber(context.local()).FromJust());
|
|
|
|
CHECK_EQ(16, message->GetStartColumn(context.local()).FromJust());
|
|
|
|
|
|
|
|
v8::Local<v8::StackTrace> stackTrace = message->GetStackTrace();
|
|
|
|
CHECK(!stackTrace.IsEmpty());
|
|
|
|
CHECK_EQ(2, stackTrace->GetFrameCount());
|
|
|
|
|
|
|
|
stackTrace = v8::Exception::GetStackTrace(error);
|
|
|
|
CHECK(!stackTrace.IsEmpty());
|
|
|
|
CHECK_EQ(2, stackTrace->GetFrameCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CreateMessageDoesNotInspectStack) {
|
|
|
|
LocalContext context;
|
|
|
|
v8::HandleScope scope(context->GetIsolate());
|
|
|
|
|
|
|
|
// Do not enable Isolate::SetCaptureStackTraceForUncaughtExceptions.
|
|
|
|
|
|
|
|
v8::Local<v8::Value> error;
|
|
|
|
{
|
|
|
|
v8::TryCatch try_catch(context->GetIsolate());
|
|
|
|
CompileRun(R"javascript(
|
|
|
|
function f1() {
|
|
|
|
throw new Error('error in f1');
|
|
|
|
};
|
|
|
|
f1();
|
|
|
|
)javascript");
|
|
|
|
CHECK(try_catch.HasCaught());
|
|
|
|
|
|
|
|
error = try_catch.Exception();
|
|
|
|
}
|
|
|
|
// The caught error should not have a stack trace attached.
|
|
|
|
CHECK(error->IsObject());
|
|
|
|
CHECK(v8::Exception::GetStackTrace(error).IsEmpty());
|
|
|
|
|
|
|
|
// The corresponding message should also not have a stack trace.
|
|
|
|
v8::Local<v8::Message> message =
|
|
|
|
v8::debug::CreateMessageFromException(context->GetIsolate(), error);
|
|
|
|
CHECK(!message.IsEmpty());
|
|
|
|
CHECK(message->GetStackTrace().IsEmpty());
|
|
|
|
}
|
2022-10-18 04:52:25 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class ScopeListener : public v8::debug::DebugDelegate {
|
|
|
|
public:
|
|
|
|
void BreakProgramRequested(v8::Local<v8::Context> context,
|
|
|
|
const std::vector<v8::debug::BreakpointId>&,
|
|
|
|
v8::debug::BreakReasons break_reasons) override {
|
|
|
|
i::Isolate* isolate = CcTest::i_isolate();
|
|
|
|
i::StackTraceFrameIterator iterator_(isolate,
|
|
|
|
isolate->debug()->break_frame_id());
|
|
|
|
// Go up one frame so we are on the script level.
|
|
|
|
iterator_.Advance();
|
|
|
|
|
|
|
|
auto frame_inspector =
|
|
|
|
std::make_unique<i::FrameInspector>(iterator_.frame(), 0, isolate);
|
|
|
|
i::ScopeIterator scope_iterator(
|
|
|
|
isolate, frame_inspector.get(),
|
|
|
|
i::ScopeIterator::ReparseStrategy::kScriptIfNeeded);
|
|
|
|
|
|
|
|
// Iterate all scopes triggering block list creation along the way. This
|
|
|
|
// should not run into any CHECKs.
|
|
|
|
while (!scope_iterator.Done()) scope_iterator.Next();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TEST(ScopeIteratorDoesNotCreateBlocklistForScriptScope) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
|
|
|
|
// Register a debug event listener which creates a ScopeIterator.
|
|
|
|
ScopeListener delegate;
|
|
|
|
v8::debug::SetDebugDelegate(isolate, &delegate);
|
|
|
|
|
|
|
|
CompileRun(R"javascript(
|
|
|
|
function foo() { debugger; }
|
|
|
|
foo();
|
|
|
|
)javascript");
|
|
|
|
|
|
|
|
// Get rid of the debug event listener.
|
|
|
|
v8::debug::SetDebugDelegate(isolate, nullptr);
|
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
2022-10-18 06:01:30 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class DebugEvaluateListener : public v8::debug::DebugDelegate {
|
|
|
|
public:
|
|
|
|
void BreakProgramRequested(v8::Local<v8::Context> context,
|
|
|
|
const std::vector<v8::debug::BreakpointId>&,
|
|
|
|
v8::debug::BreakReasons break_reasons) override {
|
|
|
|
v8::Isolate* isolate = context->GetIsolate();
|
|
|
|
auto it = v8::debug::StackTraceIterator::Create(isolate);
|
|
|
|
v8::Local<v8::Value> result =
|
|
|
|
it->Evaluate(v8_str(isolate, "x"), /* throw_on_side_effect */ false)
|
|
|
|
.ToLocalChecked();
|
|
|
|
CHECK_EQ(42, result->ToInteger(context).ToLocalChecked()->Value());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // 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) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
|
|
|
|
// Register a debug event listener which evaluates 'x'.
|
|
|
|
DebugEvaluateListener delegate;
|
|
|
|
v8::debug::SetDebugDelegate(isolate, &delegate);
|
|
|
|
|
|
|
|
static const char* source = "const x = 42; () => x; debugger;";
|
|
|
|
|
|
|
|
{
|
|
|
|
v8::ScriptCompiler::Source script_source(v8_str(source));
|
|
|
|
v8::Local<v8::Function> fun =
|
|
|
|
v8::ScriptCompiler::CompileFunction(env.local(), &script_source)
|
|
|
|
.ToLocalChecked();
|
|
|
|
|
|
|
|
fun->Call(env.local(), env->Global(), 0, nullptr).ToLocalChecked();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get rid of the debug event listener.
|
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|