OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/object.h" | 5 #include "vm/object.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
(...skipping 15355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
15366 Isolate* isolate = Isolate::Current(); | 15366 Isolate* isolate = Isolate::Current(); |
15367 Function& function = Function::Handle(); | 15367 Function& function = Function::Handle(); |
15368 Code& code = Code::Handle(); | 15368 Code& code = Code::Handle(); |
15369 // Iterate through the stack frames and create C string description | 15369 // Iterate through the stack frames and create C string description |
15370 // for each frame. | 15370 // for each frame. |
15371 intptr_t total_len = 0; | 15371 intptr_t total_len = 0; |
15372 GrowableArray<char*> frame_strings; | 15372 GrowableArray<char*> frame_strings; |
15373 for (intptr_t i = 0; i < Length(); i++) { | 15373 for (intptr_t i = 0; i < Length(); i++) { |
15374 function = FunctionAtFrame(i); | 15374 function = FunctionAtFrame(i); |
15375 if (function.IsNull()) { | 15375 if (function.IsNull()) { |
15376 // Check if null function object indicates a stack trace overflow. | 15376 // Check for null function object, which indicates a stack trace overflow. |
siva
2013/10/31 17:13:26
A null function object doesn't necessarily mean a
rmacnak
2013/11/07 21:31:12
Reverted.
| |
15377 if ((i < (Length() - 1)) && | 15377 if ((i < (Length() - 1)) && |
15378 (FunctionAtFrame(i + 1) != Function::null())) { | 15378 (FunctionAtFrame(i + 1) != Function::null())) { |
15379 const char* kTruncated = "...\n...\n"; | 15379 const char* kTruncated = "...\n...\n"; |
15380 intptr_t truncated_len = strlen(kTruncated) + 1; | 15380 intptr_t truncated_len = strlen(kTruncated) + 1; |
15381 char* chars = isolate->current_zone()->Alloc<char>(truncated_len); | 15381 char* chars = isolate->current_zone()->Alloc<char>(truncated_len); |
15382 OS::SNPrint(chars, truncated_len, "%s", kTruncated); | 15382 OS::SNPrint(chars, truncated_len, "%s", kTruncated); |
15383 frame_strings.Add(chars); | 15383 frame_strings.Add(chars); |
15384 } | 15384 } |
15385 } else if (function.is_visible() || FLAG_verbose_stacktrace) { | 15385 } else if (function.is_visible() || FLAG_verbose_stacktrace) { |
15386 code = CodeAtFrame(i); | 15386 code = CodeAtFrame(i); |
(...skipping 27 matching lines...) Expand all Loading... | |
15414 for (intptr_t i = 0; i < frame_strings.length(); i++) { | 15414 for (intptr_t i = 0; i < frame_strings.length(); i++) { |
15415 index += OS::SNPrint((chars + index), | 15415 index += OS::SNPrint((chars + index), |
15416 (total_len + 1 - index), | 15416 (total_len + 1 - index), |
15417 "%s", | 15417 "%s", |
15418 frame_strings[i]); | 15418 frame_strings[i]); |
15419 } | 15419 } |
15420 chars[total_len] = '\0'; | 15420 chars[total_len] = '\0'; |
15421 return chars; | 15421 return chars; |
15422 } | 15422 } |
15423 | 15423 |
15424 intptr_t Stacktrace::VisibleLength() const { | |
15425 // Isolate* isolate = Isolate::Current(); | |
15426 Function& function = Function::Handle(); | |
15427 Code& code = Code::Handle(); | |
15428 intptr_t frame_count = 0; | |
15429 for (intptr_t i = 0; i < Length(); i++) { | |
15430 function = FunctionAtFrame(i); | |
15431 if (function.IsNull()) { | |
15432 // Check for null function object, which indicates a stack trace overflow. | |
15433 if ((i < (Length() - 1)) && | |
15434 (FunctionAtFrame(i + 1) != Function::null())) { | |
15435 // How to inform API users? | |
rmacnak
2013/10/30 16:52:45
frame_count++ if we indicate the gap. See comment
siva
2013/10/31 17:13:26
Since you are handing out actual frames maybe the
rmacnak
2013/11/07 21:31:12
The truncation for StackOverflow happens before th
| |
15436 } | |
15437 } else if (function.is_visible() || FLAG_verbose_stacktrace) { | |
siva
2013/10/31 17:13:26
We probably don't want the verbose_stacktrace flag
rmacnak
2013/11/07 21:31:12
Removed.
| |
15438 code = CodeAtFrame(i); | |
15439 ASSERT(function.raw() == code.function()); | |
15440 uword pc = code.EntryPoint() + Smi::Value(PcOffsetAtFrame(i)); | |
15441 if (code.is_optimized() && expand_inlined()) { | |
15442 // Traverse inlined frames. | |
15443 for (InlinedFunctionsIterator it(code, pc); !it.Done(); it.Advance()) { | |
15444 function = it.function(); | |
15445 code = it.code(); | |
15446 ASSERT(function.raw() == code.function()); | |
15447 uword pc = it.pc(); | |
15448 ASSERT(pc != 0); | |
15449 ASSERT(code.EntryPoint() <= pc); | |
15450 ASSERT(pc < (code.EntryPoint() + code.Size())); | |
15451 frame_count++; | |
15452 } | |
15453 } else { | |
15454 frame_count++; | |
15455 } | |
15456 } | |
15457 } | |
15458 return frame_count; | |
15459 } | |
15460 | |
15461 bool Stacktrace::VisibleFrameInfoAt(intptr_t frame_index, | |
15462 String* function_name, | |
15463 String* script_url, | |
15464 intptr_t* line_number, | |
15465 intptr_t* col_num) const { | |
15466 ASSERT(function_name); | |
15467 ASSERT(script_url); | |
15468 ASSERT(line_number); | |
15469 ASSERT(col_num); | |
15470 | |
15471 if (frame_index < 0) { | |
15472 return false; | |
15473 } | |
15474 | |
15475 Isolate* isolate = Isolate::Current(); | |
15476 Function& function = Function::Handle(); | |
15477 Code& code = Code::Handle(); | |
15478 intptr_t frame_count = 0; | |
15479 for (intptr_t i = 0; i < Length(); i++) { | |
15480 function = FunctionAtFrame(i); | |
15481 if (function.IsNull()) { | |
15482 // Check for null function object, which indicates a stack trace overflow. | |
15483 if ((i < (Length() - 1)) && | |
15484 (FunctionAtFrame(i + 1) != Function::null())) { | |
15485 // How to inform API users? | |
rmacnak
2013/10/30 16:52:45
Function named '...' at -1, -1?
siva
2013/10/31 17:13:26
Ditto comment as above, the API implementation sho
| |
15486 } | |
15487 } else if (function.is_visible() || FLAG_verbose_stacktrace) { | |
15488 code = CodeAtFrame(i); | |
15489 ASSERT(function.raw() == code.function()); | |
15490 uword pc = code.EntryPoint() + Smi::Value(PcOffsetAtFrame(i)); | |
15491 if (code.is_optimized() && expand_inlined()) { | |
15492 // Traverse inlined frames. | |
15493 for (InlinedFunctionsIterator it(code, pc); !it.Done(); it.Advance()) { | |
15494 function = it.function(); | |
15495 code = it.code(); | |
15496 ASSERT(function.raw() == code.function()); | |
15497 uword pc = it.pc(); | |
15498 ASSERT(pc != 0); | |
15499 ASSERT(code.EntryPoint() <= pc); | |
15500 ASSERT(pc < (code.EntryPoint() + code.Size())); | |
15501 | |
15502 if (frame_count == frame_index) { | |
15503 *function_name = function.QualifiedUserVisibleName(); | |
rmacnak
2013/10/30 16:52:45
Might allocate.
| |
15504 const Script& script = Script::Handle(isolate, function.script()); | |
15505 *script_url = script.url(); | |
15506 const intptr_t token_pos = code.GetTokenIndexOfPC(pc); | |
15507 if (token_pos >= 0) { | |
15508 if (script.HasSource()) { | |
15509 script.GetTokenLocation(token_pos, line_number, col_num); | |
15510 } else { | |
15511 script.GetTokenLocation(token_pos, line_number, NULL); | |
15512 *col_num = -1; | |
15513 } | |
15514 } | |
15515 return true; | |
15516 } | |
15517 frame_count++; | |
15518 } | |
15519 } else { | |
15520 if (frame_count == frame_index) { | |
15521 *function_name = function.QualifiedUserVisibleName(); | |
rmacnak
2013/10/30 16:52:45
Might allocate.
| |
15522 const Script& script = Script::Handle(isolate, function.script()); | |
15523 *script_url = script.url(); | |
15524 const intptr_t token_pos = code.GetTokenIndexOfPC(pc); | |
15525 if (token_pos >= 0) { | |
15526 if (script.HasSource()) { | |
15527 script.GetTokenLocation(token_pos, line_number, col_num); | |
15528 } else { | |
15529 script.GetTokenLocation(token_pos, line_number, NULL); | |
15530 *col_num = -1; | |
15531 } | |
15532 } | |
15533 return true; | |
15534 } | |
15535 frame_count++; | |
15536 } | |
15537 } | |
15538 } | |
15539 return false; | |
15540 } | |
15541 | |
15424 | 15542 |
15425 void JSRegExp::set_pattern(const String& pattern) const { | 15543 void JSRegExp::set_pattern(const String& pattern) const { |
15426 StorePointer(&raw_ptr()->pattern_, pattern.raw()); | 15544 StorePointer(&raw_ptr()->pattern_, pattern.raw()); |
15427 } | 15545 } |
15428 | 15546 |
15429 | 15547 |
15430 void JSRegExp::set_num_bracket_expressions(intptr_t value) const { | 15548 void JSRegExp::set_num_bracket_expressions(intptr_t value) const { |
15431 raw_ptr()->num_bracket_expressions_ = Smi::New(value); | 15549 raw_ptr()->num_bracket_expressions_ = Smi::New(value); |
15432 } | 15550 } |
15433 | 15551 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
15601 return "_MirrorReference"; | 15719 return "_MirrorReference"; |
15602 } | 15720 } |
15603 | 15721 |
15604 | 15722 |
15605 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 15723 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
15606 JSONObject jsobj(stream); | 15724 JSONObject jsobj(stream); |
15607 } | 15725 } |
15608 | 15726 |
15609 | 15727 |
15610 } // namespace dart | 15728 } // namespace dart |
OLD | NEW |