Subject: rfc: Create a .gdbinit for in-tree programs
To: None <tech-toolchain@netbsd.org>
From: Jason R Thorpe <thorpej@wasabisystems.com>
List: tech-toolchain
Date: 09/02/2002 22:18:18
--ZGiS0Q5IWpPtfppv
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Folks..

I've found this patch pretty useful recently, especially when cross-
debugging programs.  What it does is cause <bsd.prog.mk> to create a
.gdbinit file in the objdir that sets the shared library prefix to
${DESTDIR}, and optionally allows other program-specific gdb init files
to be sourced in.

For example, if you have a DESTDIR of /export/client1, and you built
src/usr.bin/make, a .gdbinit could be created that has:

set solib-absolute-prefix /export/client1

You can also specify additional gdb init files, so if make's Makefile
wanted to specify a gdb init file which had macros to dump make(1)'s
internal data structure, it could do:

GDBINIT= ${.CURDIR}/gdbinit

...which would cause the generated .gdbinit to have e.g.:

set solib-absolute-prefix /export/client1
source /usr/src/usr.bin/make/gdbinit

It's legal to specify more than one file in GDBINIT, e.g. you could
say:

GDBINIT= ${.CURDIR}/gdbinit ${.CURDIR}/lst.lib/gdbinit

It certainly seems useful enough to plop into the tree (careful readers
will note I already did something similar for kernel builds :-)

The only thing that bothers me about it is that there doesn't seem to be
an obvious way to depend on all of the Makefiles in the "chain" (i.e. all
of the Makefile.inc's that get included along the way, etc.)  If someone
knows how to do that reasonably, I'm all ears :-)

-- 
        -- Jason R. Thorpe <thorpej@wasabisystems.com>

--ZGiS0Q5IWpPtfppv
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=bsd-prog-solib-patch

Index: bsd.prog.mk
===================================================================
RCS file: /cvsroot/sharesrc/share/mk/bsd.prog.mk,v
retrieving revision 1.156
diff -c -r1.156 bsd.prog.mk
*** bsd.prog.mk	2002/08/09 00:21:22	1.156
--- bsd.prog.mk	2002/09/03 05:17:12
***************
*** 118,133 ****
  _CCLINK=	${CC}
  .endif
  
  .if defined(DESTDIR)
  
! ${PROG}: ${LIBCRT0} ${DPSRCS} ${OBJS} ${LIBC} ${LIBCRTBEGIN} ${LIBCRTEND} ${DPADD}
  .if !commands(${PROG})
  	${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} -nostdlib ${_PROGLDOPTS} ${LIBCRT0} ${LIBCRTBEGIN} ${OBJS} ${LDADD} -L${DESTDIR}/usr/lib ${_SUPCXX} -lgcc -lc -lgcc ${LIBCRTEND}
  .endif
  
  .else
  
! ${PROG}: ${LIBCRT0} ${DPSRCS} ${OBJS} ${LIBC} ${LIBCRTBEGIN} ${LIBCRTEND} ${DPADD}
  .if !commands(${PROG})
  	${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${_PROGLDOPTS} ${OBJS} ${LDADD}
  .endif
--- 118,144 ----
  _CCLINK=	${CC}
  .endif
  
+ .gdbinit:
+ 	rm -f .gdbinit
+ .if defined(DESTDIR) && !empty(DESTDIR)
+ 	echo "set solib-absolute-prefix ${DESTDIR}" > .gdbinit
+ .else
+ 	touch .gdbinit
+ .endif
+ .for __gdbinit in ${GDBINIT}
+ 	echo "source ${__gdbinit}" >> .gdbinit
+ .endfor
+ 
  .if defined(DESTDIR)
  
! ${PROG}: .gdbinit ${LIBCRT0} ${DPSRCS} ${OBJS} ${LIBC} ${LIBCRTBEGIN} ${LIBCRTEND} ${DPADD}
  .if !commands(${PROG})
  	${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} -nostdlib ${_PROGLDOPTS} ${LIBCRT0} ${LIBCRTBEGIN} ${OBJS} ${LDADD} -L${DESTDIR}/usr/lib ${_SUPCXX} -lgcc -lc -lgcc ${LIBCRTEND}
  .endif
  
  .else
  
! ${PROG}: .gdbinit ${LIBCRT0} ${DPSRCS} ${OBJS} ${LIBC} ${LIBCRTBEGIN} ${LIBCRTEND} ${DPADD}
  .if !commands(${PROG})
  	${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${_PROGLDOPTS} ${OBJS} ${LDADD}
  .endif
***************
*** 143,149 ****
  realall: ${PROG} ${SCRIPTS}
  
  cleanprog: cleanobjs cleanextra
! 	rm -f a.out [Ee]rrs mklog core *.core ${PROG}
  
  cleanobjs:
  .if defined(OBJS) && !empty(OBJS)
--- 154,160 ----
  realall: ${PROG} ${SCRIPTS}
  
  cleanprog: cleanobjs cleanextra
! 	rm -f a.out [Ee]rrs mklog core *.core .gdbinit ${PROG}
  
  cleanobjs:
  .if defined(OBJS) && !empty(OBJS)

--ZGiS0Q5IWpPtfppv--