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