Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lecture materials
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
generic software skills
lecture materials
Commits
7542c0b1
Commit
7542c0b1
authored
11 months ago
by
Dominik Zobel
Browse files
Options
Downloads
Patches
Plain Diff
Change structure of slides
parent
417f5642
No related branches found
No related tags found
1 merge request
!56
Debugging Strategies lecture notes
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lectures/debugging-strategies/slides.qmd
+74
-56
74 additions, 56 deletions
lectures/debugging-strategies/slides.qmd
with
74 additions
and
56 deletions
lectures/debugging-strategies/slides.qmd
+
74
−
56
View file @
7542c0b1
...
...
@@ -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 co
mp
i
le
-time errors
##
Exa
mple
- 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 compiler
s
Check the manual
s
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}
```
P
ython
```
p
ython
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')
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment