1 // Copyright 2014 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.
9 #include "src/codegen.h"
10 #include "src/debug.h"
15 bool BreakLocationIterator::IsDebugBreakAtReturn() {
16 return Debug::IsDebugBreakAtReturn(rinfo());
20 void BreakLocationIterator::SetDebugBreakAtReturn() {
21 // Patch the code changing the return from JS function sequence from
26 // to a call to the debug break return code.
27 // this uses a FIXED_SEQUENCE to load an address constant
34 CodePatcher patcher(rinfo()->pc(), Assembler::kJSReturnSequenceInstructions);
35 Assembler::BlockTrampolinePoolScope block_trampoline_pool(patcher.masm());
38 Operand(reinterpret_cast<intptr_t>(debug_info_->GetIsolate()
42 patcher.masm()->mtctr(v8::internal::r0);
43 patcher.masm()->bctrl();
44 patcher.masm()->bkpt(0);
48 // Restore the JS frame exit code.
49 void BreakLocationIterator::ClearDebugBreakAtReturn() {
50 rinfo()->PatchCode(original_rinfo()->pc(),
51 Assembler::kJSReturnSequenceInstructions);
55 // A debug break in the frame exit code is identified by the JS frame exit code
56 // having been patched with a call instruction.
57 bool Debug::IsDebugBreakAtReturn(RelocInfo* rinfo) {
58 DCHECK(RelocInfo::IsJSReturn(rinfo->rmode()));
59 return rinfo->IsPatchedReturnSequence();
63 bool BreakLocationIterator::IsDebugBreakAtSlot() {
64 DCHECK(IsDebugBreakSlot());
65 // Check whether the debug break slot instructions have been patched.
66 return rinfo()->IsPatchedDebugBreakSlotSequence();
70 void BreakLocationIterator::SetDebugBreakAtSlot() {
71 DCHECK(IsDebugBreakSlot());
72 // Patch the code changing the debug break slot code from
80 // to a call to the debug break code, using a FIXED_SEQUENCE.
86 CodePatcher patcher(rinfo()->pc(), Assembler::kDebugBreakSlotInstructions);
87 Assembler::BlockTrampolinePoolScope block_trampoline_pool(patcher.masm());
90 Operand(reinterpret_cast<intptr_t>(
91 debug_info_->GetIsolate()->builtins()->Slot_DebugBreak()->entry())));
92 patcher.masm()->mtctr(v8::internal::r0);
93 patcher.masm()->bctrl();
97 void BreakLocationIterator::ClearDebugBreakAtSlot() {
98 DCHECK(IsDebugBreakSlot());
99 rinfo()->PatchCode(original_rinfo()->pc(),
100 Assembler::kDebugBreakSlotInstructions);
104 #define __ ACCESS_MASM(masm)
107 static void Generate_DebugBreakCallHelper(MacroAssembler* masm,
109 RegList non_object_regs) {
111 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
113 // Load padding words on stack.
114 __ LoadSmiLiteral(ip, Smi::FromInt(LiveEdit::kFramePaddingValue));
115 for (int i = 0; i < LiveEdit::kFramePaddingInitialSize; i++) {
118 __ LoadSmiLiteral(ip, Smi::FromInt(LiveEdit::kFramePaddingInitialSize));
121 // Store the registers containing live values on the expression stack to
122 // make sure that these are correctly updated during GC. Non object values
123 // are stored as a smi causing it to be untouched by GC.
124 DCHECK((object_regs & ~kJSCallerSaved) == 0);
125 DCHECK((non_object_regs & ~kJSCallerSaved) == 0);
126 DCHECK((object_regs & non_object_regs) == 0);
127 if ((object_regs | non_object_regs) != 0) {
128 for (int i = 0; i < kNumJSCallerSaved; i++) {
129 int r = JSCallerSavedCode(i);
131 if ((non_object_regs & (1 << r)) != 0) {
132 if (FLAG_debug_code) {
133 __ TestUnsignedSmiCandidate(reg, r0);
134 __ Assert(eq, kUnableToEncodeValueAsSmi, cr0);
139 __ MultiPush(object_regs | non_object_regs);
143 __ RecordComment("// Calling from debug break to runtime - come in - over");
145 __ mov(r3, Operand::Zero()); // no arguments
146 __ mov(r4, Operand(ExternalReference::debug_break(masm->isolate())));
148 CEntryStub ceb(masm->isolate(), 1);
151 // Restore the register values from the expression stack.
152 if ((object_regs | non_object_regs) != 0) {
153 __ MultiPop(object_regs | non_object_regs);
154 for (int i = 0; i < kNumJSCallerSaved; i++) {
155 int r = JSCallerSavedCode(i);
157 if ((non_object_regs & (1 << r)) != 0) {
160 if (FLAG_debug_code &&
161 (((object_regs | non_object_regs) & (1 << r)) == 0)) {
162 __ mov(reg, Operand(kDebugZapValue));
167 // Don't bother removing padding bytes pushed on the stack
168 // as the frame is going to be restored right away.
170 // Leave the internal frame.
173 // Now that the break point has been handled, resume normal execution by
174 // jumping to the target address intended by the caller and that was
175 // overwritten by the address of DebugBreakXXX.
176 ExternalReference after_break_target =
177 ExternalReference::debug_after_break_target_address(masm->isolate());
178 __ mov(ip, Operand(after_break_target));
179 __ LoadP(ip, MemOperand(ip));
180 __ JumpToJSEntry(ip);
184 void DebugCodegen::GenerateCallICStubDebugBreak(MacroAssembler* masm) {
185 // Register state for CallICStub
186 // ----------- S t a t e -------------
188 // -- r6 : slot in feedback array (smi)
189 // -----------------------------------
190 Generate_DebugBreakCallHelper(masm, r4.bit() | r6.bit(), 0);
194 void DebugCodegen::GenerateLoadICDebugBreak(MacroAssembler* masm) {
195 // Calling convention for IC load (from ic-ppc.cc).
196 Register receiver = LoadDescriptor::ReceiverRegister();
197 Register name = LoadDescriptor::NameRegister();
198 RegList regs = receiver.bit() | name.bit();
199 if (FLAG_vector_ics) {
200 regs |= VectorLoadICTrampolineDescriptor::SlotRegister().bit();
202 Generate_DebugBreakCallHelper(masm, regs, 0);
206 void DebugCodegen::GenerateStoreICDebugBreak(MacroAssembler* masm) {
207 // Calling convention for IC store (from ic-ppc.cc).
208 Register receiver = StoreDescriptor::ReceiverRegister();
209 Register name = StoreDescriptor::NameRegister();
210 Register value = StoreDescriptor::ValueRegister();
211 Generate_DebugBreakCallHelper(masm, receiver.bit() | name.bit() | value.bit(),
216 void DebugCodegen::GenerateKeyedLoadICDebugBreak(MacroAssembler* masm) {
217 // Calling convention for keyed IC load (from ic-ppc.cc).
218 GenerateLoadICDebugBreak(masm);
222 void DebugCodegen::GenerateKeyedStoreICDebugBreak(MacroAssembler* masm) {
223 // Calling convention for IC keyed store call (from ic-ppc.cc).
224 Register receiver = StoreDescriptor::ReceiverRegister();
225 Register name = StoreDescriptor::NameRegister();
226 Register value = StoreDescriptor::ValueRegister();
227 Generate_DebugBreakCallHelper(masm, receiver.bit() | name.bit() | value.bit(),
232 void DebugCodegen::GenerateCompareNilICDebugBreak(MacroAssembler* masm) {
233 // Register state for CompareNil IC
234 // ----------- S t a t e -------------
236 // -----------------------------------
237 Generate_DebugBreakCallHelper(masm, r3.bit(), 0);
241 void DebugCodegen::GenerateReturnDebugBreak(MacroAssembler* masm) {
242 // In places other than IC call sites it is expected that r3 is TOS which
243 // is an object - this is not generally the case so this should be used with
245 Generate_DebugBreakCallHelper(masm, r3.bit(), 0);
249 void DebugCodegen::GenerateCallFunctionStubDebugBreak(MacroAssembler* masm) {
250 // Register state for CallFunctionStub (from code-stubs-ppc.cc).
251 // ----------- S t a t e -------------
253 // -----------------------------------
254 Generate_DebugBreakCallHelper(masm, r4.bit(), 0);
258 void DebugCodegen::GenerateCallConstructStubDebugBreak(MacroAssembler* masm) {
259 // Calling convention for CallConstructStub (from code-stubs-ppc.cc)
260 // ----------- S t a t e -------------
261 // -- r3 : number of arguments (not smi)
262 // -- r4 : constructor function
263 // -----------------------------------
264 Generate_DebugBreakCallHelper(masm, r4.bit(), r3.bit());
268 void DebugCodegen::GenerateCallConstructStubRecordDebugBreak(
269 MacroAssembler* masm) {
270 // Calling convention for CallConstructStub (from code-stubs-ppc.cc)
271 // ----------- S t a t e -------------
272 // -- r3 : number of arguments (not smi)
273 // -- r4 : constructor function
274 // -- r5 : feedback array
275 // -- r6 : feedback slot (smi)
276 // -----------------------------------
277 Generate_DebugBreakCallHelper(masm, r4.bit() | r5.bit() | r6.bit(), r3.bit());
281 void DebugCodegen::GenerateSlot(MacroAssembler* masm) {
282 // Generate enough nop's to make space for a call instruction. Avoid emitting
283 // the trampoline pool in the debug break slot code.
284 Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm);
285 Label check_codesize;
286 __ bind(&check_codesize);
287 __ RecordDebugBreakSlot();
288 for (int i = 0; i < Assembler::kDebugBreakSlotInstructions; i++) {
289 __ nop(MacroAssembler::DEBUG_BREAK_NOP);
291 DCHECK_EQ(Assembler::kDebugBreakSlotInstructions,
292 masm->InstructionsGeneratedSince(&check_codesize));
296 void DebugCodegen::GenerateSlotDebugBreak(MacroAssembler* masm) {
297 // In the places where a debug break slot is inserted no registers can contain
299 Generate_DebugBreakCallHelper(masm, 0, 0);
303 void DebugCodegen::GeneratePlainReturnLiveEdit(MacroAssembler* masm) {
308 void DebugCodegen::GenerateFrameDropperLiveEdit(MacroAssembler* masm) {
309 ExternalReference restarter_frame_function_slot =
310 ExternalReference::debug_restarter_frame_function_pointer_address(
312 __ mov(ip, Operand(restarter_frame_function_slot));
313 __ li(r4, Operand::Zero());
314 __ StoreP(r4, MemOperand(ip, 0));
316 // Load the function pointer off of our current stack frame.
317 __ LoadP(r4, MemOperand(fp, StandardFrameConstants::kConstantPoolOffset -
320 // Pop return address, frame and constant pool pointer (if
321 // FLAG_enable_ool_constant_pool).
322 __ LeaveFrame(StackFrame::INTERNAL);
324 // Load context from the function.
325 __ LoadP(cp, FieldMemOperand(r4, JSFunction::kContextOffset));
327 // Get function code.
328 __ LoadP(ip, FieldMemOperand(r4, JSFunction::kSharedFunctionInfoOffset));
329 __ LoadP(ip, FieldMemOperand(ip, SharedFunctionInfo::kCodeOffset));
330 __ addi(ip, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
332 // Re-run JSFunction, r4 is function, cp is context.
337 const bool LiveEdit::kFrameDropperSupported = true;
341 } // namespace v8::internal
343 #endif // V8_TARGET_ARCH_PPC