Thread: gcc -E -dM/-dD

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    gcc -E -dM/-dD

    Hello everyone,


    I am learning some other's code -- build files. Here are two samples which I am confused.

    gcc -E -o ListDef -dM -P YourSrcCode.c

    gcc -E -o ListDef -dD -P YourSrcCode.c

    I have tried that in ListDef file (new generated after either of the two commands) and it contains several hundred lines of #define, typedef and some other definitions. Could anyone help to answer what is the function of the two commands? Differences between -dM and -dD?


    thanks in advance,
    George

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    They're basically "debug" modes of the compiler to help you track down certain problems.
    In this instance, it would seem to dump all the #defines.
    Read the manual.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I don't think most people will be able to use -dM, but -dD is useful to show what macros was used during the pre-compilation process.

    The -E option tells the compiler to just generate the precompiled output, rather than the usual "full compile". So your list file will be exactly how the compiler will see the code (on large file with all the stuff from various include files etc, all comments removed, macros replaced with their text replacement, all #if/#else etc removed (and any code that was determined not to be "needed" due to said #if/#else).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks Salem,


    Quote Originally Posted by Salem View Post
    They're basically "debug" modes of the compiler to help you track down certain problems.
    In this instance, it would seem to dump all the #defines.
    Read the manual.
    I noticed a lot of information are dumped. It means my program will use all of the dumped information?

    I can not believe my application will use so many #define and typedef. :-)


    regards,
    George

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks Mats,


    Quote Originally Posted by matsp View Post
    I don't think most people will be able to use -dM, but -dD is useful to show what macros was used during the pre-compilation process.

    The -E option tells the compiler to just generate the precompiled output, rather than the usual "full compile". So your list file will be exactly how the compiler will see the code (on large file with all the stuff from various include files etc, all comments removed, macros replaced with their text replacement, all #if/#else etc removed (and any code that was determined not to be "needed" due to said #if/#else).

    --
    Mats
    In what situation do we need to use -dM and in what situation do we need -dD?


    regards,
    George

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by man gcc
    Code:
     -dM
               -fdump-rtl-mach
                   Dump after performing the machine dependent reorganization
                   pass, to file.35.mach.
    The machine dependant re-organization is done as part of the optimisation during the compile phase. Since your original command line had "-E" as part of the command line, it will not get to this step, so there won't be any output different from "no -dM" option.

    I'm not sure what format it is, but I believe the rtl is the internal "assembler" format of gcc, and it's certainly not very useful unless you are debugging gcc's code generation for a particular processor [and unless you actually are capable of FIXING it - in other cases, it's usually sufficient to provide a small C example of something broken (after gcc -E perhaps), and a full list of which gcc argumentns give the problem. E.g. gcc -O2 err.c makes the variable x be overwritten by y because the load instruction is moved above the store instruction. And send that to [email protected] or whatever the e-mail address is]


    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks Mats,


    This is what I found from gcc manual,

    --------------------
    -dCHARS CHARS is a sequence of one or more of the following characters, and must
    not be preceded by a space. Other characters are interpreted by the compiler
    proper, or reserved for future versions of GCC, and so are silently ignored. If
    you specify characters whose behavior conflicts, the result is undefined.
    ‘M’ Instead of the normal output, generate a list of ‘#define’ directives
    for all the macros defined during the execution of the preprocessor,
    including predefined macros. This gives you a way of finding out
    what is predefined in your version of the preprocessor. Assuming
    you have no file ‘foo.h’, the command
    touch foo.h; cpp -dM foo.h
    will show all the predefined macros.
    --------------------

    seems different from your points? :-)

    I have tried that gcc -E -dM and gcc -E (without -dM) will have different output.

    I am using gcc version 3.4.5.

    Any comments?


    regards,
    George

    Quote Originally Posted by matsp View Post
    The machine dependant re-organization is done as part of the optimisation during the compile phase. Since your original command line had "-E" as part of the command line, it will not get to this step, so there won't be any output different from "no -dM" option.

    I'm not sure what format it is, but I believe the rtl is the internal "assembler" format of gcc, and it's certainly not very useful unless you are debugging gcc's code generation for a particular processor [and unless you actually are capable of FIXING it - in other cases, it's usually sufficient to provide a small C example of something broken (after gcc -E perhaps), and a full list of which gcc argumentns give the problem. E.g. gcc -O2 err.c makes the variable x be overwritten by y because the load instruction is moved above the store instruction. And send that to [email protected] or whatever the e-mail address is]


    --
    Mats

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, it appears that those have changed. In the current gcc (4.x) it means different things than in 3.x obviously.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks Mats,


    Quote Originally Posted by matsp View Post
    So, it appears that those have changed. In the current gcc (4.x) it means different things than in 3.x obviously.

    --
    Mats
    In my context, in what situation should we use -dM and in what situation should we use -dD?


    regards,
    George

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    -dM will list any macros that are defined by the compiler itself (e.g. __GNUC__, __ANSI__, __DATE__ etc)
    -dD will list all macros that are defined during the compile, which includes those supplied by the compiler and those defined by header files, C files and on the command-line.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Gcc can't find obvious copy constructor
    By SevenThunders in forum C++ Programming
    Replies: 13
    Last Post: 03-19-2009, 02:41 PM
  2. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  3. Replies: 4
    Last Post: 09-02-2007, 08:47 PM
  4. Back To The Basics: Freeing An Array on the Heap?
    By Deo in forum C++ Programming
    Replies: 12
    Last Post: 04-07-2007, 04:42 AM
  5. Compiles on gcc 3.3 but not on gcc 4.0.3
    By cunnus88 in forum C++ Programming
    Replies: 5
    Last Post: 03-29-2007, 12:24 PM