blob: f7fbe7691e4bcfcc1c375e8a7e5bc1bcb2fc137b [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// 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
3// found in the LICENSE file.
4
5#if V8_TARGET_ARCH_X64
6
7#include "src/assembler.h"
8#include "src/codegen.h"
9#include "src/debug/debug.h"
10
11
12namespace v8 {
13namespace internal {
14
15#define __ ACCESS_MASM(masm)
16
17
18void EmitDebugBreakSlot(MacroAssembler* masm) {
19 Label check_codesize;
20 __ bind(&check_codesize);
21 __ Nop(Assembler::kDebugBreakSlotLength);
22 DCHECK_EQ(Assembler::kDebugBreakSlotLength,
23 masm->SizeOfCodeGeneratedSince(&check_codesize));
24}
25
26
27void DebugCodegen::GenerateSlot(MacroAssembler* masm, RelocInfo::Mode mode) {
28 // Generate enough nop's to make space for a call instruction.
29 masm->RecordDebugBreakSlot(mode);
30 EmitDebugBreakSlot(masm);
31}
32
33
34void DebugCodegen::ClearDebugBreakSlot(Isolate* isolate, Address pc) {
35 CodePatcher patcher(isolate, pc, Assembler::kDebugBreakSlotLength);
36 EmitDebugBreakSlot(patcher.masm());
37}
38
39
40void DebugCodegen::PatchDebugBreakSlot(Isolate* isolate, Address pc,
41 Handle<Code> code) {
42 DCHECK_EQ(Code::BUILTIN, code->kind());
43 static const int kSize = Assembler::kDebugBreakSlotLength;
44 CodePatcher patcher(isolate, pc, kSize);
45 Label check_codesize;
46 patcher.masm()->bind(&check_codesize);
47 patcher.masm()->movp(kScratchRegister, reinterpret_cast<void*>(code->entry()),
48 Assembler::RelocInfoNone());
49 patcher.masm()->call(kScratchRegister);
50 // Check that the size of the code generated is as expected.
51 DCHECK_EQ(kSize, patcher.masm()->SizeOfCodeGeneratedSince(&check_codesize));
52}
53
Ben Murdoch097c5b22016-05-18 11:27:45 +010054bool DebugCodegen::DebugBreakSlotIsPatched(Address pc) {
55 return !Assembler::IsNop(pc);
56}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000057
58void DebugCodegen::GenerateDebugBreakStub(MacroAssembler* masm,
59 DebugBreakCallHelperMode mode) {
60 __ RecordComment("Debug break");
61
62 // Enter an internal frame.
63 {
64 FrameScope scope(masm, StackFrame::INTERNAL);
65
66 // Load padding words on stack.
67 for (int i = 0; i < LiveEdit::kFramePaddingInitialSize; i++) {
68 __ Push(Smi::FromInt(LiveEdit::kFramePaddingValue));
69 }
70 __ Push(Smi::FromInt(LiveEdit::kFramePaddingInitialSize));
71
72 if (mode == SAVE_RESULT_REGISTER) __ Push(rax);
73
74 __ Set(rax, 0); // No arguments (argc == 0).
75 __ Move(rbx, ExternalReference(Runtime::FunctionForId(Runtime::kDebugBreak),
76 masm->isolate()));
77
78 CEntryStub ceb(masm->isolate(), 1);
79 __ CallStub(&ceb);
80
81 if (FLAG_debug_code) {
82 for (int i = 0; i < kNumJSCallerSaved; ++i) {
83 Register reg = {JSCallerSavedCode(i)};
84 __ Set(reg, kDebugZapValue);
85 }
86 }
87
88 if (mode == SAVE_RESULT_REGISTER) __ Pop(rax);
89
90 // Read current padding counter and skip corresponding number of words.
91 __ Pop(kScratchRegister);
92 __ SmiToInteger32(kScratchRegister, kScratchRegister);
93 __ leap(rsp, Operand(rsp, kScratchRegister, times_pointer_size, 0));
94
95 // Get rid of the internal frame.
96 }
97
98 // This call did not replace a call , so there will be an unwanted
99 // return address left on the stack. Here we get rid of that.
100 __ addp(rsp, Immediate(kPCOnStackSize));
101
102 // Now that the break point has been handled, resume normal execution by
103 // jumping to the target address intended by the caller and that was
104 // overwritten by the address of DebugBreakXXX.
105 ExternalReference after_break_target =
106 ExternalReference::debug_after_break_target_address(masm->isolate());
107 __ Move(kScratchRegister, after_break_target);
108 __ Jump(Operand(kScratchRegister, 0));
109}
110
111
112void DebugCodegen::GenerateFrameDropperLiveEdit(MacroAssembler* masm) {
113 // We do not know our frame height, but set rsp based on rbp.
114 __ leap(rsp, Operand(rbp, -1 * kPointerSize));
115
116 __ Pop(rdi); // Function.
117 __ popq(rbp);
118
119 ParameterCount dummy(0);
120 __ FloodFunctionIfStepping(rdi, no_reg, dummy, dummy);
121
122 // Load context from the function.
123 __ movp(rsi, FieldOperand(rdi, JSFunction::kContextOffset));
124
125 // Clear new.target as a safety measure.
126 __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex);
127
128 // Get function code.
129 __ movp(rbx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
130 __ movp(rbx, FieldOperand(rbx, SharedFunctionInfo::kCodeOffset));
131 __ leap(rbx, FieldOperand(rbx, Code::kHeaderSize));
132
133 // Re-run JSFunction, rdi is function, rsi is context.
134 __ jmp(rbx);
135}
136
137const bool LiveEdit::kFrameDropperSupported = true;
138
139#undef __
140
141} // namespace internal
142} // namespace v8
143
144#endif // V8_TARGET_ARCH_X64