简体   繁体   English

Delphi:如何从调试器中排除单元?

[英]Delphi: how to exclude units from debugger?

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. 有时我正在逐步调试,就在FormCreate事件之前或者在FromDestroy之后调试器开始打开DevExpress单元(cxContainer.pas,...)之前,所以在FormCreate之前我的“F8”会引导我转向cxContainer而不是进入我的代码的下一行。

(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?) 如何告诉调试器“仅调试我的单元”(只有dpr文件中列出的pas文件?)

Of course sometimes it is useful to debug libraries, but in most cases it isn't. 当然,有时调试库很有用,但在大多数情况下并非如此。

You'd better follow VCL convention for your third-party components: 您最好遵循第三方组件的VCL约定:

  • Change DCU output path in all the third-party packages to a folder different than the folder you store the PAS files. 将所有第三方软件包中的DCU输出路径更改为与存储PAS文件的文件夹不同的文件夹。
  • Compile each package once in Debug mode, and save the generated DCU files in a folder (eg Debug DCUs). 在调试模式下编译每个包一次,并将生成的DCU文件保存在一个文件夹中(例如Debug DCU)。
  • Compile each package once again, but this time in Release mode, and save the generated DCU files in a folder (eg Release DCUs). 再次编译每个包,但这次是在Release模式下,将生成的DCU文件保存在一个文件夹中(例如Release DCU)。
  • Go to Delphi options and add path of release DCUs to "Library path". 转到Delphi选项并将释放DCU的路径添加到“库路径”。
  • In Delphi options, add path of source files to "Browsing path". 在Delphi选项中,将源文件的路径添加到“浏览路径”。
  • In Delphi options, add path of debug DCUs to "Debug DCU path". 在Delphi选项中,将调试DCU的路径添加到“Debug DCU path”。

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. 这样,Delphi只会在编译项目时看到该第三方组件的发布DCU,因此调试器无法进入源代码。 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. 另一方面,由于源路径包含在“浏览路径”中,您仍然可以通过Ctrl +单击单元名称或在这些单元中定义的任何内容导航到IDE内的源代码。

If you want to debug component, you can go to "Project | Options | Delphi Compiler | Compiling", and enable "Use debug .dcus". 如果要调试组件,可以转到“Project | Options | Delphi Compiler | Compiling”,并启用“Use debug .dcus”。 This will force compiler to use "Debug DCU path" instead of "Library path". 这将迫使编译器使用“Debug DCU path”而不是“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. VCL的工作原理相同,通常在调试项目时不会进入VCL源代码,但如果启用“使用调试.dcus”,则也可以调试VCL源代码。

JVCL also organizes its packages and source code the same way. JVCL也以相同的方式组织其包和源代码。

EDIT : If you take this approach, and want to have code browsing (Ctrl+Click) working; 编辑 :如果你采取这种方法,并希望有代码浏览(Ctrl +单击)工作; 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"; 请注意,在编译软件包的发行版时,必须在“Project | Options | Delphi Compiler | Compiling”中将Symbol Reference Info设置为“Reference Info”; otherwise, Ctrl+Click won't work for those units. 否则,Ctrl +单击将不适用于这些单位。 By default, Release build configuration sets Symbol Reference Info to None. 默认情况下,发布构建配置将符号引用信息设置为无。

A quick and simple solution is disabling the DEBUG switch ({$D-}) for any libraries you're using. 一个快速而简单的解决方案是禁用您正在使用的任何库的DEBUG开关({$ D-})。 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 (eg unit cxContainer; {$I cxVer.inc} interface ). 许多库(包括DevExpress)使用全局包含文件,通常位于每个源文件的顶部,或者在“unit”语句的正上方或下方(例如unit cxContainer; {$ I cxVer.inc}接口)。 Open that include file (click on it and press CTRL-Enter) and add {$D-} right at the top, and comment out any existing {$D+}. 打开包含文件(单击它并按CTRL-Enter)并在顶部添加{$ D-},并注释掉任何现有的{$ D +}。

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. 如果您拥有库的源代码,则可以在关闭库中每个包的“include debug info”编译器选项后重建其包。 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. 如果幸运的话,您的库将包含一个.inc文件,该文件指定了所需的编译器选项以及它们在每个单元中包含的选项。 In that case all you have to do is edit this inc file and rebuild all packages. 在这种情况下,您所要做的就是编辑此inc文件并重建所有包。

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. 如果您没有库的源代码,库库制造商可能提供了两组dcu:一组编译,另一组没有调试信息。 In that case, simply point your library path to the one you need. 在这种情况下,只需将您的库路径指向您需要的路径。

以您不希望调试器进入的单位关闭调试信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM