OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 // for the stack trace to be collected. The first time a construct | 615 // for the stack trace to be collected. The first time a construct |
616 // call to this function is encountered it is skipped. The seen_caller | 616 // call to this function is encountered it is skipped. The seen_caller |
617 // in/out parameter is used to remember if the caller has been seen | 617 // in/out parameter is used to remember if the caller has been seen |
618 // yet. | 618 // yet. |
619 static bool IsVisibleInStackTrace(StackFrame* raw_frame, | 619 static bool IsVisibleInStackTrace(StackFrame* raw_frame, |
620 Object* caller, | 620 Object* caller, |
621 bool* seen_caller) { | 621 bool* seen_caller) { |
622 // Only display JS frames. | 622 // Only display JS frames. |
623 if (!raw_frame->is_java_script()) return false; | 623 if (!raw_frame->is_java_script()) return false; |
624 JavaScriptFrame* frame = JavaScriptFrame::cast(raw_frame); | 624 JavaScriptFrame* frame = JavaScriptFrame::cast(raw_frame); |
625 Object* raw_fun = frame->function(); | 625 JSFunction* fun = frame->function(); |
626 // Not sure when this can happen but skip it just in case. | 626 if ((fun == caller) && !(*seen_caller)) { |
627 if (!raw_fun->IsJSFunction()) return false; | |
628 if ((raw_fun == caller) && !(*seen_caller)) { | |
629 *seen_caller = true; | 627 *seen_caller = true; |
630 return false; | 628 return false; |
631 } | 629 } |
632 // Skip all frames until we've seen the caller. | 630 // Skip all frames until we've seen the caller. |
633 if (!(*seen_caller)) return false; | 631 if (!(*seen_caller)) return false; |
634 // Also, skip non-visible built-in functions and any call with the builtins | 632 // Also, skip non-visible built-in functions and any call with the builtins |
635 // object as receiver, so as to not reveal either the builtins object or | 633 // object as receiver, so as to not reveal either the builtins object or |
636 // an internal function. | 634 // an internal function. |
637 // The --builtins-in-stack-traces command line flag allows including | 635 // The --builtins-in-stack-traces command line flag allows including |
638 // internal call sites in the stack trace for debugging purposes. | 636 // internal call sites in the stack trace for debugging purposes. |
639 if (!FLAG_builtins_in_stack_traces) { | 637 if (!FLAG_builtins_in_stack_traces) { |
640 JSFunction* fun = JSFunction::cast(raw_fun); | |
641 if (frame->receiver()->IsJSBuiltinsObject() || | 638 if (frame->receiver()->IsJSBuiltinsObject() || |
642 (fun->IsBuiltin() && !fun->shared()->native())) { | 639 (fun->IsBuiltin() && !fun->shared()->native())) { |
643 return false; | 640 return false; |
644 } | 641 } |
645 } | 642 } |
646 return true; | 643 return true; |
647 } | 644 } |
648 | 645 |
649 | 646 |
650 Handle<JSArray> Isolate::CaptureSimpleStackTrace(Handle<JSObject> error_object, | 647 Handle<JSArray> Isolate::CaptureSimpleStackTrace(Handle<JSObject> error_object, |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1194 | 1191 |
1195 void Isolate::PrintCurrentStackTrace(FILE* out) { | 1192 void Isolate::PrintCurrentStackTrace(FILE* out) { |
1196 StackTraceFrameIterator it(this); | 1193 StackTraceFrameIterator it(this); |
1197 while (!it.done()) { | 1194 while (!it.done()) { |
1198 HandleScope scope(this); | 1195 HandleScope scope(this); |
1199 // Find code position if recorded in relocation info. | 1196 // Find code position if recorded in relocation info. |
1200 JavaScriptFrame* frame = it.frame(); | 1197 JavaScriptFrame* frame = it.frame(); |
1201 int pos = frame->LookupCode()->SourcePosition(frame->pc()); | 1198 int pos = frame->LookupCode()->SourcePosition(frame->pc()); |
1202 Handle<Object> pos_obj(Smi::FromInt(pos), this); | 1199 Handle<Object> pos_obj(Smi::FromInt(pos), this); |
1203 // Fetch function and receiver. | 1200 // Fetch function and receiver. |
1204 Handle<JSFunction> fun(JSFunction::cast(frame->function())); | 1201 Handle<JSFunction> fun(frame->function()); |
1205 Handle<Object> recv(frame->receiver(), this); | 1202 Handle<Object> recv(frame->receiver(), this); |
1206 // Advance to the next JavaScript frame and determine if the | 1203 // Advance to the next JavaScript frame and determine if the |
1207 // current frame is the top-level frame. | 1204 // current frame is the top-level frame. |
1208 it.Advance(); | 1205 it.Advance(); |
1209 Handle<Object> is_top_level = it.done() | 1206 Handle<Object> is_top_level = it.done() |
1210 ? factory()->true_value() | 1207 ? factory()->true_value() |
1211 : factory()->false_value(); | 1208 : factory()->false_value(); |
1212 // Generate and print stack trace line. | 1209 // Generate and print stack trace line. |
1213 Handle<String> line = | 1210 Handle<String> line = |
1214 Execution::GetStackTraceLine(recv, fun, pos_obj, is_top_level); | 1211 Execution::GetStackTraceLine(recv, fun, pos_obj, is_top_level); |
1215 if (line->length() > 0) { | 1212 if (line->length() > 0) { |
1216 line->PrintOn(out); | 1213 line->PrintOn(out); |
1217 PrintF(out, "\n"); | 1214 PrintF(out, "\n"); |
1218 } | 1215 } |
1219 } | 1216 } |
1220 } | 1217 } |
1221 | 1218 |
1222 | 1219 |
1223 void Isolate::ComputeLocation(MessageLocation* target) { | 1220 void Isolate::ComputeLocation(MessageLocation* target) { |
1224 *target = MessageLocation(Handle<Script>(heap_.empty_script()), -1, -1); | 1221 *target = MessageLocation(Handle<Script>(heap_.empty_script()), -1, -1); |
1225 StackTraceFrameIterator it(this); | 1222 StackTraceFrameIterator it(this); |
1226 if (!it.done()) { | 1223 if (!it.done()) { |
1227 JavaScriptFrame* frame = it.frame(); | 1224 JavaScriptFrame* frame = it.frame(); |
1228 JSFunction* fun = JSFunction::cast(frame->function()); | 1225 JSFunction* fun = frame->function(); |
1229 Object* script = fun->shared()->script(); | 1226 Object* script = fun->shared()->script(); |
1230 if (script->IsScript() && | 1227 if (script->IsScript() && |
1231 !(Script::cast(script)->source()->IsUndefined())) { | 1228 !(Script::cast(script)->source()->IsUndefined())) { |
1232 int pos = frame->LookupCode()->SourcePosition(frame->pc()); | 1229 int pos = frame->LookupCode()->SourcePosition(frame->pc()); |
1233 // Compute the location from the function and the reloc info. | 1230 // Compute the location from the function and the reloc info. |
1234 Handle<Script> casted_script(Script::cast(script)); | 1231 Handle<Script> casted_script(Script::cast(script)); |
1235 *target = MessageLocation(casted_script, pos, pos + 1); | 1232 *target = MessageLocation(casted_script, pos, pos + 1); |
1236 } | 1233 } |
1237 } | 1234 } |
1238 } | 1235 } |
(...skipping 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2508 | 2505 |
2509 #ifdef DEBUG | 2506 #ifdef DEBUG |
2510 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ | 2507 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ |
2511 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_); | 2508 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_); |
2512 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) | 2509 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) |
2513 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) | 2510 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) |
2514 #undef ISOLATE_FIELD_OFFSET | 2511 #undef ISOLATE_FIELD_OFFSET |
2515 #endif | 2512 #endif |
2516 | 2513 |
2517 } } // namespace v8::internal | 2514 } } // namespace v8::internal |
OLD | NEW |