delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/06/10:47:01

Date: Sun, 6 Jul 1997 17:46:31 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Thomas Demmer <demmer AT LSTM DOT Ruhr-UNI-Bochum DOT De>
cc: djgpp AT delorie DOT com
Subject: Re: Debugging version of C library
In-Reply-To: <33B7C686.2781@LSTM.Ruhr-UNI-Bochum.De>
Message-ID: <Pine.SUN.3.91.970706174526.8624N-100000@is>
MIME-Version: 1.0

On Mon, 30 Jun 1997, Thomas Demmer wrote:

> > since rebuilding the library is not easy, I suggest to extract from
> > djlsr201.zip only the functions that you need to debug, compile them
> > with -g, put them into the library and relink your program:
> > 
> >         unzip djlsr201.zip src/libc/foo/bar.c
> >         gcc -O3 -g src/libc/foo/bar.c
> >         ar rvs lib/libc.a src/libc/foo/bar.o
> >         make yourprog
> >         gdb yourprog
> 
> I think it will suffice to copy bar.c to the working directory and link
> it into the executable:
> gcc -o foo.exe -g foo.c bar.c 
> bar.o will be seen by the linker _before_ bar.o inside libc and
> used (just because ld is a one pass linker.

Beware of such shortcuts!  I have been burned by subtle bugs and
crashes in programs when I tried to use this technique.  In some
cases, I even inserted `printf' statement into the modified library
function and saw for sure that the linker still links in the old
version from the library (the `printf' didn't work)!  Don't ask me
how can this be, but the facts are indisputable.

So I still recommend to use the longer but safer way as outlined in my
message.

> So there is no need to fiddle 
> around with libc, and probably forgetting to switch back...

Even if you don't switch back, when you strip the binary, all the
debugging symbols are gone, so you don't lose anything.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019