visual-studio 如何解决“二进制文件不是用调试信息构建的”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/646689/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get around "Binary was not built with debug information"?
提问by Mason Wheeler
I'm trying to debug a C DLL that I'm using with a Delphi program. I built the DLL with Visual C++, with debug information enabled. I built the Delphi program with Delphi 2009, with debug information enabled. But apparently they use different formats, because when I try to attach the VC++ debugger to my program, it says "binary was not built with debug information" and won't even accept as valid the breakpoints I put in the C code, which wasbuilt with debug info in the format VC++ understands.
我正在尝试调试与 Delphi 程序一起使用的 C DLL。我使用 Visual C++ 构建了 DLL,并启用了调试信息。我使用 Delphi 2009 构建了 Delphi 程序,并启用了调试信息。但显然他们使用不同的格式,因为当我尝试将 VC++ 调试器附加到我的程序时,它说“二进制文件不是用调试信息构建的”,甚至不会接受我在 C 代码中放置的断点是有效的,这是以 VC++ 理解的格式使用调试信息构建。
Does anyone know how I can get this to work?
有谁知道我怎样才能让它发挥作用?
回答by Logan Capaldo
When you say "won't accept as valid" the debug breakpoints in the C code what do you mean exactly? Does it not enable them? If so has the DLL been loaded yet when you set the breakpoints? I find it can simplify matters if I wait to set the breakpoints until after I'm sure the DLL in question has been loaded. If this is not what is happening, please elaborate on what you mean by "valid" breakpoints.
当您说“不会接受为有效”时,C 代码中的调试断点究竟是什么意思?它不启用它们吗?如果是这样,当您设置断点时,DLL 是否已加载?我发现如果我等到确定有问题的 DLL 已加载后才设置断点,则可以简化问题。如果这不是正在发生的事情,请详细说明“有效”断点的含义。
Other options are to set function breakpoints, or the compile the DLL with strategically placed DebugBreak()calls.
其他选项是设置函数断点,或使用战略性DebugBreak()调用来编译 DLL 。
Are you sure it's the right DLL that's being loaded (i.e. the debug version)?. Again, even the right DLL is being loaded I'm not sure the error is necessarily applying to the DLL and not just the main executable. Or it could be having problems loading the symbol database as suggested by jdigital, assuming you extract them out for debug builds of your DLL. Even with no debugging symbols, debugging should still be feasible, especially since it's a DLL, you can work from the exported symbols.
您确定加载的是正确的 DLL(即调试版本)吗?同样,即使加载了正确的 DLL,我也不确定错误是否一定适用于 DLL 而不仅仅是主可执行文件。或者它可能会按照 jdigital 的建议加载符号数据库时出现问题,假设您将它们提取出来用于 DLL 的调试版本。即使没有调试符号,调试也应该是可行的,尤其是因为它是一个 DLL,您可以使用导出的符号进行工作。
This isn't a COM component is it? If it is, I'd double check that the debug version was the one registered before you start up your process.
这不是 COM 组件吗?如果是,我会仔细检查调试版本是否是您启动流程之前注册的版本。
Again I'd still be interested in hearing exactly what happens when you try to set a break point. If you go to the breakpoints window in VS it should clarify why the breakpoint couldn't be set, if that's what is happening.
同样,我仍然有兴趣了解当您尝试设置断点时会发生什么。如果您转到 VS 中的断点窗口,它应该说明无法设置断点的原因,如果发生了这种情况。
Hmm. I don't have much experience with /Z7, do you still have the .obj file for the DLL? The docs seem to imply that's necessary for debugging. Alternatively I'd try building with /Ziinstead and getting a .pdb for that sucker. 
唔。我没有太多经验/Z7,你还有 DLL 的 .obj 文件吗?文档似乎暗示这是调试所必需的。或者,我会尝试用它/Zi来构建并为那个傻瓜获取一个 .pdb。
回答by Logan Capaldo
Debug formats are not standardised - basically you can't use Delphi to debug MS compiled code or vice versa.
调试格式没有标准化——基本上你不能使用 Delphi 来调试 MS 编译的代码,反之亦然。
You can debug Delphi DLLs in Delphi and you can use those DLLs with other apps not compiled with Delphi, provided you mark the Delphi functions for export. What you can't do is debug those DLLs symbolically in a 3rd party debugger, which would have to understand Object Pascal name mangling at the very least.
您可以在 Delphi 中调试 Delphi DLL,并且可以将这些 DLL 与其他未使用 Delphi 编译的应用程序一起使用,前提是您将 Delphi 函数标记为导出。您不能做的是在第 3 方调试器中以符号方式调试这些 DLL,这至少必须了解 Object Pascal 名称修饰。
回答by Ken White
Not sure about Visual C++ (don't have it installed at all anymore), but maybe this will help...
不确定 Visual C++(不再安装它),但也许这会有所帮助......
If you were writing a DLL in Delphi and using it from C++, and you wanted to debug the DLL, you'd open the source for the DLL in Delphiand set a breakpoint. You'd then use Run|Parameters and set the C++ application as the host executable and hit run in the Delphi IDE. The IDE would then launch the C++ application and run it as usual until the breakpoint in the DLL was hit, and then would break as you'd expect.
如果您在 Delphi 中编写一个 DLL 并从 C++ 使用它,并且您想调试该 DLL,您将在Delphi 中打开 DLL 的源代码并设置一个断点。然后,您将使用 Run|Parameters 并将 C++ 应用程序设置为主机可执行文件,然后在 Delphi IDE 中点击运行。然后,IDE 将启动 C++ 应用程序并照常运行它,直到命中 DLL 中的断点,然后会如您所愿地中断。
Is something similar available in VC++? (You didn't say which version of VC++, or which version of Visual Studio or the earlier IDE you were using.)
VC++ 中有类似的东西吗?(您没有说明您使用的是哪个版本的 VC++,或哪个版本的 Visual Studio 或更早的 IDE。)
If not, the only alternative I could think of is to do a quick VC++ app that uses the DLL and debug via that instead.
如果没有,我能想到的唯一替代方法是做一个使用 DLL 的快速 VC++ 应用程序并通过它进行调试。
回答by jdigital
回答by jdigital
Insure that is opening the DLL in the Debug Folder, not another one in some other folder.
确保在调试文件夹中打开 DLL,而不是在其他文件夹中打开另一个。
回答by Mark Longmire
Ten years later and this is happening to me, while debugging a custom DLL used in Team Developer, setting debugging command to start the Team Developer IDE. The objective is to step through the 3rd party code to the point of invocation of an exported function from the DLL.
十年后,这发生在我身上,在调试 Team Developer 中使用的自定义 DLL 时,设置调试命令以启动 Team Developer IDE。目标是单步执行第 3 方代码到调用从 DLL 导出的函数的点。
Starting the debugger launches the IDE without error, but running the TD project within the TD IDE causes an exception in VS on a DLL used by the TD IDE.
启动调试器可以无误地启动 IDE,但在 TD IDE 中运行 TD 项目会导致 VS 中 TD IDE 使用的 DLL 出现异常。
How do I ignore the exceptions from outside the project? Has anyone been able to get around this since '09?
如何忽略项目外部的异常?自 09 年以来,有没有人能够解决这个问题?

