Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement: Enable -g on all builds #873

Closed
matthijskooijman opened this issue Jan 17, 2020 · 12 comments · Fixed by #1446
Closed

Improvement: Enable -g on all builds #873

matthijskooijman opened this issue Jan 17, 2020 · 12 comments · Fixed by #1446

Comments

@matthijskooijman
Copy link
Contributor

Currently, the -g compiler option for adding debug symbols is only passed when the optimization level is "Debug". However, I think that passing -g is always a good idea, even with higher optimization levels.

Of course, when you expect to be debugging, you can simply enable the debug optimization level for a build. However, sometimes you need to debug a production build, in particular when you cannot reproduce the problem using a debug build, or when you want to analyze a stack dump collected from some production system.

It is true that aggressive optimizations might interfere with debugging, but in practice debugging still works reasonably well (and certainly better than having no debugging symbols at all).

Also, AFAIK adding debug symbols does not affect the produced machine code, so the only downside of adding debug symbols might be that compilation is a little slower.

Implementing this would, I think, be a matter of removing the -g option from the Debug optimization levels in boards.txt (and replacing -g with -Og in its description, which is a good idea regardless). Then, the -g option can be added unconditionally in platformt.txt.

@fpistm
Copy link
Member

fpistm commented Jan 17, 2020

Hi @matthijskooijman
I've already had several discussion about this and adding -g by default was not desired.
A better approach could be to remove the -g from the 'Debug' optimization and add a menu to enable it or not.
The main drawback is the menu addition (huge boards.txt and new menu)

@matthijskooijman
Copy link
Contributor Author

I've already had several discussion about this and adding -g by default was not desired.

Is there any record of this discussion you could link to? I'm curious what the arguments against are.

A better approach could be to remove the -g from the 'Debug' optimization and add a menu to enable it or not.
The main drawback is the menu addition (huge boards.txt and new menu)

Yeah, that could be an alternative. I guess Arduino should really support platform-level menus rather than just board-level menus, but that is probably difficult to implement wrt backward compatibility...

@fpistm
Copy link
Member

fpistm commented Jan 17, 2020

Well don't remember where it was discussed (GitHub, forums,...)
I'm not against add '-g', I've only related what I remembered.

@lyusupov
Copy link
Contributor

lyusupov commented Jan 17, 2020

AFAIR, -g increases binary size even if -Os is activated. Can be very critical for MCUs with small flash memory size.
It also increases build host's RAM consumption and overall build time.
IMHO, setting of -g by default, in general, does not seem to be a good idea.

@matthijskooijman
Copy link
Contributor Author

AFAIR, -g increases binary size even if -Os is activated. Can be very critical for MCUs with small flash memory size.

It will certainly increase the .elf file size, but I would expect it does not affect the actual code size (though I could not find anything definitive about this).

It also increases build host's RAM consumption and overall build time.

Yeah, that is a downside, but I would think it is a minimal cost.

@VitorBoss
Copy link

VitorBoss commented Feb 18, 2020

I have done some tests with Speeduino code on a Black 407VE, here ar the results:

Flag -g -Os -O1 -O2 -O3
BIN size 143.716 114.972 140.436 130.768 142.436
ELF size 404.322 276.396 341.632 272.688 335.516
RAM use 10560 10560 10560 10560 10560
free RAM 50691 50711 50675 50703 50711
loops/S 7196 6995 7446 7702 7716

@matthijskooijman
Copy link
Contributor Author

@VitorBoss, when you say -g, that means the current -g -Og flags I think? Are there any conclusions that you want to connect to your results? I guess it might be interesting to see the results of various -O options with and without -g added, which might provide some info on whether or not to enable -g by default?

@matthijskooijman
Copy link
Contributor Author

Also, thanks for taking the time to provide some test data! :-)

@VitorBoss
Copy link

VitorBoss commented Feb 18, 2020

I'm using only the menu options

Just digg on boards.txt and -g actually is -g -Og

@VitorBoss
Copy link

VitorBoss commented Feb 18, 2020

Using -g -Os give almost same results from -Os except for ELF size, it increased to 1.648.196 bytes

Edit: Actually adding -g just increase the ELF file, the performance is the same on all options. Can't tell about compile time as my PC is a very old i5-520M

@fpistm
Copy link
Member

fpistm commented Oct 16, 2020

I think I will add a new menu to enable or not the debug.
Like this it can be enable for all Ox level and by default it will be disabled for backward compatibility.

any feedback ar welcome on this proposal 😉

@fpistm
Copy link
Member

fpistm commented Jul 13, 2021

As no feedback, I will add the new menu.

@fpistm fpistm added this to the 2.x.x milestone Jul 13, 2021
fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Jul 13, 2021
Fixes stm32duino#873

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
@fpistm fpistm self-assigned this Jul 13, 2021
fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Jul 14, 2021
Fixes stm32duino#873

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
STM32 core based on ST HAL automation moved this from To do to Done Jul 14, 2021
fpistm added a commit that referenced this issue Jul 14, 2021
Fixes #873

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging a pull request may close this issue.

4 participants