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
09e21b02
Commit
09e21b02
authored
11 months ago
by
Dominik Zobel
Browse files
Options
Downloads
Patches
Plain Diff
Draft for debugging strategies lecture
parent
3296bfdd
No related branches found
No related tags found
1 merge request
!56
Debugging Strategies lecture notes
Pipeline
#66620
passed
11 months ago
Stage: test
Stage: build
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
_quarto.yml
+2
-2
2 additions, 2 deletions
_quarto.yml
lectures/debugging-strategies/slides.qmd
+195
-0
195 additions, 0 deletions
lectures/debugging-strategies/slides.qmd
with
197 additions
and
2 deletions
_quarto.yml
+
2
−
2
View file @
09e21b02
...
...
@@ -31,7 +31,7 @@ website:
-
"
lectures/programming-paradigms/slides.qmd"
-
"
lectures/data-structures/slides.qmd"
-
"
lectures/complexity/slides.qmd"
#
- "lectures/debugging/slides.qmd"
-
"
lectures/debugging
-strategies
/slides.qmd"
# - "lectures/good-scientific-practice/slides.qmd"
# - "lectures/user-experience/slides.qmd"
# - "lectures/testing/slides.qmd"
...
...
@@ -47,7 +47,7 @@ website:
-
"
exercises/programming_paradigms.qmd"
-
"
exercises/data_structures.qmd"
-
"
exercises/complexity.qmd"
# - "exercises/debugging.qmd"
# - "exercises/debugging
-strategies
.qmd"
# - "exercises/good_scientific_practice.qmd"
# - "exercises/user_experience.qmd"
# - "exercises/testing.qmd"
...
...
This diff is collapsed.
Click to expand it.
lectures/debugging-strategies/slides.qmd
0 → 100644
+
195
−
0
View file @
09e21b02
---
title: "Debugging Strategies"
author: "René Redler and Dominik Zobel"
---
# Debugging Strategies
**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
One possible distinction:
- Compile-time errors
- Run-time errors
## 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)
Also gcc compile time checks and options like `-Wall` and `-Wextra`
## Fixing compile-time errors
- Learn to understand what the compiler tries to tell you
## Run-time errors (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`, `-fsanitize=bounds-strict`
- intel (ifort): `-traceback`, `-check bounds`, `-check all`
## Run-time errors (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
## Locating the right error message (1/2) {.leftalign}
```Python
def _extend_number(num):
return 10*num + (num % 10) -1
def extend_number(num):
try:
for idx in range(num):
num = _extend_number(num)
except:
num = extend_number(num)
return num
print(extend_number('6'))
```
:::{.smaller}
Expected output:
:::
```
6543210
```
## Locating the right error message (2/2)
Output from previous code (last 15 lines)
```
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 3, in extend_number
RecursionError: maximum recursion depth exceeded while calling a Python object
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 6, in extend_number
File "<stdin>", line 6, in extend_number
File "<stdin>", line 6, in extend_number
[Previous line repeated 996 more times]
RecursionError: maximum recursion depth exceeded
```
<!--
issues in line 9 and 13
-->
## Hands-On! {.handson}
1. What are the actual issues in the code from the previous slides?
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?
# Debugging broken code
## Using debuggers {.leftalign}
Idea of debuggers:
- Investigate code before/at the issue interactively
- Set breakpoints to check actual values at specific code positions
Some debuggers:
- `pdb` (Python debugger)
- `gdb` (GNU debugger)
- commercial debuggers (like `ddt` on Levante)
## gdb {.leftalign}
Using gdb to inspect a core dump
- to get a core dump
```bash
limit -c unlimited
a.out
```
- to inspect the `core` dump
```bash
gdb a.out core
```
# 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