开发者

How to debug into Quantlib via SWIG from my C# unit test

开发者 https://www.devze.com 2023-02-15 02:30 出处:网络
I h开发者_运维知识库ave a module in Quantlib that does not work right when I invoke it from C# via SWIG. Is there a way I could debug into Quantlib from my C# unit test?No one else has answered yet, s

I h开发者_运维知识库ave a module in Quantlib that does not work right when I invoke it from C# via SWIG. Is there a way I could debug into Quantlib from my C# unit test?


No one else has answered yet, so I'll provide what we do in similar situations when debugging Ruby + SWIG.

Create a Visual Studio project that contains the C# Source Generated by SWIG, the C++ generated by SWIG, your C# unit test and the rest of the Quantlib source.

I just looked through the Quantlib provided Visual Studio solution files and don't see the SWIG targets, which is unfortunate, but if you have the C++ source at least, and can build it in debug mode, you might get there. The hard part is that the C# Dll you are calling is going to be expecting to references a certain C++ DLL in its calls. You may have to move your C++ Quantlib debug library into the Debug folder of the C# project, so it finds the specific version you want.

Once you have your solution configured, build everything as debug or rel with debug symbols.

If you at this point have the C# bindings source and the Quantlib C++ source in the same solution, you should be able to set a break point anywhere in the C# or C++ and be able to step through the calls from one to the other.

With our SWIG Ruby situation we are able to set breakpoints in the SWIG generated CXX file or in the C++ library source which is wrapped by swig and step through the calls made by the Ruby interpreter. We are able to do this by launching ruby from within Visual Studio as the start up project.

  • This is probably the key point. Have both the DLL you want to debug and the application which is loading your DLL (even if it is with a LoadLibrary call, as it would be from C# or from Ruby) in the same solution. Then Visual Studio will honor your break points in the debugged DLL. If the breakpoints are not being honored you may need to use procexp from Microsoft to see which DLL is loaded and if the C# library is finding a different version of the C++ library than you want it to.

I hope this information provides some help.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号