From: Nick Savoiu <savoiu@yahoo.com>
To: "gcc-help@gcc.gnu.org" <gcc-help@gcc.gnu.org>,
David Brown <david.brown@hesbynett.no>
Subject: Re: Does -Og work well?
Date: Thu, 14 Oct 2021 17:10:08 +0000 (UTC) [thread overview]
Message-ID: <531993457.1529564.1634231408649@mail.yahoo.com> (raw)
In-Reply-To: <f529d6ac-fa7e-c5d5-787a-65ebfa809cc2@hesbynett.no>
Yes, I've done many of these in my debugging.
My "beef" was with the GCC documentation pointing to -Og as the 'recommended' setting for debugging code. While it might improve code speed it makes debugging much harder which is not what one would expect given the documentation's rosy picture.
Nick
On Thursday, October 14, 2021, 12:09:17 AM PDT, David Brown <david.brown@hesbynett.no> wrote:
On 11/10/2021 19:47, Nick Savoiu via Gcc-help wrote:
> Hi all, I've been trying for some time to use the recommended -Og for the edit/compile/debug/repeat cycle. The hope was to speed up the code.
>
> The code does get a speed-up, however, more often than not, I'm running into issues that affect debugability: variables are marked as optimized when not expecting them to, breakpoints don't work, etc.
>
> Is anyone having such issues? If so, how do you resolve them? I tried -fvar-tracking-assignments and that helps here and there but it's no panacea.
>
Debugging is an art, not a science - there is no single correct answer.
And there is no such thing as code that is clearly and neatly written
in the source, optimised well in the object code, and easy to debug.
Pick two of these three, and you might manage it.
"-Og" can be a good start. It does a little less re-arranging of the
code than "-O2 -g" does. In my debugging, I sometimes go down from my
usual "-O2" (with additional options) to "-O1", but I never bother
trying "-O0". Without any optimisation, all meaning in C++ code is lost
in endless calls to functions that don't actually /do/ anything at the
object code level (though they have meaning for the source), and you
can't follow the generated assembly because every second instruction is
moving something into or out of the stack. (Details here may vary by
target architecture, of course.)
When you need to debug a section of code at a low level, you often need
to add extra bits to the code as an aid. Adding a few volatile
variables to hold intermediary values is often useful - and volatile
accesses are convenient places to put breakpoints. The odd "no_inline"
attribute on key functions, or pragmas to turn off inlining or lower
optimisation for a particular section of code. A compiler memory
barrier "asm volatile(:::"memory");" ensures that data and variable
accesses are separated on either side, letting your debugger clearly see
the state of variables at the point.
Of course, sometimes adding this kind of thing changes the nature of the
issue and the problem disappears - but then you have gained valuable
insight into what might be causing the problem.
David
prev parent reply other threads:[~2021-10-14 17:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <2132295523.836151.1633974475603.ref@mail.yahoo.com>
2021-10-11 17:47 ` Nick Savoiu
2021-10-11 18:07 ` Xi Ruoyao
2021-10-11 18:39 ` Jonathan Wakely
2021-10-11 19:15 ` Nick Savoiu
2021-10-11 19:21 ` Xi Ruoyao
2021-10-14 7:09 ` David Brown
2021-10-14 17:10 ` Nick Savoiu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=531993457.1529564.1634231408649@mail.yahoo.com \
--to=savoiu@yahoo.com \
--cc=david.brown@hesbynett.no \
--cc=gcc-help@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).