| 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 15227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15238 | 15238 |
| 15239 void Stacktrace::SetCatchStacktrace(const Array& code_array, | 15239 void Stacktrace::SetCatchStacktrace(const Array& code_array, |
| 15240 const Array& pc_offset_array) const { | 15240 const Array& pc_offset_array) const { |
| 15241 StorePointer(&raw_ptr()->catch_code_array_, code_array.raw()); | 15241 StorePointer(&raw_ptr()->catch_code_array_, code_array.raw()); |
| 15242 StorePointer(&raw_ptr()->catch_pc_offset_array_, pc_offset_array.raw()); | 15242 StorePointer(&raw_ptr()->catch_pc_offset_array_, pc_offset_array.raw()); |
| 15243 } | 15243 } |
| 15244 | 15244 |
| 15245 | 15245 |
| 15246 RawString* Stacktrace::FullStacktrace() const { | 15246 RawString* Stacktrace::FullStacktrace() const { |
| 15247 const Array& code_array = Array::Handle(raw_ptr()->catch_code_array_); | 15247 const Array& code_array = Array::Handle(raw_ptr()->catch_code_array_); |
| 15248 intptr_t idx = 0; |
| 15248 if (!code_array.IsNull() && (code_array.Length() > 0)) { | 15249 if (!code_array.IsNull() && (code_array.Length() > 0)) { |
| 15249 const Array& pc_offset_array = | 15250 const Array& pc_offset_array = |
| 15250 Array::Handle(raw_ptr()->catch_pc_offset_array_); | 15251 Array::Handle(raw_ptr()->catch_pc_offset_array_); |
| 15251 const Stacktrace& catch_trace = Stacktrace::Handle( | 15252 const Stacktrace& catch_trace = Stacktrace::Handle( |
| 15252 Stacktrace::New(code_array, pc_offset_array)); | 15253 Stacktrace::New(code_array, pc_offset_array)); |
| 15253 intptr_t idx = Length(); | 15254 const String& throw_string = |
| 15254 const String& trace = | 15255 String::Handle(String::New(ToCStringInternal(&idx))); |
| 15255 String::Handle(String::New(catch_trace.ToCStringInternal(idx))); | 15256 const String& catch_string = |
| 15256 const String& throw_trace = | 15257 String::Handle(String::New(catch_trace.ToCStringInternal(&idx))); |
| 15257 String::Handle(String::New(ToCStringInternal(0))); | 15258 return String::Concat(throw_string, catch_string); |
| 15258 return String::Concat(throw_trace, trace); | |
| 15259 } | 15259 } |
| 15260 return String::New(ToCStringInternal(0)); | 15260 return String::New(ToCStringInternal(&idx)); |
| 15261 } | 15261 } |
| 15262 | 15262 |
| 15263 | 15263 |
| 15264 const char* Stacktrace::ToCString() const { | 15264 const char* Stacktrace::ToCString() const { |
| 15265 const String& trace = String::Handle(FullStacktrace()); | 15265 const String& trace = String::Handle(FullStacktrace()); |
| 15266 return trace.ToCString(); | 15266 return trace.ToCString(); |
| 15267 } | 15267 } |
| 15268 | 15268 |
| 15269 | 15269 |
| 15270 void Stacktrace::PrintToJSONStream(JSONStream* stream, bool ref) const { | 15270 void Stacktrace::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15312 chars = isolate->current_zone()->Alloc<char>(len + 1); | 15312 chars = isolate->current_zone()->Alloc<char>(len + 1); |
| 15313 OS::SNPrint(chars, (len + 1), kFormatNoCol, | 15313 OS::SNPrint(chars, (len + 1), kFormatNoCol, |
| 15314 frame_index, function_name.ToCString(), | 15314 frame_index, function_name.ToCString(), |
| 15315 url.ToCString(), line); | 15315 url.ToCString(), line); |
| 15316 } | 15316 } |
| 15317 frame_strings->Add(chars); | 15317 frame_strings->Add(chars); |
| 15318 return len; | 15318 return len; |
| 15319 } | 15319 } |
| 15320 | 15320 |
| 15321 | 15321 |
| 15322 const char* Stacktrace::ToCStringInternal(intptr_t frame_index) const { | 15322 const char* Stacktrace::ToCStringInternal(intptr_t* frame_index) const { |
| 15323 Isolate* isolate = Isolate::Current(); | 15323 Isolate* isolate = Isolate::Current(); |
| 15324 Function& function = Function::Handle(); | 15324 Function& function = Function::Handle(); |
| 15325 Code& code = Code::Handle(); | 15325 Code& code = Code::Handle(); |
| 15326 // Iterate through the stack frames and create C string description | 15326 // Iterate through the stack frames and create C string description |
| 15327 // for each frame. | 15327 // for each frame. |
| 15328 intptr_t total_len = 0; | 15328 intptr_t total_len = 0; |
| 15329 GrowableArray<char*> frame_strings; | 15329 GrowableArray<char*> frame_strings; |
| 15330 intptr_t current_frame_index = frame_index; | |
| 15331 for (intptr_t i = 0; i < Length(); i++) { | 15330 for (intptr_t i = 0; i < Length(); i++) { |
| 15332 function = FunctionAtFrame(i); | 15331 function = FunctionAtFrame(i); |
| 15333 if (function.IsNull()) { | 15332 if (function.IsNull()) { |
| 15334 // Check if null function object indicates a stack trace overflow. | 15333 // Check if null function object indicates a stack trace overflow. |
| 15335 if ((i < (Length() - 1)) && | 15334 if ((i < (Length() - 1)) && |
| 15336 (FunctionAtFrame(i + 1) != Function::null())) { | 15335 (FunctionAtFrame(i + 1) != Function::null())) { |
| 15337 const char* kTruncated = "...\n...\n"; | 15336 const char* kTruncated = "...\n...\n"; |
| 15338 intptr_t truncated_len = strlen(kTruncated) + 1; | 15337 intptr_t truncated_len = strlen(kTruncated) + 1; |
| 15339 char* chars = isolate->current_zone()->Alloc<char>(truncated_len); | 15338 char* chars = isolate->current_zone()->Alloc<char>(truncated_len); |
| 15340 OS::SNPrint(chars, truncated_len, "%s", kTruncated); | 15339 OS::SNPrint(chars, truncated_len, "%s", kTruncated); |
| 15341 frame_strings.Add(chars); | 15340 frame_strings.Add(chars); |
| 15342 } | 15341 } |
| 15343 } else if (function.is_visible() || FLAG_verbose_stacktrace) { | 15342 } else if (function.is_visible() || FLAG_verbose_stacktrace) { |
| 15344 code = CodeAtFrame(i); | 15343 code = CodeAtFrame(i); |
| 15345 ASSERT(function.raw() == code.function()); | 15344 ASSERT(function.raw() == code.function()); |
| 15346 uword pc = code.EntryPoint() + Smi::Value(PcOffsetAtFrame(i)); | 15345 uword pc = code.EntryPoint() + Smi::Value(PcOffsetAtFrame(i)); |
| 15347 if (code.is_optimized() && expand_inlined()) { | 15346 if (code.is_optimized() && expand_inlined()) { |
| 15348 // Traverse inlined frames. | 15347 // Traverse inlined frames. |
| 15349 for (InlinedFunctionsIterator it(code, pc); !it.Done(); it.Advance()) { | 15348 for (InlinedFunctionsIterator it(code, pc); !it.Done(); it.Advance()) { |
| 15350 function = it.function(); | 15349 function = it.function(); |
| 15351 code = it.code(); | 15350 code = it.code(); |
| 15352 ASSERT(function.raw() == code.function()); | 15351 ASSERT(function.raw() == code.function()); |
| 15353 uword pc = it.pc(); | 15352 uword pc = it.pc(); |
| 15354 ASSERT(pc != 0); | 15353 ASSERT(pc != 0); |
| 15355 ASSERT(code.EntryPoint() <= pc); | 15354 ASSERT(code.EntryPoint() <= pc); |
| 15356 ASSERT(pc < (code.EntryPoint() + code.Size())); | 15355 ASSERT(pc < (code.EntryPoint() + code.Size())); |
| 15357 total_len += PrintOneStacktrace( | 15356 total_len += PrintOneStacktrace( |
| 15358 isolate, &frame_strings, pc, function, code, current_frame_index); | 15357 isolate, &frame_strings, pc, function, code, *frame_index); |
| 15359 current_frame_index++; // To account for inlined frames. | 15358 (*frame_index)++; // To account for inlined frames. |
| 15360 } | 15359 } |
| 15361 } else { | 15360 } else { |
| 15362 total_len += PrintOneStacktrace( | 15361 total_len += PrintOneStacktrace( |
| 15363 isolate, &frame_strings, pc, function, code, current_frame_index); | 15362 isolate, &frame_strings, pc, function, code, *frame_index); |
| 15364 current_frame_index++; | 15363 (*frame_index)++; |
| 15365 } | 15364 } |
| 15366 } | 15365 } |
| 15367 } | 15366 } |
| 15368 | 15367 |
| 15369 // Now concatenate the frame descriptions into a single C string. | 15368 // Now concatenate the frame descriptions into a single C string. |
| 15370 char* chars = isolate->current_zone()->Alloc<char>(total_len + 1); | 15369 char* chars = isolate->current_zone()->Alloc<char>(total_len + 1); |
| 15371 intptr_t index = 0; | 15370 intptr_t index = 0; |
| 15372 for (intptr_t i = 0; i < frame_strings.length(); i++) { | 15371 for (intptr_t i = 0; i < frame_strings.length(); i++) { |
| 15373 index += OS::SNPrint((chars + index), | 15372 index += OS::SNPrint((chars + index), |
| 15374 (total_len + 1 - index), | 15373 (total_len + 1 - index), |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15559 return "_MirrorReference"; | 15558 return "_MirrorReference"; |
| 15560 } | 15559 } |
| 15561 | 15560 |
| 15562 | 15561 |
| 15563 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 15562 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 15564 JSONObject jsobj(stream); | 15563 JSONObject jsobj(stream); |
| 15565 } | 15564 } |
| 15566 | 15565 |
| 15567 | 15566 |
| 15568 } // namespace dart | 15567 } // namespace dart |
| OLD | NEW |