且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

即使使用DebugType = full,也无法在发布模式下调试应用程序

更新时间:2023-01-02 21:33:53

调试优化的代码并不是一件很愉快的事情。您当然可能在设置断点时遇到麻烦,可能已内联了一个方法。当变量被优化以存储在cpu寄存器中时,检查局部变量和方法参数很容易使调试器感到困惑。

Debugging optimized code is no great pleasure. You certainly may have trouble setting breakpoints, a method may have been inlined. And inspecting local variables and method arguments is liable to make the debugger sulky when the variable was optimized to be stored in a cpu register.

您当然仍然可以检查调用堆栈,您将看到堆栈跟踪中未内联的方法。您可能会犯的基本错误:

You however certainly can still inspect call stacks, you'll see the methods that didn't get inlined in the stack trace. Basic mistakes you might make:


  • 连接调试器时,可以选择调试器类型。确保选择托管,对于本机调试器来说并没有太多用处。

  • 确保您正在寻找正确的线程,该程序可以在任意位置被破坏。使用Debug + Windows + Threads选择适当的线程

  • 请确保您实际上在代码中的某个位置被打断了。您可以轻松地将其放入Windows操作系统DLL或框架方法中,在这种情况下,几乎没有什么可看的。工具+选项,调试,符号并启用符号服务器,以便Windows内部启动的堆栈跟踪准确无误

  • 调试器必须能够找到PDB文件。使用Debug + Windows + Modules,您将看到过程中加载的程序集。首先确保您要调试的已被实际加载。右键单击它,然后选择符号负载信息。它向您显示在哪里寻找PDB文件

  • 仅我的代码选项可能会严重影响您的工作,您很可能会遇到大量非您自己的代码。工具+选项,调试,常规,然后关闭该选项。

  • when you attach a debugger, you get the option to select the debugger type. Be sure to select "Managed", you will not have much use for the native debugger
  • be sure that you are looking at the correct thread, the program can be broken at an arbitrary location. Use Debug + Windows + Threads to select the appropriate thread
  • be sure that you are actually broken at a location in your code. You can easily end up inside a Windows operating system DLL or a framework method, there will be very little to look at when that's the case. Tools + Options, Debugging, Symbols and enable the symbol server so that stack traces that start inside Windows will be accurate
  • the debugger must be able to locate the PDB files. Use Debug + Windows + Modules, you'll see the assemblies loaded in the process. First make sure that the one you want to debug is actually loaded. Right-click it and select "Symbol load information". It shows you where it looked for the PDB file
  • the "just my code" option can get in the way heavily, you are very likely to run into significant chunks of code that are not yours. Tools + Options, Debugging, General and turn that option off.