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 | |
| 33 | |
| 34 | namespace v8 { namespace internal { |
| 35 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 36 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 37 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 38 | // A debug break in the frame exit code is identified by a call instruction. |
| 39 | bool BreakLocationIterator::IsDebugBreakAtReturn() { |
| 40 | // Opcode E8 is call. |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 41 | return Debug::IsDebugBreakAtReturn(rinfo()); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | |
| 45 | // Patch the JS frame exit code with a debug break call. See |
| 46 | // CodeGenerator::VisitReturnStatement and VirtualFrame::Exit in codegen-ia32.cc |
| 47 | // for the precise return instructions sequence. |
| 48 | void BreakLocationIterator::SetDebugBreakAtReturn() { |
| 49 | ASSERT(Debug::kIa32JSReturnSequenceLength >= |
| 50 | Debug::kIa32CallInstructionLength); |
| 51 | rinfo()->PatchCodeWithCall(Debug::debug_break_return_entry()->entry(), |
| 52 | Debug::kIa32JSReturnSequenceLength - Debug::kIa32CallInstructionLength); |
| 53 | } |
| 54 | |
| 55 | |
| 56 | // Restore the JS frame exit code. |
| 57 | void BreakLocationIterator::ClearDebugBreakAtReturn() { |
| 58 | rinfo()->PatchCode(original_rinfo()->pc(), |
| 59 | Debug::kIa32JSReturnSequenceLength); |
| 60 | } |
| 61 | |
| 62 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 63 | // Check whether the JS frame exit code has been patched with a debug break. |
| 64 | bool Debug::IsDebugBreakAtReturn(RelocInfo* rinfo) { |
| 65 | ASSERT(RelocInfo::IsJSReturn(rinfo->rmode())); |
| 66 | // Opcode E8 is call. |
| 67 | return (*(rinfo->pc()) == 0xE8); |
| 68 | } |
| 69 | |
| 70 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 71 | #define __ ACCESS_MASM(masm) |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 72 | |
| 73 | |
| 74 | static void Generate_DebugBreakCallHelper(MacroAssembler* masm, |
| 75 | RegList pointer_regs, |
| 76 | bool convert_call_to_jmp) { |
| 77 | // Save the content of all general purpose registers in memory. This copy in |
| 78 | // memory is later pushed onto the JS expression stack for the fake JS frame |
| 79 | // generated and also to the C frame generated on top of that. In the JS |
| 80 | // frame ONLY the registers containing pointers will be pushed on the |
| 81 | // expression stack. This causes the GC to update these pointers so that |
| 82 | // they will have the correct value when returning from the debugger. |
| 83 | __ SaveRegistersToMemory(kJSCallerSaved); |
| 84 | |
| 85 | // Enter an internal frame. |
| 86 | __ EnterInternalFrame(); |
| 87 | |
| 88 | // Store the registers containing object pointers on the expression stack to |
| 89 | // make sure that these are correctly updated during GC. |
| 90 | __ PushRegistersFromMemory(pointer_regs); |
| 91 | |
| 92 | #ifdef DEBUG |
| 93 | __ RecordComment("// Calling from debug break to runtime - come in - over"); |
| 94 | #endif |
| 95 | __ Set(eax, Immediate(0)); // no arguments |
| 96 | __ mov(ebx, Immediate(ExternalReference::debug_break())); |
| 97 | |
| 98 | CEntryDebugBreakStub ceb; |
| 99 | __ CallStub(&ceb); |
| 100 | |
| 101 | // Restore the register values containing object pointers from the expression |
| 102 | // stack in the reverse order as they where pushed. |
| 103 | __ PopRegistersToMemory(pointer_regs); |
| 104 | |
| 105 | // Get rid of the internal frame. |
| 106 | __ LeaveInternalFrame(); |
| 107 | |
| 108 | // If this call did not replace a call but patched other code then there will |
| 109 | // be an unwanted return address left on the stack. Here we get rid of that. |
| 110 | if (convert_call_to_jmp) { |
| 111 | __ pop(eax); |
| 112 | } |
| 113 | |
| 114 | // Finally restore all registers. |
| 115 | __ RestoreRegistersFromMemory(kJSCallerSaved); |
| 116 | |
| 117 | // Now that the break point has been handled, resume normal execution by |
| 118 | // jumping to the target address intended by the caller and that was |
| 119 | // overwritten by the address of DebugBreakXXX. |
| 120 | ExternalReference after_break_target = |
| 121 | ExternalReference(Debug_Address::AfterBreakTarget()); |
| 122 | __ jmp(Operand::StaticVariable(after_break_target)); |
| 123 | } |
| 124 | |
| 125 | |
| 126 | void Debug::GenerateLoadICDebugBreak(MacroAssembler* masm) { |
| 127 | // Register state for IC load call (from ic-ia32.cc). |
| 128 | // ----------- S t a t e ------------- |
| 129 | // -- ecx : name |
| 130 | // ----------------------------------- |
| 131 | Generate_DebugBreakCallHelper(masm, ecx.bit(), false); |
| 132 | } |
| 133 | |
| 134 | |
| 135 | void Debug::GenerateStoreICDebugBreak(MacroAssembler* masm) { |
| 136 | // REgister state for IC store call (from ic-ia32.cc). |
| 137 | // ----------- S t a t e ------------- |
| 138 | // -- eax : value |
| 139 | // -- ecx : name |
| 140 | // ----------------------------------- |
| 141 | Generate_DebugBreakCallHelper(masm, eax.bit() | ecx.bit(), false); |
| 142 | } |
| 143 | |
| 144 | |
| 145 | void Debug::GenerateKeyedLoadICDebugBreak(MacroAssembler* masm) { |
| 146 | // Register state for keyed IC load call (from ic-ia32.cc). |
| 147 | // ----------- S t a t e ------------- |
| 148 | // No registers used on entry. |
| 149 | // ----------------------------------- |
| 150 | Generate_DebugBreakCallHelper(masm, 0, false); |
| 151 | } |
| 152 | |
| 153 | |
| 154 | void Debug::GenerateKeyedStoreICDebugBreak(MacroAssembler* masm) { |
| 155 | // Register state for keyed IC load call (from ic-ia32.cc). |
| 156 | // ----------- S t a t e ------------- |
| 157 | // -- eax : value |
| 158 | // ----------------------------------- |
| 159 | // Register eax contains an object that needs to be pushed on the |
| 160 | // expression stack of the fake JS frame. |
| 161 | Generate_DebugBreakCallHelper(masm, eax.bit(), false); |
| 162 | } |
| 163 | |
| 164 | |
| 165 | void Debug::GenerateCallICDebugBreak(MacroAssembler* masm) { |
| 166 | // Register state for keyed IC call call (from ic-ia32.cc) |
| 167 | // ----------- S t a t e ------------- |
| 168 | // -- eax: number of arguments |
| 169 | // ----------------------------------- |
| 170 | // The number of arguments in eax is not smi encoded. |
| 171 | Generate_DebugBreakCallHelper(masm, 0, false); |
| 172 | } |
| 173 | |
| 174 | |
| 175 | void Debug::GenerateConstructCallDebugBreak(MacroAssembler* masm) { |
| 176 | // Register state just before return from JS function (from codegen-ia32.cc). |
| 177 | // eax is the actual number of arguments not encoded as a smi see comment |
| 178 | // above IC call. |
| 179 | // ----------- S t a t e ------------- |
| 180 | // -- eax: number of arguments |
| 181 | // ----------------------------------- |
| 182 | // The number of arguments in eax is not smi encoded. |
| 183 | Generate_DebugBreakCallHelper(masm, 0, false); |
| 184 | } |
| 185 | |
| 186 | |
| 187 | void Debug::GenerateReturnDebugBreak(MacroAssembler* masm) { |
| 188 | // Register state just before return from JS function (from codegen-ia32.cc). |
| 189 | // ----------- S t a t e ------------- |
| 190 | // -- eax: return value |
| 191 | // ----------------------------------- |
| 192 | Generate_DebugBreakCallHelper(masm, eax.bit(), true); |
| 193 | } |
| 194 | |
| 195 | |
| 196 | void Debug::GenerateReturnDebugBreakEntry(MacroAssembler* masm) { |
| 197 | // OK to clobber ebx as we are returning from a JS function in the code |
| 198 | // generated by Ia32CodeGenerator::ExitJSFrame. |
| 199 | ExternalReference debug_break_return = |
| 200 | ExternalReference(Debug_Address::DebugBreakReturn()); |
| 201 | __ mov(ebx, Operand::StaticVariable(debug_break_return)); |
| 202 | __ add(Operand(ebx), Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 203 | __ jmp(Operand(ebx)); |
| 204 | } |
| 205 | |
| 206 | |
| 207 | void Debug::GenerateStubNoRegistersDebugBreak(MacroAssembler* masm) { |
| 208 | // Register state for stub CallFunction (from CallFunctionStub in ic-ia32.cc). |
| 209 | // ----------- S t a t e ------------- |
| 210 | // No registers used on entry. |
| 211 | // ----------------------------------- |
| 212 | Generate_DebugBreakCallHelper(masm, 0, false); |
| 213 | } |
| 214 | |
| 215 | |
| 216 | #undef __ |
| 217 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 218 | #endif // ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 219 | |
| 220 | } } // namespace v8::internal |