Delphi: how to exclude units from debugger?
Asked Answered
V

4

7

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.

Valetudinary answered 5/11, 2010 at 16:4 Comment(1)
See also How to skip sections of code while debugging?Nebiim
E
28

You'd better follow VCL convention for your third-party components:

  • Change DCU output path in all the third-party packages to a folder different than the folder you store the PAS files.
  • Compile each package once in Debug mode, and save the generated DCU files in a folder (e.g. Debug DCUs).
  • Compile each package once again, but this time in Release mode, and save the generated DCU files in a folder (e.g. Release DCUs).
  • Go to Delphi options and add path of release DCUs to "Library path".
  • In Delphi options, add path of source files to "Browsing path".
  • In Delphi options, add path of debug DCUs to "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. 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.

Estancia answered 5/11, 2010 at 16:31 Comment(2)
+1 Very comprehensive answer. And I learnt a knew trick. Had seen the debug dcu path, but it hadn't "clicked" wrt how to put it to good use. Thanks for that. Just one drawback that I see to it: "use debug dcu's" now means you'll be using debug dcu's for all your libraries when you often have only one you want to debug. In that case it is often handier to simply change the library path to point to the debug dcu folder for that library alone...Ghiberti
<slap forehead> You might expect a Developer using Delphi for the last 10 years to know this, but I for one didn't. </slap forehead>Kannada
S
3

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+}.

Sanguinary answered 18/9, 2014 at 7:0 Comment(0)
G
2

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.

Ghiberti answered 5/11, 2010 at 16:21 Comment(0)
C
1

Turn off debug info in units you don't want the debugger going into.

Colombo answered 5/11, 2010 at 16:18 Comment(1)
Added to save others from looking this up like I just did: This can be done with {$D-} compiler directive in the units that you don't want to debug.Selfrestraint

© 2022 - 2024 — McMap. All rights reserved.