• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 //     * Redistributions of source code must retain the above copyright
7 //       notice, this list of conditions and the following disclaimer.
8 //     * Redistributions in binary form must reproduce the above
9 //       copyright notice, this list of conditions and the following
10 //       disclaimer in the documentation and/or other materials provided
11 //       with the distribution.
12 //     * Neither the name of Google Inc. nor the names of its
13 //       contributors may be used to endorse or promote products derived
14 //       from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #include "v8.h"
29 
30 #if defined(V8_TARGET_ARCH_ARM)
31 
32 #include "codegen.h"
33 #include "debug.h"
34 
35 namespace v8 {
36 namespace internal {
37 
38 #ifdef ENABLE_DEBUGGER_SUPPORT
IsDebugBreakAtReturn()39 bool BreakLocationIterator::IsDebugBreakAtReturn() {
40   return Debug::IsDebugBreakAtReturn(rinfo());
41 }
42 
43 
SetDebugBreakAtReturn()44 void BreakLocationIterator::SetDebugBreakAtReturn() {
45   // Patch the code changing the return from JS function sequence from
46   //   mov sp, fp
47   //   ldmia sp!, {fp, lr}
48   //   add sp, sp, #4
49   //   bx lr
50   // to a call to the debug break return code.
51   // #if USE_BLX
52   //   ldr ip, [pc, #0]
53   //   blx ip
54   // #else
55   //   mov lr, pc
56   //   ldr pc, [pc, #-4]
57   // #endif
58   //   <debug break return code entry point address>
59   //   bktp 0
60   CodePatcher patcher(rinfo()->pc(), Assembler::kJSReturnSequenceInstructions);
61 #ifdef USE_BLX
62   patcher.masm()->ldr(v8::internal::ip, MemOperand(v8::internal::pc, 0));
63   patcher.masm()->blx(v8::internal::ip);
64 #else
65   patcher.masm()->mov(v8::internal::lr, v8::internal::pc);
66   patcher.masm()->ldr(v8::internal::pc, MemOperand(v8::internal::pc, -4));
67 #endif
68   patcher.Emit(Isolate::Current()->debug()->debug_break_return()->entry());
69   patcher.masm()->bkpt(0);
70 }
71 
72 
73 // Restore the JS frame exit code.
ClearDebugBreakAtReturn()74 void BreakLocationIterator::ClearDebugBreakAtReturn() {
75   rinfo()->PatchCode(original_rinfo()->pc(),
76                      Assembler::kJSReturnSequenceInstructions);
77 }
78 
79 
80 // A debug break in the frame exit code is identified by the JS frame exit code
81 // having been patched with a call instruction.
IsDebugBreakAtReturn(RelocInfo * rinfo)82 bool Debug::IsDebugBreakAtReturn(RelocInfo* rinfo) {
83   ASSERT(RelocInfo::IsJSReturn(rinfo->rmode()));
84   return rinfo->IsPatchedReturnSequence();
85 }
86 
87 
IsDebugBreakAtSlot()88 bool BreakLocationIterator::IsDebugBreakAtSlot() {
89   ASSERT(IsDebugBreakSlot());
90   // Check whether the debug break slot instructions have been patched.
91   return rinfo()->IsPatchedDebugBreakSlotSequence();
92 }
93 
94 
SetDebugBreakAtSlot()95 void BreakLocationIterator::SetDebugBreakAtSlot() {
96   ASSERT(IsDebugBreakSlot());
97   // Patch the code changing the debug break slot code from
98   //   mov r2, r2
99   //   mov r2, r2
100   //   mov r2, r2
101   // to a call to the debug break slot code.
102   // #if USE_BLX
103   //   ldr ip, [pc, #0]
104   //   blx ip
105   // #else
106   //   mov lr, pc
107   //   ldr pc, [pc, #-4]
108   // #endif
109   //   <debug break slot code entry point address>
110   CodePatcher patcher(rinfo()->pc(), Assembler::kDebugBreakSlotInstructions);
111 #ifdef USE_BLX
112   patcher.masm()->ldr(v8::internal::ip, MemOperand(v8::internal::pc, 0));
113   patcher.masm()->blx(v8::internal::ip);
114 #else
115   patcher.masm()->mov(v8::internal::lr, v8::internal::pc);
116   patcher.masm()->ldr(v8::internal::pc, MemOperand(v8::internal::pc, -4));
117 #endif
118   patcher.Emit(Isolate::Current()->debug()->debug_break_slot()->entry());
119 }
120 
121 
ClearDebugBreakAtSlot()122 void BreakLocationIterator::ClearDebugBreakAtSlot() {
123   ASSERT(IsDebugBreakSlot());
124   rinfo()->PatchCode(original_rinfo()->pc(),
125                      Assembler::kDebugBreakSlotInstructions);
126 }
127 
128 
129 #define __ ACCESS_MASM(masm)
130 
131 
Generate_DebugBreakCallHelper(MacroAssembler * masm,RegList object_regs,RegList non_object_regs)132 static void Generate_DebugBreakCallHelper(MacroAssembler* masm,
133                                           RegList object_regs,
134                                           RegList non_object_regs) {
135   __ EnterInternalFrame();
136 
137   // Store the registers containing live values on the expression stack to
138   // make sure that these are correctly updated during GC. Non object values
139   // are stored as a smi causing it to be untouched by GC.
140   ASSERT((object_regs & ~kJSCallerSaved) == 0);
141   ASSERT((non_object_regs & ~kJSCallerSaved) == 0);
142   ASSERT((object_regs & non_object_regs) == 0);
143   if ((object_regs | non_object_regs) != 0) {
144     for (int i = 0; i < kNumJSCallerSaved; i++) {
145       int r = JSCallerSavedCode(i);
146       Register reg = { r };
147       if ((non_object_regs & (1 << r)) != 0) {
148         if (FLAG_debug_code) {
149           __ tst(reg, Operand(0xc0000000));
150           __ Assert(eq, "Unable to encode value as smi");
151         }
152         __ mov(reg, Operand(reg, LSL, kSmiTagSize));
153       }
154     }
155     __ stm(db_w, sp, object_regs | non_object_regs);
156   }
157 
158 #ifdef DEBUG
159   __ RecordComment("// Calling from debug break to runtime - come in - over");
160 #endif
161   __ mov(r0, Operand(0, RelocInfo::NONE));  // no arguments
162   __ mov(r1, Operand(ExternalReference::debug_break(masm->isolate())));
163 
164   CEntryStub ceb(1);
165   __ CallStub(&ceb);
166 
167   // Restore the register values from the expression stack.
168   if ((object_regs | non_object_regs) != 0) {
169     __ ldm(ia_w, sp, object_regs | non_object_regs);
170     for (int i = 0; i < kNumJSCallerSaved; i++) {
171       int r = JSCallerSavedCode(i);
172       Register reg = { r };
173       if ((non_object_regs & (1 << r)) != 0) {
174         __ mov(reg, Operand(reg, LSR, kSmiTagSize));
175       }
176       if (FLAG_debug_code &&
177           (((object_regs |non_object_regs) & (1 << r)) == 0)) {
178         __ mov(reg, Operand(kDebugZapValue));
179       }
180     }
181   }
182 
183   __ LeaveInternalFrame();
184 
185   // Now that the break point has been handled, resume normal execution by
186   // jumping to the target address intended by the caller and that was
187   // overwritten by the address of DebugBreakXXX.
188   ExternalReference after_break_target =
189       ExternalReference(Debug_Address::AfterBreakTarget(), masm->isolate());
190   __ mov(ip, Operand(after_break_target));
191   __ ldr(ip, MemOperand(ip));
192   __ Jump(ip);
193 }
194 
195 
GenerateLoadICDebugBreak(MacroAssembler * masm)196 void Debug::GenerateLoadICDebugBreak(MacroAssembler* masm) {
197   // Calling convention for IC load (from ic-arm.cc).
198   // ----------- S t a t e -------------
199   //  -- r2    : name
200   //  -- lr    : return address
201   //  -- r0    : receiver
202   //  -- [sp]  : receiver
203   // -----------------------------------
204   // Registers r0 and r2 contain objects that need to be pushed on the
205   // expression stack of the fake JS frame.
206   Generate_DebugBreakCallHelper(masm, r0.bit() | r2.bit(), 0);
207 }
208 
209 
GenerateStoreICDebugBreak(MacroAssembler * masm)210 void Debug::GenerateStoreICDebugBreak(MacroAssembler* masm) {
211   // Calling convention for IC store (from ic-arm.cc).
212   // ----------- S t a t e -------------
213   //  -- r0    : value
214   //  -- r1    : receiver
215   //  -- r2    : name
216   //  -- lr    : return address
217   // -----------------------------------
218   // Registers r0, r1, and r2 contain objects that need to be pushed on the
219   // expression stack of the fake JS frame.
220   Generate_DebugBreakCallHelper(masm, r0.bit() | r1.bit() | r2.bit(), 0);
221 }
222 
223 
GenerateKeyedLoadICDebugBreak(MacroAssembler * masm)224 void Debug::GenerateKeyedLoadICDebugBreak(MacroAssembler* masm) {
225   // ---------- S t a t e --------------
226   //  -- lr     : return address
227   //  -- r0     : key
228   //  -- r1     : receiver
229   Generate_DebugBreakCallHelper(masm, r0.bit() | r1.bit(), 0);
230 }
231 
232 
GenerateKeyedStoreICDebugBreak(MacroAssembler * masm)233 void Debug::GenerateKeyedStoreICDebugBreak(MacroAssembler* masm) {
234   // ---------- S t a t e --------------
235   //  -- r0     : value
236   //  -- r1     : key
237   //  -- r2     : receiver
238   //  -- lr     : return address
239   Generate_DebugBreakCallHelper(masm, r0.bit() | r1.bit() | r2.bit(), 0);
240 }
241 
242 
GenerateCallICDebugBreak(MacroAssembler * masm)243 void Debug::GenerateCallICDebugBreak(MacroAssembler* masm) {
244   // Calling convention for IC call (from ic-arm.cc)
245   // ----------- S t a t e -------------
246   //  -- r2     : name
247   // -----------------------------------
248   Generate_DebugBreakCallHelper(masm, r2.bit(), 0);
249 }
250 
251 
GenerateConstructCallDebugBreak(MacroAssembler * masm)252 void Debug::GenerateConstructCallDebugBreak(MacroAssembler* masm) {
253   // Calling convention for construct call (from builtins-arm.cc)
254   //  -- r0     : number of arguments (not smi)
255   //  -- r1     : constructor function
256   Generate_DebugBreakCallHelper(masm, r1.bit(), r0.bit());
257 }
258 
259 
GenerateReturnDebugBreak(MacroAssembler * masm)260 void Debug::GenerateReturnDebugBreak(MacroAssembler* masm) {
261   // In places other than IC call sites it is expected that r0 is TOS which
262   // is an object - this is not generally the case so this should be used with
263   // care.
264   Generate_DebugBreakCallHelper(masm, r0.bit(), 0);
265 }
266 
267 
GenerateStubNoRegistersDebugBreak(MacroAssembler * masm)268 void Debug::GenerateStubNoRegistersDebugBreak(MacroAssembler* masm) {
269   // ----------- S t a t e -------------
270   //  No registers used on entry.
271   // -----------------------------------
272   Generate_DebugBreakCallHelper(masm, 0, 0);
273 }
274 
275 
GenerateSlot(MacroAssembler * masm)276 void Debug::GenerateSlot(MacroAssembler* masm) {
277   // Generate enough nop's to make space for a call instruction. Avoid emitting
278   // the constant pool in the debug break slot code.
279   Assembler::BlockConstPoolScope block_const_pool(masm);
280   Label check_codesize;
281   __ bind(&check_codesize);
282   __ RecordDebugBreakSlot();
283   for (int i = 0; i < Assembler::kDebugBreakSlotInstructions; i++) {
284     __ nop(MacroAssembler::DEBUG_BREAK_NOP);
285   }
286   ASSERT_EQ(Assembler::kDebugBreakSlotInstructions,
287             masm->InstructionsGeneratedSince(&check_codesize));
288 }
289 
290 
GenerateSlotDebugBreak(MacroAssembler * masm)291 void Debug::GenerateSlotDebugBreak(MacroAssembler* masm) {
292   // In the places where a debug break slot is inserted no registers can contain
293   // object pointers.
294   Generate_DebugBreakCallHelper(masm, 0, 0);
295 }
296 
297 
GeneratePlainReturnLiveEdit(MacroAssembler * masm)298 void Debug::GeneratePlainReturnLiveEdit(MacroAssembler* masm) {
299   masm->Abort("LiveEdit frame dropping is not supported on arm");
300 }
301 
302 
GenerateFrameDropperLiveEdit(MacroAssembler * masm)303 void Debug::GenerateFrameDropperLiveEdit(MacroAssembler* masm) {
304   masm->Abort("LiveEdit frame dropping is not supported on arm");
305 }
306 
307 const bool Debug::kFrameDropperSupported = false;
308 
309 #undef __
310 
311 
312 
313 #endif  // ENABLE_DEBUGGER_SUPPORT
314 
315 } }  // namespace v8::internal
316 
317 #endif  // V8_TARGET_ARCH_ARM
318