1/* 2 * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5#ifndef UNIX_DEBUG_H 6#define UNIX_DEBUG_H 7 8 9#include <Drivers.h> 10 11 12//#define UNIX_DEBUG_PRINT dprintf 13#define UNIX_DEBUG_PRINT ktrace_printf 14 15#if UNIX_DEBUG_LEVEL 16# define TRACE(args...) UNIX_DEBUG_PRINT(args) 17# define PRINT_ERROR(error) \ 18 do { \ 19 UNIX_DEBUG_PRINT("[%" B_PRId32 "] l. %d: %s: %s\n", \ 20 find_thread(NULL), __LINE__, __PRETTY_FUNCTION__, \ 21 strerror(error)); \ 22 } while (false) 23# if UNIX_DEBUG_LEVEL >= 2 24# define REPORT_ERROR(error) PRINT_ERROR(error) 25# define RETURN_ERROR(error) \ 26 do { \ 27 __typeof(error) error_RETURN_ERROR = (error); \ 28 PRINT_ERROR(error_RETURN_ERROR); \ 29 return error_RETURN_ERROR; \ 30 } while (false) 31# else 32# define REPORT_ERROR(error) \ 33 do { \ 34 __typeof(error) error_REPORT_ERROR = (error); \ 35 if (error_REPORT_ERROR < 0) \ 36 PRINT_ERROR(error_REPORT_ERROR); \ 37 } while (false) 38# define RETURN_ERROR(error) \ 39 do { \ 40 __typeof(error) error_RETURN_ERROR = (error); \ 41 if (error_RETURN_ERROR < 0) \ 42 PRINT_ERROR(error_RETURN_ERROR); \ 43 return error_RETURN_ERROR; \ 44 } while (false) 45# endif 46#else 47# define TRACE(args...) do {} while (false) 48# define REPORT_ERROR(error) 49# define RETURN_ERROR(error) return (error) 50#endif 51 52 53#endif // UNIX_DEBUG_H 54