如何调试从C#代码调用的C ++ dll? [英] How to debug a c++ dll called from C# code?

查看:338
本文介绍了如何调试从C#代码调用的C ++ dll?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在计算机A上运行A.exe(用C#编码),在计算机B上运行B.exe(用C#编码).
A.exe需要通过TCP与B.exe进行通信.
B.exe通过COM调用C.dll(用C ++编码).
现在,C.dll中存在一个错误.我做了以下调试准备:
(1).打开A.exe的项目以在计算机A中调试A.exe.
(2).在计算机B中打开Visual Studio并附加B.exe进程.
(3).将C.dll及其符号文件与B.exe放在一起,加载符号,打开其源代码并设置断点.

调试时,我发现它无法在C.dll中命中断点,并提示当前将不命中该断点.此文档未加载任何符号".

我确定C.dll与它的pdb文件匹配.

我的设置是否存在任何错误,否则无法正常工作?
非常感谢!

I have a A.exe(coded in C#) running on machine A, B.exe(Coded in C#) running on machine B.
A.exe needs to communicate with B.exe through TCP.
B.exe calls a C.dll(Coded in C++) through COM.
Now there a bug exists in C.dll. I do the following preparations for debugging:
(1). Open A.exe''s project to debug A.exe in machine A.
(2). Open visual studio in machine B and attach B.exe process.
(3). Put C.dll and its symbol file together with B.exe, load symbols, open its source code and set breakpoints.

When debugging, I found it cann''t hit the breakpoint in C.dll and tips "The breakpoint will not currently be hit. No symbols have been loaded for this document".

I am sure C.dll is matched with its pdb file.

Is there any error in my settings or this way won''t work?
Thanks very much!

推荐答案

这是我通常要做的.
在调试模式下同时构建B.exe和C.dll.
在Visual Studio中打开C.dll解决方案,然后从该解决方案进行调试.
按F5时,将询问可执行文件.
将其指向以调试模式构建的B.exe.
Here is what I usually do.
Build both B.exe and C.dll in debug mode.
Open the C.dll solution in Visual Studio and debug from this solution.
When pressing F5, it will ask for the executable.
Point it to B.exe that was build in debug mode.


您可以做的另一件事是为C ++中的C.dll编写测试工具.然后,您可以测试每种行为(即创建一个对象,通过一系列函数调用将其击中,然后查看对象的最终状态是什么),然后查看它是否达到了您的期望.如果您进行的测试反映了C#应用程序的预期行为,则您也许可以找出问题的根源.

如果它的行为符合您的预期,则说明您知道客户端代码中的错误.如果不是,那么您就知道它在DLL中.而且,如果您没有DLL的源代码,则可能会遇到麻烦,因为无法修复它,但是您可以在客户端代码中解决它.
Another thing you could do is write a test harness for C.dll in C++. Then you can test each behaviour (i.e. create an object, hit it with a sequence of function calls and see what the final state of the object is) and see if it does what you expect. If you make the tests mirror the behaviours the C# app expects you might be able to work out where the source of the problem is.

If it does behave as you expect then you know the bug''s in the client code. If it doesn''t then you know it''s in the DLL. And if you haven''t got the source code for the DLL you might be in trouble as you can''t fix it but you might be able to work around it in your client code.


这篇关于如何调试从C#代码调用的C ++ dll?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆