xref: /freebsd/libexec/rtld-elf/debug.h (revision 4d846d260e2b9a3d4d0a701462568268cbfe7a5b)
13124c3e0SJohn Polstra /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3e6209940SPedro F. Giffuni  *
43124c3e0SJohn Polstra  * Copyright 1996-1998 John D. Polstra.
53124c3e0SJohn Polstra  * All rights reserved.
63124c3e0SJohn Polstra  *
73124c3e0SJohn Polstra  * Redistribution and use in source and binary forms, with or without
83124c3e0SJohn Polstra  * modification, are permitted provided that the following conditions
93124c3e0SJohn Polstra  * are met:
103124c3e0SJohn Polstra  * 1. Redistributions of source code must retain the above copyright
113124c3e0SJohn Polstra  *    notice, this list of conditions and the following disclaimer.
123124c3e0SJohn Polstra  * 2. Redistributions in binary form must reproduce the above copyright
133124c3e0SJohn Polstra  *    notice, this list of conditions and the following disclaimer in the
143124c3e0SJohn Polstra  *    documentation and/or other materials provided with the distribution.
153124c3e0SJohn Polstra  *
163124c3e0SJohn Polstra  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
173124c3e0SJohn Polstra  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
183124c3e0SJohn Polstra  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
193124c3e0SJohn Polstra  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
203124c3e0SJohn Polstra  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
213124c3e0SJohn Polstra  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
223124c3e0SJohn Polstra  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
233124c3e0SJohn Polstra  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
243124c3e0SJohn Polstra  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
253124c3e0SJohn Polstra  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
263124c3e0SJohn Polstra  *
277f3dea24SPeter Wemm  * $FreeBSD$
283124c3e0SJohn Polstra  */
293124c3e0SJohn Polstra 
303124c3e0SJohn Polstra /*
313124c3e0SJohn Polstra  * Support for printing debugging messages.
323124c3e0SJohn Polstra  */
333124c3e0SJohn Polstra 
343124c3e0SJohn Polstra #ifndef DEBUG_H
353124c3e0SJohn Polstra #define DEBUG_H 1
363124c3e0SJohn Polstra 
370edd3ca7SJohn Polstra #include <sys/cdefs.h>
380edd3ca7SJohn Polstra 
39d3980376SJohn Polstra #include <string.h>
40e69dc862SAlex Richardson #include "rtld_printf.h"
41d3980376SJohn Polstra 
42e3e21edbSKonstantin Belousov void debug_printf(const char *, ...) __printflike(1, 2);
433124c3e0SJohn Polstra extern int debug;
443124c3e0SJohn Polstra 
45e3e21edbSKonstantin Belousov #ifndef NO_LD_DEBUG
461dc39023SDag-Erling Smørgrav #define dbg(...)	debug_printf(__VA_ARGS__)
473124c3e0SJohn Polstra #else
481dc39023SDag-Erling Smørgrav #define dbg(...)	((void) 0)
493124c3e0SJohn Polstra #endif
503124c3e0SJohn Polstra 
51c905e45dSPeter Wemm #ifndef COMPAT_32BIT
52c905e45dSPeter Wemm #define _MYNAME	"ld-elf.so.1"
53c905e45dSPeter Wemm #else
54c905e45dSPeter Wemm #define _MYNAME	"ld-elf32.so.1"
55c905e45dSPeter Wemm #endif
56c905e45dSPeter Wemm 
57d3980376SJohn Polstra #define assert(cond)	((cond) ? (void) 0 :		\
58c905e45dSPeter Wemm     (msg(_MYNAME ": assert failed: " __FILE__ ":"	\
59d3980376SJohn Polstra       __XSTRING(__LINE__) "\n"), abort()))
60e69dc862SAlex Richardson #define msg(s)		rtld_putstr(s)
61c905e45dSPeter Wemm #define trace()		msg(_MYNAME ": " __XSTRING(__LINE__) "\n")
62c905e45dSPeter Wemm 
63d3980376SJohn Polstra 
643124c3e0SJohn Polstra #endif /* DEBUG_H */
65