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/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
(...skipping 12752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12763 return code_array.Length(); | 12763 return code_array.Length(); |
12764 } | 12764 } |
12765 | 12765 |
12766 | 12766 |
12767 RawFunction* Stacktrace::FunctionAtFrame(intptr_t frame_index) const { | 12767 RawFunction* Stacktrace::FunctionAtFrame(intptr_t frame_index) const { |
12768 const Array& function_array = Array::Handle(raw_ptr()->function_array_); | 12768 const Array& function_array = Array::Handle(raw_ptr()->function_array_); |
12769 return reinterpret_cast<RawFunction*>(function_array.At(frame_index)); | 12769 return reinterpret_cast<RawFunction*>(function_array.At(frame_index)); |
12770 } | 12770 } |
12771 | 12771 |
12772 | 12772 |
| 12773 void Stacktrace::SetFunctionAtFrame(intptr_t frame_index, |
| 12774 const Function& func) const { |
| 12775 const Array& function_array = Array::Handle(raw_ptr()->function_array_); |
| 12776 function_array.SetAt(frame_index, func); |
| 12777 } |
| 12778 |
| 12779 |
12773 RawCode* Stacktrace::CodeAtFrame(intptr_t frame_index) const { | 12780 RawCode* Stacktrace::CodeAtFrame(intptr_t frame_index) const { |
12774 const Array& code_array = Array::Handle(raw_ptr()->code_array_); | 12781 const Array& code_array = Array::Handle(raw_ptr()->code_array_); |
12775 return reinterpret_cast<RawCode*>(code_array.At(frame_index)); | 12782 return reinterpret_cast<RawCode*>(code_array.At(frame_index)); |
12776 } | 12783 } |
12777 | 12784 |
12778 | 12785 |
| 12786 void Stacktrace::SetCodeAtFrame(intptr_t frame_index, |
| 12787 const Code& code) const { |
| 12788 const Array& code_array = Array::Handle(raw_ptr()->code_array_); |
| 12789 code_array.SetAt(frame_index, code); |
| 12790 } |
| 12791 |
| 12792 |
12779 RawSmi* Stacktrace::PcOffsetAtFrame(intptr_t frame_index) const { | 12793 RawSmi* Stacktrace::PcOffsetAtFrame(intptr_t frame_index) const { |
12780 const Array& pc_offset_array = Array::Handle(raw_ptr()->pc_offset_array_); | 12794 const Array& pc_offset_array = Array::Handle(raw_ptr()->pc_offset_array_); |
12781 return reinterpret_cast<RawSmi*>(pc_offset_array.At(frame_index)); | 12795 return reinterpret_cast<RawSmi*>(pc_offset_array.At(frame_index)); |
12782 } | 12796 } |
12783 | 12797 |
12784 | 12798 |
| 12799 void Stacktrace::SetPcOffsetAtFrame(intptr_t frame_index, |
| 12800 const Smi& pc_offset) const { |
| 12801 const Array& pc_offset_array = Array::Handle(raw_ptr()->pc_offset_array_); |
| 12802 pc_offset_array.SetAt(frame_index, pc_offset); |
| 12803 } |
| 12804 |
| 12805 |
12785 void Stacktrace::set_function_array(const Array& function_array) const { | 12806 void Stacktrace::set_function_array(const Array& function_array) const { |
12786 StorePointer(&raw_ptr()->function_array_, function_array.raw()); | 12807 StorePointer(&raw_ptr()->function_array_, function_array.raw()); |
12787 } | 12808 } |
12788 | 12809 |
12789 | 12810 |
12790 void Stacktrace::set_code_array(const Array& code_array) const { | 12811 void Stacktrace::set_code_array(const Array& code_array) const { |
12791 StorePointer(&raw_ptr()->code_array_, code_array.raw()); | 12812 StorePointer(&raw_ptr()->code_array_, code_array.raw()); |
12792 } | 12813 } |
12793 | 12814 |
12794 | 12815 |
12795 void Stacktrace::set_pc_offset_array(const Array& pc_offset_array) const { | 12816 void Stacktrace::set_pc_offset_array(const Array& pc_offset_array) const { |
12796 StorePointer(&raw_ptr()->pc_offset_array_, pc_offset_array.raw()); | 12817 StorePointer(&raw_ptr()->pc_offset_array_, pc_offset_array.raw()); |
12797 } | 12818 } |
12798 | 12819 |
12799 | 12820 |
12800 RawStacktrace* Stacktrace::New(const GrowableObjectArray& func_list, | 12821 RawStacktrace* Stacktrace::New(const Array& func_array, |
12801 const GrowableObjectArray& code_list, | 12822 const Array& code_array, |
12802 const GrowableObjectArray& pc_offset_list, | 12823 const Array& pc_offset_array, |
12803 Heap::Space space) { | 12824 Heap::Space space) { |
12804 ASSERT(Isolate::Current()->object_store()->stacktrace_class() != | 12825 ASSERT(Isolate::Current()->object_store()->stacktrace_class() != |
12805 Class::null()); | 12826 Class::null()); |
12806 Stacktrace& result = Stacktrace::Handle(); | 12827 Stacktrace& result = Stacktrace::Handle(); |
12807 { | 12828 { |
12808 RawObject* raw = Object::Allocate(Stacktrace::kClassId, | 12829 RawObject* raw = Object::Allocate(Stacktrace::kClassId, |
12809 Stacktrace::InstanceSize(), | 12830 Stacktrace::InstanceSize(), |
12810 space); | 12831 space); |
12811 NoGCScope no_gc; | 12832 NoGCScope no_gc; |
12812 result ^= raw; | 12833 result ^= raw; |
12813 } | 12834 } |
12814 // Create arrays for the function, code and pc_offset triplet for each frame. | 12835 result.set_function_array(func_array); |
12815 const Array& function_array = Array::Handle(Array::MakeArray(func_list)); | |
12816 const Array& code_array = Array::Handle(Array::MakeArray(code_list)); | |
12817 const Array& pc_offset_array = | |
12818 Array::Handle(Array::MakeArray(pc_offset_list)); | |
12819 result.set_function_array(function_array); | |
12820 result.set_code_array(code_array); | 12836 result.set_code_array(code_array); |
12821 result.set_pc_offset_array(pc_offset_array); | 12837 result.set_pc_offset_array(pc_offset_array); |
12822 return result.raw(); | 12838 return result.raw(); |
12823 } | 12839 } |
12824 | 12840 |
12825 | 12841 |
12826 void Stacktrace::Append(const GrowableObjectArray& func_list, | 12842 void Stacktrace::Append(const Array& func_list, |
12827 const GrowableObjectArray& code_list, | 12843 const Array& code_list, |
12828 const GrowableObjectArray& pc_offset_list) const { | 12844 const Array& pc_offset_list) const { |
12829 intptr_t old_length = Length(); | 12845 intptr_t old_length = Length(); |
12830 intptr_t new_length = old_length + pc_offset_list.Length(); | 12846 intptr_t new_length = old_length + pc_offset_list.Length(); |
12831 ASSERT(pc_offset_list.Length() == func_list.Length()); | 12847 ASSERT(pc_offset_list.Length() == func_list.Length()); |
12832 ASSERT(pc_offset_list.Length() == code_list.Length()); | 12848 ASSERT(pc_offset_list.Length() == code_list.Length()); |
12833 | 12849 |
12834 // Grow the arrays for function, code and pc_offset triplet to accommodate | 12850 // Grow the arrays for function, code and pc_offset triplet to accommodate |
12835 // the new stack frames. | 12851 // the new stack frames. |
12836 Array& function_array = Array::Handle(raw_ptr()->function_array_); | 12852 Array& function_array = Array::Handle(raw_ptr()->function_array_); |
12837 Array& code_array = Array::Handle(raw_ptr()->code_array_); | 12853 Array& code_array = Array::Handle(raw_ptr()->code_array_); |
12838 Array& pc_offset_array = Array::Handle(raw_ptr()->pc_offset_array_); | 12854 Array& pc_offset_array = Array::Handle(raw_ptr()->pc_offset_array_); |
(...skipping 11 matching lines...) Expand all Loading... |
12850 function_array.SetAt(i, obj); | 12866 function_array.SetAt(i, obj); |
12851 obj = code_list.At(j); | 12867 obj = code_list.At(j); |
12852 code_array.SetAt(i, obj); | 12868 code_array.SetAt(i, obj); |
12853 obj = pc_offset_list.At(j); | 12869 obj = pc_offset_list.At(j); |
12854 pc_offset_array.SetAt(i, obj); | 12870 pc_offset_array.SetAt(i, obj); |
12855 } | 12871 } |
12856 } | 12872 } |
12857 | 12873 |
12858 | 12874 |
12859 const char* Stacktrace::ToCString() const { | 12875 const char* Stacktrace::ToCString() const { |
| 12876 Isolate* isolate = Isolate::Current(); |
12860 Function& function = Function::Handle(); | 12877 Function& function = Function::Handle(); |
12861 Code& code = Code::Handle(); | 12878 Code& code = Code::Handle(); |
12862 Script& script = Script::Handle(); | 12879 Script& script = Script::Handle(); |
12863 String& function_name = String::Handle(); | 12880 String& function_name = String::Handle(); |
12864 String& url = String::Handle(); | 12881 String& url = String::Handle(); |
12865 | 12882 |
12866 // Iterate through the stack frames and create C string description | 12883 // Iterate through the stack frames and create C string description |
12867 // for each frame. | 12884 // for each frame. |
12868 intptr_t total_len = 0; | 12885 intptr_t total_len = 0; |
12869 const char* kFormat = "#%-6d %s (%s:%d:%d)\n"; | 12886 const char* kFormat = "#%-6d %s (%s:%d:%d)\n"; |
12870 GrowableArray<char*> frame_strings; | 12887 GrowableArray<char*> frame_strings; |
| 12888 char* chars; |
12871 for (intptr_t i = 0; i < Length(); i++) { | 12889 for (intptr_t i = 0; i < Length(); i++) { |
12872 function = FunctionAtFrame(i); | 12890 function = FunctionAtFrame(i); |
| 12891 if (function.IsNull()) { |
| 12892 // Check if null function object indicates a stack trace overflow. |
| 12893 if ((i < (Length() - 1)) && |
| 12894 (FunctionAtFrame(i + 1) != Function::null())) { |
| 12895 const char* kTruncated = "...\n...\n"; |
| 12896 intptr_t truncated_len = strlen(kTruncated) + 1; |
| 12897 chars = isolate->current_zone()->Alloc<char>(truncated_len); |
| 12898 OS::SNPrint(chars, truncated_len, "%s", kTruncated); |
| 12899 frame_strings.Add(chars); |
| 12900 } |
| 12901 continue; |
| 12902 } |
12873 code = CodeAtFrame(i); | 12903 code = CodeAtFrame(i); |
12874 uword pc = code.EntryPoint() + Smi::Value(PcOffsetAtFrame(i)); | 12904 uword pc = code.EntryPoint() + Smi::Value(PcOffsetAtFrame(i)); |
12875 intptr_t token_pos = code.GetTokenIndexOfPC(pc); | 12905 intptr_t token_pos = code.GetTokenIndexOfPC(pc); |
12876 script = function.script(); | 12906 script = function.script(); |
12877 function_name = function.QualifiedUserVisibleName(); | 12907 function_name = function.QualifiedUserVisibleName(); |
12878 url = script.url(); | 12908 url = script.url(); |
12879 intptr_t line = -1; | 12909 intptr_t line = -1; |
12880 intptr_t column = -1; | 12910 intptr_t column = -1; |
12881 if (token_pos >= 0) { | 12911 if (token_pos >= 0) { |
12882 script.GetTokenLocation(token_pos, &line, &column); | 12912 script.GetTokenLocation(token_pos, &line, &column); |
12883 } | 12913 } |
12884 intptr_t len = OS::SNPrint(NULL, 0, kFormat, | 12914 intptr_t len = OS::SNPrint(NULL, 0, kFormat, |
12885 i, | 12915 i, |
12886 function_name.ToCString(), | 12916 function_name.ToCString(), |
12887 url.ToCString(), | 12917 url.ToCString(), |
12888 line, column); | 12918 line, column); |
12889 total_len += len; | 12919 total_len += len; |
12890 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1); | 12920 chars = isolate->current_zone()->Alloc<char>(len + 1); |
12891 OS::SNPrint(chars, (len + 1), kFormat, | 12921 OS::SNPrint(chars, (len + 1), kFormat, |
12892 i, | 12922 i, |
12893 function_name.ToCString(), | 12923 function_name.ToCString(), |
12894 url.ToCString(), | 12924 url.ToCString(), |
12895 line, column); | 12925 line, column); |
12896 frame_strings.Add(chars); | 12926 frame_strings.Add(chars); |
12897 } | 12927 } |
12898 | 12928 |
12899 // Now concatentate the frame descriptions into a single C string. | 12929 // Now concatentate the frame descriptions into a single C string. |
12900 char* chars = Isolate::Current()->current_zone()->Alloc<char>(total_len + 1); | 12930 chars = isolate->current_zone()->Alloc<char>(total_len + 1); |
12901 intptr_t index = 0; | 12931 intptr_t index = 0; |
12902 for (intptr_t i = 0; i < frame_strings.length(); i++) { | 12932 for (intptr_t i = 0; i < frame_strings.length(); i++) { |
12903 index += OS::SNPrint((chars + index), | 12933 index += OS::SNPrint((chars + index), |
12904 (total_len + 1 - index), | 12934 (total_len + 1 - index), |
12905 "%s", | 12935 "%s", |
12906 frame_strings[i]); | 12936 frame_strings[i]); |
12907 } | 12937 } |
12908 return chars; | 12938 return chars; |
12909 } | 12939 } |
12910 | 12940 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13020 } | 13050 } |
13021 return result.raw(); | 13051 return result.raw(); |
13022 } | 13052 } |
13023 | 13053 |
13024 | 13054 |
13025 const char* WeakProperty::ToCString() const { | 13055 const char* WeakProperty::ToCString() const { |
13026 return "_WeakProperty"; | 13056 return "_WeakProperty"; |
13027 } | 13057 } |
13028 | 13058 |
13029 } // namespace dart | 13059 } // namespace dart |
OLD | NEW |