ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 1 | // 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.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 33 | namespace v8 { |
| 34 | namespace internal { |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 35 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 36 | #ifdef ENABLE_DEBUGGER_SUPPORT |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 37 | bool BreakLocationIterator::IsDebugBreakAtReturn() { |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 38 | return Debug::IsDebugBreakAtReturn(rinfo()); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 42 | void BreakLocationIterator::SetDebugBreakAtReturn() { |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 43 | // 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.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 61 | // Restore the JS frame exit code. |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 62 | void BreakLocationIterator::ClearDebugBreakAtReturn() { |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 63 | rinfo()->PatchCode(original_rinfo()->pc(), |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 64 | Assembler::kJSReturnSequenceLength); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 68 | // A debug break in the exit code is identified by a call. |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 69 | bool Debug::IsDebugBreakAtReturn(RelocInfo* rinfo) { |
| 70 | ASSERT(RelocInfo::IsJSReturn(rinfo->rmode())); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 71 | return rinfo->IsPatchedReturnSequence(); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 75 | #define __ ACCESS_MASM(masm) |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 76 | |
| 77 | |
| 78 | static 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.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 101 | CEntryStub ceb(1, ExitFrame::MODE_DEBUG); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 102 | __ 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.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 111 | // 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 | |
| 123 | void 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.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame^] | 131 | // Registers r0 and r2 contain objects that need to be pushed on the |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 132 | // expression stack of the fake JS frame. |
| 133 | Generate_DebugBreakCallHelper(masm, r0.bit() | r2.bit()); |
| 134 | } |
| 135 | |
| 136 | |
| 137 | void Debug::GenerateStoreICDebugBreak(MacroAssembler* masm) { |
| 138 | // Calling convention for IC store (from ic-arm.cc). |
| 139 | // ----------- S t a t e ------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame^] | 140 | // -- r0 : value |
| 141 | // -- r1 : receiver |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 142 | // -- r2 : name |
| 143 | // -- lr : return address |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 144 | // ----------------------------------- |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame^] | 145 | // Registers r0, r1, and r2 contain objects that need to be pushed on the |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 146 | // expression stack of the fake JS frame. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame^] | 147 | Generate_DebugBreakCallHelper(masm, r0.bit() | r1.bit() | r2.bit()); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | |
| 151 | void Debug::GenerateKeyedLoadICDebugBreak(MacroAssembler* masm) { |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 152 | // ---------- S t a t e -------------- |
| 153 | // -- lr : return address |
| 154 | // -- sp[0] : key |
| 155 | // -- sp[4] : receiver |
| 156 | Generate_DebugBreakCallHelper(masm, 0); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | |
| 160 | void Debug::GenerateKeyedStoreICDebugBreak(MacroAssembler* masm) { |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 161 | // ---------- S t a t e -------------- |
| 162 | // -- lr : return address |
| 163 | // -- sp[0] : key |
| 164 | // -- sp[4] : receiver |
| 165 | Generate_DebugBreakCallHelper(masm, 0); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | |
| 169 | void 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 | |
| 185 | void 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 | |
| 193 | void 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.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 201 | void Debug::GenerateStubNoRegistersDebugBreak(MacroAssembler* masm) { |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 202 | // ----------- S t a t e ------------- |
| 203 | // No registers used on entry. |
| 204 | // ----------------------------------- |
| 205 | Generate_DebugBreakCallHelper(masm, 0); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | |
| 209 | #undef __ |
| 210 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 211 | #endif // ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 212 | |
| 213 | } } // namespace v8::internal |