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-mips.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 
29 
30 #include "v8.h"
31 
32 #if defined(V8_TARGET_ARCH_MIPS)
33 
34 #include "codegen.h"
35 #include "debug.h"
36 
37 namespace v8 {
38 namespace internal {
39 
40 #ifdef ENABLE_DEBUGGER_SUPPORT
41 
42 bool BreakLocationIterator::IsDebugBreakAtReturn() {
43  return Debug::IsDebugBreakAtReturn(rinfo());
44 }
45 
46 
47 void BreakLocationIterator::SetDebugBreakAtReturn() {
48  // Mips return sequence:
49  // mov sp, fp
50  // lw fp, sp(0)
51  // lw ra, sp(4)
52  // addiu sp, sp, 8
53  // addiu sp, sp, N
54  // jr ra
55  // nop (in branch delay slot)
56 
57  // Make sure this constant matches the number if instrucntions we emit.
59  CodePatcher patcher(rinfo()->pc(), Assembler::kJSReturnSequenceInstructions);
60  // li and Call pseudo-instructions emit two instructions each.
61  patcher.masm()->li(v8::internal::t9,
62  Operand(reinterpret_cast<int32_t>(
63  Isolate::Current()->debug()->debug_break_return()->entry())));
64  patcher.masm()->Call(v8::internal::t9);
65  patcher.masm()->nop();
66  patcher.masm()->nop();
67  patcher.masm()->nop();
68 
69  // TODO(mips): Open issue about using breakpoint instruction instead of nops.
70  // patcher.masm()->bkpt(0);
71 }
72 
73 
74 // Restore the JS frame exit code.
75 void BreakLocationIterator::ClearDebugBreakAtReturn() {
76  rinfo()->PatchCode(original_rinfo()->pc(),
78 }
79 
80 
81 // A debug break in the exit code is identified by the JS frame exit code
82 // having been patched with li/call psuedo-instrunction (liu/ori/jalr).
83 bool Debug::IsDebugBreakAtReturn(RelocInfo* rinfo) {
84  ASSERT(RelocInfo::IsJSReturn(rinfo->rmode()));
85  return rinfo->IsPatchedReturnSequence();
86 }
87 
88 
89 bool BreakLocationIterator::IsDebugBreakAtSlot() {
90  ASSERT(IsDebugBreakSlot());
91  // Check whether the debug break slot instructions have been patched.
92  return rinfo()->IsPatchedDebugBreakSlotSequence();
93 }
94 
95 
96 void BreakLocationIterator::SetDebugBreakAtSlot() {
97  ASSERT(IsDebugBreakSlot());
98  // Patch the code changing the debug break slot code from:
99  // nop(DEBUG_BREAK_NOP) - nop(1) is sll(zero_reg, zero_reg, 1)
100  // nop(DEBUG_BREAK_NOP)
101  // nop(DEBUG_BREAK_NOP)
102  // nop(DEBUG_BREAK_NOP)
103  // to a call to the debug break slot code.
104  // li t9, address (lui t9 / ori t9 instruction pair)
105  // call t9 (jalr t9 / nop instruction pair)
106  CodePatcher patcher(rinfo()->pc(), Assembler::kDebugBreakSlotInstructions);
107  patcher.masm()->li(v8::internal::t9, Operand(reinterpret_cast<int32_t>(
108  Isolate::Current()->debug()->debug_break_slot()->entry())));
109  patcher.masm()->Call(v8::internal::t9);
110 }
111 
112 
113 void BreakLocationIterator::ClearDebugBreakAtSlot() {
114  ASSERT(IsDebugBreakSlot());
115  rinfo()->PatchCode(original_rinfo()->pc(),
117 }
118 
119 const bool Debug::FramePaddingLayout::kIsSupported = false;
120 
121 
122 #define __ ACCESS_MASM(masm)
123 
124 
125 
126 static void Generate_DebugBreakCallHelper(MacroAssembler* masm,
127  RegList object_regs,
128  RegList non_object_regs) {
129  {
130  FrameScope scope(masm, StackFrame::INTERNAL);
131 
132  // Store the registers containing live values on the expression stack to
133  // make sure that these are correctly updated during GC. Non object values
134  // are stored as a smi causing it to be untouched by GC.
135  ASSERT((object_regs & ~kJSCallerSaved) == 0);
136  ASSERT((non_object_regs & ~kJSCallerSaved) == 0);
137  ASSERT((object_regs & non_object_regs) == 0);
138  if ((object_regs | non_object_regs) != 0) {
139  for (int i = 0; i < kNumJSCallerSaved; i++) {
140  int r = JSCallerSavedCode(i);
141  Register reg = { r };
142  if ((non_object_regs & (1 << r)) != 0) {
143  if (FLAG_debug_code) {
144  __ And(at, reg, 0xc0000000);
145  __ Assert(
146  eq, "Unable to encode value as smi", at, Operand(zero_reg));
147  }
148  __ sll(reg, reg, kSmiTagSize);
149  }
150  }
151  __ MultiPush(object_regs | non_object_regs);
152  }
153 
154 #ifdef DEBUG
155  __ RecordComment("// Calling from debug break to runtime - come in - over");
156 #endif
157  __ PrepareCEntryArgs(0); // No arguments.
158  __ PrepareCEntryFunction(ExternalReference::debug_break(masm->isolate()));
159 
160  CEntryStub ceb(1);
161  __ CallStub(&ceb);
162 
163  // Restore the register values from the expression stack.
164  if ((object_regs | non_object_regs) != 0) {
165  __ MultiPop(object_regs | non_object_regs);
166  for (int i = 0; i < kNumJSCallerSaved; i++) {
167  int r = JSCallerSavedCode(i);
168  Register reg = { r };
169  if ((non_object_regs & (1 << r)) != 0) {
170  __ srl(reg, reg, kSmiTagSize);
171  }
172  if (FLAG_debug_code &&
173  (((object_regs |non_object_regs) & (1 << r)) == 0)) {
174  __ li(reg, kDebugZapValue);
175  }
176  }
177  }
178 
179  // Leave the internal frame.
180  }
181 
182  // Now that the break point has been handled, resume normal execution by
183  // jumping to the target address intended by the caller and that was
184  // overwritten by the address of DebugBreakXXX.
185  __ li(t9, Operand(
186  ExternalReference(Debug_Address::AfterBreakTarget(), masm->isolate())));
187  __ lw(t9, MemOperand(t9));
188  __ Jump(t9);
189 }
190 
191 
192 void Debug::GenerateLoadICDebugBreak(MacroAssembler* masm) {
193  // Calling convention for IC load (from ic-mips.cc).
194  // ----------- S t a t e -------------
195  // -- a2 : name
196  // -- ra : return address
197  // -- a0 : receiver
198  // -- [sp] : receiver
199  // -----------------------------------
200  // Registers a0 and a2 contain objects that need to be pushed on the
201  // expression stack of the fake JS frame.
202  Generate_DebugBreakCallHelper(masm, a0.bit() | a2.bit(), 0);
203 }
204 
205 
206 void Debug::GenerateStoreICDebugBreak(MacroAssembler* masm) {
207  // Calling convention for IC store (from ic-mips.cc).
208  // ----------- S t a t e -------------
209  // -- a0 : value
210  // -- a1 : receiver
211  // -- a2 : name
212  // -- ra : return address
213  // -----------------------------------
214  // Registers a0, a1, and a2 contain objects that need to be pushed on the
215  // expression stack of the fake JS frame.
216  Generate_DebugBreakCallHelper(masm, a0.bit() | a1.bit() | a2.bit(), 0);
217 }
218 
219 
220 void Debug::GenerateKeyedLoadICDebugBreak(MacroAssembler* masm) {
221  // ---------- S t a t e --------------
222  // -- ra : return address
223  // -- a0 : key
224  // -- a1 : receiver
225  Generate_DebugBreakCallHelper(masm, a0.bit() | a1.bit(), 0);
226 }
227 
228 
229 void Debug::GenerateKeyedStoreICDebugBreak(MacroAssembler* masm) {
230  // ---------- S t a t e --------------
231  // -- a0 : value
232  // -- a1 : key
233  // -- a2 : receiver
234  // -- ra : return address
235  Generate_DebugBreakCallHelper(masm, a0.bit() | a1.bit() | a2.bit(), 0);
236 }
237 
238 
239 void Debug::GenerateCallICDebugBreak(MacroAssembler* masm) {
240  // Calling convention for IC call (from ic-mips.cc).
241  // ----------- S t a t e -------------
242  // -- a2: name
243  // -----------------------------------
244  Generate_DebugBreakCallHelper(masm, a2.bit(), 0);
245 }
246 
247 
248 void Debug::GenerateReturnDebugBreak(MacroAssembler* masm) {
249  // In places other than IC call sites it is expected that v0 is TOS which
250  // is an object - this is not generally the case so this should be used with
251  // care.
252  Generate_DebugBreakCallHelper(masm, v0.bit(), 0);
253 }
254 
255 
256 void Debug::GenerateCallFunctionStubDebugBreak(MacroAssembler* masm) {
257  // Register state for CallFunctionStub (from code-stubs-mips.cc).
258  // ----------- S t a t e -------------
259  // -- a1 : function
260  // -----------------------------------
261  Generate_DebugBreakCallHelper(masm, a1.bit(), 0);
262 }
263 
264 
265 void Debug::GenerateCallFunctionStubRecordDebugBreak(MacroAssembler* masm) {
266  // Register state for CallFunctionStub (from code-stubs-mips.cc).
267  // ----------- S t a t e -------------
268  // -- a1 : function
269  // -- a2 : cache cell for call target
270  // -----------------------------------
271  Generate_DebugBreakCallHelper(masm, a1.bit() | a2.bit(), 0);
272 }
273 
274 
275 void Debug::GenerateCallConstructStubDebugBreak(MacroAssembler* masm) {
276  // Calling convention for CallConstructStub (from code-stubs-mips.cc).
277  // ----------- S t a t e -------------
278  // -- a0 : number of arguments (not smi)
279  // -- a1 : constructor function
280  // -----------------------------------
281  Generate_DebugBreakCallHelper(masm, a1.bit() , a0.bit());
282 }
283 
284 
285 void Debug::GenerateCallConstructStubRecordDebugBreak(MacroAssembler* masm) {
286  // Calling convention for CallConstructStub (from code-stubs-mips.cc).
287  // ----------- S t a t e -------------
288  // -- a0 : number of arguments (not smi)
289  // -- a1 : constructor function
290  // -- a2 : cache cell for call target
291  // -----------------------------------
292  Generate_DebugBreakCallHelper(masm, a1.bit() | a2.bit(), a0.bit());
293 }
294 
295 
296 void Debug::GenerateSlot(MacroAssembler* masm) {
297  // Generate enough nop's to make space for a call instruction. Avoid emitting
298  // the trampoline pool in the debug break slot code.
299  Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm);
300  Label check_codesize;
301  __ bind(&check_codesize);
302  __ RecordDebugBreakSlot();
303  for (int i = 0; i < Assembler::kDebugBreakSlotInstructions; i++) {
305  }
306  ASSERT_EQ(Assembler::kDebugBreakSlotInstructions,
307  masm->InstructionsGeneratedSince(&check_codesize));
308 }
309 
310 
311 void Debug::GenerateSlotDebugBreak(MacroAssembler* masm) {
312  // In the places where a debug break slot is inserted no registers can contain
313  // object pointers.
314  Generate_DebugBreakCallHelper(masm, 0, 0);
315 }
316 
317 
318 void Debug::GeneratePlainReturnLiveEdit(MacroAssembler* masm) {
319  masm->Abort("LiveEdit frame dropping is not supported on mips");
320 }
321 
322 
323 void Debug::GenerateFrameDropperLiveEdit(MacroAssembler* masm) {
324  masm->Abort("LiveEdit frame dropping is not supported on mips");
325 }
326 
327 
328 const bool Debug::kFrameDropperSupported = false;
329 
330 #undef __
331 
332 
333 #endif // ENABLE_DEBUGGER_SUPPORT
334 
335 } } // namespace v8::internal
336 
337 #endif // V8_TARGET_ARCH_MIPS
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
int JSCallerSavedCode(int n)
Definition: frames.cc:1403
#define __
const Register pc
const int kNumJSCallerSaved
Definition: frames-arm.h:53
friend class BlockTrampolinePoolScope
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