forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiagStackFrame.cpp
More file actions
354 lines (288 loc) · 11 KB
/
DiagStackFrame.cpp
File metadata and controls
354 lines (288 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "RuntimeDebugPch.h"
#include "Language/JavascriptFunctionArgIndex.h"
#include "Language/InterpreterStackFrame.h"
namespace Js
{
DiagStackFrame::DiagStackFrame(int frameIndex) :
frameIndex(frameIndex)
{
Assert(frameIndex >= 0);
}
// Returns whether or not this frame is on the top of the callstack.
bool DiagStackFrame::IsTopFrame()
{
return this->frameIndex == 0 && GetScriptContext()->GetDebugContext()->GetProbeContainer()->IsPrimaryBrokenToDebuggerContext();
}
ScriptFunction* DiagStackFrame::GetScriptFunction()
{
return ScriptFunction::FromVar(GetJavascriptFunction());
}
FunctionBody* DiagStackFrame::GetFunction()
{
return GetJavascriptFunction()->GetFunctionBody();
}
ScriptContext* DiagStackFrame::GetScriptContext()
{
return GetJavascriptFunction()->GetScriptContext();
}
PCWSTR DiagStackFrame::GetDisplayName()
{
return GetFunction()->GetExternalDisplayName();
}
bool DiagStackFrame::IsInterpreterFrame()
{
return false;
}
InterpreterStackFrame* DiagStackFrame::AsInterpreterFrame()
{
AssertMsg(FALSE, "AsInterpreterFrame called for non-interpreter frame.");
return nullptr;
}
ArenaAllocator * DiagStackFrame::GetArena()
{
Assert(GetScriptContext() != NULL);
return GetScriptContext()->GetThreadContext()->GetDebugManager()->GetDiagnosticArena()->Arena();
}
FrameDisplay * DiagStackFrame::GetFrameDisplay()
{
FrameDisplay *display = NULL;
Assert(this->GetFunction() != NULL);
RegSlot frameDisplayReg = this->GetFunction()->GetFrameDisplayRegister();
if (frameDisplayReg != Js::Constants::NoRegister && frameDisplayReg != 0)
{
display = (FrameDisplay*)this->GetNonVarRegValue(frameDisplayReg);
}
else
{
display = this->GetScriptFunction()->GetEnvironment();
}
return display;
}
Var DiagStackFrame::GetScopeObjectFromFrameDisplay(uint index)
{
FrameDisplay * display = GetFrameDisplay();
return (display != NULL && display->GetLength() > index) ? display->GetItem(index) : NULL;
}
Var DiagStackFrame::GetRootObject()
{
Assert(this->GetFunction());
return this->GetFunction()->LoadRootObject();
}
Var DiagStackFrame::GetInnerScopeFromRegSlot(RegSlot location)
{
return GetNonVarRegValue(location);
}
DiagInterpreterStackFrame::DiagInterpreterStackFrame(InterpreterStackFrame* frame, int frameIndex) :
DiagStackFrame(frameIndex),
m_interpreterFrame(frame)
{
Assert(m_interpreterFrame != NULL);
AssertMsg(m_interpreterFrame->GetScriptContext() && m_interpreterFrame->GetScriptContext()->IsScriptContextInDebugMode(),
"This only supports interpreter stack frames running in debug mode.");
}
JavascriptFunction* DiagInterpreterStackFrame::GetJavascriptFunction()
{
return m_interpreterFrame->GetJavascriptFunction();
}
ScriptContext* DiagInterpreterStackFrame::GetScriptContext()
{
return m_interpreterFrame->GetScriptContext();
}
int DiagInterpreterStackFrame::GetByteCodeOffset()
{
return m_interpreterFrame->GetReader()->GetCurrentOffset();
}
// Address on stack that belongs to current frame.
// Currently we only use this to determine which of given frames is above/below another one.
DWORD_PTR DiagInterpreterStackFrame::GetStackAddress()
{
return m_interpreterFrame->GetStackAddress();
}
bool DiagInterpreterStackFrame::IsInterpreterFrame()
{
return true;
}
InterpreterStackFrame* DiagInterpreterStackFrame::AsInterpreterFrame()
{
return m_interpreterFrame;
}
Var DiagInterpreterStackFrame::GetRegValue(RegSlot slotId, bool allowTemp)
{
return m_interpreterFrame->GetReg(slotId);
}
Var DiagInterpreterStackFrame::GetNonVarRegValue(RegSlot slotId)
{
return m_interpreterFrame->GetNonVarReg(slotId);
}
void DiagInterpreterStackFrame::SetRegValue(RegSlot slotId, Var value)
{
m_interpreterFrame->SetReg(slotId, value);
}
Var DiagInterpreterStackFrame::GetArgumentsObject()
{
return m_interpreterFrame->GetArgumentsObject();
}
Var DiagInterpreterStackFrame::CreateHeapArguments()
{
return m_interpreterFrame->CreateHeapArguments(GetScriptContext());
}
FrameDisplay * DiagInterpreterStackFrame::GetFrameDisplay()
{
return m_interpreterFrame->GetFrameDisplayForNestedFunc();
}
Var DiagInterpreterStackFrame::GetInnerScopeFromRegSlot(RegSlot location)
{
return m_interpreterFrame->InnerScopeFromRegSlot(location);
}
#if ENABLE_NATIVE_CODEGEN
DiagNativeStackFrame::DiagNativeStackFrame(
ScriptFunction* function,
int byteCodeOffset,
void* stackAddr,
void *codeAddr,
int frameIndex) :
DiagStackFrame(frameIndex),
m_function(function),
m_byteCodeOffset(byteCodeOffset),
m_stackAddr(stackAddr),
m_localVarSlotsOffset(InvalidOffset),
m_localVarChangedOffset(InvalidOffset)
{
Assert(m_stackAddr != NULL);
AssertMsg(m_function && m_function->GetScriptContext() && m_function->GetScriptContext()->IsScriptContextInDebugMode(),
"This only supports functions in debug mode.");
FunctionEntryPointInfo * entryPointInfo = GetFunction()->GetEntryPointFromNativeAddress((DWORD_PTR)codeAddr);
if (entryPointInfo)
{
m_localVarSlotsOffset = entryPointInfo->localVarSlotsOffset;
m_localVarChangedOffset = entryPointInfo->localVarChangedOffset;
}
else
{
AssertMsg(FALSE, "Failed to get entry point for native address. Most likely the frame is old/gone.");
}
OUTPUT_TRACE(Js::DebuggerPhase, _u("DiagNativeStackFrame::DiagNativeStackFrame: e.p(addr %p)=%p varOff=%d changedOff=%d\n"), codeAddr, entryPointInfo, m_localVarSlotsOffset, m_localVarChangedOffset);
}
JavascriptFunction* DiagNativeStackFrame::GetJavascriptFunction()
{
return m_function;
}
ScriptContext* DiagNativeStackFrame::GetScriptContext()
{
return m_function->GetScriptContext();
}
int DiagNativeStackFrame::GetByteCodeOffset()
{
return m_byteCodeOffset;
}
// Address on stack that belongs to current frame.
// Currently we only use this to determine which of given frames is above/below another one.
DWORD_PTR DiagNativeStackFrame::GetStackAddress()
{
return reinterpret_cast<DWORD_PTR>(m_stackAddr);
}
Var DiagNativeStackFrame::GetRegValue(RegSlot slotId, bool allowTemp)
{
Js::Var *varPtr = GetSlotOffsetLocation(slotId, allowTemp);
return (varPtr != NULL) ? *varPtr : NULL;
}
Var * DiagNativeStackFrame::GetSlotOffsetLocation(RegSlot slotId, bool allowTemp)
{
Assert(GetFunction() != NULL);
int32 slotOffset;
if (GetFunction()->GetSlotOffset(slotId, &slotOffset, allowTemp))
{
Assert(m_localVarSlotsOffset != InvalidOffset);
slotOffset = m_localVarSlotsOffset + slotOffset;
// We will have the var offset only (which is always the Var size. With TypeSpecialization, below will change to accommodate double offset.
return (Js::Var *)(((char *)m_stackAddr) + slotOffset);
}
Assert(false);
return NULL;
}
Var DiagNativeStackFrame::GetNonVarRegValue(RegSlot slotId)
{
return GetRegValue(slotId);
}
void DiagNativeStackFrame::SetRegValue(RegSlot slotId, Var value)
{
Js::Var *varPtr = GetSlotOffsetLocation(slotId);
Assert(varPtr != NULL);
// First assign the value
*varPtr = value;
Assert(m_localVarChangedOffset != InvalidOffset);
// Now change the bit in the stack which tells that current stack values got changed.
char *stackOffset = (((char *)m_stackAddr) + m_localVarChangedOffset);
Assert(*stackOffset == 0 || *stackOffset == FunctionBody::LocalsChangeDirtyValue);
*stackOffset = FunctionBody::LocalsChangeDirtyValue;
}
Var DiagNativeStackFrame::GetArgumentsObject()
{
return (Var)((void **)m_stackAddr)[JavascriptFunctionArgIndex_ArgumentsObject];
}
Var DiagNativeStackFrame::CreateHeapArguments()
{
// We would be creating the arguments object if there is no default arguments object present.
Assert(GetArgumentsObject() == NULL);
CallInfo const * callInfo = (CallInfo const *)&(((void **)m_stackAddr)[JavascriptFunctionArgIndex_CallInfo]);
// At the least we will have 'this' by default.
Assert(callInfo->Count > 0);
// Get the passed parameter's position (which is starting from 'this')
Var * inParams = (Var *)&(((void **)m_stackAddr)[JavascriptFunctionArgIndex_This]);
return JavascriptOperators::LoadHeapArguments(
m_function,
callInfo->Count - 1,
&inParams[1],
GetScriptContext()->GetLibrary()->GetNull(),
(PropertyId*)GetScriptContext()->GetLibrary()->GetNull(),
GetScriptContext(),
/* formalsAreLetDecls */ false);
}
#endif
DiagRuntimeStackFrame::DiagRuntimeStackFrame(JavascriptFunction* function, PCWSTR displayName, void* stackAddr, int frameIndex):
DiagStackFrame(frameIndex),
m_function(function),
m_displayName(displayName),
m_stackAddr(stackAddr)
{
}
JavascriptFunction* DiagRuntimeStackFrame::GetJavascriptFunction()
{
return m_function;
}
PCWSTR DiagRuntimeStackFrame::GetDisplayName()
{
return m_displayName;
}
DWORD_PTR DiagRuntimeStackFrame::GetStackAddress()
{
return reinterpret_cast<DWORD_PTR>(m_stackAddr);
}
int DiagRuntimeStackFrame::GetByteCodeOffset()
{
return 0;
}
Var DiagRuntimeStackFrame::GetRegValue(RegSlot slotId, bool allowTemp)
{
return nullptr;
}
Var DiagRuntimeStackFrame::GetNonVarRegValue(RegSlot slotId)
{
return nullptr;
}
void DiagRuntimeStackFrame::SetRegValue(RegSlot slotId, Var value)
{
}
Var DiagRuntimeStackFrame::GetArgumentsObject()
{
return nullptr;
}
Var DiagRuntimeStackFrame::CreateHeapArguments()
{
return nullptr;
}
} // namespace Js