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 3534192Sjdp#ifndef __GNUC__ 3634192Sjdp#error "This file must be compiled with GCC" 3734192Sjdp#endif 3834192Sjdp 3950930Sjdp#include <sys/cdefs.h> 4050930Sjdp 4155122Sjdp#include <string.h> 4255122Sjdp#include <unistd.h> 4355122Sjdp 4450930Sjdpextern void debug_printf(const char *, ...) __printflike(1, 2); 4534192Sjdpextern int debug; 4634192Sjdp 4734192Sjdp#ifdef DEBUG 48157219Sdes#define dbg(...) debug_printf(__VA_ARGS__) 4934192Sjdp#else 50157219Sdes#define dbg(...) ((void) 0) 5134192Sjdp#endif 5234192Sjdp 53127250Speter#ifndef COMPAT_32BIT 54127250Speter#define _MYNAME "ld-elf.so.1" 55127250Speter#else 56127250Speter#define _MYNAME "ld-elf32.so.1" 57127250Speter#endif 58127250Speter 5955122Sjdp#define assert(cond) ((cond) ? (void) 0 : \ 60127250Speter (msg(_MYNAME ": assert failed: " __FILE__ ":" \ 6155122Sjdp __XSTRING(__LINE__) "\n"), abort())) 6280381Ssheldonh#define msg(s) write(STDOUT_FILENO, s, strlen(s)) 63127250Speter#define trace() msg(_MYNAME ": " __XSTRING(__LINE__) "\n") 6455122Sjdp 65127250Speter 6634192Sjdp#endif /* DEBUG_H */ 67