Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions debug/slides/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
notes.pdf
slides.pdf
32 changes: 32 additions & 0 deletions debug/slides/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.PHONY: all
all: notes.pdf slides.pdf

LATEXFLAGS= -shell-escape

SRC+= preamble.tex
SRC+= abstract.tex contents.tex

DEPENDS+= examples/multiplier.pdf
DEPENDS+= examples/multiplier.tex


notes.pdf: notes.tex
notes.pdf: ${SRC} ${DEPENDS}

slides.pdf: slides.tex
slides.pdf: ${SRC} ${DEPENDS}

examples/multiplier.tex examples/multiplier.pdf:
${MAKE} -C $(dir $@) $(notdir $@)



.PHONY: clean
clean:
${RM} notes.pdf slides.pdf
${MAKE} -C examples $@



INCLUDE_MAKEFILES=../../makefiles
include ${INCLUDE_MAKEFILES}/tex.mk
22 changes: 22 additions & 0 deletions debug/slides/abstract.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
% What's the problem?
% Why is it a problem? Research gap left by other approaches?
% Why is it important? Why care?
% What's the approach? How to solve the problem?
% What's the findings? How was it evaluated, what are the results, limitations,
% what remains to be done?

% XXX Summary
\emph{Summary:}
\dots

% XXX Motivation and intended learning outcomes
\emph{Intended learning outcomes:}
\dots

% XXX Prerequisites
\emph{Prerequisites:}
\dots

% XXX Reading material
\emph{Reading:}
\dots
43 changes: 43 additions & 0 deletions debug/slides/contents.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
\mode*

\section{Debugging Python with pdb}

\subsection{A short programme}

\begin{frame}[fragile,allowframebreaks]
\inputminted[firstline=1,lastline=4,linenos]{python}{examples/multiplier.py}
\dots
\inputminted[firstline=13,linenos]{python}{examples/multiplier.py}
\end{frame}

\begin{frame}[fragile,allowframebreaks]
\inputminted[linenos,firstline=6,lastline=11]{python}{examples/multiplier.py}
\end{frame}

\subsection{Into the debugger}

\begin{frame}
\$ pdb3 multiplier.py
\end{frame}


\section{Debugging C++ with gdb}

\subsection{A short programme}

\mode<presentation>{
\begin{frame}
\includegraphics[page=1,clip,trim=2.5cm 2.5cm 2.5cm 2.5cm,width=\columnwidth]{examples/multiplier.pdf}
\end{frame}
}

\input{examples/multiplier.tex}



\subsection{Into the debugger}

\begin{frame}
\$ gdb ./multiplier
\end{frame}

4 changes: 4 additions & 0 deletions debug/slides/examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
multiplier
multiplier.cpp
multiplier.pdf
multiplier.tex
27 changes: 27 additions & 0 deletions debug/slides/examples/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.PHONY: all
all: multiplier multiplier.pdf

# must add debug flag to compiler
CPPFLAGS+= -g

multiplier: multiplier.cpp

multiplier.cpp: multiplier.cpp.nw
${NOTANGLE.cpp}

multiplier.pdf: multiplier.cpp.nw
${NOWEAVE.pdf}
${RM} multiplier.tex

multiplier.tex: multiplier.cpp.nw


.PHONY: clean
clean:
${RM} multiplier multiplier.pdf
${RM} multiplier.cpp multiplier.tex
${RM} multiplier.aux multiplier.fdb_latexmk multiplier.fls multiplier.log


INCLUDE_MAKEFILES=../../../makefiles
include ${INCLUDE_MAKEFILES}/noweb.mk
26 changes: 26 additions & 0 deletions debug/slides/examples/input_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Take input more easily."""

def input_type(t, prompt=""):
"""Take input, convert to type t; repeat if error."""
while True:
try:
return t(input(prompt))
except ValueError:
if t == int:
print(f"Sorry, can't convert to integer.")
else:
print(f"Sorry, can't convert to {t}.")

def main():
"""Test functionality of this module"""
x = input_type(int, "x = ")
y = input_type(int, "y = ")
z = input_type(float, "z = ")
name = input_type(str, "Your name: ")

print(f"{x} + {y} = {x+y}")
print(f"z = {z}")
print(f"Your name is {name}")

if __name__ == "__main__":
main()
82 changes: 82 additions & 0 deletions debug/slides/examples/multiplier.cpp.nw
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
\paragraph{What the program does}

We want to have a short program in C++ for the purpose of showing debugging
using gdb(1).

The program should ask the user for two factors.
Then the program will multiply them in a rather inefficient way --- by repeated
addition --- and then print the result.


\paragraph{Source code structure}

A C++ program is structured as follows.
We only depend on [[<iostream>]] since we want to read from standard in and
write to standard out.
We also add the [[using namespace std]] so that we don't have to type [[std::]]
before things from the [[iostream]] (e.g. [[std::cout]], see
[[<<ask the user for two factors>>]]).
<<multiplier.cpp>>=
// The multiplier program

#include <iostream>
using namespace std;

<<functions>>

int main(void) {
<<main body>>
}
@

The program execution starts in the [[main]] function.
The bulk of out program will go into [[<<main body>>]].
Then we can have helper functions in [[<<functions>>]].

In out case, we need to do the following in the [[<<main body>>]].
<<main body>>=
<<ask the user for two factors>>
<<compute and print the result>>
@


\paragraph{Communicating with the user}

We should ask the user for the two numbers and store them in variables so that
we can use them later.
We choose the type [[float]] since we don't need the precision and want to
reduce our memory footprint.
Otherwise the [[double]] type would have done a fine job too.
<<ask the user for two factors>>=
float factor1, factor2;

cout << "Enter two factors: ";
cin >> factor1 >> factor2;
@


\paragraph{Compute and print the result}

Now we want to compute the result from our input in
[[<<ask the user for two factors>>]].
We will do this with a function.
This is to introduce a call stack for our debugging purposes.
<<compute and print the result>>=
cout << factor1 << " * " << factor2
<< " = " << multiply(factor1, factor2) << endl;
@

The function [[multiply]] will be templated since we don't want to rewrite
anything in case we change types later.
This way the compiler can even infer all types automatically.
<<functions>>=
template <class type>
type multiply(type factor1, type factor2) {
type result = 0;

for (auto i = 0; i < factor2; i++)
result += factor2;

return result;
}
@
21 changes: 21 additions & 0 deletions debug/slides/examples/multiplier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
""" This program performs multiplication by
repeated addition """

import input_type as it

def multiply(a, b):
""" Computes a*b by repeated addition """
result = 0
for _ in range(b):
result += b
return result

def main():
""" Test program """
x = it.input_type(int, "x = ")
y = it.input_type(int, "y = ")
xy = multiply(x, y)
print(f"{x} * {y} = {xy}")

if __name__ == "__main__":
main()
45 changes: 45 additions & 0 deletions debug/slides/notes.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
\documentclass{article}

\usepackage[hyphens]{url}
\usepackage[hidelinks]{hyperref}

\input{preamble.tex}

\usepackage[noamsthm,notheorems]{beamerarticle}
\setjobnamebeamerversion{slides}

%\usepackage{authblk}
%\let\institute\affil

\declaretheorem[numbered=unless unique,style=theorem]{theorem}
\declaretheorem[numbered=unless unique,style=definition]{definition}
\declaretheorem[numbered=unless unique,style=definition]{assumption}
\declaretheorem[numbered=unless unique,style=definition]{protocol}
\declaretheorem[numbered=unless unique,style=example]{example}
%\declaretheorem[style=definition,numbered=unless unique,
% name=Example,refname={example,examples}]{example}
\declaretheorem[numbered=unless unique,style=remark]{remark}
\declaretheorem[numbered=unless unique,style=remark]{idea}
\declaretheorem[numbered=unless unique,style=exercise]{exercise}
\declaretheorem[numbered=unless unique,style=exercise]{question}
\declaretheorem[numbered=unless unique,style=solution]{solution}

\begin{document}
\title{%
Debugging
}
\author{Daniel Bosk}
\institute{%
KTH EECS
}

\maketitle

\begin{abstract}
\input{abstract.tex}
\end{abstract}

\input{contents.tex}

\printbibliography
\end{document}
41 changes: 41 additions & 0 deletions debug/slides/preamble.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[british]{babel}
\usepackage{booktabs}
\usepackage{noweb}
\usepackage{pdfpages}

\usepackage[all]{foreign}
\renewcommand{\foreignfullfont}{}
\renewcommand{\foreignabbrfont}{}

\usepackage{newclude}
\usepackage{import}

\usepackage[strict]{csquotes}
\usepackage[single]{acro}

\usepackage[natbib,style=alphabetic,maxbibnames=99]{biblatex}
\addbibresource{debug.bib}

\usepackage{subcaption}

\usepackage[noend]{algpseudocode}
\usepackage{xparse}

\let\email\texttt

\usepackage[outputdir=ltxobj]{minted}
\setminted{autogobble}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage[unq]{unique}
\DeclareMathOperator{\powerset}{\mathcal{P}}

\usepackage[binary-units]{siunitx}

\usepackage[capitalize]{cleveref}
Loading