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

How to debug from Fortran to C++

Torben_L_
Beginner
702 Views

Hi, I have 2 projects in visual studio 15, one c++ and one fortran.

The Fortran project is using the c++ dll as a dynamic dll. It works just fine.

But I cannot debug from the Fortran code into the c++ code.

When I try to step from Fortran to the C++ code the debugger in VS takes me to a "Source not Available" page.

How to I setup my solution to I can debug from Fortran and into the c++ code?

Regards Torben

 

 

 

 

0 Kudos
8 Replies
Kevin_D_Intel
Employee
702 Views

Within in the same solution I do not know that any specific configuration setting is needed so long as debug information is available the debugging should be able to switch source context/views between Fortran and C++.

Is the pdb file for the C++ DLL available in the same directory as the DLL?   Typically, under the IDE the DLL is copied and placed next to the executable via a custom post-build step. Perhaps that was done in your case for the DLL but the DLL's pdb file was not copied.

0 Kudos
Torben_L_
Beginner
702 Views

Hi,

Thanks for the suggestion.

The 2 projects are in the same solution and I have given them the same output folder. So yes the pdb file is in the same folder.

For the Fortran project I have the exe and pdb file and for the c++ project I have the dll, metagen, exp, lib, pdb files

The C++ is compiled with clr, but I am assuming that it does make any difference? 

 

 

0 Kudos
Kevin_D_Intel
Employee
702 Views

I don't know what could be hindering this. Is your solution/projects small enough to gather into a .zip and share with everyone here?

0 Kudos
Torben_L_
Beginner
702 Views

Hi, I have attached a example. Please a breakpoint in the file: "VLXESDK_Main.f90", line 172. The line reads:

iError = ModelSetModelEOS(ModelName)

Now run the program. Select 1 in the dos window and once the breakpoint is hit try to debug into the function. Then I get the message: "Source not available"

 

0 Kudos
FortranFan
Honored Contributor II
702 Views

Torben L. wrote:

Hi, I have attached a example. Please a breakpoint in the file: "VLXESDK_Main.f90", line 172. The line reads:

iError = ModelSetModelEOS(ModelName)

Now run the program. Select 1 in the dos window and once the breakpoint is hit try to debug into the function. Then I get the message: "Source not available"

@Torben L.,

It appears you're using managed C++ as part of Microsoft .NET as opposed to native C++ (along the lines of what most people view as standard C or C++ environments).  I've never tried this and it is unclear if Intel Fortran integration in Visual Studio supports this configuration, at least for debugging aspect.  Because if it did, then under your Fortran project -> Properties -> Configuration Properties -> Debugging -> Debugger Type, it would have allowed Auto (or something like Managed) but it only shows "Native only" option - I think that is the problem.  Hopefully Kevin and his colleagues from Intel can clarify this further.

By the way, it would appear from your above posting, the zip file includes a lot of copyrighted information - you may wish to think along the lines of "minimal working example" and try to create small, generic reproducers of your issue in the future for problem resolution - see message #6 from this thread for an illustration: https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/699941​

Good luck,

 

0 Kudos
jimdempseyatthecove
Honored Contributor III
702 Views

Try this:

Change your FORTRAN

   PROGRAM
   ...
   END PROGRAM

to

   SUBROUTINE FORTRAN_CODE
   ...
   END SUBROUTINE FORTRAN_CODE

Compile as static library.

Then add a managed C++ stub:

  extern "C" void FORTRAN_CODE();
  int main()
  {
    FORTRAN_CODE();
  }

Then check to see if you can step into FORTRAN_CODE. Note, you may need to inform the Debugger that the FORTRAN objs are not managed code. I was able to get a managed C# application to call an unmanaged C++ DLL that in turn called an unmanaged FORTRAN dll with the debugger working fine. I recall having an issue in setting the breakpoint in the unmanaged code _prior_ to stepping into the unmanaged code. As a hack, I added a dummy FORTRAN subroutine:

SUBROUTINE UNMANAGED_CODE
   INTEGER, SAVE :: BOINK = 0
   BOINK = 1 ! Force compiler optimization to not remove this subroutine
END SUBROUTINE UNMANAGED_CODE

Then in the C++ main, insert a function call to the above. Step into the function (in my case this loaded the FORTRAN DLL, in your case it may call the unmanaged code. Once in the UNMANAGED_CODE subroutine, you should be able to set your break points in any of the FORTRAN code.

I am sorry that I do not have a more specific guidline as to how this is done. Good luck.

Jim Dempsey

0 Kudos
Torben_L_
Beginner
702 Views

Hi,

Thanks for the suggestions I will need to spend some more time on this to see if I can get it to work

 

0 Kudos
Kevin_D_Intel
Employee
702 Views

The attached example is not really what I was anticipating from some of your earlier posts and I'm not finding it easy to work with given hard-coded paths and that the C++ component isn't contained within the same solution as the Fortran DLL. I tried working with it but am not getting past an access violation stepping into ModelSetModelEOS. I not able to reach a point of "Source not available" as you noted.

What I was trying to do was evaluate the guidance I received that was, from the Fortran Debug Solutions RNs (here) refer to “Debugging mixed language programs with Fortran does not work”. Also see “Native edit and continue” for some additional information.

Perhaps you can try the advice within your setup.

 

0 Kudos
Reply