ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 1 | // Copyright 2009 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 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 28 | |
| 29 | #include "v8.h" |
| 30 | |
| 31 | #include "codegen-inl.h" |
| 32 | #include "debug.h" |
| 33 | |
| 34 | |
| 35 | namespace v8 { |
| 36 | namespace internal { |
| 37 | |
| 38 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 39 | |
| 40 | bool Debug::IsDebugBreakAtReturn(v8::internal::RelocInfo* rinfo) { |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 41 | ASSERT(RelocInfo::IsJSReturn(rinfo->rmode())); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 42 | // 11th byte of patch is 0x49 (REX.WB byte of computed jump/call to r10), |
| 43 | // 11th byte of JS return is 0xCC (int3). |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 44 | ASSERT(*(rinfo->pc() + 10) == 0x49 || *(rinfo->pc() + 10) == 0xCC); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 45 | return (*(rinfo->pc() + 10) != 0xCC); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 46 | } |
| 47 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 48 | #define __ ACCESS_MASM(masm) |
| 49 | |
| 50 | static void Generate_DebugBreakCallHelper(MacroAssembler* masm, |
| 51 | RegList pointer_regs, |
| 52 | bool convert_call_to_jmp) { |
| 53 | // Save the content of all general purpose registers in memory. This copy in |
| 54 | // memory is later pushed onto the JS expression stack for the fake JS frame |
| 55 | // generated and also to the C frame generated on top of that. In the JS |
| 56 | // frame ONLY the registers containing pointers will be pushed on the |
| 57 | // expression stack. This causes the GC to update these pointers so that |
| 58 | // they will have the correct value when returning from the debugger. |
| 59 | __ SaveRegistersToMemory(kJSCallerSaved); |
| 60 | |
| 61 | // Enter an internal frame. |
| 62 | __ EnterInternalFrame(); |
| 63 | |
| 64 | // Store the registers containing object pointers on the expression stack to |
| 65 | // make sure that these are correctly updated during GC. |
| 66 | __ PushRegistersFromMemory(pointer_regs); |
| 67 | |
| 68 | #ifdef DEBUG |
| 69 | __ RecordComment("// Calling from debug break to runtime - come in - over"); |
| 70 | #endif |
| 71 | __ xor_(rax, rax); // No arguments (argc == 0). |
| 72 | __ movq(rbx, ExternalReference::debug_break()); |
| 73 | |
| 74 | CEntryDebugBreakStub ceb; |
| 75 | __ CallStub(&ceb); |
| 76 | |
| 77 | // Restore the register values containing object pointers from the expression |
| 78 | // stack in the reverse order as they where pushed. |
| 79 | __ PopRegistersToMemory(pointer_regs); |
| 80 | |
| 81 | // Get rid of the internal frame. |
| 82 | __ LeaveInternalFrame(); |
| 83 | |
| 84 | // If this call did not replace a call but patched other code then there will |
| 85 | // be an unwanted return address left on the stack. Here we get rid of that. |
| 86 | if (convert_call_to_jmp) { |
| 87 | __ pop(rax); |
| 88 | } |
| 89 | |
| 90 | // Finally restore all registers. |
| 91 | __ RestoreRegistersFromMemory(kJSCallerSaved); |
| 92 | |
| 93 | // Now that the break point has been handled, resume normal execution by |
| 94 | // jumping to the target address intended by the caller and that was |
| 95 | // overwritten by the address of DebugBreakXXX. |
| 96 | ExternalReference after_break_target = |
| 97 | ExternalReference(Debug_Address::AfterBreakTarget()); |
| 98 | __ movq(kScratchRegister, after_break_target); |
| 99 | __ jmp(Operand(kScratchRegister, 0)); |
| 100 | } |
| 101 | |
| 102 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 103 | void Debug::GenerateCallICDebugBreak(MacroAssembler* masm) { |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 104 | // Register state for keyed IC call call (from ic-x64.cc) |
| 105 | // ----------- S t a t e ------------- |
| 106 | // -- rax: number of arguments |
| 107 | // ----------------------------------- |
| 108 | // The number of arguments in rax is not smi encoded. |
| 109 | Generate_DebugBreakCallHelper(masm, 0, false); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 110 | } |
| 111 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 112 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 113 | void Debug::GenerateConstructCallDebugBreak(MacroAssembler* masm) { |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 114 | // Register state just before return from JS function (from codegen-x64.cc). |
| 115 | // rax is the actual number of arguments not encoded as a smi, see comment |
| 116 | // above IC call. |
| 117 | // ----------- S t a t e ------------- |
| 118 | // -- rax: number of arguments |
| 119 | // ----------------------------------- |
| 120 | // The number of arguments in rax is not smi encoded. |
| 121 | Generate_DebugBreakCallHelper(masm, 0, false); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 122 | } |
| 123 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 124 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 125 | void Debug::GenerateKeyedLoadICDebugBreak(MacroAssembler* masm) { |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 126 | // Register state for keyed IC load call (from ic-x64.cc). |
| 127 | // ----------- S t a t e ------------- |
| 128 | // No registers used on entry. |
| 129 | // ----------------------------------- |
| 130 | Generate_DebugBreakCallHelper(masm, 0, false); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 131 | } |
| 132 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 133 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 134 | void Debug::GenerateKeyedStoreICDebugBreak(MacroAssembler* masm) { |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 135 | // Register state for keyed IC load call (from ic-x64.cc). |
| 136 | // ----------- S t a t e ------------- |
| 137 | // -- rax : value |
| 138 | // ----------------------------------- |
| 139 | // Register rax contains an object that needs to be pushed on the |
| 140 | // expression stack of the fake JS frame. |
| 141 | Generate_DebugBreakCallHelper(masm, rax.bit(), false); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 142 | } |
| 143 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 144 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 145 | void Debug::GenerateLoadICDebugBreak(MacroAssembler* masm) { |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 146 | // Register state for IC load call (from ic-x64.cc). |
| 147 | // ----------- S t a t e ------------- |
| 148 | // -- rcx : name |
| 149 | // ----------------------------------- |
| 150 | Generate_DebugBreakCallHelper(masm, rcx.bit(), false); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 151 | } |
| 152 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 153 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 154 | void Debug::GenerateReturnDebugBreak(MacroAssembler* masm) { |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 155 | // Register state just before return from JS function (from codegen-x64.cc). |
| 156 | // ----------- S t a t e ------------- |
| 157 | // -- rax: return value |
| 158 | // ----------------------------------- |
| 159 | Generate_DebugBreakCallHelper(masm, rax.bit(), true); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 160 | } |
| 161 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 162 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 163 | void Debug::GenerateStoreICDebugBreak(MacroAssembler* masm) { |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 164 | // REgister state for IC store call (from ic-x64.cc). |
| 165 | // ----------- S t a t e ------------- |
| 166 | // -- rax : value |
| 167 | // -- rcx : name |
| 168 | // ----------------------------------- |
| 169 | Generate_DebugBreakCallHelper(masm, rax.bit() | rcx.bit(), false); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 170 | } |
| 171 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 172 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 173 | void Debug::GenerateStubNoRegistersDebugBreak(MacroAssembler* masm) { |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 174 | // Register state for stub CallFunction (from CallFunctionStub in ic-x64.cc). |
| 175 | // ----------- S t a t e ------------- |
| 176 | // No registers used on entry. |
| 177 | // ----------------------------------- |
| 178 | Generate_DebugBreakCallHelper(masm, 0, false); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 179 | } |
| 180 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 181 | |
| 182 | #undef __ |
| 183 | |
| 184 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 185 | void BreakLocationIterator::ClearDebugBreakAtReturn() { |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 186 | rinfo()->PatchCode(original_rinfo()->pc(), |
| 187 | Debug::kX64JSReturnSequenceLength); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 188 | } |
| 189 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 190 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 191 | bool BreakLocationIterator::IsDebugBreakAtReturn() { |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 192 | return Debug::IsDebugBreakAtReturn(rinfo()); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 193 | } |
| 194 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 195 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 196 | void BreakLocationIterator::SetDebugBreakAtReturn() { |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 197 | ASSERT(Debug::kX64JSReturnSequenceLength >= Debug::kX64CallInstructionLength); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame^] | 198 | rinfo()->PatchCodeWithCall(Debug::debug_break_return()->entry(), |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 199 | Debug::kX64JSReturnSequenceLength - Debug::kX64CallInstructionLength); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 200 | } |
| 201 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 202 | #endif // ENABLE_DEBUGGER_SUPPORT |
| 203 | |
| 204 | } } // namespace v8::internal |