Re: Should --enable-debug set CFLAGS to -O0 instead of -O2?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Should --enable-debug set CFLAGS to -O0 instead of -O2?
Date: 2025-08-01 03:30:03
Message-ID: 2188726.1754019003@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> writes:
> I noticed that "./configure --enable-debug" will set "-O2" to CFLAGS. To
> better debug/trace the code, I have to manually change "-O2" to "-O0" in
> src/Makefile.global.

This has been intentional for decades. It is not a bug. You're
certainly welcome to use different CFLAGS locally if that suits
your habits better.

In my mind, at least, the rationale is that we don't want to
give up more performance than we have to in debug builds, nor
let the behavior deviate from what it would be in production.

It is true than in some cases it's too hard to trace the behavior of
optimized code. What I usually do if I get frustrated while debugging
is to recompile specific file(s) at -O0. The PROFILE variable is
handy for injecting that switch.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message shveta malik 2025-08-01 03:44:05 Re: Conflict detection for update_deleted in logical replication
Previous Message Chao Li 2025-08-01 03:16:58 Should --enable-debug set CFLAGS to -O0 instead of -O2?