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

Side by Side Diff: src/runtime/runtime-internal.cc

Issue 1924253002: [wasm] Patch trapping position into stack trace (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@pass-wasm-position-to-runtime
Patch Set: add TODO with tracking bug Created 4 years, 7 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
« no previous file with comments | « src/js/messages.js ('k') | test/cctest/cctest.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/ast/prettyprinter.h" 8 #include "src/ast/prettyprinter.h"
9 #include "src/bootstrapper.h" 9 #include "src/bootstrapper.h"
10 #include "src/conversions.h" 10 #include "src/conversions.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 SealHandleScope shs(isolate); 94 SealHandleScope shs(isolate);
95 DCHECK_LE(0, args.length()); 95 DCHECK_LE(0, args.length());
96 return isolate->StackOverflow(); 96 return isolate->StackOverflow();
97 } 97 }
98 98
99 RUNTIME_FUNCTION(Runtime_ThrowWasmError) { 99 RUNTIME_FUNCTION(Runtime_ThrowWasmError) {
100 HandleScope scope(isolate); 100 HandleScope scope(isolate);
101 DCHECK_EQ(2, args.length()); 101 DCHECK_EQ(2, args.length());
102 CONVERT_SMI_ARG_CHECKED(message_id, 0); 102 CONVERT_SMI_ARG_CHECKED(message_id, 0);
103 CONVERT_SMI_ARG_CHECKED(byte_offset, 1); 103 CONVERT_SMI_ARG_CHECKED(byte_offset, 1);
104 USE(byte_offset); // TODO(clemensh): patch the stack trace with this offset 104 Handle<Object> error_obj = isolate->factory()->NewError(
105 Handle<Object> error = isolate->factory()->NewError(
106 static_cast<MessageTemplate::Template>(message_id)); 105 static_cast<MessageTemplate::Template>(message_id));
107 return isolate->Throw(*error); 106
107 // For wasm traps, the byte offset (a.k.a source position) can not be
108 // determined from relocation info, since the explicit checks for traps
109 // converge in one singe block which calls this runtime function.
110 // We hence pass the byte offset explicitely, and patch it into the top-most
111 // frame (a wasm frame) on the collected stack trace.
112 // TODO(wasm): This implementation is temporary, see bug #5007:
113 // https://bugs.chromium.org/p/v8/issues/detail?id=5007
114 Handle<JSObject> error = Handle<JSObject>::cast(error_obj);
115 Handle<Object> stack_trace_obj = JSReceiver::GetDataProperty(
116 error, isolate->factory()->stack_trace_symbol());
117 // Patch the stack trace (array of <receiver, function, code, position>).
118 if (stack_trace_obj->IsJSArray()) {
119 Handle<FixedArray> stack_elements(
120 FixedArray::cast(JSArray::cast(*stack_trace_obj)->elements()));
121 DCHECK_EQ(1, stack_elements->length() % 4);
122 DCHECK(Code::cast(stack_elements->get(3))->kind() == Code::WASM_FUNCTION);
123 DCHECK(stack_elements->get(4)->IsSmi() &&
124 Smi::cast(stack_elements->get(4))->value() >= 0);
125 stack_elements->set(4, Smi::FromInt(-1 - byte_offset));
126 }
127 Handle<Object> detailed_stack_trace_obj = JSReceiver::GetDataProperty(
128 error, isolate->factory()->detailed_stack_trace_symbol());
129 // Patch the detailed stack trace (array of JSObjects with various
130 // properties).
131 if (detailed_stack_trace_obj->IsJSArray()) {
132 Handle<FixedArray> stack_elements(
133 FixedArray::cast(JSArray::cast(*detailed_stack_trace_obj)->elements()));
134 DCHECK_GE(stack_elements->length(), 1);
135 Handle<JSObject> top_frame(JSObject::cast(stack_elements->get(0)));
136 Handle<String> wasm_offset_key =
137 isolate->factory()->InternalizeOneByteString(
138 STATIC_CHAR_VECTOR("column"));
139 LookupIterator it(top_frame, wasm_offset_key, top_frame,
140 LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
141 if (it.IsFound()) {
142 DCHECK(JSReceiver::GetDataProperty(&it)->IsSmi());
143 Maybe<bool> data_set = JSReceiver::SetDataProperty(
144 &it, handle(Smi::FromInt(byte_offset), isolate));
145 DCHECK(data_set.IsJust() && data_set.FromJust() == true);
146 USE(data_set);
147 }
148 }
149
150 return isolate->Throw(*error_obj);
108 } 151 }
109 152
110 RUNTIME_FUNCTION(Runtime_UnwindAndFindExceptionHandler) { 153 RUNTIME_FUNCTION(Runtime_UnwindAndFindExceptionHandler) {
111 SealHandleScope shs(isolate); 154 SealHandleScope shs(isolate);
112 DCHECK(args.length() == 0); 155 DCHECK(args.length() == 0);
113 return isolate->UnwindAndFindHandler(); 156 return isolate->UnwindAndFindHandler();
114 } 157 }
115 158
116 159
117 RUNTIME_FUNCTION(Runtime_PromoteScheduledException) { 160 RUNTIME_FUNCTION(Runtime_PromoteScheduledException) {
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 } 586 }
544 587
545 RUNTIME_FUNCTION(Runtime_RunMicrotasks) { 588 RUNTIME_FUNCTION(Runtime_RunMicrotasks) {
546 HandleScope scope(isolate); 589 HandleScope scope(isolate);
547 DCHECK(args.length() == 0); 590 DCHECK(args.length() == 0);
548 isolate->RunMicrotasks(); 591 isolate->RunMicrotasks();
549 return isolate->heap()->undefined_value(); 592 return isolate->heap()->undefined_value();
550 } 593 }
551 } // namespace internal 594 } // namespace internal
552 } // namespace v8 595 } // namespace v8
OLDNEW
« no previous file with comments | « src/js/messages.js ('k') | test/cctest/cctest.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698