Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
SkSL::SkSLDebugTracePlayer Class Reference

#include <SkSLDebugTracePlayer.h>

Classes

struct  VariableData
 

Public Types

using BreakpointSet = std::unordered_set< int >
 
using LineNumberMap = std::unordered_map< int, int >
 

Public Member Functions

void reset (sk_sp< DebugTracePriv > trace)
 
void step ()
 
void stepOver ()
 
void stepOut ()
 
void run ()
 
void setBreakpoints (std::unordered_set< int > breakpointLines)
 
void addBreakpoint (int line)
 
void removeBreakpoint (int line)
 
const BreakpointSetgetBreakpoints ()
 
bool traceHasCompleted () const
 
bool atBreakpoint () const
 
size_t cursor ()
 
int32_t getCurrentLine () const
 
int32_t getCurrentLineInStackFrame (int stackFrameIndex) const
 
std::vector< intgetCallStack () const
 
int getStackDepth () const
 
const LineNumberMapgetLineNumbersReached () const
 
std::vector< VariableDatagetLocalVariables (int stackFrameIndex) const
 
std::vector< VariableDatagetGlobalVariables () const
 

Detailed Description

Plays back a SkSL debug trace, allowing its contents to be viewed like a traditional debugger.

Definition at line 28 of file SkSLDebugTracePlayer.h.

Member Typedef Documentation

◆ BreakpointSet

using SkSL::SkSLDebugTracePlayer::BreakpointSet = std::unordered_set<int>

Definition at line 55 of file SkSLDebugTracePlayer.h.

◆ LineNumberMap

using SkSL::SkSLDebugTracePlayer::LineNumberMap = std::unordered_map<int, int>

Returns every line number reached inside this debug trace, along with the remaining number of times that this trace will reach it. e.g. {100, 2} means line 100 will be reached twice.

Definition at line 83 of file SkSLDebugTracePlayer.h.

Member Function Documentation

◆ addBreakpoint()

void SkSL::SkSLDebugTracePlayer::addBreakpoint ( int  line)

Definition at line 131 of file SkSLDebugTracePlayer.cpp.

131 {
132 fBreakpointLines.insert(line);
133}

◆ atBreakpoint()

bool SkSL::SkSLDebugTracePlayer::atBreakpoint ( ) const

Returns true if there is a breakpoint set at the current line.

Definition at line 123 of file SkSLDebugTracePlayer.cpp.

123 {
124 return fBreakpointLines.count(this->getCurrentLine());
125}

◆ cursor()

size_t SkSL::SkSLDebugTracePlayer::cursor ( )
inline

Retrieves the cursor position.

Definition at line 65 of file SkSLDebugTracePlayer.h.

65{ return fCursor; }

◆ getBreakpoints()

const BreakpointSet & SkSL::SkSLDebugTracePlayer::getBreakpoints ( )
inline

Definition at line 56 of file SkSLDebugTracePlayer.h.

56{ return fBreakpointLines; }

◆ getCallStack()

std::vector< int > SkSL::SkSLDebugTracePlayer::getCallStack ( ) const

Returns the call stack as an array of FunctionInfo indices.

Definition at line 139 of file SkSLDebugTracePlayer.cpp.

139 {
140 SkASSERT(!fStack.empty());
141 std::vector<int> funcs;
142 funcs.reserve(fStack.size() - 1);
143 for (size_t index = 1; index < fStack.size(); ++index) {
144 funcs.push_back(fStack[index].fFunction);
145 }
146 return funcs;
147}
#define SkASSERT(cond)
Definition SkAssert.h:116

◆ getCurrentLine()

int32_t SkSL::SkSLDebugTracePlayer::getCurrentLine ( ) const

Retrieves the current line.

Definition at line 109 of file SkSLDebugTracePlayer.cpp.

109 {
110 SkASSERT(!fStack.empty());
111 return fStack.back().fLine;
112}

◆ getCurrentLineInStackFrame()

int32_t SkSL::SkSLDebugTracePlayer::getCurrentLineInStackFrame ( int  stackFrameIndex) const

Retrieves the current line for a given stack frame.

Definition at line 114 of file SkSLDebugTracePlayer.cpp.

114 {
115 // The first entry on the stack is the "global" frame before we enter main, so offset our index
116 // by one to account for it.
117 ++stackFrameIndex;
118 SkASSERT(stackFrameIndex > 0);
119 SkASSERT((size_t)stackFrameIndex < fStack.size());
120 return fStack[stackFrameIndex].fLine;
121}

◆ getGlobalVariables()

std::vector< SkSLDebugTracePlayer::VariableData > SkSL::SkSLDebugTracePlayer::getGlobalVariables ( ) const

Definition at line 182 of file SkSLDebugTracePlayer.cpp.

182 {
183 if (fStack.empty()) {
184 return {};
185 }
186 return this->getVariablesForDisplayMask(fStack.front().fDisplayMask);
187}

◆ getLineNumbersReached()

const LineNumberMap & SkSL::SkSLDebugTracePlayer::getLineNumbersReached ( ) const
inline

Definition at line 84 of file SkSLDebugTracePlayer.h.

84{ return fLineNumbers; }

◆ getLocalVariables()

std::vector< SkSLDebugTracePlayer::VariableData > SkSL::SkSLDebugTracePlayer::getLocalVariables ( int  stackFrameIndex) const

Definition at line 170 of file SkSLDebugTracePlayer.cpp.

171 {
172 // The first entry on the stack is the "global" frame before we enter main, so offset our index
173 // by one to account for it.
174 ++stackFrameIndex;
175 if (stackFrameIndex <= 0 || (size_t)stackFrameIndex >= fStack.size()) {
176 SkDEBUGFAILF("stack frame %d doesn't exist", stackFrameIndex - 1);
177 return {};
178 }
179 return this->getVariablesForDisplayMask(fStack[stackFrameIndex].fDisplayMask);
180}
#define SkDEBUGFAILF(fmt,...)
Definition SkAssert.h:119

◆ getStackDepth()

int SkSL::SkSLDebugTracePlayer::getStackDepth ( ) const

Returns the size of the call stack.

Definition at line 149 of file SkSLDebugTracePlayer.cpp.

149 {
150 SkASSERT(!fStack.empty());
151 return fStack.size() - 1;
152}

◆ removeBreakpoint()

void SkSL::SkSLDebugTracePlayer::removeBreakpoint ( int  line)

Definition at line 135 of file SkSLDebugTracePlayer.cpp.

135 {
136 fBreakpointLines.erase(line);
137}

◆ reset()

void SkSL::SkSLDebugTracePlayer::reset ( sk_sp< DebugTracePriv trace)

Resets playback to the start of the trace. Breakpoints are not cleared.

Definition at line 18 of file SkSLDebugTracePlayer.cpp.

18 {
19 size_t nslots = debugTrace ? debugTrace->fSlotInfo.size() : 0;
20 fDebugTrace = debugTrace;
21 fCursor = 0;
22 fScope = 0;
23 fSlots.clear();
24 fSlots.resize(nslots, {/*fValue=*/0,
25 /*fScope=*/INT_MAX,
26 /*fWriteTime=*/0});
27 fStack.clear();
28 fStack.push_back({/*fFunction=*/-1,
29 /*fLine=*/-1,
30 /*fDisplayMask=*/SkBitSet(nslots)});
31 fDirtyMask.emplace(nslots);
32 fReturnValues.emplace(nslots);
33
34 if (fDebugTrace) {
35 for (size_t slotIdx = 0; slotIdx < nslots; ++slotIdx) {
36 if (fDebugTrace->fSlotInfo[slotIdx].fnReturnValue >= 0) {
37 fReturnValues->set(slotIdx);
38 }
39 }
40
41 for (const TraceInfo& trace : fDebugTrace->fTraceInfo) {
42 if (trace.op == TraceInfo::Op::kLine) {
43 fLineNumbers[trace.data[0]] += 1;
44 }
45 }
46 }
47}

◆ run()

void SkSL::SkSLDebugTracePlayer::run ( )

Advances the simulation until we hit a breakpoint, or the trace completes.

Definition at line 84 of file SkSLDebugTracePlayer.cpp.

84 {
85 this->tidyState();
86 while (!this->traceHasCompleted()) {
87 if (this->execute(fCursor++)) {
88 if (this->atBreakpoint()) {
89 break;
90 }
91 }
92 }
93}

◆ setBreakpoints()

void SkSL::SkSLDebugTracePlayer::setBreakpoints ( std::unordered_set< int breakpointLines)

Breakpoints will force the simulation to stop whenever a desired line is reached.

Definition at line 127 of file SkSLDebugTracePlayer.cpp.

127 {
128 fBreakpointLines = std::move(breakpointLines);
129}

◆ step()

void SkSL::SkSLDebugTracePlayer::step ( )

Advances the simulation to the next Line op.

Definition at line 49 of file SkSLDebugTracePlayer.cpp.

49 {
50 this->tidyState();
51 while (!this->traceHasCompleted()) {
52 if (this->execute(fCursor++)) {
53 break;
54 }
55 }
56}

◆ stepOut()

void SkSL::SkSLDebugTracePlayer::stepOut ( )

Advances the simulation until we exit from the current stack frame. Breakpoints will also stop the simulation even if we haven't left the stack frame.

Definition at line 71 of file SkSLDebugTracePlayer.cpp.

71 {
72 this->tidyState();
73 size_t initialStackDepth = fStack.size();
74 while (!this->traceHasCompleted()) {
75 if (this->execute(fCursor++)) {
76 bool hasEscapedFromInitialStackDepth = (fStack.size() < initialStackDepth);
77 if (hasEscapedFromInitialStackDepth || this->atBreakpoint()) {
78 break;
79 }
80 }
81 }
82}

◆ stepOver()

void SkSL::SkSLDebugTracePlayer::stepOver ( )

Advances the simulation to the next Line op, skipping past matched Enter/Exit pairs. Breakpoints will also stop the simulation even if we haven't reached an Exit.

Definition at line 58 of file SkSLDebugTracePlayer.cpp.

58 {
59 this->tidyState();
60 size_t initialStackDepth = fStack.size();
61 while (!this->traceHasCompleted()) {
62 bool canEscapeFromThisStackDepth = (fStack.size() <= initialStackDepth);
63 if (this->execute(fCursor++)) {
64 if (canEscapeFromThisStackDepth || this->atBreakpoint()) {
65 break;
66 }
67 }
68 }
69}

◆ traceHasCompleted()

bool SkSL::SkSLDebugTracePlayer::traceHasCompleted ( ) const

Returns true if we have reached the end of the trace.

Definition at line 105 of file SkSLDebugTracePlayer.cpp.

105 {
106 return !fDebugTrace || fCursor >= fDebugTrace->fTraceInfo.size();
107}

The documentation for this class was generated from the following files: