Bug 100939

Summary: [patch] bsd.port.mk - add basic infrastructure support for debugging
Product: Ports & Packages Reporter: Gabor Kovesdan <gabor>
Component: Individual Port(s)Assignee: Port Management Team <portmgr>
Status: Closed FIXED    
Severity: Affects Only Me CC: netchild
Priority: Normal    
Version: Latest   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
with_debug.diff none

Description Gabor Kovesdan freebsd_committer freebsd_triage 2006-07-27 22:40:21 UTC
This patch adds  a basic infrastructure support for building binaries for
debugging purposes.  A new knob, WITH_DEBUG is introduced.  If set
DEBUG_FLAGS (-g at default) are added to CFLAGS and binaries
doesn't get stripped by INSTALL_PROGRAM.  Besides, each port
could/should add its specific things for WITH_DEBUG.
DEBUG_FLAGS can be overridden, of course.

Suggested by:	netchild
Reviewed by:	netchild
Comment 1 Edwin Groothuis freebsd_committer freebsd_triage 2006-07-27 22:40:53 UTC
Responsible Changed
From-To: freebsd-ports-bugs->portmgr

bsd.port.mk is port manager territory
Comment 2 Kris Kennaway freebsd_committer freebsd_triage 2006-11-19 21:01:45 UTC
State Changed
From-To: open->feedback

The intention here is a good one but further work is necessary to make it useful: 

* even if built with debugging symbols, install(1) will strip them out 
unless you tell it not to, so this change also needs to modify the 
INSTALL_* macros. 

* Options are not disabled by setting WITH_FOO=no, they're disabled by 
setting WITHOUT_FOO.  The value of these variables has no meaning.
Comment 3 Pav Lucistnik freebsd_committer freebsd_triage 2006-11-24 13:54:39 UTC
Updated patch from submitter:
http://gabor.t-hosting.hu/patches/with_debug.diff

Another updated patch from submitter at same URL from Nov 30.
Comment 4 Pav Lucistnik freebsd_committer freebsd_triage 2006-11-30 14:02:28 UTC
> http://gabor.t-hosting.hu/patches/with_debug.diff
> 
> What about this patch? I added a check against WITHOUT_DEBUG and did a 
> sweep against ports that use WITH_DEBUG in some way
> and deleted the redundant things there. I also made some standardization 
> among these, they always respect DEBUG_FLAGS and
> always use WITH_DEBUG, instead of WITH_DEBUG_INFO now. As Pav 
> recommended, the optimizations in CFLAGS are not
> passed here, by setting CFLAGS just to DEBUG_FLAGS, since -O2 
> optimizations are not quite useful for debugging.

This patch have one problem. If the port needs to add something to
CFLAGS, it gets lost. Example with net/iaxmodem:

$ make -V CFLAGS
-O2 -fno-strict-aliasing -pipe  -I/usr/local/include
$ make -V CFLAGS WITH_DEBUG=1
-g

Obviously, the second line should read -g -I/usr/local/include

I think you'll need to do something like
CFLAGS:=        ${CFLAGS:N-O*:N-f*}
to only remove -O* and -f* flags from existing CFLAGS.

PS
Keep Cc:ing bug-followup@FreeBSD.org so your updates get recorded in PR.

-- 
Pav Lucistnik <pav@oook.cz>
              <pav@FreeBSD.org>

Pain clots and unformed lice pat this train.
Comment 5 Gabor Kovesdan freebsd_committer freebsd_triage 2006-12-07 09:46:15 UTC
Pav Lucistnik schrieb:
>> http://gabor.t-hosting.hu/patches/with_debug.diff
>>
>> What about this patch? I added a check against WITHOUT_DEBUG and did a 
>> sweep against ports that use WITH_DEBUG in some way
>> and deleted the redundant things there. I also made some standardization 
>> among these, they always respect DEBUG_FLAGS and
>> always use WITH_DEBUG, instead of WITH_DEBUG_INFO now. As Pav 
>> recommended, the optimizations in CFLAGS are not
>> passed here, by setting CFLAGS just to DEBUG_FLAGS, since -O2 
>> optimizations are not quite useful for debugging.
>>     
>
> This patch have one problem. If the port needs to add something to
> CFLAGS, it gets lost. Example with net/iaxmodem:
>
> $ make -V CFLAGS
> -O2 -fno-strict-aliasing -pipe  -I/usr/local/include
> $ make -V CFLAGS WITH_DEBUG=1
> -g
>
> Obviously, the send line should read -g -I/usr/local/include
>
> I think you'll need to do something like
> CFLAGS:=        ${CFLAGS:N-O*:N-f*}
> to only remove -O* and -f* flags from existing CFLAGS.
>
> PS
> Keep Cc:ing bug-followup@FreeBSD.org so your updates get recorded in PR.
>
>   
Rerolled, and seems to work:

http://gabor.t-hosting.hu/patches/with_debug.diff

At the same manner, what about -march? And -mmmx, -msse, -msse2, -msse3, 
-m3dnow? Can they be kept or should be removed as well? Or can we 
suppose one won't use them for debugging?

Cheers,
Gabor
Comment 6 Pav Lucistnik freebsd_committer freebsd_triage 2006-12-07 14:39:37 UTC
> > This patch have one problem. If the port needs to add something to
> > CFLAGS, it gets lost. Example with net/iaxmodem:
> >
> > $ make -V CFLAGS
> > -O2 -fno-strict-aliasing -pipe  -I/usr/local/include
> > $ make -V CFLAGS WITH_DEBUG=1
> > -g
> >
> > Obviously, the second line should read -g -I/usr/local/include
> >
> > I think you'll need to do something like
> > CFLAGS:=        ${CFLAGS:N-O*:N-f*}
> > to only remove -O* and -f* flags from existing CFLAGS.
> >
> > PS
> > Keep Cc:ing bug-followup@FreeBSD.org so your updates get recorded in PR.
> >
> >   
> Rerolled, and seems to work:
> 
> http://gabor.t-hosting.hu/patches/with_debug.diff

$ make -V CFLAGS WITH_DEBUG=1
Variable CFLAGS is recursive.

Have you tested it, at all?

> At the same manner, what about -march? And -mmmx, -msse, -msse2, -msse3, 
> -m3dnow? Can they be kept or should be removed as well? Or can we 
> suppose one won't use them for debugging?

I don't think we have to strip these.

-- 
Pav Lucistnik <pav@oook.cz>
              <pav@FreeBSD.org>

That must be wonderful!  I don't understand it at all.
  -- Moliere
Comment 7 Gabor Kovesdan freebsd_committer freebsd_triage 2006-12-07 18:11:24 UTC
Pav Lucistnik schrieb:
>
> $ make -V CFLAGS WITH_DEBUG=1
> Variable CFLAGS is recursive.
>
> Have you tested it, at all?
>
>   
Sure, I just uploaded the wrong patch. Sorry for the mess. It works with 
":=". The correct patch is at the same location now.

Gabor
Comment 8 Pav Lucistnik freebsd_committer freebsd_triage 2006-12-08 08:24:10 UTC
State Changed
From-To: feedback->open

A good patch available now
Comment 9 Pav Lucistnik freebsd_committer freebsd_triage 2007-01-23 20:00:22 UTC
State Changed
From-To: open->analyzed

Accepted for a test build on the cluster. 
http://people.freebsd.org/~pav/with_debug.diff <- tested patch
Comment 10 Pav Lucistnik freebsd_committer freebsd_triage 2007-01-31 16:13:32 UTC
State Changed
From-To: analyzed->closed

Committed, thanks.