Software Archive
Read-only legacy content
17061 Discussions

How to set a "Watch" on a variable in Fortran?

reidar
New User
1,243 Views

Is it possible to set a watch on a variable to see when and where in the program a variable is changed?


Best regards
Reidar

0 Kudos
5 Replies
mford78
Beginner
1,243 Views
In Visual Studio, you can just right click on a variable and select 'Add Watch' or 'Add Quick Watch' and it will appear in the Watch window while debugging.

What front end are you using? And do you want the program to break when the variable changes?
0 Kudos
Rob_Mueller-Albrecht
1,243 Views
Dear Reidar,

in general you set watchpoints in Fortran just as you do in C/C++. This is true for the Linux* hosted Intel Debugger (IDB) as well s for Visual Studio as was just pointed out.

The problem with Fortran watchpoints is that the concept of global variables is not a Fortran concept. Thus you have to be more careful with the scope of the variable you set your watchpoint on than in C/C++.

Let's assume yo are using IDB on the command line. Thus you are basically following GDB syntax for watchpoints.

The question then becomes - What sort of variable are you trying to set your watchpoint on and how is it declared? (E.g. in a module, in a common block, locally, ...). Depending on circumstances, you may need to specify the module name, e.g.

(idb) watch module_name%%variable_name

Thanks, Rob



0 Kudos
reidar
New User
1,243 Views

- yes, I want the program to breakwhen a specific varaiable has beenchanged.
(sometimes a variable is changed unexpected - the the debug/watchis helpful)

Best regards
Reidar

0 Kudos
reidar
New User
1,243 Views

Rob,

I am not familiar with C/C++,nor the IDB command line....

The background for my question is of course that it happened again: Somewhere
in my program a variable has been changed, and I do not undrestand why.
When we used the VAX/VMS system (1983..)you could just write "WATCH " (or something similar)
and then the program stopped and displayed the code segment where the variable was changed.
But I have never managed to do this in CVF or VS2005

The variable can be of any type, of course the most troublesome might be the global
variables, and I use modules rather than common blocks.

From what I understand from you I may achieve what I want by using the command line?

Best regards
Reidar

0 Kudos
mford78
Beginner
1,243 Views
Reidar, I see, you are looking to set what VS/IVF now refers to as a 'Data Breakpoint.' Here is a pretty good description of how to do that in Visual Studio from Intel. Setting Data Breakpoints.

My coworker and I do this/use these ALL the time, so if something in there isn't clear let me know and I'll see if I can help you clear it up.
0 Kudos
Reply