2008-09-09 20:08:45 +00:00
|
|
|
// Copyright 2006-2008 the V8 project authors. All rights reserved.
|
2008-07-03 15:10:15 +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 "v8.h"
|
|
|
|
|
|
|
|
#include "api.h"
|
|
|
|
#include "arguments.h"
|
|
|
|
#include "bootstrapper.h"
|
|
|
|
#include "code-stubs.h"
|
2010-02-08 14:33:34 +00:00
|
|
|
#include "codegen.h"
|
2009-05-20 20:28:33 +00:00
|
|
|
#include "compilation-cache.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "compiler.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "execution.h"
|
|
|
|
#include "global-handles.h"
|
2009-04-21 14:48:54 +00:00
|
|
|
#include "ic.h"
|
|
|
|
#include "ic-inl.h"
|
2010-03-09 06:38:33 +00:00
|
|
|
#include "messages.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "natives.h"
|
|
|
|
#include "stub-cache.h"
|
2008-07-30 08:49:36 +00:00
|
|
|
#include "log.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-04-29 09:04:20 +00:00
|
|
|
#include "../include/v8-debug.h"
|
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-04-20 16:36:13 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
2008-07-03 15:10:15 +00:00
|
|
|
static void PrintLn(v8::Local<v8::Value> value) {
|
|
|
|
v8::Local<v8::String> s = value->ToString();
|
2010-05-05 12:25:58 +00:00
|
|
|
ScopedVector<char> data(s->Length() + 1);
|
|
|
|
if (data.start() == NULL) {
|
2008-07-03 15:10:15 +00:00
|
|
|
V8::FatalProcessOutOfMemory("PrintLn");
|
|
|
|
return;
|
|
|
|
}
|
2010-05-05 12:25:58 +00:00
|
|
|
s->WriteAscii(data.start());
|
|
|
|
PrintF("%s\n", data.start());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-07 08:27:32 +00:00
|
|
|
static Handle<Code> ComputeCallDebugBreak(int argc, Code::Kind kind) {
|
|
|
|
CALL_HEAP_FUNCTION(StubCache::ComputeCallDebugBreak(argc, kind), Code);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-07 08:27:32 +00:00
|
|
|
static Handle<Code> ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind) {
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
StubCache::ComputeCallDebugPrepareStepIn(argc, kind), Code);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-20 17:15:46 +00:00
|
|
|
static v8::Handle<v8::Context> GetDebugEventContext() {
|
|
|
|
Handle<Context> context = Debug::debugger_entry()->GetContext();
|
|
|
|
// Top::context() may have been NULL when "script collected" event occured.
|
|
|
|
if (*context == NULL) {
|
|
|
|
return v8::Local<v8::Context>();
|
|
|
|
}
|
|
|
|
Handle<Context> global_context(context->global_context());
|
|
|
|
return v8::Utils::ToLocal(global_context);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
BreakLocationIterator::BreakLocationIterator(Handle<DebugInfo> debug_info,
|
|
|
|
BreakLocatorType type) {
|
|
|
|
debug_info_ = debug_info;
|
|
|
|
type_ = type;
|
|
|
|
reloc_iterator_ = NULL;
|
|
|
|
reloc_iterator_original_ = NULL;
|
|
|
|
Reset(); // Initialize the rest of the member variables.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BreakLocationIterator::~BreakLocationIterator() {
|
|
|
|
ASSERT(reloc_iterator_ != NULL);
|
|
|
|
ASSERT(reloc_iterator_original_ != NULL);
|
|
|
|
delete reloc_iterator_;
|
|
|
|
delete reloc_iterator_original_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BreakLocationIterator::Next() {
|
|
|
|
AssertNoAllocation nogc;
|
|
|
|
ASSERT(!RinfoDone());
|
|
|
|
|
|
|
|
// Iterate through reloc info for code and original code stopping at each
|
|
|
|
// breakable code target.
|
|
|
|
bool first = break_point_ == -1;
|
|
|
|
while (!RinfoDone()) {
|
|
|
|
if (!first) RinfoNext();
|
|
|
|
first = false;
|
|
|
|
if (RinfoDone()) return;
|
|
|
|
|
2008-09-18 08:51:43 +00:00
|
|
|
// Whenever a statement position or (plain) position is passed update the
|
|
|
|
// current value of these.
|
2008-09-22 13:57:03 +00:00
|
|
|
if (RelocInfo::IsPosition(rmode())) {
|
|
|
|
if (RelocInfo::IsStatementPosition(rmode())) {
|
2009-11-11 09:50:06 +00:00
|
|
|
statement_position_ = static_cast<int>(
|
|
|
|
rinfo()->data() - debug_info_->shared()->start_position());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2008-09-18 08:51:43 +00:00
|
|
|
// Always update the position as we don't want that to be before the
|
|
|
|
// statement position.
|
2009-11-11 09:50:06 +00:00
|
|
|
position_ = static_cast<int>(
|
|
|
|
rinfo()->data() - debug_info_->shared()->start_position());
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT(position_ >= 0);
|
|
|
|
ASSERT(statement_position_ >= 0);
|
|
|
|
}
|
|
|
|
|
2010-06-08 12:04:49 +00:00
|
|
|
if (IsDebugBreakSlot()) {
|
|
|
|
// There is always a possible break point at a debug break slot.
|
|
|
|
break_point_++;
|
|
|
|
return;
|
|
|
|
} else if (RelocInfo::IsCodeTarget(rmode())) {
|
|
|
|
// Check for breakable code target. Look in the original code as setting
|
|
|
|
// break points can cause the code targets in the running (debugged) code
|
|
|
|
// to be of a different kind than in the original code.
|
2008-07-03 15:10:15 +00:00
|
|
|
Address target = original_rinfo()->target_address();
|
2008-12-09 12:53:59 +00:00
|
|
|
Code* code = Code::GetCodeFromTargetAddress(target);
|
2010-03-01 16:24:05 +00:00
|
|
|
if ((code->is_inline_cache_stub() &&
|
|
|
|
code->kind() != Code::BINARY_OP_IC) ||
|
|
|
|
RelocInfo::IsConstructCall(rmode())) {
|
2008-07-03 15:10:15 +00:00
|
|
|
break_point_++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (code->kind() == Code::STUB) {
|
2009-09-07 07:20:05 +00:00
|
|
|
if (IsDebuggerStatement()) {
|
|
|
|
break_point_++;
|
|
|
|
return;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
if (type_ == ALL_BREAK_LOCATIONS) {
|
|
|
|
if (Debug::IsBreakStub(code)) {
|
|
|
|
break_point_++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ASSERT(type_ == SOURCE_BREAK_LOCATIONS);
|
|
|
|
if (Debug::IsSourceBreakStub(code)) {
|
|
|
|
break_point_++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for break at return.
|
2008-09-22 13:57:03 +00:00
|
|
|
if (RelocInfo::IsJSReturn(rmode())) {
|
2008-07-03 15:10:15 +00:00
|
|
|
// Set the positions to the end of the function.
|
|
|
|
if (debug_info_->shared()->HasSourceCode()) {
|
|
|
|
position_ = debug_info_->shared()->end_position() -
|
|
|
|
debug_info_->shared()->start_position();
|
|
|
|
} else {
|
|
|
|
position_ = 0;
|
|
|
|
}
|
|
|
|
statement_position_ = position_;
|
|
|
|
break_point_++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BreakLocationIterator::Next(int count) {
|
|
|
|
while (count > 0) {
|
|
|
|
Next();
|
|
|
|
count--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Find the break point closest to the supplied address.
|
|
|
|
void BreakLocationIterator::FindBreakLocationFromAddress(Address pc) {
|
|
|
|
// Run through all break points to locate the one closest to the address.
|
|
|
|
int closest_break_point = 0;
|
|
|
|
int distance = kMaxInt;
|
|
|
|
while (!Done()) {
|
|
|
|
// Check if this break point is closer that what was previously found.
|
|
|
|
if (this->pc() < pc && pc - this->pc() < distance) {
|
|
|
|
closest_break_point = break_point();
|
2009-11-11 09:50:06 +00:00
|
|
|
distance = static_cast<int>(pc - this->pc());
|
2008-07-03 15:10:15 +00:00
|
|
|
// Check whether we can't get any closer.
|
|
|
|
if (distance == 0) break;
|
|
|
|
}
|
|
|
|
Next();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move to the break point found.
|
|
|
|
Reset();
|
|
|
|
Next(closest_break_point);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Find the break point closest to the supplied source position.
|
|
|
|
void BreakLocationIterator::FindBreakLocationFromPosition(int position) {
|
|
|
|
// Run through all break points to locate the one closest to the source
|
|
|
|
// position.
|
|
|
|
int closest_break_point = 0;
|
|
|
|
int distance = kMaxInt;
|
|
|
|
while (!Done()) {
|
|
|
|
// Check if this break point is closer that what was previously found.
|
|
|
|
if (position <= statement_position() &&
|
|
|
|
statement_position() - position < distance) {
|
|
|
|
closest_break_point = break_point();
|
|
|
|
distance = statement_position() - position;
|
|
|
|
// Check whether we can't get any closer.
|
|
|
|
if (distance == 0) break;
|
|
|
|
}
|
|
|
|
Next();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move to the break point found.
|
|
|
|
Reset();
|
|
|
|
Next(closest_break_point);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BreakLocationIterator::Reset() {
|
|
|
|
// Create relocation iterators for the two code objects.
|
|
|
|
if (reloc_iterator_ != NULL) delete reloc_iterator_;
|
|
|
|
if (reloc_iterator_original_ != NULL) delete reloc_iterator_original_;
|
|
|
|
reloc_iterator_ = new RelocIterator(debug_info_->code());
|
|
|
|
reloc_iterator_original_ = new RelocIterator(debug_info_->original_code());
|
|
|
|
|
|
|
|
// Position at the first break point.
|
|
|
|
break_point_ = -1;
|
|
|
|
position_ = 1;
|
|
|
|
statement_position_ = 1;
|
|
|
|
Next();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool BreakLocationIterator::Done() const {
|
|
|
|
return RinfoDone();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BreakLocationIterator::SetBreakPoint(Handle<Object> break_point_object) {
|
|
|
|
// If there is not already a real break point here patch code with debug
|
|
|
|
// break.
|
|
|
|
if (!HasBreakPoint()) {
|
|
|
|
SetDebugBreak();
|
|
|
|
}
|
2009-09-07 07:20:05 +00:00
|
|
|
ASSERT(IsDebugBreak() || IsDebuggerStatement());
|
2008-07-03 15:10:15 +00:00
|
|
|
// Set the break point information.
|
|
|
|
DebugInfo::SetBreakPoint(debug_info_, code_position(),
|
|
|
|
position(), statement_position(),
|
|
|
|
break_point_object);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BreakLocationIterator::ClearBreakPoint(Handle<Object> break_point_object) {
|
|
|
|
// Clear the break point information.
|
|
|
|
DebugInfo::ClearBreakPoint(debug_info_, code_position(), break_point_object);
|
|
|
|
// If there are no more break points here remove the debug break.
|
|
|
|
if (!HasBreakPoint()) {
|
|
|
|
ClearDebugBreak();
|
|
|
|
ASSERT(!IsDebugBreak());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BreakLocationIterator::SetOneShot() {
|
2009-09-07 07:20:05 +00:00
|
|
|
// Debugger statement always calls debugger. No need to modify it.
|
|
|
|
if (IsDebuggerStatement()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// If there is a real break point here no more to do.
|
|
|
|
if (HasBreakPoint()) {
|
|
|
|
ASSERT(IsDebugBreak());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Patch code with debug break.
|
|
|
|
SetDebugBreak();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BreakLocationIterator::ClearOneShot() {
|
2009-09-07 07:20:05 +00:00
|
|
|
// Debugger statement always calls debugger. No need to modify it.
|
|
|
|
if (IsDebuggerStatement()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// If there is a real break point here no more to do.
|
|
|
|
if (HasBreakPoint()) {
|
|
|
|
ASSERT(IsDebugBreak());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Patch code removing debug break.
|
|
|
|
ClearDebugBreak();
|
|
|
|
ASSERT(!IsDebugBreak());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BreakLocationIterator::SetDebugBreak() {
|
2009-09-07 07:20:05 +00:00
|
|
|
// Debugger statement always calls debugger. No need to modify it.
|
|
|
|
if (IsDebuggerStatement()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// If there is already a break point here just return. This might happen if
|
2008-09-01 09:16:49 +00:00
|
|
|
// the same code is flooded with break points twice. Flooding the same
|
2008-07-03 15:10:15 +00:00
|
|
|
// function twice might happen when stepping in a function with an exception
|
|
|
|
// handler as the handler and the function is the same.
|
|
|
|
if (IsDebugBreak()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-09-22 13:57:03 +00:00
|
|
|
if (RelocInfo::IsJSReturn(rmode())) {
|
2009-02-09 12:17:39 +00:00
|
|
|
// Patch the frame exit code with a break point.
|
|
|
|
SetDebugBreakAtReturn();
|
2010-06-08 12:04:49 +00:00
|
|
|
} else if (IsDebugBreakSlot()) {
|
|
|
|
// Patch the code in the break slot.
|
|
|
|
SetDebugBreakAtSlot();
|
2008-07-03 15:10:15 +00:00
|
|
|
} else {
|
2009-04-21 14:48:54 +00:00
|
|
|
// Patch the IC call.
|
|
|
|
SetDebugBreakAtIC();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
ASSERT(IsDebugBreak());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BreakLocationIterator::ClearDebugBreak() {
|
2009-09-07 07:20:05 +00:00
|
|
|
// Debugger statement always calls debugger. No need to modify it.
|
|
|
|
if (IsDebuggerStatement()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-09-22 13:57:03 +00:00
|
|
|
if (RelocInfo::IsJSReturn(rmode())) {
|
2009-02-09 12:17:39 +00:00
|
|
|
// Restore the frame exit code.
|
|
|
|
ClearDebugBreakAtReturn();
|
2010-06-08 12:04:49 +00:00
|
|
|
} else if (IsDebugBreakSlot()) {
|
|
|
|
// Restore the code in the break slot.
|
|
|
|
ClearDebugBreakAtSlot();
|
2008-07-03 15:10:15 +00:00
|
|
|
} else {
|
2009-04-21 14:48:54 +00:00
|
|
|
// Patch the IC call.
|
|
|
|
ClearDebugBreakAtIC();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
ASSERT(!IsDebugBreak());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BreakLocationIterator::PrepareStepIn() {
|
2009-02-13 12:36:58 +00:00
|
|
|
HandleScope scope;
|
|
|
|
|
2009-09-07 07:20:05 +00:00
|
|
|
// Step in can only be prepared if currently positioned on an IC call,
|
|
|
|
// construct call or CallFunction stub call.
|
2008-07-03 15:10:15 +00:00
|
|
|
Address target = rinfo()->target_address();
|
2009-09-07 07:20:05 +00:00
|
|
|
Handle<Code> code(Code::GetCodeFromTargetAddress(target));
|
2010-06-07 08:27:32 +00:00
|
|
|
if (code->is_call_stub() || code->is_keyed_call_stub()) {
|
2008-07-03 15:10:15 +00:00
|
|
|
// Step in through IC call is handled by the runtime system. Therefore make
|
|
|
|
// sure that the any current IC is cleared and the runtime system is
|
|
|
|
// called. If the executing code has a debug break at the location change
|
|
|
|
// the call in the original code as it is the code there that will be
|
|
|
|
// executed in place of the debug break call.
|
2010-06-07 08:27:32 +00:00
|
|
|
Handle<Code> stub = ComputeCallDebugPrepareStepIn(code->arguments_count(),
|
|
|
|
code->kind());
|
2008-07-03 15:10:15 +00:00
|
|
|
if (IsDebugBreak()) {
|
|
|
|
original_rinfo()->set_target_address(stub->entry());
|
|
|
|
} else {
|
|
|
|
rinfo()->set_target_address(stub->entry());
|
|
|
|
}
|
|
|
|
} else {
|
2009-09-07 07:20:05 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
// All the following stuff is needed only for assertion checks so the code
|
|
|
|
// is wrapped in ifdef.
|
|
|
|
Handle<Code> maybe_call_function_stub = code;
|
|
|
|
if (IsDebugBreak()) {
|
|
|
|
Address original_target = original_rinfo()->target_address();
|
|
|
|
maybe_call_function_stub =
|
|
|
|
Handle<Code>(Code::GetCodeFromTargetAddress(original_target));
|
|
|
|
}
|
|
|
|
bool is_call_function_stub =
|
|
|
|
(maybe_call_function_stub->kind() == Code::STUB &&
|
|
|
|
maybe_call_function_stub->major_key() == CodeStub::CallFunction);
|
|
|
|
|
2009-07-16 07:07:51 +00:00
|
|
|
// Step in through construct call requires no changes to the running code.
|
|
|
|
// Step in through getters/setters should already be prepared as well
|
|
|
|
// because caller of this function (Debug::PrepareStep) is expected to
|
|
|
|
// flood the top frame's function with one shot breakpoints.
|
2009-09-07 07:20:05 +00:00
|
|
|
// Step in through CallFunction stub should also be prepared by caller of
|
|
|
|
// this function (Debug::PrepareStep) which should flood target function
|
|
|
|
// with breakpoints.
|
|
|
|
ASSERT(RelocInfo::IsConstructCall(rmode()) || code->is_inline_cache_stub()
|
|
|
|
|| is_call_function_stub);
|
|
|
|
#endif
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check whether the break point is at a position which will exit the function.
|
|
|
|
bool BreakLocationIterator::IsExit() const {
|
2008-09-22 13:57:03 +00:00
|
|
|
return (RelocInfo::IsJSReturn(rmode()));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool BreakLocationIterator::HasBreakPoint() {
|
|
|
|
return debug_info_->HasBreakPoint(code_position());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check whether there is a debug break at the current position.
|
|
|
|
bool BreakLocationIterator::IsDebugBreak() {
|
2008-09-22 13:57:03 +00:00
|
|
|
if (RelocInfo::IsJSReturn(rmode())) {
|
2009-02-09 12:17:39 +00:00
|
|
|
return IsDebugBreakAtReturn();
|
2010-06-08 12:04:49 +00:00
|
|
|
} else if (IsDebugBreakSlot()) {
|
|
|
|
return IsDebugBreakAtSlot();
|
2008-07-03 15:10:15 +00:00
|
|
|
} else {
|
|
|
|
return Debug::IsDebugBreak(rinfo()->target_address());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-21 14:48:54 +00:00
|
|
|
void BreakLocationIterator::SetDebugBreakAtIC() {
|
|
|
|
// Patch the original code with the current address as the current address
|
|
|
|
// might have changed by the inline caching since the code was copied.
|
|
|
|
original_rinfo()->set_target_address(rinfo()->target_address());
|
|
|
|
|
|
|
|
RelocInfo::Mode mode = rmode();
|
|
|
|
if (RelocInfo::IsCodeTarget(mode)) {
|
|
|
|
Address target = rinfo()->target_address();
|
|
|
|
Handle<Code> code(Code::GetCodeFromTargetAddress(target));
|
|
|
|
|
|
|
|
// Patch the code to invoke the builtin debug break function matching the
|
|
|
|
// calling convention used by the call site.
|
|
|
|
Handle<Code> dbgbrk_code(Debug::FindDebugBreak(code, mode));
|
|
|
|
rinfo()->set_target_address(dbgbrk_code->entry());
|
|
|
|
|
|
|
|
// For stubs that refer back to an inlined version clear the cached map for
|
|
|
|
// the inlined case to always go through the IC. As long as the break point
|
|
|
|
// is set the patching performed by the runtime system will take place in
|
|
|
|
// the code copy and will therefore have no effect on the running code
|
|
|
|
// keeping it from using the inlined code.
|
2010-05-06 10:50:22 +00:00
|
|
|
if (code->is_keyed_load_stub()) {
|
|
|
|
KeyedLoadIC::ClearInlinedVersion(pc());
|
|
|
|
} else if (code->is_keyed_store_stub()) {
|
|
|
|
KeyedStoreIC::ClearInlinedVersion(pc());
|
|
|
|
} else if (code->is_load_stub()) {
|
|
|
|
LoadIC::ClearInlinedVersion(pc());
|
|
|
|
}
|
2009-04-21 14:48:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BreakLocationIterator::ClearDebugBreakAtIC() {
|
|
|
|
// Patch the code to the original invoke.
|
|
|
|
rinfo()->set_target_address(original_rinfo()->target_address());
|
2009-06-12 11:24:13 +00:00
|
|
|
|
|
|
|
RelocInfo::Mode mode = rmode();
|
|
|
|
if (RelocInfo::IsCodeTarget(mode)) {
|
2010-07-06 12:10:49 +00:00
|
|
|
AssertNoAllocation nogc;
|
2009-06-12 11:24:13 +00:00
|
|
|
Address target = original_rinfo()->target_address();
|
2010-07-06 12:10:49 +00:00
|
|
|
Code* code = Code::GetCodeFromTargetAddress(target);
|
2009-06-12 11:24:13 +00:00
|
|
|
|
|
|
|
// Restore the inlined version of keyed stores to get back to the
|
|
|
|
// fast case. We need to patch back the keyed store because no
|
|
|
|
// patching happens when running normally. For keyed loads, the
|
|
|
|
// map check will get patched back when running normally after ICs
|
|
|
|
// have been cleared at GC.
|
|
|
|
if (code->is_keyed_store_stub()) KeyedStoreIC::RestoreInlinedVersion(pc());
|
|
|
|
}
|
2009-04-21 14:48:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-07 07:20:05 +00:00
|
|
|
bool BreakLocationIterator::IsDebuggerStatement() {
|
2010-02-08 13:44:49 +00:00
|
|
|
return RelocInfo::DEBUG_BREAK == rmode();
|
2009-09-07 07:20:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-08 12:04:49 +00:00
|
|
|
bool BreakLocationIterator::IsDebugBreakSlot() {
|
|
|
|
return RelocInfo::DEBUG_BREAK_SLOT == rmode();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Object* BreakLocationIterator::BreakPointObjects() {
|
|
|
|
return debug_info_->GetBreakPointObjects(code_position());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-13 12:36:58 +00:00
|
|
|
// Clear out all the debug break code. This is ONLY supposed to be used when
|
|
|
|
// shutting down the debugger as it will leave the break point information in
|
|
|
|
// DebugInfo even though the code is patched back to the non break point state.
|
|
|
|
void BreakLocationIterator::ClearAllDebugBreak() {
|
|
|
|
while (!Done()) {
|
|
|
|
ClearDebugBreak();
|
|
|
|
Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
bool BreakLocationIterator::RinfoDone() const {
|
|
|
|
ASSERT(reloc_iterator_->done() == reloc_iterator_original_->done());
|
|
|
|
return reloc_iterator_->done();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BreakLocationIterator::RinfoNext() {
|
|
|
|
reloc_iterator_->next();
|
|
|
|
reloc_iterator_original_->next();
|
|
|
|
#ifdef DEBUG
|
|
|
|
ASSERT(reloc_iterator_->done() == reloc_iterator_original_->done());
|
|
|
|
if (!reloc_iterator_->done()) {
|
|
|
|
ASSERT(rmode() == original_rmode());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Debug::has_break_points_ = false;
|
2009-05-18 13:14:37 +00:00
|
|
|
ScriptCache* Debug::script_cache_ = NULL;
|
2008-07-03 15:10:15 +00:00
|
|
|
DebugInfoListNode* Debug::debug_info_list_ = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
// Threading support.
|
|
|
|
void Debug::ThreadInit() {
|
2009-03-06 11:03:14 +00:00
|
|
|
thread_local_.break_count_ = 0;
|
|
|
|
thread_local_.break_id_ = 0;
|
|
|
|
thread_local_.break_frame_id_ = StackFrame::NO_ID;
|
2008-07-03 15:10:15 +00:00
|
|
|
thread_local_.last_step_action_ = StepNone;
|
2008-09-22 13:57:03 +00:00
|
|
|
thread_local_.last_statement_position_ = RelocInfo::kNoPosition;
|
2008-07-03 15:10:15 +00:00
|
|
|
thread_local_.step_count_ = 0;
|
|
|
|
thread_local_.last_fp_ = 0;
|
|
|
|
thread_local_.step_into_fp_ = 0;
|
2009-09-09 08:40:59 +00:00
|
|
|
thread_local_.step_out_fp_ = 0;
|
2008-07-03 15:10:15 +00:00
|
|
|
thread_local_.after_break_target_ = 0;
|
2009-03-06 11:03:14 +00:00
|
|
|
thread_local_.debugger_entry_ = NULL;
|
2009-05-29 08:42:02 +00:00
|
|
|
thread_local_.pending_interrupts_ = 0;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
JSCallerSavedBuffer Debug::registers_;
|
|
|
|
Debug::ThreadLocal Debug::thread_local_;
|
|
|
|
|
|
|
|
|
|
|
|
char* Debug::ArchiveDebug(char* storage) {
|
|
|
|
char* to = storage;
|
|
|
|
memcpy(to, reinterpret_cast<char*>(&thread_local_), sizeof(ThreadLocal));
|
|
|
|
to += sizeof(ThreadLocal);
|
|
|
|
memcpy(to, reinterpret_cast<char*>(®isters_), sizeof(registers_));
|
|
|
|
ThreadInit();
|
|
|
|
ASSERT(to <= storage + ArchiveSpacePerThread());
|
|
|
|
return storage + ArchiveSpacePerThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char* Debug::RestoreDebug(char* storage) {
|
|
|
|
char* from = storage;
|
|
|
|
memcpy(reinterpret_cast<char*>(&thread_local_), from, sizeof(ThreadLocal));
|
|
|
|
from += sizeof(ThreadLocal);
|
|
|
|
memcpy(reinterpret_cast<char*>(®isters_), from, sizeof(registers_));
|
|
|
|
ASSERT(from <= storage + ArchiveSpacePerThread());
|
|
|
|
return storage + ArchiveSpacePerThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Debug::ArchiveSpacePerThread() {
|
|
|
|
return sizeof(ThreadLocal) + sizeof(registers_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-09 11:06:54 +00:00
|
|
|
// Default break enabled.
|
|
|
|
bool Debug::disable_break_ = false;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Default call debugger on uncaught exception.
|
|
|
|
bool Debug::break_on_exception_ = false;
|
|
|
|
bool Debug::break_on_uncaught_exception_ = true;
|
|
|
|
|
|
|
|
Handle<Context> Debug::debug_context_ = Handle<Context>();
|
|
|
|
Code* Debug::debug_break_return_ = NULL;
|
2010-06-08 12:04:49 +00:00
|
|
|
Code* Debug::debug_break_slot_ = NULL;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2009-05-18 13:14:37 +00:00
|
|
|
void ScriptCache::Add(Handle<Script> script) {
|
|
|
|
// Create an entry in the hash map for the script.
|
|
|
|
int id = Smi::cast(script->id())->value();
|
|
|
|
HashMap::Entry* entry =
|
|
|
|
HashMap::Lookup(reinterpret_cast<void*>(id), Hash(id), true);
|
|
|
|
if (entry->value != NULL) {
|
|
|
|
ASSERT(*script == *reinterpret_cast<Script**>(entry->value));
|
|
|
|
return;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2009-05-18 13:14:37 +00:00
|
|
|
|
|
|
|
// Globalize the script object, make it weak and use the location of the
|
|
|
|
// global handle as the value in the hash map.
|
|
|
|
Handle<Script> script_ =
|
|
|
|
Handle<Script>::cast((GlobalHandles::Create(*script)));
|
|
|
|
GlobalHandles::MakeWeak(reinterpret_cast<Object**>(script_.location()),
|
|
|
|
this, ScriptCache::HandleWeakScript);
|
|
|
|
entry->value = script_.location();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-18 13:14:37 +00:00
|
|
|
Handle<FixedArray> ScriptCache::GetScripts() {
|
|
|
|
Handle<FixedArray> instances = Factory::NewFixedArray(occupancy());
|
|
|
|
int count = 0;
|
|
|
|
for (HashMap::Entry* entry = Start(); entry != NULL; entry = Next(entry)) {
|
|
|
|
ASSERT(entry->value != NULL);
|
|
|
|
if (entry->value != NULL) {
|
|
|
|
instances->set(count, *reinterpret_cast<Script**>(entry->value));
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return instances;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-18 13:14:37 +00:00
|
|
|
void ScriptCache::ProcessCollectedScripts() {
|
|
|
|
for (int i = 0; i < collected_scripts_.length(); i++) {
|
|
|
|
Debugger::OnScriptCollected(collected_scripts_[i]);
|
|
|
|
}
|
|
|
|
collected_scripts_.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ScriptCache::Clear() {
|
|
|
|
// Iterate the script cache to get rid of all the weak handles.
|
|
|
|
for (HashMap::Entry* entry = Start(); entry != NULL; entry = Next(entry)) {
|
|
|
|
ASSERT(entry != NULL);
|
|
|
|
Object** location = reinterpret_cast<Object**>(entry->value);
|
|
|
|
ASSERT((*location)->IsScript());
|
|
|
|
GlobalHandles::ClearWeakness(location);
|
|
|
|
GlobalHandles::Destroy(location);
|
|
|
|
}
|
|
|
|
// Clear the content of the hash map.
|
|
|
|
HashMap::Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ScriptCache::HandleWeakScript(v8::Persistent<v8::Value> obj, void* data) {
|
|
|
|
ScriptCache* script_cache = reinterpret_cast<ScriptCache*>(data);
|
|
|
|
// Find the location of the global handle.
|
|
|
|
Script** location =
|
|
|
|
reinterpret_cast<Script**>(Utils::OpenHandle(*obj).location());
|
|
|
|
ASSERT((*location)->IsScript());
|
|
|
|
|
|
|
|
// Remove the entry from the cache.
|
|
|
|
int id = Smi::cast((*location)->id())->value();
|
|
|
|
script_cache->Remove(reinterpret_cast<void*>(id), Hash(id));
|
|
|
|
script_cache->collected_scripts_.Add(id);
|
|
|
|
|
|
|
|
// Clear the weak handle.
|
|
|
|
obj.Dispose();
|
|
|
|
obj.Clear();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Debug::Setup(bool create_heap_objects) {
|
|
|
|
ThreadInit();
|
|
|
|
if (create_heap_objects) {
|
|
|
|
// Get code to handle debug break on return.
|
|
|
|
debug_break_return_ =
|
|
|
|
Builtins::builtin(Builtins::Return_DebugBreak);
|
|
|
|
ASSERT(debug_break_return_->IsCode());
|
2010-06-08 12:04:49 +00:00
|
|
|
// Get code to handle debug break in debug break slots.
|
|
|
|
debug_break_slot_ =
|
|
|
|
Builtins::builtin(Builtins::Slot_DebugBreak);
|
|
|
|
ASSERT(debug_break_slot_->IsCode());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-18 13:14:37 +00:00
|
|
|
void Debug::HandleWeakDebugInfo(v8::Persistent<v8::Value> obj, void* data) {
|
|
|
|
DebugInfoListNode* node = reinterpret_cast<DebugInfoListNode*>(data);
|
2010-07-01 11:48:45 +00:00
|
|
|
// We need to clear all breakpoints associated with the function to restore
|
|
|
|
// original code and avoid patching the code twice later because
|
|
|
|
// the function will live in the heap until next gc, and can be found by
|
|
|
|
// Runtime::FindSharedFunctionInfoInScript.
|
|
|
|
BreakLocationIterator it(node->debug_info(), ALL_BREAK_LOCATIONS);
|
|
|
|
it.ClearAllDebugBreak();
|
2009-05-18 13:14:37 +00:00
|
|
|
RemoveDebugInfo(node->debug_info());
|
|
|
|
#ifdef DEBUG
|
|
|
|
node = Debug::debug_info_list_;
|
|
|
|
while (node != NULL) {
|
|
|
|
ASSERT(node != reinterpret_cast<DebugInfoListNode*>(data));
|
|
|
|
node = node->next();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DebugInfoListNode::DebugInfoListNode(DebugInfo* debug_info): next_(NULL) {
|
|
|
|
// Globalize the request debug info object and make it weak.
|
|
|
|
debug_info_ = Handle<DebugInfo>::cast((GlobalHandles::Create(debug_info)));
|
|
|
|
GlobalHandles::MakeWeak(reinterpret_cast<Object**>(debug_info_.location()),
|
|
|
|
this, Debug::HandleWeakDebugInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DebugInfoListNode::~DebugInfoListNode() {
|
|
|
|
GlobalHandles::Destroy(reinterpret_cast<Object**>(debug_info_.location()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
bool Debug::CompileDebuggerScript(int index) {
|
|
|
|
HandleScope scope;
|
|
|
|
|
2008-07-25 07:37:58 +00:00
|
|
|
// Bail out if the index is invalid.
|
2008-07-03 15:10:15 +00:00
|
|
|
if (index == -1) {
|
|
|
|
return false;
|
|
|
|
}
|
2008-07-25 07:37:58 +00:00
|
|
|
|
|
|
|
// Find source and name for the requested script.
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<String> source_code = Bootstrapper::NativesSourceLookup(index);
|
|
|
|
Vector<const char> name = Natives::GetScriptName(index);
|
|
|
|
Handle<String> script_name = Factory::NewStringFromAscii(name);
|
|
|
|
|
|
|
|
// Compile the script.
|
|
|
|
bool allow_natives_syntax = FLAG_allow_natives_syntax;
|
|
|
|
FLAG_allow_natives_syntax = true;
|
2010-03-23 06:04:44 +00:00
|
|
|
Handle<SharedFunctionInfo> function_info;
|
|
|
|
function_info = Compiler::Compile(source_code,
|
|
|
|
script_name,
|
|
|
|
0, 0, NULL, NULL,
|
|
|
|
Handle<String>::null(),
|
|
|
|
NATIVES_CODE);
|
2008-07-03 15:10:15 +00:00
|
|
|
FLAG_allow_natives_syntax = allow_natives_syntax;
|
|
|
|
|
|
|
|
// Silently ignore stack overflows during compilation.
|
2010-03-23 06:04:44 +00:00
|
|
|
if (function_info.is_null()) {
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT(Top::has_pending_exception());
|
|
|
|
Top::clear_pending_exception();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-03-23 06:04:44 +00:00
|
|
|
// Execute the shared function in the debugger context.
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<Context> context = Top::global_context();
|
2008-07-25 07:37:58 +00:00
|
|
|
bool caught_exception = false;
|
|
|
|
Handle<JSFunction> function =
|
2010-03-23 06:04:44 +00:00
|
|
|
Factory::NewFunctionFromSharedFunctionInfo(function_info, context);
|
2008-07-25 07:37:58 +00:00
|
|
|
Handle<Object> result =
|
|
|
|
Execution::TryCall(function, Handle<Object>(context->global()),
|
|
|
|
0, NULL, &caught_exception);
|
|
|
|
|
|
|
|
// Check for caught exceptions.
|
2008-07-03 15:10:15 +00:00
|
|
|
if (caught_exception) {
|
2008-09-09 18:55:41 +00:00
|
|
|
Handle<Object> message = MessageHandler::MakeMessageObject(
|
2009-09-01 13:55:45 +00:00
|
|
|
"error_loading_debugger", NULL, Vector<Handle<Object> >::empty(),
|
2010-07-12 13:17:27 +00:00
|
|
|
Handle<String>(), Handle<JSArray>());
|
2008-09-09 18:55:41 +00:00
|
|
|
MessageHandler::ReportMessage(NULL, message);
|
2008-07-03 15:10:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-07-25 07:37:58 +00:00
|
|
|
// Mark this script as native and return successfully.
|
|
|
|
Handle<Script> script(Script::cast(function->shared()->script()));
|
2010-03-23 12:31:52 +00:00
|
|
|
script->set_type(Smi::FromInt(Script::TYPE_NATIVE));
|
2008-07-03 15:10:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Debug::Load() {
|
|
|
|
// Return if debugger is already loaded.
|
2008-07-16 07:07:30 +00:00
|
|
|
if (IsLoaded()) return true;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-07-25 07:37:58 +00:00
|
|
|
// Bail out if we're already in the process of compiling the native
|
|
|
|
// JavaScript source code for the debugger.
|
2008-08-14 13:41:48 +00:00
|
|
|
if (Debugger::compiling_natives() || Debugger::is_loading_debugger())
|
|
|
|
return false;
|
|
|
|
Debugger::set_loading_debugger(true);
|
2008-07-25 07:37:58 +00:00
|
|
|
|
|
|
|
// Disable breakpoints and interrupts while compiling and running the
|
|
|
|
// debugger scripts including the context creation code.
|
|
|
|
DisableBreak disable(true);
|
|
|
|
PostponeInterruptsScope postpone;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Create the debugger context.
|
|
|
|
HandleScope scope;
|
2008-07-25 07:37:58 +00:00
|
|
|
Handle<Context> context =
|
|
|
|
Bootstrapper::CreateEnvironment(Handle<Object>::null(),
|
|
|
|
v8::Handle<ObjectTemplate>(),
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
// Use the debugger context.
|
2008-07-03 15:10:15 +00:00
|
|
|
SaveContext save;
|
2008-07-25 07:37:58 +00:00
|
|
|
Top::set_context(*context);
|
|
|
|
|
|
|
|
// Expose the builtins object in the debugger context.
|
|
|
|
Handle<String> key = Factory::LookupAsciiSymbol("builtins");
|
|
|
|
Handle<GlobalObject> global = Handle<GlobalObject>(context->global());
|
|
|
|
SetProperty(global, key, Handle<Object>(global->builtins()), NONE);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Compile the JavaScript for the debugger in the debugger context.
|
|
|
|
Debugger::set_compiling_natives(true);
|
2008-07-25 07:37:58 +00:00
|
|
|
bool caught_exception =
|
|
|
|
!CompileDebuggerScript(Natives::GetIndex("mirror")) ||
|
|
|
|
!CompileDebuggerScript(Natives::GetIndex("debug"));
|
2010-03-05 22:08:58 +00:00
|
|
|
|
|
|
|
if (FLAG_enable_liveedit) {
|
|
|
|
caught_exception = caught_exception ||
|
|
|
|
!CompileDebuggerScript(Natives::GetIndex("liveedit"));
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Debugger::set_compiling_natives(false);
|
|
|
|
|
2008-08-14 13:41:48 +00:00
|
|
|
// Make sure we mark the debugger as not loading before we might
|
|
|
|
// return.
|
|
|
|
Debugger::set_loading_debugger(false);
|
|
|
|
|
2008-07-25 07:37:58 +00:00
|
|
|
// Check for caught exceptions.
|
|
|
|
if (caught_exception) return false;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Debugger loaded.
|
2008-07-25 07:37:58 +00:00
|
|
|
debug_context_ = Handle<Context>::cast(GlobalHandles::Create(*context));
|
2009-05-18 13:14:37 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Debug::Unload() {
|
|
|
|
// Return debugger is not loaded.
|
|
|
|
if (!IsLoaded()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-18 13:14:37 +00:00
|
|
|
// Clear the script cache.
|
|
|
|
DestroyScriptCache();
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Clear debugger context global handle.
|
|
|
|
GlobalHandles::Destroy(reinterpret_cast<Object**>(debug_context_.location()));
|
|
|
|
debug_context_ = Handle<Context>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-06 11:03:14 +00:00
|
|
|
// Set the flag indicating that preemption happened during debugging.
|
|
|
|
void Debug::PreemptionWhileInDebugger() {
|
|
|
|
ASSERT(InDebugger());
|
2009-05-29 08:42:02 +00:00
|
|
|
Debug::set_interrupts_pending(PREEMPT);
|
2009-03-06 11:03:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void Debug::Iterate(ObjectVisitor* v) {
|
2010-03-12 10:20:01 +00:00
|
|
|
v->VisitPointer(BitCast<Object**, Code**>(&(debug_break_return_)));
|
2010-06-08 12:04:49 +00:00
|
|
|
v->VisitPointer(BitCast<Object**, Code**>(&(debug_break_slot_)));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Object* Debug::Break(Arguments args) {
|
|
|
|
HandleScope scope;
|
2008-08-13 09:32:07 +00:00
|
|
|
ASSERT(args.length() == 0);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-06-30 17:29:00 +00:00
|
|
|
thread_local_.frame_drop_mode_ = FRAMES_UNTOUCHED;
|
2010-04-06 17:58:28 +00:00
|
|
|
|
2008-07-09 11:06:54 +00:00
|
|
|
// Get the top-most JavaScript frame.
|
|
|
|
JavaScriptFrameIterator it;
|
|
|
|
JavaScriptFrame* frame = it.frame();
|
|
|
|
|
|
|
|
// Just continue if breaks are disabled or debugger cannot be loaded.
|
|
|
|
if (disable_break() || !Load()) {
|
|
|
|
SetAfterBreakTarget(frame);
|
2008-08-13 09:32:07 +00:00
|
|
|
return Heap::undefined_value();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2008-10-03 09:57:18 +00:00
|
|
|
// Enter the debugger.
|
|
|
|
EnterDebugger debugger;
|
|
|
|
if (debugger.FailedToEnter()) {
|
|
|
|
return Heap::undefined_value();
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-07-25 07:37:58 +00:00
|
|
|
// Postpone interrupt during breakpoint processing.
|
|
|
|
PostponeInterruptsScope postpone;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Get the debug info (create it if it does not exist).
|
|
|
|
Handle<SharedFunctionInfo> shared =
|
|
|
|
Handle<SharedFunctionInfo>(JSFunction::cast(frame->function())->shared());
|
|
|
|
Handle<DebugInfo> debug_info = GetDebugInfo(shared);
|
|
|
|
|
|
|
|
// Find the break point where execution has stopped.
|
|
|
|
BreakLocationIterator break_location_iterator(debug_info,
|
|
|
|
ALL_BREAK_LOCATIONS);
|
|
|
|
break_location_iterator.FindBreakLocationFromAddress(frame->pc());
|
|
|
|
|
|
|
|
// Check whether step next reached a new statement.
|
|
|
|
if (!StepNextContinue(&break_location_iterator, frame)) {
|
|
|
|
// Decrease steps left if performing multiple steps.
|
|
|
|
if (thread_local_.step_count_ > 0) {
|
|
|
|
thread_local_.step_count_--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is one or more real break points check whether any of these are
|
|
|
|
// triggered.
|
|
|
|
Handle<Object> break_points_hit(Heap::undefined_value());
|
|
|
|
if (break_location_iterator.HasBreakPoint()) {
|
|
|
|
Handle<Object> break_point_objects =
|
|
|
|
Handle<Object>(break_location_iterator.BreakPointObjects());
|
|
|
|
break_points_hit = CheckBreakPoints(break_point_objects);
|
|
|
|
}
|
|
|
|
|
2009-09-09 08:40:59 +00:00
|
|
|
// If step out is active skip everything until the frame where we need to step
|
|
|
|
// out to is reached, unless real breakpoint is hit.
|
|
|
|
if (Debug::StepOutActive() && frame->fp() != Debug::step_out_fp() &&
|
|
|
|
break_points_hit->IsUndefined() ) {
|
|
|
|
// Step count should always be 0 for StepOut.
|
|
|
|
ASSERT(thread_local_.step_count_ == 0);
|
|
|
|
} else if (!break_points_hit->IsUndefined() ||
|
|
|
|
(thread_local_.last_step_action_ != StepNone &&
|
|
|
|
thread_local_.step_count_ == 0)) {
|
|
|
|
// Notify debugger if a real break point is triggered or if performing
|
|
|
|
// single stepping with no more steps to perform. Otherwise do another step.
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Clear all current stepping setup.
|
|
|
|
ClearStepping();
|
|
|
|
|
|
|
|
// Notify the debug event listeners.
|
2009-03-13 13:26:21 +00:00
|
|
|
Debugger::OnDebugBreak(break_points_hit, false);
|
2008-07-03 15:10:15 +00:00
|
|
|
} else if (thread_local_.last_step_action_ != StepNone) {
|
|
|
|
// Hold on to last step action as it is cleared by the call to
|
|
|
|
// ClearStepping.
|
|
|
|
StepAction step_action = thread_local_.last_step_action_;
|
|
|
|
int step_count = thread_local_.step_count_;
|
|
|
|
|
|
|
|
// Clear all current stepping setup.
|
|
|
|
ClearStepping();
|
|
|
|
|
|
|
|
// Set up for the remaining steps.
|
|
|
|
PrepareStep(step_action, step_count);
|
|
|
|
}
|
|
|
|
|
2010-06-30 17:29:00 +00:00
|
|
|
if (thread_local_.frame_drop_mode_ == FRAMES_UNTOUCHED) {
|
|
|
|
SetAfterBreakTarget(frame);
|
|
|
|
} else if (thread_local_.frame_drop_mode_ == FRAME_DROPPED_IN_IC_CALL) {
|
|
|
|
// We must have been calling IC stub. Do not go there anymore.
|
2010-04-06 17:58:28 +00:00
|
|
|
Code* plain_return = Builtins::builtin(Builtins::PlainReturn_LiveEdit);
|
|
|
|
thread_local_.after_break_target_ = plain_return->entry();
|
2010-06-30 17:29:00 +00:00
|
|
|
} else if (thread_local_.frame_drop_mode_ ==
|
|
|
|
FRAME_DROPPED_IN_DEBUG_SLOT_CALL) {
|
|
|
|
// Debug break slot stub does not return normally, instead it manually
|
|
|
|
// cleans the stack and jumps. We should patch the jump address.
|
|
|
|
Code* plain_return = Builtins::builtin(Builtins::FrameDropper_LiveEdit);
|
|
|
|
thread_local_.after_break_target_ = plain_return->entry();
|
|
|
|
} else if (thread_local_.frame_drop_mode_ == FRAME_DROPPED_IN_DIRECT_CALL) {
|
|
|
|
// Nothing to do, after_break_target is not used here.
|
2010-04-06 17:58:28 +00:00
|
|
|
} else {
|
2010-06-30 17:29:00 +00:00
|
|
|
UNREACHABLE();
|
2010-04-06 17:58:28 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-08-13 09:32:07 +00:00
|
|
|
return Heap::undefined_value();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check the break point objects for whether one or more are actually
|
|
|
|
// triggered. This function returns a JSArray with the break point objects
|
|
|
|
// which is triggered.
|
|
|
|
Handle<Object> Debug::CheckBreakPoints(Handle<Object> break_point_objects) {
|
|
|
|
int break_points_hit_count = 0;
|
|
|
|
Handle<JSArray> break_points_hit = Factory::NewJSArray(1);
|
|
|
|
|
2008-09-01 09:16:49 +00:00
|
|
|
// If there are multiple break points they are in a FixedArray.
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT(!break_point_objects->IsUndefined());
|
|
|
|
if (break_point_objects->IsFixedArray()) {
|
|
|
|
Handle<FixedArray> array(FixedArray::cast(*break_point_objects));
|
|
|
|
for (int i = 0; i < array->length(); i++) {
|
|
|
|
Handle<Object> o(array->get(i));
|
|
|
|
if (CheckBreakPoint(o)) {
|
|
|
|
break_points_hit->SetElement(break_points_hit_count++, *o);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (CheckBreakPoint(break_point_objects)) {
|
|
|
|
break_points_hit->SetElement(break_points_hit_count++,
|
|
|
|
*break_point_objects);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return undefined if no break points where triggered.
|
|
|
|
if (break_points_hit_count == 0) {
|
|
|
|
return Factory::undefined_value();
|
|
|
|
}
|
|
|
|
return break_points_hit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check whether a single break point object is triggered.
|
|
|
|
bool Debug::CheckBreakPoint(Handle<Object> break_point_object) {
|
2009-02-13 12:36:58 +00:00
|
|
|
HandleScope scope;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Ignore check if break point object is not a JSObject.
|
|
|
|
if (!break_point_object->IsJSObject()) return true;
|
|
|
|
|
|
|
|
// Get the function CheckBreakPoint (defined in debug.js).
|
|
|
|
Handle<JSFunction> check_break_point =
|
|
|
|
Handle<JSFunction>(JSFunction::cast(
|
|
|
|
debug_context()->global()->GetProperty(
|
|
|
|
*Factory::LookupAsciiSymbol("IsBreakPointTriggered"))));
|
|
|
|
|
|
|
|
// Get the break id as an object.
|
2009-03-06 11:03:14 +00:00
|
|
|
Handle<Object> break_id = Factory::NewNumberFromInt(Debug::break_id());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Call HandleBreakPointx.
|
|
|
|
bool caught_exception = false;
|
|
|
|
const int argc = 2;
|
|
|
|
Object** argv[argc] = {
|
|
|
|
break_id.location(),
|
|
|
|
reinterpret_cast<Object**>(break_point_object.location())
|
|
|
|
};
|
|
|
|
Handle<Object> result = Execution::TryCall(check_break_point,
|
|
|
|
Top::builtins(), argc, argv,
|
|
|
|
&caught_exception);
|
|
|
|
|
|
|
|
// If exception or non boolean result handle as not triggered
|
|
|
|
if (caught_exception || !result->IsBoolean()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return whether the break point is triggered.
|
|
|
|
return *result == Heap::true_value();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check whether the function has debug information.
|
|
|
|
bool Debug::HasDebugInfo(Handle<SharedFunctionInfo> shared) {
|
|
|
|
return !shared->debug_info()->IsUndefined();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-09 11:06:54 +00:00
|
|
|
// Return the debug info for this function. EnsureDebugInfo must be called
|
|
|
|
// prior to ensure the debug info has been generated for shared.
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<DebugInfo> Debug::GetDebugInfo(Handle<SharedFunctionInfo> shared) {
|
2008-07-09 11:06:54 +00:00
|
|
|
ASSERT(HasDebugInfo(shared));
|
2008-07-03 15:10:15 +00:00
|
|
|
return Handle<DebugInfo>(DebugInfo::cast(shared->debug_info()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Debug::SetBreakPoint(Handle<SharedFunctionInfo> shared,
|
2010-06-16 14:50:07 +00:00
|
|
|
Handle<Object> break_point_object,
|
|
|
|
int* source_position) {
|
2009-02-13 12:36:58 +00:00
|
|
|
HandleScope scope;
|
|
|
|
|
2008-07-09 11:06:54 +00:00
|
|
|
if (!EnsureDebugInfo(shared)) {
|
|
|
|
// Return if retrieving debug info failed.
|
|
|
|
return;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2008-07-09 11:06:54 +00:00
|
|
|
Handle<DebugInfo> debug_info = GetDebugInfo(shared);
|
2008-07-03 15:10:15 +00:00
|
|
|
// Source positions starts with zero.
|
|
|
|
ASSERT(source_position >= 0);
|
|
|
|
|
|
|
|
// Find the break point and change it.
|
|
|
|
BreakLocationIterator it(debug_info, SOURCE_BREAK_LOCATIONS);
|
2010-06-16 14:50:07 +00:00
|
|
|
it.FindBreakLocationFromPosition(*source_position);
|
2008-07-03 15:10:15 +00:00
|
|
|
it.SetBreakPoint(break_point_object);
|
|
|
|
|
2010-06-16 14:50:07 +00:00
|
|
|
*source_position = it.position();
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// At least one active break point now.
|
|
|
|
ASSERT(debug_info->GetBreakPointCount() > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Debug::ClearBreakPoint(Handle<Object> break_point_object) {
|
2009-02-13 12:36:58 +00:00
|
|
|
HandleScope scope;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
DebugInfoListNode* node = debug_info_list_;
|
|
|
|
while (node != NULL) {
|
|
|
|
Object* result = DebugInfo::FindBreakPointInfo(node->debug_info(),
|
|
|
|
break_point_object);
|
|
|
|
if (!result->IsUndefined()) {
|
|
|
|
// Get information in the break point.
|
|
|
|
BreakPointInfo* break_point_info = BreakPointInfo::cast(result);
|
|
|
|
Handle<DebugInfo> debug_info = node->debug_info();
|
|
|
|
Handle<SharedFunctionInfo> shared(debug_info->shared());
|
|
|
|
int source_position = break_point_info->statement_position()->value();
|
|
|
|
|
|
|
|
// Source positions starts with zero.
|
|
|
|
ASSERT(source_position >= 0);
|
|
|
|
|
|
|
|
// Find the break point and clear it.
|
|
|
|
BreakLocationIterator it(debug_info, SOURCE_BREAK_LOCATIONS);
|
|
|
|
it.FindBreakLocationFromPosition(source_position);
|
|
|
|
it.ClearBreakPoint(break_point_object);
|
|
|
|
|
|
|
|
// If there are no more break points left remove the debug info for this
|
|
|
|
// function.
|
|
|
|
if (debug_info->GetBreakPointCount() == 0) {
|
|
|
|
RemoveDebugInfo(debug_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
node = node->next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-13 12:36:58 +00:00
|
|
|
void Debug::ClearAllBreakPoints() {
|
|
|
|
DebugInfoListNode* node = debug_info_list_;
|
|
|
|
while (node != NULL) {
|
|
|
|
// Remove all debug break code.
|
|
|
|
BreakLocationIterator it(node->debug_info(), ALL_BREAK_LOCATIONS);
|
|
|
|
it.ClearAllDebugBreak();
|
|
|
|
node = node->next();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove all debug info.
|
|
|
|
while (debug_info_list_ != NULL) {
|
|
|
|
RemoveDebugInfo(debug_info_list_->debug_info());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void Debug::FloodWithOneShot(Handle<SharedFunctionInfo> shared) {
|
2008-07-09 11:06:54 +00:00
|
|
|
// Make sure the function has setup the debug info.
|
|
|
|
if (!EnsureDebugInfo(shared)) {
|
|
|
|
// Return if we failed to retrieve the debug info.
|
|
|
|
return;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Flood the function with break points.
|
2008-07-09 11:06:54 +00:00
|
|
|
BreakLocationIterator it(GetDebugInfo(shared), ALL_BREAK_LOCATIONS);
|
2008-07-03 15:10:15 +00:00
|
|
|
while (!it.Done()) {
|
|
|
|
it.SetOneShot();
|
|
|
|
it.Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Debug::FloodHandlerWithOneShot() {
|
2008-12-11 08:03:24 +00:00
|
|
|
// Iterate through the JavaScript stack looking for handlers.
|
2009-03-06 11:03:14 +00:00
|
|
|
StackFrame::Id id = break_frame_id();
|
2008-12-11 08:03:24 +00:00
|
|
|
if (id == StackFrame::NO_ID) {
|
|
|
|
// If there is no JavaScript stack don't do anything.
|
|
|
|
return;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
for (JavaScriptFrameIterator it(id); !it.done(); it.Advance()) {
|
|
|
|
JavaScriptFrame* frame = it.frame();
|
|
|
|
if (frame->HasHandler()) {
|
|
|
|
Handle<SharedFunctionInfo> shared =
|
|
|
|
Handle<SharedFunctionInfo>(
|
|
|
|
JSFunction::cast(frame->function())->shared());
|
|
|
|
// Flood the function with the catch block with break points
|
|
|
|
FloodWithOneShot(shared);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Debug::ChangeBreakOnException(ExceptionBreakType type, bool enable) {
|
|
|
|
if (type == BreakUncaughtException) {
|
|
|
|
break_on_uncaught_exception_ = enable;
|
|
|
|
} else {
|
|
|
|
break_on_exception_ = enable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Debug::PrepareStep(StepAction step_action, int step_count) {
|
|
|
|
HandleScope scope;
|
|
|
|
ASSERT(Debug::InDebugger());
|
|
|
|
|
|
|
|
// Remember this step action and count.
|
|
|
|
thread_local_.last_step_action_ = step_action;
|
2009-09-09 08:40:59 +00:00
|
|
|
if (step_action == StepOut) {
|
|
|
|
// For step out target frame will be found on the stack so there is no need
|
|
|
|
// to set step counter for it. It's expected to always be 0 for StepOut.
|
|
|
|
thread_local_.step_count_ = 0;
|
|
|
|
} else {
|
|
|
|
thread_local_.step_count_ = step_count;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Get the frame where the execution has stopped and skip the debug frame if
|
|
|
|
// any. The debug frame will only be present if execution was stopped due to
|
|
|
|
// hitting a break point. In other situations (e.g. unhandled exception) the
|
|
|
|
// debug frame is not present.
|
2009-03-06 11:03:14 +00:00
|
|
|
StackFrame::Id id = break_frame_id();
|
2008-12-11 08:03:24 +00:00
|
|
|
if (id == StackFrame::NO_ID) {
|
|
|
|
// If there is no JavaScript stack don't do anything.
|
|
|
|
return;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
JavaScriptFrameIterator frames_it(id);
|
|
|
|
JavaScriptFrame* frame = frames_it.frame();
|
|
|
|
|
|
|
|
// First of all ensure there is one-shot break points in the top handler
|
|
|
|
// if any.
|
|
|
|
FloodHandlerWithOneShot();
|
|
|
|
|
|
|
|
// If the function on the top frame is unresolved perform step out. This will
|
|
|
|
// be the case when calling unknown functions and having the debugger stopped
|
|
|
|
// in an unhandled exception.
|
|
|
|
if (!frame->function()->IsJSFunction()) {
|
|
|
|
// Step out: Find the calling JavaScript frame and flood it with
|
|
|
|
// breakpoints.
|
|
|
|
frames_it.Advance();
|
|
|
|
// Fill the function to return to with one-shot break points.
|
|
|
|
JSFunction* function = JSFunction::cast(frames_it.frame()->function());
|
|
|
|
FloodWithOneShot(Handle<SharedFunctionInfo>(function->shared()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the debug info (create it if it does not exist).
|
|
|
|
Handle<SharedFunctionInfo> shared =
|
|
|
|
Handle<SharedFunctionInfo>(JSFunction::cast(frame->function())->shared());
|
2008-07-09 11:06:54 +00:00
|
|
|
if (!EnsureDebugInfo(shared)) {
|
|
|
|
// Return if ensuring debug info failed.
|
|
|
|
return;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<DebugInfo> debug_info = GetDebugInfo(shared);
|
|
|
|
|
|
|
|
// Find the break location where execution has stopped.
|
|
|
|
BreakLocationIterator it(debug_info, ALL_BREAK_LOCATIONS);
|
|
|
|
it.FindBreakLocationFromAddress(frame->pc());
|
|
|
|
|
|
|
|
// Compute whether or not the target is a call target.
|
|
|
|
bool is_call_target = false;
|
2009-07-16 07:07:51 +00:00
|
|
|
bool is_load_or_store = false;
|
|
|
|
bool is_inline_cache_stub = false;
|
2009-09-07 07:20:05 +00:00
|
|
|
Handle<Code> call_function_stub;
|
2008-09-22 13:57:03 +00:00
|
|
|
if (RelocInfo::IsCodeTarget(it.rinfo()->rmode())) {
|
2008-07-03 15:10:15 +00:00
|
|
|
Address target = it.rinfo()->target_address();
|
2008-12-09 12:53:59 +00:00
|
|
|
Code* code = Code::GetCodeFromTargetAddress(target);
|
2010-06-07 08:27:32 +00:00
|
|
|
if (code->is_call_stub() || code->is_keyed_call_stub()) {
|
2009-07-16 07:07:51 +00:00
|
|
|
is_call_target = true;
|
|
|
|
}
|
|
|
|
if (code->is_inline_cache_stub()) {
|
|
|
|
is_inline_cache_stub = true;
|
|
|
|
is_load_or_store = !is_call_target;
|
|
|
|
}
|
2009-09-07 07:20:05 +00:00
|
|
|
|
|
|
|
// Check if target code is CallFunction stub.
|
|
|
|
Code* maybe_call_function_stub = code;
|
|
|
|
// If there is a breakpoint at this line look at the original code to
|
|
|
|
// check if it is a CallFunction stub.
|
|
|
|
if (it.IsDebugBreak()) {
|
|
|
|
Address original_target = it.original_rinfo()->target_address();
|
|
|
|
maybe_call_function_stub =
|
|
|
|
Code::GetCodeFromTargetAddress(original_target);
|
|
|
|
}
|
|
|
|
if (maybe_call_function_stub->kind() == Code::STUB &&
|
|
|
|
maybe_call_function_stub->major_key() == CodeStub::CallFunction) {
|
|
|
|
// Save reference to the code as we may need it to find out arguments
|
|
|
|
// count for 'step in' later.
|
|
|
|
call_function_stub = Handle<Code>(maybe_call_function_stub);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2008-09-01 09:16:49 +00:00
|
|
|
// If this is the last break code target step out is the only possibility.
|
2008-07-03 15:10:15 +00:00
|
|
|
if (it.IsExit() || step_action == StepOut) {
|
2009-09-09 08:40:59 +00:00
|
|
|
if (step_action == StepOut) {
|
|
|
|
// Skip step_count frames starting with the current one.
|
2009-09-09 09:58:00 +00:00
|
|
|
while (step_count-- > 0 && !frames_it.done()) {
|
2009-09-09 08:40:59 +00:00
|
|
|
frames_it.Advance();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ASSERT(it.IsExit());
|
|
|
|
frames_it.Advance();
|
|
|
|
}
|
|
|
|
// Skip builtin functions on the stack.
|
2009-09-09 09:58:00 +00:00
|
|
|
while (!frames_it.done() &&
|
|
|
|
JSFunction::cast(frames_it.frame()->function())->IsBuiltin()) {
|
2009-09-09 08:40:59 +00:00
|
|
|
frames_it.Advance();
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
// Step out: If there is a JavaScript caller frame, we need to
|
|
|
|
// flood it with breakpoints.
|
|
|
|
if (!frames_it.done()) {
|
|
|
|
// Fill the function to return to with one-shot break points.
|
|
|
|
JSFunction* function = JSFunction::cast(frames_it.frame()->function());
|
|
|
|
FloodWithOneShot(Handle<SharedFunctionInfo>(function->shared()));
|
2009-09-09 08:40:59 +00:00
|
|
|
// Set target frame pointer.
|
|
|
|
ActivateStepOut(frames_it.frame());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2009-09-07 07:20:05 +00:00
|
|
|
} else if (!(is_inline_cache_stub || RelocInfo::IsConstructCall(it.rmode()) ||
|
|
|
|
!call_function_stub.is_null())
|
2009-07-16 07:07:51 +00:00
|
|
|
|| step_action == StepNext || step_action == StepMin) {
|
2008-07-03 15:10:15 +00:00
|
|
|
// Step next or step min.
|
|
|
|
|
|
|
|
// Fill the current function with one-shot break points.
|
|
|
|
FloodWithOneShot(shared);
|
|
|
|
|
|
|
|
// Remember source position and frame to handle step next.
|
|
|
|
thread_local_.last_statement_position_ =
|
|
|
|
debug_info->code()->SourceStatementPosition(frame->pc());
|
|
|
|
thread_local_.last_fp_ = frame->fp();
|
|
|
|
} else {
|
2009-09-07 07:20:05 +00:00
|
|
|
// If it's CallFunction stub ensure target function is compiled and flood
|
|
|
|
// it with one shot breakpoints.
|
|
|
|
if (!call_function_stub.is_null()) {
|
|
|
|
// Find out number of arguments from the stub minor key.
|
|
|
|
// Reverse lookup required as the minor key cannot be retrieved
|
|
|
|
// from the code object.
|
|
|
|
Handle<Object> obj(
|
|
|
|
Heap::code_stubs()->SlowReverseLookup(*call_function_stub));
|
|
|
|
ASSERT(*obj != Heap::undefined_value());
|
|
|
|
ASSERT(obj->IsSmi());
|
|
|
|
// Get the STUB key and extract major and minor key.
|
|
|
|
uint32_t key = Smi::cast(*obj)->value();
|
|
|
|
// Argc in the stub is the number of arguments passed - not the
|
|
|
|
// expected arguments of the called function.
|
2010-01-15 13:42:32 +00:00
|
|
|
int call_function_arg_count =
|
|
|
|
CallFunctionStub::ExtractArgcFromMinorKey(
|
|
|
|
CodeStub::MinorKeyFromKey(key));
|
2009-09-07 07:20:05 +00:00
|
|
|
ASSERT(call_function_stub->major_key() ==
|
|
|
|
CodeStub::MajorKeyFromKey(key));
|
|
|
|
|
|
|
|
// Find target function on the expression stack.
|
2010-01-15 13:42:32 +00:00
|
|
|
// Expression stack looks like this (top to bottom):
|
2009-09-07 07:20:05 +00:00
|
|
|
// argN
|
|
|
|
// ...
|
|
|
|
// arg0
|
|
|
|
// Receiver
|
|
|
|
// Function to call
|
|
|
|
int expressions_count = frame->ComputeExpressionsCount();
|
|
|
|
ASSERT(expressions_count - 2 - call_function_arg_count >= 0);
|
|
|
|
Object* fun = frame->GetExpression(
|
|
|
|
expressions_count - 2 - call_function_arg_count);
|
|
|
|
if (fun->IsJSFunction()) {
|
|
|
|
Handle<JSFunction> js_function(JSFunction::cast(fun));
|
|
|
|
// Don't step into builtins.
|
|
|
|
if (!js_function->IsBuiltin()) {
|
|
|
|
// It will also compile target function if it's not compiled yet.
|
|
|
|
FloodWithOneShot(Handle<SharedFunctionInfo>(js_function->shared()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Fill the current function with one-shot break points even for step in on
|
|
|
|
// a call target as the function called might be a native function for
|
2009-07-16 07:07:51 +00:00
|
|
|
// which step in will not stop. It also prepares for stepping in
|
|
|
|
// getters/setters.
|
2008-07-03 15:10:15 +00:00
|
|
|
FloodWithOneShot(shared);
|
|
|
|
|
2009-07-16 07:07:51 +00:00
|
|
|
if (is_load_or_store) {
|
|
|
|
// Remember source position and frame to handle step in getter/setter. If
|
|
|
|
// there is a custom getter/setter it will be handled in
|
|
|
|
// Object::Get/SetPropertyWithCallback, otherwise the step action will be
|
|
|
|
// propagated on the next Debug::Break.
|
|
|
|
thread_local_.last_statement_position_ =
|
|
|
|
debug_info->code()->SourceStatementPosition(frame->pc());
|
|
|
|
thread_local_.last_fp_ = frame->fp();
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Step in or Step in min
|
|
|
|
it.PrepareStepIn();
|
|
|
|
ActivateStepIn(frame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check whether the current debug break should be reported to the debugger. It
|
|
|
|
// is used to have step next and step in only report break back to the debugger
|
|
|
|
// if on a different frame or in a different statement. In some situations
|
|
|
|
// there will be several break points in the same statement when the code is
|
2008-09-01 09:16:49 +00:00
|
|
|
// flooded with one-shot break points. This function helps to perform several
|
2008-07-03 15:10:15 +00:00
|
|
|
// steps before reporting break back to the debugger.
|
|
|
|
bool Debug::StepNextContinue(BreakLocationIterator* break_location_iterator,
|
|
|
|
JavaScriptFrame* frame) {
|
|
|
|
// If the step last action was step next or step in make sure that a new
|
|
|
|
// statement is hit.
|
|
|
|
if (thread_local_.last_step_action_ == StepNext ||
|
|
|
|
thread_local_.last_step_action_ == StepIn) {
|
|
|
|
// Never continue if returning from function.
|
|
|
|
if (break_location_iterator->IsExit()) return false;
|
|
|
|
|
|
|
|
// Continue if we are still on the same frame and in the same statement.
|
|
|
|
int current_statement_position =
|
|
|
|
break_location_iterator->code()->SourceStatementPosition(frame->pc());
|
|
|
|
return thread_local_.last_fp_ == frame->fp() &&
|
2008-09-18 08:51:43 +00:00
|
|
|
thread_local_.last_statement_position_ == current_statement_position;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// No step next action - don't continue.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check whether the code object at the specified address is a debug break code
|
|
|
|
// object.
|
|
|
|
bool Debug::IsDebugBreak(Address addr) {
|
2008-12-09 12:53:59 +00:00
|
|
|
Code* code = Code::GetCodeFromTargetAddress(addr);
|
2008-07-30 08:49:36 +00:00
|
|
|
return code->ic_state() == DEBUG_BREAK;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check whether a code stub with the specified major key is a possible break
|
|
|
|
// point location when looking for source break locations.
|
|
|
|
bool Debug::IsSourceBreakStub(Code* code) {
|
|
|
|
CodeStub::Major major_key = code->major_key();
|
|
|
|
return major_key == CodeStub::CallFunction;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check whether a code stub with the specified major key is a possible break
|
|
|
|
// location.
|
|
|
|
bool Debug::IsBreakStub(Code* code) {
|
|
|
|
CodeStub::Major major_key = code->major_key();
|
|
|
|
return major_key == CodeStub::CallFunction ||
|
|
|
|
major_key == CodeStub::StackCheck;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Find the builtin to use for invoking the debug break
|
2009-04-21 14:48:54 +00:00
|
|
|
Handle<Code> Debug::FindDebugBreak(Handle<Code> code, RelocInfo::Mode mode) {
|
2008-07-03 15:10:15 +00:00
|
|
|
// Find the builtin debug break function matching the calling convention
|
|
|
|
// used by the call site.
|
2009-04-21 14:48:54 +00:00
|
|
|
if (code->is_inline_cache_stub()) {
|
2010-03-01 16:24:05 +00:00
|
|
|
switch (code->kind()) {
|
|
|
|
case Code::CALL_IC:
|
2010-06-07 08:27:32 +00:00
|
|
|
case Code::KEYED_CALL_IC:
|
|
|
|
return ComputeCallDebugBreak(code->arguments_count(), code->kind());
|
2010-03-01 16:24:05 +00:00
|
|
|
|
|
|
|
case Code::LOAD_IC:
|
|
|
|
return Handle<Code>(Builtins::builtin(Builtins::LoadIC_DebugBreak));
|
|
|
|
|
|
|
|
case Code::STORE_IC:
|
|
|
|
return Handle<Code>(Builtins::builtin(Builtins::StoreIC_DebugBreak));
|
|
|
|
|
|
|
|
case Code::KEYED_LOAD_IC:
|
|
|
|
return Handle<Code>(
|
|
|
|
Builtins::builtin(Builtins::KeyedLoadIC_DebugBreak));
|
|
|
|
|
|
|
|
case Code::KEYED_STORE_IC:
|
|
|
|
return Handle<Code>(
|
|
|
|
Builtins::builtin(Builtins::KeyedStoreIC_DebugBreak));
|
|
|
|
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-21 14:48:54 +00:00
|
|
|
if (RelocInfo::IsConstructCall(mode)) {
|
|
|
|
Handle<Code> result =
|
|
|
|
Handle<Code>(Builtins::builtin(Builtins::ConstructCall_DebugBreak));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
if (code->kind() == Code::STUB) {
|
|
|
|
ASSERT(code->major_key() == CodeStub::CallFunction ||
|
|
|
|
code->major_key() == CodeStub::StackCheck);
|
|
|
|
Handle<Code> result =
|
|
|
|
Handle<Code>(Builtins::builtin(Builtins::StubNoRegisters_DebugBreak));
|
|
|
|
return result;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
UNREACHABLE();
|
|
|
|
return Handle<Code>::null();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Simple function for returning the source positions for active break points.
|
|
|
|
Handle<Object> Debug::GetSourceBreakLocations(
|
|
|
|
Handle<SharedFunctionInfo> shared) {
|
|
|
|
if (!HasDebugInfo(shared)) return Handle<Object>(Heap::undefined_value());
|
|
|
|
Handle<DebugInfo> debug_info = GetDebugInfo(shared);
|
|
|
|
if (debug_info->GetBreakPointCount() == 0) {
|
|
|
|
return Handle<Object>(Heap::undefined_value());
|
|
|
|
}
|
|
|
|
Handle<FixedArray> locations =
|
|
|
|
Factory::NewFixedArray(debug_info->GetBreakPointCount());
|
|
|
|
int count = 0;
|
|
|
|
for (int i = 0; i < debug_info->break_points()->length(); i++) {
|
|
|
|
if (!debug_info->break_points()->get(i)->IsUndefined()) {
|
|
|
|
BreakPointInfo* break_point_info =
|
|
|
|
BreakPointInfo::cast(debug_info->break_points()->get(i));
|
|
|
|
if (break_point_info->GetBreakPointCount() > 0) {
|
|
|
|
locations->set(count++, break_point_info->statement_position());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return locations;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-06 11:03:14 +00:00
|
|
|
void Debug::NewBreak(StackFrame::Id break_frame_id) {
|
|
|
|
thread_local_.break_frame_id_ = break_frame_id;
|
|
|
|
thread_local_.break_id_ = ++thread_local_.break_count_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Debug::SetBreak(StackFrame::Id break_frame_id, int break_id) {
|
|
|
|
thread_local_.break_frame_id_ = break_frame_id;
|
|
|
|
thread_local_.break_id_ = break_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-18 14:32:49 +00:00
|
|
|
// Handle stepping into a function.
|
|
|
|
void Debug::HandleStepIn(Handle<JSFunction> function,
|
2009-07-10 09:57:53 +00:00
|
|
|
Handle<Object> holder,
|
2008-12-18 14:32:49 +00:00
|
|
|
Address fp,
|
|
|
|
bool is_constructor) {
|
|
|
|
// If the frame pointer is not supplied by the caller find it.
|
|
|
|
if (fp == 0) {
|
|
|
|
StackFrameIterator it;
|
|
|
|
it.Advance();
|
|
|
|
// For constructor functions skip another frame.
|
|
|
|
if (is_constructor) {
|
|
|
|
ASSERT(it.frame()->is_construct());
|
|
|
|
it.Advance();
|
|
|
|
}
|
|
|
|
fp = it.frame()->fp();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Flood the function with one-shot break points if it is called from where
|
|
|
|
// step into was requested.
|
|
|
|
if (fp == Debug::step_in_fp()) {
|
|
|
|
// Don't allow step into functions in the native context.
|
2009-07-29 09:51:41 +00:00
|
|
|
if (!function->IsBuiltin()) {
|
2009-04-07 09:54:53 +00:00
|
|
|
if (function->shared()->code() ==
|
2009-04-07 12:11:43 +00:00
|
|
|
Builtins::builtin(Builtins::FunctionApply) ||
|
|
|
|
function->shared()->code() ==
|
|
|
|
Builtins::builtin(Builtins::FunctionCall)) {
|
|
|
|
// Handle function.apply and function.call separately to flood the
|
|
|
|
// function to be called and not the code for Builtins::FunctionApply or
|
2009-07-10 09:57:53 +00:00
|
|
|
// Builtins::FunctionCall. The receiver of call/apply is the target
|
|
|
|
// function.
|
2009-07-29 06:34:30 +00:00
|
|
|
if (!holder.is_null() && holder->IsJSFunction() &&
|
2009-07-29 09:51:41 +00:00
|
|
|
!JSFunction::cast(*holder)->IsBuiltin()) {
|
2009-07-10 09:57:53 +00:00
|
|
|
Handle<SharedFunctionInfo> shared_info(
|
|
|
|
JSFunction::cast(*holder)->shared());
|
|
|
|
Debug::FloodWithOneShot(shared_info);
|
2009-04-07 09:54:53 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Debug::FloodWithOneShot(Handle<SharedFunctionInfo>(function->shared()));
|
|
|
|
}
|
2008-12-18 14:32:49 +00:00
|
|
|
}
|
2008-12-18 15:17:02 +00:00
|
|
|
}
|
2008-12-18 14:32:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void Debug::ClearStepping() {
|
|
|
|
// Clear the various stepping setup.
|
|
|
|
ClearOneShot();
|
|
|
|
ClearStepIn();
|
2009-09-09 08:40:59 +00:00
|
|
|
ClearStepOut();
|
2008-07-03 15:10:15 +00:00
|
|
|
ClearStepNext();
|
|
|
|
|
|
|
|
// Clear multiple step counter.
|
|
|
|
thread_local_.step_count_ = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clears all the one-shot break points that are currently set. Normally this
|
|
|
|
// function is called each time a break point is hit as one shot break points
|
|
|
|
// are used to support stepping.
|
|
|
|
void Debug::ClearOneShot() {
|
|
|
|
// The current implementation just runs through all the breakpoints. When the
|
2008-09-01 09:16:49 +00:00
|
|
|
// last break point for a function is removed that function is automatically
|
2008-07-03 15:10:15 +00:00
|
|
|
// removed from the list.
|
|
|
|
|
|
|
|
DebugInfoListNode* node = debug_info_list_;
|
|
|
|
while (node != NULL) {
|
|
|
|
BreakLocationIterator it(node->debug_info(), ALL_BREAK_LOCATIONS);
|
|
|
|
while (!it.Done()) {
|
|
|
|
it.ClearOneShot();
|
|
|
|
it.Next();
|
|
|
|
}
|
|
|
|
node = node->next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Debug::ActivateStepIn(StackFrame* frame) {
|
2009-09-09 08:40:59 +00:00
|
|
|
ASSERT(!StepOutActive());
|
2008-07-03 15:10:15 +00:00
|
|
|
thread_local_.step_into_fp_ = frame->fp();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Debug::ClearStepIn() {
|
|
|
|
thread_local_.step_into_fp_ = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-09 08:40:59 +00:00
|
|
|
void Debug::ActivateStepOut(StackFrame* frame) {
|
|
|
|
ASSERT(!StepInActive());
|
|
|
|
thread_local_.step_out_fp_ = frame->fp();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Debug::ClearStepOut() {
|
|
|
|
thread_local_.step_out_fp_ = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void Debug::ClearStepNext() {
|
|
|
|
thread_local_.last_step_action_ = StepNone;
|
2008-09-22 13:57:03 +00:00
|
|
|
thread_local_.last_statement_position_ = RelocInfo::kNoPosition;
|
2008-07-03 15:10:15 +00:00
|
|
|
thread_local_.last_fp_ = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-09 11:06:54 +00:00
|
|
|
// Ensures the debug information is present for shared.
|
|
|
|
bool Debug::EnsureDebugInfo(Handle<SharedFunctionInfo> shared) {
|
|
|
|
// Return if we already have the debug info for shared.
|
|
|
|
if (HasDebugInfo(shared)) return true;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-07-09 11:06:54 +00:00
|
|
|
// Ensure shared in compiled. Return false if this failed.
|
2010-01-29 09:52:51 +00:00
|
|
|
if (!EnsureCompiled(shared, CLEAR_EXCEPTION)) return false;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Create the debug info object.
|
2008-09-01 10:15:45 +00:00
|
|
|
Handle<DebugInfo> debug_info = Factory::NewDebugInfo(shared);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Add debug info to the list.
|
|
|
|
DebugInfoListNode* node = new DebugInfoListNode(*debug_info);
|
|
|
|
node->set_next(debug_info_list_);
|
|
|
|
debug_info_list_ = node;
|
|
|
|
|
|
|
|
// Now there is at least one break point.
|
|
|
|
has_break_points_ = true;
|
|
|
|
|
2008-07-09 11:06:54 +00:00
|
|
|
return true;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Debug::RemoveDebugInfo(Handle<DebugInfo> debug_info) {
|
|
|
|
ASSERT(debug_info_list_ != NULL);
|
|
|
|
// Run through the debug info objects to find this one and remove it.
|
|
|
|
DebugInfoListNode* prev = NULL;
|
|
|
|
DebugInfoListNode* current = debug_info_list_;
|
|
|
|
while (current != NULL) {
|
|
|
|
if (*current->debug_info() == *debug_info) {
|
|
|
|
// Unlink from list. If prev is NULL we are looking at the first element.
|
|
|
|
if (prev == NULL) {
|
|
|
|
debug_info_list_ = current->next();
|
|
|
|
} else {
|
|
|
|
prev->set_next(current->next());
|
|
|
|
}
|
|
|
|
current->debug_info()->shared()->set_debug_info(Heap::undefined_value());
|
|
|
|
delete current;
|
|
|
|
|
|
|
|
// If there are no more debug info objects there are not more break
|
|
|
|
// points.
|
|
|
|
has_break_points_ = debug_info_list_ != NULL;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Move to next in list.
|
|
|
|
prev = current;
|
|
|
|
current = current->next();
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Debug::SetAfterBreakTarget(JavaScriptFrame* frame) {
|
2009-02-13 12:36:58 +00:00
|
|
|
HandleScope scope;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Get the executing function in which the debug break occurred.
|
|
|
|
Handle<SharedFunctionInfo> shared =
|
|
|
|
Handle<SharedFunctionInfo>(JSFunction::cast(frame->function())->shared());
|
2008-07-09 11:06:54 +00:00
|
|
|
if (!EnsureDebugInfo(shared)) {
|
|
|
|
// Return if we failed to retrieve the debug info.
|
|
|
|
return;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<DebugInfo> debug_info = GetDebugInfo(shared);
|
|
|
|
Handle<Code> code(debug_info->code());
|
|
|
|
Handle<Code> original_code(debug_info->original_code());
|
|
|
|
#ifdef DEBUG
|
|
|
|
// Get the code which is actually executing.
|
2009-02-25 16:52:15 +00:00
|
|
|
Handle<Code> frame_code(frame->code());
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT(frame_code.is_identical_to(code));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Find the call address in the running code. This address holds the call to
|
|
|
|
// either a DebugBreakXXX or to the debug break return entry code if the
|
|
|
|
// break point is still active after processing the break point.
|
2009-09-11 12:41:27 +00:00
|
|
|
Address addr = frame->pc() - Assembler::kCallTargetAddressOffset;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-06-08 12:04:49 +00:00
|
|
|
// Check if the location is at JS exit or debug break slot.
|
2009-09-09 17:45:21 +00:00
|
|
|
bool at_js_return = false;
|
|
|
|
bool break_at_js_return_active = false;
|
2010-06-08 12:04:49 +00:00
|
|
|
bool at_debug_break_slot = false;
|
2008-07-03 15:10:15 +00:00
|
|
|
RelocIterator it(debug_info->code());
|
2010-06-08 12:04:49 +00:00
|
|
|
while (!it.done() && !at_js_return && !at_debug_break_slot) {
|
2008-09-22 13:57:03 +00:00
|
|
|
if (RelocInfo::IsJSReturn(it.rinfo()->rmode())) {
|
2009-09-09 17:45:21 +00:00
|
|
|
at_js_return = (it.rinfo()->pc() ==
|
|
|
|
addr - Assembler::kPatchReturnSequenceAddressOffset);
|
2009-10-15 11:52:53 +00:00
|
|
|
break_at_js_return_active = it.rinfo()->IsPatchedReturnSequence();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2010-06-08 12:04:49 +00:00
|
|
|
if (RelocInfo::IsDebugBreakSlot(it.rinfo()->rmode())) {
|
|
|
|
at_debug_break_slot = (it.rinfo()->pc() ==
|
|
|
|
addr - Assembler::kPatchDebugBreakSlotAddressOffset);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
it.next();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle the jump to continue execution after break point depending on the
|
|
|
|
// break location.
|
2009-09-09 17:45:21 +00:00
|
|
|
if (at_js_return) {
|
|
|
|
// If the break point as return is still active jump to the corresponding
|
|
|
|
// place in the original code. If not the break point was removed during
|
|
|
|
// break point processing.
|
|
|
|
if (break_at_js_return_active) {
|
2008-07-03 15:10:15 +00:00
|
|
|
addr += original_code->instruction_start() - code->instruction_start();
|
|
|
|
}
|
|
|
|
|
2009-08-19 10:18:30 +00:00
|
|
|
// Move back to where the call instruction sequence started.
|
|
|
|
thread_local_.after_break_target_ =
|
|
|
|
addr - Assembler::kPatchReturnSequenceAddressOffset;
|
2010-06-08 12:04:49 +00:00
|
|
|
} else if (at_debug_break_slot) {
|
|
|
|
// Address of where the debug break slot starts.
|
|
|
|
addr = addr - Assembler::kPatchDebugBreakSlotAddressOffset;
|
|
|
|
|
|
|
|
// Continue just after the slot.
|
|
|
|
thread_local_.after_break_target_ = addr + Assembler::kDebugBreakSlotLength;
|
|
|
|
} else if (IsDebugBreak(Assembler::target_address_at(addr))) {
|
|
|
|
// We now know that there is still a debug break call at the target address,
|
|
|
|
// so the break point is still there and the original code will hold the
|
|
|
|
// address to jump to in order to complete the call which is replaced by a
|
|
|
|
// call to DebugBreakXXX.
|
|
|
|
|
|
|
|
// Find the corresponding address in the original code.
|
|
|
|
addr += original_code->instruction_start() - code->instruction_start();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Install jump to the call address in the original code. This will be the
|
|
|
|
// call which was overwritten by the call to DebugBreakXXX.
|
|
|
|
thread_local_.after_break_target_ = Assembler::target_address_at(addr);
|
2010-06-08 12:04:49 +00:00
|
|
|
} else {
|
|
|
|
// There is no longer a break point present. Don't try to look in the
|
|
|
|
// original code as the running code will have the right address. This takes
|
|
|
|
// care of the case where the last break point is removed from the function
|
|
|
|
// and therefore no "original code" is available.
|
|
|
|
thread_local_.after_break_target_ = Assembler::target_address_at(addr);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-10 09:02:16 +00:00
|
|
|
bool Debug::IsBreakAtReturn(JavaScriptFrame* frame) {
|
|
|
|
HandleScope scope;
|
|
|
|
|
|
|
|
// Get the executing function in which the debug break occurred.
|
|
|
|
Handle<SharedFunctionInfo> shared =
|
|
|
|
Handle<SharedFunctionInfo>(JSFunction::cast(frame->function())->shared());
|
|
|
|
if (!EnsureDebugInfo(shared)) {
|
|
|
|
// Return if we failed to retrieve the debug info.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Handle<DebugInfo> debug_info = GetDebugInfo(shared);
|
|
|
|
Handle<Code> code(debug_info->code());
|
|
|
|
#ifdef DEBUG
|
|
|
|
// Get the code which is actually executing.
|
|
|
|
Handle<Code> frame_code(frame->code());
|
|
|
|
ASSERT(frame_code.is_identical_to(code));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Find the call address in the running code.
|
|
|
|
Address addr = frame->pc() - Assembler::kCallTargetAddressOffset;
|
|
|
|
|
|
|
|
// Check if the location is at JS return.
|
|
|
|
RelocIterator it(debug_info->code());
|
|
|
|
while (!it.done()) {
|
|
|
|
if (RelocInfo::IsJSReturn(it.rinfo()->rmode())) {
|
|
|
|
return (it.rinfo()->pc() ==
|
|
|
|
addr - Assembler::kPatchReturnSequenceAddressOffset);
|
|
|
|
}
|
|
|
|
it.next();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-30 17:29:00 +00:00
|
|
|
void Debug::FramesHaveBeenDropped(StackFrame::Id new_break_frame_id,
|
|
|
|
FrameDropMode mode) {
|
|
|
|
thread_local_.frame_drop_mode_ = mode;
|
2010-04-06 17:58:28 +00:00
|
|
|
thread_local_.break_frame_id_ = new_break_frame_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
bool Debug::IsDebugGlobal(GlobalObject* global) {
|
|
|
|
return IsLoaded() && global == Debug::debug_context()->global();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-16 09:54:46 +00:00
|
|
|
void Debug::ClearMirrorCache() {
|
2009-02-13 12:36:58 +00:00
|
|
|
HandleScope scope;
|
2009-01-16 09:54:46 +00:00
|
|
|
ASSERT(Top::context() == *Debug::debug_context());
|
|
|
|
|
|
|
|
// Clear the mirror cache.
|
|
|
|
Handle<String> function_name =
|
|
|
|
Factory::LookupSymbol(CStrVector("ClearMirrorCache"));
|
|
|
|
Handle<Object> fun(Top::global()->GetProperty(*function_name));
|
|
|
|
ASSERT(fun->IsJSFunction());
|
|
|
|
bool caught_exception;
|
|
|
|
Handle<Object> js_object = Execution::TryCall(
|
|
|
|
Handle<JSFunction>::cast(fun),
|
|
|
|
Handle<JSObject>(Debug::debug_context()->global()),
|
|
|
|
0, NULL, &caught_exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-18 13:14:37 +00:00
|
|
|
void Debug::CreateScriptCache() {
|
|
|
|
HandleScope scope;
|
|
|
|
|
|
|
|
// Perform two GCs to get rid of all unreferenced scripts. The first GC gets
|
|
|
|
// rid of all the cached script wrappers and the second gets rid of the
|
2010-03-23 11:40:38 +00:00
|
|
|
// scripts which are no longer referenced.
|
2009-08-25 02:54:39 +00:00
|
|
|
Heap::CollectAllGarbage(false);
|
|
|
|
Heap::CollectAllGarbage(false);
|
2009-05-18 13:14:37 +00:00
|
|
|
|
|
|
|
ASSERT(script_cache_ == NULL);
|
|
|
|
script_cache_ = new ScriptCache();
|
|
|
|
|
|
|
|
// Scan heap for Script objects.
|
|
|
|
int count = 0;
|
|
|
|
HeapIterator iterator;
|
2010-01-25 22:53:18 +00:00
|
|
|
for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) {
|
2009-10-07 12:20:02 +00:00
|
|
|
if (obj->IsScript() && Script::cast(obj)->HasValidSource()) {
|
2009-05-18 13:14:37 +00:00
|
|
|
script_cache_->Add(Handle<Script>(Script::cast(obj)));
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Debug::DestroyScriptCache() {
|
|
|
|
// Get rid of the script cache if it was created.
|
|
|
|
if (script_cache_ != NULL) {
|
|
|
|
delete script_cache_;
|
|
|
|
script_cache_ = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Debug::AddScriptToScriptCache(Handle<Script> script) {
|
|
|
|
if (script_cache_ != NULL) {
|
|
|
|
script_cache_->Add(script);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<FixedArray> Debug::GetLoadedScripts() {
|
|
|
|
// Create and fill the script cache when the loaded scripts is requested for
|
|
|
|
// the first time.
|
|
|
|
if (script_cache_ == NULL) {
|
|
|
|
CreateScriptCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the script cache is not active just return an empty array.
|
|
|
|
ASSERT(script_cache_ != NULL);
|
|
|
|
if (script_cache_ == NULL) {
|
|
|
|
Factory::NewFixedArray(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Perform GC to get unreferenced scripts evicted from the cache before
|
|
|
|
// returning the content.
|
2009-08-25 02:54:39 +00:00
|
|
|
Heap::CollectAllGarbage(false);
|
2009-05-18 13:14:37 +00:00
|
|
|
|
|
|
|
// Get the scripts from the cache.
|
|
|
|
return script_cache_->GetScripts();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Debug::AfterGarbageCollection() {
|
|
|
|
// Generate events for collected scripts.
|
|
|
|
if (script_cache_ != NULL) {
|
|
|
|
script_cache_->ProcessCollectedScripts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-31 11:24:59 +00:00
|
|
|
Mutex* Debugger::debugger_access_ = OS::CreateMutex();
|
2009-02-03 07:59:12 +00:00
|
|
|
Handle<Object> Debugger::event_listener_ = Handle<Object>();
|
|
|
|
Handle<Object> Debugger::event_listener_data_ = Handle<Object>();
|
2008-07-03 15:10:15 +00:00
|
|
|
bool Debugger::compiling_natives_ = false;
|
2008-08-14 13:41:48 +00:00
|
|
|
bool Debugger::is_loading_debugger_ = false;
|
2009-03-31 11:24:59 +00:00
|
|
|
bool Debugger::never_unload_debugger_ = false;
|
2009-04-29 12:54:07 +00:00
|
|
|
v8::Debug::MessageHandler2 Debugger::message_handler_ = NULL;
|
2009-05-25 07:51:04 +00:00
|
|
|
bool Debugger::debugger_unload_pending_ = false;
|
2009-04-21 14:06:48 +00:00
|
|
|
v8::Debug::HostDispatchHandler Debugger::host_dispatch_handler_ = NULL;
|
2010-01-18 15:48:41 +00:00
|
|
|
Mutex* Debugger::dispatch_handler_access_ = OS::CreateMutex();
|
2009-11-18 08:59:28 +00:00
|
|
|
v8::Debug::DebugMessageDispatchHandler
|
|
|
|
Debugger::debug_message_dispatch_handler_ = NULL;
|
2010-01-18 15:48:41 +00:00
|
|
|
MessageDispatchHelperThread* Debugger::message_dispatch_helper_thread_ = NULL;
|
2009-04-22 14:16:50 +00:00
|
|
|
int Debugger::host_dispatch_micros_ = 100 * 1000;
|
2009-03-03 12:23:45 +00:00
|
|
|
DebuggerAgent* Debugger::agent_ = NULL;
|
2009-04-24 12:05:40 +00:00
|
|
|
LockingCommandMessageQueue Debugger::command_queue_(kQueueInitialSize);
|
2009-03-27 09:56:53 +00:00
|
|
|
Semaphore* Debugger::command_received_ = OS::CreateSemaphore(0);
|
2010-07-14 08:23:35 +00:00
|
|
|
LockingCommandMessageQueue Debugger::event_command_queue_(kQueueInitialSize);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
Handle<Object> Debugger::MakeJSObject(Vector<const char> constructor_name,
|
|
|
|
int argc, Object*** argv,
|
|
|
|
bool* caught_exception) {
|
|
|
|
ASSERT(Top::context() == *Debug::debug_context());
|
|
|
|
|
|
|
|
// Create the execution state object.
|
|
|
|
Handle<String> constructor_str = Factory::LookupSymbol(constructor_name);
|
|
|
|
Handle<Object> constructor(Top::global()->GetProperty(*constructor_str));
|
|
|
|
ASSERT(constructor->IsJSFunction());
|
|
|
|
if (!constructor->IsJSFunction()) {
|
|
|
|
*caught_exception = true;
|
|
|
|
return Factory::undefined_value();
|
|
|
|
}
|
|
|
|
Handle<Object> js_object = Execution::TryCall(
|
|
|
|
Handle<JSFunction>::cast(constructor),
|
|
|
|
Handle<JSObject>(Debug::debug_context()->global()), argc, argv,
|
|
|
|
caught_exception);
|
|
|
|
return js_object;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Object> Debugger::MakeExecutionState(bool* caught_exception) {
|
|
|
|
// Create the execution state object.
|
2009-03-06 11:03:14 +00:00
|
|
|
Handle<Object> break_id = Factory::NewNumberFromInt(Debug::break_id());
|
2008-07-03 15:10:15 +00:00
|
|
|
const int argc = 1;
|
|
|
|
Object** argv[argc] = { break_id.location() };
|
|
|
|
return MakeJSObject(CStrVector("MakeExecutionState"),
|
|
|
|
argc, argv, caught_exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Object> Debugger::MakeBreakEvent(Handle<Object> exec_state,
|
|
|
|
Handle<Object> break_points_hit,
|
|
|
|
bool* caught_exception) {
|
|
|
|
// Create the new break event object.
|
|
|
|
const int argc = 2;
|
|
|
|
Object** argv[argc] = { exec_state.location(),
|
|
|
|
break_points_hit.location() };
|
|
|
|
return MakeJSObject(CStrVector("MakeBreakEvent"),
|
|
|
|
argc,
|
|
|
|
argv,
|
|
|
|
caught_exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Object> Debugger::MakeExceptionEvent(Handle<Object> exec_state,
|
|
|
|
Handle<Object> exception,
|
|
|
|
bool uncaught,
|
|
|
|
bool* caught_exception) {
|
|
|
|
// Create the new exception event object.
|
|
|
|
const int argc = 3;
|
|
|
|
Object** argv[argc] = { exec_state.location(),
|
|
|
|
exception.location(),
|
|
|
|
uncaught ? Factory::true_value().location() :
|
|
|
|
Factory::false_value().location()};
|
|
|
|
return MakeJSObject(CStrVector("MakeExceptionEvent"),
|
|
|
|
argc, argv, caught_exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Object> Debugger::MakeNewFunctionEvent(Handle<Object> function,
|
|
|
|
bool* caught_exception) {
|
|
|
|
// Create the new function event object.
|
|
|
|
const int argc = 1;
|
|
|
|
Object** argv[argc] = { function.location() };
|
|
|
|
return MakeJSObject(CStrVector("MakeNewFunctionEvent"),
|
|
|
|
argc, argv, caught_exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Object> Debugger::MakeCompileEvent(Handle<Script> script,
|
2009-02-05 10:10:45 +00:00
|
|
|
bool before,
|
2008-07-03 15:10:15 +00:00
|
|
|
bool* caught_exception) {
|
|
|
|
// Create the compile event object.
|
|
|
|
Handle<Object> exec_state = MakeExecutionState(caught_exception);
|
2009-02-05 10:10:45 +00:00
|
|
|
Handle<Object> script_wrapper = GetScriptWrapper(script);
|
2008-07-03 15:10:15 +00:00
|
|
|
const int argc = 3;
|
2009-02-05 10:10:45 +00:00
|
|
|
Object** argv[argc] = { exec_state.location(),
|
|
|
|
script_wrapper.location(),
|
|
|
|
before ? Factory::true_value().location() :
|
|
|
|
Factory::false_value().location() };
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
return MakeJSObject(CStrVector("MakeCompileEvent"),
|
|
|
|
argc,
|
|
|
|
argv,
|
|
|
|
caught_exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-18 13:14:37 +00:00
|
|
|
Handle<Object> Debugger::MakeScriptCollectedEvent(int id,
|
|
|
|
bool* caught_exception) {
|
|
|
|
// Create the script collected event object.
|
|
|
|
Handle<Object> exec_state = MakeExecutionState(caught_exception);
|
|
|
|
Handle<Object> id_object = Handle<Smi>(Smi::FromInt(id));
|
|
|
|
const int argc = 2;
|
|
|
|
Object** argv[argc] = { exec_state.location(), id_object.location() };
|
|
|
|
|
|
|
|
return MakeJSObject(CStrVector("MakeScriptCollectedEvent"),
|
|
|
|
argc,
|
|
|
|
argv,
|
|
|
|
caught_exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void Debugger::OnException(Handle<Object> exception, bool uncaught) {
|
|
|
|
HandleScope scope;
|
|
|
|
|
|
|
|
// Bail out based on state or if there is no listener for this event
|
|
|
|
if (Debug::InDebugger()) return;
|
|
|
|
if (!Debugger::EventActive(v8::Exception)) return;
|
|
|
|
|
|
|
|
// Bail out if exception breaks are not active
|
|
|
|
if (uncaught) {
|
|
|
|
// Uncaught exceptions are reported by either flags.
|
|
|
|
if (!(Debug::break_on_uncaught_exception() ||
|
|
|
|
Debug::break_on_exception())) return;
|
|
|
|
} else {
|
|
|
|
// Caught exceptions are reported is activated.
|
|
|
|
if (!Debug::break_on_exception()) return;
|
|
|
|
}
|
|
|
|
|
2008-10-03 09:57:18 +00:00
|
|
|
// Enter the debugger.
|
|
|
|
EnterDebugger debugger;
|
|
|
|
if (debugger.FailedToEnter()) return;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Clear all current stepping setup.
|
|
|
|
Debug::ClearStepping();
|
|
|
|
// Create the event data object.
|
|
|
|
bool caught_exception = false;
|
|
|
|
Handle<Object> exec_state = MakeExecutionState(&caught_exception);
|
|
|
|
Handle<Object> event_data;
|
|
|
|
if (!caught_exception) {
|
|
|
|
event_data = MakeExceptionEvent(exec_state, exception, uncaught,
|
|
|
|
&caught_exception);
|
|
|
|
}
|
|
|
|
// Bail out and don't call debugger if exception.
|
|
|
|
if (caught_exception) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-29 09:04:20 +00:00
|
|
|
// Process debug event.
|
|
|
|
ProcessDebugEvent(v8::Exception, Handle<JSObject>::cast(event_data), false);
|
2008-07-03 15:10:15 +00:00
|
|
|
// Return to continue execution from where the exception was thrown.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-13 13:26:21 +00:00
|
|
|
void Debugger::OnDebugBreak(Handle<Object> break_points_hit,
|
|
|
|
bool auto_continue) {
|
2008-07-03 15:10:15 +00:00
|
|
|
HandleScope scope;
|
|
|
|
|
2008-07-16 07:07:30 +00:00
|
|
|
// Debugger has already been entered by caller.
|
|
|
|
ASSERT(Top::context() == *Debug::debug_context());
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Bail out if there is no listener for this event
|
|
|
|
if (!Debugger::EventActive(v8::Break)) return;
|
|
|
|
|
|
|
|
// Debugger must be entered in advance.
|
|
|
|
ASSERT(Top::context() == *Debug::debug_context());
|
|
|
|
|
|
|
|
// Create the event data object.
|
|
|
|
bool caught_exception = false;
|
|
|
|
Handle<Object> exec_state = MakeExecutionState(&caught_exception);
|
|
|
|
Handle<Object> event_data;
|
|
|
|
if (!caught_exception) {
|
|
|
|
event_data = MakeBreakEvent(exec_state, break_points_hit,
|
|
|
|
&caught_exception);
|
|
|
|
}
|
|
|
|
// Bail out and don't call debugger if exception.
|
|
|
|
if (caught_exception) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-29 09:04:20 +00:00
|
|
|
// Process debug event.
|
|
|
|
ProcessDebugEvent(v8::Break,
|
|
|
|
Handle<JSObject>::cast(event_data),
|
|
|
|
auto_continue);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Debugger::OnBeforeCompile(Handle<Script> script) {
|
|
|
|
HandleScope scope;
|
|
|
|
|
|
|
|
// Bail out based on state or if there is no listener for this event
|
|
|
|
if (Debug::InDebugger()) return;
|
|
|
|
if (compiling_natives()) return;
|
|
|
|
if (!EventActive(v8::BeforeCompile)) return;
|
|
|
|
|
2008-10-03 09:57:18 +00:00
|
|
|
// Enter the debugger.
|
|
|
|
EnterDebugger debugger;
|
|
|
|
if (debugger.FailedToEnter()) return;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Create the event data object.
|
|
|
|
bool caught_exception = false;
|
2009-02-05 10:10:45 +00:00
|
|
|
Handle<Object> event_data = MakeCompileEvent(script, true, &caught_exception);
|
2008-07-03 15:10:15 +00:00
|
|
|
// Bail out and don't call debugger if exception.
|
|
|
|
if (caught_exception) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-29 09:04:20 +00:00
|
|
|
// Process debug event.
|
|
|
|
ProcessDebugEvent(v8::BeforeCompile,
|
|
|
|
Handle<JSObject>::cast(event_data),
|
|
|
|
true);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Handle debugger actions when a new script is compiled.
|
2010-03-05 22:08:58 +00:00
|
|
|
void Debugger::OnAfterCompile(Handle<Script> script,
|
|
|
|
AfterCompileFlags after_compile_flags) {
|
2008-07-16 07:07:30 +00:00
|
|
|
HandleScope scope;
|
|
|
|
|
2009-05-18 13:14:37 +00:00
|
|
|
// Add the newly compiled script to the script cache.
|
|
|
|
Debug::AddScriptToScriptCache(script);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// No more to do if not debugging.
|
2009-03-31 11:24:59 +00:00
|
|
|
if (!IsDebuggerActive()) return;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-05-18 13:14:37 +00:00
|
|
|
// No compile events while compiling natives.
|
|
|
|
if (compiling_natives()) return;
|
|
|
|
|
2009-02-05 10:10:45 +00:00
|
|
|
// Store whether in debugger before entering debugger.
|
|
|
|
bool in_debugger = Debug::InDebugger();
|
|
|
|
|
2008-10-03 09:57:18 +00:00
|
|
|
// Enter the debugger.
|
|
|
|
EnterDebugger debugger;
|
|
|
|
if (debugger.FailedToEnter()) return;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// If debugging there might be script break points registered for this
|
|
|
|
// script. Make sure that these break points are set.
|
|
|
|
|
2010-03-23 11:40:38 +00:00
|
|
|
// Get the function UpdateScriptBreakPoints (defined in debug-debugger.js).
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<Object> update_script_break_points =
|
|
|
|
Handle<Object>(Debug::debug_context()->global()->GetProperty(
|
|
|
|
*Factory::LookupAsciiSymbol("UpdateScriptBreakPoints")));
|
|
|
|
if (!update_script_break_points->IsJSFunction()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ASSERT(update_script_break_points->IsJSFunction());
|
|
|
|
|
|
|
|
// Wrap the script object in a proper JS object before passing it
|
|
|
|
// to JavaScript.
|
|
|
|
Handle<JSValue> wrapper = GetScriptWrapper(script);
|
|
|
|
|
|
|
|
// Call UpdateScriptBreakPoints expect no exceptions.
|
2008-07-16 07:07:30 +00:00
|
|
|
bool caught_exception = false;
|
2008-07-03 15:10:15 +00:00
|
|
|
const int argc = 1;
|
|
|
|
Object** argv[argc] = { reinterpret_cast<Object**>(wrapper.location()) };
|
|
|
|
Handle<Object> result = Execution::TryCall(
|
|
|
|
Handle<JSFunction>::cast(update_script_break_points),
|
|
|
|
Top::builtins(), argc, argv,
|
|
|
|
&caught_exception);
|
|
|
|
if (caught_exception) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Bail out based on state or if there is no listener for this event
|
2010-03-05 22:08:58 +00:00
|
|
|
if (in_debugger && (after_compile_flags & SEND_WHEN_DEBUGGING) == 0) return;
|
2008-07-03 15:10:15 +00:00
|
|
|
if (!Debugger::EventActive(v8::AfterCompile)) return;
|
|
|
|
|
|
|
|
// Create the compile state object.
|
|
|
|
Handle<Object> event_data = MakeCompileEvent(script,
|
2009-02-05 10:10:45 +00:00
|
|
|
false,
|
2008-07-03 15:10:15 +00:00
|
|
|
&caught_exception);
|
|
|
|
// Bail out and don't call debugger if exception.
|
|
|
|
if (caught_exception) {
|
|
|
|
return;
|
|
|
|
}
|
2009-04-29 09:04:20 +00:00
|
|
|
// Process debug event.
|
|
|
|
ProcessDebugEvent(v8::AfterCompile,
|
|
|
|
Handle<JSObject>::cast(event_data),
|
|
|
|
true);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-18 13:14:37 +00:00
|
|
|
void Debugger::OnScriptCollected(int id) {
|
|
|
|
HandleScope scope;
|
|
|
|
|
|
|
|
// No more to do if not debugging.
|
|
|
|
if (!IsDebuggerActive()) return;
|
|
|
|
if (!Debugger::EventActive(v8::ScriptCollected)) return;
|
|
|
|
|
|
|
|
// Enter the debugger.
|
|
|
|
EnterDebugger debugger;
|
|
|
|
if (debugger.FailedToEnter()) return;
|
|
|
|
|
|
|
|
// Create the script collected state object.
|
|
|
|
bool caught_exception = false;
|
|
|
|
Handle<Object> event_data = MakeScriptCollectedEvent(id,
|
|
|
|
&caught_exception);
|
|
|
|
// Bail out and don't call debugger if exception.
|
|
|
|
if (caught_exception) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process debug event.
|
|
|
|
ProcessDebugEvent(v8::ScriptCollected,
|
|
|
|
Handle<JSObject>::cast(event_data),
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void Debugger::ProcessDebugEvent(v8::DebugEvent event,
|
2009-04-29 09:04:20 +00:00
|
|
|
Handle<JSObject> event_data,
|
2009-03-13 13:26:21 +00:00
|
|
|
bool auto_continue) {
|
2009-02-13 12:36:58 +00:00
|
|
|
HandleScope scope;
|
|
|
|
|
2009-05-29 08:42:02 +00:00
|
|
|
// Clear any pending debug break if this is a real break.
|
|
|
|
if (!auto_continue) {
|
|
|
|
Debug::clear_interrupt_pending(DEBUGBREAK);
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Create the execution state.
|
|
|
|
bool caught_exception = false;
|
|
|
|
Handle<Object> exec_state = MakeExecutionState(&caught_exception);
|
|
|
|
if (caught_exception) {
|
|
|
|
return;
|
|
|
|
}
|
2009-03-27 09:56:53 +00:00
|
|
|
// First notify the message handler if any.
|
|
|
|
if (message_handler_ != NULL) {
|
2009-04-29 09:04:20 +00:00
|
|
|
NotifyMessageHandler(event,
|
|
|
|
Handle<JSObject>::cast(exec_state),
|
|
|
|
event_data,
|
|
|
|
auto_continue);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2010-07-14 08:23:35 +00:00
|
|
|
// Notify registered debug event listener. This can be either a C or
|
|
|
|
// a JavaScript function. Don't call event listener for v8::Break
|
|
|
|
// here, if it's only a debug command -- they will be processed later.
|
|
|
|
if ((event != v8::Break || !auto_continue) && !event_listener_.is_null()) {
|
|
|
|
CallEventCallback(event, exec_state, event_data, NULL);
|
|
|
|
}
|
|
|
|
// Process pending debug commands.
|
|
|
|
if (event == v8::Break) {
|
|
|
|
while (!event_command_queue_.IsEmpty()) {
|
|
|
|
CommandMessage command = event_command_queue_.Get();
|
|
|
|
if (!event_listener_.is_null()) {
|
|
|
|
CallEventCallback(v8::BreakForCommand,
|
|
|
|
exec_state,
|
|
|
|
event_data,
|
|
|
|
command.client_data());
|
|
|
|
}
|
|
|
|
command.Dispose();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-14 08:23:35 +00:00
|
|
|
void Debugger::CallEventCallback(v8::DebugEvent event,
|
|
|
|
Handle<Object> exec_state,
|
|
|
|
Handle<Object> event_data,
|
|
|
|
v8::Debug::ClientData* client_data) {
|
|
|
|
if (event_listener_->IsProxy()) {
|
|
|
|
CallCEventCallback(event, exec_state, event_data, client_data);
|
|
|
|
} else {
|
|
|
|
CallJSEventCallback(event, exec_state, event_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Debugger::CallCEventCallback(v8::DebugEvent event,
|
|
|
|
Handle<Object> exec_state,
|
|
|
|
Handle<Object> event_data,
|
|
|
|
v8::Debug::ClientData* client_data) {
|
|
|
|
Handle<Proxy> callback_obj(Handle<Proxy>::cast(event_listener_));
|
|
|
|
v8::Debug::EventCallback2 callback =
|
|
|
|
FUNCTION_CAST<v8::Debug::EventCallback2>(callback_obj->proxy());
|
|
|
|
EventDetailsImpl event_details(
|
|
|
|
event,
|
|
|
|
Handle<JSObject>::cast(exec_state),
|
|
|
|
Handle<JSObject>::cast(event_data),
|
|
|
|
event_listener_data_,
|
|
|
|
client_data);
|
|
|
|
callback(event_details);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Debugger::CallJSEventCallback(v8::DebugEvent event,
|
|
|
|
Handle<Object> exec_state,
|
|
|
|
Handle<Object> event_data) {
|
|
|
|
ASSERT(event_listener_->IsJSFunction());
|
|
|
|
Handle<JSFunction> fun(Handle<JSFunction>::cast(event_listener_));
|
|
|
|
|
|
|
|
// Invoke the JavaScript debug event listener.
|
|
|
|
const int argc = 4;
|
|
|
|
Object** argv[argc] = { Handle<Object>(Smi::FromInt(event)).location(),
|
|
|
|
exec_state.location(),
|
|
|
|
Handle<Object>::cast(event_data).location(),
|
|
|
|
event_listener_data_.location() };
|
|
|
|
bool caught_exception = false;
|
|
|
|
Execution::TryCall(fun, Top::global(), argc, argv, &caught_exception);
|
|
|
|
// Silently ignore exceptions from debug event listeners.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-28 08:23:20 +00:00
|
|
|
Handle<Context> Debugger::GetDebugContext() {
|
|
|
|
never_unload_debugger_ = true;
|
|
|
|
EnterDebugger debugger;
|
|
|
|
return Debug::debug_context();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-31 11:24:59 +00:00
|
|
|
void Debugger::UnloadDebugger() {
|
|
|
|
// Make sure that there are no breakpoints left.
|
|
|
|
Debug::ClearAllBreakPoints();
|
|
|
|
|
|
|
|
// Unload the debugger if feasible.
|
|
|
|
if (!never_unload_debugger_) {
|
|
|
|
Debug::Unload();
|
|
|
|
}
|
|
|
|
|
2009-05-25 07:51:04 +00:00
|
|
|
// Clear the flag indicating that the debugger should be unloaded.
|
|
|
|
debugger_unload_pending_ = false;
|
2009-03-31 11:24:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-27 09:56:53 +00:00
|
|
|
void Debugger::NotifyMessageHandler(v8::DebugEvent event,
|
2009-04-29 09:04:20 +00:00
|
|
|
Handle<JSObject> exec_state,
|
|
|
|
Handle<JSObject> event_data,
|
2009-03-13 13:26:21 +00:00
|
|
|
bool auto_continue) {
|
2009-02-13 12:36:58 +00:00
|
|
|
HandleScope scope;
|
|
|
|
|
2008-07-16 07:07:30 +00:00
|
|
|
if (!Debug::Load()) return;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Process the individual events.
|
2009-04-27 12:38:20 +00:00
|
|
|
bool sendEventMessage = false;
|
2008-07-03 15:10:15 +00:00
|
|
|
switch (event) {
|
|
|
|
case v8::Break:
|
2010-07-14 08:23:35 +00:00
|
|
|
case v8::BreakForCommand:
|
2009-04-27 12:38:20 +00:00
|
|
|
sendEventMessage = !auto_continue;
|
2008-07-03 15:10:15 +00:00
|
|
|
break;
|
|
|
|
case v8::Exception:
|
2009-04-27 12:38:20 +00:00
|
|
|
sendEventMessage = true;
|
2008-07-03 15:10:15 +00:00
|
|
|
break;
|
|
|
|
case v8::BeforeCompile:
|
|
|
|
break;
|
|
|
|
case v8::AfterCompile:
|
2009-04-27 12:38:20 +00:00
|
|
|
sendEventMessage = true;
|
2008-07-03 15:10:15 +00:00
|
|
|
break;
|
2009-05-18 13:14:37 +00:00
|
|
|
case v8::ScriptCollected:
|
|
|
|
sendEventMessage = true;
|
|
|
|
break;
|
2008-07-03 15:10:15 +00:00
|
|
|
case v8::NewFunction:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
2009-04-27 12:38:20 +00:00
|
|
|
// The debug command interrupt flag might have been set when the command was
|
|
|
|
// added. It should be enough to clear the flag only once while we are in the
|
|
|
|
// debugger.
|
|
|
|
ASSERT(Debug::InDebugger());
|
|
|
|
StackGuard::Continue(DEBUGCOMMAND);
|
|
|
|
|
|
|
|
// Notify the debugger that a debug event has occurred unless auto continue is
|
|
|
|
// active in which case no event is send.
|
|
|
|
if (sendEventMessage) {
|
2009-04-29 09:04:20 +00:00
|
|
|
MessageImpl message = MessageImpl::NewEvent(
|
|
|
|
event,
|
|
|
|
auto_continue,
|
|
|
|
Handle<JSObject>::cast(exec_state),
|
|
|
|
Handle<JSObject>::cast(event_data));
|
|
|
|
InvokeMessageHandler(message);
|
2009-04-27 12:38:20 +00:00
|
|
|
}
|
2009-05-27 20:57:01 +00:00
|
|
|
|
|
|
|
// If auto continue don't make the event cause a break, but process messages
|
|
|
|
// in the queue if any. For script collected events don't even process
|
|
|
|
// messages in the queue as the execution state might not be what is expected
|
|
|
|
// by the client.
|
2009-05-29 19:17:48 +00:00
|
|
|
if ((auto_continue && !HasCommands()) || event == v8::ScriptCollected) {
|
2009-04-27 12:38:20 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
v8::TryCatch try_catch;
|
2009-10-15 20:06:08 +00:00
|
|
|
|
|
|
|
// DebugCommandProcessor goes here.
|
|
|
|
v8::Local<v8::Object> cmd_processor;
|
|
|
|
{
|
|
|
|
v8::Local<v8::Object> api_exec_state =
|
|
|
|
v8::Utils::ToLocal(Handle<JSObject>::cast(exec_state));
|
|
|
|
v8::Local<v8::String> fun_name =
|
|
|
|
v8::String::New("debugCommandProcessor");
|
|
|
|
v8::Local<v8::Function> fun =
|
|
|
|
v8::Function::Cast(*api_exec_state->Get(fun_name));
|
|
|
|
|
|
|
|
v8::Handle<v8::Boolean> running =
|
|
|
|
auto_continue ? v8::True() : v8::False();
|
|
|
|
static const int kArgc = 1;
|
|
|
|
v8::Handle<Value> argv[kArgc] = { running };
|
|
|
|
cmd_processor = v8::Object::Cast(*fun->Call(api_exec_state, kArgc, argv));
|
|
|
|
if (try_catch.HasCaught()) {
|
|
|
|
PrintLn(try_catch.Exception());
|
|
|
|
return;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2009-10-15 20:06:08 +00:00
|
|
|
bool running = auto_continue;
|
|
|
|
|
2009-03-13 13:26:21 +00:00
|
|
|
// Process requests from the debugger.
|
2008-07-03 15:10:15 +00:00
|
|
|
while (true) {
|
2009-03-13 13:26:21 +00:00
|
|
|
// Wait for new command in the queue.
|
2009-04-22 14:16:50 +00:00
|
|
|
if (Debugger::host_dispatch_handler_) {
|
|
|
|
// In case there is a host dispatch - do periodic dispatches.
|
|
|
|
if (!command_received_->Wait(host_dispatch_micros_)) {
|
|
|
|
// Timout expired, do the dispatch.
|
|
|
|
Debugger::host_dispatch_handler_();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// In case there is no host dispatch - just wait.
|
|
|
|
command_received_->Wait();
|
|
|
|
}
|
2009-03-13 13:26:21 +00:00
|
|
|
|
|
|
|
// Get the command from the queue.
|
2009-04-24 12:05:40 +00:00
|
|
|
CommandMessage command = command_queue_.Get();
|
2009-03-13 13:26:21 +00:00
|
|
|
Logger::DebugTag("Got request from command queue, in interactive loop.");
|
2009-03-31 11:24:59 +00:00
|
|
|
if (!Debugger::IsDebuggerActive()) {
|
2009-04-21 14:06:48 +00:00
|
|
|
// Delete command text and user data.
|
|
|
|
command.Dispose();
|
2008-07-03 15:10:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-27 09:56:53 +00:00
|
|
|
// Invoke JavaScript to process the debug request.
|
2008-07-03 15:10:15 +00:00
|
|
|
v8::Local<v8::String> fun_name;
|
|
|
|
v8::Local<v8::Function> fun;
|
2008-11-24 10:31:22 +00:00
|
|
|
v8::Local<v8::Value> request;
|
2008-07-03 15:10:15 +00:00
|
|
|
v8::TryCatch try_catch;
|
2008-11-24 10:31:22 +00:00
|
|
|
fun_name = v8::String::New("processDebugRequest");
|
2008-07-03 15:10:15 +00:00
|
|
|
fun = v8::Function::Cast(*cmd_processor->Get(fun_name));
|
2009-04-21 14:48:54 +00:00
|
|
|
|
2009-04-21 14:06:48 +00:00
|
|
|
request = v8::String::New(command.text().start(),
|
|
|
|
command.text().length());
|
2008-11-24 10:31:22 +00:00
|
|
|
static const int kArgc = 1;
|
|
|
|
v8::Handle<Value> argv[kArgc] = { request };
|
|
|
|
v8::Local<v8::Value> response_val = fun->Call(cmd_processor, kArgc, argv);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-11-24 10:31:22 +00:00
|
|
|
// Get the response.
|
|
|
|
v8::Local<v8::String> response;
|
2008-07-03 15:10:15 +00:00
|
|
|
if (!try_catch.HasCaught()) {
|
2008-11-24 10:31:22 +00:00
|
|
|
// Get response string.
|
|
|
|
if (!response_val->IsUndefined()) {
|
|
|
|
response = v8::String::Cast(*response_val);
|
|
|
|
} else {
|
|
|
|
response = v8::String::New("");
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Log the JSON request/response.
|
|
|
|
if (FLAG_trace_debug_json) {
|
2008-11-24 10:31:22 +00:00
|
|
|
PrintLn(request);
|
|
|
|
PrintLn(response);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the running state.
|
2008-11-24 10:31:22 +00:00
|
|
|
fun_name = v8::String::New("isRunning");
|
|
|
|
fun = v8::Function::Cast(*cmd_processor->Get(fun_name));
|
|
|
|
static const int kArgc = 1;
|
|
|
|
v8::Handle<Value> argv[kArgc] = { response };
|
|
|
|
v8::Local<v8::Value> running_val = fun->Call(cmd_processor, kArgc, argv);
|
|
|
|
if (!try_catch.HasCaught()) {
|
|
|
|
running = running_val->ToBoolean()->Value();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// In case of failure the result text is the exception text.
|
2008-11-24 10:31:22 +00:00
|
|
|
response = try_catch.Exception()->ToString();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the result.
|
2009-04-29 09:04:20 +00:00
|
|
|
MessageImpl message = MessageImpl::NewResponse(
|
|
|
|
event,
|
|
|
|
running,
|
|
|
|
Handle<JSObject>::cast(exec_state),
|
|
|
|
Handle<JSObject>::cast(event_data),
|
|
|
|
Handle<String>(Utils::OpenHandle(*response)),
|
|
|
|
command.client_data());
|
|
|
|
InvokeMessageHandler(message);
|
|
|
|
command.Dispose();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-03-16 07:36:52 +00:00
|
|
|
// Return from debug event processing if either the VM is put into the
|
|
|
|
// runnning state (through a continue command) or auto continue is active
|
|
|
|
// and there are no more commands queued.
|
2009-10-15 20:06:08 +00:00
|
|
|
if (running && !HasCommands()) {
|
2008-07-03 15:10:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-27 09:56:53 +00:00
|
|
|
void Debugger::SetEventListener(Handle<Object> callback,
|
|
|
|
Handle<Object> data) {
|
|
|
|
HandleScope scope;
|
|
|
|
|
|
|
|
// Clear the global handles for the event listener and the event listener data
|
|
|
|
// object.
|
|
|
|
if (!event_listener_.is_null()) {
|
|
|
|
GlobalHandles::Destroy(
|
|
|
|
reinterpret_cast<Object**>(event_listener_.location()));
|
|
|
|
event_listener_ = Handle<Object>();
|
|
|
|
}
|
|
|
|
if (!event_listener_data_.is_null()) {
|
|
|
|
GlobalHandles::Destroy(
|
|
|
|
reinterpret_cast<Object**>(event_listener_data_.location()));
|
|
|
|
event_listener_data_ = Handle<Object>();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is a new debug event listener register it together with its data
|
|
|
|
// object.
|
|
|
|
if (!callback->IsUndefined() && !callback->IsNull()) {
|
|
|
|
event_listener_ = Handle<Object>::cast(GlobalHandles::Create(*callback));
|
|
|
|
if (data.is_null()) {
|
|
|
|
data = Factory::undefined_value();
|
|
|
|
}
|
|
|
|
event_listener_data_ = Handle<Object>::cast(GlobalHandles::Create(*data));
|
|
|
|
}
|
|
|
|
|
2009-05-25 07:51:04 +00:00
|
|
|
ListenersChanged();
|
2009-03-27 09:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-29 12:54:07 +00:00
|
|
|
void Debugger::SetMessageHandler(v8::Debug::MessageHandler2 handler) {
|
2009-03-31 11:24:59 +00:00
|
|
|
ScopedLock with(debugger_access_);
|
|
|
|
|
2009-03-27 09:56:53 +00:00
|
|
|
message_handler_ = handler;
|
2009-05-25 07:51:04 +00:00
|
|
|
ListenersChanged();
|
2009-04-24 12:05:40 +00:00
|
|
|
if (handler == NULL) {
|
2009-03-31 11:24:59 +00:00
|
|
|
// Send an empty command to the debugger if in a break to make JavaScript
|
|
|
|
// run again if the debugger is closed.
|
|
|
|
if (Debug::InDebugger()) {
|
|
|
|
ProcessCommand(Vector<const uint16_t>::empty());
|
|
|
|
}
|
2009-03-27 09:56:53 +00:00
|
|
|
}
|
2009-05-25 07:51:04 +00:00
|
|
|
}
|
2009-05-20 20:28:33 +00:00
|
|
|
|
2009-05-25 07:51:04 +00:00
|
|
|
|
|
|
|
void Debugger::ListenersChanged() {
|
2009-05-20 20:28:33 +00:00
|
|
|
if (IsDebuggerActive()) {
|
2009-05-25 07:51:04 +00:00
|
|
|
// Disable the compilation cache when the debugger is active.
|
2009-05-20 20:28:33 +00:00
|
|
|
CompilationCache::Disable();
|
2010-01-15 22:40:57 +00:00
|
|
|
debugger_unload_pending_ = false;
|
2009-05-20 20:28:33 +00:00
|
|
|
} else {
|
|
|
|
CompilationCache::Enable();
|
2009-05-25 07:51:04 +00:00
|
|
|
// Unload the debugger if event listener and message handler cleared.
|
2010-01-15 22:40:57 +00:00
|
|
|
// Schedule this for later, because we may be in non-V8 thread.
|
|
|
|
debugger_unload_pending_ = true;
|
2009-05-20 20:28:33 +00:00
|
|
|
}
|
2009-03-27 09:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-22 14:16:50 +00:00
|
|
|
void Debugger::SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler,
|
|
|
|
int period) {
|
2009-03-27 09:56:53 +00:00
|
|
|
host_dispatch_handler_ = handler;
|
2009-04-22 14:16:50 +00:00
|
|
|
host_dispatch_micros_ = period * 1000;
|
2009-03-27 09:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-18 08:59:28 +00:00
|
|
|
void Debugger::SetDebugMessageDispatchHandler(
|
2010-01-18 15:48:41 +00:00
|
|
|
v8::Debug::DebugMessageDispatchHandler handler, bool provide_locker) {
|
|
|
|
ScopedLock with(dispatch_handler_access_);
|
2009-11-18 08:59:28 +00:00
|
|
|
debug_message_dispatch_handler_ = handler;
|
2010-01-18 15:48:41 +00:00
|
|
|
|
|
|
|
if (provide_locker && message_dispatch_helper_thread_ == NULL) {
|
|
|
|
message_dispatch_helper_thread_ = new MessageDispatchHelperThread;
|
|
|
|
message_dispatch_helper_thread_->Start();
|
|
|
|
}
|
2009-11-18 08:59:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-27 09:56:53 +00:00
|
|
|
// Calls the registered debug message handler. This callback is part of the
|
2009-04-29 09:04:20 +00:00
|
|
|
// public API.
|
|
|
|
void Debugger::InvokeMessageHandler(MessageImpl message) {
|
2009-03-31 11:24:59 +00:00
|
|
|
ScopedLock with(debugger_access_);
|
|
|
|
|
2009-03-27 09:56:53 +00:00
|
|
|
if (message_handler_ != NULL) {
|
2009-04-29 09:04:20 +00:00
|
|
|
message_handler_(message);
|
2009-03-27 09:56:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-30 08:49:36 +00:00
|
|
|
// Puts a command coming from the public API on the queue. Creates
|
|
|
|
// a copy of the command string managed by the debugger. Up to this
|
|
|
|
// point, the command data was managed by the API client. Called
|
2009-04-24 12:05:40 +00:00
|
|
|
// by the API client thread.
|
2009-04-21 14:06:48 +00:00
|
|
|
void Debugger::ProcessCommand(Vector<const uint16_t> command,
|
|
|
|
v8::Debug::ClientData* client_data) {
|
|
|
|
// Need to cast away const.
|
2009-04-24 12:05:40 +00:00
|
|
|
CommandMessage message = CommandMessage::New(
|
2009-03-27 09:56:53 +00:00
|
|
|
Vector<uint16_t>(const_cast<uint16_t*>(command.start()),
|
2009-04-21 14:06:48 +00:00
|
|
|
command.length()),
|
|
|
|
client_data);
|
2008-08-06 10:02:49 +00:00
|
|
|
Logger::DebugTag("Put command on command_queue.");
|
2009-04-21 14:06:48 +00:00
|
|
|
command_queue_.Put(message);
|
2008-07-03 15:10:15 +00:00
|
|
|
command_received_->Signal();
|
2009-04-15 19:09:38 +00:00
|
|
|
|
|
|
|
// Set the debug command break flag to have the command processed.
|
2009-03-13 13:26:21 +00:00
|
|
|
if (!Debug::InDebugger()) {
|
|
|
|
StackGuard::DebugCommand();
|
|
|
|
}
|
2009-11-18 08:59:28 +00:00
|
|
|
|
2010-01-18 15:48:41 +00:00
|
|
|
MessageDispatchHelperThread* dispatch_thread;
|
|
|
|
{
|
|
|
|
ScopedLock with(dispatch_handler_access_);
|
|
|
|
dispatch_thread = message_dispatch_helper_thread_;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dispatch_thread == NULL) {
|
|
|
|
CallMessageDispatchHandler();
|
|
|
|
} else {
|
|
|
|
dispatch_thread->Schedule();
|
2009-11-18 08:59:28 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-27 09:56:53 +00:00
|
|
|
bool Debugger::HasCommands() {
|
|
|
|
return !command_queue_.IsEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-14 08:23:35 +00:00
|
|
|
void Debugger::EnqueueDebugCommand(v8::Debug::ClientData* client_data) {
|
|
|
|
CommandMessage message = CommandMessage::New(Vector<uint16_t>(), client_data);
|
|
|
|
event_command_queue_.Put(message);
|
|
|
|
|
|
|
|
// Set the debug command break flag to have the command processed.
|
|
|
|
if (!Debug::InDebugger()) {
|
|
|
|
StackGuard::DebugCommand();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-31 11:24:59 +00:00
|
|
|
bool Debugger::IsDebuggerActive() {
|
|
|
|
ScopedLock with(debugger_access_);
|
|
|
|
|
|
|
|
return message_handler_ != NULL || !event_listener_.is_null();
|
2009-03-27 09:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Object> Debugger::Call(Handle<JSFunction> fun,
|
|
|
|
Handle<Object> data,
|
|
|
|
bool* pending_exception) {
|
2009-03-31 11:24:59 +00:00
|
|
|
// When calling functions in the debugger prevent it from beeing unloaded.
|
|
|
|
Debugger::never_unload_debugger_ = true;
|
|
|
|
|
2009-03-27 09:56:53 +00:00
|
|
|
// Enter the debugger.
|
|
|
|
EnterDebugger debugger;
|
2010-03-24 13:09:02 +00:00
|
|
|
if (debugger.FailedToEnter()) {
|
2009-03-27 09:56:53 +00:00
|
|
|
return Factory::undefined_value();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the execution state.
|
|
|
|
bool caught_exception = false;
|
|
|
|
Handle<Object> exec_state = MakeExecutionState(&caught_exception);
|
|
|
|
if (caught_exception) {
|
|
|
|
return Factory::undefined_value();
|
|
|
|
}
|
|
|
|
|
|
|
|
static const int kArgc = 2;
|
|
|
|
Object** argv[kArgc] = { exec_state.location(), data.location() };
|
2010-03-24 13:09:02 +00:00
|
|
|
Handle<Object> result = Execution::Call(
|
|
|
|
fun,
|
|
|
|
Handle<Object>(Debug::debug_context_->global_proxy()),
|
|
|
|
kArgc,
|
|
|
|
argv,
|
|
|
|
pending_exception);
|
2009-03-27 09:56:53 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-18 20:30:29 +00:00
|
|
|
static void StubMessageHandler2(const v8::Debug::Message& message) {
|
|
|
|
// Simply ignore message.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Debugger::StartAgent(const char* name, int port,
|
|
|
|
bool wait_for_connection) {
|
|
|
|
if (wait_for_connection) {
|
|
|
|
// Suspend V8 if it is already running or set V8 to suspend whenever
|
|
|
|
// it starts.
|
|
|
|
// Provide stub message handler; V8 auto-continues each suspend
|
|
|
|
// when there is no message handler; we doesn't need it.
|
|
|
|
// Once become suspended, V8 will stay so indefinitely long, until remote
|
|
|
|
// debugger connects and issues "continue" command.
|
|
|
|
Debugger::message_handler_ = StubMessageHandler2;
|
|
|
|
v8::Debug::DebugBreak();
|
|
|
|
}
|
|
|
|
|
2009-03-27 09:56:53 +00:00
|
|
|
if (Socket::Setup()) {
|
|
|
|
agent_ = new DebuggerAgent(name, port);
|
|
|
|
agent_->Start();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Debugger::StopAgent() {
|
|
|
|
if (agent_ != NULL) {
|
|
|
|
agent_->Shutdown();
|
|
|
|
agent_->Join();
|
|
|
|
delete agent_;
|
|
|
|
agent_ = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-25 10:36:00 +00:00
|
|
|
void Debugger::WaitForAgent() {
|
|
|
|
if (agent_ != NULL)
|
|
|
|
agent_->WaitUntilListening();
|
|
|
|
}
|
|
|
|
|
2010-01-18 15:48:41 +00:00
|
|
|
|
|
|
|
void Debugger::CallMessageDispatchHandler() {
|
|
|
|
v8::Debug::DebugMessageDispatchHandler handler;
|
|
|
|
{
|
|
|
|
ScopedLock with(dispatch_handler_access_);
|
|
|
|
handler = Debugger::debug_message_dispatch_handler_;
|
|
|
|
}
|
|
|
|
if (handler != NULL) {
|
|
|
|
handler();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-29 09:04:20 +00:00
|
|
|
MessageImpl MessageImpl::NewEvent(DebugEvent event,
|
|
|
|
bool running,
|
|
|
|
Handle<JSObject> exec_state,
|
|
|
|
Handle<JSObject> event_data) {
|
|
|
|
MessageImpl message(true, event, running,
|
|
|
|
exec_state, event_data, Handle<String>(), NULL);
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MessageImpl MessageImpl::NewResponse(DebugEvent event,
|
|
|
|
bool running,
|
|
|
|
Handle<JSObject> exec_state,
|
|
|
|
Handle<JSObject> event_data,
|
|
|
|
Handle<String> response_json,
|
|
|
|
v8::Debug::ClientData* client_data) {
|
|
|
|
MessageImpl message(false, event, running,
|
|
|
|
exec_state, event_data, response_json, client_data);
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MessageImpl::MessageImpl(bool is_event,
|
|
|
|
DebugEvent event,
|
|
|
|
bool running,
|
|
|
|
Handle<JSObject> exec_state,
|
|
|
|
Handle<JSObject> event_data,
|
|
|
|
Handle<String> response_json,
|
|
|
|
v8::Debug::ClientData* client_data)
|
|
|
|
: is_event_(is_event),
|
|
|
|
event_(event),
|
|
|
|
running_(running),
|
|
|
|
exec_state_(exec_state),
|
|
|
|
event_data_(event_data),
|
|
|
|
response_json_(response_json),
|
|
|
|
client_data_(client_data) {}
|
|
|
|
|
|
|
|
|
|
|
|
bool MessageImpl::IsEvent() const {
|
|
|
|
return is_event_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MessageImpl::IsResponse() const {
|
|
|
|
return !is_event_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DebugEvent MessageImpl::GetEvent() const {
|
|
|
|
return event_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MessageImpl::WillStartRunning() const {
|
|
|
|
return running_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v8::Handle<v8::Object> MessageImpl::GetExecutionState() const {
|
|
|
|
return v8::Utils::ToLocal(exec_state_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v8::Handle<v8::Object> MessageImpl::GetEventData() const {
|
|
|
|
return v8::Utils::ToLocal(event_data_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v8::Handle<v8::String> MessageImpl::GetJSON() const {
|
|
|
|
v8::HandleScope scope;
|
|
|
|
|
|
|
|
if (IsEvent()) {
|
|
|
|
// Call toJSONProtocol on the debug event object.
|
|
|
|
Handle<Object> fun = GetProperty(event_data_, "toJSONProtocol");
|
|
|
|
if (!fun->IsJSFunction()) {
|
|
|
|
return v8::Handle<v8::String>();
|
|
|
|
}
|
|
|
|
bool caught_exception;
|
|
|
|
Handle<Object> json = Execution::TryCall(Handle<JSFunction>::cast(fun),
|
|
|
|
event_data_,
|
|
|
|
0, NULL, &caught_exception);
|
|
|
|
if (caught_exception || !json->IsString()) {
|
|
|
|
return v8::Handle<v8::String>();
|
|
|
|
}
|
|
|
|
return scope.Close(v8::Utils::ToLocal(Handle<String>::cast(json)));
|
|
|
|
} else {
|
|
|
|
return v8::Utils::ToLocal(response_json_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v8::Handle<v8::Context> MessageImpl::GetEventContext() const {
|
2010-05-20 17:15:46 +00:00
|
|
|
v8::Handle<v8::Context> context = GetDebugEventContext();
|
|
|
|
// Top::context() may be NULL when "script collected" event occures.
|
|
|
|
ASSERT(!context.IsEmpty() || event_ == v8::ScriptCollected);
|
|
|
|
return GetDebugEventContext();
|
2009-04-29 09:04:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v8::Debug::ClientData* MessageImpl::GetClientData() const {
|
|
|
|
return client_data_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-20 17:15:46 +00:00
|
|
|
EventDetailsImpl::EventDetailsImpl(DebugEvent event,
|
|
|
|
Handle<JSObject> exec_state,
|
|
|
|
Handle<JSObject> event_data,
|
2010-07-14 08:23:35 +00:00
|
|
|
Handle<Object> callback_data,
|
|
|
|
v8::Debug::ClientData* client_data)
|
2010-05-20 17:15:46 +00:00
|
|
|
: event_(event),
|
|
|
|
exec_state_(exec_state),
|
|
|
|
event_data_(event_data),
|
2010-07-14 08:23:35 +00:00
|
|
|
callback_data_(callback_data),
|
|
|
|
client_data_(client_data) {}
|
2010-05-20 17:15:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
DebugEvent EventDetailsImpl::GetEvent() const {
|
|
|
|
return event_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v8::Handle<v8::Object> EventDetailsImpl::GetExecutionState() const {
|
|
|
|
return v8::Utils::ToLocal(exec_state_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v8::Handle<v8::Object> EventDetailsImpl::GetEventData() const {
|
|
|
|
return v8::Utils::ToLocal(event_data_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v8::Handle<v8::Context> EventDetailsImpl::GetEventContext() const {
|
|
|
|
return GetDebugEventContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v8::Handle<v8::Value> EventDetailsImpl::GetCallbackData() const {
|
|
|
|
return v8::Utils::ToLocal(callback_data_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-14 08:23:35 +00:00
|
|
|
v8::Debug::ClientData* EventDetailsImpl::GetClientData() const {
|
|
|
|
return client_data_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-24 12:05:40 +00:00
|
|
|
CommandMessage::CommandMessage() : text_(Vector<uint16_t>::empty()),
|
|
|
|
client_data_(NULL) {
|
2009-03-27 09:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-24 12:05:40 +00:00
|
|
|
CommandMessage::CommandMessage(const Vector<uint16_t>& text,
|
|
|
|
v8::Debug::ClientData* data)
|
2009-04-21 14:06:48 +00:00
|
|
|
: text_(text),
|
2009-04-22 14:16:50 +00:00
|
|
|
client_data_(data) {
|
2009-04-21 14:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-24 12:05:40 +00:00
|
|
|
CommandMessage::~CommandMessage() {
|
2009-04-21 14:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-24 12:05:40 +00:00
|
|
|
void CommandMessage::Dispose() {
|
2009-04-21 14:06:48 +00:00
|
|
|
text_.Dispose();
|
|
|
|
delete client_data_;
|
|
|
|
client_data_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-24 12:05:40 +00:00
|
|
|
CommandMessage CommandMessage::New(const Vector<uint16_t>& command,
|
|
|
|
v8::Debug::ClientData* data) {
|
|
|
|
return CommandMessage(command.Clone(), data);
|
2009-04-21 14:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-24 12:05:40 +00:00
|
|
|
CommandMessageQueue::CommandMessageQueue(int size) : start_(0), end_(0),
|
|
|
|
size_(size) {
|
|
|
|
messages_ = NewArray<CommandMessage>(size);
|
2008-07-30 08:49:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-24 12:05:40 +00:00
|
|
|
CommandMessageQueue::~CommandMessageQueue() {
|
2009-04-21 14:48:54 +00:00
|
|
|
while (!IsEmpty()) {
|
2009-04-24 12:05:40 +00:00
|
|
|
CommandMessage m = Get();
|
2009-04-21 14:06:48 +00:00
|
|
|
m.Dispose();
|
|
|
|
}
|
2008-07-30 08:49:36 +00:00
|
|
|
DeleteArray(messages_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-24 12:05:40 +00:00
|
|
|
CommandMessage CommandMessageQueue::Get() {
|
2008-07-30 08:49:36 +00:00
|
|
|
ASSERT(!IsEmpty());
|
|
|
|
int result = start_;
|
|
|
|
start_ = (start_ + 1) % size_;
|
|
|
|
return messages_[result];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-24 12:05:40 +00:00
|
|
|
void CommandMessageQueue::Put(const CommandMessage& message) {
|
2008-07-30 08:49:36 +00:00
|
|
|
if ((end_ + 1) % size_ == start_) {
|
|
|
|
Expand();
|
|
|
|
}
|
|
|
|
messages_[end_] = message;
|
|
|
|
end_ = (end_ + 1) % size_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-24 12:05:40 +00:00
|
|
|
void CommandMessageQueue::Expand() {
|
|
|
|
CommandMessageQueue new_queue(size_ * 2);
|
2008-07-30 08:49:36 +00:00
|
|
|
while (!IsEmpty()) {
|
|
|
|
new_queue.Put(Get());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2009-04-24 12:05:40 +00:00
|
|
|
CommandMessage* array_to_free = messages_;
|
2008-07-30 08:49:36 +00:00
|
|
|
*this = new_queue;
|
|
|
|
new_queue.messages_ = array_to_free;
|
2009-04-21 14:06:48 +00:00
|
|
|
// Make the new_queue empty so that it doesn't call Dispose on any messages.
|
|
|
|
new_queue.start_ = new_queue.end_;
|
2008-07-30 08:49:36 +00:00
|
|
|
// Automatic destructor called on new_queue, freeing array_to_free.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-24 12:05:40 +00:00
|
|
|
LockingCommandMessageQueue::LockingCommandMessageQueue(int size)
|
|
|
|
: queue_(size) {
|
2008-07-30 08:49:36 +00:00
|
|
|
lock_ = OS::CreateMutex();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-24 12:05:40 +00:00
|
|
|
LockingCommandMessageQueue::~LockingCommandMessageQueue() {
|
2008-07-30 08:49:36 +00:00
|
|
|
delete lock_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-24 12:05:40 +00:00
|
|
|
bool LockingCommandMessageQueue::IsEmpty() const {
|
2008-07-30 08:49:36 +00:00
|
|
|
ScopedLock sl(lock_);
|
|
|
|
return queue_.IsEmpty();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2008-07-30 08:49:36 +00:00
|
|
|
|
2009-04-24 12:05:40 +00:00
|
|
|
CommandMessage LockingCommandMessageQueue::Get() {
|
2008-07-30 08:49:36 +00:00
|
|
|
ScopedLock sl(lock_);
|
2009-04-24 12:05:40 +00:00
|
|
|
CommandMessage result = queue_.Get();
|
2009-04-21 14:06:48 +00:00
|
|
|
Logger::DebugEvent("Get", result.text());
|
2008-07-30 08:49:36 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-24 12:05:40 +00:00
|
|
|
void LockingCommandMessageQueue::Put(const CommandMessage& message) {
|
2008-07-30 08:49:36 +00:00
|
|
|
ScopedLock sl(lock_);
|
|
|
|
queue_.Put(message);
|
2009-04-21 14:06:48 +00:00
|
|
|
Logger::DebugEvent("Put", message.text());
|
2008-07-30 08:49:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-24 12:05:40 +00:00
|
|
|
void LockingCommandMessageQueue::Clear() {
|
2008-07-30 08:49:36 +00:00
|
|
|
ScopedLock sl(lock_);
|
|
|
|
queue_.Clear();
|
|
|
|
}
|
|
|
|
|
2010-01-18 15:48:41 +00:00
|
|
|
|
|
|
|
MessageDispatchHelperThread::MessageDispatchHelperThread()
|
|
|
|
: sem_(OS::CreateSemaphore(0)), mutex_(OS::CreateMutex()),
|
|
|
|
already_signalled_(false) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MessageDispatchHelperThread::~MessageDispatchHelperThread() {
|
|
|
|
delete mutex_;
|
|
|
|
delete sem_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MessageDispatchHelperThread::Schedule() {
|
|
|
|
{
|
|
|
|
ScopedLock lock(mutex_);
|
|
|
|
if (already_signalled_) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
already_signalled_ = true;
|
|
|
|
}
|
|
|
|
sem_->Signal();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MessageDispatchHelperThread::Run() {
|
|
|
|
while (true) {
|
|
|
|
sem_->Wait();
|
|
|
|
{
|
|
|
|
ScopedLock lock(mutex_);
|
|
|
|
already_signalled_ = false;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
Locker locker;
|
|
|
|
Debugger::CallMessageDispatchHandler();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-20 16:36:13 +00:00
|
|
|
#endif // ENABLE_DEBUGGER_SUPPORT
|
2008-07-30 08:49:36 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|