diff --git a/_quarto.yml b/_quarto.yml index 4fc4489f8e4f4389964262128172e42f1f7be7d7..afeb5b7d25c1d6a9ba7035a04ba55d8db9406de9 100644 --- a/_quarto.yml +++ b/_quarto.yml @@ -65,8 +65,7 @@ website: - old_lectures/hardware/slides.qmd - old_lectures/file-and-data-systems/slides.qmd - old_lectures/memory-hierarchies/slides.qmd - - + - old_lectures/debugging-compiled-languages/slides.qmd format: html: theme: cosmo diff --git a/exercises/debugging-strategies.qmd b/exercises/debugging-strategies.qmd index f6f05b036dd195e164c820417cbc967c8517bafb..fceb96db065806b1e55f5b4f87ee2caeac00b311 100644 --- a/exercises/debugging-strategies.qmd +++ b/exercises/debugging-strategies.qmd @@ -24,22 +24,3 @@ Document your strategy of narrowing it down step by step. **This task is NOT about fixing any of the issues^[You can try, if you want. But this is NOT part of the homework]!** -### 2. Approach on locating Fortran bugs - -For this exercise, check out the Fortran code [schnecke_flt.f90](../lectures/debugging-strategies/static/schnecke_flt.f90). -You can compile it on Levante e.g. by loading GCC 11.2.0 compilers with - -```bash -module load gcc/11.2.0-gcc-11.2.0 -``` - -and then run - -```bash -gfortran schnecke_flt.f90 -``` - -**Task** - -- Use additional compiler flags and `gdb` to locate the error. Document your approach. - diff --git a/lectures/debugging-strategies/slides.qmd b/lectures/debugging-strategies/slides.qmd index 23a2696438ce22d0cad3b60ffc2a417e3a918d90..5c96f6c8c8ec9f97b99176db5e310212a36af409 100644 --- a/lectures/debugging-strategies/slides.qmd +++ b/lectures/debugging-strategies/slides.qmd @@ -1,6 +1,5 @@ --- title: "Debugging Strategies" -author: "Dominik Zobel and René Redler" --- # Debugging vs. Testing {.leftalign} @@ -10,28 +9,8 @@ author: "Dominik Zobel and René Redler" **Debugging:** Identify issue(s) and fix a broken program -## Different kind of errors - -```{dot} -digraph { - node [ shape="box" ]; - - compile_ask [ label="Compile program\nSuccessfull?", shape="invhouse", style="filled", fillcolor="#ccccff" ]; - compile_fail [ label="Fix compile-time error(s)" ]; - compile_ok [ label="Run it!\nDid everything\nwork as intended?", shape="hexagon", style="filled", fillcolor="#dddddd" ]; - run_fail [ label="Fix run-time error(s)" ]; - run_ok [ label="Great!", shape="house", style="filled", fillcolor="#ccccff" ]; - - compile_ask -> compile_fail [ label="no", color="#ff0000", fontcolor="#ff0000" ]; - compile_ask -> compile_ok [ label="yes", color="#32dd32", fontcolor="#32dd32" ]; - compile_ok -> run_fail [ label="no", color="#ff0000", fontcolor="#ff0000" ]; - compile_ok -> run_ok [ label="yes", color="#32dd32", fontcolor="#32dd32" ]; -} -``` - ## Strategies covered in this lecture - - Understand compiler usage and messages - Include debug output/logging mechanisms - Narrow down the code where the error occured (divide and conquer) - Use a debugger @@ -39,406 +18,13 @@ digraph { ## Other strategies - - Consider the last working state and focus on what changed since - - If changes are committed in a repo, - find the last valid commit (`git bisect`) - - Search online for this or similar issues - - Ask colleagues working with the same code - - Call for vendor support - - - -# Compile-time errors {.leftalign} - - - Make the compiler say what you need to know - - Learn to understand what the compiler tries to tell you - - -## GCC C++ compiler examples {auto-animate=true} - -::::::::{.columns} - -:::{.column width=45%} - -```cpp -int main() { - return 0 -} - - - - - -``` - -Compiling with - -`gcc test.cpp -o test` - -::: - -:::{.column width=55% .smaller} - - -``` -test.cpp: In function ‘int main()’: -test.cpp:2:12: error: expected ‘;’ before ‘}’ token - 2 | return 0 - | ^ - | ; - 3 | } - | ~ - - - - - - - - - - - - - -``` - -::: - -:::::::: - - -## GCC C++ compiler examples {auto-animate=true} - -::::::::{.columns} - -:::{.column width=45%} - -```cpp -int main() { - using namespace std; - cout << "Hello" << endl; - return 0; -} - - - -``` - -Compiling with - -`gcc test.cpp -o test` - -::: - -:::{.column width=55% .smaller} - - -``` -test.cpp: In function ‘int main()’: -test.cpp:3:4: error: ‘cout’ was not declared in this scope - 3 | cout << "Hello" << endl; - | ^~~~ -test.cpp:1:1: note: ‘std::cout’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’? - +++ |+#include <iostream> - 1 | int main() { -test.cpp:3:23: error: ‘endl’ was not declared in this scope - 3 | cout << "Hello" << endl; - | ^~~~ -test.cpp:1:1: note: ‘std::endl’ is defined in header ‘<ostream>’; did you forget to ‘#include <ostream>’? - +++ |+#include <ostream> - 1 | int main() { - - - - - - -``` - -::: - -:::::::: - - -## GCC C++ compiler examples {auto-animate=true} - -::::::::{.columns} - -:::{.column width=45%} - -```cpp -#include <iostream> - -int main { - using namespace std; - cout << "Hello" << endl; - return 0; -} -``` - -Compiling with - -`gcc test.cpp -o test` - -::: - -:::{.column width=55% .smaller} - - -``` -test.cpp:3:5: error: cannot declare ‘::main’ to be a global variable - 3 | int main { - | ^~~~ -test.cpp:4:4: error: expected primary-expression before ‘using’ - 4 | using namespace std; - | ^~~~~ -test.cpp:4:4: error: expected ‘}’ before ‘using’ -test.cpp:3:10: note: to match this ‘{’ - 3 | int main { - | ^ -test.cpp:5:4: error: ‘cout’ does not name a type - 5 | cout << "Hello" << endl; - | ^~~~ -test.cpp:6:4: error: expected unqualified-id before ‘return’ - 6 | return 0; - | ^~~~~~ -test.cpp:7:1: error: expected declaration before ‘}’ token - 7 | } - | ^ -``` - -::: - -:::::::: - - -## GCC C++ compiler examples {auto-animate=true} - -::::::::{.columns} - -:::{.column width=45%} - -```cpp -#include <iostream> - -int main() { - using namespace std; - cout << "Hello" << endl; - return 0; -} -``` - -Compiling with - -`gcc test.cpp -o test` - -::: - -:::{.column width=55% .smaller} - - -``` -/usr/bin/ld: /tmp/ccrbNm7k.o: warning: relocation against `_ZSt4cout' in read-only section `.text' -/usr/bin/ld: /tmp/ccrbNm7k.o: in function `main': -test.cpp:(.text+0x15): undefined reference to `std::cout' -/usr/bin/ld: test.cpp:(.text+0x1d): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' -/usr/bin/ld: test.cpp:(.text+0x24): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)' -/usr/bin/ld: test.cpp:(.text+0x2f): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))' -/usr/bin/ld: /tmp/ccrbNm7k.o: in function `__static_initialization_and_destruction_0(int, int)': -test.cpp:(.text+0x66): undefined reference to `std::ios_base::Init::Init()' -/usr/bin/ld: test.cpp:(.text+0x81): undefined reference to `std::ios_base::Init::~Init()' -/usr/bin/ld: warning: creating DT_TEXTREL in a PIE -collect2: error: ld returned 1 exit status -``` - -::: - -:::::::: - - -## GCC C++ compiler examples {auto-animate=true} - -::::::::{.columns} - -:::{.column width=45%} - -```cpp -#include <iostream> - -int main() { - using namespace std; - cout << "Hello" << endl; - return 0; -} -``` - -Compiling with - -`g++ test.cpp -o test` - -::: - -:::{.column width=55% .smaller} - - -Compilation succeeded - -::: - -:::::::: - - - -## Remarks - - - The issue is always at or before the first error - - Most compilers give good feedback by default - - - -## Compiler flags for compilation output {.leftalign} - -_Setting compiler flags for compiled languages like Fortran and C_ - -Check the manuals - - - [GCC manuals](https://gcc.gnu.org/onlinedocs/) - - [Intel Fortran compiler options](https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-guide-reference/2024-1/compiler-options-001.html) - -Also gcc compile time checks and options like - - - `-Wall` and - - `-Wextra` - - - -# Run-time errors {.leftalign} - - - Let the compiler help you if something goes wrong - - Understand where to look for issues - - - -## Look out for compiler warnings {.leftalign auto-animate=true} - -::::::::{.columns} - -:::{.column width=48%} - -```c -#include <stdlib.h> - -int main() { - int number = 1; - int* ptr; - ptr = &number; - - free(ptr); - // ERROR: Trying to free - // memory from stack - - return 0; -} -``` - -Compiling with - -`gcc inv_ptr.c -o inv_ptr` - -::: - -:::{.column width=52% .fragment} - -Compiler output - -``` -inv_ptr.c: In function ‘main’: -inv_ptr.c:8:4: warning: ‘free’ called on unallocated object ‘number’ [-Wfree-nonheap-object] - 8 | free(ptr); - | ^~~~~~~~~ -inv_ptr.c:4:8: note: declared here - 4 | int number = 1; - | ^~~~~~ -``` - -Run output e.g. - -``` -Segmentation fault -``` - -::: - -:::::::: - - -## Look out for compiler warnings {.leftalign auto-animate=true} - -::::::::{.columns} - -:::{.column width=48%} - -```c -#include <stdlib.h> - -int main() { - int number = 1; - int* ptr; - ptr = &number; - - free(ptr); - // ERROR: Trying to free - // memory from stack - - return 0; -} -``` - -Compiling with - -`gcc inv_ptr.c -Werror -o inv_ptr` - -::: - -:::{.column width=52%} - -Compiler output - -``` -inv_ptr.c: In function ‘main’: -inv_ptr.c:8:4: error: ‘free’ called on unallocated object ‘number’ [-Werror=free-nonheap-object] - 8 | free(ptr); - | ^~~~~~~~~ -inv_ptr.c:4:8: note: declared here - 4 | int number = 1; - | ^~~~~~ -cc1: all warnings being treated as errors -``` - -::: - -:::::::: - - - -## Compiler flags for run-time output (1/2) {.leftalign} - -_Setting compiler flags for compiled languages like Fortran and C_ - -Typically using `-g` for Intel, GCC and many other compilers - -In the Fortran world, also - -- gfortran: `-fbacktrace`, `-fbounds-check` -- intel (ifort): `-traceback`, `-check bounds`, `-check all` - - -## Compiler flags for run-time output (2/2) {.leftalign} - -Try with more than just one compiler - -$\Rightarrow$ HPC systems usually provide native compiler plus gcc/gfortan. Try both variants. +- [Debugging compiled code](../../old_lectures/debugging-compiled-languages/) +- Consider the last working state and focus on what changed since +- If changes are committed in a repo, + find the last valid commit (`git bisect`) +- Search online for this or similar issues +- Ask colleagues working with the same code +- Call for vendor support @@ -743,141 +329,6 @@ Some debuggers: _Debuggers can also be used in IDEs and JupyterHub_ - -## gdb {.leftalign} - -Using gdb to inspect a core dump - - - to get a core dump - -```bash -ulimit -c unlimited -a.out -``` - -:::{.smaller} - -For core dumps, also `man 5 core` - -::: - - - to inspect the `core` dump - -```bash -gdb a.out core -``` - - -## gdb example - - -::::::::{.columns .smaller} - -:::{.column width=50%} - -```fortranfree -program loop_count_2d - implicit none - integer, parameter :: leni = 3 - integer, parameter :: lenj = 5 - integer, parameter :: len = leni*leni - ! ERROR: leni used twice for len - - integer :: my_ij(2,len) - integer :: i, j, n, ii, jj - - n = 0 - do j = 1, lenj - do i = 1, leni - n = n+1 - my_ij(1,n) = i - my_ij(2,n) = j - enddo - enddo -``` - -::: - -:::{.column width=50%} - -```{.fortranfree startFrom="20"} - do n = 1, len - jj = ( n - 1) / leni + 1 - ii = n - (jj-1) * leni - - if ( ii /= my_ij(1,n) ) then - print *, ' wrong i ', n, & - ii, my_ij(1,n) - end if - - if ( jj /= my_ij(2,n) ) then - print *, ' wrong j ', n, & - jj, my_ij(2,n) - end if - enddo -end program loop_count_2d -``` - -::: - -:::::::: - - -## Some gdb Commands - -::::::::{.columns .smaller} - -:::{.column width=50%} - - - `b <line>`: Add breakpoint at given line number - - `info b`: Show current breakpoints - - `clear`: Clear current breakpoint - - `d`: Clear all breakpoints - - `run`: Run the program - - `l`: Print code - - `info locals`: Print value of local variables - -::: - -:::{.column width=50%} - - - `p <var>`: Print value of variable - - `up`, `down` or `frame <num>`: Navigate stack - - `n`: Next line (without descending) - - `step`: Next command - - `h`: Show help - - `bt`: Create backtrace - - `c`: Continue execution - - `q`: Quit gdb - -::: - -:::::::: - - -## gdb Live Demo - - -# Debugging Flowchart - -::::::::{.columns} - -:::{.column width=35%} - -[](static/debug-flow.png) - -::: - -:::{.column width=60%} - - - Click on flowchart to enlarge - - Intended as a guideline, not strict rule - -::: - -:::::::: - - # Further reading Topic 20 (in ch 3) of *The pragmatic programmer* [UHH Library system](https://katalogplus.sub.uni-hamburg.de/vufind/Record/168729271X) | [MPS ebooks](https://ebooks.mpdl.mpg.de/ebooks/Record/EB001950880) | [German ebook via UHH](https://katalogplus.sub.uni-hamburg.de/vufind/Record/1755846843) diff --git a/old_lectures/_metadata.yml b/old_lectures/_metadata.yml new file mode 100644 index 0000000000000000000000000000000000000000..aa3b8eac4f97507b98bf5a56d7556db8df9c9771 --- /dev/null +++ b/old_lectures/_metadata.yml @@ -0,0 +1,19 @@ +format: + revealjs: + transition: slide + slide-number: true + code-background: true + logo: ../../static/logos.png + footer: "[Generic Software Skills](../../index.html) | [CC-BY 4.0](https://creativecommons.org/licenses/by/4.0/)" + theme: [default, ../lectures/custom.scss] + chalkboard: + buttons: true + navigation-mode: linear + auto-stretch: true + center: true + mermaid: + theme: default + +jupyter: python3 +execute: + cache: true diff --git a/old_lectures/debugging-compiled-languages/slides.qmd b/old_lectures/debugging-compiled-languages/slides.qmd new file mode 100644 index 0000000000000000000000000000000000000000..ca13d3115d28108a1542968afd330aeea5fcf641 --- /dev/null +++ b/old_lectures/debugging-compiled-languages/slides.qmd @@ -0,0 +1,554 @@ +--- +title: Debugging compiled languages +--- + + + +# Compile-time errors {.leftalign} + + - Make the compiler say what you need to know + - Learn to understand what the compiler tries to tell you + + +## GCC C++ compiler examples {auto-animate=true} + +::::::::{.columns} + +:::{.column width=45%} + +```cpp +int main() { + return 0 +} + + + + + +``` + +Compiling with + +`gcc test.cpp -o test` + +::: + +:::{.column width=55% .smaller} + + +``` +test.cpp: In function ‘int main()’: +test.cpp:2:12: error: expected ‘;’ before ‘}’ token + 2 | return 0 + | ^ + | ; + 3 | } + | ~ + + + + + + + + + + + + + +``` + +::: + +:::::::: + + +## GCC C++ compiler examples {auto-animate=true} + +::::::::{.columns} + +:::{.column width=45%} + +```cpp +int main() { + using namespace std; + cout << "Hello" << endl; + return 0; +} + + + +``` + +Compiling with + +`gcc test.cpp -o test` + +::: + +:::{.column width=55% .smaller} + + +``` +test.cpp: In function ‘int main()’: +test.cpp:3:4: error: ‘cout’ was not declared in this scope + 3 | cout << "Hello" << endl; + | ^~~~ +test.cpp:1:1: note: ‘std::cout’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’? + +++ |+#include <iostream> + 1 | int main() { +test.cpp:3:23: error: ‘endl’ was not declared in this scope + 3 | cout << "Hello" << endl; + | ^~~~ +test.cpp:1:1: note: ‘std::endl’ is defined in header ‘<ostream>’; did you forget to ‘#include <ostream>’? + +++ |+#include <ostream> + 1 | int main() { + + + + + + +``` + +::: + +:::::::: + + +## GCC C++ compiler examples {auto-animate=true} + +::::::::{.columns} + +:::{.column width=45%} + +```cpp +#include <iostream> + +int main { + using namespace std; + cout << "Hello" << endl; + return 0; +} +``` + +Compiling with + +`gcc test.cpp -o test` + +::: + +:::{.column width=55% .smaller} + + +``` +test.cpp:3:5: error: cannot declare ‘::main’ to be a global variable + 3 | int main { + | ^~~~ +test.cpp:4:4: error: expected primary-expression before ‘using’ + 4 | using namespace std; + | ^~~~~ +test.cpp:4:4: error: expected ‘}’ before ‘using’ +test.cpp:3:10: note: to match this ‘{’ + 3 | int main { + | ^ +test.cpp:5:4: error: ‘cout’ does not name a type + 5 | cout << "Hello" << endl; + | ^~~~ +test.cpp:6:4: error: expected unqualified-id before ‘return’ + 6 | return 0; + | ^~~~~~ +test.cpp:7:1: error: expected declaration before ‘}’ token + 7 | } + | ^ +``` + +::: + +:::::::: + + +## GCC C++ compiler examples {auto-animate=true} + +::::::::{.columns} + +:::{.column width=45%} + +```cpp +#include <iostream> + +int main() { + using namespace std; + cout << "Hello" << endl; + return 0; +} +``` + +Compiling with + +`gcc test.cpp -o test` + +::: + +:::{.column width=55% .smaller} + + +``` +/usr/bin/ld: /tmp/ccrbNm7k.o: warning: relocation against `_ZSt4cout' in read-only section `.text' +/usr/bin/ld: /tmp/ccrbNm7k.o: in function `main': +test.cpp:(.text+0x15): undefined reference to `std::cout' +/usr/bin/ld: test.cpp:(.text+0x1d): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' +/usr/bin/ld: test.cpp:(.text+0x24): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)' +/usr/bin/ld: test.cpp:(.text+0x2f): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))' +/usr/bin/ld: /tmp/ccrbNm7k.o: in function `__static_initialization_and_destruction_0(int, int)': +test.cpp:(.text+0x66): undefined reference to `std::ios_base::Init::Init()' +/usr/bin/ld: test.cpp:(.text+0x81): undefined reference to `std::ios_base::Init::~Init()' +/usr/bin/ld: warning: creating DT_TEXTREL in a PIE +collect2: error: ld returned 1 exit status +``` + +::: + +:::::::: + + +## GCC C++ compiler examples {auto-animate=true} + +::::::::{.columns} + +:::{.column width=45%} + +```cpp +#include <iostream> + +int main() { + using namespace std; + cout << "Hello" << endl; + return 0; +} +``` + +Compiling with + +`g++ test.cpp -o test` + +::: + +:::{.column width=55% .smaller} + + +Compilation succeeded + +::: + +:::::::: + + + +## Remarks + + - The issue is always at or before the first error + - Most compilers give good feedback by default + + + +## Compiler flags for compilation output {.leftalign} + +_Setting compiler flags for compiled languages like Fortran and C_ + +Check the manuals + + - [GCC manuals](https://gcc.gnu.org/onlinedocs/) + - [Intel Fortran compiler options](https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-guide-reference/2024-1/compiler-options-001.html) + +Also gcc compile time checks and options like + + - `-Wall` and + - `-Wextra` + + + +# Run-time errors {.leftalign} + + - Let the compiler help you if something goes wrong + - Understand where to look for issues + + + +## Look out for compiler warnings {.leftalign auto-animate=true} + +::::::::{.columns} + +:::{.column width=48%} + +```c +#include <stdlib.h> + +int main() { + int number = 1; + int* ptr; + ptr = &number; + + free(ptr); + // ERROR: Trying to free + // memory from stack + + return 0; +} +``` + +Compiling with + +`gcc inv_ptr.c -o inv_ptr` + +::: + +:::{.column width=52% .fragment} + +Compiler output + +``` +inv_ptr.c: In function ‘main’: +inv_ptr.c:8:4: warning: ‘free’ called on unallocated object ‘number’ [-Wfree-nonheap-object] + 8 | free(ptr); + | ^~~~~~~~~ +inv_ptr.c:4:8: note: declared here + 4 | int number = 1; + | ^~~~~~ +``` + +Run output e.g. + +``` +Segmentation fault +``` + +::: + +:::::::: + + +## Look out for compiler warnings {.leftalign auto-animate=true} + +::::::::{.columns} + +:::{.column width=48%} + +```c +#include <stdlib.h> + +int main() { + int number = 1; + int* ptr; + ptr = &number; + + free(ptr); + // ERROR: Trying to free + // memory from stack + + return 0; +} +``` + +Compiling with + +`gcc inv_ptr.c -Werror -o inv_ptr` + +::: + +:::{.column width=52%} + +Compiler output + +``` +inv_ptr.c: In function ‘main’: +inv_ptr.c:8:4: error: ‘free’ called on unallocated object ‘number’ [-Werror=free-nonheap-object] + 8 | free(ptr); + | ^~~~~~~~~ +inv_ptr.c:4:8: note: declared here + 4 | int number = 1; + | ^~~~~~ +cc1: all warnings being treated as errors +``` + +::: + +:::::::: + + + +## Compiler flags for run-time output (1/2) {.leftalign} + +_Setting compiler flags for compiled languages like Fortran and C_ + +Typically using `-g` for Intel, GCC and many other compilers + +In the Fortran world, also + +- gfortran: `-fbacktrace`, `-fbounds-check` +- intel (ifort): `-traceback`, `-check bounds`, `-check all` + + +## Compiler flags for run-time output (2/2) {.leftalign} + +Try with more than just one compiler + +$\Rightarrow$ HPC systems usually provide native compiler plus gcc/gfortan. Try both variants. + + + + + +## gdb {.leftalign} + +Using gdb to inspect a core dump + + - to get a core dump + +```bash +ulimit -c unlimited +a.out +``` + +:::{.smaller} + +For core dumps, also `man 5 core` + +::: + + - to inspect the `core` dump + +```bash +gdb a.out core +``` + + +## gdb example + + +::::::::{.columns .smaller} + +:::{.column width=50%} + +```fortranfree +program loop_count_2d + implicit none + integer, parameter :: leni = 3 + integer, parameter :: lenj = 5 + integer, parameter :: len = leni*leni + ! ERROR: leni used twice for len + + integer :: my_ij(2,len) + integer :: i, j, n, ii, jj + + n = 0 + do j = 1, lenj + do i = 1, leni + n = n+1 + my_ij(1,n) = i + my_ij(2,n) = j + enddo + enddo +``` + +::: + +:::{.column width=50%} + +```{.fortranfree startFrom="20"} + do n = 1, len + jj = ( n - 1) / leni + 1 + ii = n - (jj-1) * leni + + if ( ii /= my_ij(1,n) ) then + print *, ' wrong i ', n, & + ii, my_ij(1,n) + end if + + if ( jj /= my_ij(2,n) ) then + print *, ' wrong j ', n, & + jj, my_ij(2,n) + end if + enddo +end program loop_count_2d +``` + +::: + +:::::::: + + +## Some gdb Commands + +::::::::{.columns .smaller} + +:::{.column width=50%} + + - `b <line>`: Add breakpoint at given line number + - `info b`: Show current breakpoints + - `clear`: Clear current breakpoint + - `d`: Clear all breakpoints + - `run`: Run the program + - `l`: Print code + - `info locals`: Print value of local variables + +::: + +:::{.column width=50%} + + - `p <var>`: Print value of variable + - `up`, `down` or `frame <num>`: Navigate stack + - `n`: Next line (without descending) + - `step`: Next command + - `h`: Show help + - `bt`: Create backtrace + - `c`: Continue execution + - `q`: Quit gdb + +::: + +:::::::: + + +## gdb Live Demo + + +# Debugging Flowchart + +::::::::{.columns} + +:::{.column width=35%} + +[](static/debug-flow.png) + +::: + +:::{.column width=60%} + + - Click on flowchart to enlarge + - Intended as a guideline, not strict rule + +::: + +:::::::: + +## Approach on locating Fortran bugs + +For this exercise, check out the Fortran code [schnecke_flt.f90](../lectures/debugging-strategies/static/schnecke_flt.f90). +You can compile it on Levante e.g. by loading GCC 11.2.0 compilers with + +```bash +module load gcc/11.2.0-gcc-11.2.0 +``` + +and then run + +```bash +gfortran schnecke_flt.f90 +``` + +**Task** + +- Use additional compiler flags and `gdb` to locate the error. Document your approach. + diff --git a/lectures/debugging-strategies/static/debug-flow.dot b/old_lectures/debugging-compiled-languages/static/debug-flow.dot similarity index 100% rename from lectures/debugging-strategies/static/debug-flow.dot rename to old_lectures/debugging-compiled-languages/static/debug-flow.dot diff --git a/lectures/debugging-strategies/static/debug-flow.png b/old_lectures/debugging-compiled-languages/static/debug-flow.png similarity index 100% rename from lectures/debugging-strategies/static/debug-flow.png rename to old_lectures/debugging-compiled-languages/static/debug-flow.png diff --git a/lectures/debugging-strategies/static/schnecke_flt.f90 b/old_lectures/debugging-compiled-languages/static/schnecke_flt.f90 similarity index 100% rename from lectures/debugging-strategies/static/schnecke_flt.f90 rename to old_lectures/debugging-compiled-languages/static/schnecke_flt.f90