blob: bc88d4668d7c0b911519396bb5e09c574e7bd24d [file] [log] [blame]
ager@chromium.org5ec48922009-05-05 07:25:34 +00001// 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.org71affb52009-05-26 05:44:31 +000028
29#include "v8.h"
30
31#include "codegen-inl.h"
32#include "debug.h"
33
34
35namespace v8 {
36namespace internal {
37
38#ifdef ENABLE_DEBUGGER_SUPPORT
39
40bool Debug::IsDebugBreakAtReturn(v8::internal::RelocInfo* rinfo) {
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +000041 ASSERT(RelocInfo::IsJSReturn(rinfo->rmode()));
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +000042 return rinfo->IsPatchedReturnSequence();
kasperl@chromium.org71affb52009-05-26 05:44:31 +000043}
44
sgjesse@chromium.org911335c2009-08-19 12:59:44 +000045#define __ ACCESS_MASM(masm)
46
47static 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.org71affb52009-05-26 05:44:31 +0000100void Debug::GenerateCallICDebugBreak(MacroAssembler* masm) {
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000101 // 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.org71affb52009-05-26 05:44:31 +0000107}
108
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000109
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000110void Debug::GenerateConstructCallDebugBreak(MacroAssembler* masm) {
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000111 // 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.org71affb52009-05-26 05:44:31 +0000119}
120
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000121
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000122void Debug::GenerateKeyedLoadICDebugBreak(MacroAssembler* masm) {
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000123 // 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.org71affb52009-05-26 05:44:31 +0000128}
129
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000130
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000131void Debug::GenerateKeyedStoreICDebugBreak(MacroAssembler* masm) {
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000132 // 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.org71affb52009-05-26 05:44:31 +0000139}
140
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000141
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000142void Debug::GenerateLoadICDebugBreak(MacroAssembler* masm) {
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000143 // 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.org71affb52009-05-26 05:44:31 +0000148}
149
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000150
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000151void Debug::GenerateReturnDebugBreak(MacroAssembler* masm) {
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000152 // 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.org71affb52009-05-26 05:44:31 +0000157}
158
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000159
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000160void Debug::GenerateStoreICDebugBreak(MacroAssembler* masm) {
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000161 // 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.org71affb52009-05-26 05:44:31 +0000167}
168
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000169
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000170void Debug::GenerateStubNoRegistersDebugBreak(MacroAssembler* masm) {
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000171 // 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.org71affb52009-05-26 05:44:31 +0000176}
177
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000178
179#undef __
180
181
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000182void BreakLocationIterator::ClearDebugBreakAtReturn() {
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000183 rinfo()->PatchCode(original_rinfo()->pc(),
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000184 Assembler::kJSReturnSequenceLength);
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000185}
186
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000187
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000188bool BreakLocationIterator::IsDebugBreakAtReturn() {
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000189 return Debug::IsDebugBreakAtReturn(rinfo());
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000190}
191
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000192
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000193void BreakLocationIterator::SetDebugBreakAtReturn() {
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000194 ASSERT(Assembler::kJSReturnSequenceLength >=
195 Assembler::kCallInstructionLength);
ager@chromium.orga1645e22009-09-09 19:27:10 +0000196 rinfo()->PatchCodeWithCall(Debug::debug_break_return()->entry(),
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000197 Assembler::kJSReturnSequenceLength - Assembler::kCallInstructionLength);
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000198}
199
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000200#endif // ENABLE_DEBUGGER_SUPPORT
201
202} } // namespace v8::internal