Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29559 Discussions

DEBUG ifx VS2022 watch class variable

Haku
Novice
1,200 Views

Environment

Visual Studio 2022 : 17.14.21

IFX : 2025.3.0

Problem

In debug mode, Visual Studio cannot display correct Watch values for a polymorphic (class) allocatable array.

type :: Layer
!...
end type Layer 

type extends(Layer):: extended_Layer
!...
end type extended_Layer

class(layer),allocatable,dimension(:):: L

allocate(extended_Layer::L(5))

situation 1
Right after allocation, I cannot inspect L correctly in the Watch window.

situation 2 
Even if I use select type, I still can’t inspect the variable properly inside the type is block:

select type (L)
type is (extended_Layer)
  ! ...
end select

The Watch window shows an incorrect upper bound for L (e.g., -1) as below, although print statements show the correct values at runtime.

Haku_1-1766493758068.png

Does this mean IFX + Visual Studio currently cannot reliably display polymorphic (class) variables in Watch?
If so, is the recommended workaround to use print statements, or to pass the object into a subroutine with a non-polymorphic dummy argument?

Thanks in advance.

 

0 Kudos
4 Replies
JohnNichols
Honored Contributor I
1,065 Views

I watch  this forum, mainly because of the neat people. 

Your question is interesting, but it would help if it was a complete small program so I could put it into a sln and run it.  I am not going to make the program. 

 

0 Kudos
Haku
Novice
813 Views

Thanks for your reply, and I'm sorry for the late follow-up.

I'll share a simple program below-just copy/paste it into an empty Fortran project and it should run.

module simple_class
implicit none(external)
private
public :: basic_layer, advanced_layer,alayer_1

type basic_layer
integer :: layer_id
double precision:: dx,dy
end type basic_layer
type ,extends(basic_layer) :: advanced_layer
  double precision :: dz
end type advanced_layer
class(basic_layer),allocatable :: alayer_1(:)
contains
end module simple_class

program main
use simple_class,only:  advanced_layer,basic_layer,alayer_1
type(basic_layer) :: layer1
type(advanced_layer) :: layer2
class(basic_layer),allocatable :: layer3,layer4

!===successful watcher debug session===
layer1%layer_id = 1
layer1%dx = 0.1d0;layer1%dy = 0.2d0
continue

layer2%layer_id = 2
layer2%dx = 0.3d0;layer2%dy = 0.4d0;layer2%dz = 0.5d0
continue

allocate(basic_layer::layer3)
select type(layer3)  ! to confirm the dynamic type
type is (basic_layer)
  layer3%layer_id = 3
  layer3%dx = 0.6d0;layer3%dy = 0.7d0
end select

continue

allocate(advanced_layer::layer4)
select type(layer4)  ! to confirm the dynamic type
type is(advanced_layer)
  layer4%layer_id = 4
  layer4%dx = 0.8d0;layer4%dy = 0.9d0;layer4%dz = 1.0d0
  print *, "layer4%dz =", layer4%dz
end select
continue
!===successful watcher debug session===

!===failure watcher debug session===
allocate(advanced_layer::alayer_1(3))
select type(alayer_1)  ! to confirm the dynamic type
type is(advanced_layer)
  alayer_1(:)%layer_id = 5
  alayer_1(:)%dx = 1.1d0;alayer_1(:)%dy = 1.2d0;alayer_1(:)%dz = 1.3d0
  print *, "alayer_1(1)%dz =", alayer_1(1)%dz
end select
continue
!===failure watcher debug session===

!===successful watcher debug session===
!-use block to see the content
test : block
type(advanced_layer) :: aLayer(3)
select type(alayer_1) ! to confirm the dynamic type
type is (advanced_layer)
  aLayer = alayer_1
end select

continue
end block test
!===successful watcher debug session===

end program main

As shown in comments:

  • If I define a variable as type(layer1,layer2) or as a scalar class (layer3,layer4), it can be inspected correctly in the debug Watch window.
  • However, when I define an array of class, the Watch failed and shows stange values (like in the picture below). 

Haku_0-1767942349649.png

For now, the only workaround I have is the last "block" part: by assigning an element into a specific type variable (aLayer),I can watch this aLayer variable to check the original variable. But it's tedious to insert this block everywhere just for debugging. 
Is it simply hard(or unsupported) for the debugger to inspect an array of class objects? Even though the OOP part in fortran attract me a lot.
Thanks in advance!

0 Kudos
JohnNichols
Honored Contributor I
745 Views

Screenshot 2026-01-10 103301.png

I cannot see the variables and it crashes the debugger, your method will work it is not elegant, and in pure math not elegant is the kiss of death.  

Last night, I had to spend several hours in a fast food restaurant who serve H_ppy M_als, and so I read a Project Gutenberg book on the Tenth (Irish) Division in WW1.  It is incredibly satisfying read and has some great English sentences.   If you think you are having a bad day, this will show you it can get a lot worse. 

0 Kudos
Haku
Novice
694 Views

Thank you for your interesting suggestion.
As a result, since the debugger has trouble inspecting arrays of class objects, I decided to use a preprocessor-based approach to the basic type so that it can be inspected in the watch window.

Have a nice day!!

0 Kudos
Reply