v8  3.14.5(node0.10.28)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
debug-arm.cc
Go to the documentation of this file.
1 // Copyright 2012 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
39 bool BreakLocationIterator::IsDebugBreakAtReturn() {
40  return Debug::IsDebugBreakAtReturn(rinfo());
41 }
42 
43 
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  // #ifdef 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.
74 void BreakLocationIterator::ClearDebugBreakAtReturn() {
75  rinfo()->PatchCode(original_rinfo()->pc(),
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.
82 bool Debug::IsDebugBreakAtReturn(RelocInfo* rinfo) {
83  ASSERT(RelocInfo::IsJSReturn(rinfo->rmode()));
84  return rinfo->IsPatchedReturnSequence();
85 }
86 
87 
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 
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  // #ifdef 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 
122 void BreakLocationIterator::ClearDebugBreakAtSlot() {
123  ASSERT(IsDebugBreakSlot());
124  rinfo()->PatchCode(original_rinfo()->pc(),
126 }
127 
128 const bool Debug::FramePaddingLayout::kIsSupported = false;
129 
130 
131 #define __ ACCESS_MASM(masm)
132 
133 
134 static void Generate_DebugBreakCallHelper(MacroAssembler* masm,
135  RegList object_regs,
136  RegList non_object_regs) {
137  {
138  FrameScope scope(masm, StackFrame::INTERNAL);
139 
140  // Store the registers containing live values on the expression stack to
141  // make sure that these are correctly updated during GC. Non object values
142  // are stored as a smi causing it to be untouched by GC.
143  ASSERT((object_regs & ~kJSCallerSaved) == 0);
144  ASSERT((non_object_regs & ~kJSCallerSaved) == 0);
145  ASSERT((object_regs & non_object_regs) == 0);
146  if ((object_regs | non_object_regs) != 0) {
147  for (int i = 0; i < kNumJSCallerSaved; i++) {
148  int r = JSCallerSavedCode(i);
149  Register reg = { r };
150  if ((non_object_regs & (1 << r)) != 0) {
151  if (FLAG_debug_code) {
152  __ tst(reg, Operand(0xc0000000));
153  __ Assert(eq, "Unable to encode value as smi");
154  }
155  __ mov(reg, Operand(reg, LSL, kSmiTagSize));
156  }
157  }
158  __ stm(db_w, sp, object_regs | non_object_regs);
159  }
160 
161 #ifdef DEBUG
162  __ RecordComment("// Calling from debug break to runtime - come in - over");
163 #endif
164  __ mov(r0, Operand(0, RelocInfo::NONE)); // no arguments
165  __ mov(r1, Operand(ExternalReference::debug_break(masm->isolate())));
166 
167  CEntryStub ceb(1);
168  __ CallStub(&ceb);
169 
170  // Restore the register values from the expression stack.
171  if ((object_regs | non_object_regs) != 0) {
172  __ ldm(ia_w, sp, object_regs | non_object_regs);
173  for (int i = 0; i < kNumJSCallerSaved; i++) {
174  int r = JSCallerSavedCode(i);
175  Register reg = { r };
176  if ((non_object_regs & (1 << r)) != 0) {
177  __ mov(reg, Operand(reg, LSR, kSmiTagSize));
178  }
179  if (FLAG_debug_code &&
180  (((object_regs |non_object_regs) & (1 << r)) == 0)) {
181  __ mov(reg, Operand(kDebugZapValue));
182  }
183  }
184  }
185 
186  // Leave the internal frame.
187  }
188 
189  // Now that the break point has been handled, resume normal execution by
190  // jumping to the target address intended by the caller and that was
191  // overwritten by the address of DebugBreakXXX.
192  ExternalReference after_break_target =
193  ExternalReference(Debug_Address::AfterBreakTarget(), masm->isolate());
194  __ mov(ip, Operand(after_break_target));
195  __ ldr(ip, MemOperand(ip));
196  __ Jump(ip);
197 }
198 
199 
200 void Debug::GenerateLoadICDebugBreak(MacroAssembler* masm) {
201  // Calling convention for IC load (from ic-arm.cc).
202  // ----------- S t a t e -------------
203  // -- r2 : name
204  // -- lr : return address
205  // -- r0 : receiver
206  // -- [sp] : receiver
207  // -----------------------------------
208  // Registers r0 and r2 contain objects that need to be pushed on the
209  // expression stack of the fake JS frame.
210  Generate_DebugBreakCallHelper(masm, r0.bit() | r2.bit(), 0);
211 }
212 
213 
214 void Debug::GenerateStoreICDebugBreak(MacroAssembler* masm) {
215  // Calling convention for IC store (from ic-arm.cc).
216  // ----------- S t a t e -------------
217  // -- r0 : value
218  // -- r1 : receiver
219  // -- r2 : name
220  // -- lr : return address
221  // -----------------------------------
222  // Registers r0, r1, and r2 contain objects that need to be pushed on the
223  // expression stack of the fake JS frame.
224  Generate_DebugBreakCallHelper(masm, r0.bit() | r1.bit() | r2.bit(), 0);
225 }
226 
227 
228 void Debug::GenerateKeyedLoadICDebugBreak(MacroAssembler* masm) {
229  // ---------- S t a t e --------------
230  // -- lr : return address
231  // -- r0 : key
232  // -- r1 : receiver
233  Generate_DebugBreakCallHelper(masm, r0.bit() | r1.bit(), 0);
234 }
235 
236 
237 void Debug::GenerateKeyedStoreICDebugBreak(MacroAssembler* masm) {
238  // ---------- S t a t e --------------
239  // -- r0 : value
240  // -- r1 : key
241  // -- r2 : receiver
242  // -- lr : return address
243  Generate_DebugBreakCallHelper(masm, r0.bit() | r1.bit() | r2.bit(), 0);
244 }
245 
246 
247 void Debug::GenerateCallICDebugBreak(MacroAssembler* masm) {
248  // Calling convention for IC call (from ic-arm.cc)
249  // ----------- S t a t e -------------
250  // -- r2 : name
251  // -----------------------------------
252  Generate_DebugBreakCallHelper(masm, r2.bit(), 0);
253 }
254 
255 
256 void Debug::GenerateReturnDebugBreak(MacroAssembler* masm) {
257  // In places other than IC call sites it is expected that r0 is TOS which
258  // is an object - this is not generally the case so this should be used with
259  // care.
260  Generate_DebugBreakCallHelper(masm, r0.bit(), 0);
261 }
262 
263 
264 void Debug::GenerateCallFunctionStubDebugBreak(MacroAssembler* masm) {
265  // Register state for CallFunctionStub (from code-stubs-arm.cc).
266  // ----------- S t a t e -------------
267  // -- r1 : function
268  // -----------------------------------
269  Generate_DebugBreakCallHelper(masm, r1.bit(), 0);
270 }
271 
272 
273 void Debug::GenerateCallFunctionStubRecordDebugBreak(MacroAssembler* masm) {
274  // Register state for CallFunctionStub (from code-stubs-arm.cc).
275  // ----------- S t a t e -------------
276  // -- r1 : function
277  // -- r2 : cache cell for call target
278  // -----------------------------------
279  Generate_DebugBreakCallHelper(masm, r1.bit() | r2.bit(), 0);
280 }
281 
282 
283 void Debug::GenerateCallConstructStubDebugBreak(MacroAssembler* masm) {
284  // Calling convention for CallConstructStub (from code-stubs-arm.cc)
285  // ----------- S t a t e -------------
286  // -- r0 : number of arguments (not smi)
287  // -- r1 : constructor function
288  // -----------------------------------
289  Generate_DebugBreakCallHelper(masm, r1.bit(), r0.bit());
290 }
291 
292 
293 void Debug::GenerateCallConstructStubRecordDebugBreak(MacroAssembler* masm) {
294  // Calling convention for CallConstructStub (from code-stubs-arm.cc)
295  // ----------- S t a t e -------------
296  // -- r0 : number of arguments (not smi)
297  // -- r1 : constructor function
298  // -- r2 : cache cell for call target
299  // -----------------------------------
300  Generate_DebugBreakCallHelper(masm, r1.bit() | r2.bit(), r0.bit());
301 }
302 
303 
304 void Debug::GenerateSlot(MacroAssembler* masm) {
305  // Generate enough nop's to make space for a call instruction. Avoid emitting
306  // the constant pool in the debug break slot code.
307  Assembler::BlockConstPoolScope block_const_pool(masm);
308  Label check_codesize;
309  __ bind(&check_codesize);
310  __ RecordDebugBreakSlot();
311  for (int i = 0; i < Assembler::kDebugBreakSlotInstructions; i++) {
313  }
314  ASSERT_EQ(Assembler::kDebugBreakSlotInstructions,
315  masm->InstructionsGeneratedSince(&check_codesize));
316 }
317 
318 
319 void Debug::GenerateSlotDebugBreak(MacroAssembler* masm) {
320  // In the places where a debug break slot is inserted no registers can contain
321  // object pointers.
322  Generate_DebugBreakCallHelper(masm, 0, 0);
323 }
324 
325 
326 void Debug::GeneratePlainReturnLiveEdit(MacroAssembler* masm) {
327  masm->Abort("LiveEdit frame dropping is not supported on arm");
328 }
329 
330 
331 void Debug::GenerateFrameDropperLiveEdit(MacroAssembler* masm) {
332  masm->Abort("LiveEdit frame dropping is not supported on arm");
333 }
334 
335 const bool Debug::kFrameDropperSupported = false;
336 
337 #undef __
338 
339 
340 
341 #endif // ENABLE_DEBUGGER_SUPPORT
342 
343 } } // namespace v8::internal
344 
345 #endif // V8_TARGET_ARCH_ARM
static const int kDebugBreakSlotInstructions
uint32_t RegList
Definition: frames.h:38
#define ASSERT(condition)
Definition: checks.h:270
const RegList kJSCallerSaved
Definition: frames-arm.h:47
friend class BlockConstPoolScope
const Register r2
int JSCallerSavedCode(int n)
Definition: frames.cc:1403
const Register sp
const Register ip
#define __
const Register pc
const int kNumJSCallerSaved
Definition: frames-arm.h:53
const Register r0
const Register lr
const Register r1
const int kSmiTagSize
Definition: v8.h:4015
#define ASSERT_EQ(v1, v2)
Definition: checks.h:271
static const int kJSReturnSequenceInstructions
const uint32_t kDebugZapValue
Definition: v8globals.h:84