| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #if V8_TARGET_ARCH_X64 | 5 #if V8_TARGET_ARCH_X64 |
| 6 | 6 |
| 7 #include "src/debug/debug.h" | 7 #include "src/debug/debug.h" |
| 8 | 8 |
| 9 #include "src/assembler.h" | 9 #include "src/assembler.h" |
| 10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 } | 57 } |
| 58 | 58 |
| 59 void DebugCodegen::GenerateDebugBreakStub(MacroAssembler* masm, | 59 void DebugCodegen::GenerateDebugBreakStub(MacroAssembler* masm, |
| 60 DebugBreakCallHelperMode mode) { | 60 DebugBreakCallHelperMode mode) { |
| 61 __ RecordComment("Debug break"); | 61 __ RecordComment("Debug break"); |
| 62 | 62 |
| 63 // Enter an internal frame. | 63 // Enter an internal frame. |
| 64 { | 64 { |
| 65 FrameScope scope(masm, StackFrame::INTERNAL); | 65 FrameScope scope(masm, StackFrame::INTERNAL); |
| 66 | 66 |
| 67 // Load padding words on stack. | |
| 68 for (int i = 0; i < LiveEdit::kFramePaddingInitialSize; i++) { | |
| 69 __ Push(Smi::FromInt(LiveEdit::kFramePaddingValue)); | |
| 70 } | |
| 71 __ Push(Smi::FromInt(LiveEdit::kFramePaddingInitialSize)); | |
| 72 | |
| 73 // Push arguments for DebugBreak call. | 67 // Push arguments for DebugBreak call. |
| 74 if (mode == SAVE_RESULT_REGISTER) { | 68 if (mode == SAVE_RESULT_REGISTER) { |
| 75 // Break on return. | 69 // Break on return. |
| 76 __ Push(rax); | 70 __ Push(rax); |
| 77 } else { | 71 } else { |
| 78 // Non-return breaks. | 72 // Non-return breaks. |
| 79 __ Push(masm->isolate()->factory()->the_hole_value()); | 73 __ Push(masm->isolate()->factory()->the_hole_value()); |
| 80 } | 74 } |
| 81 __ Set(rax, 1); | |
| 82 __ Move(rbx, ExternalReference(Runtime::FunctionForId(Runtime::kDebugBreak), | |
| 83 masm->isolate())); | |
| 84 | 75 |
| 85 CEntryStub ceb(masm->isolate(), 1); | 76 __ CallRuntime(Runtime::kDebugBreak, 1, kDontSaveFPRegs); |
| 86 __ CallStub(&ceb); | |
| 87 | 77 |
| 88 if (FLAG_debug_code) { | 78 if (FLAG_debug_code) { |
| 89 for (int i = 0; i < kNumJSCallerSaved; ++i) { | 79 for (int i = 0; i < kNumJSCallerSaved; ++i) { |
| 90 Register reg = {JSCallerSavedCode(i)}; | 80 Register reg = {JSCallerSavedCode(i)}; |
| 91 // Do not clobber rax if mode is SAVE_RESULT_REGISTER. It will | 81 // Do not clobber rax if mode is SAVE_RESULT_REGISTER. It will |
| 92 // contain return value of the function. | 82 // contain return value of the function. |
| 93 if (!(reg.is(rax) && (mode == SAVE_RESULT_REGISTER))) { | 83 if (!(reg.is(rax) && (mode == SAVE_RESULT_REGISTER))) { |
| 94 __ Set(reg, kDebugZapValue); | 84 __ Set(reg, kDebugZapValue); |
| 95 } | 85 } |
| 96 } | 86 } |
| 97 } | 87 } |
| 98 | |
| 99 // Read current padding counter and skip corresponding number of words. | |
| 100 __ Pop(kScratchRegister); | |
| 101 __ SmiToInteger32(kScratchRegister, kScratchRegister); | |
| 102 __ leap(rsp, Operand(rsp, kScratchRegister, times_pointer_size, 0)); | |
| 103 | |
| 104 // Get rid of the internal frame. | 88 // Get rid of the internal frame. |
| 105 } | 89 } |
| 106 | 90 |
| 107 // This call did not replace a call , so there will be an unwanted | 91 __ MaybeDropFrames(); |
| 108 // return address left on the stack. Here we get rid of that. | |
| 109 __ addp(rsp, Immediate(kPCOnStackSize)); | |
| 110 | 92 |
| 111 // Now that the break point has been handled, resume normal execution by | 93 // Return to caller. |
| 112 // jumping to the target address intended by the caller and that was | 94 __ ret(0); |
| 113 // overwritten by the address of DebugBreakXXX. | |
| 114 ExternalReference after_break_target = | |
| 115 ExternalReference::debug_after_break_target_address(masm->isolate()); | |
| 116 __ Move(kScratchRegister, after_break_target); | |
| 117 __ Jump(Operand(kScratchRegister, 0)); | |
| 118 } | 95 } |
| 119 | 96 |
| 97 void DebugCodegen::GenerateHandleDebuggerStatement(MacroAssembler* masm) { |
| 98 { |
| 99 FrameScope scope(masm, StackFrame::INTERNAL); |
| 100 __ CallRuntime(Runtime::kHandleDebuggerStatement, 0); |
| 101 } |
| 102 __ MaybeDropFrames(); |
| 120 | 103 |
| 121 void DebugCodegen::GenerateFrameDropperLiveEdit(MacroAssembler* masm) { | 104 // Return to caller. |
| 122 // We do not know our frame height, but set rsp based on rbp. | 105 __ ret(0); |
| 123 __ leap(rsp, Operand(rbp, FrameDropperFrameConstants::kFunctionOffset)); | 106 } |
| 124 __ Pop(rdi); // Function. | |
| 125 __ addp(rsp, | |
| 126 Immediate(-FrameDropperFrameConstants::kCodeOffset)); // INTERNAL | |
| 127 // frame marker | |
| 128 // and code | |
| 129 __ popq(rbp); | |
| 130 | 107 |
| 131 ParameterCount dummy(0); | 108 void DebugCodegen::GenerateFrameDropperTrampoline(MacroAssembler* masm) { |
| 132 __ CheckDebugHook(rdi, no_reg, dummy, dummy); | 109 // Frame is being dropped: |
| 110 // - Drop to the target frame specified by rbx. |
| 111 // - Look up current function on the frame. |
| 112 // - Leave the frame. |
| 113 // - Restart the frame by calling the function. |
| 114 __ movp(rbp, rbx); |
| 115 __ movp(rdi, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
| 116 __ leave(); |
| 133 | 117 |
| 134 // Load context from the function. | 118 __ movp(rbx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); |
| 135 __ movp(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); | 119 __ LoadSharedFunctionInfoSpecialField( |
| 120 rbx, rbx, SharedFunctionInfo::kFormalParameterCountOffset); |
| 136 | 121 |
| 137 // Clear new.target as a safety measure. | 122 ParameterCount dummy(rbx); |
| 138 __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex); | 123 __ InvokeFunction(rdi, no_reg, dummy, dummy, JUMP_FUNCTION, |
| 139 | 124 CheckDebugStepCallWrapper()); |
| 140 // Get function code. | |
| 141 __ movp(rbx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); | |
| 142 __ movp(rbx, FieldOperand(rbx, SharedFunctionInfo::kCodeOffset)); | |
| 143 __ leap(rbx, FieldOperand(rbx, Code::kHeaderSize)); | |
| 144 | |
| 145 // Re-run JSFunction, rdi is function, rsi is context. | |
| 146 __ jmp(rbx); | |
| 147 } | 125 } |
| 148 | 126 |
| 149 const bool LiveEdit::kFrameDropperSupported = true; | 127 const bool LiveEdit::kFrameDropperSupported = true; |
| 150 | 128 |
| 151 #undef __ | 129 #undef __ |
| 152 | 130 |
| 153 } // namespace internal | 131 } // namespace internal |
| 154 } // namespace v8 | 132 } // namespace v8 |
| 155 | 133 |
| 156 #endif // V8_TARGET_ARCH_X64 | 134 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |