sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1 | // Copyright 2010 the V8 project authors. All rights reserved. |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 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 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 31 | #if defined(V8_TARGET_ARCH_X64) |
| 32 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 33 | #include "codegen-inl.h" |
| 34 | #include "debug.h" |
| 35 | |
| 36 | |
| 37 | namespace v8 { |
| 38 | namespace internal { |
| 39 | |
| 40 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 41 | |
| 42 | bool Debug::IsDebugBreakAtReturn(v8::internal::RelocInfo* rinfo) { |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 43 | ASSERT(RelocInfo::IsJSReturn(rinfo->rmode())); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 44 | return rinfo->IsPatchedReturnSequence(); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 45 | } |
| 46 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 47 | #define __ ACCESS_MASM(masm) |
| 48 | |
| 49 | static void Generate_DebugBreakCallHelper(MacroAssembler* masm, |
| 50 | RegList pointer_regs, |
| 51 | bool convert_call_to_jmp) { |
| 52 | // Save the content of all general purpose registers in memory. This copy in |
| 53 | // memory is later pushed onto the JS expression stack for the fake JS frame |
| 54 | // generated and also to the C frame generated on top of that. In the JS |
| 55 | // frame ONLY the registers containing pointers will be pushed on the |
| 56 | // expression stack. This causes the GC to update these pointers so that |
| 57 | // they will have the correct value when returning from the debugger. |
| 58 | __ SaveRegistersToMemory(kJSCallerSaved); |
| 59 | |
| 60 | // Enter an internal frame. |
| 61 | __ EnterInternalFrame(); |
| 62 | |
| 63 | // Store the registers containing object pointers on the expression stack to |
| 64 | // make sure that these are correctly updated during GC. |
| 65 | __ PushRegistersFromMemory(pointer_regs); |
| 66 | |
| 67 | #ifdef DEBUG |
| 68 | __ RecordComment("// Calling from debug break to runtime - come in - over"); |
| 69 | #endif |
| 70 | __ xor_(rax, rax); // No arguments (argc == 0). |
| 71 | __ movq(rbx, ExternalReference::debug_break()); |
| 72 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 73 | CEntryStub ceb(1, ExitFrame::MODE_DEBUG); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 74 | __ CallStub(&ceb); |
| 75 | |
| 76 | // Restore the register values containing object pointers from the expression |
| 77 | // stack in the reverse order as they where pushed. |
| 78 | __ PopRegistersToMemory(pointer_regs); |
| 79 | |
| 80 | // Get rid of the internal frame. |
| 81 | __ LeaveInternalFrame(); |
| 82 | |
| 83 | // If this call did not replace a call but patched other code then there will |
| 84 | // be an unwanted return address left on the stack. Here we get rid of that. |
| 85 | if (convert_call_to_jmp) { |
| 86 | __ pop(rax); |
| 87 | } |
| 88 | |
| 89 | // Finally restore all registers. |
| 90 | __ RestoreRegistersFromMemory(kJSCallerSaved); |
| 91 | |
| 92 | // Now that the break point has been handled, resume normal execution by |
| 93 | // jumping to the target address intended by the caller and that was |
| 94 | // overwritten by the address of DebugBreakXXX. |
| 95 | ExternalReference after_break_target = |
| 96 | ExternalReference(Debug_Address::AfterBreakTarget()); |
| 97 | __ movq(kScratchRegister, after_break_target); |
| 98 | __ jmp(Operand(kScratchRegister, 0)); |
| 99 | } |
| 100 | |
| 101 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 102 | void Debug::GenerateCallICDebugBreak(MacroAssembler* masm) { |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 103 | // Register state for keyed IC call call (from ic-x64.cc) |
| 104 | // ----------- S t a t e ------------- |
| 105 | // -- rax: number of arguments |
| 106 | // ----------------------------------- |
| 107 | // The number of arguments in rax is not smi encoded. |
| 108 | Generate_DebugBreakCallHelper(masm, 0, false); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 109 | } |
| 110 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 111 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 112 | void Debug::GenerateConstructCallDebugBreak(MacroAssembler* masm) { |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 113 | // Register state just before return from JS function (from codegen-x64.cc). |
| 114 | // rax is the actual number of arguments not encoded as a smi, see comment |
| 115 | // above IC call. |
| 116 | // ----------- S t a t e ------------- |
| 117 | // -- rax: number of arguments |
| 118 | // ----------------------------------- |
| 119 | // The number of arguments in rax is not smi encoded. |
| 120 | Generate_DebugBreakCallHelper(masm, 0, false); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 121 | } |
| 122 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 123 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 124 | void Debug::GenerateKeyedLoadICDebugBreak(MacroAssembler* masm) { |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 125 | // Register state for keyed IC load call (from ic-x64.cc). |
| 126 | // ----------- S t a t e ------------- |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 127 | // -- rax : key |
| 128 | // -- rdx : receiver |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 129 | // ----------------------------------- |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 130 | Generate_DebugBreakCallHelper(masm, rax.bit() | rdx.bit(), 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 |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 138 | // -- rcx : key |
| 139 | // -- rdx : receiver |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 140 | // ----------------------------------- |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 141 | Generate_DebugBreakCallHelper(masm, rax.bit() | rcx.bit() | rdx.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 ------------- |
sgjesse@chromium.org | 82dbbab | 2010-06-02 08:57:44 +0000 | [diff] [blame] | 148 | // -- rax : receiver |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 149 | // -- rcx : name |
| 150 | // ----------------------------------- |
sgjesse@chromium.org | 82dbbab | 2010-06-02 08:57:44 +0000 | [diff] [blame] | 151 | Generate_DebugBreakCallHelper(masm, rax.bit() | rcx.bit(), false); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 152 | } |
| 153 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 154 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 155 | void Debug::GenerateReturnDebugBreak(MacroAssembler* masm) { |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 156 | // Register state just before return from JS function (from codegen-x64.cc). |
| 157 | // ----------- S t a t e ------------- |
| 158 | // -- rax: return value |
| 159 | // ----------------------------------- |
| 160 | Generate_DebugBreakCallHelper(masm, rax.bit(), true); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 161 | } |
| 162 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 163 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 164 | void Debug::GenerateStoreICDebugBreak(MacroAssembler* masm) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 165 | // Register state for IC store call (from ic-x64.cc). |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 166 | // ----------- S t a t e ------------- |
| 167 | // -- rax : value |
| 168 | // -- rcx : name |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 169 | // -- rdx : receiver |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 170 | // ----------------------------------- |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 171 | Generate_DebugBreakCallHelper(masm, rax.bit() | rcx.bit() | rdx.bit(), false); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 172 | } |
| 173 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 174 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 175 | void Debug::GenerateStubNoRegistersDebugBreak(MacroAssembler* masm) { |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 176 | // Register state for stub CallFunction (from CallFunctionStub in ic-x64.cc). |
| 177 | // ----------- S t a t e ------------- |
| 178 | // No registers used on entry. |
| 179 | // ----------------------------------- |
| 180 | Generate_DebugBreakCallHelper(masm, 0, false); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 181 | } |
| 182 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 183 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame^] | 184 | void Debug::GenerateSlot(MacroAssembler* masm) { |
| 185 | // Generate enough nop's to make space for a call instruction. |
| 186 | Label check_codesize; |
| 187 | __ bind(&check_codesize); |
| 188 | __ RecordDebugBreakSlot(); |
| 189 | for (int i = 0; i < Assembler::kDebugBreakSlotLength; i++) { |
| 190 | __ nop(); |
| 191 | } |
| 192 | ASSERT_EQ(Assembler::kDebugBreakSlotLength, |
| 193 | masm->SizeOfCodeGeneratedSince(&check_codesize)); |
| 194 | } |
| 195 | |
| 196 | |
| 197 | void Debug::GenerateSlotDebugBreak(MacroAssembler* masm) { |
| 198 | // In the places where a debug break slot is inserted no registers can contain |
| 199 | // object pointers. |
| 200 | Generate_DebugBreakCallHelper(masm, 0, true); |
| 201 | } |
| 202 | |
| 203 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 204 | void Debug::GeneratePlainReturnLiveEdit(MacroAssembler* masm) { |
| 205 | masm->Abort("LiveEdit frame dropping is not supported on x64"); |
| 206 | } |
| 207 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame^] | 208 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 209 | void Debug::GenerateFrameDropperLiveEdit(MacroAssembler* masm) { |
| 210 | masm->Abort("LiveEdit frame dropping is not supported on x64"); |
| 211 | } |
| 212 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 213 | #undef __ |
| 214 | |
| 215 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 216 | void Debug::SetUpFrameDropperFrame(StackFrame* bottom_js_frame, |
| 217 | Handle<Code> code) { |
| 218 | UNREACHABLE(); |
| 219 | } |
| 220 | const int Debug::kFrameDropperFrameSize = -1; |
| 221 | |
| 222 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 223 | void BreakLocationIterator::ClearDebugBreakAtReturn() { |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 224 | rinfo()->PatchCode(original_rinfo()->pc(), |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 225 | Assembler::kJSReturnSequenceLength); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 226 | } |
| 227 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 228 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 229 | bool BreakLocationIterator::IsDebugBreakAtReturn() { |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 230 | return Debug::IsDebugBreakAtReturn(rinfo()); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 231 | } |
| 232 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 233 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 234 | void BreakLocationIterator::SetDebugBreakAtReturn() { |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 235 | ASSERT(Assembler::kJSReturnSequenceLength >= |
| 236 | Assembler::kCallInstructionLength); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 237 | rinfo()->PatchCodeWithCall(Debug::debug_break_return()->entry(), |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 238 | Assembler::kJSReturnSequenceLength - Assembler::kCallInstructionLength); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 239 | } |
| 240 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame^] | 241 | |
| 242 | bool BreakLocationIterator::IsDebugBreakAtSlot() { |
| 243 | ASSERT(IsDebugBreakSlot()); |
| 244 | // Check whether the debug break slot instructions have been patched. |
| 245 | return !Assembler::IsNop(rinfo()->pc()); |
| 246 | } |
| 247 | |
| 248 | |
| 249 | void BreakLocationIterator::SetDebugBreakAtSlot() { |
| 250 | ASSERT(IsDebugBreakSlot()); |
| 251 | rinfo()->PatchCodeWithCall( |
| 252 | Debug::debug_break_slot()->entry(), |
| 253 | Assembler::kDebugBreakSlotLength - Assembler::kCallInstructionLength); |
| 254 | } |
| 255 | |
| 256 | |
| 257 | void BreakLocationIterator::ClearDebugBreakAtSlot() { |
| 258 | ASSERT(IsDebugBreakSlot()); |
| 259 | rinfo()->PatchCode(original_rinfo()->pc(), Assembler::kDebugBreakSlotLength); |
| 260 | } |
| 261 | |
| 262 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 263 | #endif // ENABLE_DEBUGGER_SUPPORT |
| 264 | |
| 265 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 266 | |
| 267 | #endif // V8_TARGET_ARCH_X64 |