我是否应该将调试信息编译为“完整”版本?或“仅限 pdb”?

发布于 2024-12-08 22:30:24 字数 302 浏览 1 评论 0原文

在 Visual Studio for a C# 项目中,如果转到“项目属性”>“构建>高级>调试信息您有三个选项:nonefullpdb-only

哪种设置最适合发布版本?


那么,fullpdb-only 之间有什么区别?

如果我使用 full 会对性能产生影响吗?如果我使用 pdb-only 调试生产问题会更困难吗?

In Visual Studio for a C# project, if you go to Project Properties > Build > Advanced > Debug Info you have three options: none, full, or pdb-only.

Which setting is the most appropriate for a release build?


So, what are the differences between full and pdb-only?

If I use full will there be performance ramifications? If I use pdb-only will it be harder to debug production issues?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

蓝戈者 2024-12-15 22:30:24

我将使用 pdb-only 进行构建。您将无法将调试器附加到已发布的产品,但如果您收到故障转储,您可以使用 Visual Studio 或 WinDBG 检查崩溃时的堆栈跟踪和内存转储。

如果您使用 full 而不是 pdb-only,您将获得相同的好处,只不过可执行文件可以直接附加到调试器。您需要根据您的产品和需求确定这是否合理。顾客。

请务必将 PDB 文件保存在某个位置,以便在收到崩溃报告时可以引用它们。如果您可以设置 符号服务器 来存储这些调试符号,那就更好了。

如果您选择使用none进行构建,那么当现场发生崩溃时您将无法追索。您将无法对事故进行任何形式的事后检查,这可能会严重妨碍您追踪问题的能力。

关于性能的说明:

两者John Robbins< /a> 和 Eric Lippert 撰写了有关 /debug 标志的博客文章,它们都表明此设置对性能的影响为零。有一个单独的 /optimize 标志指示编译器是否应该执行优化。

I would build with pdb-only. You will not be able to attach a debugger to the released product, but if you get a crash dump, you can use Visual Studio or WinDBG to examine the stack traces and memory dumps at the time of the crash.

If you go with full rather than pdb-only, you'll get the same benefits, except that the executable can be attached directly to a debugger. You'll need to determine if this is reasonable given your product & customers.

Be sure to save the PDB files somewhere so that you can reference them when a crash report comes in. If you can set up a symbol server to store those debugging symbols, so much the better.

If you opt to build with none, you will have no recourse when there's a crash in the field. You won't be able to do any sort of after-the-fact examination of the crash, which could severely hamper your ability to track down the problem.

A note about performance:

Both John Robbins and Eric Lippert have written blog posts about the /debug flag, and they both indicate that this setting has zero performance impact. There is a separate /optimize flag which dictates whether the compiler should perform optimizations.

痴情换悲伤 2024-12-15 22:30:24

警告
/debug 开关的 MSDN 文档(在 Visual Studio 中是调试信息)似乎已经过时了!这就是它的内容不正确

如果您使用 /debug:full,请注意,这会对
JIT 优化代码的速度和大小,对代码影响很小
/debug 的质量:完全。我们建议 /debug:pdbonly 或不使用 PDB
生成发布代码。

/debug:pdbonly 和 /debug:full 之间的一个区别是
/debug:full 编译器发出一个 DebuggableAttribute,用于
告诉 JIT 编译器调试信息可用。

那么,现在的情况又是怎样呢?

  1. 仅 Pdb – 在 .NET 2.0 之前,它有助于调查已发布产品(客户计算机)的故障转储。但它不允许附加调试器。 .NET 2.0 中的情况并非如此。它与完全完全相同。
  2. 完整 – 这有助于我们调查故障转储,还允许我们将调试器附加到发布版本。但与 MSDN 提到的不同,它不会影响性能(自 .NET 2.0 起)。它的功能与仅 Pdb 完全相同。

如果它们完全相同,为什么我们有这些选项? John Robbins(Windows 调试之神)发现这些是由于历史原因。

在 .NET 1.0 中存在差异,但在 .NET 2.0 中则没有。
看起来 .NET 4.0 将遵循相同的模式。后
与 CLR 调试团队仔细检查,没有任何区别
全部。

控制 JITter 是否进行调试构建的是 /optimize
转变。 <...>

底线是您想要构建您的发布版本
/optimize+ 和任何 /debug 开关,以便您可以使用源代码进行调试
代码。

然后他继续证明这一点。

现在,优化是单独开关 /optimize 的一部分(在 Visual Studio 中称为优化代码)。

简而言之,无论 DebugInfo 设置 pdb-only 还是 full,我们都会得到相同的结果。建议避免,因为它会使您无法分析已发布产品或附加调试器的故障转储。

WARNING
MSDN documentation for /debug switch (In Visual Studio it is Debug Info) seems to be out-of-date! This is what it has which is incorrect

If you use /debug:full, be aware that there is some impact on the
speed and size of JIT optimized code and a small impact on code
quality with /debug:full. We recommend /debug:pdbonly or no PDB for
generating release code.

One difference between /debug:pdbonly and /debug:full is that with
/debug:full the compiler emits a DebuggableAttribute, which is used to
tell the JIT compiler that debug information is available.

Then, what is true now?

  1. Pdb-only – Prior to .NET 2.0, it helped to investigate the crash dumps from released product (customer machines). But it didn't let attaching the debugger. This is not the case from .NET 2.0. It is exactly same as Full.
  2. Full – This helps us to investigate crash dumps, and also allows us to attach debugger to release build. But unlike MSDN mentions, it doesn't impact the performance (since .NET 2.0). It does exactly same as Pdb-only.

If they are exactly same, why do we have these options? John Robbins (windows debugging god) found out these are there for historical reasons.

Back in .NET 1.0 there were differences, but in .NET 2.0 there isn’t.
It looks like .NET 4.0 will follow the same pattern. After
double-checking with the CLR Debugging Team, there is no difference at
all.

What controls whether the JITter does a debug build is the /optimize
switch. <…>

The bottom line is that you want to build your release builds with
/optimize+ and any of the /debug switches so you can debug with source
code.

then he goes on to prove it.

Now the optimization is part of a separate switch /optimize (in visual studio it is called Optimize code).

In short, irrespective of DebugInfo setting pdb-only or full, we will have same results. The recommendation is to avoid None since it would deprive you of being able to analyze the crash dumps from released product or attaching debugger.

栩栩如生 2024-12-15 22:30:24

您只需要 PDB,但不想将 PDB 文件提供给用户。不过,将它们与二进制文件一起使用,可以让您将故障转储加载到 WinDbg 等调试器中,并查看程序实际失败的位置。当您的代码在您无权访问的计算机上崩溃时,这可能非常有用。

完全调试将 [Debuggable] 属性添加到您的代码中。这对速度有很大影响。例如,可以禁用某些循环优化以使单步执行更容易。此外,它对 JIT 流程的影响很小,因为它打开了跟踪。

You'll want PDB only, but you won't want to give the PDB files to users. Having them for yourself though, alongside your binaries, gives you the ability to load crash dumps into a debugger like WinDbg and see where your program actually failed. This can be rather useful when your code is crashing on a machine you don't have access to.

Full debug adds the [Debuggable] attribute to your code. This has a huge impact on speed. For example, some loop optimizations may be disabled to make single stepping easier. In addition, it has a small effect on the JIT process, as it turns on tracking.

云裳 2024-12-15 22:30:24

我正在编写未处理的异常处理程序,并且堆栈跟踪包含仅使用 pdb 时的行号,否则当我选择“无”时,我只会获取子/函数的名称。

如果我不分发 .pdb,即使使用仅 pdb 构建,我也不会在堆栈跟踪中获得行号。

因此,我将 pdb 与 VB 应用程序中的 exe 一起分发(XCOPY 部署在 LAN 上)。

I'm in the process of writing a unhandled exception handler and the stack trace includes the line number when pdb-only is used, otherwise I just get the name of the Sub/Function when I choose None.

If I don't distribute the .pdb I don't get the line number in the stack trace even with the pdb-only build.

So, I'm distributing (XCOPY deploy on a LAN) the pdb along with the exe from my VB app.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文