Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Unified Diff: src/debug/debug.cc

Issue 1732253002: [debugger] add utility to print break location. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: address comment Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/debug/debug.h ('k') | src/flag-definitions.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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),
« no previous file with comments | « src/debug/debug.h ('k') | src/flag-definitions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698