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 "src/v8.h"
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/api.h"
|
|
|
|
#include "src/compilation-cache.h"
|
2016-10-19 02:00:21 +00:00
|
|
|
#include "src/debug/debug-interface.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.h"
|
|
|
|
#include "src/frames.h"
|
2017-02-23 11:46:29 +00:00
|
|
|
#include "src/objects-inl.h"
|
2018-07-05 20:34:14 +00:00
|
|
|
#include "src/snapshot/natives.h"
|
2017-11-17 09:15:36 +00:00
|
|
|
#include "src/snapshot/snapshot.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/utils.h"
|
|
|
|
#include "test/cctest/cctest.h"
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
using ::v8::internal::Handle;
|
2018-06-03 05:09:41 +00:00
|
|
|
using ::v8::internal::StepNone; // From StepAction enum
|
2008-08-22 13:33:59 +00:00
|
|
|
using ::v8::internal::StepIn; // From StepAction enum
|
|
|
|
using ::v8::internal::StepNext; // From StepAction enum
|
|
|
|
using ::v8::internal::StepOut; // From StepAction enum
|
|
|
|
|
|
|
|
// --- 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
|
|
|
|
|
|
|
debug->SetBreakPoint(function, break_point, &position);
|
|
|
|
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.
|
|
|
|
static void ChangeBreakOnException(bool caught, bool uncaught) {
|
2013-09-19 09:17:13 +00:00
|
|
|
v8::internal::Debug* debug = CcTest::i_isolate()->debug();
|
2011-03-18 20:35:07 +00:00
|
|
|
debug->ChangeBreakOnException(v8::internal::BreakException, caught);
|
|
|
|
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.
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllGarbage(Heap::kMakeHeapIterableMask);
|
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.
|
2013-09-19 09:46:15 +00:00
|
|
|
HeapIterator iterator(CcTest::heap());
|
2017-10-13 16:33:03 +00:00
|
|
|
for (HeapObject* obj = iterator.next(); obj != nullptr;
|
|
|
|
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:
|
|
|
|
void BreakProgramRequested(v8::Local<v8::Context>,
|
|
|
|
const std::vector<v8::debug::BreakpointId>&) {
|
|
|
|
v8::internal::Debug* debug = CcTest::i_isolate()->debug();
|
|
|
|
// When hitting a debug event listener there must be a break set.
|
|
|
|
CHECK_NE(debug->break_id(), 0);
|
2008-12-11 08:03:24 +00:00
|
|
|
|
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:
|
|
|
|
void BreakProgramRequested(v8::Local<v8::Context>,
|
|
|
|
const std::vector<v8::debug::BreakpointId>&) {
|
|
|
|
v8::internal::Debug* debug = CcTest::i_isolate()->debug();
|
|
|
|
// When hitting a debug event listener there must be a break set.
|
|
|
|
CHECK_NE(debug->break_id(), 0);
|
2008-12-11 08:03:24 +00:00
|
|
|
|
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:
|
|
|
|
void BreakProgramRequested(v8::Local<v8::Context>,
|
|
|
|
const std::vector<v8::debug::BreakpointId>&) {
|
|
|
|
v8::internal::Debug* debug = CcTest::i_isolate()->debug();
|
|
|
|
// When hitting a debug event listener there must be a break set.
|
|
|
|
CHECK_NE(debug->break_id(), 0);
|
2008-12-11 08:03:24 +00:00
|
|
|
|
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
|
|
|
|
[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*) {
|
|
|
|
v8::debug::BreakRightNow(isolate);
|
|
|
|
}
|
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:
|
|
|
|
void BreakProgramRequested(v8::Local<v8::Context>,
|
|
|
|
const std::vector<v8::debug::BreakpointId>&) {
|
|
|
|
v8::Isolate* v8_isolate = CcTest::isolate();
|
|
|
|
v8::internal::Isolate* isolate = CcTest::i_isolate();
|
|
|
|
v8::internal::Debug* debug = isolate->debug();
|
|
|
|
// When hitting a debug event listener there must be a break set.
|
|
|
|
CHECK_NE(debug->break_id(), 0);
|
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.
|
2018-03-08 14:07:39 +00:00
|
|
|
bp = SetBreakPoint(builtin, 0);
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
|
|
|
bp = SetBreakPoint(builtin, 0);
|
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) {
|
|
|
|
i::FLAG_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(
|
|
|
|
"test(0.5); test(0.6);"
|
|
|
|
"%OptimizeFunctionOnNextCall(test); test(0.7);");
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
bp = SetBreakPoint(builtin, 0);
|
|
|
|
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.
|
|
|
|
CompileRun("%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) {
|
|
|
|
i::FLAG_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(
|
|
|
|
"test(4); test(5);"
|
|
|
|
"%OptimizeFunctionOnNextCall(test); test(6);");
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
bp = SetBreakPoint(builtin, 0);
|
|
|
|
CompileRun("'a'.repeat(2);");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
CompileRun("test(7);");
|
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
|
|
|
// Re-optimize.
|
|
|
|
CompileRun("%OptimizeFunctionOnNextCall(test);");
|
|
|
|
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) {
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
|
|
|
i::FLAG_experimental_inline_promise_constructor = 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(
|
|
|
|
"test(4); test(5);"
|
|
|
|
"%OptimizeFunctionOnNextCall(test); test(6);");
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
bp = SetBreakPoint(builtin, 0);
|
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.
|
|
|
|
CompileRun("%OptimizeFunctionOnNextCall(test);");
|
|
|
|
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) {
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
|
|
|
i::FLAG_block_concurrent_recompilation = 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) }");
|
|
|
|
// Trigger concurrent compile job. It is suspended until unblock.
|
|
|
|
CompileRun(
|
|
|
|
"test(0.5); test(0.6);"
|
|
|
|
"%OptimizeFunctionOnNextCall(test, 'concurrent'); test(0.7);");
|
|
|
|
CHECK_EQ(0, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run with breakpoint.
|
|
|
|
bp = SetBreakPoint(builtin, 0);
|
|
|
|
// Have the concurrent compile job finish now.
|
|
|
|
CompileRun(
|
|
|
|
"%UnblockConcurrentRecompilation();"
|
|
|
|
"%GetOptimizationStatus(test, 'sync');");
|
|
|
|
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) {
|
|
|
|
i::FLAG_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(
|
|
|
|
"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.
|
|
|
|
CompileRun("%OptimizeFunctionOnNextCall(test);");
|
|
|
|
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 ===
|
|
|
|
// This does not work with no-snapshot build.
|
|
|
|
#ifdef V8_USE_SNAPSHOT
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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.
|
|
|
|
bp = SetBreakPoint(function, 0);
|
|
|
|
ExpectInt32("f()", 2);
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
ExpectInt32("f()", 2);
|
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
ExpectInt32("f()", 2);
|
|
|
|
CHECK_EQ(2, 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-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')");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
CompileRun("o.f");
|
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
CompileRun("get_wrapper(o, 'f', 2)");
|
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
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)");
|
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
CompileRun("o.f = 3");
|
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
|
|
|
// === 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)");
|
|
|
|
CHECK_EQ(1, break_point_hit_count);
|
|
|
|
|
|
|
|
CompileRun("o.f = 3");
|
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
CompileRun("set_wrapper(o, 'f', 2)");
|
|
|
|
CHECK_EQ(2, break_point_hit_count);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
// Run without breakpoints.
|
|
|
|
ClearBreakPoint(bp);
|
|
|
|
CompileRun("o.f = 3");
|
|
|
|
CompileRun("o.f");
|
|
|
|
CHECK_EQ(42, break_point_hit_count);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::debug::SetDebugDelegate(env->GetIsolate(), nullptr);
|
2018-03-27 19:18:36 +00:00
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
2018-03-09 08:46:47 +00:00
|
|
|
TEST(BreakPointInlineApiFunction) {
|
|
|
|
i::FLAG_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();
|
2018-03-09 08:46:47 +00:00
|
|
|
CompileRun("function g() { return 1 + f(); }");
|
|
|
|
|
|
|
|
// === 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) {
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
|
|
|
i::FLAG_block_concurrent_recompilation = 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) {
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
|
|
|
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(
|
|
|
|
"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.
|
|
|
|
CompileRun("%OptimizeFunctionOnNextCall(test);");
|
|
|
|
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);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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);
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepNext);
|
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);
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepNext);
|
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);
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepNext);
|
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);
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepNext);
|
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);
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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.
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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.
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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.
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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.
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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.
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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.
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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.
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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.
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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.
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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.
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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.
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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.
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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.
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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.
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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.
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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.
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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.
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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.
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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.
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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.
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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 = ..."
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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 = ..."
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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 = {};"
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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;"
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
run_step.set_step_action(StepIn);
|
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();
|
|
|
|
run_step.set_step_action(StepIn);
|
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();
|
|
|
|
run_step.set_step_action(StepIn);
|
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);
|
|
|
|
run_step.set_step_action(StepIn);
|
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);
|
|
|
|
run_step.set_step_action(StepIn);
|
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";
|
|
|
|
|
2015-11-19 13:45:42 +00:00
|
|
|
v8::ScriptOrigin origin(v8_str(env->GetIsolate(), script_name),
|
|
|
|
v8::Integer::New(env->GetIsolate(), 0));
|
|
|
|
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) {
|
2013-06-27 15:19:04 +00:00
|
|
|
i::FLAG_stress_compaction = false;
|
2012-10-12 11:41:14 +00:00
|
|
|
#ifdef VERIFY_HEAP
|
|
|
|
i::FLAG_verify_heap = true;
|
|
|
|
#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:
|
|
|
|
void BreakProgramRequested(
|
|
|
|
v8::Local<v8::Context>,
|
|
|
|
const std::vector<v8::debug::BreakpointId>&) override {
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
};
|
2017-12-18 08:10:06 +00:00
|
|
|
|
|
|
|
TEST(DebugBreakInWrappedScript) {
|
|
|
|
i::FLAG_stress_compaction = false;
|
|
|
|
#ifdef VERIFY_HEAP
|
|
|
|
i::FLAG_verify_heap = true;
|
|
|
|
#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:
|
|
|
|
ChangeBreakOnException(true, true);
|
|
|
|
|
|
|
|
{
|
|
|
|
v8::ScriptCompiler::Source script_source(v8_str(source));
|
|
|
|
v8::Local<v8::Function> fun =
|
|
|
|
v8::ScriptCompiler::CompileFunctionInContext(
|
2018-06-03 05:09:41 +00:00
|
|
|
env.local(), &script_source, 0, nullptr, 0, nullptr)
|
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);
|
2017-12-18 08:10:06 +00:00
|
|
|
CheckDebuggerUnloaded();
|
|
|
|
}
|
|
|
|
|
2017-11-29 14:00:16 +00:00
|
|
|
TEST(DebugBreakWithoutJS) {
|
|
|
|
i::FLAG_stress_compaction = false;
|
|
|
|
#ifdef VERIFY_HEAP
|
|
|
|
i::FLAG_verify_heap = true;
|
|
|
|
#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.
|
|
|
|
v8::RegisterExtension(new v8::Extension("simpletest",
|
|
|
|
kSimpleExtensionSource));
|
|
|
|
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; }
|
|
|
|
virtual ~EmptyExternalStringResource() {}
|
|
|
|
virtual size_t length() const { return empty_.length(); }
|
|
|
|
virtual const uint16_t* data() const { return empty_.start(); }
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
private:
|
|
|
|
::v8::internal::EmbeddedVector<uint16_t, 1> empty_;
|
|
|
|
};
|
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.
|
|
|
|
v8::Local<v8::String> script = v8_str(isolate,
|
|
|
|
"function f() {\n"
|
|
|
|
" debugger;\n"
|
|
|
|
"}\n");
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
v8::ScriptOrigin origin1 = v8::ScriptOrigin(v8_str(isolate, "name"));
|
|
|
|
v8::Local<v8::Script> script1 =
|
|
|
|
v8::Script::Compile(env.local(), script, &origin1).ToLocalChecked();
|
|
|
|
USE(script1);
|
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++) {
|
|
|
|
Handle<v8::internal::Script> 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
|
|
|
|
|
|
|
v8::internal::Script::InitLineEnds(script);
|
|
|
|
v8::internal::FixedArray* ends =
|
|
|
|
v8::internal::FixedArray::cast(script->line_ends());
|
|
|
|
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:
|
|
|
|
void BreakProgramRequested(v8::Local<v8::Context> paused_context,
|
|
|
|
const std::vector<v8::debug::BreakpointId>&
|
|
|
|
inspector_break_points_hit) override {
|
|
|
|
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,
|
|
|
|
v8::Local<v8::Value> promise,
|
|
|
|
bool is_uncaught) override {
|
|
|
|
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:
|
|
|
|
ChangeBreakOnException(false, true);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
const char* source = "var a=1";
|
|
|
|
v8::ScriptCompiler::Source script_source(
|
|
|
|
v8::String::NewFromUtf8(isolate, source, v8::NewStringType::kNormal)
|
|
|
|
.ToLocalChecked());
|
|
|
|
|
|
|
|
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.
|
|
|
|
TEST(DebugBreakFunctionApply) {
|
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.
|
|
|
|
v8::Local<v8::Function> foo = CompileFunction(
|
|
|
|
&env,
|
|
|
|
"function baz(x) { }"
|
|
|
|
"function bar(x) { baz(); }"
|
|
|
|
"function foo(){ bar.apply(this, [1]); }",
|
|
|
|
"foo");
|
|
|
|
|
|
|
|
// Register a debug event listener which steps 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
|
|
|
|
|
|
|
// Limit the number of debug breaks. This is a regression test for issue 493
|
|
|
|
// where this test would enter an infinite loop.
|
|
|
|
break_point_hit_count = 0;
|
|
|
|
max_break_point_hit_count = 10000; // 10000 => infinite loop.
|
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.
|
2011-12-02 13:23:44 +00:00
|
|
|
CHECK_GT(break_point_hit_count, 1);
|
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
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
i::EmbeddedVector<char, 1024> buffer;
|
2015-07-30 09:11:24 +00:00
|
|
|
SNPrintF(buffer, "function f() {%s%s%s}", loop_head, loop_bodies[i],
|
|
|
|
loop_tail);
|
|
|
|
|
|
|
|
i::PrintF("%s\n", buffer.start());
|
|
|
|
|
|
|
|
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.
|
|
|
|
CompileRun(buffer.start());
|
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
|
|
|
|
|
|
|
// Register a debug event listener which 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
|
|
|
|
|
|
|
// 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:
|
|
|
|
void BreakProgramRequested(v8::Local<v8::Context> paused_context,
|
|
|
|
const std::vector<v8::debug::BreakpointId>&
|
|
|
|
inspector_break_points_hit) override {
|
|
|
|
int expected_frame_count = 4;
|
|
|
|
int expected_line_number[] = {1, 4, 7, 12};
|
|
|
|
|
|
|
|
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) {
|
|
|
|
i::FLAG_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 =
|
|
|
|
"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"
|
|
|
|
"g(false); \n"
|
|
|
|
"g(false); \n"
|
|
|
|
"%OptimizeFunctionOnNextCall(g); \n"
|
|
|
|
"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:
|
|
|
|
// When doing StepNext through the first script, the debugger is not reset
|
|
|
|
// 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;
|
|
|
|
delegate.set_step_action(StepNext);
|
|
|
|
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:
|
|
|
|
void BreakProgramRequested(v8::Local<v8::Context> paused_context,
|
|
|
|
const std::vector<v8::debug::BreakpointId>&
|
|
|
|
inspector_break_points_hit) override {
|
|
|
|
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:
|
|
|
|
void BreakProgramRequested(v8::Local<v8::Context> paused_context,
|
|
|
|
const std::vector<v8::debug::BreakpointId>&
|
|
|
|
inspector_break_points_hit) override {
|
|
|
|
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
|
|
|
|
|
|
|
virtual void Run() {
|
|
|
|
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);
|
|
|
|
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-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,
|
|
|
|
v8::Local<v8::Value> promise,
|
|
|
|
bool is_uncaught) override {
|
|
|
|
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();
|
2014-09-30 15:29:08 +00:00
|
|
|
ChangeBreakOnException(false, true);
|
|
|
|
|
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:
|
|
|
|
void BreakProgramRequested(v8::Local<v8::Context> paused_context,
|
|
|
|
const std::vector<v8::debug::BreakpointId>&
|
|
|
|
inspector_break_points_hit) override {
|
|
|
|
++break_point_hit_count;
|
|
|
|
if (break_point_hit_count >= 3) return;
|
|
|
|
PrepareStep(StepNext);
|
|
|
|
}
|
|
|
|
int break_point_hit_count = 0;
|
|
|
|
};
|
2016-04-19 15:28:49 +00:00
|
|
|
|
|
|
|
TEST(DebugStepOverFunctionWithCaughtException) {
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
|
|
|
|
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) {
|
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
|
|
|
create_params.constraints.set_max_old_space_size(10);
|
|
|
|
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.
|
|
|
|
int length = 10 * i::MB / i::kPointerSize;
|
|
|
|
i_isolate->factory()->NewFixedArray(length, i::TENURED);
|
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) {
|
|
|
|
i::FLAG_always_opt = false;
|
|
|
|
LocalContext env;
|
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2017-03-21 11:08:36 +00:00
|
|
|
v8::debug::Coverage::SelectMode(isolate, v8::debug::Coverage::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()
|
|
|
|
.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) {
|
|
|
|
i::FLAG_always_opt = false;
|
|
|
|
LocalContext env;
|
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
v8::debug::Coverage::SelectMode(isolate, v8::debug::Coverage::kPreciseCount);
|
|
|
|
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()
|
|
|
|
.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) {
|
|
|
|
i::FLAG_always_opt = false;
|
|
|
|
LocalContext env;
|
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
v8::debug::Coverage::SelectMode(isolate, v8::debug::Coverage::kPreciseCount);
|
|
|
|
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);
|
|
|
|
|
2018-01-30 09:04:58 +00:00
|
|
|
i::Snapshot::EnsureAllBuiltinsAreDeserialized(iisolate);
|
|
|
|
|
2017-11-17 09:15:36 +00:00
|
|
|
i::Builtins* builtins = iisolate->builtins();
|
2017-03-10 17:18:08 +00:00
|
|
|
bool fail = false;
|
|
|
|
for (int i = 0; i < i::Builtins::builtin_count; i++) {
|
2018-06-03 05:09:41 +00:00
|
|
|
i::Code* builtin = builtins->builtin(i);
|
|
|
|
if (builtin->kind() != i::Code::BUILTIN) continue;
|
2017-05-23 09:06:51 +00:00
|
|
|
auto prediction = builtin->GetBuiltinCatchPrediction();
|
|
|
|
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);
|
|
|
|
v8::PersistentValueVector<v8::debug::Script> scripts(isolate);
|
|
|
|
v8::debug::GetLoadedScripts(isolate, scripts);
|
2017-10-18 09:06:55 +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;
|
|
|
|
CHECK(scripts.Get(0)->GetPossibleBreakpoints(
|
|
|
|
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
|
|
|
{
|
|
|
|
i::HeapIterator iterator(isolate->heap());
|
|
|
|
while (i::HeapObject* obj = iterator.next()) {
|
|
|
|
if (!obj->IsJSFunction()) continue;
|
|
|
|
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
|
|
|
|
|
|
|
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) {
|
|
|
|
i::FLAG_expose_gc = true;
|
|
|
|
i::FLAG_expose_natives_as = "natives";
|
|
|
|
|
|
|
|
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;
|
|
|
|
CompileWithOrigin(v8_str("function foo(){}"), v8_str("normal.js"));
|
|
|
|
std::unordered_map<int, int> count_by_type;
|
|
|
|
{
|
|
|
|
i::DisallowHeapAllocation no_gc;
|
|
|
|
i::Script::Iterator iterator(i_isolate);
|
|
|
|
i::Script* script;
|
|
|
|
while ((script = iterator.Next()) != nullptr) {
|
|
|
|
if (script->type() == i::Script::TYPE_NATIVE &&
|
|
|
|
script->name()->IsUndefined(i_isolate)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
++count_by_type[script->type()];
|
|
|
|
scripts.emplace_back(script, i_isolate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CHECK_EQ(count_by_type[i::Script::TYPE_NATIVE],
|
|
|
|
i::Natives::GetBuiltinsCount());
|
|
|
|
CHECK_EQ(count_by_type[i::Script::TYPE_EXTENSION], 2);
|
|
|
|
CHECK_EQ(count_by_type[i::Script::TYPE_NORMAL], 1);
|
|
|
|
CHECK_EQ(count_by_type[i::Script::TYPE_WASM], 0);
|
|
|
|
CHECK_EQ(count_by_type[i::Script::TYPE_INSPECTOR], 0);
|
|
|
|
|
|
|
|
i::Handle<i::Script> native_array_script =
|
|
|
|
FindScript(i_isolate, scripts, "native array.js").ToHandleChecked();
|
|
|
|
CHECK_EQ(native_array_script->type(), i::Script::TYPE_NATIVE);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test first positon.
|
|
|
|
CHECK_EQ(script->GetSourceLocation(0).GetLineNumber(), 0);
|
|
|
|
CHECK_EQ(script->GetSourceLocation(0).GetColumnNumber(), 0);
|
|
|
|
|
|
|
|
// Test second positon.
|
|
|
|
CHECK_EQ(script->GetSourceLocation(1).GetLineNumber(), 0);
|
|
|
|
CHECK_EQ(script->GetSourceLocation(1).GetColumnNumber(), 1);
|
|
|
|
|
|
|
|
// Test first positin in function a().
|
|
|
|
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);
|
|
|
|
|
|
|
|
// Test first positin in function b().
|
|
|
|
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);
|
|
|
|
|
|
|
|
// Test first positin in function c().
|
|
|
|
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);
|
|
|
|
|
|
|
|
// Test first positin in function d().
|
|
|
|
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.
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(1, 10)), start_a);
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(2, 13)), start_b);
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(3, 0)), start_b + 5);
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(3, 2)), start_b + 7);
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(4, 0)), start_b + 16);
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(5, 12)), start_c);
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(6, 0)), start_c + 6);
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(7, 0)), start_c + 19);
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(8, 0)), start_c + 35);
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(9, 0)), start_c + 48);
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(10, 0)), start_c + 64);
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(11, 0)), start_c + 70);
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(12, 10)), start_d);
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(13, 0)), start_d + 6);
|
|
|
|
for (int i = 1; i <= num_lines_d; ++i) {
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(start_line_d + i, 0)),
|
|
|
|
6 + (i * line_length_d) + start_d);
|
|
|
|
}
|
|
|
|
CHECK_EQ(script->GetSourceOffset(v8::debug::Location(start_line_d + 17, 0)),
|
|
|
|
start_d + 158);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakProgramRequested(v8::Local<v8::Context> paused_context,
|
|
|
|
const std::vector<v8::debug::BreakpointId>&
|
|
|
|
inspector_break_points_hit) override {
|
|
|
|
++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);
|
|
|
|
}
|