2 * Copyright (C) 2008, 2013, 2014 Apple Inc. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "CallFrame.h"
29 #include "CallFrameInlines.h"
30 #include "CodeBlock.h"
31 #include "Interpreter.h"
32 #include "JSActivation.h"
33 #include "JSCInlines.h"
34 #include "VMEntryScope.h"
35 #include <wtf/StringPrintStream.h>
40 JSStack
* CallFrame::stack()
42 return &interpreter()->stack();
48 unsigned CallFrame::locationAsBytecodeOffset() const
51 ASSERT(hasLocationAsBytecodeOffset());
52 return currentVPC() - codeBlock()->instructions().begin();
55 void CallFrame::setLocationAsBytecodeOffset(unsigned offset
)
58 setCurrentVPC(codeBlock()->instructions().begin() + offset
);
59 ASSERT(hasLocationAsBytecodeOffset());
62 Instruction
* CallFrame::currentVPC() const
64 return codeBlock()->instructions().begin() + locationAsBytecodeOffset();
66 void CallFrame::setCurrentVPC(Instruction
* vpc
)
68 setLocationAsBytecodeOffset(vpc
- codeBlock()->instructions().begin());
73 unsigned CallFrame::bytecodeOffsetFromCodeOriginIndex()
75 ASSERT(hasLocationAsCodeOriginIndex());
76 CodeBlock
* codeBlock
= this->codeBlock();
79 CodeOrigin codeOrigin
;
80 unsigned index
= locationAsCodeOriginIndex();
81 ASSERT(codeBlock
->canGetCodeOrigin(index
));
82 codeOrigin
= codeBlock
->codeOrigin(index
);
84 for (InlineCallFrame
* inlineCallFrame
= codeOrigin
.inlineCallFrame
; inlineCallFrame
;) {
85 if (inlineCallFrame
->baselineCodeBlock() == codeBlock
)
86 return codeOrigin
.bytecodeIndex
;
88 codeOrigin
= inlineCallFrame
->caller
;
89 inlineCallFrame
= codeOrigin
.inlineCallFrame
;
91 return codeOrigin
.bytecodeIndex
;
94 #endif // ENABLE(DFG_JIT)
96 unsigned CallFrame::bytecodeOffset()
101 if (hasLocationAsCodeOriginIndex())
102 return bytecodeOffsetFromCodeOriginIndex();
104 return locationAsBytecodeOffset();
107 CodeOrigin
CallFrame::codeOrigin()
110 return CodeOrigin(0);
112 if (hasLocationAsCodeOriginIndex()) {
113 unsigned index
= locationAsCodeOriginIndex();
114 ASSERT(codeBlock()->canGetCodeOrigin(index
));
115 return codeBlock()->codeOrigin(index
);
118 return CodeOrigin(locationAsBytecodeOffset());
121 Register
* CallFrame::topOfFrameInternal()
123 CodeBlock
* codeBlock
= this->codeBlock();
125 return registers() + codeBlock
->stackPointerOffset();
128 JSGlobalObject
* CallFrame::vmEntryGlobalObject()
130 if (this == lexicalGlobalObject()->globalExec())
131 return lexicalGlobalObject();
133 // For any ExecState that's not a globalExec, the
134 // dynamic global object must be set since code is running
135 ASSERT(vm().entryScope
);
136 return vm().entryScope
->globalObject();
139 JSActivation
* CallFrame::activation() const
141 CodeBlock
* codeBlock
= this->codeBlock();
142 RELEASE_ASSERT(codeBlock
->needsActivation());
143 VirtualRegister activationRegister
= codeBlock
->activationRegister();
144 return registers()[activationRegister
.offset()].Register::activation();
147 void CallFrame::setActivation(JSActivation
* activation
)
149 CodeBlock
* codeBlock
= this->codeBlock();
150 RELEASE_ASSERT(codeBlock
->needsActivation());
151 VirtualRegister activationRegister
= codeBlock
->activationRegister();
152 registers()[activationRegister
.offset()] = activation
;
155 void CallFrame::dump(PrintStream
& out
)
157 if (CodeBlock
* codeBlock
= this->codeBlock()) {
158 out
.print(codeBlock
->inferredName(), "#", codeBlock
->hashAsStringIfPossible(), " [", codeBlock
->jitType(), "]");
161 thisValue().dumpForBacktrace(out
);
163 for (size_t i
= 0; i
< argumentCount(); ++i
) {
165 JSValue value
= argument(i
);
166 value
.dumpForBacktrace(out
);
174 out
.print(returnPC());
177 const char* CallFrame::describeFrame()
179 const size_t bufferSize
= 200;
180 static char buffer
[bufferSize
+ 1];
182 WTF::StringPrintStream stringStream
;
186 strncpy(buffer
, stringStream
.toCString().data(), bufferSize
);
187 buffer
[bufferSize
] = '\0';