1127664Sbms/*-
2127664Sbms * Copyright 1996-1998 John D. Polstra.
3127664Sbms * All rights reserved.
4127664Sbms *
5127664Sbms * Redistribution and use in source and binary forms, with or without
6127664Sbms * modification, are permitted provided that the following conditions
7127664Sbms * are met:
8127664Sbms * 1. Redistributions of source code must retain the above copyright
9127664Sbms *    notice, this list of conditions and the following disclaimer.
10127664Sbms * 2. Redistributions in binary form must reproduce the above copyright
11127664Sbms *    notice, this list of conditions and the following disclaimer in the
12127664Sbms *    documentation and/or other materials provided with the distribution.
13127664Sbms *
14127664Sbms * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15127664Sbms * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16127664Sbms * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17127664Sbms * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18127664Sbms * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19127664Sbms * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20127664Sbms * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21127664Sbms * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22127664Sbms * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23127664Sbms * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24127664Sbms *
25127664Sbms * $FreeBSD$
26127664Sbms */
27127664Sbms
28127664Sbms/*
29127664Sbms * Support for printing debugging messages.
30127664Sbms */
31127664Sbms
32127664Sbms#ifndef DEBUG_H
33127664Sbms#define DEBUG_H 1
34127664Sbms
35127664Sbms#include <sys/cdefs.h>
36127664Sbms
37214518Srpaulo#include <string.h>
38127664Sbms#include <unistd.h>
39127664Sbms
40127664Sbmsextern void debug_printf(const char *, ...) __printflike(1, 2);
41127664Sbmsextern int debug;
42127664Sbms
43127664Sbms#ifdef DEBUG
44127664Sbms#define dbg(...)	debug_printf(__VA_ARGS__)
45127664Sbms#else
46127664Sbms#define dbg(...)	((void) 0)
47127664Sbms#endif
48127664Sbms
49127664Sbms#ifndef COMPAT_32BIT
50147894Ssam#define _MYNAME	"ld-elf.so.1"
51127664Sbms#else
52127664Sbms#define _MYNAME	"ld-elf32.so.1"
53127664Sbms#endif
54147894Ssam
55127664Sbms#define assert(cond)	((cond) ? (void) 0 :		\
56127664Sbms    (msg(_MYNAME ": assert failed: " __FILE__ ":"	\
57127664Sbms      __XSTRING(__LINE__) "\n"), abort()))
58127664Sbms#define msg(s)		write(STDOUT_FILENO, s, strlen(s))
59127664Sbms#define trace()		msg(_MYNAME ": " __XSTRING(__LINE__) "\n")
60127664Sbms
61127664Sbms
62127664Sbms#endif /* DEBUG_H */
63146768Ssam