Show file name/line number in stack trace

Review URL: http://codereview.chromium.org/1002010

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4186 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
peter.rybin@gmail.com 2010-03-18 22:15:54 +00:00
parent ec974ddb50
commit f822f101a0
3 changed files with 51 additions and 0 deletions

View File

@ -520,6 +520,31 @@ void JavaScriptFrame::Print(StringStream* accumulator,
Code* code = NULL; Code* code = NULL;
if (IsConstructor()) accumulator->Add("new "); if (IsConstructor()) accumulator->Add("new ");
accumulator->PrintFunction(function, receiver, &code); 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); accumulator->Add("(this=%o", receiver);
// Get scope information for nicer output, if possible. If code is // Get scope information for nicer output, if possible. If code is

View File

@ -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) { void CustomArguments::IterateInstance(ObjectVisitor* v) {
v->VisitPointers(values_, values_ + 4); v->VisitPointers(values_, values_ + 4);
} }

View File

@ -267,6 +267,8 @@ Handle<JSValue> GetScriptWrapper(Handle<Script> script);
// Script line number computations. // Script line number computations.
void InitScriptLineEnds(Handle<Script> script); void InitScriptLineEnds(Handle<Script> script);
int GetScriptLineNumber(Handle<Script> script, int code_position); 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 // Computes the enumerable keys from interceptors. Used for debug mirrors and
// by GetKeysInFixedArrayFor below. // by GetKeysInFixedArrayFor below.