fpizlo@apple.com | bc16ddb | 2016-09-06 01:02:22 +0000 | [diff] [blame] | 1 | /* |
mark.lam@apple.com | 5ba0779 | 2019-08-27 22:14:52 +0000 | [diff] [blame] | 2 | * Copyright (C) 2016-2019 Apple Inc. All rights reserved. |
fpizlo@apple.com | bc16ddb | 2016-09-06 01:02:22 +0000 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 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. |
| 12 | * |
| 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. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "StackFrame.h" |
| 28 | |
| 29 | #include "CodeBlock.h" |
| 30 | #include "DebuggerPrimitives.h" |
ross.kirsling@sony.com | e257a3b | 2020-05-19 23:56:00 +0000 | [diff] [blame] | 31 | #include "JSCellInlines.h" |
fpizlo@apple.com | bc16ddb | 2016-09-06 01:02:22 +0000 | [diff] [blame] | 32 | #include <wtf/text/StringBuilder.h> |
| 33 | |
| 34 | namespace JSC { |
| 35 | |
fpizlo@apple.com | a06a0d2 | 2017-09-10 19:00:03 +0000 | [diff] [blame] | 36 | StackFrame::StackFrame(VM& vm, JSCell* owner, JSCell* callee) |
| 37 | : m_callee(vm, owner, callee) |
fpizlo@apple.com | a06a0d2 | 2017-09-10 19:00:03 +0000 | [diff] [blame] | 38 | { |
| 39 | } |
| 40 | |
keith_miller@apple.com | 0f985ec | 2019-10-23 00:55:38 +0000 | [diff] [blame] | 41 | StackFrame::StackFrame(VM& vm, JSCell* owner, JSCell* callee, CodeBlock* codeBlock, BytecodeIndex bytecodeIndex) |
fpizlo@apple.com | a06a0d2 | 2017-09-10 19:00:03 +0000 | [diff] [blame] | 42 | : m_callee(vm, owner, callee) |
| 43 | , m_codeBlock(vm, owner, codeBlock) |
keith_miller@apple.com | 0f985ec | 2019-10-23 00:55:38 +0000 | [diff] [blame] | 44 | , m_bytecodeIndex(bytecodeIndex) |
fpizlo@apple.com | a06a0d2 | 2017-09-10 19:00:03 +0000 | [diff] [blame] | 45 | { |
| 46 | } |
| 47 | |
jfbastien@apple.com | 17e92c5 | 2017-11-01 06:15:59 +0000 | [diff] [blame] | 48 | StackFrame::StackFrame(Wasm::IndexOrName indexOrName) |
| 49 | : m_wasmFunctionIndexOrName(indexOrName) |
| 50 | , m_isWasmFrame(true) |
| 51 | { |
| 52 | } |
| 53 | |
fpizlo@apple.com | bc16ddb | 2016-09-06 01:02:22 +0000 | [diff] [blame] | 54 | intptr_t StackFrame::sourceID() const |
| 55 | { |
sbarati@apple.com | 812da91 | 2016-12-12 03:11:18 +0000 | [diff] [blame] | 56 | if (!m_codeBlock) |
fpizlo@apple.com | bc16ddb | 2016-09-06 01:02:22 +0000 | [diff] [blame] | 57 | return noSourceID; |
ysuzuki@apple.com | c9db6aa | 2019-02-09 00:29:21 +0000 | [diff] [blame] | 58 | return m_codeBlock->ownerExecutable()->sourceID(); |
fpizlo@apple.com | bc16ddb | 2016-09-06 01:02:22 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | String StackFrame::sourceURL() const |
| 62 | { |
sbarati@apple.com | 5db42f8 | 2017-04-04 22:23:37 +0000 | [diff] [blame] | 63 | if (m_isWasmFrame) |
utatane.tea@gmail.com | 8407763 | 2018-06-23 08:39:34 +0000 | [diff] [blame] | 64 | return "[wasm code]"_s; |
sbarati@apple.com | 5db42f8 | 2017-04-04 22:23:37 +0000 | [diff] [blame] | 65 | |
sbarati@apple.com | 812da91 | 2016-12-12 03:11:18 +0000 | [diff] [blame] | 66 | if (!m_codeBlock) { |
utatane.tea@gmail.com | 8407763 | 2018-06-23 08:39:34 +0000 | [diff] [blame] | 67 | return "[native code]"_s; |
sbarati@apple.com | 812da91 | 2016-12-12 03:11:18 +0000 | [diff] [blame] | 68 | } |
fpizlo@apple.com | bc16ddb | 2016-09-06 01:02:22 +0000 | [diff] [blame] | 69 | |
ysuzuki@apple.com | c9db6aa | 2019-02-09 00:29:21 +0000 | [diff] [blame] | 70 | String sourceURL = m_codeBlock->ownerExecutable()->sourceURL(); |
fpizlo@apple.com | bc16ddb | 2016-09-06 01:02:22 +0000 | [diff] [blame] | 71 | if (!sourceURL.isNull()) |
| 72 | return sourceURL; |
| 73 | return emptyString(); |
| 74 | } |
| 75 | |
| 76 | String StackFrame::functionName(VM& vm) const |
| 77 | { |
jfbastien@apple.com | c139985 | 2017-12-01 02:41:10 +0000 | [diff] [blame] | 78 | if (m_isWasmFrame) |
| 79 | return makeString(m_wasmFunctionIndexOrName); |
sbarati@apple.com | 5db42f8 | 2017-04-04 22:23:37 +0000 | [diff] [blame] | 80 | |
sbarati@apple.com | 812da91 | 2016-12-12 03:11:18 +0000 | [diff] [blame] | 81 | if (m_codeBlock) { |
| 82 | switch (m_codeBlock->codeType()) { |
fpizlo@apple.com | bc16ddb | 2016-09-06 01:02:22 +0000 | [diff] [blame] | 83 | case EvalCode: |
utatane.tea@gmail.com | 8407763 | 2018-06-23 08:39:34 +0000 | [diff] [blame] | 84 | return "eval code"_s; |
fpizlo@apple.com | bc16ddb | 2016-09-06 01:02:22 +0000 | [diff] [blame] | 85 | case ModuleCode: |
utatane.tea@gmail.com | 8407763 | 2018-06-23 08:39:34 +0000 | [diff] [blame] | 86 | return "module code"_s; |
fpizlo@apple.com | bc16ddb | 2016-09-06 01:02:22 +0000 | [diff] [blame] | 87 | case FunctionCode: |
| 88 | break; |
| 89 | case GlobalCode: |
utatane.tea@gmail.com | 8407763 | 2018-06-23 08:39:34 +0000 | [diff] [blame] | 90 | return "global code"_s; |
fpizlo@apple.com | bc16ddb | 2016-09-06 01:02:22 +0000 | [diff] [blame] | 91 | default: |
| 92 | ASSERT_NOT_REACHED(); |
| 93 | } |
| 94 | } |
| 95 | String name; |
sbarati@apple.com | 812da91 | 2016-12-12 03:11:18 +0000 | [diff] [blame] | 96 | if (m_callee) { |
| 97 | if (m_callee->isObject()) |
| 98 | name = getCalculatedDisplayName(vm, jsCast<JSObject*>(m_callee.get())).impl(); |
sbarati@apple.com | 812da91 | 2016-12-12 03:11:18 +0000 | [diff] [blame] | 99 | } |
fpizlo@apple.com | bc16ddb | 2016-09-06 01:02:22 +0000 | [diff] [blame] | 100 | return name.isNull() ? emptyString() : name; |
| 101 | } |
| 102 | |
| 103 | void StackFrame::computeLineAndColumn(unsigned& line, unsigned& column) const |
| 104 | { |
sbarati@apple.com | 812da91 | 2016-12-12 03:11:18 +0000 | [diff] [blame] | 105 | if (!m_codeBlock) { |
fpizlo@apple.com | bc16ddb | 2016-09-06 01:02:22 +0000 | [diff] [blame] | 106 | line = 0; |
| 107 | column = 0; |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | int divot = 0; |
| 112 | int unusedStartOffset = 0; |
| 113 | int unusedEndOffset = 0; |
keith_miller@apple.com | 0f985ec | 2019-10-23 00:55:38 +0000 | [diff] [blame] | 114 | m_codeBlock->expressionRangeForBytecodeIndex(m_bytecodeIndex, divot, unusedStartOffset, unusedEndOffset, line, column); |
fpizlo@apple.com | bc16ddb | 2016-09-06 01:02:22 +0000 | [diff] [blame] | 115 | |
ysuzuki@apple.com | c9db6aa | 2019-02-09 00:29:21 +0000 | [diff] [blame] | 116 | ScriptExecutable* executable = m_codeBlock->ownerExecutable(); |
mark.lam@apple.com | 5ba0779 | 2019-08-27 22:14:52 +0000 | [diff] [blame] | 117 | if (Optional<int> overrideLineNumber = executable->overrideLineNumber(m_codeBlock->vm())) |
ysuzuki@apple.com | 5fbfa40 | 2019-02-04 21:02:27 +0000 | [diff] [blame] | 118 | line = overrideLineNumber.value(); |
fpizlo@apple.com | bc16ddb | 2016-09-06 01:02:22 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | String StackFrame::toString(VM& vm) const |
| 122 | { |
| 123 | StringBuilder traceBuild; |
| 124 | String functionName = this->functionName(vm); |
| 125 | String sourceURL = this->sourceURL(); |
| 126 | traceBuild.append(functionName); |
| 127 | if (!sourceURL.isEmpty()) { |
| 128 | if (!functionName.isEmpty()) |
| 129 | traceBuild.append('@'); |
| 130 | traceBuild.append(sourceURL); |
sbarati@apple.com | 812da91 | 2016-12-12 03:11:18 +0000 | [diff] [blame] | 131 | if (hasLineAndColumnInfo()) { |
fpizlo@apple.com | bc16ddb | 2016-09-06 01:02:22 +0000 | [diff] [blame] | 132 | unsigned line; |
| 133 | unsigned column; |
| 134 | computeLineAndColumn(line, column); |
| 135 | |
| 136 | traceBuild.append(':'); |
| 137 | traceBuild.appendNumber(line); |
| 138 | traceBuild.append(':'); |
| 139 | traceBuild.appendNumber(column); |
| 140 | } |
| 141 | } |
| 142 | return traceBuild.toString().impl(); |
| 143 | } |
| 144 | |
fpizlo@apple.com | bb132ab | 2018-02-15 23:38:15 +0000 | [diff] [blame] | 145 | void StackFrame::visitChildren(SlotVisitor& visitor) |
fpizlo@apple.com | a06a0d2 | 2017-09-10 19:00:03 +0000 | [diff] [blame] | 146 | { |
fpizlo@apple.com | bb132ab | 2018-02-15 23:38:15 +0000 | [diff] [blame] | 147 | if (m_callee) |
| 148 | visitor.append(m_callee); |
| 149 | if (m_codeBlock) |
| 150 | visitor.append(m_codeBlock); |
fpizlo@apple.com | a06a0d2 | 2017-09-10 19:00:03 +0000 | [diff] [blame] | 151 | } |
| 152 | |
fpizlo@apple.com | bc16ddb | 2016-09-06 01:02:22 +0000 | [diff] [blame] | 153 | } // namespace JSC |
| 154 | |