How to debug a Windows* Fortran application from the command line

Introduction

For Fortran applications built within Microsoft Visual Studio*, you can debug the program by setting a breakpoint at the first executable line and then pressing F5 (or clicking the GO button).  But if you built the application using command line tools, this method is not available.  This article describes how to begin debugging an application built from the command line.

Note: This technique requires that a supported version of Microsoft Visual Studio is installed. It will not work if you are using Microsoft Visual C++ Express Edition* or the Windows Platform SDK to support the compiler environment.

Building the Application

Add the /debug option to the ifort command when compiling and linking.  For example:

ifort /debug /Od hello.f90

or

ifort /c /debug /Od main.f90
ifort /c /debug /Od sub.f90
ifort /debug /exe:main.exe main.obj sub.obj

This will create a .pdb (Program Database) file alongside the executable.  The .pdb file is required for debugging. The /Od option disables optimization to enhance debugging.

Start Debugging

In order to start the debugger, you must be in a command prompt environment which includes definitions for Microsoft Visual Studio.  This is the default for an Intel Fortran "Build Environment" session.

Type the command:

devenv /debugexe hello.exe

where hello.exe is replaced with the name of your executable. If the program requires command line arguments, they may follow the executable name on the command line.

Wait for Visual Studio to finish loading.

You must now set a breakpoint at the main program.  To do this, select Debug > New Breakpoint > Break at Function... or press CTRL-B.  You will see a dialog similar to the following:

new-breakpoint.gif

If you have built an IA-32 architecture application, type into the Function box the name:

_MAIN__

Note that there is one underscore before MAIN and two underscores after.

If you have built an Intel® 64 architecture application, type into the Function box the name:

MAIN__

In this case there is no leading underscore and two trailing underscores.

Click OK.

Press F5 or click the Start Debugging button.  The program will now begin executing but will break at the Fortran main program.  From there you may set additional breakpoints as desired.

If at the end of the session you close Visual Studio and allow it to save the new Visual Studio solution it created, you can debug again just by opening the solution (.sln file).  Your previously set breakpoints will be preserved.

Questions?

If you have comments or questions specifically relating to this article, use the Comments box below. For other questions, please visit our user forum.

For more complete information about compiler optimizations, see our Optimization Notice.

5 comments

Top
anonymous's picture

I have read the article "How to debug a Windows* Fortran application from the command line" published on : February 5, 2009 12:00 AM PST and when attempting to debug an Intel Visual Fortran program by following the article's directions it does not work. According to the information output to my screen the /debugexe qualifier is not valid. The info tells me:

To attach the debugger from the command line, use:
VsJITDebugger.exe -p <pid>

A little help, please!

Thanks.

yjyincj's picture

I got a project with a main file and 16 modules. It was compiled by command line with debug option as following
ifort /debug:all /Od main.f90 module1.f90 ....... module16.f90
Then I triggered the VS GUI debugger using the command:
devenv main.exe

It was opened. But it does not stop at the break point I set. For example, I set line 23 at _MAIN__ , it just go ahead and without stop.

anonymous's picture

I have the debugger working. However, I can only see locally defined fortan variables. Before when using the debugger, if you hover the mouse icon above any variable that is within scope, the value will be highlighted. I can not get this feature to work, nor can I get the watch to work of variables that are not locally defined but are globally defined.

I am not a Fortran expert, but I am used to using the debugger instead in C.

Steve Lionel (Intel)'s picture

Sorry - to debug Fortran programs in Microsoft Visual Studio requires that the Fortran compiler you use supply a plugin to Visual Studio for Fortran. Only those compilers built to be used with Visual Studio have such a thing. Absoft does not. I don't know which compiler you used under Eclipse, but it is unlikely to be one that supports Visual Studio. Furthermore, the Fortran-specific debug information tends to be compiler-specific.

Absoft has their own debugger, and I assume that whatever compiler you used in Eclipse (gfortran?) has a debugger as well. Please consult your compiler's documentation.

If you have questions about Intel's Fortran compiler for Windows, please ask in our user forum at http://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/

anonymous's picture

Hi,

I have the fortran application built using Eclipse or ABSoft. However i want to debug this fortran application in Visual Studio 2005.I found that its possible to debug the application but variable values or stepin stepout functionality is simply not working.(So of no use). Can you guide me how to debug it correctly?

Also, if there is some way i can debug fortran application in tool(free one) other than VS2005, plz advice.

Thanks,
Sandip

Add a Comment

Have a technical question? Visit our forums. Have site or software product issues? Contact support.