// Copyright 2012 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef V8_DEBUG_H_ #define V8_DEBUG_H_ #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" namespace v8 { namespace internal { // Forward declarations. class DebugScope; // 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 }; // The different types of breakpoint position alignments. // Must match Debug.BreakPositionAlignment in debug-debugger.js enum BreakPositionAlignment { STATEMENT_ALIGNED = 0, BREAK_POSITION_ALIGNED = 1 }; // Class for iterating through the break points in a function and changing // them. class BreakLocationIterator { public: explicit BreakLocationIterator(Handle debug_info, BreakLocatorType type); virtual ~BreakLocationIterator(); void Next(); void Next(int count); void FindBreakLocationFromAddress(Address pc); void FindBreakLocationFromPosition(int position, BreakPositionAlignment alignment); void Reset(); bool Done() const; void SetBreakPoint(Handle break_point_object); void ClearBreakPoint(Handle break_point_object); void SetOneShot(); void ClearOneShot(); bool IsStepInLocation(Isolate* isolate); void PrepareStepIn(Isolate* isolate); bool IsExit() const; bool HasBreakPoint(); bool IsDebugBreak(); Object* BreakPointObjects(); void ClearAllDebugBreak(); inline int code_position() { return static_cast(pc() - debug_info_->code()->entry()); } 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(); } inline RelocInfo::Mode rmode() const { return reloc_iterator_->rinfo()->rmode(); } inline RelocInfo* original_rinfo() { return reloc_iterator_original_->rinfo(); } inline RelocInfo::Mode original_rmode() const { return reloc_iterator_original_->rinfo()->rmode(); } bool IsDebuggerStatement(); protected: bool RinfoDone() const; void RinfoNext(); BreakLocatorType type_; int break_point_; int position_; int statement_position_; Handle debug_info_; RelocIterator* reloc_iterator_; RelocIterator* reloc_iterator_original_; private: void SetDebugBreak(); void ClearDebugBreak(); void SetDebugBreakAtIC(); void ClearDebugBreakAtIC(); bool IsDebugBreakAtReturn(); void SetDebugBreakAtReturn(); void ClearDebugBreakAtReturn(); bool IsDebugBreakSlot(); bool IsDebugBreakAtSlot(); void SetDebugBreakAtSlot(); void ClearDebugBreakAtSlot(); DISALLOW_COPY_AND_ASSIGN(BreakLocationIterator); }; // 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: explicit ScriptCache(Isolate* isolate); virtual ~ScriptCache() { Clear(); } // Add script to the cache. void Add(Handle