• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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_ARM64
6 
7 #include "src/arm64/frames-arm64.h"
8 #include "src/codegen.h"
9 #include "src/debug/debug.h"
10 
11 namespace v8 {
12 namespace internal {
13 
14 #define __ ACCESS_MASM(masm)
15 
16 
EmitDebugBreakSlot(Assembler * masm)17 void EmitDebugBreakSlot(Assembler* masm) {
18   Label check_size;
19   __ bind(&check_size);
20   for (int i = 0; i < Assembler::kDebugBreakSlotInstructions; i++) {
21     __ nop(Assembler::DEBUG_BREAK_NOP);
22   }
23   DCHECK_EQ(Assembler::kDebugBreakSlotInstructions,
24             static_cast<int>(masm->InstructionsGeneratedSince(&check_size)));
25 }
26 
27 
GenerateSlot(MacroAssembler * masm,RelocInfo::Mode mode)28 void DebugCodegen::GenerateSlot(MacroAssembler* masm, RelocInfo::Mode mode) {
29   // Generate enough nop's to make space for a call instruction. Avoid emitting
30   // the constant pool in the debug break slot code.
31   InstructionAccurateScope scope(masm, Assembler::kDebugBreakSlotInstructions);
32   masm->RecordDebugBreakSlot(mode);
33   EmitDebugBreakSlot(masm);
34 }
35 
36 
ClearDebugBreakSlot(Isolate * isolate,Address pc)37 void DebugCodegen::ClearDebugBreakSlot(Isolate* isolate, Address pc) {
38   PatchingAssembler patcher(isolate, reinterpret_cast<Instruction*>(pc),
39                             Assembler::kDebugBreakSlotInstructions);
40   EmitDebugBreakSlot(&patcher);
41 }
42 
43 
PatchDebugBreakSlot(Isolate * isolate,Address pc,Handle<Code> code)44 void DebugCodegen::PatchDebugBreakSlot(Isolate* isolate, Address pc,
45                                        Handle<Code> code) {
46   DCHECK_EQ(Code::BUILTIN, code->kind());
47   PatchingAssembler patcher(isolate, reinterpret_cast<Instruction*>(pc),
48                             Assembler::kDebugBreakSlotInstructions);
49   // Patch the code emitted by DebugCodegen::GenerateSlots, changing the debug
50   // break slot code from
51   //   mov x0, x0    @ nop DEBUG_BREAK_NOP
52   //   mov x0, x0    @ nop DEBUG_BREAK_NOP
53   //   mov x0, x0    @ nop DEBUG_BREAK_NOP
54   //   mov x0, x0    @ nop DEBUG_BREAK_NOP
55   //   mov x0, x0    @ nop DEBUG_BREAK_NOP
56   // to a call to the debug slot code.
57   //   ldr ip0, [pc, #(2 * kInstructionSize)]
58   //   blr ip0
59   //   b skip
60   //   <debug break slot code entry point address (64 bits)>
61   //   skip:
62 
63   Label skip_constant;
64   // The first instruction of a patched debug break slot must be a load literal
65   // loading the address of the debug break slot code.
66   patcher.ldr_pcrel(ip0, (2 * kInstructionSize) >> kLoadLiteralScaleLog2);
67   patcher.b(&skip_constant);
68   patcher.dc64(reinterpret_cast<int64_t>(code->entry()));
69   patcher.bind(&skip_constant);
70   // TODO(all): check the following is correct.
71   // The debug break slot code will push a frame and call statically compiled
72   // code. By using blr,  this call site will be registered in the frame.
73   // The debugger can now iterate on the frames to find this call.
74   patcher.blr(ip0);
75 }
76 
77 
GenerateDebugBreakStub(MacroAssembler * masm,DebugBreakCallHelperMode mode)78 void DebugCodegen::GenerateDebugBreakStub(MacroAssembler* masm,
79                                           DebugBreakCallHelperMode mode) {
80   __ RecordComment("Debug break");
81   Register scratch = x10;
82   {
83     FrameScope scope(masm, StackFrame::INTERNAL);
84 
85     // Load padding words on stack.
86     __ Mov(scratch, Smi::FromInt(LiveEdit::kFramePaddingValue));
87     __ PushMultipleTimes(scratch, LiveEdit::kFramePaddingInitialSize);
88     __ Mov(scratch, Smi::FromInt(LiveEdit::kFramePaddingInitialSize));
89     __ Push(scratch);
90 
91     if (mode == SAVE_RESULT_REGISTER) __ Push(x0);
92 
93     __ Mov(x0, 0);  // No arguments.
94     __ Mov(x1, ExternalReference(Runtime::FunctionForId(Runtime::kDebugBreak),
95                                  masm->isolate()));
96 
97     CEntryStub stub(masm->isolate(), 1);
98     __ CallStub(&stub);
99 
100     if (FLAG_debug_code) {
101       for (int i = 0; i < kNumJSCallerSaved; i++) {
102         Register reg = Register::XRegFromCode(JSCallerSavedCode(i));
103         __ Mov(reg, Operand(kDebugZapValue));
104       }
105     }
106 
107     // Restore the register values from the expression stack.
108     if (mode == SAVE_RESULT_REGISTER) __ Pop(x0);
109 
110     // Don't bother removing padding bytes pushed on the stack
111     // as the frame is going to be restored right away.
112 
113     // Leave the internal frame.
114   }
115 
116   // Now that the break point has been handled, resume normal execution by
117   // jumping to the target address intended by the caller and that was
118   // overwritten by the address of DebugBreakXXX.
119   ExternalReference after_break_target =
120       ExternalReference::debug_after_break_target_address(masm->isolate());
121   __ Mov(scratch, after_break_target);
122   __ Ldr(scratch, MemOperand(scratch));
123   __ Br(scratch);
124 }
125 
126 
GenerateFrameDropperLiveEdit(MacroAssembler * masm)127 void DebugCodegen::GenerateFrameDropperLiveEdit(MacroAssembler* masm) {
128   // We do not know our frame height, but set sp based on fp.
129   __ Sub(masm->StackPointer(), fp, kPointerSize);
130   __ AssertStackConsistency();
131 
132   __ Pop(x1, fp, lr);  // Function, Frame, Return address.
133 
134   ParameterCount dummy(0);
135   __ FloodFunctionIfStepping(x1, no_reg, dummy, dummy);
136 
137   UseScratchRegisterScope temps(masm);
138   Register scratch = temps.AcquireX();
139 
140   // Load context from the function.
141   __ Ldr(cp, FieldMemOperand(x1, JSFunction::kContextOffset));
142 
143   // Clear new.target as a safety measure.
144   __ LoadRoot(x3, Heap::kUndefinedValueRootIndex);
145 
146   // Get function code.
147   __ Ldr(scratch, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset));
148   __ Ldr(scratch, FieldMemOperand(scratch, SharedFunctionInfo::kCodeOffset));
149   __ Add(scratch, scratch, Code::kHeaderSize - kHeapObjectTag);
150 
151   // Re-run JSFunction, x1 is function, cp is context.
152   __ Br(scratch);
153 }
154 
155 
156 const bool LiveEdit::kFrameDropperSupported = true;
157 
158 }  // namespace internal
159 }  // namespace v8
160 
161 #endif  // V8_TARGET_ARCH_ARM64
162