Delphi:如何从调试器中排除单元?
有时,当我逐步调试时,就在 FormCreate 事件之前或 FromDestroy 之后,调试器开始打开 DevExpress 单元(cxContainer.pas,...),因此在 FormCreate 之前,我的“F8”将我引导到 cxContainer进入我的代码的下一行。
(这只是一个例子,当然任何第 3 方库都可能发生这种情况)
我如何告诉调试器“仅调试我的单元”(仅 dpr 文件中列出的 pas 文件?)
当然有时调试库很有用,但在大多数情况下并非如此。
Sometimes as I am debugging step-by-step, just before a FormCreate Event or just after the FromDestroy the debugger starts to open DevExpress units (cxContainer.pas, ...) and so before FormCreate my "F8" leads me to cxContainer instead of going into the next line of my code.
(this is just an example, it can happen of course with any 3rd party library)
How do I tell the debugger "debug only my units" (only the pas files listed in dpr file?)
Of course sometimes it is useful to debug libraries, but in most cases it isn't.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您最好遵循第三方组件的VCL约定:
这样,当您编译项目时,Delphi 将只能看到该第三方组件的发布 DCU,因此调试器无法单步执行源代码。
另一方面,由于源路径包含在“浏览路径”中,您仍然可以通过 Ctrl+单击单元名称或这些单元中定义的任何内容导航到 IDE 内的源代码。
如果要调试组件,可以进入“项目|选项|Delphi编译器|编译”,并启用“使用调试.dcus”。这将强制编译器使用“调试 DCU 路径”而不是“库路径”。
VCL 的工作原理相同,通常在调试项目时不会进入 VCL 源代码,但如果启用“Use debug .dcus”,您也可以调试 VCL 源代码。
JVCL 也以相同的方式组织其包和源代码。
编辑:
如果您采用这种方法,并且希望代码浏览(Ctrl+单击)正常工作;请注意,编译release版本的包时,必须将“Project | Options | Delphi Compiler | Compiling”中的Symbol Reference Info设置为“Reference Info”;否则,Ctrl+单击对这些单位不起作用。默认情况下,发布构建配置将“符号引用信息”设置为“无”。
You'd better follow VCL convention for your third-party components:
This way, Delphi will only see release DCUs of that third-party component when you are compiling your project, so the debugger cannot step into the source code.
On the other hand, since source path is included in "Browsing path", you can still navigate to the source code inside IDE by Ctrl+Click on unit name, or anything defined in those units.
If you want to debug component, you can go to "Project | Options | Delphi Compiler | Compiling", and enable "Use debug .dcus". This will force compiler to use "Debug DCU path" instead of "Library path".
VCL works the same, generally you don't step into VCL source code when you are debugging your project, but if you enable "Use debug .dcus" you can debug VCL source code too.
JVCL also organizes its packages and source code the same way.
EDIT:
If you take this approach, and want to have code browsing (Ctrl+Click) working; please take note that when you compile release version of packages, you must set Symbol Reference Info in "Project | Options | Delphi Compiler | Compiling" to "Reference Info"; otherwise, Ctrl+Click won't work for those units. By default, Release build configuration sets Symbol Reference Info to None.
一个快速而简单的解决方案是禁用您正在使用的任何库的 DEBUG 开关 ({$D-})。许多库(包括 DevExpress)使用全局包含文件,通常位于每个源文件的顶部,或者位于“unit”语句的正上方或下方(例如,unit cxContainer; {$I cxVer.inc} interface )。打开该包含文件(单击它并按 CTRL-Enter)并在顶部添加 {$D-},并注释掉任何现有的 {$D+}。
A quick and simple solution is disabling the DEBUG switch ({$D-}) for any libraries you're using. Many libraries (including DevExpress) use a global include file, usually at the top of each source file, or right above or below the "unit" statement (e.g. unit cxContainer; {$I cxVer.inc} interface ). Open that include file (click on it and press CTRL-Enter) and add {$D-} right at the top, and comment out any existing {$D+}.
只有一种方法可以告诉编译器不要调试单元:在没有调试信息的情况下编译它。
如果您有库的源代码,则可以在关闭库中每个包的“包含调试信息”编译器选项后重建其包。如果幸运的话,您的库将包含一个 .inc 文件,该文件指定它们所需的编译器选项以及它们包含在每个单元中的编译器选项。在这种情况下,您所要做的就是编辑此 inc 文件并重建所有包。
如果您没有库的源代码,库制造商可能提供了两组 dcu:一组编译有调试信息,另一组没有调试信息。在这种情况下,只需将您的库路径指向您需要的路径即可。
There is only one way to tell the compiler not to debug a unit: compile it without debug information.
If you have the source to your libraries, you can rebuild their package after having turned off the "include debug info" compiler option for each package in the library. If you are lucky, your libraries will include an .inc file which specifies the compiler options they need and which they include in each unit. In that case all you have to do is edit this inc file and rebuild all packages.
If you don't have the source to your libraries, the library makers may have provided two sets of dcu's: one compiled with, the other without debug information. In that case, simply point your library path to the one you need.
关闭您不希望调试器进入的单元中的调试信息。
Turn off debug info in units you don't want the debugger going into.