Silverfrost Forums

Welcome to our forums

Debugging: Can't step into function

27 May 2015 7:54 #16348

Whilst trying to debug someone else's code I found that I am not able to step into an external function that has been provided with an explicit interface using a module.

The following code illustrates this. When you run using the debugger you are not able to step into the adder function (the line: adder = a + b). You are not able to 'Getto cursor' to this location either.

It works if the interface is copied into main directly (copy/paste and remove the module), but not with it in the module.

Any thoughts? The stack trace shows a call to the interface, which isn't right.

module interfaces

   interface
      function adder(a, b)
         real, intent(in) :: a, b
         real :: adder
      end function adder
   end interface
   
end module interfaces

function adder(a, b)
   real, intent(in) :: a, b
   real :: adder
   adder = a + b
end function adder

program main

   use interfaces, only: adder
   
   real :: a, b, y
   a = 1.0
   b = 2.0
   
   y = adder(a, b)
   
   print *, y

end program main
27 May 2015 8:16 #16349

What do you mean by 'external function'? Presumably the code is question is compiled with a debug option?

27 May 2015 12:17 (Edited: 15 Jun 2015 10:08) #16350

Quoted from Robert What do you mean by 'external function'? That is the term used to make it clear that the code for the body of the function in question is not CONTAINed in a module.

I can reproduce the bug with FTN95 7.10 and 7.20. For every compilation mentioned here, I used the /DEBUG option. Here are a couple of related findings.

  1. If the module with just the interface in it is moved to a separate file, source debugging capability is restored. DavidB, please try this strategy with your larger program and advise us as to whether it worked.

  2. If just the function code is moved to a separate file, leaving the module with the interface in place, source level debugging capability is lost completely. When SDBG is launched with this modification to the source code, we see the disassembly immediately.

27 May 2015 2:26 #16351

Could you send us your simple example so we can look at it?

27 May 2015 2:52 #16352

DavidB already posted his simple example code, where you can do symbolic debugging in the main program but not in the function. Here is the code to reproduce case 2 in my post above, where there is complete failure of source debugging.

File adder.f90:

module interfaces

   interface
      function adder(a, b)
         real, intent(in) :: a, b
         real :: adder
      end function adder
   end interface

end module interfaces

program main

   use interfaces, only: adder

   real :: a, b, y
   a = 1.0
   b = 2.0

   y = adder(a, b)

   print *, y

end program main

File func.f90:

function adder(a, b)
   real, intent(in) :: a, b
   real :: adder
   adder = a + b
end function adder

Building and debugging:

ftn95 adder.f90 /debug
ftn95 func.f90 /debug
slink adder.obj func.obj /debug
sdbg adder.exe
27 May 2015 4:34 #16353

Quoted from Robert What do you mean by 'external function'?

As mecej4 says, it just means a function that is not inside a module. Sorry, I was using External in the sense of its definition in the Fortran standard.

I am compiling with debugging enabled (actually I am using /CHECK but that doesn't matter).

The 'complete' example is given at the top of this post.

Quoted from mecej4

  1. If the module with just the interface in it is moved to a separate file, source debugging capability is restored. DavidB, please try this strategy with your larger program and advise us as to whether it worked.

Yes this does work.

Quoted from mecej4

  1. If just the function code is moved to a separate file, leaving the module with the interface in place, source level debugging capability is lost completely. When SDBG is launched with this modification to the source code, we see the disassembly immediately.

Another manifestation of the same bug.

I generally don't use external functions so have only just found this with other peoples' code. Unfortunately they want the functions to be exportable in a DLL so I can't just move the function bodies into the modules.

Please login to reply.