Skip to content

ports/Makefile: Reinstate -O0 option on demand. #14076

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stinos
Copy link
Contributor

@stinos stinos commented Mar 12, 2024

-Og introduced in for example 9ffb1ad and c5dbbf7 results in a binary with debug symbols, but essentially breaks debugging with gdb since it still allows the compiler to optimize temporaries for instance, so gdb will report 'optimized out' for a lot of variables and breakpoints will often halt at the wrong line.
-O0 has none of these problems so allow it by specifying DEBUG=2, leaving the original DEBUG=1 functionality as-is.

See for instance https://stackoverflow.com/questions/63386189/whats-the-difference-between-a-compilers-o0-option-and-og-option for some more information.

I'm not sure if DEBUG=2 is a common way of doing this, but it's definitely pretty simple. Likewise: don't know if all ports I changed this for even work with gdb?

In theory -g3 is also better than -g but at least with -O0 -g stepping through the source and looking at variables and memory all just seems to work fine enough, whereas -Og is just not usable for getting detailed information on a problem quickly.

Copy link

codecov bot commented Mar 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.39%. Comparing base (77f08b7) to head (fa5994b).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #14076   +/-   ##
=======================================
  Coverage   98.39%   98.39%           
=======================================
  Files         161      161           
  Lines       21156    21156           
=======================================
  Hits        20816    20816           
  Misses        340      340           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Mar 12, 2024

Code size report:

   bare-arm:  +560 +0.989% 
minimal x86: +2853 +1.527% [incl +16(data)]
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS

@iabdalkader
Copy link
Contributor

Can we consider adding -ggdb3 to include macro definitions ? Without those you have to calculate register addresses (some base + some other base + offset) manually and then cast just to get a register value.

@stinos
Copy link
Contributor Author

stinos commented Mar 13, 2024

Can we consider adding -ggdb3

You mean in the same way, e.g DEBUG=1 -> -g, DEBUG=2 -> -ggdb3 ?

Without those you have to calculate register addresses (some base + some other base + offset) manually

Does that also work with -g3? I'm not sure we want to hardcode gdb here.

@robert-hh
Copy link
Contributor

robert-hh commented Mar 13, 2024

How about an additional compile flags option, which csn be set at the make command line. Maybe it exists already. Seem you can use CFLAGS for that purpose, since all settings for CFLAGS in makefile are CFLAGS +=.

@iabdalkader
Copy link
Contributor

You mean in the same way, e.g DEBUG=1 -> -g, DEBUG=2 -> -ggdb3 ?

I'm not sure, maybe, but if you use O0 it's likely you also want macros.

Does that also work with -g3? I'm not sure we want to hardcode gdb here.

The manual says:
Level 3 includes extra information, such as all the macro definitions present in the program. Some debuggers support macro expansion when you use -g3.

@stinos
Copy link
Contributor Author

stinos commented Mar 13, 2024

How about an additional compile flags option, which csn be set at the make command line. Maybe it exists already. Seem you can use CFLAGS for that purpose, since all settings for CFLAGS in makefile are CFLAGS +=.

Since the docs say

If you use multiple -g options, with or without level numbers, the last such option is the one that is effective.

then that's probably not going to work since the ones passed on the commandline come first?

@dlech
Copy link
Contributor

dlech commented Mar 13, 2024

Can we just use COPT to override the optimization consistently across ports to allow any optimization rather than trying to make new options to try to cover all cases?

I'm already used to doing make DEBUG=1 COPT=-O0 for the unix port.

@dpgeorge dpgeorge added the ports Relates to multiple ports, or a new/proposed port label Mar 15, 2024
@stinos
Copy link
Contributor Author

stinos commented Mar 15, 2024

Just to be clear: is the idea behing COPT that it stands for `C optimization options'? Then yes implementing that consistently is probably the way to go.

And why is -g in CFLAGS not COPT? Does the build process use the debug information somewhere perhaps, because it seems silly to first add it then remove it again.

@dlech
Copy link
Contributor

dlech commented Mar 15, 2024

is the idea behing COPT that it stands for `C optimization options'?

Yes, that is the idea. Basically, just the -O flag.

And why is -g in CFLAGS not COPT?

Because it isn't the -O flag.

@dpgeorge
Copy link
Member

I think the simplest thing is to make more consistent use of COPT across the ports, allow it to be overridden on the command line, and document it.

And, I'm happy to change -g to -g3 in the relevant Makefile's. But I think -ggdb3 should be specified by the user on the command line if they need that.

-Og introduced in for example 9ffb1ad and c5dbbf7 results in a binary
with debug symbols, but essentially breaks debugging with gdb since
it still allows the compiler to optimize temporaries for instance,
so gdb will report 'optimized out' for a lot of variables and will
often halt on other lines than where breakpoints are defined.
-O0 has none of these problems, but also makes for a large binary, so
allow specifying it via COPT=-O0 by making all Makefiles consistently
use this flag and related CSUPEROPT as well.

Signed-off-by: stijn <stijn@ignitron.net>
@stinos
Copy link
Contributor Author

stinos commented Mar 19, 2024

I think the simplest thing is to make more consistent use of COPT across the ports, allow it to be overridden on the command line

Ok, changed that already.

and document it.

In gettingstarted.rst?

It's now only in unix/README.md but that also seems to be the only one which documents DEBUG=1 whereas most ports have that.

But I think -ggdb3 should be specified by the user on the command line if they need that.

Sounds reasonable but that should be via CFLAGS_EXTRA then I guess, which not all ports have now and the ones which do have it do not use it consistently as 'append to CFLAGS', making it impossible to override -g (e.g. unix Makefile does a CFLAGS += -g after the line where it appends CFLAGS_EXTRA to CFLAGS)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ports Relates to multiple ports, or a new/proposed port
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy