<?xml version="1.0" encoding="utf-8"?>
<launchpad-bug id="576468">
  <date_last_updated>2010-05-10 17:00:00.870645+00:00</date_last_updated>
  <api_links>
    <bug_api_link>https://api.launchpad.net/1.0/bugs/576468</bug_api_link>
    <bug_owner_link>https://api.launchpad.net/1.0/~paul-mccullagh</bug_owner_link>
    <milestone_link></milestone_link>
    <linked_branches_collection_link>https://api.launchpad.net/1.0/bugs/576468/linked_branches</linked_branches_collection_link>
    <activity_link>https://api.launchpad.net/1.0/bugs/576468/activity</activity_link>
  </api_links>
  <bug_web_link>https://bugs.launchpad.net/bugs/576468</bug_web_link>
  <owner>Paul McCullagh</owner>
  <assignee></assignee>
  <milestone_title></milestone_title>
  <duplicate_link></duplicate_link>
  <duplicate_bug_id></duplicate_bug_id>
  <title>Problem building --with-debug</title>
  <status>Invalid</status>
  <importance>Wishlist</importance>
  <created>2010-05-06 15:44:14.098773+00:00</created>
  <description>
<![CDATA[I configured MariaDB with --with-debug=full, but I still get it building with "-O2", for example:

gcc -DHAVE_CONFIG_H -I. -I../include -I../include -I../include    -g -g -O2   -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT  -DDONT_DECLARE_CXA_PURE_VIRTUAL -MT strxmov.o -MD -MP -MF .deps/strxmov.Tpo -c -o strxmov.o strxmov.c

It looks like AC_PROG_LIBTOOL sets:

CFLAGS = -g -O2
CXXFLAGS = -g -O2

This is the same with autoconf 2.63 on Mac and autoconf 2.59 on Linux.

MySQL 5.1.46 configure has the same problem.

Here is a quick patch which fixes the problem:

=== modified file 'configure.in'
--- configure.in	2010-04-29 07:29:04 +0000
+++ configure.in	2010-05-06 15:41:15 +0000
@@ -15,6 +15,12 @@
 # first part and a 100 character second part.
 AM_INIT_AUTOMAKE([1.9 tar-ustar])
 AC_PROG_LIBTOOL
+if test "$CFLAGS" = "-g -O2" ; then
+	CFLAGS=""
+fi
+if test "$CXXFLAGS" = "-g -O2" ; then
+	CXXFLAGS=""
+fi
 
 AM_CONFIG_HEADER([include/config.h])]]>  </description>
  <activities>
    <activity datechanged="2010-05-06T15:44:14.098773+00:00">
      <oldvalue>
<![CDATA[]]>      </oldvalue>
      <newvalue>
<![CDATA[]]>      </newvalue>
      <whatchanged>bug</whatchanged>
      <person>Paul McCullagh</person>
      <message>added bug</message>
    </activity>
    <activity datechanged="2010-05-10T16:59:56.876056+00:00">
      <oldvalue>
<![CDATA[Undecided]]>      </oldvalue>
      <newvalue>
<![CDATA[Wishlist]]>      </newvalue>
      <whatchanged>maria: importance</whatchanged>
      <person>Paul McCullagh</person>
      <message></message>
    </activity>
    <activity datechanged="2010-05-10T16:59:56.876056+00:00">
      <oldvalue>
<![CDATA[New]]>      </oldvalue>
      <newvalue>
<![CDATA[Invalid]]>      </newvalue>
      <whatchanged>maria: status</whatchanged>
      <person>Paul McCullagh</person>
      <message></message>
    </activity>
  </activities>
  <comments>
    <comment commentlink="https://api.launchpad.net/1.0/maria/+bug/576468/comments/1" datecreated="2010-05-10T13:42:21.959272+00:00">
      <person>Michael Widenius</person>
      <subject>
<![CDATA[[Bug 576468] [NEW] Problem building --with-debug]]>      </subject>
      <content>
<![CDATA[
Hi!

>>>>> "Paul" == Paul McCullagh <paul.mccullagh@primebase.org> writes:

Paul> Public bug reported:
Paul> I configured MariaDB with --with-debug=full, but I still get it building
Paul> with "-O2", for example:

Paul> gcc -DHAVE_CONFIG_H -I. -I../include -I../include -I../include    -g -g
Paul> -O2   -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE
Paul> -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT
Paul> -DDONT_DECLARE_CXA_PURE_VIRTUAL -MT strxmov.o -MD -MP -MF
Paul> .deps/strxmov.Tpo -c -o strxmov.o strxmov.c

Paul> It looks like AC_PROG_LIBTOOL sets:

Paul> CFLAGS = -g -O2
Paul> CXXFLAGS = -g -O2

Paul> This is the same with autoconf 2.63 on Mac and autoconf 2.59 on Linux.

Paul> MySQL 5.1.46 configure has the same problem.

Paul> Here is a quick patch which fixes the problem:

I usually don't mind the -O2 (except sometimes in the debugger) as
this makes the code act in more similar ways as it will for the
final user. (Some strange bugs are more likely to appear in optimized
code).

What I do when I don't want the -O2 is :

CFLAGS="" CXXFLAGS="" ./configure --with-debug=full

I tested this and with this I didn't get -O2 in my Makefiles

Regards,
Monty
]]>      </content>
    </comment>
    <comment commentlink="https://api.launchpad.net/1.0/maria/+bug/576468/comments/2" datecreated="2010-05-10T16:58:20.233756+00:00">
      <person>Paul McCullagh</person>
      <subject>
<![CDATA[Re: Problem building --with-debug]]>      </subject>
      <content>
<![CDATA[Thanks Monty, setting CFLAGS and CXXFLAGS to "" in the environment works for me too.

But I guess I am now missing a configuration option that specifically turns optimizations off. The problem is (as you mentioned) when working in the debugger.

With -O2 local variables are often not available in the debugger.

So it may be convenient to have an option like, for example, --without-optimization. Default will be enabled, of course.

]]>      </content>
    </comment>
    <comment commentlink="https://api.launchpad.net/1.0/maria/+bug/576468/comments/3" datecreated="2010-05-10T16:59:56.876056+00:00">
      <person>Paul McCullagh</person>
      <subject>
<![CDATA[Re: Problem building --with-debug]]>      </subject>
      <content>
<![CDATA[This is not a bug. But I changing this to a feature request because I think it would be convenient to have a configure option that specifically turns off optimization for debug and development purposes.
]]>      </content>
    </comment>
  </comments>
</launchpad-bug>
