Does optimization for GDB work at all in GCC 9.2.1?

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess

szekelyisz
Posts: 10
Joined: Wed Jan 03, 2018 8:15 pm

Does optimization for GDB work at all in GCC 9.2.1?

Postby szekelyisz » Tue Apr 06, 2021 2:59 pm

Hi,

I'm using ChibiStudio with included GCC 9.2.1. I noticed that when I compile my code with -O0 I get a binary size of around 70 kB. But when I wanted to add more debugging information with -Og -ggdb, the compiled binary size dropped to 47kB and the debugging experience is like with -O2 or -O3 (stepping through the code line by line jumps around like it was optimized on some level). Optimizing for GDB should leave even more information in the binary so I'd expect the size of it to be bigger, and linear code execution just like -O0.

Has anybody come across this?

Here are all my compiler flags:

Code: Select all

-specs=nano.specs -mcpu=cortex-m4 -Og -ggdb3 -fomit-frame-pointer -falign-functions=16 -Wall -ffunction-sections -fdata-sections -fno-common -nostartfiles -Wl,-Map=build/Debug/ch.map,--cref,--no-warn-mismatch,--library-path=/home/szabi/chibios/os/common/startup/ARMCMx/compilers/GCC/ld,--script=board/STM32F427xG.ld,--gc-sections,-print-memory-usage,--defsym=__process_stack_size__=0x1000,--defsym=__main_stack_size__=0x400 -mno-thumb-interwork


Thanks,
Szabi

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Does optimization for GDB work at all in GCC 9.2.1?

Postby Giovanni » Tue Apr 06, 2021 3:09 pm

Hi,

As far I know debugging information do not contribute to the binary image size, it is metadata used by the debugger.

Giovanni

szekelyisz
Posts: 10
Joined: Wed Jan 03, 2018 8:15 pm

Re: Does optimization for GDB work at all in GCC 9.2.1?

Postby szekelyisz » Tue Apr 06, 2021 3:17 pm

Thanks. That makes sense, but it still doesn't explain why -Og code is smaller than -O0. As far as I understand -Og disables at least all those optimizations as -O0 (and maybe more).

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Does optimization for GDB work at all in GCC 9.2.1?

Postby Giovanni » Tue Apr 06, 2021 3:19 pm

-Og disables all optimizations that impact "debug experience quality" and only those
-O0 disables all optimizations, all of them

Giovanni


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 3 guests