ftape-tracing.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #ifndef _FTAPE_TRACING_H
  2. #define _FTAPE_TRACING_H
  3. /*
  4. * Copyright (C) 1994-1996 Bas Laarhoven,
  5. * (C) 1996-1997 Claus-Justus Heine.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; see the file COPYING. If not, write to
  16. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  17. *
  18. * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-tracing.h,v $
  19. * $Revision: 1.2 $
  20. * $Date: 1997/10/05 19:18:28 $
  21. *
  22. * This file contains definitions that eases the debugging of the
  23. * QIC-40/80/3010/3020 floppy-tape driver "ftape" for Linux.
  24. */
  25. #include <linux/kernel.h>
  26. /*
  27. * Be very careful with TRACE_EXIT and TRACE_ABORT.
  28. *
  29. * if (something) TRACE_EXIT error;
  30. *
  31. * will NOT work. Use
  32. *
  33. * if (something) {
  34. * TRACE_EXIT error;
  35. * }
  36. *
  37. * instead. Maybe a bit dangerous, but save lots of lines of code.
  38. */
  39. #define LL_X "%d/%d KB"
  40. #define LL(x) (unsigned int)((__u64)(x)>>10), (unsigned int)((x)&1023)
  41. typedef enum {
  42. ft_t_nil = -1,
  43. ft_t_bug,
  44. ft_t_err,
  45. ft_t_warn,
  46. ft_t_info,
  47. ft_t_noise,
  48. ft_t_flow,
  49. ft_t_fdc_dma,
  50. ft_t_data_flow,
  51. ft_t_any
  52. } ft_trace_t;
  53. #ifdef CONFIG_FT_NO_TRACE_AT_ALL
  54. /* the compiler will optimize away most TRACE() macros
  55. */
  56. #define FT_TRACE_TOP_LEVEL ft_t_bug
  57. #define TRACE_FUN(level) do {} while(0)
  58. #define TRACE_EXIT return
  59. #define TRACE(l, m, i...) \
  60. { \
  61. if ((ft_trace_t)(l) == FT_TRACE_TOP_LEVEL) { \
  62. printk(KERN_INFO"ftape%s(%s):\n" \
  63. KERN_INFO m".\n" ,__FILE__, __FUNCTION__ , ##i); \
  64. } \
  65. }
  66. #define SET_TRACE_LEVEL(l) if ((l) == (l)) do {} while(0)
  67. #define TRACE_LEVEL FT_TRACE_TOP_LEVEL
  68. #else
  69. #ifdef CONFIG_FT_NO_TRACE
  70. /* the compiler will optimize away many TRACE() macros
  71. * the ftape_simple_trace_call() function simply increments
  72. * the function nest level.
  73. */
  74. #define FT_TRACE_TOP_LEVEL ft_t_warn
  75. #define TRACE_FUN(level) ftape_function_nest_level++
  76. #define TRACE_EXIT ftape_function_nest_level--; return
  77. #else
  78. #ifdef CONFIG_FT_FULL_DEBUG
  79. #define FT_TRACE_TOP_LEVEL ft_t_any
  80. #else
  81. #define FT_TRACE_TOP_LEVEL ft_t_flow
  82. #endif
  83. #define TRACE_FUN(level) \
  84. const ft_trace_t _tracing = level; \
  85. if (ftape_tracing >= (ft_trace_t)(level) && \
  86. (ft_trace_t)(level) <= FT_TRACE_TOP_LEVEL) \
  87. ftape_trace_call(__FILE__, __FUNCTION__); \
  88. ftape_function_nest_level ++;
  89. #define TRACE_EXIT \
  90. --ftape_function_nest_level; \
  91. if (ftape_tracing >= (ft_trace_t)(_tracing) && \
  92. (ft_trace_t)(_tracing) <= FT_TRACE_TOP_LEVEL) \
  93. ftape_trace_exit(__FILE__, __FUNCTION__); \
  94. return
  95. #endif
  96. #define TRACE(l, m, i...) \
  97. { \
  98. if (ftape_tracing >= (ft_trace_t)(l) && \
  99. (ft_trace_t)(l) <= FT_TRACE_TOP_LEVEL) { \
  100. ftape_trace_log(__FILE__, __FUNCTION__); \
  101. printk(m".\n" ,##i); \
  102. } \
  103. }
  104. #define SET_TRACE_LEVEL(l) \
  105. { \
  106. if ((ft_trace_t)(l) <= FT_TRACE_TOP_LEVEL) { \
  107. ftape_tracing = (ft_trace_t)(l); \
  108. } else { \
  109. ftape_tracing = FT_TRACE_TOP_LEVEL; \
  110. } \
  111. }
  112. #define TRACE_LEVEL \
  113. ((ftape_tracing <= FT_TRACE_TOP_LEVEL) ? ftape_tracing : FT_TRACE_TOP_LEVEL)
  114. /* Global variables declared in tracing.c
  115. */
  116. extern ft_trace_t ftape_tracing; /* sets default level */
  117. extern int ftape_function_nest_level;
  118. /* Global functions declared in tracing.c
  119. */
  120. extern void ftape_trace_call(const char *file, const char *name);
  121. extern void ftape_trace_exit(const char *file, const char *name);
  122. extern void ftape_trace_log (const char *file, const char *name);
  123. #endif /* !defined(CONFIG_FT_NO_TRACE_AT_ALL) */
  124. /*
  125. * Abort with a message.
  126. */
  127. #define TRACE_ABORT(res, i...) \
  128. { \
  129. TRACE(i); \
  130. TRACE_EXIT res; \
  131. }
  132. /* The following transforms the common "if(result < 0) ... " into a
  133. * one-liner.
  134. */
  135. #define _TRACE_CATCH(level, fun, action) \
  136. { \
  137. int _res = (fun); \
  138. if (_res < 0) { \
  139. do { action /* */ ; } while(0); \
  140. TRACE_ABORT(_res, level, "%s failed: %d", #fun, _res); \
  141. } \
  142. }
  143. #define TRACE_CATCH(fun, fail) _TRACE_CATCH(ft_t_err, fun, fail)
  144. /* Abort the current function when signalled. This doesn't belong here,
  145. * but rather into ftape-rw.h (maybe)
  146. */
  147. #define FT_SIGNAL_EXIT(sig_mask) \
  148. if (sigtestsetmask(&current->pending.signal, sig_mask)) { \
  149. TRACE_ABORT(-EINTR, \
  150. ft_t_warn, \
  151. "interrupted by non-blockable signal"); \
  152. }
  153. #endif /* _FTAPE_TRACING_H */