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
3 // found in the LICENSE file.
4
5 #if V8_TARGET_ARCH_ARM
6
7 #include "src/codegen.h"
8 #include "src/debug/debug.h"
9
10 namespace v8 {
11 namespace internal {
12
13 #define __ ACCESS_MASM(masm)
14
15
EmitDebugBreakSlot(MacroAssembler * masm)16 void EmitDebugBreakSlot(MacroAssembler* masm) {
17 Label check_size;
18 __ bind(&check_size);
19 for (int i = 0; i < Assembler::kDebugBreakSlotInstructions; i++) {
20 __ nop(MacroAssembler::DEBUG_BREAK_NOP);
21 }
22 DCHECK_EQ(Assembler::kDebugBreakSlotInstructions,
23 masm->InstructionsGeneratedSince(&check_size));
24 }
25
26
GenerateSlot(MacroAssembler * masm,RelocInfo::Mode mode)27 void DebugCodegen::GenerateSlot(MacroAssembler* masm, RelocInfo::Mode mode) {
28 // Generate enough nop's to make space for a call instruction. Avoid emitting
29 // the constant pool in the debug break slot code.
30 Assembler::BlockConstPoolScope block_const_pool(masm);
31 masm->RecordDebugBreakSlot(mode);
32 EmitDebugBreakSlot(masm);
33 }
34
35
ClearDebugBreakSlot(Isolate * isolate,Address pc)36 void DebugCodegen::ClearDebugBreakSlot(Isolate* isolate, Address pc) {
37 CodePatcher patcher(isolate, pc, Assembler::kDebugBreakSlotInstructions);
38 EmitDebugBreakSlot(patcher.masm());
39 }
40
41
PatchDebugBreakSlot(Isolate * isolate,Address pc,Handle<Code> code)42 void DebugCodegen::PatchDebugBreakSlot(Isolate* isolate, Address pc,
43 Handle<Code> code) {
44 DCHECK(code->is_debug_stub());
45 CodePatcher patcher(isolate, pc, Assembler::kDebugBreakSlotInstructions);
46 // Patch the code changing the debug break slot code from
47 // mov r2, r2
48 // mov r2, r2
49 // mov r2, r2
50 // mov r2, r2
51 // to a call to the debug break slot code.
52 // ldr ip, [pc, #0]
53 // b skip
54 // <debug break slot code entry point address>
55 // skip:
56 // blx ip
57 Label skip_constant;
58 patcher.masm()->ldr(ip, MemOperand(v8::internal::pc, 0));
59 patcher.masm()->b(&skip_constant);
60 patcher.Emit(code->entry());
61 patcher.masm()->bind(&skip_constant);
62 patcher.masm()->blx(ip);
63 }
64
DebugBreakSlotIsPatched(Address pc)65 bool DebugCodegen::DebugBreakSlotIsPatched(Address pc) {
66 Instr current_instr = Assembler::instr_at(pc);
67 return !Assembler::IsNop(current_instr, Assembler::DEBUG_BREAK_NOP);
68 }
69
GenerateDebugBreakStub(MacroAssembler * masm,DebugBreakCallHelperMode mode)70 void DebugCodegen::GenerateDebugBreakStub(MacroAssembler* masm,
71 DebugBreakCallHelperMode mode) {
72 __ RecordComment("Debug break");
73 {
74 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
75
76 // Load padding words on stack.
77 __ mov(ip, Operand(Smi::FromInt(LiveEdit::kFramePaddingValue)));
78 for (int i = 0; i < LiveEdit::kFramePaddingInitialSize; i++) {
79 __ push(ip);
80 }
81 __ mov(ip, Operand(Smi::FromInt(LiveEdit::kFramePaddingInitialSize)));
82 __ push(ip);
83
84 // Push arguments for DebugBreak call.
85 if (mode == SAVE_RESULT_REGISTER) {
86 // Break on return.
87 __ push(r0);
88 } else {
89 // Non-return breaks.
90 __ Push(masm->isolate()->factory()->the_hole_value());
91 }
92 __ mov(r0, Operand(1));
93 __ mov(r1,
94 Operand(ExternalReference(
95 Runtime::FunctionForId(Runtime::kDebugBreak), masm->isolate())));
96
97 CEntryStub ceb(masm->isolate(), 1);
98 __ CallStub(&ceb);
99
100 if (FLAG_debug_code) {
101 for (int i = 0; i < kNumJSCallerSaved; i++) {
102 Register reg = {JSCallerSavedCode(i)};
103 // Do not clobber r0 if mode is SAVE_RESULT_REGISTER. It will
104 // contain return value of the function.
105 if (!(reg.is(r0) && (mode == SAVE_RESULT_REGISTER))) {
106 __ mov(reg, Operand(kDebugZapValue));
107 }
108 }
109 }
110
111 // Don't bother removing padding bytes pushed on the stack
112 // as the frame is going to be restored right away.
113
114 // Leave the internal frame.
115 }
116
117 // Now that the break point has been handled, resume normal execution by
118 // jumping to the target address intended by the caller and that was
119 // overwritten by the address of DebugBreakXXX.
120 ExternalReference after_break_target =
121 ExternalReference::debug_after_break_target_address(masm->isolate());
122 __ mov(ip, Operand(after_break_target));
123 __ ldr(ip, MemOperand(ip));
124 __ Jump(ip);
125 }
126
127
GenerateFrameDropperLiveEdit(MacroAssembler * masm)128 void DebugCodegen::GenerateFrameDropperLiveEdit(MacroAssembler* masm) {
129 // Load the function pointer off of our current stack frame.
130 __ ldr(r1, MemOperand(fp, FrameDropperFrameConstants::kFunctionOffset));
131
132 // Pop return address, frame and constant pool pointer (if
133 // FLAG_enable_embedded_constant_pool).
134 __ LeaveFrame(StackFrame::INTERNAL);
135
136 ParameterCount dummy(0);
137 __ FloodFunctionIfStepping(r1, no_reg, dummy, dummy);
138
139 { ConstantPoolUnavailableScope constant_pool_unavailable(masm);
140 // Load context from the function.
141 __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
142
143 // Clear new.target as a safety measure.
144 __ LoadRoot(r3, Heap::kUndefinedValueRootIndex);
145
146 // Get function code.
147 __ ldr(ip, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
148 __ ldr(ip, FieldMemOperand(ip, SharedFunctionInfo::kCodeOffset));
149 __ add(ip, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
150
151 // Re-run JSFunction, r1 is function, cp is context.
152 __ Jump(ip);
153 }
154 }
155
156
157 const bool LiveEdit::kFrameDropperSupported = true;
158
159 #undef __
160
161 } // namespace internal
162 } // namespace v8
163
164 #endif // V8_TARGET_ARCH_ARM
165