如何从C#调试进入Fortran代码?

huangapple go评论83阅读模式
英文:

How can I debug into Fortran code from C#?

问题

I have a mixed language class library used for numerical modeling. It is C# calling a native DLL that is created using C++ wrapping Fortran libraries. My solution contains a unit testing project, from which I can debug from the C# into the C++ and Fortran. I have a specific unit test that compares modeling results with different class library. This second library has C# calling Fortran directly. It is this second library that is giving me a problem. I have been able to compile most of the DLLs for this second library in debug mode using "Enable native code debugging" for the C# projects. I have also enabled "Just my code" to avoid debugging through Microsoft code. I can step from my unit test into the C# layer of the second library. When I get to the only Fortran call, my step into just steps over. After the step over, but not before, I can see the Fortran DLL I am trying to step into in the modules window. It is listed as user code and the pdb file is correctly referenced. I have forced the debugger to run the Fortran a second time, but it still will not step in. I have run out of ideas on what to check to get the debugging to work.

I have not included the projects from the second library into my solution. I am just pulling the compiled DLLs from a directory.

I am using VS2019 16.11.18 and Intel Fortran 2019.6.324

Edit: Some details.

I have not included the code from the second library in my solution because it uses Fortran source which has been modified from my original source and is incompatible. The team that modified it did not consider compatibility with other users and applications.

Update 6/13/2023:

I took the code from my unit test and created a simple application. It has a run button, so I can start the program separately from running the numerics, and a console to monitor output. I have tried starting the program and then using debug -> attach from the class library. I can then run the calculation and see the debugger step though the C# in the library, but it won't step into the Fortran. I did put break points in the Fortran. When I mouse over them, it says that symbols are not loaded. It is debug mode and debug native code is enabled.

英文:

I have a mixed language class library used for numerical modeling. It is C# calling a native DLL that is created using C++ wrapping Fortran libraries. My solution contains a unit testing project, from which I can debug from the C# into the C++ and Fortran. I have a specific unit test that compares modeling results with different class library. This second library has C# calling Fortran directly. It is this second library that is giving me a problem. I have been able to compile most of the DLLs for this second library in debug mode using "Enable native code debugging" for the C# projects. I have also enabled "Just my code" to avoid debugging through Microsoft code. I can step from my unit test into the C# layer of the second library. When I get to the only Fortran call, my step into just steps over. After the step over, but not before, I can see the Fortran DLL I am trying to step into in the modules window. It is listed as user code and the pdb file is correctly referenced. I have forced the debugger to run the Fortran a second time, but it still will not step in. I have run out of ideas on what to check to get the debugging to work.

I have not included the projects from the second library into my solution. I am just pulling the compiled DLLs from a directory.

I am using VS2019 16.11.18 and Intel Fortran 2019.6.324

Edit: Some details.

I have not included the code from the second library in my solution because it uses Fortran source which has been modified from my original source and is incompatible. The team that modified it did not consider compatibility with other users and applications.

Update 6/13/2023:

I took the code from my unit test and created a simple application. It has a run button, so I can start the program separately from running the numerics, and a console to monitor output. I have tried starting the program and then using debug -> attach from the class library. I can then run the calculation and see the debugger step though the C# in the library, but it won't step into the Fortran. I did put break points in the Fortran. When I mouse over them, it says that symbols are not loaded. It is debug mode and debug native code is enabled.

答案1

得分: 0

我最终找到了解决方法。与其从我的库解决方案中运行单元测试,我在包含需要调试的DLL的解决方案中创建了一个单元测试项目。除了单元测试之外,我还不得不将我的库中的42个类移动到新的单元测试项目中。一旦我正确构建了单元测试,我发现每次运行它时都必须手动复制3个英特尔Fortran DLL到单元测试运行的文件夹中。最后的关键是,我必须以管理员模式运行Visual Studio。这在我自己的解决方案中调试本地代码时并不需要。我不知道为什么需要管理员模式。

英文:

I finally came up with a resolution. Instead of running a unit test from my library solution, I created a unit test project in the solution containing the DLLs I needed to debug. In addition to the unit test, I had to move 42 classes from my library into the new unit test project. Once I had the unit test building correctly, I found that I had to hand copy 3 Intel Fortran DLLs into the folder where the unit test was running, each time I ran it. The final piece of the puzzle was that I had to run Visual Studio in admin mode. This is not something I had to do when debugging into native code in my own solution. I do not know why admin mode is required.

huangapple
  • 本文由 发表于 2023年6月12日 05:43:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76452615.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定