OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 // Code object for debug break return entry code. | 389 // Code object for debug break return entry code. |
390 static Code* debug_break_return_entry_; | 390 static Code* debug_break_return_entry_; |
391 | 391 |
392 // Code to call for handling debug break on return. | 392 // Code to call for handling debug break on return. |
393 static Code* debug_break_return_; | 393 static Code* debug_break_return_; |
394 | 394 |
395 DISALLOW_COPY_AND_ASSIGN(Debug); | 395 DISALLOW_COPY_AND_ASSIGN(Debug); |
396 }; | 396 }; |
397 | 397 |
398 | 398 |
| 399 // A Queue of Vector<uint16_t> objects. A thread-safe version is |
| 400 // LockingMessageQueue, based on this class. |
| 401 class MessageQueue BASE_EMBEDDED { |
| 402 public: |
| 403 explicit MessageQueue(int size); |
| 404 ~MessageQueue(); |
| 405 bool IsEmpty() const { return start_ == end_; } |
| 406 Vector<uint16_t> Get(); |
| 407 void Put(const Vector<uint16_t>& message); |
| 408 void Clear() { start_ = end_ = 0; } // Queue is empty after Clear(). |
| 409 private: |
| 410 // Doubles the size of the message queue, and copies the messages. |
| 411 void Expand(); |
| 412 |
| 413 Vector<uint16_t>* messages_; |
| 414 int start_; |
| 415 int end_; |
| 416 int size_; // The size of the queue buffer. Queue can hold size-1 messages. |
| 417 }; |
| 418 |
| 419 |
| 420 // LockingMessageQueue is a thread-safe circular buffer of Vector<uint16_t> |
| 421 // messages. The message data is not managed by LockingMessageQueue. |
| 422 // Pointers to the data are passed in and out. Implemented by adding a |
| 423 // Mutex to MessageQueue. Includes logging of all puts and gets. |
| 424 class LockingMessageQueue BASE_EMBEDDED { |
| 425 public: |
| 426 explicit LockingMessageQueue(int size); |
| 427 ~LockingMessageQueue(); |
| 428 bool IsEmpty() const; |
| 429 Vector<uint16_t> Get(); |
| 430 void Put(const Vector<uint16_t>& message); |
| 431 void Clear(); |
| 432 private: |
| 433 MessageQueue queue_; |
| 434 Mutex* lock_; |
| 435 DISALLOW_COPY_AND_ASSIGN(LockingMessageQueue); |
| 436 }; |
| 437 |
| 438 |
399 class DebugMessageThread; | 439 class DebugMessageThread; |
400 | 440 |
401 class Debugger { | 441 class Debugger { |
402 public: | 442 public: |
403 static void DebugRequest(const uint16_t* json_request, int length); | 443 static void DebugRequest(const uint16_t* json_request, int length); |
404 | 444 |
405 static Handle<Object> MakeJSObject(Vector<const char> constructor_name, | 445 static Handle<Object> MakeJSObject(Vector<const char> constructor_name, |
406 int argc, Object*** argv, | 446 int argc, Object*** argv, |
407 bool* caught_exception); | 447 bool* caught_exception); |
408 static Handle<Object> MakeExecutionState(bool* caught_exception); | 448 static Handle<Object> MakeExecutionState(bool* caught_exception); |
(...skipping 11 matching lines...) Expand all Loading... |
420 bool* caught_exception); | 460 bool* caught_exception); |
421 static void OnDebugBreak(Handle<Object> break_points_hit, bool auto_continue); | 461 static void OnDebugBreak(Handle<Object> break_points_hit, bool auto_continue); |
422 static void OnException(Handle<Object> exception, bool uncaught); | 462 static void OnException(Handle<Object> exception, bool uncaught); |
423 static void OnBeforeCompile(Handle<Script> script); | 463 static void OnBeforeCompile(Handle<Script> script); |
424 static void OnAfterCompile(Handle<Script> script, | 464 static void OnAfterCompile(Handle<Script> script, |
425 Handle<JSFunction> fun); | 465 Handle<JSFunction> fun); |
426 static void OnNewFunction(Handle<JSFunction> fun); | 466 static void OnNewFunction(Handle<JSFunction> fun); |
427 static void ProcessDebugEvent(v8::DebugEvent event, | 467 static void ProcessDebugEvent(v8::DebugEvent event, |
428 Handle<Object> event_data, | 468 Handle<Object> event_data, |
429 bool auto_continue); | 469 bool auto_continue); |
| 470 static void NotifyMessageHandler(v8::DebugEvent event, |
| 471 Handle<Object> exec_state, |
| 472 Handle<Object> event_data, |
| 473 bool auto_continue); |
430 static void SetEventListener(Handle<Object> callback, Handle<Object> data); | 474 static void SetEventListener(Handle<Object> callback, Handle<Object> data); |
431 static void SetMessageHandler(v8::DebugMessageHandler handler, void* data); | 475 static void SetMessageHandler(v8::DebugMessageHandler handler, void* data, |
| 476 bool message_handler_thread); |
432 static void TearDown(); | 477 static void TearDown(); |
433 static void SetHostDispatchHandler(v8::DebugHostDispatchHandler handler, | 478 static void SetHostDispatchHandler(v8::DebugHostDispatchHandler handler, |
434 void* data); | 479 void* data); |
| 480 |
| 481 // Invoke the message handler function. |
| 482 static void InvokeMessageHandler(Vector< uint16_t> message); |
| 483 |
| 484 // Send a message to the message handler eiher through the message thread or |
| 485 // directly. |
435 static void SendMessage(Vector<uint16_t> message); | 486 static void SendMessage(Vector<uint16_t> message); |
| 487 |
| 488 // Send the JSON message for a debug event. |
| 489 static bool SendEventMessage(Handle<Object> event_data); |
| 490 |
| 491 // Add a debugger command to the command queue. |
436 static void ProcessCommand(Vector<const uint16_t> command); | 492 static void ProcessCommand(Vector<const uint16_t> command); |
| 493 |
| 494 // Check whether there are commands in the command queue. |
437 static bool HasCommands(); | 495 static bool HasCommands(); |
| 496 |
438 static void ProcessHostDispatch(void* dispatch); | 497 static void ProcessHostDispatch(void* dispatch); |
439 static void UpdateActiveDebugger(); | 498 static void UpdateActiveDebugger(); |
440 static Handle<Object> Call(Handle<JSFunction> fun, | 499 static Handle<Object> Call(Handle<JSFunction> fun, |
441 Handle<Object> data, | 500 Handle<Object> data, |
442 bool* pending_exception); | 501 bool* pending_exception); |
443 | 502 |
444 // Start the debugger agent listening on the provided port. | 503 // Start the debugger agent listening on the provided port. |
445 static bool StartAgent(const char* name, int port); | 504 static bool StartAgent(const char* name, int port); |
446 | 505 |
447 // Stop the debugger agent. | 506 // Stop the debugger agent. |
(...skipping 22 matching lines...) Expand all Loading... |
470 static bool compiling_natives_; // Are we compiling natives? | 529 static bool compiling_natives_; // Are we compiling natives? |
471 static bool is_loading_debugger_; // Are we loading the debugger? | 530 static bool is_loading_debugger_; // Are we loading the debugger? |
472 static DebugMessageThread* message_thread_; | 531 static DebugMessageThread* message_thread_; |
473 static v8::DebugMessageHandler message_handler_; | 532 static v8::DebugMessageHandler message_handler_; |
474 static void* message_handler_data_; | 533 static void* message_handler_data_; |
475 static v8::DebugHostDispatchHandler host_dispatch_handler_; | 534 static v8::DebugHostDispatchHandler host_dispatch_handler_; |
476 static void* host_dispatch_handler_data_; | 535 static void* host_dispatch_handler_data_; |
477 | 536 |
478 static DebuggerAgent* agent_; | 537 static DebuggerAgent* agent_; |
479 | 538 |
| 539 static const int kQueueInitialSize = 4; |
| 540 static LockingMessageQueue command_queue_; |
| 541 static LockingMessageQueue message_queue_; |
| 542 static Semaphore* command_received_; // Signaled for each command received. |
| 543 static Semaphore* message_received_; // Signalled for each message send. |
| 544 |
480 friend class DebugMessageThread; | 545 friend class DebugMessageThread; |
481 }; | 546 }; |
482 | 547 |
483 | 548 |
484 // A Queue of Vector<uint16_t> objects. A thread-safe version is | 549 // Thread to read messages from the message queue and invoke the debug message |
485 // LockingMessageQueue, based on this class. | 550 // handler in another thread as the V8 thread. This thread is started if the |
486 class MessageQueue BASE_EMBEDDED { | 551 // registration of the debug message handler requested to be called in a thread |
487 public: | 552 // seperate from the V8 thread. |
488 explicit MessageQueue(int size); | |
489 ~MessageQueue(); | |
490 bool IsEmpty() const { return start_ == end_; } | |
491 Vector<uint16_t> Get(); | |
492 void Put(const Vector<uint16_t>& message); | |
493 void Clear() { start_ = end_ = 0; } // Queue is empty after Clear(). | |
494 private: | |
495 // Doubles the size of the message queue, and copies the messages. | |
496 void Expand(); | |
497 | |
498 Vector<uint16_t>* messages_; | |
499 int start_; | |
500 int end_; | |
501 int size_; // The size of the queue buffer. Queue can hold size-1 messages. | |
502 }; | |
503 | |
504 | |
505 // LockingMessageQueue is a thread-safe circular buffer of Vector<uint16_t> | |
506 // messages. The message data is not managed by LockingMessageQueue. | |
507 // Pointers to the data are passed in and out. Implemented by adding a | |
508 // Mutex to MessageQueue. Includes logging of all puts and gets. | |
509 class LockingMessageQueue BASE_EMBEDDED { | |
510 public: | |
511 explicit LockingMessageQueue(int size); | |
512 ~LockingMessageQueue(); | |
513 bool IsEmpty() const; | |
514 Vector<uint16_t> Get(); | |
515 void Put(const Vector<uint16_t>& message); | |
516 void Clear(); | |
517 private: | |
518 MessageQueue queue_; | |
519 Mutex* lock_; | |
520 DISALLOW_COPY_AND_ASSIGN(LockingMessageQueue); | |
521 }; | |
522 | |
523 | |
524 /* This class is the data for a running thread that serializes | |
525 * event messages and command processing for the debugger. | |
526 * All uncommented methods are called only from this message thread. | |
527 */ | |
528 class DebugMessageThread: public Thread { | 553 class DebugMessageThread: public Thread { |
529 public: | 554 public: |
530 DebugMessageThread(); // Called from API thread. | 555 DebugMessageThread() : keep_running_(true) {} |
531 virtual ~DebugMessageThread(); | 556 virtual ~DebugMessageThread() {} |
532 // Called by V8 thread. Reports events from V8 VM. | |
533 // Also handles command processing in stopped state of V8, | |
534 // when host_running_ is false. | |
535 void DebugEvent(v8::DebugEvent, | |
536 Handle<Object> exec_state, | |
537 Handle<Object> event_data, | |
538 bool auto_continue); | |
539 // Puts event on the output queue. Called by V8. | |
540 // This is where V8 hands off | |
541 // processing of the event to the DebugMessageThread thread, | |
542 // which forwards it to the debug_message_handler set by the API. | |
543 void SendMessage(Vector<uint16_t> event_json); | |
544 // Formats an event into JSON, and calls SendMessage. | |
545 bool SetEventJSONFromEvent(Handle<Object> event_data); | |
546 // Puts a command coming from the public API on the queue. Called | |
547 // by the API client thread. This is where the API client hands off | |
548 // processing of the command to the DebugMessageThread thread. | |
549 void ProcessCommand(Vector<uint16_t> command); | |
550 void ProcessHostDispatch(void* dispatch); | |
551 void OnDebuggerInactive(); | |
552 | 557 |
553 // Main function of DebugMessageThread thread. | 558 // Main function of DebugMessageThread thread. |
554 void Run(); | 559 void Run(); |
555 | |
556 // Check whether there are commands in the queue. | |
557 bool HasCommands() { return !command_queue_.IsEmpty(); } | |
558 void Stop(); | 560 void Stop(); |
559 | 561 |
560 bool host_running_; // Is the debugging host running or stopped? | |
561 Semaphore* command_received_; // Non-zero when command queue is non-empty. | |
562 Semaphore* message_received_; // Exactly equal to message queue length. | |
563 private: | 562 private: |
564 bool TwoByteEqualsAscii(Vector<uint16_t> two_byte, const char* ascii); | |
565 | |
566 static const int kQueueInitialSize = 4; | |
567 LockingMessageQueue command_queue_; | |
568 LockingMessageQueue message_queue_; | |
569 bool keep_running_; | 563 bool keep_running_; |
570 DISALLOW_COPY_AND_ASSIGN(DebugMessageThread); | 564 DISALLOW_COPY_AND_ASSIGN(DebugMessageThread); |
571 }; | 565 }; |
572 | 566 |
573 | 567 |
574 // This class is used for entering the debugger. Create an instance in the stack | 568 // This class is used for entering the debugger. Create an instance in the stack |
575 // to enter the debugger. This will set the current break state, make sure the | 569 // to enter the debugger. This will set the current break state, make sure the |
576 // debugger is loaded and switch to the debugger context. If the debugger for | 570 // debugger is loaded and switch to the debugger context. If the debugger for |
577 // some reason could not be entered FailedToEnter will return true. | 571 // some reason could not be entered FailedToEnter will return true. |
578 class EnterDebugger BASE_EMBEDDED { | 572 class EnterDebugger BASE_EMBEDDED { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 } | 695 } |
702 private: | 696 private: |
703 Debug::AddressId id_; | 697 Debug::AddressId id_; |
704 int reg_; | 698 int reg_; |
705 }; | 699 }; |
706 | 700 |
707 | 701 |
708 } } // namespace v8::internal | 702 } } // namespace v8::internal |
709 | 703 |
710 #endif // V8_V8_DEBUG_H_ | 704 #endif // V8_V8_DEBUG_H_ |
OLD | NEW |