OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 150 |
151 | 151 |
152 // Is there any debug info for the function? | 152 // Is there any debug info for the function? |
153 static bool HasDebugInfo(v8::Local<v8::Function> fun) { | 153 static bool HasDebugInfo(v8::Local<v8::Function> fun) { |
154 Handle<v8::internal::JSFunction> f = | 154 Handle<v8::internal::JSFunction> f = |
155 Handle<v8::internal::JSFunction>::cast(v8::Utils::OpenHandle(*fun)); | 155 Handle<v8::internal::JSFunction>::cast(v8::Utils::OpenHandle(*fun)); |
156 Handle<v8::internal::SharedFunctionInfo> shared(f->shared()); | 156 Handle<v8::internal::SharedFunctionInfo> shared(f->shared()); |
157 return shared->HasDebugInfo(); | 157 return shared->HasDebugInfo(); |
158 } | 158 } |
159 | 159 |
160 | 160 // Set a break point in a function with a position relative to function start, |
161 // Set a break point in a function and return the associated break point | 161 // and return the associated break point number. |
162 // number. | 162 static int SetBreakPoint(v8::Local<v8::Function> fun, int position) { |
163 static int SetBreakPoint(Handle<v8::internal::JSFunction> fun, int position) { | 163 i::Handle<i::JSFunction> function = |
| 164 i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*fun)); |
| 165 position += function->shared()->start_position(); |
164 static int break_point = 0; | 166 static int break_point = 0; |
165 v8::internal::Isolate* isolate = fun->GetIsolate(); | 167 v8::internal::Isolate* isolate = function->GetIsolate(); |
166 v8::internal::Debug* debug = isolate->debug(); | 168 v8::internal::Debug* debug = isolate->debug(); |
167 debug->SetBreakPoint( | 169 debug->SetBreakPoint( |
168 fun, | 170 function, |
169 Handle<Object>(v8::internal::Smi::FromInt(++break_point), isolate), | 171 Handle<Object>(v8::internal::Smi::FromInt(++break_point), isolate), |
170 &position); | 172 &position); |
171 return break_point; | 173 return break_point; |
172 } | 174 } |
173 | 175 |
174 | 176 |
175 // Set a break point in a function and return the associated break point | |
176 // number. | |
177 static int SetBreakPoint(v8::Local<v8::Function> fun, int position) { | |
178 return SetBreakPoint( | |
179 i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*fun)), position); | |
180 } | |
181 | |
182 | |
183 // Set a break point in a function using the Debug object and return the | 177 // Set a break point in a function using the Debug object and return the |
184 // associated break point number. | 178 // associated break point number. |
185 static int SetBreakPointFromJS(v8::Isolate* isolate, | 179 static int SetBreakPointFromJS(v8::Isolate* isolate, |
186 const char* function_name, | 180 const char* function_name, |
187 int line, int position) { | 181 int line, int position) { |
188 EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer; | 182 EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer; |
189 SNPrintF(buffer, | 183 SNPrintF(buffer, |
190 "debug.Debug.setBreakPoint(%s,%d,%d)", | 184 "debug.Debug.setBreakPoint(%s,%d,%d)", |
191 function_name, line, position); | 185 function_name, line, position); |
192 buffer[SMALL_STRING_BUFFER_SIZE - 1] = '\0'; | 186 buffer[SMALL_STRING_BUFFER_SIZE - 1] = '\0'; |
(...skipping 7839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8032 if (location.IsDebuggerStatement()) found_debugger = true; | 8026 if (location.IsDebuggerStatement()) found_debugger = true; |
8033 } | 8027 } |
8034 CHECK(found_call); | 8028 CHECK(found_call); |
8035 CHECK(found_return); | 8029 CHECK(found_return); |
8036 CHECK(found_debugger); | 8030 CHECK(found_debugger); |
8037 | 8031 |
8038 // Test underlying implementation. | 8032 // Test underlying implementation. |
8039 TestBreakLocation::Iterator* iterator = | 8033 TestBreakLocation::Iterator* iterator = |
8040 TestBreakLocation::GetIterator(debug_info, i::ALL_BREAK_LOCATIONS); | 8034 TestBreakLocation::GetIterator(debug_info, i::ALL_BREAK_LOCATIONS); |
8041 CHECK(iterator->GetBreakLocation().IsDebuggerStatement()); | 8035 CHECK(iterator->GetBreakLocation().IsDebuggerStatement()); |
8042 CHECK_EQ(7, iterator->GetBreakLocation().position()); | 8036 CHECK_EQ(17, iterator->GetBreakLocation().position()); |
8043 iterator->Next(); | 8037 iterator->Next(); |
8044 CHECK(iterator->GetBreakLocation().IsDebugBreakSlot()); | 8038 CHECK(iterator->GetBreakLocation().IsDebugBreakSlot()); |
8045 CHECK_EQ(22, iterator->GetBreakLocation().position()); | 8039 CHECK_EQ(32, iterator->GetBreakLocation().position()); |
8046 iterator->Next(); | 8040 iterator->Next(); |
8047 CHECK(iterator->GetBreakLocation().IsCall()); | 8041 CHECK(iterator->GetBreakLocation().IsCall()); |
8048 CHECK_EQ(22, iterator->GetBreakLocation().position()); | 8042 CHECK_EQ(32, iterator->GetBreakLocation().position()); |
8049 iterator->Next(); | 8043 iterator->Next(); |
8050 CHECK(iterator->GetBreakLocation().IsDebuggerStatement()); | 8044 CHECK(iterator->GetBreakLocation().IsDebuggerStatement()); |
8051 CHECK_EQ(37, iterator->GetBreakLocation().position()); | 8045 CHECK_EQ(47, iterator->GetBreakLocation().position()); |
8052 iterator->Next(); | 8046 iterator->Next(); |
8053 CHECK(iterator->GetBreakLocation().IsReturn()); | 8047 CHECK(iterator->GetBreakLocation().IsReturn()); |
8054 CHECK_EQ(50, iterator->GetBreakLocation().position()); | 8048 CHECK_EQ(60, iterator->GetBreakLocation().position()); |
8055 iterator->Next(); | 8049 iterator->Next(); |
8056 CHECK(iterator->Done()); | 8050 CHECK(iterator->Done()); |
8057 delete iterator; | 8051 delete iterator; |
8058 | 8052 |
8059 iterator = TestBreakLocation::GetIterator(debug_info, i::CALLS_AND_RETURNS); | 8053 iterator = TestBreakLocation::GetIterator(debug_info, i::CALLS_AND_RETURNS); |
8060 CHECK(iterator->GetBreakLocation().IsCall()); | 8054 CHECK(iterator->GetBreakLocation().IsCall()); |
8061 CHECK_EQ(22, iterator->GetBreakLocation().position()); | 8055 CHECK_EQ(32, iterator->GetBreakLocation().position()); |
8062 iterator->Next(); | 8056 iterator->Next(); |
8063 CHECK(iterator->GetBreakLocation().IsReturn()); | 8057 CHECK(iterator->GetBreakLocation().IsReturn()); |
8064 CHECK_EQ(50, iterator->GetBreakLocation().position()); | 8058 CHECK_EQ(60, iterator->GetBreakLocation().position()); |
8065 iterator->Next(); | 8059 iterator->Next(); |
8066 CHECK(iterator->Done()); | 8060 CHECK(iterator->Done()); |
8067 delete iterator; | 8061 delete iterator; |
8068 | 8062 |
8069 DisableDebugger(isolate); | 8063 DisableDebugger(isolate); |
8070 } | 8064 } |
8071 | 8065 |
8072 TEST(DisableTailCallElimination) { | 8066 TEST(DisableTailCallElimination) { |
8073 i::FLAG_allow_natives_syntax = true; | 8067 i::FLAG_allow_natives_syntax = true; |
8074 i::FLAG_harmony_tailcalls = true; | 8068 i::FLAG_harmony_tailcalls = true; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8209 "function foo() {\n" | 8203 "function foo() {\n" |
8210 " try { throw new Error(); } catch (e) {}\n" | 8204 " try { throw new Error(); } catch (e) {}\n" |
8211 "}\n" | 8205 "}\n" |
8212 "debugger;\n" | 8206 "debugger;\n" |
8213 "foo();\n" | 8207 "foo();\n" |
8214 "foo();\n"); | 8208 "foo();\n"); |
8215 | 8209 |
8216 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr); | 8210 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr); |
8217 CHECK_EQ(break_point_hit_count, 4); | 8211 CHECK_EQ(break_point_hit_count, 4); |
8218 } | 8212 } |
OLD | NEW |