blob: 52e8a98f9f198356e1ee3c1e331d387fa753dae0 [file] [log] [blame]
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001// Copyright 2006-2008 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
ager@chromium.org9258b6b2008-09-11 09:11:10 +000028#ifndef V8_V8_DEBUG_H_
29#define V8_V8_DEBUG_H_
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000030
ager@chromium.orgc27e4e72008-09-04 13:52:27 +000031#include "../include/v8-debug.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000032#include "assembler.h"
33#include "code-stubs.h"
34#include "factory.h"
35#include "platform.h"
36#include "string-stream.h"
37
38
39namespace v8 { namespace internal {
40
41// Step actions. NOTE: These values are in macros.py as well.
42enum StepAction {
43 StepNone = -1, // Stepping not prepared.
44 StepOut = 0, // Step out of the current function.
45 StepNext = 1, // Step to the next statement in the current function.
46 StepIn = 2, // Step into new functions invoked or the next statement
47 // in the current function.
48 StepMin = 3, // Perform a minimum step in the current function.
49 StepInMin = 4 // Step into new functions invoked or perform a minimum step
50 // in the current function.
51};
52
53
54// Type of exception break. NOTE: These values are in macros.py as well.
55enum ExceptionBreakType {
56 BreakException = 0,
57 BreakUncaughtException = 1
58};
59
60
61// Type of exception break. NOTE: These values are in macros.py as well.
62enum BreakLocatorType {
63 ALL_BREAK_LOCATIONS = 0,
64 SOURCE_BREAK_LOCATIONS = 1
65};
66
67
68// Class for iterating through the break points in a function and changing
69// them.
70class BreakLocationIterator {
71 public:
72 explicit BreakLocationIterator(Handle<DebugInfo> debug_info,
73 BreakLocatorType type);
74 virtual ~BreakLocationIterator();
75
76 void Next();
77 void Next(int count);
78 void FindBreakLocationFromAddress(Address pc);
79 void FindBreakLocationFromPosition(int position);
80 void Reset();
81 bool Done() const;
82 void SetBreakPoint(Handle<Object> break_point_object);
83 void ClearBreakPoint(Handle<Object> break_point_object);
84 void SetOneShot();
85 void ClearOneShot();
86 void PrepareStepIn();
87 bool IsExit() const;
88 bool HasBreakPoint();
89 bool IsDebugBreak();
90 Object* BreakPointObjects();
91
92
93 inline int code_position() { return pc() - debug_info_->code()->entry(); }
94 inline int break_point() { return break_point_; }
95 inline int position() { return position_; }
96 inline int statement_position() { return statement_position_; }
97 inline Address pc() { return reloc_iterator_->rinfo()->pc(); }
98 inline Code* code() { return debug_info_->code(); }
99 inline RelocInfo* rinfo() { return reloc_iterator_->rinfo(); }
ager@chromium.org236ad962008-09-25 09:45:57 +0000100 inline RelocInfo::Mode rmode() const {
101 return reloc_iterator_->rinfo()->rmode();
102 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000103 inline RelocInfo* original_rinfo() {
104 return reloc_iterator_original_->rinfo();
105 }
ager@chromium.org236ad962008-09-25 09:45:57 +0000106 inline RelocInfo::Mode original_rmode() const {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000107 return reloc_iterator_original_->rinfo()->rmode();
108 }
109
110 protected:
111 bool RinfoDone() const;
112 void RinfoNext();
113
114 BreakLocatorType type_;
115 int break_point_;
116 int position_;
117 int statement_position_;
118 Handle<DebugInfo> debug_info_;
119 RelocIterator* reloc_iterator_;
120 RelocIterator* reloc_iterator_original_;
121
122 private:
123 void SetDebugBreak();
124 void ClearDebugBreak();
125
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000126 DISALLOW_COPY_AND_ASSIGN(BreakLocationIterator);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000127};
128
129
130// Linked list holding debug info objects. The debug info objects are kept as
131// weak handles to avoid a debug info object to keep a function alive.
132class DebugInfoListNode {
133 public:
134 explicit DebugInfoListNode(DebugInfo* debug_info);
135 virtual ~DebugInfoListNode();
136
137 DebugInfoListNode* next() { return next_; }
138 void set_next(DebugInfoListNode* next) { next_ = next; }
139 Handle<DebugInfo> debug_info() { return debug_info_; }
140
141 private:
142 // Global (weak) handle to the debug info object.
143 Handle<DebugInfo> debug_info_;
144
145 // Next pointer for linked list.
146 DebugInfoListNode* next_;
147};
148
149
150// This class contains the debugger support. The main purpose is to handle
151// setting break points in the code.
152//
153// This class controls the debug info for all functions which currently have
154// active breakpoints in them. This debug info is held in the heap root object
155// debug_info which is a FixedArray. Each entry in this list is of class
156// DebugInfo.
157class Debug {
158 public:
159 static void Setup(bool create_heap_objects);
160 static bool Load();
161 static void Unload();
162 static bool IsLoaded() { return !debug_context_.is_null(); }
163 static bool InDebugger() { return Top::is_break(); }
164 static void Iterate(ObjectVisitor* v);
165
166 static Object* Break(Arguments args);
167 static void SetBreakPoint(Handle<SharedFunctionInfo> shared,
168 int source_position,
169 Handle<Object> break_point_object);
170 static void ClearBreakPoint(Handle<Object> break_point_object);
171 static void FloodWithOneShot(Handle<SharedFunctionInfo> shared);
172 static void FloodHandlerWithOneShot();
173 static void ChangeBreakOnException(ExceptionBreakType type, bool enable);
174 static void PrepareStep(StepAction step_action, int step_count);
175 static void ClearStepping();
176 static bool StepNextContinue(BreakLocationIterator* break_location_iterator,
177 JavaScriptFrame* frame);
178 static Handle<DebugInfo> GetDebugInfo(Handle<SharedFunctionInfo> shared);
179 static bool HasDebugInfo(Handle<SharedFunctionInfo> shared);
kasper.lundbd3ec4e2008-07-09 11:06:54 +0000180
181 // Returns whether the operation succedded.
182 static bool EnsureDebugInfo(Handle<SharedFunctionInfo> shared);
183
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000184 static bool IsDebugBreak(Address addr);
185
186 // Check whether a code stub with the specified major key is a possible break
187 // point location.
188 static bool IsSourceBreakStub(Code* code);
189 static bool IsBreakStub(Code* code);
190
191 // Find the builtin to use for invoking the debug break
192 static Handle<Code> FindDebugBreak(RelocInfo* rinfo);
193
194 static Handle<Object> GetSourceBreakLocations(
195 Handle<SharedFunctionInfo> shared);
196 static Code* GetCodeTarget(Address target);
197
198 // Getter for the debug_context.
199 inline static Handle<Context> debug_context() { return debug_context_; }
200
201 // Check whether a global object is the debug global object.
202 static bool IsDebugGlobal(GlobalObject* global);
203
204 // Fast check to see if any break points are active.
205 inline static bool has_break_points() { return has_break_points_; }
206
207 static bool StepInActive() { return thread_local_.step_into_fp_ != 0; }
208 static Address step_in_fp() { return thread_local_.step_into_fp_; }
209 static Address* step_in_fp_addr() { return &thread_local_.step_into_fp_; }
210
kasper.lundbd3ec4e2008-07-09 11:06:54 +0000211 // Getter and setter for the disable break state.
212 static bool disable_break() { return disable_break_; }
213 static void set_disable_break(bool disable_break) {
214 disable_break_ = disable_break;
215 }
216
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000217 // Getters for the current exception break state.
218 static bool break_on_exception() { return break_on_exception_; }
219 static bool break_on_uncaught_exception() {
220 return break_on_uncaught_exception_;
221 }
222
223 enum AddressId {
224 k_after_break_target_address,
225 k_debug_break_return_address,
226 k_register_address
227 };
228
229 // Support for setting the address to jump to when returning from break point.
230 static Address* after_break_target_address() {
231 return reinterpret_cast<Address*>(&thread_local_.after_break_target_);
232 }
233
234 // Support for saving/restoring registers when handling debug break calls.
235 static Address* register_address(int r) {
236 return reinterpret_cast<Address *>(&registers_[r]);
237 }
238
kasper.lund7276f142008-07-30 08:49:36 +0000239 // Address of the debug break return entry code.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000240 static Code* debug_break_return_entry() { return debug_break_return_entry_; }
241
242 // Support for getting the address of the debug break on return code.
243 static Address* debug_break_return_address() {
244 return reinterpret_cast<Address*>(&debug_break_return_);
245 }
246
247 static const int kEstimatedNofDebugInfoEntries = 16;
248 static const int kEstimatedNofBreakPointsInFunction = 16;
249
250 static void HandleWeakDebugInfo(v8::Persistent<v8::Object> obj, void* data);
251
252 friend class Debugger;
253 friend Handle<FixedArray> GetDebuggedFunctions(); // Found in test-debug.cc
254
255 // Threading support.
256 static char* ArchiveDebug(char* to);
257 static char* RestoreDebug(char* from);
258 static int ArchiveSpacePerThread();
259
260 // Code generation assumptions.
261 static const int kIa32CallInstructionLength = 5;
262 static const int kIa32JSReturnSequenceLength = 6;
263
264 private:
265 static bool CompileDebuggerScript(int index);
266 static void ClearOneShot();
267 static void ActivateStepIn(StackFrame* frame);
268 static void ClearStepIn();
269 static void ClearStepNext();
kasper.lundbd3ec4e2008-07-09 11:06:54 +0000270 // Returns whether the compile succedded.
271 static bool EnsureCompiled(Handle<SharedFunctionInfo> shared);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000272 static void RemoveDebugInfo(Handle<DebugInfo> debug_info);
273 static void SetAfterBreakTarget(JavaScriptFrame* frame);
274 static Handle<Object> CheckBreakPoints(Handle<Object> break_point);
275 static bool CheckBreakPoint(Handle<Object> break_point_object);
276
277 // Global handle to debug context where all the debugger JavaScript code is
278 // loaded.
279 static Handle<Context> debug_context_;
280
281 // Boolean state indicating whether any break points are set.
282 static bool has_break_points_;
283 static DebugInfoListNode* debug_info_list_;
284
kasper.lundbd3ec4e2008-07-09 11:06:54 +0000285 static bool disable_break_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000286 static bool break_on_exception_;
287 static bool break_on_uncaught_exception_;
288
289 // Per-thread:
290 class ThreadLocal {
291 public:
292 // Step action for last step performed.
293 StepAction last_step_action_;
294
295 // Source statement position from last step next action.
296 int last_statement_position_;
297
298 // Number of steps left to perform before debug event.
299 int step_count_;
300
301 // Frame pointer from last step next action.
302 Address last_fp_;
303
304 // Frame pointer for frame from which step in was performed.
305 Address step_into_fp_;
306
307 // Storage location for jump when exiting debug break calls.
308 Address after_break_target_;
309 };
310
311 // Storage location for registers when handling debug break calls
312 static JSCallerSavedBuffer registers_;
313 static ThreadLocal thread_local_;
314 static void ThreadInit();
315
316 // Code object for debug break return entry code.
317 static Code* debug_break_return_entry_;
318
319 // Code to call for handling debug break on return.
320 static Code* debug_break_return_;
321
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000322 DISALLOW_COPY_AND_ASSIGN(Debug);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000323};
324
325
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000326class DebugMessageThread;
327
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000328class Debugger {
329 public:
330 static void DebugRequest(const uint16_t* json_request, int length);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000331
332 static Handle<Object> MakeJSObject(Vector<const char> constructor_name,
333 int argc, Object*** argv,
334 bool* caught_exception);
335 static Handle<Object> MakeExecutionState(bool* caught_exception);
336 static Handle<Object> MakeBreakEvent(Handle<Object> exec_state,
337 Handle<Object> break_points_hit,
338 bool* caught_exception);
339 static Handle<Object> MakeExceptionEvent(Handle<Object> exec_state,
340 Handle<Object> exception,
341 bool uncaught,
342 bool* caught_exception);
343 static Handle<Object> MakeNewFunctionEvent(Handle<Object> func,
344 bool* caught_exception);
345 static Handle<Object> MakeCompileEvent(Handle<Script> script,
346 Handle<Object> script_function,
347 bool* caught_exception);
348 static Handle<String> ProcessRequest(Handle<Object> exec_state,
349 Handle<Object> request,
350 bool stopped);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000351 static void OnDebugBreak(Handle<Object> break_points_hit);
352 static void OnException(Handle<Object> exception, bool uncaught);
353 static void OnBeforeCompile(Handle<Script> script);
354 static void OnAfterCompile(Handle<Script> script,
355 Handle<JSFunction> fun);
356 static void OnNewFunction(Handle<JSFunction> fun);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000357 static void ProcessDebugEvent(v8::DebugEvent event,
358 Handle<Object> event_data);
359 static void SetMessageHandler(v8::DebugMessageHandler handler, void* data);
360 static void SendMessage(Vector<uint16_t> message);
361 static void ProcessCommand(Vector<const uint16_t> command);
362 static void UpdateActiveDebugger();
363 inline static bool EventActive(v8::DebugEvent event) {
364 // Currently argument event is not used.
365 return !Debugger::compiling_natives_ && Debugger::debugger_active_;
366 }
367
368 static void set_debugger_active(bool debugger_active) {
369 Debugger::debugger_active_ = debugger_active;
370 }
371 static bool debugger_active() { return Debugger::debugger_active_; }
372 static void set_compiling_natives(bool compiling_natives) {
373 Debugger::compiling_natives_ = compiling_natives;
374 }
375 static bool compiling_natives() { return Debugger::compiling_natives_; }
mads.s.agercbaa0602008-08-14 13:41:48 +0000376 static void set_loading_debugger(bool v) { is_loading_debugger_ = v; }
377 static bool is_loading_debugger() { return Debugger::is_loading_debugger_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000378
379 private:
380 static bool debugger_active_; // Are there any active debugger?
381 static bool compiling_natives_; // Are we compiling natives?
mads.s.agercbaa0602008-08-14 13:41:48 +0000382 static bool is_loading_debugger_; // Are we loading the debugger?
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000383 static DebugMessageThread* message_thread_;
384 static v8::DebugMessageHandler debug_message_handler_;
385 static void* debug_message_handler_data_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000386};
387
388
kasper.lund7276f142008-07-30 08:49:36 +0000389// A Queue of Vector<uint16_t> objects. A thread-safe version is
390// LockingMessageQueue, based on this class.
391class MessageQueue BASE_EMBEDDED {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000392 public:
kasper.lund7276f142008-07-30 08:49:36 +0000393 explicit MessageQueue(int size);
394 ~MessageQueue();
395 bool IsEmpty() const { return start_ == end_; }
396 Vector<uint16_t> Get();
397 void Put(const Vector<uint16_t>& message);
398 void Clear() { start_ = end_ = 0; } // Queue is empty after Clear().
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000399 private:
kasper.lund7276f142008-07-30 08:49:36 +0000400 // Doubles the size of the message queue, and copies the messages.
401 void Expand();
402
403 Vector<uint16_t>* messages_;
404 int start_;
405 int end_;
406 int size_; // The size of the queue buffer. Queue can hold size-1 messages.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000407};
408
409
kasper.lund7276f142008-07-30 08:49:36 +0000410// LockingMessageQueue is a thread-safe circular buffer of Vector<uint16_t>
411// messages. The message data is not managed by LockingMessageQueue.
412// Pointers to the data are passed in and out. Implemented by adding a
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +0000413// Mutex to MessageQueue. Includes logging of all puts and gets.
kasper.lund7276f142008-07-30 08:49:36 +0000414class LockingMessageQueue BASE_EMBEDDED {
415 public:
416 explicit LockingMessageQueue(int size);
417 ~LockingMessageQueue();
418 bool IsEmpty() const;
419 Vector<uint16_t> Get();
420 void Put(const Vector<uint16_t>& message);
421 void Clear();
422 private:
kasper.lund7276f142008-07-30 08:49:36 +0000423 MessageQueue queue_;
424 Mutex* lock_;
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000425 DISALLOW_COPY_AND_ASSIGN(LockingMessageQueue);
kasper.lund7276f142008-07-30 08:49:36 +0000426};
427
428
429/* This class is the data for a running thread that serializes
430 * event messages and command processing for the debugger.
431 * All uncommented methods are called only from this message thread.
432 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000433class DebugMessageThread: public Thread {
434 public:
kasper.lund7276f142008-07-30 08:49:36 +0000435 DebugMessageThread(); // Called from API thread.
436 virtual ~DebugMessageThread(); // Never called.
437 // Called by V8 thread. Reports events from V8 VM.
438 // Also handles command processing in stopped state of V8,
439 // when host_running_ is false.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000440 void DebugEvent(v8::DebugEvent,
441 Handle<Object> exec_state,
442 Handle<Object> event_data);
kasper.lund7276f142008-07-30 08:49:36 +0000443 // Puts event on the output queue. Called by V8.
444 // This is where V8 hands off
445 // processing of the event to the DebugMessageThread thread,
446 // which forwards it to the debug_message_handler set by the API.
447 void SendMessage(Vector<uint16_t> event_json);
448 // Formats an event into JSON, and calls SendMessage.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000449 void SetEventJSONFromEvent(Handle<Object> event_data);
kasper.lund7276f142008-07-30 08:49:36 +0000450 // Puts a command coming from the public API on the queue. Called
451 // by the API client thread. This is where the API client hands off
452 // processing of the command to the DebugMessageThread thread.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000453 void ProcessCommand(Vector<uint16_t> command);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000454 void OnDebuggerInactive();
455
kasper.lund7276f142008-07-30 08:49:36 +0000456 // Main function of DebugMessageThread thread.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000457 void Run();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000458
kasper.lund7276f142008-07-30 08:49:36 +0000459 bool host_running_; // Is the debugging host running or stopped?
460 Semaphore* command_received_; // Non-zero when command queue is non-empty.
461 Semaphore* message_received_; // Exactly equal to message queue length.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000462 private:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000463 bool TwoByteEqualsAscii(Vector<uint16_t> two_byte, const char* ascii);
464
kasper.lund7276f142008-07-30 08:49:36 +0000465 static const int kQueueInitialSize = 4;
466 LockingMessageQueue command_queue_;
467 LockingMessageQueue message_queue_;
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000468 DISALLOW_COPY_AND_ASSIGN(DebugMessageThread);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000469};
470
471
472// Helper class to support saving/restoring the top break frame id.
473class SaveBreakFrame {
474 public:
475 SaveBreakFrame() : set_(!it_.done()) {
476 if (set_) {
477 // Store the previous break is and frame id.
478 break_id_ = Top::break_id();
479 break_frame_id_ = Top::break_frame_id();
480
481 // Create the new break info.
482 Top::new_break(it_.frame()->id());
483 }
484 }
485
486 ~SaveBreakFrame() {
487 if (set_) {
488 // restore to the previous break state.
489 Top::set_break(break_frame_id_, break_id_);
490 }
491 }
492
493 private:
494 JavaScriptFrameIterator it_;
495 const bool set_; // Was the break actually set?
496 StackFrame::Id break_frame_id_; // Previous break frame id.
497 int break_id_; // Previous break id.
498};
499
500
501class EnterDebuggerContext BASE_EMBEDDED {
502 public:
503 // Enter the debugger by storing the previous top context and setting the
504 // current top context to the debugger context.
505 EnterDebuggerContext() {
506 // NOTE the member variable save which saves the previous context before
507 // this change.
508 Top::set_context(*Debug::debug_context());
509 Top::set_security_context(*Debug::debug_context());
510 }
511
512 private:
513 SaveContext save;
514};
515
516
kasper.lundbd3ec4e2008-07-09 11:06:54 +0000517// Stack allocated class for disabling break.
518class DisableBreak BASE_EMBEDDED {
519 public:
520 // Enter the debugger by storing the previous top context and setting the
521 // current top context to the debugger context.
522 explicit DisableBreak(bool disable_break) {
523 prev_disable_break_ = Debug::disable_break();
524 Debug::set_disable_break(disable_break);
525 }
526 ~DisableBreak() {
527 Debug::set_disable_break(prev_disable_break_);
528 }
529
530 private:
531 // The previous state of the disable break used to restore the value when this
532 // object is destructed.
533 bool prev_disable_break_;
534};
535
536
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000537// Debug_Address encapsulates the Address pointers used in generating debug
538// code.
539class Debug_Address {
540 public:
541 Debug_Address(Debug::AddressId id, int reg = 0)
542 : id_(id), reg_(reg) {
543 ASSERT(reg == 0 || id == Debug::k_register_address);
544 }
545
546 static Debug_Address AfterBreakTarget() {
547 return Debug_Address(Debug::k_after_break_target_address);
548 }
549
550 static Debug_Address DebugBreakReturn() {
551 return Debug_Address(Debug::k_debug_break_return_address);
552 }
553
554 static Debug_Address Register(int reg) {
555 return Debug_Address(Debug::k_register_address, reg);
556 }
557
558 Address address() const {
559 switch (id_) {
560 case Debug::k_after_break_target_address:
561 return reinterpret_cast<Address>(Debug::after_break_target_address());
562 case Debug::k_debug_break_return_address:
563 return reinterpret_cast<Address>(Debug::debug_break_return_address());
564 case Debug::k_register_address:
565 return reinterpret_cast<Address>(Debug::register_address(reg_));
566 default:
567 UNREACHABLE();
568 return NULL;
569 }
570 }
571 private:
572 Debug::AddressId id_;
573 int reg_;
574};
575
576
577} } // namespace v8::internal
578
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000579#endif // V8_V8_DEBUG_H_