OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-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 3854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3865 char* pos = strstr(message, breakpoints); | 3865 char* pos = strstr(message, breakpoints); |
3866 if (pos == NULL) { | 3866 if (pos == NULL) { |
3867 return -1; | 3867 return -1; |
3868 } | 3868 } |
3869 int res = -1; | 3869 int res = -1; |
3870 res = atoi(pos + strlen(breakpoints)); | 3870 res = atoi(pos + strlen(breakpoints)); |
3871 return res; | 3871 return res; |
3872 } | 3872 } |
3873 | 3873 |
3874 | 3874 |
| 3875 // We match parts of the message to get total frames number. |
| 3876 int GetTotalFramesInt(char *message) { |
| 3877 const char* prefix = "\"totalFrames\":"; |
| 3878 char* pos = strstr(message, prefix); |
| 3879 if (pos == NULL) { |
| 3880 return -1; |
| 3881 } |
| 3882 pos += strlen(prefix); |
| 3883 char* pos_end = pos; |
| 3884 long res = strtol(pos, &pos_end, 10); |
| 3885 if (pos_end == pos) { |
| 3886 return -1; |
| 3887 } |
| 3888 return static_cast<int>(res); |
| 3889 } |
| 3890 |
| 3891 |
3875 /* Test MessageQueues */ | 3892 /* Test MessageQueues */ |
3876 /* Tests the message queues that hold debugger commands and | 3893 /* Tests the message queues that hold debugger commands and |
3877 * response messages to the debugger. Fills queues and makes | 3894 * response messages to the debugger. Fills queues and makes |
3878 * them grow. | 3895 * them grow. |
3879 */ | 3896 */ |
3880 Barriers message_queue_barriers; | 3897 Barriers message_queue_barriers; |
3881 | 3898 |
3882 // This is the debugger thread, that executes no v8 calls except | 3899 // This is the debugger thread, that executes no v8 calls except |
3883 // placing JSON debugger commands in the queue. | 3900 // placing JSON debugger commands in the queue. |
3884 class MessageQueueDebuggerThread : public v8::internal::Thread { | 3901 class MessageQueueDebuggerThread : public v8::internal::Thread { |
(...skipping 1935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5820 v8::Debug::ProcessDebugMessages(); | 5837 v8::Debug::ProcessDebugMessages(); |
5821 // At least two messages should come | 5838 // At least two messages should come |
5822 CHECK_GE(counting_message_handler_counter, 2); | 5839 CHECK_GE(counting_message_handler_counter, 2); |
5823 | 5840 |
5824 // Get rid of the debug message handler. | 5841 // Get rid of the debug message handler. |
5825 v8::Debug::SetMessageHandler2(NULL); | 5842 v8::Debug::SetMessageHandler2(NULL); |
5826 CheckDebuggerUnloaded(); | 5843 CheckDebuggerUnloaded(); |
5827 } | 5844 } |
5828 | 5845 |
5829 | 5846 |
| 5847 struct BracktraceData { |
| 5848 static int frame_counter; |
| 5849 static void MessageHandler(const v8::Debug::Message& message) { |
| 5850 char print_buffer[1000]; |
| 5851 v8::String::Value json(message.GetJSON()); |
| 5852 Utf16ToAscii(*json, json.length(), print_buffer, 1000); |
| 5853 |
| 5854 if (strstr(print_buffer, "backtrace") == NULL) { |
| 5855 return; |
| 5856 } |
| 5857 frame_counter = GetTotalFramesInt(print_buffer); |
| 5858 } |
| 5859 }; |
| 5860 |
| 5861 int BracktraceData::frame_counter; |
| 5862 |
| 5863 |
| 5864 // Test that debug messages get processed when ProcessDebugMessages is called. |
| 5865 TEST(Backtrace) { |
| 5866 v8::HandleScope scope; |
| 5867 DebugLocalContext env; |
| 5868 |
| 5869 v8::Debug::SetMessageHandler2(BracktraceData::MessageHandler); |
| 5870 |
| 5871 const int kBufferSize = 1000; |
| 5872 uint16_t buffer[kBufferSize]; |
| 5873 const char* scripts_command = |
| 5874 "{\"seq\":0," |
| 5875 "\"type\":\"request\"," |
| 5876 "\"command\":\"backtrace\"}"; |
| 5877 |
| 5878 // Check backtrace from ProcessDebugMessages. |
| 5879 BracktraceData::frame_counter = -10; |
| 5880 v8::Debug::SendCommand(buffer, AsciiToUtf16(scripts_command, buffer)); |
| 5881 v8::Debug::ProcessDebugMessages(); |
| 5882 CHECK_EQ(BracktraceData::frame_counter, 0); |
| 5883 |
| 5884 v8::Handle<v8::String> void0 = v8::String::New("void(0)"); |
| 5885 v8::Handle<v8::Script> script = v8::Script::Compile(void0, void0); |
| 5886 |
| 5887 // Check backtrace from "void(0)" script. |
| 5888 BracktraceData::frame_counter = -10; |
| 5889 v8::Debug::SendCommand(buffer, AsciiToUtf16(scripts_command, buffer)); |
| 5890 script->Run(); |
| 5891 CHECK_EQ(BracktraceData::frame_counter, 1); |
| 5892 |
| 5893 // Get rid of the debug message handler. |
| 5894 v8::Debug::SetMessageHandler2(NULL); |
| 5895 CheckDebuggerUnloaded(); |
| 5896 } |
| 5897 |
| 5898 |
5830 TEST(GetMirror) { | 5899 TEST(GetMirror) { |
5831 v8::HandleScope scope; | 5900 v8::HandleScope scope; |
5832 DebugLocalContext env; | 5901 DebugLocalContext env; |
5833 v8::Handle<v8::Value> obj = v8::Debug::GetMirror(v8::String::New("hodja")); | 5902 v8::Handle<v8::Value> obj = v8::Debug::GetMirror(v8::String::New("hodja")); |
5834 v8::Handle<v8::Function> run_test = v8::Handle<v8::Function>::Cast( | 5903 v8::Handle<v8::Function> run_test = v8::Handle<v8::Function>::Cast( |
5835 v8::Script::New( | 5904 v8::Script::New( |
5836 v8::String::New( | 5905 v8::String::New( |
5837 "function runTest(mirror) {" | 5906 "function runTest(mirror) {" |
5838 " return mirror.isString() && (mirror.length() == 5);" | 5907 " return mirror.isString() && (mirror.length() == 5);" |
5839 "}" | 5908 "}" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5951 | 6020 |
5952 break_point_hit_count = 0; | 6021 break_point_hit_count = 0; |
5953 foo->Call(env->Global(), 0, NULL); | 6022 foo->Call(env->Global(), 0, NULL); |
5954 CHECK_EQ(1, break_point_hit_count); | 6023 CHECK_EQ(1, break_point_hit_count); |
5955 | 6024 |
5956 v8::Debug::SetDebugEventListener(NULL); | 6025 v8::Debug::SetDebugEventListener(NULL); |
5957 debugee_context = v8::Handle<v8::Context>(); | 6026 debugee_context = v8::Handle<v8::Context>(); |
5958 debugger_context = v8::Handle<v8::Context>(); | 6027 debugger_context = v8::Handle<v8::Context>(); |
5959 CheckDebuggerUnloaded(); | 6028 CheckDebuggerUnloaded(); |
5960 } | 6029 } |
OLD | NEW |