Delphi – Compiler Options for Using Debug DCUs?

In the component I am writing, I want to include automatic detection of registered image formats, but it is a solution that works only when the compiler option of Use Debug DCU is disabled.

What I really want to know is an alternative to this solution, which does not involve compiler option dependencies.

But for now, I just want to know how to Check whether the compiler option of Use Debug DCU is set at runtime.

There is no reliable way to run

The Use Debug DCUs compiler option only switches the search path; the compiler will eventually find out what is unknown. (Misleading) The user may have copied the Release dcu to the debug directory, The reverse is also true.

Even if the user is not misunderstood, some files may be added to the project (and compiled with the project) to include some bug fixes. For example, if the user has added Graphics.pas to In the project, execute release / no-debug build, but keep the compiler option of Use Debug DCU, then the Graphics.dcu actually linked is not the debug version, because it is rebuilt with the executable file. So you get a “hybrid” Debugging and non-debugging dcus packages.

You can try to detect whether there is debugging information related to certain objects or methods, but this is also unreliable: if you use “Build with Debug Dcus” but then “Debug Information” is set to false, then you are actually throwing away the debugging information so that you no longer look for it.

But this link code fails on the Debug DCU

The code from the GLScene project is not a good hack, it uses a hard-coded offset into the code of TPiture.RegisterFileFormat, and then continues to use the hard-coded offset to get the address of the global FileFormats variable (without calling the GetFileFormats routine). Too many magic numbers!

My first question is to compare the TList identified by the GLScene method with the TList I determined, but guess: there is no problem on my machine, the two routines are in two cases Both got the same result. On my machine, GLScene was ugly, but it was not broken by Debug DCU.

I even tried “fingerprinting” some rtl/vcl units (SysUtils, Graphics, Classes); I listed all public classes, generated some code using RTTI for each method in each class, and dumped the first 1024 bytes of the code into a string file. Use Debug DCU and non Debug DCU to run the program, I got the same result. My text file contains fingerprints of 3500 methods!

Not a good idea

Since this option does not really affect the way the compiler compiles (linker linking only), creating code that depends on this option is very unreliable and Not a good idea. This will only affect low-level attacks, and you don’t want low-level attacks that can cause the application to crash under completely uncontrollable conditions.

The only real option is to change a Replace the hack with a hack that will not fail (or at least fail in a controlled way).

In the component I am writing, I want to include automatic detection of registered image formats, but it is a solution that only works when the compiler option of Use Debug DCU is disabled.

What I really want to know is an alternative to this solution, it does not involve Compiler options depend.

But for now, I just want to know how to check whether the compiler option of Use Debug DCU is set at runtime.

< /p>

There is no reliable way to obtain this information at runtime

The Use Debug DCUs compiler option only switches the search path; the compiler will eventually find out what is unknown. (Misleading) The user may have copied the Release dcu to the debug directory, and vice versa.

Even if the user is not misunderstood, some files may be added to the project (and compiled with the project) to include some bug fixes For example, if the user has added Graphics.pas to the project, executed release/no-debug build, but kept the compiler option of Use Debug DCU, then the actually linked Graphics.dcu is not the debug version, because it is an executable The file is rebuilt. So you get a “mixed” debug and non-debug dcus package.

You can try to detect whether there is debugging information related to certain objects or methods, but this is also unreliable: If you use “Build with Debug Dcus” but then set “Debug Information” to false, then you are actually throwing away the debugging information so that you no longer look for it.

But this link code is in Debug DCU failed

The code from the GLScene project is not a good hack. It uses a hard-coded offset into the code of TPiture.RegisterFileFormat, and then continues to use the hard-coded offset to get the global FileFormats The address of the variable (do not call the GetFileFormats routine). There are too many magic numbers there!

My first question is to compare the TList identified by the GLScene method with the TList I determined, but guess: there is no problem on my machine, the two routines are in two cases Both got the same result. On my machine, GLScene was ugly, but it was not broken by Debug DCU.

I even tried “fingerprinting” some rtl/vcl units (SysUtils, Graphics, Classes); I listed all public classes, generated some code using RTTI for each method in each class, and dumped the first 1024 bytes of the code into a string file. Use Debug DCU and non Debug DCU to run the program, I got the same result. My text file contains fingerprints of 3500 methods!

Not a good idea

Since this option does not really affect the way the compiler compiles (linker linking only), creating code that depends on this option is very unreliable and Not a good idea. This only affects low-level attacks, and you don’t want low-level attacks that can cause the application to crash under completely uncontrollable circumstances.

The only real option is to change a Replace the hack with a hack that will not fail (or at least fail in a controlled way).

Leave a Comment

Your email address will not be published.