Search code examples
gccgdbcompiler-flags

What does GCC's "-wrapper" flag do?


From the GCC manual, there is the following overall option:

-wrapper
Invoke all subcommands under a wrapper program.
The name of the wrapper program and its parameters
are passed as a comma separated list.

gcc -c t.c -wrapper gdb,--args

This will invoke all subprograms of gcc under gdb --args', thus the invocation of cc1 will begdb --args cc1 ...'.

I'm having trouble understanding the example and the purpose of the flag.

gcc -c t.c will create a t.o.
and then what? the object file is sent to gdb?
or is gdb given the responsibility of creating the object file (asummingly adding debugging information)?


Solution

  • Yes, for debugging the compiler itself. Or otherwise "trace" what is going on in the compiler - you could for example print the arguments passed to cc1 itself by adding a program that does that and then runs cc1.

    gdb is not in charge of generating anything, it is just wrapping around cc1 whihc is the "compiler proper" - when you run gcc -c t.c the compiler first runs cpp -o t.i t.c to preprocess the t.c file. Then it runs cc1 -o t.s t.i and finally as -o t.o t.s (or something along those lines. With the wrapper, it would run those commands as, for example, gdb --args cc1 -o t.s t.i.

    Edit: This is of course much simplified compared to a "real" compile - there's a whole bunch of arguments passed to cc1, etc.