1

Our project just started to use the -Og flag when compiling the software in debug mode vs. the -g3 flag.

man GCC says:

"-Og Optimize debugging experience. -Og enables optimizations that do not interfere with debugging. It should be the optimization level of choice for the standard edit-compile-debug cycle, offering a reasonable level of optimization while maintaining fast compilation and a good debugging experience."

The problem is any variable that is set by a inline call is "optimized out" so you can't do "break if" commands using the variable or print the variable until either is is reset by something (that is not an inline function) or until the variable is passed up or down into a new function (you can then see the value, etc.) I have read the GCC man page, but I don't see anything about this problem or how to fix it beyond going back to the -g3 flag for debugging and don't use the -Og flag. So is there someway to use -Og and still be able to see the variable after it is set by inline?

The compiler is gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) for RH 7.3 OS and we are using ddd as the GUI.

This is an example of non - inline where the pid is optimized out:

C unit getting pid to check.

    pid = et->printPid(); <= optimized out, can't set break if using pid
    if( pid > 0 ) <= optimized out, can do a break if
    {
        pid = waitpid( pid, &status, WNOHANG ); <= now you can "see" the pid setting and add break if
        if( pid == -1 )

FuEvEventTable.h

   pid_t printPid() { return( myPrintPid ); }

If printPid was a inline (which is want normally we do to return or set variables in a class) the same thing happens, so { return( myPrintPid ); } style might be the problem.

Jamin Grey
  • 10,151
  • 6
  • 39
  • 52
user3416126
  • 148
  • 11
  • Could you show sample of code there is variable become inlined? – knst May 16 '17 at 20:42
  • Added example of code where pid is an optimize variable until it is reset. – user3416126 May 18 '17 at 12:43
  • We have been testing different flag options and adding -fno-inline to -ggdb3 -Og which seems to have fixed the “optimize variable” problem. This is the man description, so since this is a “normal” default if we were not using the -O flag I think its ok, but we don’t know what -Og is really optimizing. -fno-inline Do not expand any functions inline apart from those marked with the "always_inline" attribute. This is the default when not optimizing. Single functions can be exempted from inlining by marking them with the "noinline" attribute – user3416126 May 19 '17 at 15:34
  • Because of the side effects of using -Og we decided NOT to compile using it and will only use the -ggdb3. Hopefully a future release of the gnc compiler will fix this side effect. – user3416126 Jun 08 '17 at 14:37

0 Answers0