debug.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (c) 1993,1994 The University of Utah and
  3. * the Computer Systems Laboratory (CSL). All rights reserved.
  4. *
  5. * Permission to use, copy, modify and distribute this software and its
  6. * documentation is hereby granted, provided that both the copyright
  7. * notice and this permission notice appear in all copies of the
  8. * software, derivative works or modified versions, and any portions
  9. * thereof, and that both notices appear in supporting documentation.
  10. *
  11. * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
  12. * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
  13. * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  14. *
  15. * CSL requests users of this software to return to csl-dist@cs.utah.edu any
  16. * improvements that they make and grant CSL redistribution rights.
  17. *
  18. * Author: Bryan Ford, University of Utah CSL
  19. */
  20. /*
  21. * File: debug.h
  22. * Author: Bryan Ford
  23. *
  24. * This file contains definitions for kernel debugging,
  25. * which are compiled in on the DEBUG symbol.
  26. *
  27. */
  28. #ifndef _mach_debug__debug_
  29. #define _mach_debug__debug_
  30. #include <kern/assert.h> /*XXX*/
  31. void panic(const char *fmt, ...);
  32. #ifndef NDEBUG
  33. #define here() printf("@ %s:%d\n", __FILE__, __LINE__)
  34. #define message(args) ({ printf("@ %s:%d: ", __FILE__, __LINE__); printf args; printf("\n"); })
  35. #define otsan() panic("%s:%d: off the straight and narrow!", __FILE__, __LINE__)
  36. #define struct_id_decl unsigned struct_id;
  37. #define struct_id_init(p,id) ((p)->struct_id = (id))
  38. #define struct_id_denit(p) ((p)->struct_id = 0)
  39. #define struct_id_verify(p,id) \
  40. ({ if ((p)->struct_id != (id)) \
  41. panic("%s:%d: "#p" (%08x) struct_id should be "#id" (%08x), is %08x\n", \
  42. __FILE__, __LINE__, (p), (id), (p->struct_id)); \
  43. })
  44. #else /* NDEBUG */
  45. #define otsan()
  46. #define struct_id_decl
  47. #define struct_id_init(p,id)
  48. #define struct_id_denit(p)
  49. #define struct_id_verify(p,id)
  50. #endif /* NDEBUG */
  51. extern void log (int level, const char *fmt, ...);
  52. extern void panic_init(void);
  53. extern void Panic (const char *file, int line, const char *fun,
  54. const char *s, ...)
  55. __attribute__ ((noreturn, format (printf, 4, 5)));
  56. #define gnumach_panic(s, ...) \
  57. Panic (__FILE__, __LINE__, __FUNCTION__, s, ##__VA_ARGS__)
  58. extern void SoftDebugger (const char *message);
  59. extern void Debugger (const char *message) __attribute__ ((noreturn));
  60. #endif /* _mach_debug__debug_ */