OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 can_access_heap_objects_(true) { | 105 can_access_heap_objects_(true) { |
106 Reset(); | 106 Reset(); |
107 } | 107 } |
108 StackFrameIterator::StackFrameIterator(Isolate* isolate, | 108 StackFrameIterator::StackFrameIterator(Isolate* isolate, |
109 bool use_top, Address fp, Address sp) | 109 bool use_top, Address fp, Address sp) |
110 : isolate_(isolate), | 110 : isolate_(isolate), |
111 STACK_FRAME_TYPE_LIST(INITIALIZE_SINGLETON) | 111 STACK_FRAME_TYPE_LIST(INITIALIZE_SINGLETON) |
112 frame_(NULL), handler_(NULL), | 112 frame_(NULL), handler_(NULL), |
113 thread_(use_top ? isolate_->thread_local_top() : NULL), | 113 thread_(use_top ? isolate_->thread_local_top() : NULL), |
114 fp_(use_top ? NULL : fp), sp_(sp), | 114 fp_(use_top ? NULL : fp), sp_(sp), |
115 advance_(use_top ? &StackFrameIterator::AdvanceWithHandler : | 115 advance_(&StackFrameIterator::AdvanceWithoutHandler), |
116 &StackFrameIterator::AdvanceWithoutHandler), | |
117 can_access_heap_objects_(false) { | 116 can_access_heap_objects_(false) { |
118 if (use_top || fp != NULL) { | 117 if (use_top || fp != NULL) { |
119 Reset(); | 118 Reset(); |
120 } | 119 } |
121 } | 120 } |
122 | 121 |
123 #undef INITIALIZE_SINGLETON | 122 #undef INITIALIZE_SINGLETON |
124 | 123 |
125 | 124 |
126 void StackFrameIterator::AdvanceWithHandler() { | 125 void StackFrameIterator::AdvanceWithHandler() { |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 return Isolate::handler(top) != NULL; | 291 return Isolate::handler(top) != NULL; |
293 } | 292 } |
294 | 293 |
295 | 294 |
296 void SafeStackFrameIterator::AdvanceOneFrame() { | 295 void SafeStackFrameIterator::AdvanceOneFrame() { |
297 ASSERT(!done()); | 296 ASSERT(!done()); |
298 StackFrame* last_frame = iterator_.frame(); | 297 StackFrame* last_frame = iterator_.frame(); |
299 Address last_sp = last_frame->sp(), last_fp = last_frame->fp(); | 298 Address last_sp = last_frame->sp(), last_fp = last_frame->fp(); |
300 // Before advancing to the next stack frame, perform pointer validity tests | 299 // Before advancing to the next stack frame, perform pointer validity tests |
301 iteration_done_ = !IsValidFrame(last_frame) || | 300 iteration_done_ = !IsValidFrame(last_frame) || |
302 !CanIterateHandles(last_frame, iterator_.handler()) || | |
303 !IsValidCaller(last_frame); | 301 !IsValidCaller(last_frame); |
304 if (iteration_done_) return; | 302 if (iteration_done_) return; |
305 | 303 |
306 iterator_.Advance(); | 304 iterator_.Advance(); |
307 if (iterator_.done()) return; | 305 if (iterator_.done()) return; |
308 // Check that we have actually moved to the previous frame in the stack | 306 // Check that we have actually moved to the previous frame in the stack |
309 StackFrame* prev_frame = iterator_.frame(); | 307 StackFrame* prev_frame = iterator_.frame(); |
310 iteration_done_ = prev_frame->sp() < last_sp || prev_frame->fp() < last_fp; | 308 iteration_done_ = prev_frame->sp() < last_sp || prev_frame->fp() < last_fp; |
311 } | 309 } |
312 | 310 |
313 | 311 |
314 bool SafeStackFrameIterator::CanIterateHandles(StackFrame* frame, | |
315 StackHandler* handler) { | |
316 // If StackIterator iterates over StackHandles, verify that | |
317 // StackHandlerIterator can be instantiated (see StackHandlerIterator | |
318 // constructor.) | |
319 return !is_valid_top_ || (frame->sp() <= handler->address()); | |
320 } | |
321 | |
322 | |
323 bool SafeStackFrameIterator::IsValidFrame(StackFrame* frame) const { | 312 bool SafeStackFrameIterator::IsValidFrame(StackFrame* frame) const { |
324 return IsValidStackAddress(frame->sp()) && IsValidStackAddress(frame->fp()); | 313 return IsValidStackAddress(frame->sp()) && IsValidStackAddress(frame->fp()); |
325 } | 314 } |
326 | 315 |
327 | 316 |
328 bool SafeStackFrameIterator::IsValidCaller(StackFrame* frame) { | 317 bool SafeStackFrameIterator::IsValidCaller(StackFrame* frame) { |
329 StackFrame::State state; | 318 StackFrame::State state; |
330 if (frame->is_entry() || frame->is_entry_construct()) { | 319 if (frame->is_entry() || frame->is_entry_construct()) { |
331 // See EntryFrame::GetCallerState. It computes the caller FP address | 320 // See EntryFrame::GetCallerState. It computes the caller FP address |
332 // and calls ExitFrame::GetStateForFramePointer on it. We need to be | 321 // and calls ExitFrame::GetStateForFramePointer on it. We need to be |
(...skipping 1288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1621 ZoneList<StackFrame*> list(10, zone); | 1610 ZoneList<StackFrame*> list(10, zone); |
1622 for (StackFrameIterator it(isolate); !it.done(); it.Advance()) { | 1611 for (StackFrameIterator it(isolate); !it.done(); it.Advance()) { |
1623 StackFrame* frame = AllocateFrameCopy(it.frame(), zone); | 1612 StackFrame* frame = AllocateFrameCopy(it.frame(), zone); |
1624 list.Add(frame, zone); | 1613 list.Add(frame, zone); |
1625 } | 1614 } |
1626 return list.ToVector(); | 1615 return list.ToVector(); |
1627 } | 1616 } |
1628 | 1617 |
1629 | 1618 |
1630 } } // namespace v8::internal | 1619 } } // namespace v8::internal |
OLD | NEW |