Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Side by Side Diff: runtime/vm/object.cc

Issue 248213002: Expose functionality to create a stack trace to internal vm code. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 11790 matching lines...) Expand 10 before | Expand all | Expand 10 after
11801 const intptr_t len = NumberOfChecks(); 11801 const intptr_t len = NumberOfChecks();
11802 for (intptr_t i = 1; i < len; i++) { 11802 for (intptr_t i = 1; i < len; i++) {
11803 if (GetTargetAt(i) != first_target.raw()) { 11803 if (GetTargetAt(i) != first_target.raw()) {
11804 return false; 11804 return false;
11805 } 11805 }
11806 } 11806 }
11807 return true; 11807 return true;
11808 } 11808 }
11809 11809
11810 11810
11811 RawICData* ICData::New(const Function& function, 11811 RawICData* ICData::New(const Function& caller_function,
11812 const String& target_name, 11812 const String& target_name,
11813 const Array& arguments_descriptor, 11813 const Array& arguments_descriptor,
11814 intptr_t deopt_id, 11814 intptr_t deopt_id,
11815 intptr_t num_args_tested) { 11815 intptr_t num_args_tested) {
11816 ASSERT(!function.IsNull()); 11816 ASSERT(!caller_function.IsNull());
11817 ASSERT(!target_name.IsNull()); 11817 ASSERT(!target_name.IsNull());
11818 ASSERT(!arguments_descriptor.IsNull()); 11818 ASSERT(!arguments_descriptor.IsNull());
11819 ASSERT(Object::icdata_class() != Class::null()); 11819 ASSERT(Object::icdata_class() != Class::null());
11820 ASSERT(num_args_tested >= 0); 11820 ASSERT(num_args_tested >= 0);
11821 ICData& result = ICData::Handle(); 11821 ICData& result = ICData::Handle();
11822 { 11822 {
11823 // IC data objects are long living objects, allocate them in old generation. 11823 // IC data objects are long living objects, allocate them in old generation.
11824 RawObject* raw = Object::Allocate(ICData::kClassId, 11824 RawObject* raw = Object::Allocate(ICData::kClassId,
11825 ICData::InstanceSize(), 11825 ICData::InstanceSize(),
11826 Heap::kOld); 11826 Heap::kOld);
11827 NoGCScope no_gc; 11827 NoGCScope no_gc;
11828 result ^= raw; 11828 result ^= raw;
11829 } 11829 }
11830 result.set_function(function); 11830 result.set_function(caller_function);
11831 result.set_target_name(target_name); 11831 result.set_target_name(target_name);
11832 result.set_arguments_descriptor(arguments_descriptor); 11832 result.set_arguments_descriptor(arguments_descriptor);
11833 result.set_deopt_id(deopt_id); 11833 result.set_deopt_id(deopt_id);
11834 result.set_num_args_tested(num_args_tested); 11834 result.set_num_args_tested(num_args_tested);
11835 result.set_deopt_reason(kDeoptUnknown); 11835 result.set_deopt_reason(kDeoptUnknown);
11836 result.set_is_closure_call(false); 11836 result.set_is_closure_call(false);
11837 // Number of array elements in one test entry. 11837 // Number of array elements in one test entry.
11838 intptr_t len = result.TestEntryLength(); 11838 intptr_t len = result.TestEntryLength();
11839 // IC data array must be null terminated (sentinel entry). 11839 // IC data array must be null terminated (sentinel entry).
11840 const Array& ic_data = Array::Handle(Array::New(len, Heap::kOld)); 11840 const Array& ic_data = Array::Handle(Array::New(len, Heap::kOld));
(...skipping 6250 matching lines...) Expand 10 before | Expand all | Expand 10 after
18091 chars = isolate->current_zone()->Alloc<char>(len + 1); 18091 chars = isolate->current_zone()->Alloc<char>(len + 1);
18092 OS::SNPrint(chars, (len + 1), kFormatNoCol, 18092 OS::SNPrint(chars, (len + 1), kFormatNoCol,
18093 frame_index, function_name.ToCString(), 18093 frame_index, function_name.ToCString(),
18094 url.ToCString(), line); 18094 url.ToCString(), line);
18095 } 18095 }
18096 frame_strings->Add(chars); 18096 frame_strings->Add(chars);
18097 return len; 18097 return len;
18098 } 18098 }
18099 18099
18100 18100
18101 const char* Stacktrace::ToCStringInternal(intptr_t* frame_index) const { 18101 const char* Stacktrace::ToCStringInternal(intptr_t* frame_index,
18102 intptr_t max_frames) const {
18102 Isolate* isolate = Isolate::Current(); 18103 Isolate* isolate = Isolate::Current();
18103 Function& function = Function::Handle(); 18104 Function& function = Function::Handle();
18104 Code& code = Code::Handle(); 18105 Code& code = Code::Handle();
18105 // Iterate through the stack frames and create C string description 18106 // Iterate through the stack frames and create C string description
18106 // for each frame. 18107 // for each frame.
18107 intptr_t total_len = 0; 18108 intptr_t total_len = 0;
18108 GrowableArray<char*> frame_strings; 18109 GrowableArray<char*> frame_strings;
18109 for (intptr_t i = 0; i < Length(); i++) { 18110 for (intptr_t i = 0; (i < Length()) && (*frame_index < max_frames); i++) {
18110 function = FunctionAtFrame(i); 18111 function = FunctionAtFrame(i);
18111 if (function.IsNull()) { 18112 if (function.IsNull()) {
18112 // Check if null function object indicates a stack trace overflow. 18113 // Check if null function object indicates a stack trace overflow.
18113 if ((i < (Length() - 1)) && 18114 if ((i < (Length() - 1)) &&
18114 (FunctionAtFrame(i + 1) != Function::null())) { 18115 (FunctionAtFrame(i + 1) != Function::null())) {
18115 const char* kTruncated = "...\n...\n"; 18116 const char* kTruncated = "...\n...\n";
18116 intptr_t truncated_len = strlen(kTruncated) + 1; 18117 intptr_t truncated_len = strlen(kTruncated) + 1;
18117 char* chars = isolate->current_zone()->Alloc<char>(truncated_len); 18118 char* chars = isolate->current_zone()->Alloc<char>(truncated_len);
18118 OS::SNPrint(chars, truncated_len, "%s", kTruncated); 18119 OS::SNPrint(chars, truncated_len, "%s", kTruncated);
18119 frame_strings.Add(chars); 18120 frame_strings.Add(chars);
18120 } 18121 }
18121 } else if (function.is_visible() || FLAG_verbose_stacktrace) { 18122 } else if (function.is_visible() || FLAG_verbose_stacktrace) {
18122 code = CodeAtFrame(i); 18123 code = CodeAtFrame(i);
18123 ASSERT(function.raw() == code.function()); 18124 ASSERT(function.raw() == code.function());
18124 uword pc = code.EntryPoint() + Smi::Value(PcOffsetAtFrame(i)); 18125 uword pc = code.EntryPoint() + Smi::Value(PcOffsetAtFrame(i));
18125 if (code.is_optimized() && expand_inlined()) { 18126 if (code.is_optimized() && expand_inlined()) {
18126 // Traverse inlined frames. 18127 // Traverse inlined frames.
18127 for (InlinedFunctionsIterator it(code, pc); !it.Done(); it.Advance()) { 18128 for (InlinedFunctionsIterator it(code, pc);
18129 !it.Done() && (*frame_index < max_frames); it.Advance()) {
18128 function = it.function(); 18130 function = it.function();
18129 if (function.is_visible() || FLAG_verbose_stacktrace) { 18131 if (function.is_visible() || FLAG_verbose_stacktrace) {
18130 code = it.code(); 18132 code = it.code();
18131 ASSERT(function.raw() == code.function()); 18133 ASSERT(function.raw() == code.function());
18132 uword pc = it.pc(); 18134 uword pc = it.pc();
18133 ASSERT(pc != 0); 18135 ASSERT(pc != 0);
18134 ASSERT(code.EntryPoint() <= pc); 18136 ASSERT(code.EntryPoint() <= pc);
18135 ASSERT(pc < (code.EntryPoint() + code.Size())); 18137 ASSERT(pc < (code.EntryPoint() + code.Size()));
18136 total_len += PrintOneStacktrace( 18138 total_len += PrintOneStacktrace(
18137 isolate, &frame_strings, pc, function, code, *frame_index); 18139 isolate, &frame_strings, pc, function, code, *frame_index);
18140 (*frame_index)++; // To account for inlined frames.
18138 } 18141 }
18139 (*frame_index)++; // To account for inlined frames.
18140 } 18142 }
18141 } else { 18143 } else {
18142 total_len += PrintOneStacktrace( 18144 total_len += PrintOneStacktrace(
18143 isolate, &frame_strings, pc, function, code, *frame_index); 18145 isolate, &frame_strings, pc, function, code, *frame_index);
18144 (*frame_index)++; 18146 (*frame_index)++;
18145 } 18147 }
18146 } 18148 }
18147 } 18149 }
18148 18150
18149 // Now concatenate the frame descriptions into a single C string. 18151 // Now concatenate the frame descriptions into a single C string.
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
18464 return tag_label.ToCString(); 18466 return tag_label.ToCString();
18465 } 18467 }
18466 18468
18467 18469
18468 void UserTag::PrintToJSONStream(JSONStream* stream, bool ref) const { 18470 void UserTag::PrintToJSONStream(JSONStream* stream, bool ref) const {
18469 Instance::PrintToJSONStream(stream, ref); 18471 Instance::PrintToJSONStream(stream, ref);
18470 } 18472 }
18471 18473
18472 18474
18473 } // namespace dart 18475 } // namespace dart
OLDNEW
« runtime/vm/flow_graph_builder.h ('K') | « runtime/vm/object.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698