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