2

假设我在调试模式下编译了一个动态库(Windows DLL 和/或 Linux 共享对象文件,.so)以供动态链接到它的客户端应用程序使用。我的源代码可供客户端应用程序开发人员使用。

我需要对以下调试场景进行一些说明。我一直理解/假设为了让客户端应用程序调试到我的库中(例如,为了让客户端应用程序开发人员在调试时进入我的源代码,比如说使用F10in MS VC++),他们实际上必须自己构建了我的库的本地副本(可以访问我的源代码),或者至少可以在本地访问我的源代码而无需构建它(不确定这是否足够?)。

我说得对吗?换句话说,如果客户端应用程序动态链接到我自己动态构建的应用程序,我认为仅仅为库提供调试符号(MS VC++ 中的 PDB 文件)是不够的。感谢是否有人可以帮我解决这个问题?Linux 的情况如何?我的理解又和上面一样。现在,如果我编译了一个静态库(Windows LIB 和/或 Linux 库 .a);我的理解是,他们不需要我的源代码的本地构建副本(我还没有尝试过这个)?

我的前提是否正确?如果没有,有人可以提供一些详细的解释,最好用一个例子吗?感谢您的输入。

4

2 回答 2

2

I have more experience with Windows than linux. But I would think the concept is similar.

if the client application is linking dynamically to my application which has itself been built dynamically.

I'm not quite sure if I understand "building dynamically". You might be confused with the dynamic aspect of dll? dll is linked at runtime (not build time) to allow a part of component to be deployed without a full app. For example, an app on Windows that rely on a dll provided by the OS are not impacted when Windows updates that dll as long as the interface is maintained. The only difference between a dll and exe is that dll's entry function is dllmain as opposed to main in exe.

(The only "dynamic build" concept I can think of is building templated classes. But I don't think that's what you mean here.)

Hence, debugging a .dll isn't different from debugging a .exe, it's just that .dll is a separate binary file from the executable. All the source code provide is allowing debugger to align the stepping with lines in source code. When source code is not available, then debugger can still step through assembly code with symbols.

When situation doesn't allow, then developers who are good at reading assembly code can do debugging with only symbols and no source code.

You can usually build a binary with optimized option, then compiler might optimize the assembly code so much that source code alignment in the debugger might not be possible. This usually happens with released code. In those cases when you step through the code, you sometimes see the line or condition jumps that are seemingly different from what you would expect. There is the same on .exe, .exe with libs, or .dll. This is probably why you thought it is always necessary to build your own binary to debug dlls?

于 2012-07-06T06:19:48.540 回答
2

根据要求,这是我的评论作为答案。由于它只解决了 Windows 方面的问题,任何拥有 Linux(或 Mac!)部分答案的人都可以自由编辑它(我已将此标记为社区 wiki 答案)。


对于 VC++,只需要调试构建 DLL + 匹配 PDB + 匹配源即可。困难的部分是让他们都匹配;-)

此外,如果源文件与编译 DLL 时的路径相同,它会更顺利地工作,但 Visual Studio 也完全能够提示您手动浏览源文件(如果有的话)。

于 2012-07-06T17:35:02.213 回答