2012-04-20 11:06:12 +00:00
|
|
|
// Copyright 2012 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.
|
|
|
|
|
2009-05-04 13:36:43 +00:00
|
|
|
#ifndef V8_DEBUG_H_
|
|
|
|
#define V8_DEBUG_H_
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-05-06 06:50:20 +00:00
|
|
|
#include "allocation.h"
|
2011-03-18 20:35:07 +00:00
|
|
|
#include "arguments.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "assembler.h"
|
2009-03-03 12:23:45 +00:00
|
|
|
#include "debug-agent.h"
|
2008-10-03 09:57:18 +00:00
|
|
|
#include "execution.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "factory.h"
|
2011-01-06 13:14:32 +00:00
|
|
|
#include "flags.h"
|
2011-07-12 08:03:19 +00:00
|
|
|
#include "frames-inl.h"
|
2009-05-18 13:14:37 +00:00
|
|
|
#include "hashmap.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "platform.h"
|
|
|
|
#include "string-stream.h"
|
2009-03-06 11:03:14 +00:00
|
|
|
#include "v8threads.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-04-20 16:36:13 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
|
|
|
#include "../include/v8-debug.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-03-06 11:03:14 +00:00
|
|
|
|
|
|
|
// Forward declarations.
|
|
|
|
class EnterDebugger;
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Step actions. NOTE: These values are in macros.py as well.
|
|
|
|
enum StepAction {
|
|
|
|
StepNone = -1, // Stepping not prepared.
|
|
|
|
StepOut = 0, // Step out of the current function.
|
|
|
|
StepNext = 1, // Step to the next statement in the current function.
|
|
|
|
StepIn = 2, // Step into new functions invoked or the next statement
|
|
|
|
// in the current function.
|
|
|
|
StepMin = 3, // Perform a minimum step in the current function.
|
|
|
|
StepInMin = 4 // Step into new functions invoked or perform a minimum step
|
|
|
|
// in the current function.
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Type of exception break. NOTE: These values are in macros.py as well.
|
|
|
|
enum ExceptionBreakType {
|
|
|
|
BreakException = 0,
|
|
|
|
BreakUncaughtException = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Type of exception break. NOTE: These values are in macros.py as well.
|
|
|
|
enum BreakLocatorType {
|
|
|
|
ALL_BREAK_LOCATIONS = 0,
|
|
|
|
SOURCE_BREAK_LOCATIONS = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-07-01 13:44:10 +00:00
|
|
|
// The different types of breakpoint position alignments.
|
|
|
|
// Must match Debug.BreakPositionAlignment in debug-debugger.js
|
|
|
|
enum BreakPositionAlignment {
|
|
|
|
STATEMENT_ALIGNED = 0,
|
|
|
|
BREAK_POSITION_ALIGNED = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Class for iterating through the break points in a function and changing
|
|
|
|
// them.
|
|
|
|
class BreakLocationIterator {
|
|
|
|
public:
|
|
|
|
explicit BreakLocationIterator(Handle<DebugInfo> debug_info,
|
|
|
|
BreakLocatorType type);
|
|
|
|
virtual ~BreakLocationIterator();
|
|
|
|
|
|
|
|
void Next();
|
|
|
|
void Next(int count);
|
|
|
|
void FindBreakLocationFromAddress(Address pc);
|
2013-07-01 13:44:10 +00:00
|
|
|
void FindBreakLocationFromPosition(int position,
|
|
|
|
BreakPositionAlignment alignment);
|
2008-07-03 15:10:15 +00:00
|
|
|
void Reset();
|
|
|
|
bool Done() const;
|
|
|
|
void SetBreakPoint(Handle<Object> break_point_object);
|
|
|
|
void ClearBreakPoint(Handle<Object> break_point_object);
|
|
|
|
void SetOneShot();
|
|
|
|
void ClearOneShot();
|
2013-06-25 13:42:44 +00:00
|
|
|
bool IsStepInLocation(Isolate* isolate);
|
2013-02-15 09:27:10 +00:00
|
|
|
void PrepareStepIn(Isolate* isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
bool IsExit() const;
|
|
|
|
bool HasBreakPoint();
|
|
|
|
bool IsDebugBreak();
|
|
|
|
Object* BreakPointObjects();
|
2009-02-13 12:36:58 +00:00
|
|
|
void ClearAllDebugBreak();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2009-11-11 09:50:06 +00:00
|
|
|
inline int code_position() {
|
|
|
|
return static_cast<int>(pc() - debug_info_->code()->entry());
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
inline int break_point() { return break_point_; }
|
|
|
|
inline int position() { return position_; }
|
|
|
|
inline int statement_position() { return statement_position_; }
|
|
|
|
inline Address pc() { return reloc_iterator_->rinfo()->pc(); }
|
|
|
|
inline Code* code() { return debug_info_->code(); }
|
|
|
|
inline RelocInfo* rinfo() { return reloc_iterator_->rinfo(); }
|
2008-09-22 13:57:03 +00:00
|
|
|
inline RelocInfo::Mode rmode() const {
|
|
|
|
return reloc_iterator_->rinfo()->rmode();
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
inline RelocInfo* original_rinfo() {
|
|
|
|
return reloc_iterator_original_->rinfo();
|
|
|
|
}
|
2008-09-22 13:57:03 +00:00
|
|
|
inline RelocInfo::Mode original_rmode() const {
|
2008-07-03 15:10:15 +00:00
|
|
|
return reloc_iterator_original_->rinfo()->rmode();
|
|
|
|
}
|
|
|
|
|
2009-09-07 07:20:05 +00:00
|
|
|
bool IsDebuggerStatement();
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
protected:
|
|
|
|
bool RinfoDone() const;
|
|
|
|
void RinfoNext();
|
|
|
|
|
|
|
|
BreakLocatorType type_;
|
|
|
|
int break_point_;
|
|
|
|
int position_;
|
|
|
|
int statement_position_;
|
|
|
|
Handle<DebugInfo> debug_info_;
|
|
|
|
RelocIterator* reloc_iterator_;
|
|
|
|
RelocIterator* reloc_iterator_original_;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void SetDebugBreak();
|
|
|
|
void ClearDebugBreak();
|
2009-04-21 14:48:54 +00:00
|
|
|
|
|
|
|
void SetDebugBreakAtIC();
|
|
|
|
void ClearDebugBreakAtIC();
|
|
|
|
|
2009-02-09 12:17:39 +00:00
|
|
|
bool IsDebugBreakAtReturn();
|
|
|
|
void SetDebugBreakAtReturn();
|
|
|
|
void ClearDebugBreakAtReturn();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-06-08 12:04:49 +00:00
|
|
|
bool IsDebugBreakSlot();
|
|
|
|
bool IsDebugBreakAtSlot();
|
|
|
|
void SetDebugBreakAtSlot();
|
|
|
|
void ClearDebugBreakAtSlot();
|
|
|
|
|
2008-08-28 09:55:41 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(BreakLocationIterator);
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-05-18 13:14:37 +00:00
|
|
|
// Cache of all script objects in the heap. When a script is added a weak handle
|
|
|
|
// to it is created and that weak handle is stored in the cache. The weak handle
|
|
|
|
// callback takes care of removing the script from the cache. The key used in
|
|
|
|
// the cache is the script id.
|
|
|
|
class ScriptCache : private HashMap {
|
|
|
|
public:
|
2013-09-03 06:59:01 +00:00
|
|
|
explicit ScriptCache(Isolate* isolate)
|
|
|
|
: HashMap(ScriptMatch), isolate_(isolate), collected_scripts_(10) {}
|
2009-05-18 13:14:37 +00:00
|
|
|
virtual ~ScriptCache() { Clear(); }
|
|
|
|
|
|
|
|
// Add script to the cache.
|
|
|
|
void Add(Handle<Script> script);
|
|
|
|
|
|
|
|
// Return the scripts in the cache.
|
|
|
|
Handle<FixedArray> GetScripts();
|
|
|
|
|
|
|
|
// Generate debugger events for collected scripts.
|
|
|
|
void ProcessCollectedScripts();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Calculate the hash value from the key (script id).
|
2012-01-10 12:58:41 +00:00
|
|
|
static uint32_t Hash(int key) {
|
|
|
|
return ComputeIntegerHash(key, v8::internal::kZeroHashSeed);
|
|
|
|
}
|
2009-05-18 13:14:37 +00:00
|
|
|
|
|
|
|
// Scripts match if their keys (script id) match.
|
|
|
|
static bool ScriptMatch(void* key1, void* key2) { return key1 == key2; }
|
|
|
|
|
|
|
|
// Clear the cache releasing all the weak handles.
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
// Weak handle callback for scripts in the cache.
|
2013-01-25 08:31:46 +00:00
|
|
|
static void HandleWeakScript(v8::Isolate* isolate,
|
2013-06-03 08:17:04 +00:00
|
|
|
v8::Persistent<v8::Value>* obj,
|
2013-01-25 08:31:46 +00:00
|
|
|
void* data);
|
2009-05-18 13:14:37 +00:00
|
|
|
|
2013-09-03 06:59:01 +00:00
|
|
|
Isolate* isolate_;
|
2009-05-18 13:14:37 +00:00
|
|
|
// List used during GC to temporarily store id's of collected scripts.
|
|
|
|
List<int> collected_scripts_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Linked list holding debug info objects. The debug info objects are kept as
|
|
|
|
// weak handles to avoid a debug info object to keep a function alive.
|
|
|
|
class DebugInfoListNode {
|
|
|
|
public:
|
|
|
|
explicit DebugInfoListNode(DebugInfo* debug_info);
|
|
|
|
virtual ~DebugInfoListNode();
|
|
|
|
|
|
|
|
DebugInfoListNode* next() { return next_; }
|
|
|
|
void set_next(DebugInfoListNode* next) { next_ = next; }
|
|
|
|
Handle<DebugInfo> debug_info() { return debug_info_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Global (weak) handle to the debug info object.
|
|
|
|
Handle<DebugInfo> debug_info_;
|
|
|
|
|
|
|
|
// Next pointer for linked list.
|
|
|
|
DebugInfoListNode* next_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// This class contains the debugger support. The main purpose is to handle
|
|
|
|
// setting break points in the code.
|
|
|
|
//
|
|
|
|
// This class controls the debug info for all functions which currently have
|
|
|
|
// active breakpoints in them. This debug info is held in the heap root object
|
|
|
|
// debug_info which is a FixedArray. Each entry in this list is of class
|
|
|
|
// DebugInfo.
|
|
|
|
class Debug {
|
|
|
|
public:
|
2012-01-13 13:09:52 +00:00
|
|
|
void SetUp(bool create_heap_objects);
|
2011-03-18 20:35:07 +00:00
|
|
|
bool Load();
|
|
|
|
void Unload();
|
|
|
|
bool IsLoaded() { return !debug_context_.is_null(); }
|
|
|
|
bool InDebugger() { return thread_local_.debugger_entry_ != NULL; }
|
|
|
|
void PreemptionWhileInDebugger();
|
|
|
|
void Iterate(ObjectVisitor* v);
|
|
|
|
|
2011-03-30 14:17:39 +00:00
|
|
|
Object* Break(Arguments args);
|
2012-06-19 14:29:48 +00:00
|
|
|
void SetBreakPoint(Handle<JSFunction> function,
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Object> break_point_object,
|
|
|
|
int* source_position);
|
2012-06-19 14:29:48 +00:00
|
|
|
bool SetBreakPointForScript(Handle<Script> script,
|
|
|
|
Handle<Object> break_point_object,
|
2013-07-01 13:44:10 +00:00
|
|
|
int* source_position,
|
|
|
|
BreakPositionAlignment alignment);
|
2011-03-18 20:35:07 +00:00
|
|
|
void ClearBreakPoint(Handle<Object> break_point_object);
|
|
|
|
void ClearAllBreakPoints();
|
2012-06-19 14:29:48 +00:00
|
|
|
void FloodWithOneShot(Handle<JSFunction> function);
|
2012-03-15 14:17:22 +00:00
|
|
|
void FloodBoundFunctionWithOneShot(Handle<JSFunction> function);
|
2011-03-18 20:35:07 +00:00
|
|
|
void FloodHandlerWithOneShot();
|
|
|
|
void ChangeBreakOnException(ExceptionBreakType type, bool enable);
|
|
|
|
bool IsBreakOnException(ExceptionBreakType type);
|
2013-09-08 19:05:29 +00:00
|
|
|
void PrepareStep(StepAction step_action,
|
|
|
|
int step_count,
|
|
|
|
StackFrame::Id frame_id);
|
2011-03-18 20:35:07 +00:00
|
|
|
void ClearStepping();
|
2012-04-20 11:06:12 +00:00
|
|
|
void ClearStepOut();
|
|
|
|
bool IsStepping() { return thread_local_.step_count_ > 0; }
|
2011-03-18 20:35:07 +00:00
|
|
|
bool StepNextContinue(BreakLocationIterator* break_location_iterator,
|
|
|
|
JavaScriptFrame* frame);
|
2008-07-03 15:10:15 +00:00
|
|
|
static Handle<DebugInfo> GetDebugInfo(Handle<SharedFunctionInfo> shared);
|
|
|
|
static bool HasDebugInfo(Handle<SharedFunctionInfo> shared);
|
2008-07-09 11:06:54 +00:00
|
|
|
|
2011-09-13 08:31:21 +00:00
|
|
|
void PrepareForBreakPoints();
|
|
|
|
|
2012-09-03 14:23:00 +00:00
|
|
|
// This function is used in FunctionNameUsing* tests.
|
|
|
|
Object* FindSharedFunctionInfoInScript(Handle<Script> script, int position);
|
|
|
|
|
2012-06-19 14:29:48 +00:00
|
|
|
// Returns whether the operation succeeded. Compilation can only be triggered
|
|
|
|
// if a valid closure is passed as the second argument, otherwise the shared
|
|
|
|
// function needs to be compiled already.
|
|
|
|
bool EnsureDebugInfo(Handle<SharedFunctionInfo> shared,
|
|
|
|
Handle<JSFunction> function);
|
2008-07-09 11:06:54 +00:00
|
|
|
|
2009-08-19 10:18:30 +00:00
|
|
|
// Returns true if the current stub call is patched to call the debugger.
|
2008-07-03 15:10:15 +00:00
|
|
|
static bool IsDebugBreak(Address addr);
|
2009-08-19 10:18:30 +00:00
|
|
|
// Returns true if the current return statement has been patched to be
|
|
|
|
// a debugger breakpoint.
|
2009-02-13 12:36:58 +00:00
|
|
|
static bool IsDebugBreakAtReturn(RelocInfo* rinfo);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Check whether a code stub with the specified major key is a possible break
|
|
|
|
// point location.
|
|
|
|
static bool IsSourceBreakStub(Code* code);
|
|
|
|
static bool IsBreakStub(Code* code);
|
|
|
|
|
|
|
|
// Find the builtin to use for invoking the debug break
|
2009-04-21 14:48:54 +00:00
|
|
|
static Handle<Code> FindDebugBreak(Handle<Code> code, RelocInfo::Mode mode);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
static Handle<Object> GetSourceBreakLocations(
|
2013-07-01 13:44:10 +00:00
|
|
|
Handle<SharedFunctionInfo> shared,
|
|
|
|
BreakPositionAlignment position_aligment);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Getter for the debug_context.
|
2011-03-18 20:35:07 +00:00
|
|
|
inline Handle<Context> debug_context() { return debug_context_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Check whether a global object is the debug global object.
|
2011-03-18 20:35:07 +00:00
|
|
|
bool IsDebugGlobal(GlobalObject* global);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-06-10 09:02:16 +00:00
|
|
|
// Check whether this frame is just about to return.
|
2011-03-18 20:35:07 +00:00
|
|
|
bool IsBreakAtReturn(JavaScriptFrame* frame);
|
2010-06-10 09:02:16 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Fast check to see if any break points are active.
|
2011-03-18 20:35:07 +00:00
|
|
|
inline bool has_break_points() { return has_break_points_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
void NewBreak(StackFrame::Id break_frame_id);
|
|
|
|
void SetBreak(StackFrame::Id break_frame_id, int break_id);
|
|
|
|
StackFrame::Id break_frame_id() {
|
2009-03-06 11:03:14 +00:00
|
|
|
return thread_local_.break_frame_id_;
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
int break_id() { return thread_local_.break_id_; }
|
2009-03-06 11:03:14 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
bool StepInActive() { return thread_local_.step_into_fp_ != 0; }
|
|
|
|
void HandleStepIn(Handle<JSFunction> function,
|
|
|
|
Handle<Object> holder,
|
|
|
|
Address fp,
|
|
|
|
bool is_constructor);
|
|
|
|
Address step_in_fp() { return thread_local_.step_into_fp_; }
|
|
|
|
Address* step_in_fp_addr() { return &thread_local_.step_into_fp_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
bool StepOutActive() { return thread_local_.step_out_fp_ != 0; }
|
|
|
|
Address step_out_fp() { return thread_local_.step_out_fp_; }
|
2009-09-09 08:40:59 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
EnterDebugger* debugger_entry() {
|
2009-03-06 11:03:14 +00:00
|
|
|
return thread_local_.debugger_entry_;
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
void set_debugger_entry(EnterDebugger* entry) {
|
2009-03-06 11:03:14 +00:00
|
|
|
thread_local_.debugger_entry_ = entry;
|
|
|
|
}
|
|
|
|
|
2009-05-29 08:42:02 +00:00
|
|
|
// Check whether any of the specified interrupts are pending.
|
2011-03-18 20:35:07 +00:00
|
|
|
bool is_interrupt_pending(InterruptFlag what) {
|
2009-05-29 08:42:02 +00:00
|
|
|
return (thread_local_.pending_interrupts_ & what) != 0;
|
2009-03-06 11:03:14 +00:00
|
|
|
}
|
2009-05-29 08:42:02 +00:00
|
|
|
|
|
|
|
// Set specified interrupts as pending.
|
2011-03-18 20:35:07 +00:00
|
|
|
void set_interrupts_pending(InterruptFlag what) {
|
2009-05-29 08:42:02 +00:00
|
|
|
thread_local_.pending_interrupts_ |= what;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear specified interrupts from pending.
|
2011-03-18 20:35:07 +00:00
|
|
|
void clear_interrupt_pending(InterruptFlag what) {
|
2009-05-29 08:42:02 +00:00
|
|
|
thread_local_.pending_interrupts_ &= ~static_cast<int>(what);
|
2009-03-06 11:03:14 +00:00
|
|
|
}
|
|
|
|
|
2008-07-09 11:06:54 +00:00
|
|
|
// Getter and setter for the disable break state.
|
2011-03-18 20:35:07 +00:00
|
|
|
bool disable_break() { return disable_break_; }
|
|
|
|
void set_disable_break(bool disable_break) {
|
2008-07-09 11:06:54 +00:00
|
|
|
disable_break_ = disable_break;
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Getters for the current exception break state.
|
2011-03-18 20:35:07 +00:00
|
|
|
bool break_on_exception() { return break_on_exception_; }
|
|
|
|
bool break_on_uncaught_exception() {
|
2008-07-03 15:10:15 +00:00
|
|
|
return break_on_uncaught_exception_;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum AddressId {
|
|
|
|
k_after_break_target_address,
|
|
|
|
k_debug_break_return_address,
|
2010-06-08 12:04:49 +00:00
|
|
|
k_debug_break_slot_address,
|
2010-08-27 07:08:03 +00:00
|
|
|
k_restarter_frame_function_pointer
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Support for setting the address to jump to when returning from break point.
|
2011-03-18 20:35:07 +00:00
|
|
|
Address* after_break_target_address() {
|
2008-07-03 15:10:15 +00:00
|
|
|
return reinterpret_cast<Address*>(&thread_local_.after_break_target_);
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
Address* restarter_frame_function_pointer_address() {
|
2010-07-30 11:58:43 +00:00
|
|
|
Object*** address = &thread_local_.restarter_frame_function_pointer_;
|
|
|
|
return reinterpret_cast<Address*>(address);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Support for saving/restoring registers when handling debug break calls.
|
2011-03-18 20:35:07 +00:00
|
|
|
Object** register_address(int r) {
|
2008-10-03 15:53:44 +00:00
|
|
|
return ®isters_[r];
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2009-09-09 17:45:21 +00:00
|
|
|
// Access to the debug break on return code.
|
2011-03-18 20:35:07 +00:00
|
|
|
Code* debug_break_return() { return debug_break_return_; }
|
|
|
|
Code** debug_break_return_address() {
|
2008-10-03 15:53:44 +00:00
|
|
|
return &debug_break_return_;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2010-06-08 12:04:49 +00:00
|
|
|
// Access to the debug break in debug break slot code.
|
2011-03-18 20:35:07 +00:00
|
|
|
Code* debug_break_slot() { return debug_break_slot_; }
|
|
|
|
Code** debug_break_slot_address() {
|
2010-06-08 12:04:49 +00:00
|
|
|
return &debug_break_slot_;
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
static const int kEstimatedNofDebugInfoEntries = 16;
|
|
|
|
static const int kEstimatedNofBreakPointsInFunction = 16;
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
// Passed to MakeWeak.
|
2013-01-25 08:31:46 +00:00
|
|
|
static void HandleWeakDebugInfo(v8::Isolate* isolate,
|
2013-06-03 08:17:04 +00:00
|
|
|
v8::Persistent<v8::Value>* obj,
|
2013-01-25 08:31:46 +00:00
|
|
|
void* data);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
friend class Debugger;
|
2009-02-13 12:50:47 +00:00
|
|
|
friend Handle<FixedArray> GetDebuggedFunctions(); // In test-debug.cc
|
|
|
|
friend void CheckDebuggerUnloaded(bool check_functions); // In test-debug.cc
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Threading support.
|
2011-03-18 20:35:07 +00:00
|
|
|
char* ArchiveDebug(char* to);
|
|
|
|
char* RestoreDebug(char* from);
|
2008-07-03 15:10:15 +00:00
|
|
|
static int ArchiveSpacePerThread();
|
2011-03-18 20:35:07 +00:00
|
|
|
void FreeThreadResources() { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-01-16 09:54:46 +00:00
|
|
|
// Mirror cache handling.
|
2011-03-18 20:35:07 +00:00
|
|
|
void ClearMirrorCache();
|
2009-01-16 09:54:46 +00:00
|
|
|
|
2009-05-18 13:14:37 +00:00
|
|
|
// Script cache handling.
|
2011-03-18 20:35:07 +00:00
|
|
|
void CreateScriptCache();
|
|
|
|
void DestroyScriptCache();
|
|
|
|
void AddScriptToScriptCache(Handle<Script> script);
|
|
|
|
Handle<FixedArray> GetLoadedScripts();
|
2009-05-18 13:14:37 +00:00
|
|
|
|
|
|
|
// Garbage collection notifications.
|
2011-03-18 20:35:07 +00:00
|
|
|
void AfterGarbageCollection();
|
2009-05-18 13:14:37 +00:00
|
|
|
|
2008-12-09 11:12:14 +00:00
|
|
|
// Code generator routines.
|
2010-06-08 12:04:49 +00:00
|
|
|
static void GenerateSlot(MacroAssembler* masm);
|
2008-12-09 11:12:14 +00:00
|
|
|
static void GenerateLoadICDebugBreak(MacroAssembler* masm);
|
|
|
|
static void GenerateStoreICDebugBreak(MacroAssembler* masm);
|
|
|
|
static void GenerateKeyedLoadICDebugBreak(MacroAssembler* masm);
|
|
|
|
static void GenerateKeyedStoreICDebugBreak(MacroAssembler* masm);
|
2013-04-30 07:56:09 +00:00
|
|
|
static void GenerateCompareNilICDebugBreak(MacroAssembler* masm);
|
2008-12-09 11:12:14 +00:00
|
|
|
static void GenerateReturnDebugBreak(MacroAssembler* masm);
|
2011-11-08 14:39:37 +00:00
|
|
|
static void GenerateCallFunctionStubDebugBreak(MacroAssembler* masm);
|
2012-01-27 16:09:20 +00:00
|
|
|
static void GenerateCallFunctionStubRecordDebugBreak(MacroAssembler* masm);
|
|
|
|
static void GenerateCallConstructStubDebugBreak(MacroAssembler* masm);
|
|
|
|
static void GenerateCallConstructStubRecordDebugBreak(MacroAssembler* masm);
|
2010-06-08 12:04:49 +00:00
|
|
|
static void GenerateSlotDebugBreak(MacroAssembler* masm);
|
2010-04-06 17:58:28 +00:00
|
|
|
static void GeneratePlainReturnLiveEdit(MacroAssembler* masm);
|
2010-08-13 13:54:28 +00:00
|
|
|
|
|
|
|
// FrameDropper is a code replacement for a JavaScript frame with possibly
|
|
|
|
// several frames above.
|
|
|
|
// There is no calling conventions here, because it never actually gets
|
|
|
|
// called, it only gets returned to.
|
2010-04-06 17:58:28 +00:00
|
|
|
static void GenerateFrameDropperLiveEdit(MacroAssembler* masm);
|
2008-12-09 11:12:14 +00:00
|
|
|
|
|
|
|
// Called from stub-cache.cc.
|
|
|
|
static void GenerateCallICDebugBreak(MacroAssembler* masm);
|
|
|
|
|
2010-06-30 17:29:00 +00:00
|
|
|
// Describes how exactly a frame has been dropped from stack.
|
|
|
|
enum FrameDropMode {
|
|
|
|
// No frame has been dropped.
|
|
|
|
FRAMES_UNTOUCHED,
|
|
|
|
// The top JS frame had been calling IC stub. IC stub mustn't be called now.
|
|
|
|
FRAME_DROPPED_IN_IC_CALL,
|
|
|
|
// The top JS frame had been calling debug break slot stub. Patch the
|
|
|
|
// address this stub jumps to in the end.
|
|
|
|
FRAME_DROPPED_IN_DEBUG_SLOT_CALL,
|
|
|
|
// The top JS frame had been calling some C++ function. The return address
|
|
|
|
// gets patched automatically.
|
2011-04-28 20:05:50 +00:00
|
|
|
FRAME_DROPPED_IN_DIRECT_CALL,
|
2012-06-22 20:50:03 +00:00
|
|
|
FRAME_DROPPED_IN_RETURN_CALL,
|
|
|
|
CURRENTLY_SET_MODE
|
2010-06-30 17:29:00 +00:00
|
|
|
};
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
void FramesHaveBeenDropped(StackFrame::Id new_break_frame_id,
|
2010-07-30 11:58:43 +00:00
|
|
|
FrameDropMode mode,
|
|
|
|
Object** restarter_frame_function_pointer);
|
|
|
|
|
|
|
|
// Initializes an artificial stack frame. The data it contains is used for:
|
|
|
|
// a. successful work of frame dropper code which eventually gets control,
|
|
|
|
// b. being compatible with regular stack structure for various stack
|
|
|
|
// iterators.
|
|
|
|
// Returns address of stack allocated pointer to restarted function,
|
|
|
|
// the value that is called 'restarter_frame_function_pointer'. The value
|
|
|
|
// at this address (possibly updated by GC) may be used later when preparing
|
|
|
|
// 'step in' operation.
|
|
|
|
static Object** SetUpFrameDropperFrame(StackFrame* bottom_js_frame,
|
|
|
|
Handle<Code> code);
|
2010-04-06 17:58:28 +00:00
|
|
|
|
|
|
|
static const int kFrameDropperFrameSize;
|
|
|
|
|
2010-08-13 13:54:28 +00:00
|
|
|
// Architecture-specific constant.
|
|
|
|
static const bool kFrameDropperSupported;
|
|
|
|
|
2012-05-03 17:31:34 +00:00
|
|
|
/**
|
|
|
|
* Defines layout of a stack frame that supports padding. This is a regular
|
|
|
|
* internal frame that has a flexible stack structure. LiveEdit can shift
|
|
|
|
* its lower part up the stack, taking up the 'padding' space when additional
|
|
|
|
* stack memory is required.
|
|
|
|
* Such frame is expected immediately above the topmost JavaScript frame.
|
|
|
|
*
|
|
|
|
* Stack Layout:
|
|
|
|
* --- Top
|
|
|
|
* LiveEdit routine frames
|
|
|
|
* ---
|
|
|
|
* C frames of debug handler
|
|
|
|
* ---
|
|
|
|
* ...
|
|
|
|
* ---
|
|
|
|
* An internal frame that has n padding words:
|
|
|
|
* - any number of words as needed by code -- upper part of frame
|
|
|
|
* - padding size: a Smi storing n -- current size of padding
|
|
|
|
* - padding: n words filled with kPaddingValue in form of Smi
|
|
|
|
* - 3 context/type words of a regular InternalFrame
|
|
|
|
* - fp
|
|
|
|
* ---
|
|
|
|
* Topmost JavaScript frame
|
|
|
|
* ---
|
|
|
|
* ...
|
|
|
|
* --- Bottom
|
|
|
|
*/
|
|
|
|
class FramePaddingLayout : public AllStatic {
|
|
|
|
public:
|
|
|
|
// Architecture-specific constant.
|
|
|
|
static const bool kIsSupported;
|
|
|
|
|
|
|
|
// A size of frame base including fp. Padding words starts right above
|
|
|
|
// the base.
|
|
|
|
static const int kFrameBaseSize = 4;
|
|
|
|
|
|
|
|
// A number of words that should be reserved on stack for the LiveEdit use.
|
|
|
|
// Normally equals 1. Stored on stack in form of Smi.
|
|
|
|
static const int kInitialSize;
|
|
|
|
// A value that padding words are filled with (in form of Smi). Going
|
|
|
|
// bottom-top, the first word not having this value is a counter word.
|
|
|
|
static const int kPaddingValue;
|
|
|
|
};
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
2011-03-18 20:35:07 +00:00
|
|
|
explicit Debug(Isolate* isolate);
|
|
|
|
~Debug();
|
|
|
|
|
2013-09-03 06:59:01 +00:00
|
|
|
static bool CompileDebuggerScript(Isolate* isolate, int index);
|
2011-03-18 20:35:07 +00:00
|
|
|
void ClearOneShot();
|
|
|
|
void ActivateStepIn(StackFrame* frame);
|
|
|
|
void ClearStepIn();
|
|
|
|
void ActivateStepOut(StackFrame* frame);
|
|
|
|
void ClearStepNext();
|
2009-01-15 19:08:34 +00:00
|
|
|
// Returns whether the compile succeeded.
|
2011-03-18 20:35:07 +00:00
|
|
|
void RemoveDebugInfo(Handle<DebugInfo> debug_info);
|
|
|
|
void SetAfterBreakTarget(JavaScriptFrame* frame);
|
|
|
|
Handle<Object> CheckBreakPoints(Handle<Object> break_point);
|
|
|
|
bool CheckBreakPoint(Handle<Object> break_point_object);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Global handle to debug context where all the debugger JavaScript code is
|
|
|
|
// loaded.
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Context> debug_context_;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Boolean state indicating whether any break points are set.
|
2011-03-18 20:35:07 +00:00
|
|
|
bool has_break_points_;
|
2009-05-18 13:14:37 +00:00
|
|
|
|
|
|
|
// Cache of all scripts in the heap.
|
2011-03-18 20:35:07 +00:00
|
|
|
ScriptCache* script_cache_;
|
2009-05-18 13:14:37 +00:00
|
|
|
|
|
|
|
// List of active debug info objects.
|
2011-03-18 20:35:07 +00:00
|
|
|
DebugInfoListNode* debug_info_list_;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
bool disable_break_;
|
|
|
|
bool break_on_exception_;
|
|
|
|
bool break_on_uncaught_exception_;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-03-06 11:03:14 +00:00
|
|
|
// Per-thread data.
|
2008-07-03 15:10:15 +00:00
|
|
|
class ThreadLocal {
|
|
|
|
public:
|
2009-03-06 11:03:14 +00:00
|
|
|
// Counter for generating next break id.
|
|
|
|
int break_count_;
|
|
|
|
|
|
|
|
// Current break id.
|
|
|
|
int break_id_;
|
|
|
|
|
|
|
|
// Frame id for the frame of the current break.
|
|
|
|
StackFrame::Id break_frame_id_;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Step action for last step performed.
|
|
|
|
StepAction last_step_action_;
|
|
|
|
|
|
|
|
// Source statement position from last step next action.
|
|
|
|
int last_statement_position_;
|
|
|
|
|
|
|
|
// Number of steps left to perform before debug event.
|
|
|
|
int step_count_;
|
|
|
|
|
|
|
|
// Frame pointer from last step next action.
|
|
|
|
Address last_fp_;
|
|
|
|
|
2011-09-13 14:38:39 +00:00
|
|
|
// Number of queued steps left to perform before debug event.
|
|
|
|
int queued_step_count_;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Frame pointer for frame from which step in was performed.
|
|
|
|
Address step_into_fp_;
|
|
|
|
|
2009-09-09 08:40:59 +00:00
|
|
|
// Frame pointer for the frame where debugger should be called when current
|
|
|
|
// step out action is completed.
|
|
|
|
Address step_out_fp_;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Storage location for jump when exiting debug break calls.
|
|
|
|
Address after_break_target_;
|
2009-03-06 11:03:14 +00:00
|
|
|
|
2010-06-30 17:29:00 +00:00
|
|
|
// Stores the way how LiveEdit has patched the stack. It is used when
|
|
|
|
// debugger returns control back to user script.
|
|
|
|
FrameDropMode frame_drop_mode_;
|
2010-04-06 17:58:28 +00:00
|
|
|
|
2009-03-06 11:03:14 +00:00
|
|
|
// Top debugger entry.
|
|
|
|
EnterDebugger* debugger_entry_;
|
|
|
|
|
2009-05-29 08:42:02 +00:00
|
|
|
// Pending interrupts scheduled while debugging.
|
|
|
|
int pending_interrupts_;
|
2010-07-30 11:58:43 +00:00
|
|
|
|
|
|
|
// When restarter frame is on stack, stores the address
|
|
|
|
// of the pointer to function being restarted. Otherwise (most of the time)
|
|
|
|
// stores NULL. This pointer is used with 'step in' implementation.
|
|
|
|
Object** restarter_frame_function_pointer_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Storage location for registers when handling debug break calls
|
2011-03-18 20:35:07 +00:00
|
|
|
JSCallerSavedBuffer registers_;
|
|
|
|
ThreadLocal thread_local_;
|
|
|
|
void ThreadInit();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Code to call for handling debug break on return.
|
2011-03-18 20:35:07 +00:00
|
|
|
Code* debug_break_return_;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-06-08 12:04:49 +00:00
|
|
|
// Code to call for handling debug break in debug break slots.
|
2011-03-18 20:35:07 +00:00
|
|
|
Code* debug_break_slot_;
|
|
|
|
|
|
|
|
Isolate* isolate_;
|
|
|
|
|
|
|
|
friend class Isolate;
|
2010-06-08 12:04:49 +00:00
|
|
|
|
2008-08-28 09:55:41 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(Debug);
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-03-30 14:17:39 +00:00
|
|
|
DECLARE_RUNTIME_FUNCTION(Object*, Debug_Break);
|
|
|
|
|
|
|
|
|
2009-04-29 09:04:20 +00:00
|
|
|
// Message delivered to the message handler callback. This is either a debugger
|
|
|
|
// event or the response to a command.
|
|
|
|
class MessageImpl: public v8::Debug::Message {
|
|
|
|
public:
|
|
|
|
// Create a message object for a debug event.
|
|
|
|
static MessageImpl NewEvent(DebugEvent event,
|
|
|
|
bool running,
|
|
|
|
Handle<JSObject> exec_state,
|
|
|
|
Handle<JSObject> event_data);
|
|
|
|
|
|
|
|
// Create a message object for the response to a debug command.
|
|
|
|
static MessageImpl NewResponse(DebugEvent event,
|
|
|
|
bool running,
|
|
|
|
Handle<JSObject> exec_state,
|
|
|
|
Handle<JSObject> event_data,
|
|
|
|
Handle<String> response_json,
|
|
|
|
v8::Debug::ClientData* client_data);
|
|
|
|
|
|
|
|
// Implementation of interface v8::Debug::Message.
|
|
|
|
virtual bool IsEvent() const;
|
|
|
|
virtual bool IsResponse() const;
|
|
|
|
virtual DebugEvent GetEvent() const;
|
|
|
|
virtual bool WillStartRunning() const;
|
|
|
|
virtual v8::Handle<v8::Object> GetExecutionState() const;
|
|
|
|
virtual v8::Handle<v8::Object> GetEventData() const;
|
|
|
|
virtual v8::Handle<v8::String> GetJSON() const;
|
|
|
|
virtual v8::Handle<v8::Context> GetEventContext() const;
|
|
|
|
virtual v8::Debug::ClientData* GetClientData() const;
|
2013-09-10 14:26:07 +00:00
|
|
|
virtual v8::Isolate* GetIsolate() const;
|
2009-04-29 09:04:20 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
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);
|
|
|
|
|
|
|
|
bool is_event_; // Does this message represent a debug event?
|
|
|
|
DebugEvent event_; // Debug event causing the break.
|
|
|
|
bool running_; // Will the VM start running after this event?
|
|
|
|
Handle<JSObject> exec_state_; // Current execution state.
|
|
|
|
Handle<JSObject> event_data_; // Data associated with the event.
|
|
|
|
Handle<String> response_json_; // Response JSON if message holds a response.
|
|
|
|
v8::Debug::ClientData* client_data_; // Client data passed with the request.
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-05-20 17:15:46 +00:00
|
|
|
// Details of the debug event delivered to the debug event listener.
|
|
|
|
class EventDetailsImpl : public v8::Debug::EventDetails {
|
|
|
|
public:
|
|
|
|
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
|
|
|
virtual DebugEvent GetEvent() const;
|
|
|
|
virtual v8::Handle<v8::Object> GetExecutionState() const;
|
|
|
|
virtual v8::Handle<v8::Object> GetEventData() const;
|
|
|
|
virtual v8::Handle<v8::Context> GetEventContext() const;
|
|
|
|
virtual v8::Handle<v8::Value> GetCallbackData() const;
|
2010-07-14 08:23:35 +00:00
|
|
|
virtual v8::Debug::ClientData* GetClientData() const;
|
2010-05-20 17:15:46 +00:00
|
|
|
private:
|
|
|
|
DebugEvent event_; // Debug event causing the break.
|
2010-07-14 08:23:35 +00:00
|
|
|
Handle<JSObject> exec_state_; // Current execution state.
|
|
|
|
Handle<JSObject> event_data_; // Data associated with the event.
|
|
|
|
Handle<Object> callback_data_; // User data passed with the callback
|
|
|
|
// when it was registered.
|
|
|
|
v8::Debug::ClientData* client_data_; // Data passed to DebugBreakForCommand.
|
2010-05-20 17:15:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-04-21 14:06:48 +00:00
|
|
|
// Message send by user to v8 debugger or debugger output message.
|
|
|
|
// In addition to command text it may contain a pointer to some user data
|
|
|
|
// which are expected to be passed along with the command reponse to message
|
|
|
|
// handler.
|
2009-04-24 12:05:40 +00:00
|
|
|
class CommandMessage {
|
2009-04-21 14:06:48 +00:00
|
|
|
public:
|
2009-04-24 12:05:40 +00:00
|
|
|
static CommandMessage New(const Vector<uint16_t>& command,
|
2009-04-21 14:06:48 +00:00
|
|
|
v8::Debug::ClientData* data);
|
2009-04-24 12:05:40 +00:00
|
|
|
CommandMessage();
|
|
|
|
~CommandMessage();
|
2009-04-21 14:06:48 +00:00
|
|
|
|
|
|
|
// Deletes user data and disposes of the text.
|
|
|
|
void Dispose();
|
|
|
|
Vector<uint16_t> text() const { return text_; }
|
|
|
|
v8::Debug::ClientData* client_data() const { return client_data_; }
|
|
|
|
private:
|
2009-04-24 12:05:40 +00:00
|
|
|
CommandMessage(const Vector<uint16_t>& text,
|
|
|
|
v8::Debug::ClientData* data);
|
2009-04-21 14:06:48 +00:00
|
|
|
|
|
|
|
Vector<uint16_t> text_;
|
|
|
|
v8::Debug::ClientData* client_data_;
|
|
|
|
};
|
|
|
|
|
2009-04-24 12:05:40 +00:00
|
|
|
// A Queue of CommandMessage objects. A thread-safe version is
|
|
|
|
// LockingCommandMessageQueue, based on this class.
|
|
|
|
class CommandMessageQueue BASE_EMBEDDED {
|
2009-03-27 09:56:53 +00:00
|
|
|
public:
|
2009-04-24 12:05:40 +00:00
|
|
|
explicit CommandMessageQueue(int size);
|
|
|
|
~CommandMessageQueue();
|
2009-03-27 09:56:53 +00:00
|
|
|
bool IsEmpty() const { return start_ == end_; }
|
2009-04-24 12:05:40 +00:00
|
|
|
CommandMessage Get();
|
|
|
|
void Put(const CommandMessage& message);
|
2009-03-27 09:56:53 +00:00
|
|
|
void Clear() { start_ = end_ = 0; } // Queue is empty after Clear().
|
|
|
|
private:
|
|
|
|
// Doubles the size of the message queue, and copies the messages.
|
|
|
|
void Expand();
|
|
|
|
|
2009-04-24 12:05:40 +00:00
|
|
|
CommandMessage* messages_;
|
2009-03-27 09:56:53 +00:00
|
|
|
int start_;
|
|
|
|
int end_;
|
|
|
|
int size_; // The size of the queue buffer. Queue can hold size-1 messages.
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-01-18 15:48:41 +00:00
|
|
|
class MessageDispatchHelperThread;
|
|
|
|
|
|
|
|
|
2009-04-24 12:05:40 +00:00
|
|
|
// LockingCommandMessageQueue is a thread-safe circular buffer of CommandMessage
|
|
|
|
// messages. The message data is not managed by LockingCommandMessageQueue.
|
2009-03-27 09:56:53 +00:00
|
|
|
// Pointers to the data are passed in and out. Implemented by adding a
|
2009-04-24 12:05:40 +00:00
|
|
|
// Mutex to CommandMessageQueue. Includes logging of all puts and gets.
|
|
|
|
class LockingCommandMessageQueue BASE_EMBEDDED {
|
2009-03-27 09:56:53 +00:00
|
|
|
public:
|
2011-06-10 09:54:04 +00:00
|
|
|
LockingCommandMessageQueue(Logger* logger, int size);
|
2013-07-31 07:51:46 +00:00
|
|
|
bool IsEmpty() const;
|
2009-04-24 12:05:40 +00:00
|
|
|
CommandMessage Get();
|
|
|
|
void Put(const CommandMessage& message);
|
2009-03-27 09:56:53 +00:00
|
|
|
void Clear();
|
|
|
|
private:
|
2011-06-10 09:54:04 +00:00
|
|
|
Logger* logger_;
|
2009-04-24 12:05:40 +00:00
|
|
|
CommandMessageQueue queue_;
|
2013-08-29 09:58:30 +00:00
|
|
|
mutable Mutex mutex_;
|
2009-04-24 12:05:40 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(LockingCommandMessageQueue);
|
2009-03-27 09:56:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
class Debugger {
|
|
|
|
public:
|
2011-03-18 20:35:07 +00:00
|
|
|
~Debugger();
|
|
|
|
|
|
|
|
void DebugRequest(const uint16_t* json_request, int length);
|
|
|
|
|
|
|
|
Handle<Object> MakeJSObject(Vector<const char> constructor_name,
|
2011-10-06 09:31:38 +00:00
|
|
|
int argc,
|
|
|
|
Handle<Object> argv[],
|
2011-03-18 20:35:07 +00:00
|
|
|
bool* caught_exception);
|
|
|
|
Handle<Object> MakeExecutionState(bool* caught_exception);
|
|
|
|
Handle<Object> MakeBreakEvent(Handle<Object> exec_state,
|
|
|
|
Handle<Object> break_points_hit,
|
|
|
|
bool* caught_exception);
|
|
|
|
Handle<Object> MakeExceptionEvent(Handle<Object> exec_state,
|
|
|
|
Handle<Object> exception,
|
|
|
|
bool uncaught,
|
|
|
|
bool* caught_exception);
|
|
|
|
Handle<Object> MakeNewFunctionEvent(Handle<Object> func,
|
|
|
|
bool* caught_exception);
|
|
|
|
Handle<Object> MakeCompileEvent(Handle<Script> script,
|
|
|
|
bool before,
|
|
|
|
bool* caught_exception);
|
|
|
|
Handle<Object> MakeScriptCollectedEvent(int id,
|
|
|
|
bool* caught_exception);
|
|
|
|
void OnDebugBreak(Handle<Object> break_points_hit, bool auto_continue);
|
|
|
|
void OnException(Handle<Object> exception, bool uncaught);
|
|
|
|
void OnBeforeCompile(Handle<Script> script);
|
2010-03-05 22:08:58 +00:00
|
|
|
|
|
|
|
enum AfterCompileFlags {
|
|
|
|
NO_AFTER_COMPILE_FLAGS,
|
|
|
|
SEND_WHEN_DEBUGGING
|
|
|
|
};
|
2011-03-18 20:35:07 +00:00
|
|
|
void OnAfterCompile(Handle<Script> script,
|
|
|
|
AfterCompileFlags after_compile_flags);
|
|
|
|
void OnScriptCollected(int id);
|
|
|
|
void ProcessDebugEvent(v8::DebugEvent event,
|
|
|
|
Handle<JSObject> event_data,
|
|
|
|
bool auto_continue);
|
|
|
|
void NotifyMessageHandler(v8::DebugEvent event,
|
|
|
|
Handle<JSObject> exec_state,
|
|
|
|
Handle<JSObject> event_data,
|
|
|
|
bool auto_continue);
|
|
|
|
void SetEventListener(Handle<Object> callback, Handle<Object> data);
|
|
|
|
void SetMessageHandler(v8::Debug::MessageHandler2 handler);
|
|
|
|
void SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler,
|
2013-09-02 12:26:06 +00:00
|
|
|
TimeDelta period);
|
2011-03-18 20:35:07 +00:00
|
|
|
void SetDebugMessageDispatchHandler(
|
2010-01-18 15:48:41 +00:00
|
|
|
v8::Debug::DebugMessageDispatchHandler handler,
|
|
|
|
bool provide_locker);
|
2009-03-27 09:56:53 +00:00
|
|
|
|
|
|
|
// Invoke the message handler function.
|
2011-03-18 20:35:07 +00:00
|
|
|
void InvokeMessageHandler(MessageImpl message);
|
2009-03-27 09:56:53 +00:00
|
|
|
|
|
|
|
// Add a debugger command to the command queue.
|
2011-03-18 20:35:07 +00:00
|
|
|
void ProcessCommand(Vector<const uint16_t> command,
|
|
|
|
v8::Debug::ClientData* client_data = NULL);
|
2009-03-27 09:56:53 +00:00
|
|
|
|
|
|
|
// Check whether there are commands in the command queue.
|
2011-03-18 20:35:07 +00:00
|
|
|
bool HasCommands();
|
2009-03-27 09:56:53 +00:00
|
|
|
|
2010-07-14 08:23:35 +00:00
|
|
|
// Enqueue a debugger command to the command queue for event listeners.
|
2011-03-18 20:35:07 +00:00
|
|
|
void EnqueueDebugCommand(v8::Debug::ClientData* client_data = NULL);
|
2010-07-14 08:23:35 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Object> Call(Handle<JSFunction> fun,
|
|
|
|
Handle<Object> data,
|
|
|
|
bool* pending_exception);
|
2008-11-27 08:01:27 +00:00
|
|
|
|
2009-03-03 12:23:45 +00:00
|
|
|
// Start the debugger agent listening on the provided port.
|
2011-03-18 20:35:07 +00:00
|
|
|
bool StartAgent(const char* name, int port,
|
|
|
|
bool wait_for_connection = false);
|
2009-03-03 12:23:45 +00:00
|
|
|
|
2009-03-19 21:07:07 +00:00
|
|
|
// Stop the debugger agent.
|
2011-03-18 20:35:07 +00:00
|
|
|
void StopAgent();
|
2009-03-19 21:07:07 +00:00
|
|
|
|
2009-09-25 10:36:00 +00:00
|
|
|
// Blocks until the agent has started listening for connections
|
2011-03-18 20:35:07 +00:00
|
|
|
void WaitForAgent();
|
2009-09-25 10:36:00 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
void CallMessageDispatchHandler();
|
2010-01-18 15:48:41 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Context> GetDebugContext();
|
2010-04-28 08:23:20 +00:00
|
|
|
|
2009-03-31 11:24:59 +00:00
|
|
|
// Unload the debugger if possible. Only called when no debugger is currently
|
|
|
|
// active.
|
2011-03-18 20:35:07 +00:00
|
|
|
void UnloadDebugger();
|
2010-04-28 09:18:53 +00:00
|
|
|
friend void ForceUnloadDebugger(); // In test-debug.cc
|
2009-03-31 11:24:59 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
inline bool EventActive(v8::DebugEvent event) {
|
2013-08-29 09:58:30 +00:00
|
|
|
LockGuard<RecursiveMutex> lock_guard(debugger_access_);
|
2009-03-31 11:24:59 +00:00
|
|
|
|
|
|
|
// Check whether the message handler was been cleared.
|
2009-05-25 07:51:04 +00:00
|
|
|
if (debugger_unload_pending_) {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (isolate_->debug()->debugger_entry() == NULL) {
|
2010-01-15 22:40:57 +00:00
|
|
|
UnloadDebugger();
|
|
|
|
}
|
2009-03-31 11:24:59 +00:00
|
|
|
}
|
|
|
|
|
2011-01-06 13:14:32 +00:00
|
|
|
if (((event == v8::BeforeCompile) || (event == v8::AfterCompile)) &&
|
|
|
|
!FLAG_debug_compile_events) {
|
|
|
|
return false;
|
|
|
|
|
|
|
|
} else if ((event == v8::ScriptCollected) &&
|
|
|
|
!FLAG_debug_script_collected_events) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Currently argument event is not used.
|
2009-03-31 11:24:59 +00:00
|
|
|
return !compiling_natives_ && Debugger::IsDebuggerActive();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
void set_compiling_natives(bool compiling_natives) {
|
2011-10-18 13:40:33 +00:00
|
|
|
compiling_natives_ = compiling_natives;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
bool compiling_natives() const { return compiling_natives_; }
|
|
|
|
void set_loading_debugger(bool v) { is_loading_debugger_ = v; }
|
|
|
|
bool is_loading_debugger() const { return is_loading_debugger_; }
|
2012-09-10 09:24:17 +00:00
|
|
|
void set_live_edit_enabled(bool v) { live_edit_enabled_ = v; }
|
2013-01-21 17:06:30 +00:00
|
|
|
bool live_edit_enabled() const {
|
|
|
|
return FLAG_enable_liveedit && live_edit_enabled_ ;
|
|
|
|
}
|
2011-10-18 13:40:33 +00:00
|
|
|
void set_force_debugger_active(bool force_debugger_active) {
|
|
|
|
force_debugger_active_ = force_debugger_active;
|
|
|
|
}
|
|
|
|
bool force_debugger_active() const { return force_debugger_active_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
bool IsDebuggerActive();
|
2010-05-19 09:07:33 +00:00
|
|
|
|
|
|
|
private:
|
2011-06-10 09:54:04 +00:00
|
|
|
explicit Debugger(Isolate* isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
|
|
|
|
void CallEventCallback(v8::DebugEvent event,
|
|
|
|
Handle<Object> exec_state,
|
|
|
|
Handle<Object> event_data,
|
|
|
|
v8::Debug::ClientData* client_data);
|
|
|
|
void CallCEventCallback(v8::DebugEvent event,
|
|
|
|
Handle<Object> exec_state,
|
|
|
|
Handle<Object> event_data,
|
|
|
|
v8::Debug::ClientData* client_data);
|
|
|
|
void CallJSEventCallback(v8::DebugEvent event,
|
|
|
|
Handle<Object> exec_state,
|
|
|
|
Handle<Object> event_data);
|
|
|
|
void ListenersChanged();
|
|
|
|
|
2013-08-29 09:58:30 +00:00
|
|
|
RecursiveMutex* debugger_access_; // Mutex guarding debugger variables.
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Object> event_listener_; // Global handle to listener.
|
|
|
|
Handle<Object> event_listener_data_;
|
|
|
|
bool compiling_natives_; // Are we compiling natives?
|
|
|
|
bool is_loading_debugger_; // Are we loading the debugger?
|
2012-09-10 09:24:17 +00:00
|
|
|
bool live_edit_enabled_; // Enable LiveEdit.
|
2011-03-18 20:35:07 +00:00
|
|
|
bool never_unload_debugger_; // Can we unload the debugger?
|
2011-10-18 13:40:33 +00:00
|
|
|
bool force_debugger_active_; // Activate debugger without event listeners.
|
2011-03-18 20:35:07 +00:00
|
|
|
v8::Debug::MessageHandler2 message_handler_;
|
|
|
|
bool debugger_unload_pending_; // Was message handler cleared?
|
|
|
|
v8::Debug::HostDispatchHandler host_dispatch_handler_;
|
2013-08-29 09:58:30 +00:00
|
|
|
Mutex dispatch_handler_access_; // Mutex guarding dispatch handler.
|
2011-03-18 20:35:07 +00:00
|
|
|
v8::Debug::DebugMessageDispatchHandler debug_message_dispatch_handler_;
|
|
|
|
MessageDispatchHelperThread* message_dispatch_helper_thread_;
|
2013-09-02 12:26:06 +00:00
|
|
|
TimeDelta host_dispatch_period_;
|
2011-03-18 20:35:07 +00:00
|
|
|
|
|
|
|
DebuggerAgent* agent_;
|
2009-03-03 12:23:45 +00:00
|
|
|
|
2009-03-27 09:56:53 +00:00
|
|
|
static const int kQueueInitialSize = 4;
|
2011-03-18 20:35:07 +00:00
|
|
|
LockingCommandMessageQueue command_queue_;
|
2013-09-02 12:26:06 +00:00
|
|
|
Semaphore command_received_; // Signaled for each command received.
|
2011-03-18 20:35:07 +00:00
|
|
|
LockingCommandMessageQueue event_command_queue_;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate_;
|
2010-07-14 08:23:35 +00:00
|
|
|
|
2009-03-31 11:24:59 +00:00
|
|
|
friend class EnterDebugger;
|
2011-03-18 20:35:07 +00:00
|
|
|
friend class Isolate;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(Debugger);
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-10-03 09:57:18 +00:00
|
|
|
// This class is used for entering the debugger. Create an instance in the stack
|
|
|
|
// to enter the debugger. This will set the current break state, make sure the
|
|
|
|
// debugger is loaded and switch to the debugger context. If the debugger for
|
|
|
|
// some reason could not be entered FailedToEnter will return true.
|
|
|
|
class EnterDebugger BASE_EMBEDDED {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2013-09-03 06:59:01 +00:00
|
|
|
explicit EnterDebugger(Isolate* isolate);
|
2011-10-03 11:13:20 +00:00
|
|
|
~EnterDebugger();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-03 09:57:18 +00:00
|
|
|
// Check whether the debugger could be entered.
|
|
|
|
inline bool FailedToEnter() { return load_failed_; }
|
|
|
|
|
2008-11-27 08:01:27 +00:00
|
|
|
// Check whether there are any JavaScript frames on the stack.
|
2008-12-11 08:03:24 +00:00
|
|
|
inline bool HasJavaScriptFrames() { return has_js_frames_; }
|
2008-11-27 08:01:27 +00:00
|
|
|
|
2009-05-05 09:38:45 +00:00
|
|
|
// Get the active context from before entering the debugger.
|
|
|
|
inline Handle<Context> GetContext() { return save_.context(); }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate_;
|
2009-03-06 11:03:14 +00:00
|
|
|
EnterDebugger* prev_; // Previous debugger entry if entered recursively.
|
2008-07-03 15:10:15 +00:00
|
|
|
JavaScriptFrameIterator it_;
|
2008-12-11 08:03:24 +00:00
|
|
|
const bool has_js_frames_; // Were there any JavaScript frames?
|
2008-07-03 15:10:15 +00:00
|
|
|
StackFrame::Id break_frame_id_; // Previous break frame id.
|
|
|
|
int break_id_; // Previous break id.
|
2008-10-03 09:57:18 +00:00
|
|
|
bool load_failed_; // Did the debugger fail to load?
|
|
|
|
SaveContext save_; // Saves previous context.
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-09 11:06:54 +00:00
|
|
|
// Stack allocated class for disabling break.
|
|
|
|
class DisableBreak BASE_EMBEDDED {
|
|
|
|
public:
|
2013-09-03 06:59:01 +00:00
|
|
|
explicit DisableBreak(Isolate* isolate, bool disable_break)
|
|
|
|
: isolate_(isolate) {
|
2011-03-18 20:35:07 +00:00
|
|
|
prev_disable_break_ = isolate_->debug()->disable_break();
|
|
|
|
isolate_->debug()->set_disable_break(disable_break);
|
2008-07-09 11:06:54 +00:00
|
|
|
}
|
|
|
|
~DisableBreak() {
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate_->debug()->set_disable_break(prev_disable_break_);
|
2008-07-09 11:06:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate_;
|
2008-07-09 11:06:54 +00:00
|
|
|
// The previous state of the disable break used to restore the value when this
|
|
|
|
// object is destructed.
|
|
|
|
bool prev_disable_break_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Debug_Address encapsulates the Address pointers used in generating debug
|
|
|
|
// code.
|
|
|
|
class Debug_Address {
|
|
|
|
public:
|
2010-08-27 07:41:46 +00:00
|
|
|
explicit Debug_Address(Debug::AddressId id) : id_(id) { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
static Debug_Address AfterBreakTarget() {
|
|
|
|
return Debug_Address(Debug::k_after_break_target_address);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Debug_Address DebugBreakReturn() {
|
|
|
|
return Debug_Address(Debug::k_debug_break_return_address);
|
|
|
|
}
|
|
|
|
|
2010-07-30 11:58:43 +00:00
|
|
|
static Debug_Address RestarterFrameFunctionPointer() {
|
|
|
|
return Debug_Address(Debug::k_restarter_frame_function_pointer);
|
|
|
|
}
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Address address(Isolate* isolate) const {
|
|
|
|
Debug* debug = isolate->debug();
|
2008-07-03 15:10:15 +00:00
|
|
|
switch (id_) {
|
|
|
|
case Debug::k_after_break_target_address:
|
2011-03-18 20:35:07 +00:00
|
|
|
return reinterpret_cast<Address>(debug->after_break_target_address());
|
2008-07-03 15:10:15 +00:00
|
|
|
case Debug::k_debug_break_return_address:
|
2011-03-18 20:35:07 +00:00
|
|
|
return reinterpret_cast<Address>(debug->debug_break_return_address());
|
2010-06-08 12:04:49 +00:00
|
|
|
case Debug::k_debug_break_slot_address:
|
2011-03-18 20:35:07 +00:00
|
|
|
return reinterpret_cast<Address>(debug->debug_break_slot_address());
|
2010-07-30 11:58:43 +00:00
|
|
|
case Debug::k_restarter_frame_function_pointer:
|
|
|
|
return reinterpret_cast<Address>(
|
2011-03-18 20:35:07 +00:00
|
|
|
debug->restarter_frame_function_pointer_address());
|
2008-07-03 15:10:15 +00:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2011-09-08 19:57:14 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
Debug::AddressId id_;
|
|
|
|
};
|
|
|
|
|
2010-01-18 15:48:41 +00:00
|
|
|
// The optional thread that Debug Agent may use to temporary call V8 to process
|
|
|
|
// pending debug requests if debuggee is not running V8 at the moment.
|
|
|
|
// Techincally it does not call V8 itself, rather it asks embedding program
|
|
|
|
// to do this via v8::Debug::HostDispatchHandler
|
|
|
|
class MessageDispatchHelperThread: public Thread {
|
|
|
|
public:
|
2011-03-18 20:35:07 +00:00
|
|
|
explicit MessageDispatchHelperThread(Isolate* isolate);
|
2013-09-02 12:26:06 +00:00
|
|
|
~MessageDispatchHelperThread() {}
|
2010-01-18 15:48:41 +00:00
|
|
|
|
|
|
|
void Schedule();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void Run();
|
|
|
|
|
2013-03-21 16:12:50 +00:00
|
|
|
Isolate* isolate_;
|
2013-09-02 12:26:06 +00:00
|
|
|
Semaphore sem_;
|
2013-08-29 09:58:30 +00:00
|
|
|
Mutex mutex_;
|
2010-01-18 15:48:41 +00:00
|
|
|
bool already_signalled_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(MessageDispatchHelperThread);
|
|
|
|
};
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
} } // namespace v8::internal
|
|
|
|
|
2009-04-20 17:44:39 +00:00
|
|
|
#endif // ENABLE_DEBUGGER_SUPPORT
|
2009-04-20 16:36:13 +00:00
|
|
|
|
2009-05-04 13:36:43 +00:00
|
|
|
#endif // V8_DEBUG_H_
|