// Copyright 2011 the V8 project authors. All rights reserved. // 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. #ifndef V8_DEBUG_H_ #define V8_DEBUG_H_ #include "allocation.h" #include "arguments.h" #include "assembler.h" #include "debug-agent.h" #include "execution.h" #include "factory.h" #include "flags.h" #include "frames-inl.h" #include "hashmap.h" #include "platform.h" #include "string-stream.h" #include "v8threads.h" #ifdef ENABLE_DEBUGGER_SUPPORT #include "../include/v8-debug.h" namespace v8 { namespace internal { // Forward declarations. class EnterDebugger; // 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 }; // 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); void Reset(); bool Done() const; void SetBreakPoint(Handle break_point_object); void ClearBreakPoint(Handle break_point_object); void SetOneShot(); void ClearOneShot(); void PrepareStepIn(); 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: ScriptCache() : HashMap(ScriptMatch), collected_scripts_(10) {} virtual ~ScriptCache() { Clear(); } // Add script to the cache. void Add(Handle