# Methods of debugging Fortran projects

**URL:** <https://fortran-lang.discourse.group/t/methods-of-debugging-fortran-projects/3001>\
**Category:** Help\
**Created:** [March 18, 2022, 4:02am UTC](https://fortran-lang.discourse.group/t/methods-of-debugging-fortran-projects/3001 "2022-03-18T04:02:15Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hongyi](https://avatars.discourse-cdn.com/v4/letter/h/5fc32e/32.png) [@Hongyi](https://fortran-lang.discourse.group/u/Hongyi)\
**Post date:** [March 18, 2022, 4:02am UTC](https://fortran-lang.discourse.group/t/methods-of-debugging-fortran-projects/3001/1 "2022-03-18T04:02:15Z")

</div>

It’s well known that Fortran in nature is a type of compiled language. To make matters worse, there are very few IDEs specially developed for Fortran, which is especially true on Linux systems.

So, I want to know if there are some elegant methods of debugging the Fortran project on Linux operating system, especially when using Intel oneAPI Toolkits.

Regards,  
HZ

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [March 18, 2022, 5:09am UTC](https://fortran-lang.discourse.group/t/methods-of-debugging-fortran-projects/3001/3 "2022-03-18T05:09:04Z")

</div>

Intel has one of the more extensive suites of tools for debugging and optimizing codes, with much of the documentation available on their web site as well as a good amount that comes with the tools when you install them; there are a few IDEs for Fortran on Linux, and I would hazard to say that TotalView is one of the most commonly used commercial debuggers. Apparently gdb is not what you have in mind? If you are interested primarily in Intel products have you tried their web site already? If you compile with the major debug flags on you can often detect problems without the need for a debugger. Debuggers are useful for investigating logic problems in code but generally fail on actual bugs; the compiler flags are generally more useful with that category (over and under-indexing arrays, type mismatches, …).

Read this first …

[Tips for Debugging Run-time Failures in Intel Fortran Applications](https://www.intel.com/content/www/us/en/developer/articles/training/tips-for-debugging-run-time-failures-in-intel-fortran-applications.html)

After that, it depends on whether you are using Intel processors, whether you are interested in parallel processing, whether tuning the code is part of what you consider to be debugging, … this can take a few days to read:

> **[oneAPI Documentation](https://www.intel.com/content/www/us/en/developer/tools/oneapi/documentation-library.html?s=Newest)**
>
> Access a complete repository of resources for this API from Intel.

gdb(1) is worth trying to master in line mode, and a lot of GUI users get converted over to CLI users using it; but there are a lot of wrappers for gdb; ddd may already be on your system, but also take a look at  
[http://sourceware.org/gdb/wiki/GDB%20Front%20Ends](http://sourceware.org/gdb/wiki/GDB%20Front%20Ends)

If you are an fpm(1) user you can easily run in the TDU world half-way between GUI and CLI with something like this:

fpm run --runner ‘gdb -tui’

What editor do you use? If you are a vim(1) user edit your code and enter

```nohighlight
:packadd termdebug
:Termdebug

```

If you use emacs(1) there are web books on using gdb(1) and everything else in there (but I am a vi/vim user unless working with an emacs(1) fan so I’ll leave that up to others – no editor holy wars please).

---

<div class="post-metadata">

**Author:** ![Hongyi](https://avatars.discourse-cdn.com/v4/letter/h/5fc32e/32.png) [@Hongyi](https://fortran-lang.discourse.group/u/Hongyi)\
**Post date:** [March 18, 2022, 8:33am UTC](https://fortran-lang.discourse.group/t/methods-of-debugging-fortran-projects/3001/4 "2022-03-18T08:33:33Z")

</div>

> [@urbanjost](#):
>
> there are a few IDEs for Fortran on Linux, and I would hazard to say that TotalView is one of the most commonly used commercial debuggers.

Thank you for sharing your opinion with me.

> [@urbanjost](#):
>
> Apparently gdb is not what you have in mind?

Though gdb is powerful, it’s a bit complicated and difficult to understand.

> [@urbanjost](#):
>
> Debuggers are useful for investigating logic problems in code

This is just one of the core things I’m focusing on.

> [@urbanjost](#):
>
> but also take a look at  
> [http://sourceware.org/gdb/wiki/GDB%20Front%20Ends](http://sourceware.org/gdb/wiki/GDB%20Front%20Ends)

Thank you for telling me this great website. Though there are so many tools listed above, most of them are not designed for Fortran, IMO.

> [@urbanjost](#):
>
> If you are an fpm(1) user you can easily run in the TDU world half-way between GUI and CLI with something like this:
> 
> fpm run --runner ‘gdb -tui’

Do you mean this tool?

> **[GitHub - fortran-lang/fpm: Fortran Package Manager (fpm)](https://github.com/fortran-lang/fpm)**
>
> Fortran Package Manager (fpm). Contribute to fortran-lang/fpm development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [March 18, 2022, 11:35am UTC](https://fortran-lang.discourse.group/t/methods-of-debugging-fortran-projects/3001/5 "2022-03-18T11:35:38Z")

</div>

> [@Hongyi](#):
>
> It’s well known that Fortran in nature is a type of compiled language. To make matters worse, there are very few IDEs specially developed for Fortran, which is especially true on Linux systems.

The Fortran Tools list has a [Text Editors, Integrated Development Environments, and Plugins](https://github.com/Beliavsky/Fortran-tools-on-GitHub#text-editors-integrated-development-environments-and-plugins) section, as does [fortran-lang](https://fortran-lang.org/learn/os_setup/ides).

---

<div class="post-metadata">

**Author:** ![gnikit](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/gnikit/32/1213_2.png) [@gnikit](https://fortran-lang.discourse.group/u/gnikit)\
**Post date:** [March 18, 2022, 2:44pm UTC](https://fortran-lang.discourse.group/t/methods-of-debugging-fortran-projects/3001/6 "2022-03-18T14:44:45Z")

</div>

Hi @Hongyi, for Linux regardless of if you are using ifort or gfortran you should be able to use VS Code + the [Modern Fortran](https://marketplace.visualstudio.com/items?itemName=krvajalm.linter-gfortran) extension. Please use the pre-Release version and allow it to install `fortls`.

That should give you an IDE level debugging functionality with breaking points, hover, watch windows, stepping, etc. OpenMP threads should also work, but no MPI, conditional or functional breakpoint support.

FYI You will need to make sure you use Intel’s GDB version in your `launch.json`, see the [docs](https://code.visualstudio.com/docs/cpp/cpp-debug) for how to do that

---

<div class="post-metadata">

**Author:** ![Hongyi](https://avatars.discourse-cdn.com/v4/letter/h/5fc32e/32.png) [@Hongyi](https://fortran-lang.discourse.group/u/Hongyi)\
**Post date:** [March 19, 2022, 1:21am UTC](https://fortran-lang.discourse.group/t/methods-of-debugging-fortran-projects/3001/7 "2022-03-19T01:21:06Z")

</div>

> [@gnikit](#):
>
> Hi @Hongyi, for Linux regardless of if you are using ifort or gfortran you should be able to use VS Code + the [Modern Fortran](https://marketplace.visualstudio.com/items?itemName=krvajalm.linter-gfortran) extension. Please use the pre-Release version and allow it to install `fortls` .

Thank you for your insightful tips. I mainly use Emacs.

Regards,  
HZ

---

<div class="post-metadata">

**Author:** ![snano](https://avatars.discourse-cdn.com/v4/letter/s/fbc32d/32.png) [@snano](https://fortran-lang.discourse.group/u/snano)\
**Post date:** [March 19, 2022, 9:24am UTC](https://fortran-lang.discourse.group/t/methods-of-debugging-fortran-projects/3001/8 "2022-03-19T09:24:46Z")

</div>

I use VS code with Modern Fortran, it is very nice and user-friendly. I did not use it for debugging purposes.

However, whenever I try to create a new program, the program template appears with 2 cursors and leads to simultaneous writing in two-place (though useful), which leads to the wrong syntax. (for clarity see the attached image file). Maybe someone has a better experience (and is willing to share it) in using VS code with Modern Fortran.

 ![1](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/3/3d070b41aa069565d106a6adebc3e83ad4c7b9f5.png)

---

<div class="post-metadata">

**Author:** ![gnikit](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/gnikit/32/1213_2.png) [@gnikit](https://fortran-lang.discourse.group/u/gnikit)\
**Post date:** [March 19, 2022, 10:19am UTC](https://fortran-lang.discourse.group/t/methods-of-debugging-fortran-projects/3001/9 "2022-03-19T10:19:40Z")

</div>

This is because you are using the program snippet of the extension, which generates the template. Snippets insert code with placeholders, which the user can then navigate using `Tab`. The two cursors are basically VS Code’s way of typing at the same time the program name at both the start and end of the scope. Once done, press `Tab` to move to the body of the scope.

For more info on how to use snippets see: [Snippets in Visual Studio Code](https://code.visualstudio.com/docs/editor/userdefinedsnippets)

I should also add, that snippets will not necessarily fit all your cases, so it does not always make sense to use them. Let me know if you would like to see certain snippets in the extension.

Also, you can define your own custom snippets in VS Code:[Snippets in Visual Studio Code](https://code.visualstudio.com/docs/editor/userdefinedsnippets#_create-your-own-snippets)

---

<div class="post-metadata">

**Author:** ![nshaffer](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/nshaffer/32/161_2.png) [@nshaffer](https://fortran-lang.discourse.group/u/nshaffer)\
**Post date:** [March 19, 2022, 11:50am UTC](https://fortran-lang.discourse.group/t/methods-of-debugging-fortran-projects/3001/10 "2022-03-19T11:50:29Z")

</div>

Are you using GUI emacs or terminal emacs? I find the built-in gdb integration reasonably nice to use in GUI emacs. Open up your main program, then `M-x gdb` to start a session, then `M-x gdb-many-windows` to get buffers for tracking variables and the call stack. You can set breakpoints by clicking in the gutter of your source file buffer, like in most IDEs. Control the debugger with the gdb prompt (like terminal) or with the menu.

---

<div class="post-metadata">

**Author:** ![snano](https://avatars.discourse-cdn.com/v4/letter/s/fbc32d/32.png) [@snano](https://fortran-lang.discourse.group/u/snano)\
**Post date:** [March 19, 2022, 12:11pm UTC](https://fortran-lang.discourse.group/t/methods-of-debugging-fortran-projects/3001/11 "2022-03-19T12:11:22Z")

</div>

Thanks for the suggestion. I will try them. Further, custom snippets seem pretty new to me and hopefully fantastic in the future as I continue using Modern Fortran in more depth.

---

<div class="post-metadata">

**Author:** ![Hongyi](https://avatars.discourse-cdn.com/v4/letter/h/5fc32e/32.png) [@Hongyi](https://fortran-lang.discourse.group/u/Hongyi)\
**Post date:** [March 19, 2022, 12:50pm UTC](https://fortran-lang.discourse.group/t/methods-of-debugging-fortran-projects/3001/12 "2022-03-19T12:50:07Z")

</div>

Thank you very much for your tips. I’m using GUI Emacs. Do you have experience working with Emacs using Intel oneAPI?

Regards,  
HZ

---

<div class="post-metadata">

**Author:** ![nshaffer](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/nshaffer/32/161_2.png) [@nshaffer](https://fortran-lang.discourse.group/u/nshaffer)\
**Post date:** [March 19, 2022, 3:57pm UTC](https://fortran-lang.discourse.group/t/methods-of-debugging-fortran-projects/3001/13 "2022-03-19T15:57:20Z")

</div>

Emacs is just using gdb, so if you are able to debug the executable with gdb in your terminal, then it will also work when using emacs. I have debugged programs built with ifort and gfortran this way. I would guess ifx works the same, but I’ve never done it myself.

---

<div class="post-metadata">

**Author:** ![Hongyi](https://avatars.discourse-cdn.com/v4/letter/h/5fc32e/32.png) [@Hongyi](https://fortran-lang.discourse.group/u/Hongyi)\
**Post date:** [March 20, 2022, 12:11am UTC](https://fortran-lang.discourse.group/t/methods-of-debugging-fortran-projects/3001/14 "2022-03-20T00:11:10Z")

</div>

> [@nshaffer](#):
>
> I would guess ifx works the same, but I’ve never done it myself.

What do you mean by saying **ifx**?

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [March 20, 2022, 1:05am UTC](https://fortran-lang.discourse.group/t/methods-of-debugging-fortran-projects/3001/15 "2022-03-20T01:05:19Z")

</div>

> [@Hongyi](#):
>
> > [@nshaffer](#):
> >
> > I would guess ifx works the same, but I’ve never done it myself.
> 
> What do you mean by saying **ifx**?

It is the new LLVM-based compiler of Intel, as described [here](https://www.intel.com/content/www/us/en/developer/articles/guide/porting-guide-for-ifort-to-ifx.html).

---

<div class="post-metadata">

**Author:** ![Hongyi](https://avatars.discourse-cdn.com/v4/letter/h/5fc32e/32.png) [@Hongyi](https://fortran-lang.discourse.group/u/Hongyi)\
**Post date:** [March 20, 2022, 1:25am UTC](https://fortran-lang.discourse.group/t/methods-of-debugging-fortran-projects/3001/16 "2022-03-20T01:25:58Z")

</div>

> [@Beliavsky](#):
>
> It is the new LLVM-based compiler of Intel, as described [here](https://www.intel.com/content/www/us/en/developer/articles/guide/porting-guide-for-ifort-to-ifx.html).

Really. I’ve installed it, but I haven’t noticed it until now:

```auto
$ module load compiler
$ which ifx
/opt/intel/oneapi/compiler/2022.0.2/linux/bin/ifx

```

---

<div class="post-metadata">

**Author:** ![wtstephens](https://avatars.discourse-cdn.com/v4/letter/w/a698b9/32.png) [@wtstephens](https://fortran-lang.discourse.group/u/wtstephens)\
**Post date:** [February 10, 2025, 3:51pm UTC](https://fortran-lang.discourse.group/t/methods-of-debugging-fortran-projects/3001/17 "2025-02-10T15:51:11Z")

</div>

I can debug in VS Code under Windows 10 – meaning set breakpoints and look at some variables, **limited to** integer, real, character arrays.

My launch.json is the cppvsdbg type, with Intel 2025 Fortran installed (there is also an Intel 2023 version installed).

Am I supposed to be able to see more variables? Such as integer arrays?

If so, what am I missing?
