Skip to content

Commit 1a45a98

Browse files
committed
Add 'Backtraces' chapter
1 parent d515121 commit 1a45a98

File tree

9 files changed

+475
-157
lines changed

9 files changed

+475
-157
lines changed

presentation/Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ presentation:=${tex_source:.tex=.pdf}
33

44
ocaml_dir:=../ocaml
55
sources_dir:=src
6-
sources:=${sources_dir}/ocaml/domain_state.h ${sources_dir}/ocaml/domain_state_abbr.h
6+
sources:=${sources_dir}/ocaml/domain_state.h \
7+
${sources_dir}/ocaml/domain_state_abbr.h \
8+
${sources_dir}/ocaml/domain_state_backtrace.h
79

810

911
.PHONY: all
@@ -39,3 +41,5 @@ ${sources_dir}/ocaml/domain_state.h:
3941
${sources_dir}/ocaml/domain_state_abbr.h: ${sources_dir}/ocaml/domain_state.h
4042
sed -nf ${sources_dir}/domain_state_abbr.sed >$@ <$<
4143

44+
${sources_dir}/ocaml/domain_state_backtrace.h: ${sources_dir}/ocaml/domain_state.h
45+
sed -nf ${sources_dir}/domain_state_backtrace.sed >$@ <$<

presentation/backtrace.tex

+382-119
Large diffs are not rendered by default.

presentation/diagrams/backtrace/backtrace.tex

+33-20
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
\frameLocal{1}{\frameMainLocalOne}
1414
\end{funFrame}
1515

16-
1716
\ifthenelse{\step<13}{
1817
\trapFrame[name=ExnC,handler=\trapExnCHandler,next=\trapExnCNext,color=WildStrawberry]{\trapExnCBegin}
1918
\coordAtRight{exnCtrap}{\exnHandlerAfterExnCTrap}
@@ -47,7 +46,7 @@
4746
\frameLocal{1}{\frameDefinitelyLocalOne}
4847
\end{funFrame}
4948

50-
\begin{funFrame}[name=raise,color=SeaGreen]{\frameCamlRaiseExnBegin}{\frameCamlRaiseExnEnd}
49+
\begin{funFrame}[color=SeaGreen]{\frameCamlRaiseExnBegin}{\frameCamlRaiseExnEnd}
5150
\funReturnAddr{\frameCamlRaiseExnRetaddr}
5251
\end{funFrame}
5352
}{}
@@ -66,10 +65,10 @@
6665
}{}
6766

6867

69-
\coordinate (bottom) at ($(stackBL) + (0,-0.5)$);
68+
\coordinate (bottom) at ($(stackBL) + (0,-0.25)$);
7069

7170

72-
\ifthenelse{\step=1}{
71+
\ifthenelse{\step=1 \or \step=2}{
7372
\domainStateBacktrace[pos=(bottom),yFactor=0.03]{\exnHandlerAfterExnATrap}{}{0}
7473
\draw [->,>=latex] (exnHandlerRight.east) to [out=0,in=0] (exnAtrap.east);
7574
}{}
@@ -90,56 +89,70 @@
9089
\draw [->,>=latex] (exnHandlerRight.east) to [out=0,in=0] (exnCtrap.east);
9190
}{}
9291

93-
\ifthenelse{\step>1 \and \step<5}{
94-
\showRegister{sp}{\stashBacktraceArgSPvA}
95-
\showRegister{trapsp}{\stashBacktraceArgTrapSPvA}
96-
}{}
97-
9892
\ifthenelse{\step=2}{
99-
\domainStateBacktrace[pos=(bottom),yFactor=0.03]{\exnHandlerAfterExnATrap}{}{0}
93+
\showRegister{sp}{\stashBacktraceArgSPvA}
10094
}{}
10195

10296
\ifthenelse{\step=3}{
10397
\domainStateBacktrace[pos=(bottom),yFactor=0.03]{\exnHandlerAfterExnATrap}{\nextFrameDescrPCvA}{1}
104-
\showRegister[color=OrangeRed,offset=-0.5]{sp}{\nextFrameDescrSPvA}
98+
\showRegister{sp}{\nextFrameDescrSPvA}
10599
}{}
106100

107101
\ifthenelse{\step=4}{
108102
\domainStateBacktrace[pos=(bottom),yFactor=0.03]{\exnHandlerAfterExnATrap}{\nextFrameDescrPCvB}{2}
109-
\showRegister[color=OrangeRed,offset=-0.8]{sp}{\nextFrameDescrSPvB}
103+
\showRegister[opacity=0.25]{sp}{\nextFrameDescrSPvA}
104+
\showRegister[offset=-0.8]{sp}{\nextFrameDescrSPvB}
110105
}{}
111106

107+
% Drawing order matter for z-index trapsp/sp
108+
\ifthenelse{\step>1 \and \step<5}{
109+
\showRegister{trapsp}{\stashBacktraceArgTrapSPvA}
110+
\showRegister{pc}{\frameCamlRaiseExnEnd}
111+
}{}
112112

113-
\ifthenelse{\step>6 \and \step<10}{
114-
\showRegister{sp}{\stashBacktraceArgSPvB}
115-
\showRegister{trapsp}{\stashBacktraceArgTrapSPvB}
113+
\ifthenelse{\step>5 \and \step<10}{
114+
\draw [->,>=latex] (exnHandlerRight.east) to [out=0,in=0] (exnBtrap.east);
116115
}{}
117116

118117
\ifthenelse{\step=7}{
119118
\domainStateBacktrace[pos=(bottom),yFactor=0.03]{\exnHandlerAfterExnPopTrapvA}{\nextFrameDescrPCvC}{3}
120-
\showRegister[color=OrangeRed,offset=-0.5]{sp}{\nextFrameDescrSPvC}
119+
\showRegister[opacity=0.25]{sp}{\stashBacktraceArgSPvB}
120+
\showRegister{sp}{\nextFrameDescrSPvC}
121121
}{}
122122

123123
\ifthenelse{\step=8}{
124124
\domainStateBacktrace[pos=(bottom),yFactor=0.03]{\exnHandlerAfterExnPopTrapvA}{\nextFrameDescrPCvD}{4}
125-
\showRegister[color=OrangeRed]{sp}{\nextFrameDescrSPvD}
125+
\showRegister[opacity=0.25]{sp}{\nextFrameDescrSPvC}
126+
\showRegister{sp}{\nextFrameDescrSPvD}
126127
}{}
127128

128129
\ifthenelse{\step=9}{
129130
\domainStateBacktrace[pos=(bottom),yFactor=0.03]{\exnHandlerAfterExnPopTrapvA}{\nextFrameDescrPCvE}{5}
130-
\showRegister[color=OrangeRed,offset=-0.8]{sp}{\nextFrameDescrSPvE}
131+
\showRegister[opacity=0.25]{sp}{\nextFrameDescrSPvD}
132+
\showRegister[offset=-0.8]{sp}{\nextFrameDescrSPvE}
133+
}{}
134+
135+
% Drawing order matter for z-index trapsp/sp
136+
\ifthenelse{\step>6 \and \step<10}{
137+
\showRegister{pc}{\frameCamlReraiseExnEndvB}
138+
\showRegister{trapsp}{\stashBacktraceArgTrapSPvB}
131139
}{}
132140

133141

134142
\ifthenelse{\step>10 \and \step<13}{
135-
\showRegister[offset=-0.5]{trapsp}{\stashBacktraceArgTrapSPvC}
136-
\showRegister{sp}{\stashBacktraceArgSPvC}
143+
\draw [->,>=latex] (exnHandlerRight.east) to [out=0,in=0] (exnCtrap.east);
137144
}{}
138145

139146
\ifthenelse{\step=12}{
140147
\domainStateBacktrace[pos=(bottom),yFactor=0.03]{\exnHandlerAfterExnPopTrapvB}{\nextFrameDescrPCvF}{\stashBacktraceBacktracePosvC}
141148
}{}
142149

150+
% Drawing order matter for z-index trapsp/sp
151+
\ifthenelse{\step>10 \and \step<13}{
152+
\showRegister{pc}{\frameCamlReraiseExnEndvC}
153+
\showRegister{trapsp}{\stashBacktraceArgTrapSPvC}
154+
}{}
155+
143156

144157
\end{stackDiagram}
145158
\end{tikzpicture}

presentation/presentation.tex

+5-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
\documentclass[aspectratio=169,usenames,dvipsnames,8pt,compress]{beamer}
2-
%\setbeameroption{show notes on second screen}
2+
\setbeamertemplate{navigation symbols}{}
33
\setbeamersize{
44
text margin left=5pt,
55
text margin right=5pt
@@ -202,22 +202,13 @@ \section{Catching exceptions}
202202
\section{Nested handlers}
203203
\input{nested.tex}
204204

205-
\section{Bonus: Default handler}
205+
\section{Backtraces}
206+
\input{backtrace.tex}
207+
208+
\section{Bonus: The default handler}
206209
\input{default.tex}
207210

208211
\section*{Outro}
209212
\input{outro.tex}
210213

211-
212-
% TODO
213-
%\section{Backtraces}
214-
%\input{backtrace.tex}
215-
216-
% Rewrite exn trap on realloc
217-
% Exceptions from C
218-
% Exceptions and effects
219-
% Exceptions in bytecode
220-
% Exceptions and TSan
221-
% RBP bug with exn
222-
223214
\end{document}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
1,/exn_handler/ {
2+
p
3+
}
4+
5+
/action_pending/ {
6+
s|.*|\t/* ... */| p
7+
}
8+
9+
10+
/backtrace_pos/, /backtrace_buffer/ {
11+
p
12+
}
13+
14+
/caml_domain_state/ {
15+
s|.*|\t\/* ... */\n\0| p
16+
}

presentation/takeaway.tex

-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
\begin{itemize}
2828
\item Use \funcname{raise\_notrace} to inhibit the backtrace collection
2929
\end{itemize}
30-
\bigskip
31-
\listocaml[firstline=205,lastline=210]{../ocaml/otherlibs/dynlink/dynlink\_compilerlibs/misc.ml}{otherlibs/dynlink/dynlink\_compilerlibs/misc.ml:205}
3230
}
3331
\end{enumerate}
3432
\end{frame}

presentation/tikz/stack.tex

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@
322322
\By = \yOffset{#3}; \By = \By + 0.5 * \yFactor;
323323
}
324324
325-
\draw [->,>=stealth,color=\srColor] (\Ax, \Ay)
325+
\draw [->,>=stealth,color=\srColor,opacity=\srOpacity] (\Ax, \Ay)
326326
node [draw,fill=white,rounded corners,left] {#2}
327327
-- (\Bx, \By);
328328
}

src/notrace/Makefile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
rootdir:=..
2+
src:=notrace.ml
3+
ocflags:=-g
4+
bin:=notrace.exe
5+
cmm:=camlNotrace__all_somes_327 camlNotrace__fun_347
6+
dump:=camlNotrace__all_somes_327 camlNotrace__fun_347
7+
ocamlrunparam=b
8+
9+
include ../Makefile.mk

src/notrace/notrace.ml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module Array = struct
2+
let exists2 p a1 a2 =
3+
let n = Array.length a1 in
4+
if Array.length a2 <> n then invalid_arg "Misc.Stdlib.Array.exists2";
5+
let rec loop i =
6+
if i = n then false
7+
else if p (Array.unsafe_get a1 i) (Array.unsafe_get a2 i) then true
8+
else loop (succ i) in
9+
loop 0
10+
11+
let for_alli p a =
12+
let n = Array.length a in
13+
let rec loop i =
14+
if i = n then true
15+
else if p i (Array.unsafe_get a i) then loop (succ i)
16+
else false in
17+
loop 0
18+
19+
let all_somes a =
20+
try
21+
Some (Array.map (function None -> raise_notrace Exit | Some x -> x) a)
22+
with
23+
| Exit -> None
24+
end

0 commit comments

Comments
 (0)