Skip to content

Commit

Permalink
Add 'Backtraces' chapter
Browse files Browse the repository at this point in the history
  • Loading branch information
fabbing committed Aug 15, 2023
1 parent d515121 commit 1a45a98
Show file tree
Hide file tree
Showing 9 changed files with 475 additions and 157 deletions.
6 changes: 5 additions & 1 deletion presentation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ presentation:=${tex_source:.tex=.pdf}

ocaml_dir:=../ocaml
sources_dir:=src
sources:=${sources_dir}/ocaml/domain_state.h ${sources_dir}/ocaml/domain_state_abbr.h
sources:=${sources_dir}/ocaml/domain_state.h \
${sources_dir}/ocaml/domain_state_abbr.h \
${sources_dir}/ocaml/domain_state_backtrace.h


.PHONY: all
Expand Down Expand Up @@ -39,3 +41,5 @@ ${sources_dir}/ocaml/domain_state.h:
${sources_dir}/ocaml/domain_state_abbr.h: ${sources_dir}/ocaml/domain_state.h
sed -nf ${sources_dir}/domain_state_abbr.sed >$@ <$<

${sources_dir}/ocaml/domain_state_backtrace.h: ${sources_dir}/ocaml/domain_state.h
sed -nf ${sources_dir}/domain_state_backtrace.sed >$@ <$<
501 changes: 382 additions & 119 deletions presentation/backtrace.tex

Large diffs are not rendered by default.

53 changes: 33 additions & 20 deletions presentation/diagrams/backtrace/backtrace.tex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
\frameLocal{1}{\frameMainLocalOne}
\end{funFrame}


\ifthenelse{\step<13}{
\trapFrame[name=ExnC,handler=\trapExnCHandler,next=\trapExnCNext,color=WildStrawberry]{\trapExnCBegin}
\coordAtRight{exnCtrap}{\exnHandlerAfterExnCTrap}
Expand Down Expand Up @@ -47,7 +46,7 @@
\frameLocal{1}{\frameDefinitelyLocalOne}
\end{funFrame}

\begin{funFrame}[name=raise,color=SeaGreen]{\frameCamlRaiseExnBegin}{\frameCamlRaiseExnEnd}
\begin{funFrame}[color=SeaGreen]{\frameCamlRaiseExnBegin}{\frameCamlRaiseExnEnd}
\funReturnAddr{\frameCamlRaiseExnRetaddr}
\end{funFrame}
}{}
Expand All @@ -66,10 +65,10 @@
}{}


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


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

\ifthenelse{\step>1 \and \step<5}{
\showRegister{sp}{\stashBacktraceArgSPvA}
\showRegister{trapsp}{\stashBacktraceArgTrapSPvA}
}{}

\ifthenelse{\step=2}{
\domainStateBacktrace[pos=(bottom),yFactor=0.03]{\exnHandlerAfterExnATrap}{}{0}
\showRegister{sp}{\stashBacktraceArgSPvA}
}{}

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

\ifthenelse{\step=4}{
\domainStateBacktrace[pos=(bottom),yFactor=0.03]{\exnHandlerAfterExnATrap}{\nextFrameDescrPCvB}{2}
\showRegister[color=OrangeRed,offset=-0.8]{sp}{\nextFrameDescrSPvB}
\showRegister[opacity=0.25]{sp}{\nextFrameDescrSPvA}
\showRegister[offset=-0.8]{sp}{\nextFrameDescrSPvB}
}{}

% Drawing order matter for z-index trapsp/sp
\ifthenelse{\step>1 \and \step<5}{
\showRegister{trapsp}{\stashBacktraceArgTrapSPvA}
\showRegister{pc}{\frameCamlRaiseExnEnd}
}{}

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

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

\ifthenelse{\step=8}{
\domainStateBacktrace[pos=(bottom),yFactor=0.03]{\exnHandlerAfterExnPopTrapvA}{\nextFrameDescrPCvD}{4}
\showRegister[color=OrangeRed]{sp}{\nextFrameDescrSPvD}
\showRegister[opacity=0.25]{sp}{\nextFrameDescrSPvC}
\showRegister{sp}{\nextFrameDescrSPvD}
}{}

\ifthenelse{\step=9}{
\domainStateBacktrace[pos=(bottom),yFactor=0.03]{\exnHandlerAfterExnPopTrapvA}{\nextFrameDescrPCvE}{5}
\showRegister[color=OrangeRed,offset=-0.8]{sp}{\nextFrameDescrSPvE}
\showRegister[opacity=0.25]{sp}{\nextFrameDescrSPvD}
\showRegister[offset=-0.8]{sp}{\nextFrameDescrSPvE}
}{}

% Drawing order matter for z-index trapsp/sp
\ifthenelse{\step>6 \and \step<10}{
\showRegister{pc}{\frameCamlReraiseExnEndvB}
\showRegister{trapsp}{\stashBacktraceArgTrapSPvB}
}{}


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

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

% Drawing order matter for z-index trapsp/sp
\ifthenelse{\step>10 \and \step<13}{
\showRegister{pc}{\frameCamlReraiseExnEndvC}
\showRegister{trapsp}{\stashBacktraceArgTrapSPvC}
}{}


\end{stackDiagram}
\end{tikzpicture}
19 changes: 5 additions & 14 deletions presentation/presentation.tex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
\documentclass[aspectratio=169,usenames,dvipsnames,8pt,compress]{beamer}
%\setbeameroption{show notes on second screen}
\setbeamertemplate{navigation symbols}{}
\setbeamersize{
text margin left=5pt,
text margin right=5pt
Expand Down Expand Up @@ -202,22 +202,13 @@ \section{Catching exceptions}
\section{Nested handlers}
\input{nested.tex}

\section{Bonus: Default handler}
\section{Backtraces}
\input{backtrace.tex}

\section{Bonus: The default handler}
\input{default.tex}

\section*{Outro}
\input{outro.tex}


% TODO
%\section{Backtraces}
%\input{backtrace.tex}

% Rewrite exn trap on realloc
% Exceptions from C
% Exceptions and effects
% Exceptions in bytecode
% Exceptions and TSan
% RBP bug with exn

\end{document}
16 changes: 16 additions & 0 deletions presentation/src/domain_state_backtrace.sed
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
1,/exn_handler/ {
p
}

/action_pending/ {
s|.*|\t/* ... */| p
}


/backtrace_pos/, /backtrace_buffer/ {
p
}

/caml_domain_state/ {
s|.*|\t\/* ... */\n\0| p
}
2 changes: 0 additions & 2 deletions presentation/takeaway.tex
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
\begin{itemize}
\item Use \funcname{raise\_notrace} to inhibit the backtrace collection
\end{itemize}
\bigskip
\listocaml[firstline=205,lastline=210]{../ocaml/otherlibs/dynlink/dynlink\_compilerlibs/misc.ml}{otherlibs/dynlink/dynlink\_compilerlibs/misc.ml:205}
}
\end{enumerate}
\end{frame}
2 changes: 1 addition & 1 deletion presentation/tikz/stack.tex
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@
\By = \yOffset{#3}; \By = \By + 0.5 * \yFactor;
}
\draw [->,>=stealth,color=\srColor] (\Ax, \Ay)
\draw [->,>=stealth,color=\srColor,opacity=\srOpacity] (\Ax, \Ay)
node [draw,fill=white,rounded corners,left] {#2}
-- (\Bx, \By);
}
Expand Down
9 changes: 9 additions & 0 deletions src/notrace/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rootdir:=..
src:=notrace.ml
ocflags:=-g
bin:=notrace.exe
cmm:=camlNotrace__all_somes_327 camlNotrace__fun_347
dump:=camlNotrace__all_somes_327 camlNotrace__fun_347
ocamlrunparam=b

include ../Makefile.mk
24 changes: 24 additions & 0 deletions src/notrace/notrace.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Array = struct
let exists2 p a1 a2 =
let n = Array.length a1 in
if Array.length a2 <> n then invalid_arg "Misc.Stdlib.Array.exists2";
let rec loop i =
if i = n then false
else if p (Array.unsafe_get a1 i) (Array.unsafe_get a2 i) then true
else loop (succ i) in
loop 0

let for_alli p a =
let n = Array.length a in
let rec loop i =
if i = n then true
else if p i (Array.unsafe_get a i) then loop (succ i)
else false in
loop 0

let all_somes a =
try
Some (Array.map (function None -> raise_notrace Exit | Some x -> x) a)
with
| Exit -> None
end

0 comments on commit 1a45a98

Please sign in to comment.