[PATCH] Fix /bin/sh compilation with CFLAGS += -DDEBUG > 1

John Baldwin jhb at freebsd.org
Tue Oct 12 13:14:46 UTC 2010


On Tuesday, October 12, 2010 6:47:49 am Garrett Cooper wrote:
> Hi,
>     It looks like the format strings are broken on 64-bit archs in
> /bin/sh's TRACE functionality (can be enabled by uncommenting -DDEBUG
> > 1 in bin/sh/Makefile). The attached patch fixes this functionality
> again so one can trace sh's calls with TRACE, which may or may be
> helpful to those debugging /bin/sh.
>     Tested build and execution on amd64; tested build on i386.
> Thanks!
> -Garrett

I don't think the Makefile bits are needed, you can just use
'make DEBUG_FLAGS="-g -DDEBUG=2"' instead.

Also, if you plan on using -g you should generally set DEBUG_FLAGS anyway so 
binaries are not stripped.

The use of things like PRIoMAX is not done in FreeBSD as it is ugly.  You can
use things like '%t' to print ptrdiff_t types instead.  So for example, for
the first hunk, I would change the type of 'startloc' to ptrdiff_t and use 
this:

        TRACE(("evalbackq: size=%td: \"%.*s\"\n",
                (dest - stackblock()) - startloc,
                (int)((dest - stackblock()) - startloc),
                stackblock() + startloc));

Also, in your change here, you used %j to print a size_t.  That will break on 
i386.  You should use %z to print size_t's, but even better is to just use %t 
to print a ptrdiff_t (which is the type that holds the difference of two 
pointers).

The various changes in jobs.c should use '%td' as well rather than (int) 
casts.

-- 
John Baldwin


More information about the freebsd-hackers mailing list