blob: e6b61b4d2d26e68c7553aba2579597957d4ac8c9 [file] [log] [blame]
ager@chromium.org8bb60582008-12-11 12:02:20 +00001// Copyright 2006-2008 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#include "codegen-inl.h"
31#include "debug.h"
32
kasperl@chromium.org71affb52009-05-26 05:44:31 +000033namespace v8 {
34namespace internal {
ager@chromium.org8bb60582008-12-11 12:02:20 +000035
ager@chromium.org65dad4b2009-04-23 08:48:43 +000036#ifdef ENABLE_DEBUGGER_SUPPORT
iposva@chromium.org245aa852009-02-10 00:49:54 +000037bool BreakLocationIterator::IsDebugBreakAtReturn() {
ager@chromium.org4af710e2009-09-15 12:20:11 +000038 return Debug::IsDebugBreakAtReturn(rinfo());
iposva@chromium.org245aa852009-02-10 00:49:54 +000039}
40
41
iposva@chromium.org245aa852009-02-10 00:49:54 +000042void BreakLocationIterator::SetDebugBreakAtReturn() {
ager@chromium.org4af710e2009-09-15 12:20:11 +000043 // Patch the code changing the return from JS function sequence from
44 // mov sp, fp
45 // ldmia sp!, {fp, lr}
46 // add sp, sp, #4
47 // bx lr
48 // to a call to the debug break return code.
49 // mov lr, pc
50 // ldr pc, [pc, #-4]
51 // <debug break return code entry point address>
52 // bktp 0
53 CodePatcher patcher(rinfo()->pc(), 4);
54 patcher.masm()->mov(v8::internal::lr, v8::internal::pc);
55 patcher.masm()->ldr(v8::internal::pc, MemOperand(v8::internal::pc, -4));
56 patcher.Emit(Debug::debug_break_return()->entry());
57 patcher.masm()->bkpt(0);
iposva@chromium.org245aa852009-02-10 00:49:54 +000058}
59
60
ager@chromium.org4af710e2009-09-15 12:20:11 +000061// Restore the JS frame exit code.
iposva@chromium.org245aa852009-02-10 00:49:54 +000062void BreakLocationIterator::ClearDebugBreakAtReturn() {
ager@chromium.org4af710e2009-09-15 12:20:11 +000063 rinfo()->PatchCode(original_rinfo()->pc(),
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +000064 Assembler::kJSReturnSequenceLength);
iposva@chromium.org245aa852009-02-10 00:49:54 +000065}
66
67
ager@chromium.org4af710e2009-09-15 12:20:11 +000068// A debug break in the exit code is identified by a call.
ager@chromium.org381abbb2009-02-25 13:23:22 +000069bool Debug::IsDebugBreakAtReturn(RelocInfo* rinfo) {
70 ASSERT(RelocInfo::IsJSReturn(rinfo->rmode()));
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +000071 return rinfo->IsPatchedReturnSequence();
ager@chromium.org381abbb2009-02-25 13:23:22 +000072}
73
74
ager@chromium.org65dad4b2009-04-23 08:48:43 +000075#define __ ACCESS_MASM(masm)
ager@chromium.org8bb60582008-12-11 12:02:20 +000076
77
78static void Generate_DebugBreakCallHelper(MacroAssembler* masm,
79 RegList pointer_regs) {
80 // Save the content of all general purpose registers in memory. This copy in
81 // memory is later pushed onto the JS expression stack for the fake JS frame
82 // generated and also to the C frame generated on top of that. In the JS
83 // frame ONLY the registers containing pointers will be pushed on the
84 // expression stack. This causes the GC to update these pointers so that
85 // they will have the correct value when returning from the debugger.
86 __ SaveRegistersToMemory(kJSCallerSaved);
87
88 __ EnterInternalFrame();
89
90 // Store the registers containing object pointers on the expression stack to
91 // make sure that these are correctly updated during GC.
92 // Use sp as base to push.
93 __ CopyRegistersFromMemoryToStack(sp, pointer_regs);
94
95#ifdef DEBUG
96 __ RecordComment("// Calling from debug break to runtime - come in - over");
97#endif
98 __ mov(r0, Operand(0)); // no arguments
99 __ mov(r1, Operand(ExternalReference::debug_break()));
100
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000101 CEntryStub ceb(1, ExitFrame::MODE_DEBUG);
ager@chromium.org8bb60582008-12-11 12:02:20 +0000102 __ CallStub(&ceb);
103
104 // Restore the register values containing object pointers from the expression
105 // stack in the reverse order as they where pushed.
106 // Use sp as base to pop.
107 __ CopyRegistersFromStackToMemory(sp, r3, pointer_regs);
108
109 __ LeaveInternalFrame();
110
ager@chromium.org8bb60582008-12-11 12:02:20 +0000111 // Finally restore all registers.
112 __ RestoreRegistersFromMemory(kJSCallerSaved);
113
114 // Now that the break point has been handled, resume normal execution by
115 // jumping to the target address intended by the caller and that was
116 // overwritten by the address of DebugBreakXXX.
117 __ mov(ip, Operand(ExternalReference(Debug_Address::AfterBreakTarget())));
118 __ ldr(ip, MemOperand(ip));
119 __ Jump(ip);
120}
121
122
123void Debug::GenerateLoadICDebugBreak(MacroAssembler* masm) {
124 // Calling convention for IC load (from ic-arm.cc).
125 // ----------- S t a t e -------------
126 // -- r0 : receiver
127 // -- r2 : name
128 // -- lr : return address
129 // -- [sp] : receiver
130 // -----------------------------------
ager@chromium.org5c838252010-02-19 08:53:10 +0000131 // Registers r0 and r2 contain objects that need to be pushed on the
ager@chromium.org8bb60582008-12-11 12:02:20 +0000132 // expression stack of the fake JS frame.
133 Generate_DebugBreakCallHelper(masm, r0.bit() | r2.bit());
134}
135
136
137void Debug::GenerateStoreICDebugBreak(MacroAssembler* masm) {
138 // Calling convention for IC store (from ic-arm.cc).
139 // ----------- S t a t e -------------
ager@chromium.org5c838252010-02-19 08:53:10 +0000140 // -- r0 : value
141 // -- r1 : receiver
ager@chromium.org8bb60582008-12-11 12:02:20 +0000142 // -- r2 : name
143 // -- lr : return address
ager@chromium.org8bb60582008-12-11 12:02:20 +0000144 // -----------------------------------
ager@chromium.org5c838252010-02-19 08:53:10 +0000145 // Registers r0, r1, and r2 contain objects that need to be pushed on the
ager@chromium.org8bb60582008-12-11 12:02:20 +0000146 // expression stack of the fake JS frame.
ager@chromium.org5c838252010-02-19 08:53:10 +0000147 Generate_DebugBreakCallHelper(masm, r0.bit() | r1.bit() | r2.bit());
ager@chromium.org8bb60582008-12-11 12:02:20 +0000148}
149
150
151void Debug::GenerateKeyedLoadICDebugBreak(MacroAssembler* masm) {
ager@chromium.org4af710e2009-09-15 12:20:11 +0000152 // ---------- S t a t e --------------
153 // -- lr : return address
154 // -- sp[0] : key
155 // -- sp[4] : receiver
156 Generate_DebugBreakCallHelper(masm, 0);
ager@chromium.org8bb60582008-12-11 12:02:20 +0000157}
158
159
160void Debug::GenerateKeyedStoreICDebugBreak(MacroAssembler* masm) {
ager@chromium.org4af710e2009-09-15 12:20:11 +0000161 // ---------- S t a t e --------------
162 // -- lr : return address
163 // -- sp[0] : key
164 // -- sp[4] : receiver
165 Generate_DebugBreakCallHelper(masm, 0);
ager@chromium.org8bb60582008-12-11 12:02:20 +0000166}
167
168
169void Debug::GenerateCallICDebugBreak(MacroAssembler* masm) {
170 // Calling convention for IC call (from ic-arm.cc)
171 // ----------- S t a t e -------------
172 // -- r0: number of arguments
173 // -- r1: receiver
174 // -- lr: return address
175 // -----------------------------------
176 // Register r1 contains an object that needs to be pushed on the expression
177 // stack of the fake JS frame. r0 is the actual number of arguments not
178 // encoded as a smi, therefore it cannot be on the expression stack of the
179 // fake JS frame as it can easily be an invalid pointer (e.g. 1). r0 will be
180 // pushed on the stack of the C frame and restored from there.
181 Generate_DebugBreakCallHelper(masm, r1.bit());
182}
183
184
185void Debug::GenerateConstructCallDebugBreak(MacroAssembler* masm) {
186 // In places other than IC call sites it is expected that r0 is TOS which
187 // is an object - this is not generally the case so this should be used with
188 // care.
189 Generate_DebugBreakCallHelper(masm, r0.bit());
190}
191
192
193void Debug::GenerateReturnDebugBreak(MacroAssembler* masm) {
194 // In places other than IC call sites it is expected that r0 is TOS which
195 // is an object - this is not generally the case so this should be used with
196 // care.
197 Generate_DebugBreakCallHelper(masm, r0.bit());
198}
199
200
ager@chromium.org8bb60582008-12-11 12:02:20 +0000201void Debug::GenerateStubNoRegistersDebugBreak(MacroAssembler* masm) {
ager@chromium.org4af710e2009-09-15 12:20:11 +0000202 // ----------- S t a t e -------------
203 // No registers used on entry.
204 // -----------------------------------
205 Generate_DebugBreakCallHelper(masm, 0);
ager@chromium.org8bb60582008-12-11 12:02:20 +0000206}
207
208
209#undef __
210
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000211#endif // ENABLE_DEBUGGER_SUPPORT
ager@chromium.org8bb60582008-12-11 12:02:20 +0000212
213} } // namespace v8::internal