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 12805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12816 return code_array.Length(); | 12816 return code_array.Length(); |
12817 } | 12817 } |
12818 | 12818 |
12819 | 12819 |
12820 RawFunction* Stacktrace::FunctionAtFrame(intptr_t frame_index) const { | 12820 RawFunction* Stacktrace::FunctionAtFrame(intptr_t frame_index) const { |
12821 const Array& function_array = Array::Handle(raw_ptr()->function_array_); | 12821 const Array& function_array = Array::Handle(raw_ptr()->function_array_); |
12822 return reinterpret_cast<RawFunction*>(function_array.At(frame_index)); | 12822 return reinterpret_cast<RawFunction*>(function_array.At(frame_index)); |
12823 } | 12823 } |
12824 | 12824 |
12825 | 12825 |
12826 void Stacktrace::SetFunctionAtFrame(intptr_t frame_index, | |
12827 const Function& func) const { | |
12828 const Array& function_array = Array::Handle(raw_ptr()->function_array_); | |
12829 function_array.SetAt(frame_index, func); | |
12830 } | |
12831 | |
12832 | |
12833 RawCode* Stacktrace::CodeAtFrame(intptr_t frame_index) const { | 12826 RawCode* Stacktrace::CodeAtFrame(intptr_t frame_index) const { |
12834 const Array& code_array = Array::Handle(raw_ptr()->code_array_); | 12827 const Array& code_array = Array::Handle(raw_ptr()->code_array_); |
12835 return reinterpret_cast<RawCode*>(code_array.At(frame_index)); | 12828 return reinterpret_cast<RawCode*>(code_array.At(frame_index)); |
12836 } | 12829 } |
12837 | 12830 |
12838 | 12831 |
12839 void Stacktrace::SetCodeAtFrame(intptr_t frame_index, | |
12840 const Code& code) const { | |
12841 const Array& code_array = Array::Handle(raw_ptr()->code_array_); | |
12842 code_array.SetAt(frame_index, code); | |
12843 } | |
12844 | |
12845 | |
12846 RawSmi* Stacktrace::PcOffsetAtFrame(intptr_t frame_index) const { | 12832 RawSmi* Stacktrace::PcOffsetAtFrame(intptr_t frame_index) const { |
12847 const Array& pc_offset_array = Array::Handle(raw_ptr()->pc_offset_array_); | 12833 const Array& pc_offset_array = Array::Handle(raw_ptr()->pc_offset_array_); |
12848 return reinterpret_cast<RawSmi*>(pc_offset_array.At(frame_index)); | 12834 return reinterpret_cast<RawSmi*>(pc_offset_array.At(frame_index)); |
12849 } | 12835 } |
12850 | 12836 |
12851 | 12837 |
12852 void Stacktrace::SetPcOffsetAtFrame(intptr_t frame_index, | |
12853 const Smi& pc_offset) const { | |
12854 const Array& pc_offset_array = Array::Handle(raw_ptr()->pc_offset_array_); | |
12855 pc_offset_array.SetAt(frame_index, pc_offset); | |
12856 } | |
12857 | |
12858 | |
12859 void Stacktrace::set_function_array(const Array& function_array) const { | 12838 void Stacktrace::set_function_array(const Array& function_array) const { |
12860 StorePointer(&raw_ptr()->function_array_, function_array.raw()); | 12839 StorePointer(&raw_ptr()->function_array_, function_array.raw()); |
12861 } | 12840 } |
12862 | 12841 |
12863 | 12842 |
12864 void Stacktrace::set_code_array(const Array& code_array) const { | 12843 void Stacktrace::set_code_array(const Array& code_array) const { |
12865 StorePointer(&raw_ptr()->code_array_, code_array.raw()); | 12844 StorePointer(&raw_ptr()->code_array_, code_array.raw()); |
12866 } | 12845 } |
12867 | 12846 |
12868 | 12847 |
12869 void Stacktrace::set_pc_offset_array(const Array& pc_offset_array) const { | 12848 void Stacktrace::set_pc_offset_array(const Array& pc_offset_array) const { |
12870 StorePointer(&raw_ptr()->pc_offset_array_, pc_offset_array.raw()); | 12849 StorePointer(&raw_ptr()->pc_offset_array_, pc_offset_array.raw()); |
12871 } | 12850 } |
12872 | 12851 |
12873 | 12852 |
12874 RawStacktrace* Stacktrace::New(const Array& func_array, | 12853 RawStacktrace* Stacktrace::New(const GrowableObjectArray& func_list, |
12875 const Array& code_array, | 12854 const GrowableObjectArray& code_list, |
12876 const Array& pc_offset_array, | 12855 const GrowableObjectArray& pc_offset_list, |
12877 Heap::Space space) { | 12856 Heap::Space space) { |
12878 ASSERT(Isolate::Current()->object_store()->stacktrace_class() != | 12857 ASSERT(Isolate::Current()->object_store()->stacktrace_class() != |
12879 Class::null()); | 12858 Class::null()); |
12880 Stacktrace& result = Stacktrace::Handle(); | 12859 Stacktrace& result = Stacktrace::Handle(); |
12881 { | 12860 { |
12882 RawObject* raw = Object::Allocate(Stacktrace::kClassId, | 12861 RawObject* raw = Object::Allocate(Stacktrace::kClassId, |
12883 Stacktrace::InstanceSize(), | 12862 Stacktrace::InstanceSize(), |
12884 space); | 12863 space); |
12885 NoGCScope no_gc; | 12864 NoGCScope no_gc; |
12886 result ^= raw; | 12865 result ^= raw; |
12887 } | 12866 } |
12888 result.set_function_array(func_array); | 12867 // Create arrays for the function, code and pc_offset triplet for each frame. |
| 12868 const Array& function_array = Array::Handle(Array::MakeArray(func_list)); |
| 12869 const Array& code_array = Array::Handle(Array::MakeArray(code_list)); |
| 12870 const Array& pc_offset_array = |
| 12871 Array::Handle(Array::MakeArray(pc_offset_list)); |
| 12872 result.set_function_array(function_array); |
12889 result.set_code_array(code_array); | 12873 result.set_code_array(code_array); |
12890 result.set_pc_offset_array(pc_offset_array); | 12874 result.set_pc_offset_array(pc_offset_array); |
12891 return result.raw(); | 12875 return result.raw(); |
12892 } | 12876 } |
12893 | 12877 |
12894 | 12878 |
12895 void Stacktrace::Append(const Array& func_list, | 12879 void Stacktrace::Append(const GrowableObjectArray& func_list, |
12896 const Array& code_list, | 12880 const GrowableObjectArray& code_list, |
12897 const Array& pc_offset_list) const { | 12881 const GrowableObjectArray& pc_offset_list) const { |
12898 intptr_t old_length = Length(); | 12882 intptr_t old_length = Length(); |
12899 intptr_t new_length = old_length + pc_offset_list.Length(); | 12883 intptr_t new_length = old_length + pc_offset_list.Length(); |
12900 ASSERT(pc_offset_list.Length() == func_list.Length()); | 12884 ASSERT(pc_offset_list.Length() == func_list.Length()); |
12901 ASSERT(pc_offset_list.Length() == code_list.Length()); | 12885 ASSERT(pc_offset_list.Length() == code_list.Length()); |
12902 | 12886 |
12903 // Grow the arrays for function, code and pc_offset triplet to accommodate | 12887 // Grow the arrays for function, code and pc_offset triplet to accommodate |
12904 // the new stack frames. | 12888 // the new stack frames. |
12905 Array& function_array = Array::Handle(raw_ptr()->function_array_); | 12889 Array& function_array = Array::Handle(raw_ptr()->function_array_); |
12906 Array& code_array = Array::Handle(raw_ptr()->code_array_); | 12890 Array& code_array = Array::Handle(raw_ptr()->code_array_); |
12907 Array& pc_offset_array = Array::Handle(raw_ptr()->pc_offset_array_); | 12891 Array& pc_offset_array = Array::Handle(raw_ptr()->pc_offset_array_); |
(...skipping 11 matching lines...) Expand all Loading... |
12919 function_array.SetAt(i, obj); | 12903 function_array.SetAt(i, obj); |
12920 obj = code_list.At(j); | 12904 obj = code_list.At(j); |
12921 code_array.SetAt(i, obj); | 12905 code_array.SetAt(i, obj); |
12922 obj = pc_offset_list.At(j); | 12906 obj = pc_offset_list.At(j); |
12923 pc_offset_array.SetAt(i, obj); | 12907 pc_offset_array.SetAt(i, obj); |
12924 } | 12908 } |
12925 } | 12909 } |
12926 | 12910 |
12927 | 12911 |
12928 const char* Stacktrace::ToCString() const { | 12912 const char* Stacktrace::ToCString() const { |
12929 Isolate* isolate = Isolate::Current(); | |
12930 Function& function = Function::Handle(); | 12913 Function& function = Function::Handle(); |
12931 Code& code = Code::Handle(); | 12914 Code& code = Code::Handle(); |
12932 Script& script = Script::Handle(); | 12915 Script& script = Script::Handle(); |
12933 String& function_name = String::Handle(); | 12916 String& function_name = String::Handle(); |
12934 String& url = String::Handle(); | 12917 String& url = String::Handle(); |
12935 | 12918 |
12936 // Iterate through the stack frames and create C string description | 12919 // Iterate through the stack frames and create C string description |
12937 // for each frame. | 12920 // for each frame. |
12938 intptr_t total_len = 0; | 12921 intptr_t total_len = 0; |
12939 const char* kFormat = "#%-6d %s (%s:%d:%d)\n"; | 12922 const char* kFormat = "#%-6d %s (%s:%d:%d)\n"; |
12940 GrowableArray<char*> frame_strings; | 12923 GrowableArray<char*> frame_strings; |
12941 char* chars; | |
12942 for (intptr_t i = 0; i < Length(); i++) { | 12924 for (intptr_t i = 0; i < Length(); i++) { |
12943 function = FunctionAtFrame(i); | 12925 function = FunctionAtFrame(i); |
12944 if (function.IsNull()) { | |
12945 // Check if null function object indicates a stack trace overflow. | |
12946 if ((i < (Length() - 1)) && | |
12947 (FunctionAtFrame(i + 1) != Function::null())) { | |
12948 const char* kTruncated = "...\n...\n"; | |
12949 intptr_t truncated_len = strlen(kTruncated) + 1; | |
12950 chars = isolate->current_zone()->Alloc<char>(truncated_len); | |
12951 OS::SNPrint(chars, truncated_len, "%s", kTruncated); | |
12952 frame_strings.Add(chars); | |
12953 } | |
12954 continue; | |
12955 } | |
12956 code = CodeAtFrame(i); | 12926 code = CodeAtFrame(i); |
12957 uword pc = code.EntryPoint() + Smi::Value(PcOffsetAtFrame(i)); | 12927 uword pc = code.EntryPoint() + Smi::Value(PcOffsetAtFrame(i)); |
12958 intptr_t token_pos = code.GetTokenIndexOfPC(pc); | 12928 intptr_t token_pos = code.GetTokenIndexOfPC(pc); |
12959 script = function.script(); | 12929 script = function.script(); |
12960 function_name = function.QualifiedUserVisibleName(); | 12930 function_name = function.QualifiedUserVisibleName(); |
12961 url = script.url(); | 12931 url = script.url(); |
12962 intptr_t line = -1; | 12932 intptr_t line = -1; |
12963 intptr_t column = -1; | 12933 intptr_t column = -1; |
12964 if (token_pos >= 0) { | 12934 if (token_pos >= 0) { |
12965 script.GetTokenLocation(token_pos, &line, &column); | 12935 script.GetTokenLocation(token_pos, &line, &column); |
12966 } | 12936 } |
12967 intptr_t len = OS::SNPrint(NULL, 0, kFormat, | 12937 intptr_t len = OS::SNPrint(NULL, 0, kFormat, |
12968 i, | 12938 i, |
12969 function_name.ToCString(), | 12939 function_name.ToCString(), |
12970 url.ToCString(), | 12940 url.ToCString(), |
12971 line, column); | 12941 line, column); |
12972 total_len += len; | 12942 total_len += len; |
12973 chars = isolate->current_zone()->Alloc<char>(len + 1); | 12943 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1); |
12974 OS::SNPrint(chars, (len + 1), kFormat, | 12944 OS::SNPrint(chars, (len + 1), kFormat, |
12975 i, | 12945 i, |
12976 function_name.ToCString(), | 12946 function_name.ToCString(), |
12977 url.ToCString(), | 12947 url.ToCString(), |
12978 line, column); | 12948 line, column); |
12979 frame_strings.Add(chars); | 12949 frame_strings.Add(chars); |
12980 } | 12950 } |
12981 | 12951 |
12982 // Now concatentate the frame descriptions into a single C string. | 12952 // Now concatentate the frame descriptions into a single C string. |
12983 chars = isolate->current_zone()->Alloc<char>(total_len + 1); | 12953 char* chars = Isolate::Current()->current_zone()->Alloc<char>(total_len + 1); |
12984 intptr_t index = 0; | 12954 intptr_t index = 0; |
12985 for (intptr_t i = 0; i < frame_strings.length(); i++) { | 12955 for (intptr_t i = 0; i < frame_strings.length(); i++) { |
12986 index += OS::SNPrint((chars + index), | 12956 index += OS::SNPrint((chars + index), |
12987 (total_len + 1 - index), | 12957 (total_len + 1 - index), |
12988 "%s", | 12958 "%s", |
12989 frame_strings[i]); | 12959 frame_strings[i]); |
12990 } | 12960 } |
12991 return chars; | 12961 return chars; |
12992 } | 12962 } |
12993 | 12963 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13103 } | 13073 } |
13104 return result.raw(); | 13074 return result.raw(); |
13105 } | 13075 } |
13106 | 13076 |
13107 | 13077 |
13108 const char* WeakProperty::ToCString() const { | 13078 const char* WeakProperty::ToCString() const { |
13109 return "_WeakProperty"; | 13079 return "_WeakProperty"; |
13110 } | 13080 } |
13111 | 13081 |
13112 } // namespace dart | 13082 } // namespace dart |
OLD | NEW |