https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78685
--- Comment #30 from Lukas Grätz <lukas.gra...@tu-darmstadt.de> --- (In reply to rguent...@suse.de from comment #29) > On Mon, 28 Apr 2025, Hi-Angel at yandex dot ru wrote: > > Hi, I understand it's a low-priority issue, but could we at least change the > > documentation to say that `-Og` is "supposed to be useful for debugging, but > > currently isn't"? I mean, it's a decades old problem, and likely won't be > > fixed > > in the near future; however the recommendation being present in GCC docs is > > harmful, because over and over in different projects someone brings up "why > > aren't you using Og instead of O0", wasting I think thousands of man-hours > > globally. > > > > Having docs clarified here would be immensely useful, WDYT? > > There is still the issue that -O0 does not do variable-tracking which > means you get no debug info for the prologue/epilogue - -Og fixes that, > at the expense of degraded debugging experience. > > -Og is supposed to be a blend of optimization which result should be > still debuggable (better than -O2). > > I agree the documentation is misleading, while it may want to spell > out the -fvar-tracking issue it fixes, it suggests the debugging > experience is better than -O0 which it is not. > > I'll note that -Og was also mainly motivated by C++ standard library > debugging where you end up with quite deep inlining from abstraction > penalty which _is_ a bad experience when debugging (and also for > runtime performance). I am not a GCC developer, but in my opinion, the solutions are not that complicated nor is there a reason that this bug report remained open so many years. There are multiple options to deal with it: 1. Deprecate -Og in favor to -O0 -fvar-tracking. -Og never worked as intended anyway. 2. Change the semantics of -Og to mean -O0 -fvar-tracking. You could introduce something like -Og1 to get the old -Og back. 3. Introduce a new option that is really optimized for the best debugging experience. Again this would mean -O0 -fvar-tracking, but this would make it easier if new options like -fvar-tracking were introduced in future gcc versions. For C++ the situation might be different, but for C, the run-time performance is mostly irrelevant when debugging.