.net 发布生成 .pdb 文件,为什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5457095/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 15:24:59  来源:igfitidea点击:

Release generating .pdb files, why?

.netvisual-studiodebuggingpdb-filesdebug-symbols

提问by m.edmondson

Why does Visual Studio 2005 generate the .pdbfiles when compiling in release? I won't be debugging a release build, so why are they generated?

为什么 Visual Studio 2005.pdb在发布时编译时会生成文件?我不会调试发布版本,那么为什么会生成它们呢?

回答by Cody Gray

Because without the PDB files, it would be impossible to debug a "Release" build by anything other than address-level debugging.Optimizations really do a number on your code, making it very difficult to find the culprit if something goes wrong (say, an exception is thrown). Even setting breakpoints is extremely difficult, because lines of source code cannot be matched up one-to-one with (or even in the same order as) the generated assembly code. PDB files help you and the debugger out, making post-mortem debugging significantly easier.

因为如果没有 PDB 文件,就不可能通过地址级调试以外的任何方式来调试“发布”构建。优化确实对您的代码产生了影响,如果出现问题(例如抛出异常),则很难找到罪魁祸首。甚至设置断点也极其困难,因为源代码行无法与生成的汇编代码一一对应(或什至以相同的顺序)。PDB 文件可以帮助您和调试器,使事后调试变得更加容易。

You make the point that if your software is ready for release, you should have done all your debugging by then. While that's certainly true, there are a couple of important points to keep in mind:

您指出,如果您的软件已准备好发布,那么您应该在那时完成所有调试。虽然这当然是真的,但有几个要点需要牢记:

  1. You should alsotest and debug your application (before you release it) using the "Release" build. That's because turning optimizations on (they are disabled by default under the "Debug" configuration) can sometimes cause subtle bugs to appear that you wouldn't otherwise catch. When you're doing this debugging, you'll want the PDB symbols.

  2. Customers frequently report edge cases and bugs that only crop up under "ideal" conditions. These are things that are almost impossible to reproduce in the lab because they rely on some whacky configuration of that user's machine. If they're particularly helpful customers, they'll report the exception that was thrown and provide you with a stack trace. Or they'll even let you borrow their machine to debug your software remotely. In either of those cases, you'll want the PDB files to assist you.

  3. Profiling should alwaysbe done on "Release" builds with optimizations enabled. And once again, the PDB files come in handy, because they allow the assembly instructions being profiled to be mapped back to the source code that you actually wrote.

  1. 应该使用“发布”版本测试和调试您的应用程序(在发布之前)。这是因为打开优化(它们在“调试”配置下默认禁用)有时会导致出现细微的错误,否则您不会发现这些错误。在进行此调试时,您将需要 PDB 符号。

  2. 客户经常报告仅在“理想”条件下才会出现的边缘情况和错误。这些东西在实验室中几乎不可能重现,因为它们依赖于该用户机器的一些古怪配置。如果他们是特别有帮助的客户,他们会报告抛出的异常并为您提供堆栈跟踪。或者他们甚至会让你借用他们的机器远程调试你的软件。在任何一种情况下,您都需要 PDB 文件来帮助您。

  3. 始终在启用优化的“发布”版本上进行分析。再一次,PDB 文件派上用场,因为它们允许将被分析的汇编指令映射回您实际编写的源代码。

You can't go back and generate the PDB files afterthe compile.*If you don't create them during the build, you've lost your opportunity. It doesn't hurt anything to create them. If you don't want to distribute them, you can simply omit them from your binaries. But if you later decide you want them, you're out of luck. Better to always generate them and archive a copy, just in case you ever need them.

编译无法返回并生成 PDB 文件。*如果您不在构建期间创建它们,您就失去了机会。创建它们没有任何伤害。如果您不想分发它们,您可以简单地从二进制文件中省略它们。但是,如果您后来决定想要它们,那您就不走运了。最好始终生成它们并存档副本,以防万一您需要它们。

If you really want to turn them off, that's always an option. In your project's Properties window, set the "Debug Info" option to "none" for any configuration you want to change.

如果你真的想关闭它们,那总是一个选择。在项目的“属性”窗口中,将要更改的任何配置的“调试信息”选项设置为“无”。

Do note, however, that the "Debug" and "Release" configurations doby default use different settings for emitting debug information. You will want to keep this setting. The "Debug Info" option is set to "full" for a Debug build, which means that in addition to a PDB file, debugging symbol information is embedded into the assembly. You also get symbols that support cool features like edit-and-continue. In Release mode, the "pdb-only" option is selected, which, like it sounds, includes only the PDB file, without affecting the content of the assembly. So it's not quite as simple as the mere presence or absence of PDB files in your /bindirectory. But assuming you use the "pdb-only" option, the PDB file's presence will in no way affect the run-time performance of your code.

不过请注意,即“调试”和“释放”的配置发射调试信息在默认情况下使用不同的设置。您将希望保留此设置。对于 Debug 版本,“Debug Info”选项设置为“full”,这意味着除了 PDB 文件之外,调试符号信息也被嵌入到程序集中。您还可以获得支持编辑并继续等酷功能的符号。在 Release 模式下,选择了“pdb-only”选项,就像听起来一样,它只包含 PDB 文件,而不会影响程序集的内容。因此,这并不像/bin目录中是否存在 PDB 文件那么简单。但假设您使用“pdb-only”选项,则 PDB 文件'

*As Marc Sherman points out in a comment, as long as your source code has not changed (or you can retrieve the original code from a version-control system), you can rebuild it and generate a matching PDB file. At least, usually. This works well most of the time, but the compiler is not guaranteed to generate identical binaries each time you compile the same code, so there maybe subtle differences. Worse, if you have made any upgrades to your toolchain in the meantime (like applying a service pack for Visual Studio), the PDBs are even less likely to match. To guarantee the reliable generation of ex postfactoPDB files, you would need to archive not only the source code in your version-control system, but also the binaries for your entire build toolchain to ensure that you could precisely recreate the configuration of your build environment. It goes without saying that it is much easier to simply create and archive the PDB files.

*正如Marc Sherman 在评论中指出的那样,只要您的源代码没有更改(或者您可以从版本控制系统中检索原始代码),您就可以重建它并生成匹配的 PDB 文件。至少,通常。这在大多数情况下运行良好,但不能保证每次编译相同代码时编译器都生成相同的二进制文件,因此可能存在细微差别。更糟糕的是,如果您在此期间对工具链进行了任何升级(例如为 Visual Studio 应用服务包),则 PDB 更不可能匹配。保证可靠的事后生成PDB 文件,您不仅需要存档版本控制系统中的源代码,还需要存档整个构建工具链的二进制文件,以确保您可以精确地重新创建构建环境的配置。不用说,简单地创建和归档 PDB 文件要容易得多。

回答by Aliostad

PDB can be generated for Releaseas well as for Debug. This is set at (in VS2010 but in VS2005 must be similar):

PDB 可以生成 forRelease以及 for Debug。这是设置在(在 VS2010 但在 VS2005 中必须相似):

Project → Properties → Build → Advanced → Debug Info

项目 → 属性 → 构建 → 高级 → 调试信息

Just change it to None.

只需将其更改为None.

回答by user1714880

Without the .pdb files it is virtually imposible to step through the production code; you have to rely on other tools which can be costly and time consuming. I understand you can use tracing or windbg for instance but it really depends on what you want to achieve. In certain scenarios you just want to step through the remote code (no errors or exceptions) using the production data to observe particular behaviour, and this is where .pdb files come handy. Without them running the debugger on that code is impossible.

如果没有 .pdb 文件,几乎不可能单步执行生产代码;您必须依赖其他工具,这可能既昂贵又耗时。我知道您可以使用跟踪或windbg,但这实际上取决于您想要实现的目标。在某些情况下,您只想使用生产数据单步执行远程代码(无错误或异常)以观察特定行为,而这正是 .pdb 文件派上用场的地方。没有他们在该代码上运行调试器是不可能的。

回答by jdehaan

Why are you so sure you will not debug release builds? Sometimes (hopefully rarely but happens) you may get a defect report from a customer that is not reproducible in the debug version for some reason (different timings, small different behaviour or whatever). If that issue appears to be reproducible in the release build you'll be happy to have the matching pdb.

为什么你这么确定你不会调试发布版本?有时(希望很少但会发生)您可能会从客户那里得到一份缺陷报告,由于某种原因(不同的时间、细微的不同行为或其他原因),该报告在调试版本中无法重现。如果该问题在发布版本中似乎可以重现,您将很高兴拥有匹配的 pdb。

回答by rlranft

Also, you can utilize crash dumps to debug your software. The customer sends it to you and then you can use it to identify the exact version of your source - and Visual Studio will even pull the right set of debugging symbols (and source if you're set up correctly) using the crash dump. See Microsoft's documentation on Symbol Stores.

此外,您可以利用故障转储来调试您的软件。客户将其发送给您,然后您可以使用它来识别源的确切版本 - Visual Studio 甚至会使用故障转储提取正确的调试符号集(如果设置正确,则为源)。请参阅 Microsoft关于 Symbol Stores文档

回答by Ajay2707

.PDB file is the short name of "Program Database". It contains the information about debug point for debugger and resources which are used or reference. Its generated when we build as debug mode. Its allow to application to debug at runtime.

.PDB 文件是“程序数据库”的简称。它包含有关调试器的调试点和使用或参考的资源的信息。它在我们以调试模式构建时生成。它允许应用程序在运行时进行调试。

The size is increase of .PDB file in debug mode. It is used when we are testing our application.

大小是在调试模式下 .PDB 文件的增加。它在我们测试我们的应用程序时使用。

Good article of pdb file.

pdb 文件的好文章。

http://www.codeproject.com/Articles/37456/How-To-Inspect-the-Content-of-a-Program-Database-P

http://www.codeproject.com/Articles/37456/How-To-Inspect-the-Content-of-a-Program-Database-P

回答by GregRos

In a multi-project solution, you usually want to have one configuration that generates no PDB or XML files at all. Instead of changing the Debug Infoproperty of every project to none, I thought it would be more expedient to add a post-build event that only works in a specific configuration.

在多项目解决方案中,您通常希望有一个完全不生成 PDB 或 XML 文件的配置。与其将Debug Info每个项目的属性更改为none,我认为添加一个仅适用于特定配置的构建后事件会更方便。

Unfortunately, Visual Studio doesn't allow you to specify different post-build events for different configurations. So I decided to do this manually, by editing the csprojfile of the startup project and adding the following (instead of any existing PostBuildEventtag):

不幸的是,Visual Studio 不允许您为不同的配置指定不同的生成后事件。因此,我决定手动执行此操作,方法是编辑csproj启动项目的文件并添加以下内容(而不是任何现有PostBuildEvent标签):

  <PropertyGroup Condition="'$(Configuration)' == 'Publish'">
    <PostBuildEvent>
        del *.pdb
        del *.xml
    </PostBuildEvent>
  </PropertyGroup>

Unfortunately, this will make the post build event textbox blank and putting anything in it can have unpredictable results.

不幸的是,这将使后期构建事件文本框空白,并且将任何内容放入其中可能会产生不可预测的结果。

回答by Mark Johanes

Debug symbols (.pdb) and XML doc (.xml) files make up a large percentage of the total size and should not be part of the regular deployment package. But it should be possible to access them in case they are needed.

调试符号 ( .pdb) 和 XML doc (.xml) 文件占总大小的很大一部分,不应成为常规部署包的一部分。但是应该可以在需要时访问它们。

One possible approach: at the end of the TFS build process, move them to a separate artifact.

一种可能的方法:在 TFS 构建过程结束时,将它们移至单独的工件。

回答by prosti

Actually without PDB files and symbolic information they have it would be impossible to create a successful crash report (memory dump files) and Microsoft would not have the complete picture what caused the problem.

实际上,如果没有 PDB 文件和他们拥有的符号信息,就不可能创建成功的崩溃报告(内存转储文件),而且 Microsoft 将无法了解导致问题的原因。

And so having PDB improves crash reporting.

因此,拥有 PDB 可以改进崩溃报告。