134192Sjdp/*-
234192Sjdp * Copyright 1996-1998 John D. Polstra.
334192Sjdp * All rights reserved.
434192Sjdp *
534192Sjdp * Redistribution and use in source and binary forms, with or without
634192Sjdp * modification, are permitted provided that the following conditions
734192Sjdp * are met:
834192Sjdp * 1. Redistributions of source code must retain the above copyright
934192Sjdp *    notice, this list of conditions and the following disclaimer.
1034192Sjdp * 2. Redistributions in binary form must reproduce the above copyright
1134192Sjdp *    notice, this list of conditions and the following disclaimer in the
1234192Sjdp *    documentation and/or other materials provided with the distribution.
1334192Sjdp *
1434192Sjdp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1534192Sjdp * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1634192Sjdp * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1734192Sjdp * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1834192Sjdp * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1934192Sjdp * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2034192Sjdp * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2134192Sjdp * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2234192Sjdp * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2334192Sjdp * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2434192Sjdp *
2550476Speter * $FreeBSD$
2634192Sjdp */
2734192Sjdp
2834192Sjdp/*
2934192Sjdp * Support for printing debugging messages.
3034192Sjdp */
3134192Sjdp
3234192Sjdp#ifndef DEBUG_H
3334192Sjdp#define DEBUG_H 1
3434192Sjdp
3550930Sjdp#include <sys/cdefs.h>
3650930Sjdp
3755122Sjdp#include <string.h>
3855122Sjdp#include <unistd.h>
3955122Sjdp
4050930Sjdpextern void debug_printf(const char *, ...) __printflike(1, 2);
4134192Sjdpextern int debug;
4234192Sjdp
4334192Sjdp#ifdef DEBUG
44157219Sdes#define dbg(...)	debug_printf(__VA_ARGS__)
4534192Sjdp#else
46157219Sdes#define dbg(...)	((void) 0)
4734192Sjdp#endif
4834192Sjdp
49127250Speter#ifndef COMPAT_32BIT
50127250Speter#define _MYNAME	"ld-elf.so.1"
51127250Speter#else
52127250Speter#define _MYNAME	"ld-elf32.so.1"
53127250Speter#endif
54127250Speter
5555122Sjdp#define assert(cond)	((cond) ? (void) 0 :		\
56127250Speter    (msg(_MYNAME ": assert failed: " __FILE__ ":"	\
5755122Sjdp      __XSTRING(__LINE__) "\n"), abort()))
5880381Ssheldonh#define msg(s)		write(STDOUT_FILENO, s, strlen(s))
59127250Speter#define trace()		msg(_MYNAME ": " __XSTRING(__LINE__) "\n")
6055122Sjdp
61127250Speter
6234192Sjdp#endif /* DEBUG_H */
63