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())); |
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 | |
| 71 | CEntryDebugBreakStub ceb; |
| 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 | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 161 | // REgister state for IC store call (from ic-x64.cc). |
| 162 | // ----------- S t a t e ------------- |
| 163 | // -- rax : value |
| 164 | // -- rcx : name |
| 165 | // ----------------------------------- |
| 166 | Generate_DebugBreakCallHelper(masm, rax.bit() | rcx.bit(), false); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 167 | } |
| 168 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 169 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 170 | void Debug::GenerateStubNoRegistersDebugBreak(MacroAssembler* masm) { |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 171 | // Register state for stub CallFunction (from CallFunctionStub in ic-x64.cc). |
| 172 | // ----------- S t a t e ------------- |
| 173 | // No registers used on entry. |
| 174 | // ----------------------------------- |
| 175 | Generate_DebugBreakCallHelper(masm, 0, false); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 176 | } |
| 177 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 178 | |
| 179 | #undef __ |
| 180 | |
| 181 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 182 | void BreakLocationIterator::ClearDebugBreakAtReturn() { |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 183 | rinfo()->PatchCode(original_rinfo()->pc(), |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame^] | 184 | Assembler::kJSReturnSequenceLength); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 185 | } |
| 186 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 187 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 188 | bool BreakLocationIterator::IsDebugBreakAtReturn() { |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 189 | return Debug::IsDebugBreakAtReturn(rinfo()); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 190 | } |
| 191 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 192 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 193 | void BreakLocationIterator::SetDebugBreakAtReturn() { |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame^] | 194 | ASSERT(Assembler::kJSReturnSequenceLength >= |
| 195 | Assembler::kCallInstructionLength); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 196 | rinfo()->PatchCodeWithCall(Debug::debug_break_return()->entry(), |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame^] | 197 | Assembler::kJSReturnSequenceLength - Assembler::kCallInstructionLength); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 198 | } |
| 199 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 200 | #endif // ENABLE_DEBUGGER_SUPPORT |
| 201 | |
| 202 | } } // namespace v8::internal |