Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

(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.

like image 300
LaBracca Avatar asked Nov 05 '10 16:11

LaBracca


3 Answers

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.

like image 102
vcldeveloper Avatar answered Nov 20 '22 16:11

vcldeveloper


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

like image 44
Ziggy Tolnay Avatar answered Nov 20 '22 16:11

Ziggy Tolnay


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.

like image 2
Marjan Venema Avatar answered Nov 20 '22 18:11

Marjan Venema