Re: Patch - Debug builds without optimization

Lists: pgsql-hackers
From: Radosław Smogura <rsmogura(at)softperience(dot)eu>
To: PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Patch - Debug builds without optimization
Date: 2011-06-16 12:30:27
Message-ID: bd703a80f570c36a50d609e7c3323f80@mail.softperience.eu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello,

I'm sending following patch which disables optimization when
--enable-debug is passed. It was nasty (for me, at least) that debug
build required passing of CFLAGS with -O0 to get nice traceable code.

Regards,
Radek

Attachment Content-Type Size
configure_no_opt_when_debug.patch text/x-diff 1.6 KB

From: Radosław Smogura <rsmogura(at)softperience(dot)eu>
To: PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Cc: Radosław Smogura <rsmogura(at)softperience(dot)eu>
Subject: Re: Patch - Debug builds without optimization
Date: 2011-06-16 12:51:19
Message-ID: 9fc868afe1d5136ddd15eca2539e9fee@mail.softperience.eu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, 16 Jun 2011 14:30:27 +0200, Radosław Smogura wrote:
> Hello,
>
> I'm sending following patch which disables optimization when
> --enable-debug is passed. It was nasty (for me, at least) that debug
> build required passing of CFLAGS with -O0 to get nice traceable code.
>
> Regards,
> Radek

Sorry for mess, this should be submited.

Attachment Content-Type Size
configure_no_opt_when_debug.patch text/x-diff 1.4 KB

From: Florian Pflug <fgp(at)phlo(dot)org>
To: Radosław Smogura <rsmogura(at)softperience(dot)eu>
Cc: PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Patch - Debug builds without optimization
Date: 2011-06-16 12:51:50
Message-ID: D8E087E5-B932-458E-85A0-A54D176EFB0A@phlo.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Jun16, 2011, at 14:30 , Radosław Smogura wrote:
> I'm sending following patch which disables optimization when --enable-debug is passed. It was nasty (for me, at least) that debug build required passing of CFLAGS with -O0 to get nice traceable code.

Unfortunately, with some compilers (gcc, I'm looking at you) you get considerably fewer warnings with -O0 than with -O1, even if you specify -Wall. The reason seems to be that some of the warnings need information produces by some of the optimization passes.

I usually use -O1 for debug builds, these are usually still at least somewhat debuggable with gdb.

best regards,
Florian Pflug


From: Bernd Helmle <mailings(at)oopsware(dot)de>
To: Radosław Smogura <rsmogura(at)softperience(dot)eu>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Patch - Debug builds without optimization
Date: 2011-06-16 13:37:24
Message-ID: 67C356596C1DDB01F9A098BC@apophis.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

--On 16. Juni 2011 14:30:27 +0200 Radosław Smogura <rsmogura(at)softperience(dot)eu>
wrote:

> Hello,
>
> I'm sending following patch which disables optimization when --enable-debug
> is passed. It was nasty (for me, at least) that debug build required passing
> of CFLAGS with -O0 to get nice traceable code.
>

-O0 hides bugs in your code (e.g. look at
<http://archives.postgresql.org/message-id/9714F5232AB2C4FCFCB392D5@amenophis>
and replies for an example to do it better). Doing this automatically on debug
builds would be a step backwards.

--
Thanks

Bernd


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Florian Pflug <fgp(at)phlo(dot)org>
Cc: Radosław Smogura <rsmogura(at)softperience(dot)eu>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Patch - Debug builds without optimization
Date: 2011-06-16 14:10:49
Message-ID: 29585.1308233449@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Florian Pflug <fgp(at)phlo(dot)org> writes:
> On Jun16, 2011, at 14:30 , Radosaw Smogura wrote:
>> I'm sending following patch which disables optimization when --enable-debug is passed. It was nasty (for me, at least) that debug build required passing of CFLAGS with -O0 to get nice traceable code.

> Unfortunately, with some compilers (gcc, I'm looking at you) you get
> considerably fewer warnings with -O0 than with -O1, even if you specify
> -Wall.

Yes. There is *zero* chance of this being accepted, because it would
break a lot of warnings that developers need to see.

> I usually use -O1 for debug builds, these are usually still at least
> somewhat debuggable with gdb.

I tend to do that too, but I still think that folding it into
--enable-debug would be a mistake. The normal assumption (at least when
using gcc) is that --enable-debug doesn't cost any performance. We
would annoy many people, especially packagers, if that stopped being
true.

I could see providing some other nonstandard configure switch that
changed the default -O level ... but realistically, would that do
anything that you couldn't already do by setting CFLAGS, ie

./configure CFLAGS="-O0 -g"

regards, tom lane


From: Florian Pflug <fgp(at)phlo(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Radosław Smogura <rsmogura(at)softperience(dot)eu>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Patch - Debug builds without optimization
Date: 2011-06-16 14:43:32
Message-ID: E97B5F5C-6CD1-471C-9B6D-B551043AB465@phlo.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Jun16, 2011, at 16:10 , Tom Lane wrote:
> Florian Pflug <fgp(at)phlo(dot)org> writes:
>> I usually use -O1 for debug builds, these are usually still at least
>> somewhat debuggable with gdb.
>
> I tend to do that too, but I still think that folding it into
> --enable-debug would be a mistake.

+1.

I didn't mean to suggest we fold -O1 into --enable-debug, I
was just handling out advice to the OP ;-)

best regards,
Florian Pflug


From: Greg Smith <greg(at)2ndQuadrant(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Patch - Debug builds without optimization
Date: 2011-06-16 15:04:04
Message-ID: 4DFA1B64.2030906@2ndQuadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 06/16/2011 10:10 AM, Tom Lane wrote:
> I could see providing some other nonstandard configure switch that
> changed the default -O level ... but realistically, would that do
> anything that you couldn't already do by setting CFLAGS, ie
>
> ./configure CFLAGS="-O0 -g"
>

I think a small discussion of the issue Radek ran into is appropriate to
put somewhere, with this example. The install procedure section of the
docs already includes a CFLAGS example:

./configure CC=/opt/bin/gcc CFLAGS='-O2 -pipe'

There is also a section talking about setting options like
--enable-cassert in the Developer's FAQ. Looking at all the info out
there about developer/debug builds, it's really kind of sketchy and
distributed though. No one place that pulls all the most common things
people need together into one resource.

What seems like the idea solution here is to add a new section to the
install procedure with brief coverage of this entire area. Here's a
prototype of text that might go there:

= Installation for development and debugging =

When modifying the PostgreSQL source code, or when trying to find the
source of a bug in the program, it may be helpful to build the program
in a way that makes this process easier. There are build-time only
changes that enable better error checking and debugging, including:

Pass --enable-cassert to configure. This can make bugs more visible,
because they cause operations to abort with a clear error. That makes
some types of debugging much easier. This is risky on a production
server, as described in the documentation for this parameter.

Pass --enable-debug to configure. This provides better information about
what the server is doing when looking at it using a debugger. It's less
risky to a production server than enabling assertions, and it normally
has less of a performance impact hgtoo. See its documentation for more
details.

Disable compiler optimization. When using a debugger to trace into the
source code of the server, steps may optimized away by the normal build
process. In some situations --enable-debug will disable such
optimization, but this is not always the case. Specifically disabling
optimization is possible with many compilers by setting the compiler
flags when configuration the source code build, such as:

./configure CFLAGS="-O0 -g"

This example for the gcc compiler disables optimizations, and tells the
compiler to provide extra debugging information most useful with the gdb
debugger.

--
Greg Smith 2ndQuadrant US greg(at)2ndQuadrant(dot)com Baltimore, MD
PostgreSQL Training, Services, and 24x7 Support www.2ndQuadrant.us


From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Radosław Smogura <rsmogura(at)softperience(dot)eu>
Cc: PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Patch - Debug builds without optimization
Date: 2011-06-16 15:54:40
Message-ID: 1308239462-sup-1118@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Excerpts from Radosław Smogura's message of jue jun 16 08:30:27 -0400 2011:
> Hello,
>
> I'm sending following patch which disables optimization when
> --enable-debug is passed. It was nasty (for me, at least) that debug
> build required passing of CFLAGS with -O0 to get nice traceable code.

I disagree with this change. Debug builds are very useful to have in
production, and you don't want to be running -O0 there. I have found
that you can use a src/Makefile.custom like this for those times when you
want to debug stuff in a particular set of files:

CFLAGS := $(patsubst -O2,-O0,$(CFLAGS))

Then you remove the .o files that you want to debug, and rerun make.
This places the burden on the developer wanting to mess with random code
changes. Of course, this means that production builds are not as
debuggable, but IME it's much less of a problem there.

--
Álvaro Herrera <alvherre(at)commandprompt(dot)com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Bernd Helmle <mailings(at)oopsware(dot)de>
Cc: Radosław Smogura <rsmogura(at)softperience(dot)eu>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Patch - Debug builds without optimization
Date: 2011-06-16 17:06:50
Message-ID: 1308243991-sup-8819@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Excerpts from Bernd Helmle's message of jue jun 16 09:37:24 -0400 2011:
>
>
> --On 16. Juni 2011 14:30:27 +0200 Radosław Smogura <rsmogura(at)softperience(dot)eu>
> wrote:
>
> > Hello,
> >
> > I'm sending following patch which disables optimization when --enable-debug
> > is passed. It was nasty (for me, at least) that debug build required passing
> > of CFLAGS with -O0 to get nice traceable code.
>
> -O0 hides bugs in your code (e.g. look at
> <http://archives.postgresql.org/message-id/9714F5232AB2C4FCFCB392D5@amenophis>
> and replies for an example to do it better). Doing this automatically on debug
> builds would be a step backwards.

Hah, seems I don't always do it the same way ;-)

--
Álvaro Herrera <alvherre(at)commandprompt(dot)com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Radosław Smogura <rsmogura(at)softperience(dot)eu>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Patch - Debug builds without optimization
Date: 2011-06-16 20:00:21
Message-ID: 8779.1308254421@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Alvaro Herrera <alvherre(at)commandprompt(dot)com> writes:
> I disagree with this change. Debug builds are very useful to have in
> production, and you don't want to be running -O0 there. I have found
> that you can use a src/Makefile.custom like this for those times when you
> want to debug stuff in a particular set of files:

> CFLAGS := $(patsubst -O2,-O0,$(CFLAGS))

> Then you remove the .o files that you want to debug, and rerun make.

FWIW, I only use Makefile.custom for more-or-less-permanent changes to
the build behavior of a particular machine. For one-shot things like
recompiling some particular file(s) at -O0, it's easier to do this:

rm foo.o
make PROFILE=-O0
reinstall postgres executable

The makefiles automatically add PROFILE at the end of CFLAGS, so you can
inject any compile flag this way --- I think the original intent was to
use it to add -pg for gprof-enabled builds. But it's handy for this.

BTW, if you're hacking Postgres code and don't already have a
"reinstall" script, you need one. Mine is basically

pg_ctl stop
cd $PGBLDROOT/src/backend
make install-bin
pg_ctl start

regards, tom lane


From: Radosław Smogura <rsmogura(at)softperience(dot)eu>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Patch - Debug builds without optimization
Date: 2011-06-16 21:13:08
Message-ID: 62bd6dbd78aa2c47af885faa4b5d6405@mail.softperience.eu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, 16 Jun 2011 16:00:21 -0400, Tom Lane wrote:
> Alvaro Herrera <alvherre(at)commandprompt(dot)com> writes:
>> I disagree with this change. Debug builds are very useful to have
>> in
>> production, and you don't want to be running -O0 there. I have
>> found
>> that you can use a src/Makefile.custom like this for those times
>> when you
>> want to debug stuff in a particular set of files:
>
>> CFLAGS := $(patsubst -O2,-O0,$(CFLAGS))
>
>> Then you remove the .o files that you want to debug, and rerun make.
>
> FWIW, I only use Makefile.custom for more-or-less-permanent changes
> to
> the build behavior of a particular machine. For one-shot things like
> recompiling some particular file(s) at -O0, it's easier to do this:
>
> rm foo.o
> make PROFILE=-O0
> reinstall postgres executable
>
> The makefiles automatically add PROFILE at the end of CFLAGS, so you
> can
> inject any compile flag this way --- I think the original intent was
> to
> use it to add -pg for gprof-enabled builds. But it's handy for this.
>
> BTW, if you're hacking Postgres code and don't already have a
> "reinstall" script, you need one. Mine is basically
>
> pg_ctl stop
> cd $PGBLDROOT/src/backend
> make install-bin
> pg_ctl start
>
> regards, tom lane
Thanks,

Actually I do something like above, but good to know "install-bin"
target, I fired before "gmake -j5 install".

Regards,
Radek


From: Greg Stark <stark(at)mit(dot)edu>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, Radosław Smogura <rsmogura(at)softperience(dot)eu>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Patch - Debug builds without optimization
Date: 2011-06-20 01:39:12
Message-ID: BANLkTimiQ9phD2qxEx+-rmXUo1k-tEj6yw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Jun 16, 2011 at 9:00 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> BTW, if you're hacking Postgres code and don't already have a
> "reinstall" script, you need one.  Mine is basically
>
>        pg_ctl stop
>        cd $PGBLDROOT/src/backend
>        make install-bin
>        pg_ctl start

I've always wondered what other people do to iterate quickly. It's a
bit of a pain that you can't just run the binary out of the build
tree. This looks a lot safer than some of the things I was considering
doing with symlinks.

--
greg


From: Greg Smith <greg(at)2ndquadrant(dot)com>
To: Greg Stark <stark(at)mit(dot)edu>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Alvaro Herrera <alvherre(at)commandprompt(dot)com>, Rados?aw Smogura <rsmogura(at)softperience(dot)eu>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Patch - Debug builds without optimization
Date: 2011-06-20 04:25:08
Message-ID: 4DFECBA4.1000302@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greg Stark wrote:
> I've always wondered what other people do to iterate quickly.

I'd have bet money you had an elisp program for this by now!

The peg utility script I use makes a reinstall as simple as:

stop
peg build

The UI for peg is still is a little rough around switching to another
project when using git, and the PGDATA handling could be better. Being
able to give each patch I want to play with its own binary+data tree
with a couple of simple commands is the time consuming part to setup I
wanted to automate completely, and for that it works great:
https://github.com/gregs1104/peg

--
Greg Smith 2ndQuadrant US greg(at)2ndQuadrant(dot)com Baltimore, MD
PostgreSQL Training, Services, and 24x7 Support www.2ndQuadrant.us


From: Radosław Smogura <rsmogura(at)softperience(dot)eu>
To: Greg Stark <stark(at)mit(dot)edu>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Patch - Debug builds without optimization
Date: 2011-06-20 07:07:19
Message-ID: 201106200907.19329.rsmogura@softperience.eu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greg Stark <stark(at)mit(dot)edu> Monday 20 of June 2011 03:39:12
> On Thu, Jun 16, 2011 at 9:00 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> > BTW, if you're hacking Postgres code and don't already have a
> > "reinstall" script, you need one. Mine is basically
> >
> > pg_ctl stop
> > cd $PGBLDROOT/src/backend
> > make install-bin
> > pg_ctl start
>
> I've always wondered what other people do to iterate quickly. It's a
> bit of a pain that you can't just run the binary out of the build
> tree. This looks a lot safer than some of the things I was considering
> doing with symlinks.
I actually go to installation directory
and call in one line (simple because up arrow helps).

pg_ctl -D db stop; gmake -C ../postgresql -j5 install; pg_ctl -D db start

Regards,
Radek


From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Greg Smith <greg(at)2ndquadrant(dot)com>
Cc: Greg Stark <stark(at)mit(dot)edu>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Rados?aw Smogura <rsmogura(at)softperience(dot)eu>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Patch - Debug builds without optimization
Date: 2011-06-20 17:27:23
Message-ID: 1308590627-sup-2608@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Excerpts from Greg Smith's message of lun jun 20 00:25:08 -0400 2011:
> Greg Stark wrote:
> > I've always wondered what other people do to iterate quickly.
>
> I'd have bet money you had an elisp program for this by now!

Yeah :-)

> The peg utility script I use makes a reinstall as simple as:
>
> stop
> peg build

But you're building the entire server there, which was Tom's point --
you only need to build and reinstall the backend.

I have my own "runpg" utility which does a lot of these things too ...
The main difference (to Tom's approach) is that I don't use pg_ctl to
start/stop the server, because I always keep that running in a terminal,
which makes for easier debugging because the logs are always there and I
can ctrl-c it ... Well I guess it's pretty much the same thing, because
Tom probably has a script to stop the server.

--
Álvaro Herrera <alvherre(at)commandprompt(dot)com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Greg Smith <greg(at)2ndquadrant(dot)com>, Greg Stark <stark(at)mit(dot)edu>, Rados?aw Smogura <rsmogura(at)softperience(dot)eu>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Patch - Debug builds without optimization
Date: 2011-06-20 17:34:30
Message-ID: 14550.1308591270@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Alvaro Herrera <alvherre(at)commandprompt(dot)com> writes:
> Excerpts from Greg Smith's message of lun jun 20 00:25:08 -0400 2011:
>> The peg utility script I use makes a reinstall as simple as:
>>
>> stop
>> peg build

> But you're building the entire server there, which was Tom's point --
> you only need to build and reinstall the backend.

Right, I was trying to illustrate how to have minimal turnaround time
when testing a small code change. Rebuilding from scratch is slow
enough that you lose focus while waiting. (Or I do, anyway.)

Granted, stuff like ccache can help with that, but why not adopt a
process that's not slow in the first place?

regards, tom lane


From: Greg Smith <greg(at)2ndQuadrant(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, Greg Stark <stark(at)mit(dot)edu>, Rados?aw Smogura <rsmogura(at)softperience(dot)eu>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Patch - Debug builds without optimization
Date: 2011-06-21 04:21:03
Message-ID: 4E001C2F.6020500@2ndQuadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 06/20/2011 01:34 PM, Tom Lane wrote:
> I was trying to illustrate how to have minimal turnaround time
> when testing a small code change. Rebuilding from scratch is slow
> enough that you lose focus while waiting. (Or I do, anyway.)
>

I just keep upgrading to the fastest CPU I can possibly justify to avoid
losing focus; it goes fast with 8 cores. I was trying to demonstrate
that peg makes this very high level now, and I was more jousting at the
idea that everyone should bother to write their own individual reinstall
script.

The peg code makes it easy to assimilate whatever other neat
optimization ideas one might come across. I just pushed an update out
that absorbed this one, so now if you do:

stop
peg rebuild

It uses the install-bin trick you suggested. It even does a couple of
sanity checks so that it will probably fall back to a regular build if
it doesn't look like you have a good install and binary tree already.
Maybe I'll make a "reinstall" alias that does this combination next.

I don't expect to improve your workflow. But people who haven't already
invested a good chunk of work in automating things already will probably
take some time to catch up with where peg puts them on day one.

--
Greg Smith 2ndQuadrant US greg(at)2ndQuadrant(dot)com Baltimore, MD
PostgreSQL Training, Services, and 24x7 Support www.2ndQuadrant.us


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Greg Smith <greg(at)2ndQuadrant(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Patch - Debug builds without optimization
Date: 2011-11-29 21:32:42
Message-ID: 201111292132.pATLWgI21684@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


I have applied the attached patch to help make suggestsions for server
developers. I didn't reproduce most of the text because it was already
listed with the options. Let me know if you want additional text.

---------------------------------------------------------------------------

Greg Smith wrote:
> On 06/16/2011 10:10 AM, Tom Lane wrote:
> > I could see providing some other nonstandard configure switch that
> > changed the default -O level ... but realistically, would that do
> > anything that you couldn't already do by setting CFLAGS, ie
> >
> > ./configure CFLAGS="-O0 -g"
> >
>
> I think a small discussion of the issue Radek ran into is appropriate to
> put somewhere, with this example. The install procedure section of the
> docs already includes a CFLAGS example:
>
> ./configure CC=/opt/bin/gcc CFLAGS='-O2 -pipe'
>
> There is also a section talking about setting options like
> --enable-cassert in the Developer's FAQ. Looking at all the info out
> there about developer/debug builds, it's really kind of sketchy and
> distributed though. No one place that pulls all the most common things
> people need together into one resource.
>
> What seems like the idea solution here is to add a new section to the
> install procedure with brief coverage of this entire area. Here's a
> prototype of text that might go there:
>
> = Installation for development and debugging =
>
> When modifying the PostgreSQL source code, or when trying to find the
> source of a bug in the program, it may be helpful to build the program
> in a way that makes this process easier. There are build-time only
> changes that enable better error checking and debugging, including:
>
> Pass --enable-cassert to configure. This can make bugs more visible,
> because they cause operations to abort with a clear error. That makes
> some types of debugging much easier. This is risky on a production
> server, as described in the documentation for this parameter.
>
> Pass --enable-debug to configure. This provides better information about
> what the server is doing when looking at it using a debugger. It's less
> risky to a production server than enabling assertions, and it normally
> has less of a performance impact hgtoo. See its documentation for more
> details.
>
> Disable compiler optimization. When using a debugger to trace into the
> source code of the server, steps may optimized away by the normal build
> process. In some situations --enable-debug will disable such
> optimization, but this is not always the case. Specifically disabling
> optimization is possible with many compilers by setting the compiler
> flags when configuration the source code build, such as:
>
> ./configure CFLAGS="-O0 -g"
>
> This example for the gcc compiler disables optimizations, and tells the
> compiler to provide extra debugging information most useful with the gdb
> debugger.
>
> --
> Greg Smith 2ndQuadrant US greg(at)2ndQuadrant(dot)com Baltimore, MD
> PostgreSQL Training, Services, and 24x7 Support www.2ndQuadrant.us
>
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

Attachment Content-Type Size
/rtmp/doc text/x-diff 711 bytes

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Greg Smith <greg(at)2ndQuadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Patch - Debug builds without optimization
Date: 2011-11-29 22:07:59
Message-ID: 1322604479.7093.5.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On tis, 2011-11-29 at 16:32 -0500, Bruce Momjian wrote:
> I have applied the attached patch to help make suggestsions for server
> developers. I didn't reproduce most of the text because it was already
> listed with the options. Let me know if you want additional text.

Advising "server developers" to use CFLAGS="-O0 -g", without
qualification, is dangerous, in my mind, because that loses a lot of
compiler checks. The only reason to use -O0 is when you really need to
debug something in single steps and you can't make sense of it any other
way.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Greg Smith <greg(at)2ndQuadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Patch - Debug builds without optimization
Date: 2011-11-29 22:12:11
Message-ID: 8632.1322604731@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> On tis, 2011-11-29 at 16:32 -0500, Bruce Momjian wrote:
>> I have applied the attached patch to help make suggestsions for server
>> developers. I didn't reproduce most of the text because it was already
>> listed with the options. Let me know if you want additional text.

> Advising "server developers" to use CFLAGS="-O0 -g", without
> qualification, is dangerous, in my mind, because that loses a lot of
> compiler checks. The only reason to use -O0 is when you really need to
> debug something in single steps and you can't make sense of it any other
> way.

Yes. -O0 is really a pretty horrid default choice, and we should NOT be
recommending it, especially not with no discussion of the disadvantages.

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, Greg Smith <greg(at)2ndQuadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Patch - Debug builds without optimization
Date: 2011-11-30 00:13:49
Message-ID: 201111300013.pAU0Dno28959@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> > On tis, 2011-11-29 at 16:32 -0500, Bruce Momjian wrote:
> >> I have applied the attached patch to help make suggestsions for server
> >> developers. I didn't reproduce most of the text because it was already
> >> listed with the options. Let me know if you want additional text.
>
> > Advising "server developers" to use CFLAGS="-O0 -g", without
> > qualification, is dangerous, in my mind, because that loses a lot of
> > compiler checks. The only reason to use -O0 is when you really need to
> > debug something in single steps and you can't make sense of it any other
> > way.
>
> Yes. -O0 is really a pretty horrid default choice, and we should NOT be
> recommending it, especially not with no discussion of the disadvantages.

I have applied the attached patch to mention the debugger. OK?

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

Attachment Content-Type Size
unknown_filename text/plain 1.1 KB

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Greg Smith <greg(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Patch - Debug builds without optimization
Date: 2011-11-30 03:02:50
Message-ID: CA+TgmoZ33VOyPo2UyE25RVgUQxj_nV3Zp-AxTzv_WqLj=CE0rg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Nov 29, 2011 at 7:13 PM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
>> Yes.  -O0 is really a pretty horrid default choice, and we should NOT be
>> recommending it, especially not with no discussion of the disadvantages.
>
> I have applied the attached patch to mention the debugger.  OK?

Not really. That's still too much encouragement. I think you should
just take that part out altogether.

Discussing changes before committing them might be a good idea, too.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Greg Smith <greg(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Patch - Debug builds without optimization
Date: 2011-11-30 03:35:34
Message-ID: 201111300335.pAU3ZYd24491@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert Haas wrote:
> On Tue, Nov 29, 2011 at 7:13 PM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> >> Yes. ?-O0 is really a pretty horrid default choice, and we should NOT be
> >> recommending it, especially not with no discussion of the disadvantages.
> >
> > I have applied the attached patch to mention the debugger. ?OK?
>
> Not really. That's still too much encouragement. I think you should
> just take that part out altogether.
>
> Discussing changes before committing them might be a good idea, too.

Well, the original patch got no replies, so I figured it was OK.

I modified the docs to just mention that a debugger might need special
flags.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

Attachment Content-Type Size
/rtmp/debug text/x-diff 980 bytes

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, Greg Smith <greg(at)2ndQuadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Patch - Debug builds without optimization
Date: 2011-11-30 06:05:14
Message-ID: 28526.1322633114@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> I have applied the attached patch to mention the debugger. OK?

> Server developers should consider using the configure options
> <option>--enable-cassert</> and <option>--enable-debug</> to enhance the
> ability to detect and debug server errors. They should also consider
> ! running configure with <literal>CFLAGS="-O0 -g"</> if using a debugger.

I still think this is basically useless. If we're going to mention the
topic at all, we should provide enough information to be helpful, which
this does not. Furthermore, it's concretely wrong in that it suggests
you need to say -g when --enable-debug already does that, and that it
fails to note that all this advice is gcc-specific.

I suggest wording along these lines:

When developing code inside the server, it's recommended to
use the configure options --enable-cassert, which turns on many
run-time error checks, and --enable-debug, which improves the
usefulness of debugging tools.

If you use gcc, it's best to build with an optimization level
of at least -O1, because using level -O0 disables some important
compiler warnings (such as use of an uninitialized variable).
However, nonzero optimization levels can complicate debugging
because stepping through the compiled code will usually not
match up one-to-one with source code lines. If you get confused
while trying to debug optimized code, recompile the specific
file(s) of interest with -O0. An easy way to do this with the
Unix makefiles is "make PROFILE=-O0 file.o".

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, Greg Smith <greg(at)2ndQuadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Patch - Debug builds without optimization
Date: 2011-12-02 22:09:40
Message-ID: 201112022209.pB2M9eD22670@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > I have applied the attached patch to mention the debugger. OK?
>
> > Server developers should consider using the configure options
> > <option>--enable-cassert</> and <option>--enable-debug</> to enhance the
> > ability to detect and debug server errors. They should also consider
> > ! running configure with <literal>CFLAGS="-O0 -g"</> if using a debugger.
>
> I still think this is basically useless. If we're going to mention the
> topic at all, we should provide enough information to be helpful, which
> this does not. Furthermore, it's concretely wrong in that it suggests
> you need to say -g when --enable-debug already does that, and that it
> fails to note that all this advice is gcc-specific.
>
> I suggest wording along these lines:
>
> When developing code inside the server, it's recommended to
> use the configure options --enable-cassert, which turns on many
> run-time error checks, and --enable-debug, which improves the
> usefulness of debugging tools.
>
> If you use gcc, it's best to build with an optimization level
> of at least -O1, because using level -O0 disables some important
> compiler warnings (such as use of an uninitialized variable).
> However, nonzero optimization levels can complicate debugging
> because stepping through the compiled code will usually not
> match up one-to-one with source code lines. If you get confused
> while trying to debug optimized code, recompile the specific
> file(s) of interest with -O0. An easy way to do this with the
> Unix makefiles is "make PROFILE=-O0 file.o".

OK, I make some slight modifications and applied the attached patch.

Ideally we could tell everyone to read the developer's FAQ, but that is
too large for people who are debugging problems in our shipped code ---
that is why I was excited to get something into our main docs.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

Attachment Content-Type Size
/rtmp/debug text/x-diff 1.7 KB