![]() ![]() ![]() |
![]() |
![]() |
![]() Driver Technical Tips Compiler Switches That Aid in Debugging This week we look at two switches for the Microsoft C/C++ compiler that can save a lot of time. The first is -P, which creates a preprocessor output file, and the second is -Fc, which produces a mixed source and assembly listing. -P Programmers occasionally get error messages from the Microsoft Compiler that are extremely difficult to decipher. Tracking down the problem is complicated by having nested include files, and not knowing from exactly which directory an include file is being taken. Furthermore, macros (#define’s) and typedefs can make it very difficult to see what’s going on. The problem is that error messages refer to code that has been preprocessed, i.e., include files have been inserted and all macros have been expanded. In a complex set of modules, the code that the compiler sees can look very different from what the programmer sees. This is where the -P switch comes in handy. It causes the compiler to output a file (with the extension .i), that contains the output of the preprocessor. Since it contains all the fully expanded include files, it’s often a huge text file. But a search for an offending variable name in this file is often far more illuminating than poring over your raw source modules. One thing to watch out for: When you specify -P, the compiler always succeeds, i.e., completes without an error, and this causes NMAKE to continue processing. However, since the compiler does not produce an object file, the link fails. So turn on –P to generate your .i file, and then remove it when the errors have been corrected. -Fc Sometimes you really need to see the instructions that are being generated from your source code. One way to do this is by loading the code into a debugger, but that’s not always practical. Another way is to use the Microsoft utility DUMPBIN with the /disasm switch, but that doesn’t show you your source code. A good solution is the -Fc switch, which will produce a listing (with extension .cod) that contains both the source code and the generated instructions. This is useful for examining optimizations, or for understanding the semantics of a complex expression. Studying the .cod file can teach you a lot about how the compiler implements the C++ (or C) language.
Adding the Switches to Your Build for DriverWorks
C_DEFINES=-DNTVERSION=$(NTVERSION)Then change it to C_DEFINES=-DNTVERSION=$(NTVERSION) -P
Adding the Switches to Your Build for VtoolsD
C:> set XFLAGS= -FcAlternately, you can edit your project make file (xxx.MAK) and add the switch: XFLAGS=-Fc Back to technical tip start page. |
DriverCentral ·
DriverStudio ·
Free downloads ·
Resources ·
Support and Services ·
Shop NuMega
|