C# 调试 DLL 的发布版本(带有 PDB 文件)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/769995/
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
Debugging a release version of a DLL (with PDB file)
提问by M4N
If I have a DLL (that was built in release-mode) and the corresponding PDB file, is it possible to debug (step-into) classes/methods contained in that DLL?
如果我有一个 DLL(以发布模式构建)和相应的 PDB 文件,是否可以调试(逐步进入)包含在该 DLL 中的类/方法?
If so, what are the required steps/configuration (e.g. where to put the PDB file)?
如果是,所需的步骤/配置是什么(例如将 PDB 文件放在哪里)?
Edit:
编辑:
If have the PDB file in the same place as the DLL (in the bin/debug directory of a simple console test application). I can see that the symbols for the DLL are loaded (in the Output window and also in the Modules window), but still I cannot step into the methods of that DLL.
如果 PDB 文件与 DLL 位于同一位置(在简单控制台测试应用程序的 bin/debug 目录中)。我可以看到 DLL 的符号已加载(在“输出”窗口和“模块”窗口中),但我仍然无法进入该 DLL 的方法。
Could this be the result of compiler optimizations (as described by Michael in his answer)?
这可能是编译器优化的结果(如迈克尔在他的回答中所描述的)?
采纳答案by M4N
I finally found what cause the problems debugging a DLL that was built in release configuration:
我终于找到了导致调试在发布配置中内置的 DLL 出现问题的原因:
First of all, it basically works as expected. Which means, if I have a DLL built in release-configuration plus the corresponding PDB file, then I can debug the classes/methods contained in that DLL.
首先,它基本上按预期工作。这意味着,如果我有一个内置发布配置的 DLL 加上相应的 PDB 文件,那么我可以调试该 DLL 中包含的类/方法。
When I first tried this, I unfortunately tried to step into methods of a class which has the DebuggerStepThroughAttribute, e.g:
当我第一次尝试这个时,不幸的是我试图进入一个具有DebuggerStepThroughAttribute的类的方法,例如:
[System.Diagnostics.DebuggerStepThrough]
public class MyClass {
public void Test() { ... }
}
In that case, it is of course not possible to step into the method from the debugger (as expected/intended).
在这种情况下,当然不可能从调试器进入该方法(如预期/预期的那样)。
So everything works as intended. Thanks a lot for your answers.
所以一切都按预期工作。非常感谢你的回答。
回答by Marc Gravell
The pdb is usually (for me at least) detected if it is next to the dll (like with the intellisense xml files).
如果 pdb 位于 dll 旁边(就像智能感知 xml 文件一样),通常会(至少对我而言)检测到它。
Alternatively; you'll need a break point after the module has loaded...
或者; 模块加载后你需要一个断点......
At the break-point, bring up the "Modules" window (Ctrl+D,M - or Debug->Windows->Modules). Right click on your dll "Load symbols from", "Symbol path", etc.
在断点处,调出“模块”窗口(Ctrl+D,M - 或 Debug->Windows->Modules)。右键单击您的 dll“从以下位置加载符号”、“符号路径”等。
回答by Michael
Yes, you can debug release code with a PDB. There are some pitfalls however with debugging optimized code, more info hereand here.
是的,您可以使用 PDB 调试发布代码。然而,调试优化代码有一些陷阱,更多信息在这里和这里。
Your PDB just needs to be in a place that the debugger can find it - for local debugging same directory as the dll is usually easiest. Otherwise, put it in some place that the debugger can find it, and point the debugger to that place with the symbol path.
您的 PDB 只需要在调试器可以找到它的地方 - 对于本地调试,与 dll 相同的目录通常是最简单的。否则,将其放在调试器可以找到的某个位置,并使用符号路径将调试器指向该位置。
回答by Stephen Nutt
Debugging a release build is typically much harder that debugging a debug version. In general you'll need some understanding of x86 assembler and you'll likely spend some time looking at the disassembly window. This tends to be the only way to figure out what line of code you are really on since in a release build with optimizations on the compiler may do significant inlining and instruction reordering. In addition I find the debugger frequently fails to correctly report values of variables. If you need to know a variable's value and you are not sure the debugger is correct, go into the disassembly window and find the memory location or register it is located in.
调试发布版本通常比调试调试版本要困难得多。通常,您需要对 x86 汇编器有一定的了解,并且可能会花一些时间查看反汇编窗口。这往往是确定您真正使用哪一行代码的唯一方法,因为在编译器优化的发布版本中可能会进行重要的内联和指令重新排序。此外,我发现调试器经常无法正确报告变量的值。如果您需要知道一个变量的值并且您不确定调试器是否正确,请进入反汇编窗口并找到它所在的内存位置或寄存器。
The pdb files can be stored in a Symbol Server. Check out Setting up a Symbol Serverfor a good tutorial. Every product we build on a build machine publishes the symbols to our symbol server, so we can always debug any crash dumps we receive from WinQual.
pdb 文件可以存储在符号服务器中。查看设置符号服务器以获得一个很好的教程。我们在构建机器上构建的每个产品都会将符号发布到我们的符号服务器,因此我们始终可以调试从 WinQual 收到的任何故障转储。