OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/debug/debug.h" | 5 #include "src/debug/debug.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 1835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1846 // Return to continue execution from where the exception was thrown. | 1846 // Return to continue execution from where the exception was thrown. |
1847 } | 1847 } |
1848 | 1848 |
1849 | 1849 |
1850 void Debug::OnDebugBreak(Handle<Object> break_points_hit, bool auto_continue) { | 1850 void Debug::OnDebugBreak(Handle<Object> break_points_hit, bool auto_continue) { |
1851 // The caller provided for DebugScope. | 1851 // The caller provided for DebugScope. |
1852 AssertDebugContext(); | 1852 AssertDebugContext(); |
1853 // Bail out if there is no listener for this event | 1853 // Bail out if there is no listener for this event |
1854 if (ignore_events()) return; | 1854 if (ignore_events()) return; |
1855 | 1855 |
| 1856 #ifdef DEBUG |
| 1857 PrintBreakLocation(); |
| 1858 #endif // DEBUG |
| 1859 |
1856 HandleScope scope(isolate_); | 1860 HandleScope scope(isolate_); |
1857 // Create the event data object. | 1861 // Create the event data object. |
1858 Handle<Object> event_data; | 1862 Handle<Object> event_data; |
1859 // Bail out and don't call debugger if exception. | 1863 // Bail out and don't call debugger if exception. |
1860 if (!MakeBreakEvent(break_points_hit).ToHandle(&event_data)) return; | 1864 if (!MakeBreakEvent(break_points_hit).ToHandle(&event_data)) return; |
1861 | 1865 |
1862 // Process debug event. | 1866 // Process debug event. |
1863 ProcessDebugEvent(v8::Break, | 1867 ProcessDebugEvent(v8::Break, |
1864 Handle<JSObject>::cast(event_data), | 1868 Handle<JSObject>::cast(event_data), |
1865 auto_continue); | 1869 auto_continue); |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2307 | 2311 |
2308 HandleScope scope(isolate_); | 2312 HandleScope scope(isolate_); |
2309 DebugScope debug_scope(this); | 2313 DebugScope debug_scope(this); |
2310 if (debug_scope.failed()) return; | 2314 if (debug_scope.failed()) return; |
2311 | 2315 |
2312 // Notify the debug event listeners. Indicate auto continue if the break was | 2316 // Notify the debug event listeners. Indicate auto continue if the break was |
2313 // a debug command break. | 2317 // a debug command break. |
2314 OnDebugBreak(isolate_->factory()->undefined_value(), debug_command_only); | 2318 OnDebugBreak(isolate_->factory()->undefined_value(), debug_command_only); |
2315 } | 2319 } |
2316 | 2320 |
| 2321 #ifdef DEBUG |
| 2322 void Debug::PrintBreakLocation() { |
| 2323 if (!FLAG_print_break_location) return; |
| 2324 HandleScope scope(isolate_); |
| 2325 JavaScriptFrameIterator iterator(isolate_); |
| 2326 if (iterator.done()) return; |
| 2327 JavaScriptFrame* frame = iterator.frame(); |
| 2328 FrameSummary summary = GetFirstFrameSummary(frame); |
| 2329 int source_position = |
| 2330 summary.abstract_code()->SourcePosition(summary.code_offset()); |
| 2331 Handle<Object> script_obj(summary.function()->shared()->script(), isolate_); |
| 2332 PrintF("[debug] break in function '"); |
| 2333 summary.function()->PrintName(); |
| 2334 PrintF("'.\n"); |
| 2335 if (script_obj->IsScript()) { |
| 2336 Handle<Script> script = Handle<Script>::cast(script_obj); |
| 2337 Handle<String> source(String::cast(script->source())); |
| 2338 Script::InitLineEnds(script); |
| 2339 int line = Script::GetLineNumber(script, source_position); |
| 2340 int column = Script::GetColumnNumber(script, source_position); |
| 2341 Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends())); |
| 2342 int line_start = |
| 2343 line == 0 ? 0 : Smi::cast(line_ends->get(line - 1))->value(); |
| 2344 int line_end = Smi::cast(line_ends->get(line))->value(); |
| 2345 DisallowHeapAllocation no_gc; |
| 2346 String::FlatContent content = source->GetFlatContent(); |
| 2347 if (content.IsOneByte()) { |
| 2348 PrintF("[debug] %.*s\n", line_end - line_start, |
| 2349 content.ToOneByteVector().start() + line_start); |
| 2350 PrintF("[debug] "); |
| 2351 for (int i = 0; i < column; i++) PrintF(" "); |
| 2352 PrintF("^\n"); |
| 2353 } else { |
| 2354 PrintF("[debug] at line %d column %d\n", line, column); |
| 2355 } |
| 2356 } |
| 2357 } |
| 2358 #endif // DEBUG |
2317 | 2359 |
2318 DebugScope::DebugScope(Debug* debug) | 2360 DebugScope::DebugScope(Debug* debug) |
2319 : debug_(debug), | 2361 : debug_(debug), |
2320 prev_(debug->debugger_entry()), | 2362 prev_(debug->debugger_entry()), |
2321 save_(debug_->isolate_), | 2363 save_(debug_->isolate_), |
2322 no_termination_exceptons_(debug_->isolate_, | 2364 no_termination_exceptons_(debug_->isolate_, |
2323 StackGuard::TERMINATE_EXECUTION) { | 2365 StackGuard::TERMINATE_EXECUTION) { |
2324 // Link recursive debugger entry. | 2366 // Link recursive debugger entry. |
2325 base::NoBarrier_Store(&debug_->thread_local_.current_debug_scope_, | 2367 base::NoBarrier_Store(&debug_->thread_local_.current_debug_scope_, |
2326 reinterpret_cast<base::AtomicWord>(this)); | 2368 reinterpret_cast<base::AtomicWord>(this)); |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2617 } | 2659 } |
2618 | 2660 |
2619 | 2661 |
2620 void LockingCommandMessageQueue::Clear() { | 2662 void LockingCommandMessageQueue::Clear() { |
2621 base::LockGuard<base::Mutex> lock_guard(&mutex_); | 2663 base::LockGuard<base::Mutex> lock_guard(&mutex_); |
2622 queue_.Clear(); | 2664 queue_.Clear(); |
2623 } | 2665 } |
2624 | 2666 |
2625 } // namespace internal | 2667 } // namespace internal |
2626 } // namespace v8 | 2668 } // namespace v8 |
OLD | NEW |