Skip to content
Snippets Groups Projects
Commit 7542c0b1 authored by Dominik Zobel's avatar Dominik Zobel
Browse files

Change structure of slides

parent 417f5642
No related branches found
No related tags found
1 merge request!56Debugging Strategies lecture notes
......@@ -3,19 +3,14 @@ title: "Debugging Strategies"
author: "René Redler and Dominik Zobel"
---
# Debugging Strategies
# Debugging Strategies {.leftalign}
**Testing:** Trying to break programs to make them more robust
**Debugging:** Trying to fix a broken program
## Issue, Bug, ...
Discussion of code behaviour
# Different kind of errors
## Different kind of errors
```{dot}
digraph {
......@@ -34,58 +29,55 @@ digraph {
}
```
## General strategies
- Search online for this or similar issues
- Add output verbosity, especially around where the error occured
- Narrow down the code where the error occured (divide and conquer)
- Use a debugger
- Did it work before? What changed since?
## Compile-time errors {.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)
# Compile-time errors {.leftalign}
Also gcc compile time checks and options like `-Wall` and `-Wextra`
- Make the compiler say what you need to know
- Learn to understand what the compiler tries to tell you
## Fixing compile-time errors
## Example
- Learn to understand what the compiler tries to tell you
TODO
## Run-time errors (1/2) {.leftalign}
## Compiler flags for compilation output {.leftalign}
_Setting compiler flags for compiled languages like Fortran and C_
Typically using `-g` for Intel, GCC and many other compilers
Check the manuals
In the Fortran world, also
- [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)
- gfortran: `-fbacktrace`, `-fbounds-check`
- intel (ifort): `-traceback`, `-check bounds`, `-check all`
Also gcc compile time checks and options like `-Wall` and `-Wextra`
## Run-time errors (2/2) {.leftalign}
## Fixing compile-time errors {.leftalign}
For Fortran programs try with more than just one compiler.
HPC systems usally provide native compiler plus gcc/gfortan. Try both variants.
- Make the compiler say what you need to know
- Learn to understand what the compiler tries to tell you
$\Rightarrow$_Example program with issue illustrating the compiler flags_
$\Rightarrow$_Show use of `gdb`_
# Run-time errors {.leftalign}
## Fixing run-time errors
- Produce sensible debug messages to determine code area with the issue
- Use proper compiler flags for debug output
- Check prerequisites/environment
- Use debugger
- Let the compiler help you if something goes wrong
- Understand where to look for issues
## Locating the right error message (1/2) {.leftalign}
```Python
```python
def _extend_number(num):
return 10*num + (num % 10) -1
......@@ -141,21 +133,63 @@ issues in line 9 and 13
## Hands-On! {.handson}
1. What are the actual issues in the code from the previous slides?
1. What are the actual issues in the code from the previous slides based on the error messages?
2. How to rectify them?
## General strategies
- Search online for this or similar issues
- Add output verbosity, especially around where the error occured
- Narrow down the code where the error occured (divide and conquer)
- Use a debugger
- Did it work before? What changed since?
## 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}
For Fortran programs try with more than just one compiler.
HPC systems usally provide native compiler plus gcc/gfortan. Try both variants.
$\Rightarrow$_Example program with issue illustrating the compiler flags_
$\Rightarrow$_Show use of `gdb`_
## Fixing run-time errors
- Produce sensible debug messages to determine code area with the issue
- Use proper compiler flags for debug output
- Check prerequisites/environment
- Use debugger
# Debugging broken code
## Logging
_Make debugging easier with proper logging_
- Very minimal logger for Python
```Python
import logging
logging.basicConfig(filename='output.log', level=logging.WARNING, datefmt='%H:%M:%S',
format='[%(asctime)s] %(levelname)-8s in %(pathname)s:%(lineno)d %(message)s')
logging.warning('Example warning message')
logging.error('Example error message')
```
## Using debuggers {.leftalign}
Idea of debuggers:
......@@ -250,20 +284,4 @@ end program loop_count_2d
::::::::
# How to make debugging easier
## Logging
Consider using logging mechanisms
- Very minimal logger for Python
```Python
import logging
logging.basicConfig(filename='output.log', level=logging.WARNING, datefmt='%H:%M:%S',
format='[%(asctime)s] %(levelname)-8s in %(pathname)s:%(lineno)d %(message)s')
logging.warning('Example warning message')
logging.error('Example error message')
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment