blob: 951acd5bf06b148142271c7194958144148362e2 [file] [log] [blame]
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001// Copyright 2006-2008 Google Inc. All Rights Reserved.
2// 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
28#ifndef V8_DEBUG_H_
29#define V8_DEBUG_H_
30
31#include "../public/debug.h"
32#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(); }
100 inline RelocMode rmode() const { return reloc_iterator_->rinfo()->rmode(); }
101 inline RelocInfo* original_rinfo() {
102 return reloc_iterator_original_->rinfo();
103 }
104 inline RelocMode original_rmode() const {
105 return reloc_iterator_original_->rinfo()->rmode();
106 }
107
108 protected:
109 bool RinfoDone() const;
110 void RinfoNext();
111
112 BreakLocatorType type_;
113 int break_point_;
114 int position_;
115 int statement_position_;
116 Handle<DebugInfo> debug_info_;
117 RelocIterator* reloc_iterator_;
118 RelocIterator* reloc_iterator_original_;
119
120 private:
121 void SetDebugBreak();
122 void ClearDebugBreak();
123
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000124 DISALLOW_COPY_AND_ASSIGN(BreakLocationIterator);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000125};
126
127
128// Linked list holding debug info objects. The debug info objects are kept as
129// weak handles to avoid a debug info object to keep a function alive.
130class DebugInfoListNode {
131 public:
132 explicit DebugInfoListNode(DebugInfo* debug_info);
133 virtual ~DebugInfoListNode();
134
135 DebugInfoListNode* next() { return next_; }
136 void set_next(DebugInfoListNode* next) { next_ = next; }
137 Handle<DebugInfo> debug_info() { return debug_info_; }
138
139 private:
140 // Global (weak) handle to the debug info object.
141 Handle<DebugInfo> debug_info_;
142
143 // Next pointer for linked list.
144 DebugInfoListNode* next_;
145};
146
147
148// This class contains the debugger support. The main purpose is to handle
149// setting break points in the code.
150//
151// This class controls the debug info for all functions which currently have
152// active breakpoints in them. This debug info is held in the heap root object
153// debug_info which is a FixedArray. Each entry in this list is of class
154// DebugInfo.
155class Debug {
156 public:
157 static void Setup(bool create_heap_objects);
158 static bool Load();
159 static void Unload();
160 static bool IsLoaded() { return !debug_context_.is_null(); }
161 static bool InDebugger() { return Top::is_break(); }
162 static void Iterate(ObjectVisitor* v);
163
164 static Object* Break(Arguments args);
165 static void SetBreakPoint(Handle<SharedFunctionInfo> shared,
166 int source_position,
167 Handle<Object> break_point_object);
168 static void ClearBreakPoint(Handle<Object> break_point_object);
169 static void FloodWithOneShot(Handle<SharedFunctionInfo> shared);
170 static void FloodHandlerWithOneShot();
171 static void ChangeBreakOnException(ExceptionBreakType type, bool enable);
172 static void PrepareStep(StepAction step_action, int step_count);
173 static void ClearStepping();
174 static bool StepNextContinue(BreakLocationIterator* break_location_iterator,
175 JavaScriptFrame* frame);
176 static Handle<DebugInfo> GetDebugInfo(Handle<SharedFunctionInfo> shared);
177 static bool HasDebugInfo(Handle<SharedFunctionInfo> shared);
kasper.lundbd3ec4e2008-07-09 11:06:54 +0000178
179 // Returns whether the operation succedded.
180 static bool EnsureDebugInfo(Handle<SharedFunctionInfo> shared);
181
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000182 static bool IsDebugBreak(Address addr);
183
184 // Check whether a code stub with the specified major key is a possible break
185 // point location.
186 static bool IsSourceBreakStub(Code* code);
187 static bool IsBreakStub(Code* code);
188
189 // Find the builtin to use for invoking the debug break
190 static Handle<Code> FindDebugBreak(RelocInfo* rinfo);
191
192 static Handle<Object> GetSourceBreakLocations(
193 Handle<SharedFunctionInfo> shared);
194 static Code* GetCodeTarget(Address target);
195
196 // Getter for the debug_context.
197 inline static Handle<Context> debug_context() { return debug_context_; }
198
199 // Check whether a global object is the debug global object.
200 static bool IsDebugGlobal(GlobalObject* global);
201
202 // Fast check to see if any break points are active.
203 inline static bool has_break_points() { return has_break_points_; }
204
205 static bool StepInActive() { return thread_local_.step_into_fp_ != 0; }
206 static Address step_in_fp() { return thread_local_.step_into_fp_; }
207 static Address* step_in_fp_addr() { return &thread_local_.step_into_fp_; }
208
kasper.lundbd3ec4e2008-07-09 11:06:54 +0000209 // Getter and setter for the disable break state.
210 static bool disable_break() { return disable_break_; }
211 static void set_disable_break(bool disable_break) {
212 disable_break_ = disable_break;
213 }
214
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000215 // Getters for the current exception break state.
216 static bool break_on_exception() { return break_on_exception_; }
217 static bool break_on_uncaught_exception() {
218 return break_on_uncaught_exception_;
219 }
220
221 enum AddressId {
222 k_after_break_target_address,
223 k_debug_break_return_address,
224 k_register_address
225 };
226
227 // Support for setting the address to jump to when returning from break point.
228 static Address* after_break_target_address() {
229 return reinterpret_cast<Address*>(&thread_local_.after_break_target_);
230 }
231
232 // Support for saving/restoring registers when handling debug break calls.
233 static Address* register_address(int r) {
234 return reinterpret_cast<Address *>(&registers_[r]);
235 }
236
kasper.lund7276f142008-07-30 08:49:36 +0000237 // Address of the debug break return entry code.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000238 static Code* debug_break_return_entry() { return debug_break_return_entry_; }
239
240 // Support for getting the address of the debug break on return code.
241 static Address* debug_break_return_address() {
242 return reinterpret_cast<Address*>(&debug_break_return_);
243 }
244
245 static const int kEstimatedNofDebugInfoEntries = 16;
246 static const int kEstimatedNofBreakPointsInFunction = 16;
247
248 static void HandleWeakDebugInfo(v8::Persistent<v8::Object> obj, void* data);
249
250 friend class Debugger;
251 friend Handle<FixedArray> GetDebuggedFunctions(); // Found in test-debug.cc
252
253 // Threading support.
254 static char* ArchiveDebug(char* to);
255 static char* RestoreDebug(char* from);
256 static int ArchiveSpacePerThread();
257
258 // Code generation assumptions.
259 static const int kIa32CallInstructionLength = 5;
260 static const int kIa32JSReturnSequenceLength = 6;
261
262 private:
263 static bool CompileDebuggerScript(int index);
264 static void ClearOneShot();
265 static void ActivateStepIn(StackFrame* frame);
266 static void ClearStepIn();
267 static void ClearStepNext();
kasper.lundbd3ec4e2008-07-09 11:06:54 +0000268 // Returns whether the compile succedded.
269 static bool EnsureCompiled(Handle<SharedFunctionInfo> shared);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000270 static void RemoveDebugInfo(Handle<DebugInfo> debug_info);
271 static void SetAfterBreakTarget(JavaScriptFrame* frame);
272 static Handle<Object> CheckBreakPoints(Handle<Object> break_point);
273 static bool CheckBreakPoint(Handle<Object> break_point_object);
274
275 // Global handle to debug context where all the debugger JavaScript code is
276 // loaded.
277 static Handle<Context> debug_context_;
278
279 // Boolean state indicating whether any break points are set.
280 static bool has_break_points_;
281 static DebugInfoListNode* debug_info_list_;
282
kasper.lundbd3ec4e2008-07-09 11:06:54 +0000283 static bool disable_break_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000284 static bool break_on_exception_;
285 static bool break_on_uncaught_exception_;
286
287 // Per-thread:
288 class ThreadLocal {
289 public:
290 // Step action for last step performed.
291 StepAction last_step_action_;
292
293 // Source statement position from last step next action.
294 int last_statement_position_;
295
296 // Number of steps left to perform before debug event.
297 int step_count_;
298
299 // Frame pointer from last step next action.
300 Address last_fp_;
301
302 // Frame pointer for frame from which step in was performed.
303 Address step_into_fp_;
304
305 // Storage location for jump when exiting debug break calls.
306 Address after_break_target_;
307 };
308
309 // Storage location for registers when handling debug break calls
310 static JSCallerSavedBuffer registers_;
311 static ThreadLocal thread_local_;
312 static void ThreadInit();
313
314 // Code object for debug break return entry code.
315 static Code* debug_break_return_entry_;
316
317 // Code to call for handling debug break on return.
318 static Code* debug_break_return_;
319
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000320 DISALLOW_COPY_AND_ASSIGN(Debug);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000321};
322
323
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000324class DebugMessageThread;
325
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000326class Debugger {
327 public:
328 static void DebugRequest(const uint16_t* json_request, int length);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000329
330 static Handle<Object> MakeJSObject(Vector<const char> constructor_name,
331 int argc, Object*** argv,
332 bool* caught_exception);
333 static Handle<Object> MakeExecutionState(bool* caught_exception);
334 static Handle<Object> MakeBreakEvent(Handle<Object> exec_state,
335 Handle<Object> break_points_hit,
336 bool* caught_exception);
337 static Handle<Object> MakeExceptionEvent(Handle<Object> exec_state,
338 Handle<Object> exception,
339 bool uncaught,
340 bool* caught_exception);
341 static Handle<Object> MakeNewFunctionEvent(Handle<Object> func,
342 bool* caught_exception);
343 static Handle<Object> MakeCompileEvent(Handle<Script> script,
344 Handle<Object> script_function,
345 bool* caught_exception);
346 static Handle<String> ProcessRequest(Handle<Object> exec_state,
347 Handle<Object> request,
348 bool stopped);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000349 static void OnDebugBreak(Handle<Object> break_points_hit);
350 static void OnException(Handle<Object> exception, bool uncaught);
351 static void OnBeforeCompile(Handle<Script> script);
352 static void OnAfterCompile(Handle<Script> script,
353 Handle<JSFunction> fun);
354 static void OnNewFunction(Handle<JSFunction> fun);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000355 static void ProcessDebugEvent(v8::DebugEvent event,
356 Handle<Object> event_data);
357 static void SetMessageHandler(v8::DebugMessageHandler handler, void* data);
358 static void SendMessage(Vector<uint16_t> message);
359 static void ProcessCommand(Vector<const uint16_t> command);
360 static void UpdateActiveDebugger();
361 inline static bool EventActive(v8::DebugEvent event) {
362 // Currently argument event is not used.
363 return !Debugger::compiling_natives_ && Debugger::debugger_active_;
364 }
365
366 static void set_debugger_active(bool debugger_active) {
367 Debugger::debugger_active_ = debugger_active;
368 }
369 static bool debugger_active() { return Debugger::debugger_active_; }
370 static void set_compiling_natives(bool compiling_natives) {
371 Debugger::compiling_natives_ = compiling_natives;
372 }
373 static bool compiling_natives() { return Debugger::compiling_natives_; }
mads.s.agercbaa0602008-08-14 13:41:48 +0000374 static void set_loading_debugger(bool v) { is_loading_debugger_ = v; }
375 static bool is_loading_debugger() { return Debugger::is_loading_debugger_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000376
377 private:
378 static bool debugger_active_; // Are there any active debugger?
379 static bool compiling_natives_; // Are we compiling natives?
mads.s.agercbaa0602008-08-14 13:41:48 +0000380 static bool is_loading_debugger_; // Are we loading the debugger?
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000381 static DebugMessageThread* message_thread_;
382 static v8::DebugMessageHandler debug_message_handler_;
383 static void* debug_message_handler_data_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000384};
385
386
kasper.lund7276f142008-07-30 08:49:36 +0000387// A Queue of Vector<uint16_t> objects. A thread-safe version is
388// LockingMessageQueue, based on this class.
389class MessageQueue BASE_EMBEDDED {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000390 public:
kasper.lund7276f142008-07-30 08:49:36 +0000391 explicit MessageQueue(int size);
392 ~MessageQueue();
393 bool IsEmpty() const { return start_ == end_; }
394 Vector<uint16_t> Get();
395 void Put(const Vector<uint16_t>& message);
396 void Clear() { start_ = end_ = 0; } // Queue is empty after Clear().
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000397 private:
kasper.lund7276f142008-07-30 08:49:36 +0000398 // Doubles the size of the message queue, and copies the messages.
399 void Expand();
400
401 Vector<uint16_t>* messages_;
402 int start_;
403 int end_;
404 int size_; // The size of the queue buffer. Queue can hold size-1 messages.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000405};
406
407
kasper.lund7276f142008-07-30 08:49:36 +0000408// LockingMessageQueue is a thread-safe circular buffer of Vector<uint16_t>
409// messages. The message data is not managed by LockingMessageQueue.
410// Pointers to the data are passed in and out. Implemented by adding a
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +0000411// Mutex to MessageQueue. Includes logging of all puts and gets.
kasper.lund7276f142008-07-30 08:49:36 +0000412class LockingMessageQueue BASE_EMBEDDED {
413 public:
414 explicit LockingMessageQueue(int size);
415 ~LockingMessageQueue();
416 bool IsEmpty() const;
417 Vector<uint16_t> Get();
418 void Put(const Vector<uint16_t>& message);
419 void Clear();
420 private:
kasper.lund7276f142008-07-30 08:49:36 +0000421 MessageQueue queue_;
422 Mutex* lock_;
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000423 DISALLOW_COPY_AND_ASSIGN(LockingMessageQueue);
kasper.lund7276f142008-07-30 08:49:36 +0000424};
425
426
427/* This class is the data for a running thread that serializes
428 * event messages and command processing for the debugger.
429 * All uncommented methods are called only from this message thread.
430 */
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000431class DebugMessageThread: public Thread {
432 public:
kasper.lund7276f142008-07-30 08:49:36 +0000433 DebugMessageThread(); // Called from API thread.
434 virtual ~DebugMessageThread(); // Never called.
435 // Called by V8 thread. Reports events from V8 VM.
436 // Also handles command processing in stopped state of V8,
437 // when host_running_ is false.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000438 void DebugEvent(v8::DebugEvent,
439 Handle<Object> exec_state,
440 Handle<Object> event_data);
kasper.lund7276f142008-07-30 08:49:36 +0000441 // Puts event on the output queue. Called by V8.
442 // This is where V8 hands off
443 // processing of the event to the DebugMessageThread thread,
444 // which forwards it to the debug_message_handler set by the API.
445 void SendMessage(Vector<uint16_t> event_json);
446 // Formats an event into JSON, and calls SendMessage.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000447 void SetEventJSONFromEvent(Handle<Object> event_data);
kasper.lund7276f142008-07-30 08:49:36 +0000448 // Puts a command coming from the public API on the queue. Called
449 // by the API client thread. This is where the API client hands off
450 // processing of the command to the DebugMessageThread thread.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000451 void ProcessCommand(Vector<uint16_t> command);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000452 void OnDebuggerInactive();
453
kasper.lund7276f142008-07-30 08:49:36 +0000454 // Main function of DebugMessageThread thread.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000455 void Run();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000456
kasper.lund7276f142008-07-30 08:49:36 +0000457 bool host_running_; // Is the debugging host running or stopped?
458 Semaphore* command_received_; // Non-zero when command queue is non-empty.
459 Semaphore* message_received_; // Exactly equal to message queue length.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000460 private:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000461 bool TwoByteEqualsAscii(Vector<uint16_t> two_byte, const char* ascii);
462
kasper.lund7276f142008-07-30 08:49:36 +0000463 static const int kQueueInitialSize = 4;
464 LockingMessageQueue command_queue_;
465 LockingMessageQueue message_queue_;
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000466 DISALLOW_COPY_AND_ASSIGN(DebugMessageThread);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000467};
468
469
470// Helper class to support saving/restoring the top break frame id.
471class SaveBreakFrame {
472 public:
473 SaveBreakFrame() : set_(!it_.done()) {
474 if (set_) {
475 // Store the previous break is and frame id.
476 break_id_ = Top::break_id();
477 break_frame_id_ = Top::break_frame_id();
478
479 // Create the new break info.
480 Top::new_break(it_.frame()->id());
481 }
482 }
483
484 ~SaveBreakFrame() {
485 if (set_) {
486 // restore to the previous break state.
487 Top::set_break(break_frame_id_, break_id_);
488 }
489 }
490
491 private:
492 JavaScriptFrameIterator it_;
493 const bool set_; // Was the break actually set?
494 StackFrame::Id break_frame_id_; // Previous break frame id.
495 int break_id_; // Previous break id.
496};
497
498
499class EnterDebuggerContext BASE_EMBEDDED {
500 public:
501 // Enter the debugger by storing the previous top context and setting the
502 // current top context to the debugger context.
503 EnterDebuggerContext() {
504 // NOTE the member variable save which saves the previous context before
505 // this change.
506 Top::set_context(*Debug::debug_context());
507 Top::set_security_context(*Debug::debug_context());
508 }
509
510 private:
511 SaveContext save;
512};
513
514
kasper.lundbd3ec4e2008-07-09 11:06:54 +0000515// Stack allocated class for disabling break.
516class DisableBreak BASE_EMBEDDED {
517 public:
518 // Enter the debugger by storing the previous top context and setting the
519 // current top context to the debugger context.
520 explicit DisableBreak(bool disable_break) {
521 prev_disable_break_ = Debug::disable_break();
522 Debug::set_disable_break(disable_break);
523 }
524 ~DisableBreak() {
525 Debug::set_disable_break(prev_disable_break_);
526 }
527
528 private:
529 // The previous state of the disable break used to restore the value when this
530 // object is destructed.
531 bool prev_disable_break_;
532};
533
534
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000535// Debug_Address encapsulates the Address pointers used in generating debug
536// code.
537class Debug_Address {
538 public:
539 Debug_Address(Debug::AddressId id, int reg = 0)
540 : id_(id), reg_(reg) {
541 ASSERT(reg == 0 || id == Debug::k_register_address);
542 }
543
544 static Debug_Address AfterBreakTarget() {
545 return Debug_Address(Debug::k_after_break_target_address);
546 }
547
548 static Debug_Address DebugBreakReturn() {
549 return Debug_Address(Debug::k_debug_break_return_address);
550 }
551
552 static Debug_Address Register(int reg) {
553 return Debug_Address(Debug::k_register_address, reg);
554 }
555
556 Address address() const {
557 switch (id_) {
558 case Debug::k_after_break_target_address:
559 return reinterpret_cast<Address>(Debug::after_break_target_address());
560 case Debug::k_debug_break_return_address:
561 return reinterpret_cast<Address>(Debug::debug_break_return_address());
562 case Debug::k_register_address:
563 return reinterpret_cast<Address>(Debug::register_address(reg_));
564 default:
565 UNREACHABLE();
566 return NULL;
567 }
568 }
569 private:
570 Debug::AddressId id_;
571 int reg_;
572};
573
574
575} } // namespace v8::internal
576
577#endif // V8_DEBUG_H_