Index: src/debug/debug.cc |
diff --git a/src/debug/debug.cc b/src/debug/debug.cc |
index 42192b0b5340bebf36e94fadd38b1862c2241831..ef170e59c7f7bc93c8fd3c6a2bcfea4bc0d5dee9 100644 |
--- a/src/debug/debug.cc |
+++ b/src/debug/debug.cc |
@@ -1853,6 +1853,10 @@ void Debug::OnDebugBreak(Handle<Object> break_points_hit, bool auto_continue) { |
// Bail out if there is no listener for this event |
if (ignore_events()) return; |
+#ifdef DEBUG |
+ PrintBreakLocation(); |
+#endif // DEBUG |
+ |
HandleScope scope(isolate_); |
// Create the event data object. |
Handle<Object> event_data; |
@@ -2314,6 +2318,44 @@ void Debug::ProcessDebugMessages(bool debug_command_only) { |
OnDebugBreak(isolate_->factory()->undefined_value(), debug_command_only); |
} |
+#ifdef DEBUG |
+void Debug::PrintBreakLocation() { |
+ if (!FLAG_print_break_location) return; |
+ HandleScope scope(isolate_); |
+ JavaScriptFrameIterator iterator(isolate_); |
+ if (iterator.done()) return; |
+ JavaScriptFrame* frame = iterator.frame(); |
+ FrameSummary summary = GetFirstFrameSummary(frame); |
+ int source_position = |
+ summary.abstract_code()->SourcePosition(summary.code_offset()); |
+ Handle<Object> script_obj(summary.function()->shared()->script(), isolate_); |
+ PrintF("[debug] break in function '"); |
+ summary.function()->PrintName(); |
+ PrintF("'.\n"); |
+ if (script_obj->IsScript()) { |
+ Handle<Script> script = Handle<Script>::cast(script_obj); |
+ Handle<String> source(String::cast(script->source())); |
+ Script::InitLineEnds(script); |
+ int line = Script::GetLineNumber(script, source_position); |
+ int column = Script::GetColumnNumber(script, source_position); |
+ Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends())); |
+ int line_start = |
+ line == 0 ? 0 : Smi::cast(line_ends->get(line - 1))->value(); |
+ int line_end = Smi::cast(line_ends->get(line))->value(); |
+ DisallowHeapAllocation no_gc; |
+ String::FlatContent content = source->GetFlatContent(); |
+ if (content.IsOneByte()) { |
+ PrintF("[debug] %.*s\n", line_end - line_start, |
+ content.ToOneByteVector().start() + line_start); |
+ PrintF("[debug] "); |
+ for (int i = 0; i < column; i++) PrintF(" "); |
+ PrintF("^\n"); |
+ } else { |
+ PrintF("[debug] at line %d column %d\n", line, column); |
+ } |
+ } |
+} |
+#endif // DEBUG |
DebugScope::DebugScope(Debug* debug) |
: debug_(debug), |