Skip to content

Commit 47a815d

Browse files
committed
Add 'Scanning the stack with frame_descr' slide
Clarify the stack scanning technique
1 parent c5600f9 commit 47a815d

File tree

5 files changed

+144
-18
lines changed

5 files changed

+144
-18
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
/presentation/src/ocaml/domain_state.h
1313
/presentation/src/ocaml/domain_state_abbr.h
14+
/presentation/src/ocaml/domain_state_backtrace.h
1415

1516

1617
/src/**/*.annot

presentation/backtrace.tex

+43-17
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,12 @@ \subsection{One advantage of raising with debugging information}
134134
\mintc[firstline=190,lastline=192,highlightlines={191-192}]{../ocaml/runtime/amd64.S}
135135
\mintc[firstline=234,lastline=237,highlightlines={235-237}]{../ocaml/runtime/amd64.S}
136136
}
137-
\onslide*<1>{\listCamlRaiseExn[highlightlines=705]{}}
138-
\onslide*<2>{\listCamlRaiseExn[highlightlines={707-708}]{}}
139-
\onslide*<3>{\listCamlRaiseExn[highlightlines={712-714}]{}}
140-
\onslide*<4>{\listCamlRaiseExn[highlightlines={715-720}]{}}
141-
\onslide*<5>{\providecommand\step{1}\input{diagrams/backtrace/backtrace.tex}}
142-
\onslide*<6>{\providecommand\step{2}\input{diagrams/backtrace/backtrace.tex}}
137+
\onslide*<1>{\listCamlRaiseExn[highlightlines=705]{}}%
138+
\onslide*<2>{\listCamlRaiseExn[highlightlines={707-708}]{}}%
139+
\onslide*<3>{\listCamlRaiseExn[highlightlines={712-714}]{}}%
140+
\onslide*<4>{\listCamlRaiseExn[highlightlines={715-720}]{}}%
141+
\onslide*<5>{\providecommand\step{1}\input{diagrams/backtrace/backtrace.tex}}%
142+
\onslide*<6>{\providecommand\step{2}\input{diagrams/backtrace/backtrace.tex}}%
143143
\end{column}
144144
\end{columns}
145145
\end{frame}
@@ -212,6 +212,32 @@ \subsection{One advantage of raising with debugging information}
212212
\end{columns}
213213
\end{frame}
214214

215+
\begin{frame}{Backtraces}{Scanning the stack with \typename{frame\_descr}}
216+
\begin{columns}[c]
217+
\begin{column}{0.5\textwidth}
218+
\begin{itemize}
219+
\item Given the return address of the code that raises the exception by calling \funcname{caml\_raise\_exn} (\funcarg{pc} argument of \funcname{caml\_stash\_backtrace})
220+
\item And the position of the stack pointer (\funcarg{sp} argument of \funcname{caml\_stash\_backtrace})
221+
\item The frame size given by \typename{frame\_descr}.\funcarg{frame\_size}, allows to find the end of the previous frame
222+
\item And the return address of the caller of this function
223+
\bigskip
224+
\onslide<3->{
225+
\item Note that traps (here the reddish \funcname{ExnA}, \funcname{ExnB} and \funcname{ExnC} blocks) belong to the frame that installed them, and so the frame size changes when traps are removed
226+
}
227+
\end{itemize}
228+
\end{column}
229+
\begin{column}{0.5\textwidth}
230+
\raggedleft
231+
\onslide*<1>{\providecommand\step{2}\input{diagrams/backtrace/backtrace.tex}}%
232+
\onslide*<2>{\providecommand\step{1}\input{diagrams/backtrace/scanstack.tex}}%
233+
\onslide*<3>{\providecommand\step{2}\input{diagrams/backtrace/scanstack.tex}}%
234+
\onslide*<4>{\providecommand\step{3}\input{diagrams/backtrace/scanstack.tex}}%
235+
\onslide*<5>{\providecommand\step{4}\input{diagrams/backtrace/scanstack.tex}}%
236+
\onslide*<6>{\providecommand\step{5}\input{diagrams/backtrace/scanstack.tex}}%
237+
\end{column}
238+
\end{columns}
239+
\end{frame}
240+
215241
% Duplicate of previous-previous slide
216242
\begin{frame}{Backtraces}{Continuing on \funcname{caml\_stash\_backtrace}}
217243
\begin{columns}[c]
@@ -241,8 +267,8 @@ \subsection{One advantage of raising with debugging information}
241267
\begin{column}{0.5\textwidth}
242268
\raggedleft
243269
\onslide*<1>{\listStashBacktrace[highlightlines={114-115}]{}}
244-
\onslide*<2>{\providecommand\step{3}\input{diagrams/backtrace/backtrace.tex}}
245-
\onslide*<3>{\providecommand\step{4}\input{diagrams/backtrace/backtrace.tex}}
270+
\onslide*<2>{\providecommand\step{3}\input{diagrams/backtrace/backtrace.tex}}%
271+
\onslide*<3>{\providecommand\step{4}\input{diagrams/backtrace/backtrace.tex}}%
246272
\end{column}
247273
\end{columns}
248274
\end{frame}
@@ -385,15 +411,15 @@ \subsection{One advantage of raising with debugging information}
385411
\end{column}
386412
\begin{column}{0.45\textwidth}
387413
\raggedleft
388-
\onslide*<1>{\providecommand\step{6}\input{diagrams/backtrace/backtrace.tex}}
389-
\onslide*<2>{\providecommand\step{6}\input{diagrams/backtrace/backtrace.tex}}
390-
\onslide*<3>{\providecommand\step{7}\input{diagrams/backtrace/backtrace.tex}}
391-
\onslide*<4>{\providecommand\step{8}\input{diagrams/backtrace/backtrace.tex}}
392-
\onslide*<5>{\providecommand\step{9}\input{diagrams/backtrace/backtrace.tex}}
393-
\onslide*<6>{\providecommand\step{10}\input{diagrams/backtrace/backtrace.tex}}
394-
\onslide*<7>{\providecommand\step{11}\input{diagrams/backtrace/backtrace.tex}}
395-
\onslide*<8>{\providecommand\step{12}\input{diagrams/backtrace/backtrace.tex}}
396-
\onslide*<9>{\providecommand\step{13}\input{diagrams/backtrace/backtrace.tex}}
414+
\onslide*<1>{\providecommand\step{6}\input{diagrams/backtrace/backtrace.tex}}%
415+
\onslide*<2>{\providecommand\step{6}\input{diagrams/backtrace/backtrace.tex}}%
416+
\onslide*<3>{\providecommand\step{7}\input{diagrams/backtrace/backtrace.tex}}%
417+
\onslide*<4>{\providecommand\step{8}\input{diagrams/backtrace/backtrace.tex}}%
418+
\onslide*<5>{\providecommand\step{9}\input{diagrams/backtrace/backtrace.tex}}%
419+
\onslide*<6>{\providecommand\step{10}\input{diagrams/backtrace/backtrace.tex}}%
420+
\onslide*<7>{\providecommand\step{11}\input{diagrams/backtrace/backtrace.tex}}%
421+
\onslide*<8>{\providecommand\step{12}\input{diagrams/backtrace/backtrace.tex}}%
422+
\onslide*<9>{\providecommand\step{13}\input{diagrams/backtrace/backtrace.tex}}%
397423
\end{column}
398424
\end{columns}
399425
\end{frame}

presentation/diagrams/backtrace/backtrace.tex

-1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,5 @@
153153
\showRegister{trapsp}{\stashBacktraceArgTrapSPvC}
154154
}{}
155155

156-
157156
\end{stackDiagram}
158157
\end{tikzpicture}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
\begin{tikzpicture}[font=\sffamily\tiny]
2+
\input{../src/backtrace/gdb.out}
3+
4+
\newcommand\trapExnAEnd{\xinteval{\trapExnABegin - 2 * \wordSize}}
5+
\newcommand\trapExnBEnd{\xinteval{\trapExnBBegin - 2 * \wordSize}}
6+
\newcommand\trapExnCEnd{\xinteval{\trapExnCBegin - 2 * \wordSize}}
7+
8+
\begin{stackDiagram}[yFactor=0.35,showAddress=true]{\frameMainBegin}{\frameDefinitelyEnd}
9+
\callStack
10+
11+
\begin{funFrame}[name=main,color=GreenYellow]{\frameMainBegin}{\frameMainEnd}
12+
\funReturnAddr{\frameMainRetaddr}
13+
\frameLocal{1}{\frameMainLocalOne}
14+
\end{funFrame}
15+
16+
\trapFrame[name=ExnC,handler=\trapExnCHandler,next=\trapExnCNext,color=WildStrawberry]{\trapExnCBegin}
17+
\coordAtRight{exnCtrap}{\exnHandlerAfterExnCTrap}
18+
19+
20+
\trapFrame[name=ExnB,handler=\trapExnBHandler,next=\trapExnBNext,color=OrangeRed]{\trapExnBBegin}
21+
\coordAtRight{exnBtrap}{\exnHandlerAfterExnBTrap}
22+
23+
\begin{funFrame}[name=maybe,color=YellowGreen]{\frameMaybeBegin}{\frameMaybeEnd}
24+
\funReturnAddr{\frameMaybeRetaddr}
25+
\frameLocal{1}{\frameMaybeLocalOne}
26+
\end{funFrame}
27+
28+
\begin{funFrame}[name=probably,color=Green]{\frameProbablyBegin}{\frameProbablyEnd}
29+
\funReturnAddr{\frameProbablyRetaddr}
30+
\frameLocal{1}{\frameProbablyLocalOne}
31+
\end{funFrame}
32+
33+
34+
\trapFrame[name=ExnA,handler=\trapExnAHandler,next=\trapExnANext,color=Red]{\trapExnABegin}
35+
\coordAtRight{exnAtrap}{\exnHandlerAfterExnATrap}
36+
37+
\begin{funFrame}[name=definitely,color=JungleGreen]{\frameDefinitelyBegin}{\frameDefinitelyEnd}
38+
\funReturnAddr{\frameDefinitelyRetaddr}
39+
\frameLocal{1}{\frameDefinitelyLocalOne}
40+
\end{funFrame}
41+
42+
\begin{funFrame}[color=SeaGreen]{\frameCamlRaiseExnBegin}{\frameCamlRaiseExnEnd}
43+
\funReturnAddr{\frameCamlRaiseExnRetaddr}
44+
\end{funFrame}
45+
46+
47+
\coordinate (bottom) at ($(stackBL) + (0,-0.25)$);
48+
\domainStateBacktrace[pos=(bottom),yFactor=0.03]{\exnHandlerAfterExnATrap}{}{0}
49+
50+
51+
\newcommand\lineToNextFrame[2]{
52+
% #1 -> from
53+
% #2 -> to
54+
55+
\tikzmath{
56+
\Ax = 0;
57+
\Ay = \yOffset{#1}; \Ay = \Ay + 0.5 * \yFactor;
58+
\Bx = 0;
59+
\By = \yOffset{#2}; \By = \By + 0.5 * \yFactor;
60+
\Cx = 0;
61+
\Cy = \yOffset{#2}; \Cy = \Cy - 0.5 * \yFactor;
62+
\Lx = -0.08 * \xFactor;
63+
\Ly = (\Ay + \By) / 2;
64+
}
65+
66+
\node (plus) [draw,circle,fill=white,inner sep=0,label={above,rotate=90:framesize}] at (\Lx,\Ly) { + };
67+
68+
\draw [out=180,in=-90] (\Ax,\Ay) to (plus.south);
69+
\draw [out=90,in=180] (plus.north) to (\Bx,\By);
70+
71+
\draw [->,>=stealth,out=180,in=180,looseness=1.5] (\Bx,\By) to (\Cx,\Cy);
72+
73+
\coordinate (TL) at ($ (0,\Cy+0.5*\yFactor) + (0.06,-0.06) $);
74+
\coordinate (BR) at ($ (\xFactor,\Cy-0.5*\yFactor) + (-0.4,0.06) $);
75+
\node [draw,thick,color=red,rounded corners=2,fit=(TL) (BR),inner sep=0] {};
76+
}
77+
78+
\ifthenelse{\step<3}{
79+
\lineToNextFrame{\frameDefinitelyEnd}{\trapExnAEnd}
80+
}{}
81+
82+
\ifthenelse{\step=2}{
83+
\lineToNextFrame{\trapExnAEnd}{\frameMaybeEnd}
84+
}{}
85+
86+
\ifthenelse{\step>2}{
87+
\lineToNextFrame{\frameProbablyEnd}{\frameMaybeEnd}
88+
}{}
89+
90+
\ifthenelse{\step>3}{
91+
\lineToNextFrame{\frameMaybeEnd}{\trapExnBEnd}
92+
}{}
93+
94+
\ifthenelse{\step=5}{
95+
\lineToNextFrame{\trapExnBEnd}{\frameEntryEnd}
96+
}{}
97+
98+
\end{stackDiagram}
99+
\end{tikzpicture}

presentation/presentation.tex

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
\usetikzlibrary{matrix}
2727
\usetikzlibrary{positioning}
2828
\usetikzlibrary{shapes.geometric}
29+
\usetikzlibrary{fit}
2930

3031

3132
\usemintedstyle{pastie}

0 commit comments

Comments
 (0)