Revision: 4186
Author: [email protected]
Date: Thu Mar 18 15:15:54 2010
Log: Show file name/line number in stack trace

Review URL: http://codereview.chromium.org/1002010
http://code.google.com/p/v8/source/detail?r=4186

Modified:
 /branches/bleeding_edge/src/frames.cc
 /branches/bleeding_edge/src/handles.cc
 /branches/bleeding_edge/src/handles.h

=======================================
--- /branches/bleeding_edge/src/frames.cc       Mon Mar  8 22:38:33 2010
+++ /branches/bleeding_edge/src/frames.cc       Thu Mar 18 15:15:54 2010
@@ -520,6 +520,31 @@
   Code* code = NULL;
   if (IsConstructor()) accumulator->Add("new ");
   accumulator->PrintFunction(function, receiver, &code);
+
+  if (function->IsJSFunction()) {
+ Handle<SharedFunctionInfo> shared(JSFunction::cast(function)->shared());
+    Object* script_obj = shared->script();
+    if (script_obj->IsScript()) {
+      Handle<Script> script(Script::cast(script_obj));
+      accumulator->Add(" [");
+      accumulator->PrintName(script->name());
+
+      Address pc = this->pc();
+      if (code != NULL && code->kind() == Code::FUNCTION &&
+ pc >= code->instruction_start() && pc < code->relocation_start()) {
+        int source_pos = code->SourcePosition(pc);
+        int line = GetScriptLineNumberSafe(script, source_pos) + 1;
+        accumulator->Add(":%d", line);
+      } else {
+        int function_start_pos = shared->start_position();
+        int line = GetScriptLineNumberSafe(script, function_start_pos) + 1;
+        accumulator->Add(":~%d", line);
+      }
+
+      accumulator->Add("] ");
+    }
+  }
+
   accumulator->Add("(this=%o", receiver);

   // Get scope information for nicer output, if possible. If code is
=======================================
--- /branches/bleeding_edge/src/handles.cc      Wed Mar 17 01:14:59 2010
+++ /branches/bleeding_edge/src/handles.cc      Thu Mar 18 15:15:54 2010
@@ -512,6 +512,30 @@
   }
   return right + script->line_offset()->value();
 }
+
+
+int GetScriptLineNumberSafe(Handle<Script> script, int code_pos) {
+  AssertNoAllocation no_allocation;
+  if (!script->line_ends()->IsUndefined()) {
+    return GetScriptLineNumber(script, code_pos);
+  }
+ // Slow mode: we do not have line_ends. We have to iterate through source.
+  if (!script->source()->IsString()) {
+    return -1;
+  }
+  String* source = String::cast(script->source());
+  int line = 0;
+  int len = source->length();
+  for (int pos = 0; pos < len; pos++) {
+    if (pos == code_pos) {
+      break;
+    }
+    if (source->Get(pos) == '\n') {
+      line++;
+    }
+  }
+  return line;
+}


 void CustomArguments::IterateInstance(ObjectVisitor* v) {
=======================================
--- /branches/bleeding_edge/src/handles.h       Tue Mar  2 10:47:03 2010
+++ /branches/bleeding_edge/src/handles.h       Thu Mar 18 15:15:54 2010
@@ -267,6 +267,8 @@
 // Script line number computations.
 void InitScriptLineEnds(Handle<Script> script);
 int GetScriptLineNumber(Handle<Script> script, int code_position);
+// The safe version does not make heap allocations but may work much slower.
+int GetScriptLineNumberSafe(Handle<Script> script, int code_position);

// Computes the enumerable keys from interceptors. Used for debug mirrors and
 // by GetKeysInFixedArrayFor below.

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

To unsubscribe from this group, send email to v8-dev+unsubscribegooglegroups.com or reply 
to this email with the words "REMOVE ME" as the subject.

Reply via email to