Reviewers: Søren Gjesse,
Message:
Hi Soren
I'd like to see Top::PrintStack() more helpful, i.e. with script names/line
number.
I don't know, whether this implementation is accurate enough.
Peter
Description:
Show file name/line number in stack trace
Please review this at http://codereview.chromium.org/1002010
Affected files:
M src/frames.cc
M src/handles.h
M src/handles.cc
Index: src/frames.cc
diff --git a/src/frames.cc b/src/frames.cc
index
3bf4c93e39893bba2031a58dd984e9ba450603c1..12eaf7a19ff3ed0ea0cfc5510ab7350b94e76894
100644
--- a/src/frames.cc
+++ b/src/frames.cc
@@ -520,6 +520,28 @@ void JavaScriptFrame::Print(StringStream* accumulator,
Code* code = NULL;
if (IsConstructor()) accumulator->Add("new ");
accumulator->PrintFunction(function, receiver, &code);
+
+ if (function->IsJSFunction() && code != NULL) {
+ 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 (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 {
+ accumulator->Add(":unknown");
+ }
+
+ accumulator->Add("] ");
+ }
+ }
+
accumulator->Add("(this=%o", receiver);
// Get scope information for nicer output, if possible. If code is
Index: src/handles.cc
diff --git a/src/handles.cc b/src/handles.cc
index
c71d92bb15afce798b8c7f8369e3270f9d6b198d..16d64d3b6d3da5ff064c41ca827d44192240c75a
100644
--- a/src/handles.cc
+++ b/src/handles.cc
@@ -514,6 +514,30 @@ int GetScriptLineNumber(Handle<Script> script, int
code_pos) {
}
+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) {
v->VisitPointers(values_, values_ + 4);
}
Index: src/handles.h
diff --git a/src/handles.h b/src/handles.h
index
0c137a4ce7caa64a8bb4870a69376e58328e4a5a..f241da203675ab728d44559d6ce6fa2b52eb0d41
100644
--- a/src/handles.h
+++ b/src/handles.h
@@ -267,6 +267,8 @@ Handle<JSValue> GetScriptWrapper(Handle<Script> script);
// 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