2012-04-20 11:06:12 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-05-04 13:36:43 +00:00
|
|
|
#ifndef V8_DEBUG_H_
|
|
|
|
#define V8_DEBUG_H_
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/allocation.h"
|
|
|
|
#include "src/arguments.h"
|
|
|
|
#include "src/assembler.h"
|
|
|
|
#include "src/execution.h"
|
|
|
|
#include "src/factory.h"
|
|
|
|
#include "src/flags.h"
|
|
|
|
#include "src/frames-inl.h"
|
|
|
|
#include "src/hashmap.h"
|
|
|
|
#include "src/liveedit.h"
|
|
|
|
#include "src/platform.h"
|
|
|
|
#include "src/string-stream.h"
|
|
|
|
#include "src/v8threads.h"
|
|
|
|
|
|
|
|
#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.
|
2014-06-03 14:39:55 +00:00
|
|
|
class DebugScope;
|
2009-03-06 11:03:14 +00:00
|
|
|
|
|
|
|
|
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:
|
2014-06-02 12:51:19 +00:00
|
|
|
explicit ScriptCache(Isolate* isolate);
|
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
|
|
|
|
|
|
|
// Clear the cache releasing all the weak handles.
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
// Weak handle callback for scripts in the cache.
|
2013-12-18 08:09:37 +00:00
|
|
|
static void HandleWeakScript(
|
|
|
|
const v8::WeakCallbackData<v8::Value, 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_;
|
|
|
|
};
|
|
|
|
|
2014-05-27 13:20:58 +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;
|
|
|
|
virtual v8::Isolate* GetIsolate() const;
|
|
|
|
|
|
|
|
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.
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 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,
|
|
|
|
Handle<Object> callback_data,
|
|
|
|
v8::Debug::ClientData* client_data);
|
|
|
|
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;
|
|
|
|
virtual v8::Debug::ClientData* GetClientData() const;
|
|
|
|
private:
|
|
|
|
DebugEvent event_; // Debug event causing the break.
|
|
|
|
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.
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
class CommandMessage {
|
|
|
|
public:
|
|
|
|
static CommandMessage New(const Vector<uint16_t>& command,
|
|
|
|
v8::Debug::ClientData* data);
|
|
|
|
CommandMessage();
|
|
|
|
|
|
|
|
// 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:
|
|
|
|
CommandMessage(const Vector<uint16_t>& text,
|
|
|
|
v8::Debug::ClientData* data);
|
|
|
|
|
|
|
|
Vector<uint16_t> text_;
|
|
|
|
v8::Debug::ClientData* client_data_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// A Queue of CommandMessage objects. A thread-safe version is
|
|
|
|
// LockingCommandMessageQueue, based on this class.
|
|
|
|
class CommandMessageQueue BASE_EMBEDDED {
|
|
|
|
public:
|
|
|
|
explicit CommandMessageQueue(int size);
|
|
|
|
~CommandMessageQueue();
|
|
|
|
bool IsEmpty() const { return start_ == end_; }
|
|
|
|
CommandMessage Get();
|
|
|
|
void Put(const CommandMessage& message);
|
|
|
|
void Clear() { start_ = end_ = 0; } // Queue is empty after Clear().
|
|
|
|
private:
|
|
|
|
// Doubles the size of the message queue, and copies the messages.
|
|
|
|
void Expand();
|
|
|
|
|
|
|
|
CommandMessage* messages_;
|
|
|
|
int start_;
|
|
|
|
int end_;
|
|
|
|
int size_; // The size of the queue buffer. Queue can hold size-1 messages.
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// LockingCommandMessageQueue is a thread-safe circular buffer of CommandMessage
|
|
|
|
// messages. The message data is not managed by LockingCommandMessageQueue.
|
|
|
|
// Pointers to the data are passed in and out. Implemented by adding a
|
|
|
|
// Mutex to CommandMessageQueue. Includes logging of all puts and gets.
|
|
|
|
class LockingCommandMessageQueue BASE_EMBEDDED {
|
|
|
|
public:
|
|
|
|
LockingCommandMessageQueue(Logger* logger, int size);
|
|
|
|
bool IsEmpty() const;
|
|
|
|
CommandMessage Get();
|
|
|
|
void Put(const CommandMessage& message);
|
|
|
|
void Clear();
|
|
|
|
private:
|
|
|
|
Logger* logger_;
|
|
|
|
CommandMessageQueue queue_;
|
|
|
|
mutable Mutex mutex_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(LockingCommandMessageQueue);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-06-02 12:51:19 +00:00
|
|
|
class PromiseOnStack {
|
|
|
|
public:
|
|
|
|
PromiseOnStack(Isolate* isolate,
|
|
|
|
PromiseOnStack* prev,
|
|
|
|
Handle<JSFunction> getter);
|
|
|
|
~PromiseOnStack();
|
|
|
|
StackHandler* handler() { return handler_; }
|
|
|
|
Handle<JSFunction> getter() { return getter_; }
|
|
|
|
PromiseOnStack* prev() { return prev_; }
|
|
|
|
private:
|
|
|
|
Isolate* isolate_;
|
|
|
|
StackHandler* handler_;
|
|
|
|
Handle<JSFunction> getter_;
|
|
|
|
PromiseOnStack* prev_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// 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:
|
2014-05-27 13:20:58 +00:00
|
|
|
enum AfterCompileFlags {
|
|
|
|
NO_AFTER_COMPILE_FLAGS,
|
|
|
|
SEND_WHEN_DEBUGGING
|
|
|
|
};
|
2014-06-02 11:41:50 +00:00
|
|
|
|
|
|
|
// Debug event triggers.
|
|
|
|
void OnDebugBreak(Handle<Object> break_points_hit, bool auto_continue);
|
|
|
|
void OnException(Handle<Object> exception, bool uncaught);
|
|
|
|
void OnBeforeCompile(Handle<Script> script);
|
2014-05-27 13:20:58 +00:00
|
|
|
void OnAfterCompile(Handle<Script> script,
|
|
|
|
AfterCompileFlags after_compile_flags);
|
|
|
|
void OnScriptCollected(int id);
|
|
|
|
|
2014-06-02 11:41:50 +00:00
|
|
|
// API facing.
|
2014-05-27 13:20:58 +00:00
|
|
|
void SetEventListener(Handle<Object> callback, Handle<Object> data);
|
|
|
|
void SetMessageHandler(v8::Debug::MessageHandler handler);
|
|
|
|
void EnqueueCommandMessage(Vector<const uint16_t> command,
|
|
|
|
v8::Debug::ClientData* client_data = NULL);
|
|
|
|
// Enqueue a debugger command to the command queue for event listeners.
|
|
|
|
void EnqueueDebugCommand(v8::Debug::ClientData* client_data = NULL);
|
|
|
|
MUST_USE_RESULT MaybeHandle<Object> Call(Handle<JSFunction> fun,
|
|
|
|
Handle<Object> data);
|
|
|
|
Handle<Context> GetDebugContext();
|
2014-06-02 12:51:19 +00:00
|
|
|
void HandleDebugBreak();
|
2014-06-02 11:41:50 +00:00
|
|
|
void ProcessDebugMessages(bool debug_command_only);
|
2014-05-27 13:20:58 +00:00
|
|
|
|
2014-06-02 12:51:19 +00:00
|
|
|
// Internal logic
|
2011-03-18 20:35:07 +00:00
|
|
|
bool Load();
|
2014-05-28 10:41:13 +00:00
|
|
|
void Break(Arguments args, JavaScriptFrame*);
|
|
|
|
void SetAfterBreakTarget(JavaScriptFrame* frame);
|
2014-06-02 11:41:50 +00:00
|
|
|
|
2014-06-02 12:51:19 +00:00
|
|
|
// Scripts handling.
|
|
|
|
Handle<FixedArray> GetLoadedScripts();
|
|
|
|
|
|
|
|
// Break point handling.
|
2014-05-08 09:33:11 +00:00
|
|
|
bool 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);
|
2014-04-30 15:17:51 +00:00
|
|
|
|
2014-06-02 12:51:19 +00:00
|
|
|
// Stepping handling.
|
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);
|
2014-06-02 12:51:19 +00:00
|
|
|
bool StepInActive() { return thread_local_.step_into_fp_ != 0; }
|
|
|
|
void HandleStepIn(Handle<JSFunction> function,
|
|
|
|
Handle<Object> holder,
|
|
|
|
Address fp,
|
|
|
|
bool is_constructor);
|
|
|
|
bool StepOutActive() { return thread_local_.step_out_fp_ != 0; }
|
|
|
|
|
|
|
|
// Purge all code objects that have no debug break slots.
|
|
|
|
void PrepareForBreakPoints();
|
2014-06-02 11:41:50 +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-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
|
|
|
|
2012-09-03 14:23:00 +00:00
|
|
|
// This function is used in FunctionNameUsing* tests.
|
|
|
|
Object* FindSharedFunctionInfoInScript(Handle<Script> script, int position);
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
// 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
|
|
|
|
2014-06-02 12:51:19 +00:00
|
|
|
// Promise handling.
|
|
|
|
void PromiseHandlePrologue(Handle<JSFunction> promise_getter);
|
|
|
|
void PromiseHandleEpilogue();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-06-02 12:51:19 +00:00
|
|
|
// Support for LiveEdit
|
2014-05-28 10:21:46 +00:00
|
|
|
void FramesHaveBeenDropped(StackFrame::Id new_break_frame_id,
|
|
|
|
LiveEdit::FrameDropMode mode,
|
|
|
|
Object** restarter_frame_function_pointer);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
// Passed to MakeWeak.
|
2013-12-18 08:09:37 +00:00
|
|
|
static void HandleWeakDebugInfo(
|
|
|
|
const v8::WeakCallbackData<v8::Value, void>& data);
|
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
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
// Record function from which eval was called.
|
|
|
|
static void RecordEvalCaller(Handle<Script> script);
|
|
|
|
|
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
|
|
|
|
2014-06-02 12:51:19 +00:00
|
|
|
// Flags and states.
|
2014-06-03 14:39:55 +00:00
|
|
|
DebugScope* debugger_entry() { return thread_local_.current_debug_scope_; }
|
2014-06-02 12:51:19 +00:00
|
|
|
inline Handle<Context> debug_context() { return debug_context_; }
|
|
|
|
void set_live_edit_enabled(bool v) { live_edit_enabled_ = v; }
|
|
|
|
bool live_edit_enabled() const {
|
|
|
|
return FLAG_enable_liveedit && live_edit_enabled_ ;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool is_active() const { return is_active_; }
|
|
|
|
inline bool is_loaded() const { return !debug_context_.is_null(); }
|
|
|
|
inline bool has_break_points() const { return has_break_points_; }
|
2014-06-03 14:39:55 +00:00
|
|
|
inline bool in_debug_scope() const {
|
|
|
|
return thread_local_.current_debug_scope_ != NULL;
|
2014-06-02 12:51:19 +00:00
|
|
|
}
|
|
|
|
void set_disable_break(bool v) { break_disabled_ = v; }
|
|
|
|
|
|
|
|
StackFrame::Id break_frame_id() { return thread_local_.break_frame_id_; }
|
|
|
|
int break_id() { return thread_local_.break_id_; }
|
|
|
|
|
|
|
|
// Support for embedding into generated code.
|
|
|
|
Address after_break_target_address() {
|
|
|
|
return reinterpret_cast<Address>(&after_break_target_);
|
|
|
|
}
|
|
|
|
|
|
|
|
Address restarter_frame_function_pointer_address() {
|
|
|
|
Object*** address = &thread_local_.restarter_frame_function_pointer_;
|
|
|
|
return reinterpret_cast<Address>(address);
|
|
|
|
}
|
|
|
|
|
|
|
|
Address step_in_fp_addr() {
|
|
|
|
return reinterpret_cast<Address>(&thread_local_.step_into_fp_);
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
2011-03-18 20:35:07 +00:00
|
|
|
explicit Debug(Isolate* isolate);
|
|
|
|
|
2014-06-02 11:41:50 +00:00
|
|
|
void UpdateState();
|
|
|
|
void Unload();
|
|
|
|
void SetNextBreakId() {
|
|
|
|
thread_local_.break_id_ = ++thread_local_.break_count_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether there are commands in the command queue.
|
|
|
|
inline bool has_commands() const { return !command_queue_.IsEmpty(); }
|
2014-06-02 12:51:19 +00:00
|
|
|
inline bool ignore_events() const { return is_suppressed_ || !is_active_; }
|
2014-06-02 11:41:50 +00:00
|
|
|
|
|
|
|
// Constructors for debug event objects.
|
2014-05-27 13:20:58 +00:00
|
|
|
MUST_USE_RESULT MaybeHandle<Object> MakeJSObject(
|
2014-06-02 11:41:50 +00:00
|
|
|
const char* constructor_name,
|
2014-05-27 13:20:58 +00:00
|
|
|
int argc,
|
|
|
|
Handle<Object> argv[]);
|
|
|
|
MUST_USE_RESULT MaybeHandle<Object> MakeExecutionState();
|
|
|
|
MUST_USE_RESULT MaybeHandle<Object> MakeBreakEvent(
|
|
|
|
Handle<Object> break_points_hit);
|
|
|
|
MUST_USE_RESULT MaybeHandle<Object> MakeExceptionEvent(
|
|
|
|
Handle<Object> exception,
|
|
|
|
bool uncaught,
|
|
|
|
Handle<Object> promise);
|
|
|
|
MUST_USE_RESULT MaybeHandle<Object> MakeCompileEvent(
|
|
|
|
Handle<Script> script, bool before);
|
|
|
|
MUST_USE_RESULT MaybeHandle<Object> MakeScriptCollectedEvent(int id);
|
|
|
|
|
2014-06-02 12:51:19 +00:00
|
|
|
// Mirror cache handling.
|
|
|
|
void ClearMirrorCache();
|
|
|
|
|
|
|
|
// Returns a promise if it does not have a reject handler.
|
|
|
|
Handle<Object> GetPromiseForUncaughtException();
|
2014-06-02 11:41:50 +00:00
|
|
|
|
2014-05-27 13:20:58 +00:00
|
|
|
void CallEventCallback(v8::DebugEvent event,
|
|
|
|
Handle<Object> exec_state,
|
|
|
|
Handle<Object> event_data,
|
|
|
|
v8::Debug::ClientData* client_data);
|
|
|
|
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 InvokeMessageHandler(MessageImpl message);
|
|
|
|
|
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);
|
|
|
|
Handle<Object> CheckBreakPoints(Handle<Object> break_point);
|
|
|
|
bool CheckBreakPoint(Handle<Object> break_point_object);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-06-03 14:39:55 +00:00
|
|
|
inline void AssertDebugContext() {
|
|
|
|
ASSERT(isolate_->context() == *debug_context());
|
|
|
|
ASSERT(in_debug_scope());
|
|
|
|
}
|
|
|
|
|
2014-05-27 13:20:58 +00:00
|
|
|
void ThreadInit();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-05-27 13:20:58 +00:00
|
|
|
// Global handles.
|
|
|
|
Handle<Context> debug_context_;
|
|
|
|
Handle<Object> event_listener_;
|
|
|
|
Handle<Object> event_listener_data_;
|
|
|
|
|
|
|
|
v8::Debug::MessageHandler message_handler_;
|
|
|
|
|
|
|
|
static const int kQueueInitialSize = 4;
|
|
|
|
Semaphore command_received_; // Signaled for each command received.
|
|
|
|
LockingCommandMessageQueue command_queue_;
|
|
|
|
LockingCommandMessageQueue event_command_queue_;
|
|
|
|
|
|
|
|
bool is_active_;
|
2014-06-02 11:41:50 +00:00
|
|
|
bool is_suppressed_;
|
2014-05-27 13:20:58 +00:00
|
|
|
bool live_edit_enabled_;
|
|
|
|
bool has_break_points_;
|
2014-06-02 11:41:50 +00:00
|
|
|
bool break_disabled_;
|
2014-05-27 13:20:58 +00:00
|
|
|
bool break_on_exception_;
|
|
|
|
bool break_on_uncaught_exception_;
|
|
|
|
|
|
|
|
ScriptCache* script_cache_; // Cache of all scripts in the heap.
|
|
|
|
DebugInfoListNode* debug_info_list_; // List of active debug info objects.
|
|
|
|
|
2014-05-28 10:41:13 +00:00
|
|
|
// Storage location for jump when exiting debug break calls.
|
|
|
|
// Note that this address is not GC safe. It should be computed immediately
|
|
|
|
// before returning to the DebugBreakCallHelper.
|
|
|
|
Address after_break_target_;
|
|
|
|
|
2009-03-06 11:03:14 +00:00
|
|
|
// Per-thread data.
|
2008-07-03 15:10:15 +00:00
|
|
|
class ThreadLocal {
|
|
|
|
public:
|
2014-05-28 10:21:46 +00:00
|
|
|
// Top debugger entry.
|
2014-06-03 14:39:55 +00:00
|
|
|
DebugScope* current_debug_scope_;
|
2014-05-28 10:21:46 +00:00
|
|
|
|
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_;
|
|
|
|
|
2014-05-28 10:21:46 +00:00
|
|
|
// Stores the way how LiveEdit has patched the stack. It is used when
|
|
|
|
// debugger returns control back to user script.
|
|
|
|
LiveEdit::FrameDropMode frame_drop_mode_;
|
|
|
|
|
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_;
|
2014-05-21 15:00:32 +00:00
|
|
|
|
|
|
|
// When a promise is being resolved, we may want to trigger a debug event
|
|
|
|
// if we catch a throw. For this purpose we remember the try-catch
|
|
|
|
// handler address that would catch the exception. We also hold onto a
|
|
|
|
// closure that returns a promise if the exception is considered uncaught.
|
|
|
|
// Due to the possibility of reentry we use a linked list.
|
|
|
|
PromiseOnStack* promise_on_stack_;
|
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
|
|
|
ThreadLocal thread_local_;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate_;
|
|
|
|
|
|
|
|
friend class Isolate;
|
2014-06-03 14:39:55 +00:00
|
|
|
friend class DebugScope;
|
2014-06-02 11:41:50 +00:00
|
|
|
friend class DisableBreak;
|
|
|
|
friend class SuppressDebug;
|
2010-06-08 12:04:49 +00:00
|
|
|
|
2014-06-02 12:51:19 +00:00
|
|
|
friend Handle<FixedArray> GetDebuggedFunctions(); // In test-debug.cc
|
|
|
|
friend void CheckDebuggerUnloaded(bool check_functions); // In test-debug.cc
|
|
|
|
|
2008-08-28 09:55:41 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(Debug);
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-04-22 12:50:58 +00:00
|
|
|
DECLARE_RUNTIME_FUNCTION(Debug_Break);
|
2011-03-30 14:17:39 +00:00
|
|
|
|
|
|
|
|
2014-06-03 14:39:55 +00:00
|
|
|
// This scope is used to load and enter the debug context and create a new
|
|
|
|
// break state. Leaving the scope will restore the previous state.
|
|
|
|
// On failure to load, FailedToEnter returns true.
|
|
|
|
class DebugScope BASE_EMBEDDED {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2014-06-03 14:39:55 +00:00
|
|
|
explicit DebugScope(Debug* debug);
|
|
|
|
~DebugScope();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-06-03 14:39:55 +00:00
|
|
|
// Check whether loading was successful.
|
|
|
|
inline bool failed() { return failed_; }
|
2008-10-03 09:57:18 +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:
|
2014-06-03 14:39:55 +00:00
|
|
|
Isolate* isolate() { return debug_->isolate_; }
|
|
|
|
|
|
|
|
Debug* debug_;
|
|
|
|
DebugScope* prev_; // Previous scope if entered recursively.
|
2008-07-03 15:10:15 +00:00
|
|
|
StackFrame::Id break_frame_id_; // Previous break frame id.
|
2014-06-03 14:39:55 +00:00
|
|
|
int break_id_; // Previous break id.
|
|
|
|
bool failed_; // Did the debug context 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:
|
2014-06-02 11:41:50 +00:00
|
|
|
explicit DisableBreak(Debug* debug, bool disable_break)
|
|
|
|
: debug_(debug), old_state_(debug->break_disabled_) {
|
|
|
|
debug_->break_disabled_ = disable_break;
|
2008-07-09 11:06:54 +00:00
|
|
|
}
|
2014-06-02 11:41:50 +00:00
|
|
|
~DisableBreak() { debug_->break_disabled_ = old_state_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Debug* debug_;
|
|
|
|
bool old_state_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(DisableBreak);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class SuppressDebug BASE_EMBEDDED {
|
|
|
|
public:
|
|
|
|
explicit SuppressDebug(Debug* debug)
|
|
|
|
: debug_(debug), old_state_(debug->is_suppressed_) {
|
|
|
|
debug_->is_suppressed_ = true;
|
2008-07-09 11:06:54 +00:00
|
|
|
}
|
2014-06-02 11:41:50 +00:00
|
|
|
~SuppressDebug() { debug_->is_suppressed_ = old_state_; }
|
2008-07-09 11:06:54 +00:00
|
|
|
|
|
|
|
private:
|
2014-06-02 11:41:50 +00:00
|
|
|
Debug* debug_;
|
|
|
|
bool old_state_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(SuppressDebug);
|
2008-07-09 11:06:54 +00:00
|
|
|
};
|
|
|
|
|
2014-05-27 13:20:58 +00:00
|
|
|
|
|
|
|
// Code generator routines.
|
|
|
|
class DebugCodegen : public AllStatic {
|
|
|
|
public:
|
|
|
|
static void GenerateSlot(MacroAssembler* masm);
|
|
|
|
static void GenerateCallICStubDebugBreak(MacroAssembler* masm);
|
|
|
|
static void GenerateLoadICDebugBreak(MacroAssembler* masm);
|
|
|
|
static void GenerateStoreICDebugBreak(MacroAssembler* masm);
|
|
|
|
static void GenerateKeyedLoadICDebugBreak(MacroAssembler* masm);
|
|
|
|
static void GenerateKeyedStoreICDebugBreak(MacroAssembler* masm);
|
|
|
|
static void GenerateCompareNilICDebugBreak(MacroAssembler* masm);
|
|
|
|
static void GenerateReturnDebugBreak(MacroAssembler* masm);
|
|
|
|
static void GenerateCallFunctionStubDebugBreak(MacroAssembler* masm);
|
|
|
|
static void GenerateCallConstructStubDebugBreak(MacroAssembler* masm);
|
|
|
|
static void GenerateCallConstructStubRecordDebugBreak(MacroAssembler* masm);
|
|
|
|
static void GenerateSlotDebugBreak(MacroAssembler* masm);
|
|
|
|
static void GeneratePlainReturnLiveEdit(MacroAssembler* masm);
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
static void GenerateFrameDropperLiveEdit(MacroAssembler* masm);
|
|
|
|
};
|
|
|
|
|
2014-05-28 10:21:46 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|
|
|
|
|
2009-05-04 13:36:43 +00:00
|
|
|
#endif // V8_DEBUG_H_
|