ftape-tracing.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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/config.h>
  26. #include <linux/kernel.h>
  27. /*
  28. * Be very careful with TRACE_EXIT and TRACE_ABORT.
  29. *
  30. * if (something) TRACE_EXIT error;
  31. *
  32. * will NOT work. Use
  33. *
  34. * if (something) {
  35. * TRACE_EXIT error;
  36. * }
  37. *
  38. * instead. Maybe a bit dangerous, but save lots of lines of code.
  39. */
  40. #define LL_X "%d/%d KB"
  41. #define LL(x) (unsigned int)((__u64)(x)>>10), (unsigned int)((x)&1023)
  42. typedef enum {
  43. ft_t_nil = -1,
  44. ft_t_bug,
  45. ft_t_err,
  46. ft_t_warn,
  47. ft_t_info,
  48. ft_t_noise,
  49. ft_t_flow,
  50. ft_t_fdc_dma,
  51. ft_t_data_flow,
  52. ft_t_any
  53. } ft_trace_t;
  54. #ifdef CONFIG_FT_NO_TRACE_AT_ALL
  55. /* the compiler will optimize away most TRACE() macros
  56. */
  57. #define FT_TRACE_TOP_LEVEL ft_t_bug
  58. #define TRACE_FUN(level) do {} while(0)
  59. #define TRACE_EXIT return
  60. #define TRACE(l, m, i...) \
  61. { \
  62. if ((ft_trace_t)(l) == FT_TRACE_TOP_LEVEL) { \
  63. printk(KERN_INFO"ftape%s(%s):\n" \
  64. KERN_INFO m".\n" ,__FILE__, __FUNCTION__ , ##i); \
  65. } \
  66. }
  67. #define SET_TRACE_LEVEL(l) if ((l) == (l)) do {} while(0)
  68. #define TRACE_LEVEL FT_TRACE_TOP_LEVEL
  69. #else
  70. #ifdef CONFIG_FT_NO_TRACE
  71. /* the compiler will optimize away many TRACE() macros
  72. * the ftape_simple_trace_call() function simply increments
  73. * the function nest level.
  74. */
  75. #define FT_TRACE_TOP_LEVEL ft_t_warn
  76. #define TRACE_FUN(level) ftape_function_nest_level++
  77. #define TRACE_EXIT ftape_function_nest_level--; return
  78. #else
  79. #ifdef CONFIG_FT_FULL_DEBUG
  80. #define FT_TRACE_TOP_LEVEL ft_t_any
  81. #else
  82. #define FT_TRACE_TOP_LEVEL ft_t_flow
  83. #endif
  84. #define TRACE_FUN(level) \
  85. const ft_trace_t _tracing = level; \
  86. if (ftape_tracing >= (ft_trace_t)(level) && \
  87. (ft_trace_t)(level) <= FT_TRACE_TOP_LEVEL) \
  88. ftape_trace_call(__FILE__, __FUNCTION__); \
  89. ftape_function_nest_level ++;
  90. #define TRACE_EXIT \
  91. --ftape_function_nest_level; \
  92. if (ftape_tracing >= (ft_trace_t)(_tracing) && \
  93. (ft_trace_t)(_tracing) <= FT_TRACE_TOP_LEVEL) \
  94. ftape_trace_exit(__FILE__, __FUNCTION__); \
  95. return
  96. #endif
  97. #define TRACE(l, m, i...) \
  98. { \
  99. if (ftape_tracing >= (ft_trace_t)(l) && \
  100. (ft_trace_t)(l) <= FT_TRACE_TOP_LEVEL) { \
  101. ftape_trace_log(__FILE__, __FUNCTION__); \
  102. printk(m".\n" ,##i); \
  103. } \
  104. }
  105. #define SET_TRACE_LEVEL(l) \
  106. { \
  107. if ((ft_trace_t)(l) <= FT_TRACE_TOP_LEVEL) { \
  108. ftape_tracing = (ft_trace_t)(l); \
  109. } else { \
  110. ftape_tracing = FT_TRACE_TOP_LEVEL; \
  111. } \
  112. }
  113. #define TRACE_LEVEL \
  114. ((ftape_tracing <= FT_TRACE_TOP_LEVEL) ? ftape_tracing : FT_TRACE_TOP_LEVEL)
  115. /* Global variables declared in tracing.c
  116. */
  117. extern ft_trace_t ftape_tracing; /* sets default level */
  118. extern int ftape_function_nest_level;
  119. /* Global functions declared in tracing.c
  120. */
  121. extern void ftape_trace_call(const char *file, const char *name);
  122. extern void ftape_trace_exit(const char *file, const char *name);
  123. extern void ftape_trace_log (const char *file, const char *name);
  124. #endif /* !defined(CONFIG_FT_NO_TRACE_AT_ALL) */
  125. /*
  126. * Abort with a message.
  127. */
  128. #define TRACE_ABORT(res, i...) \
  129. { \
  130. TRACE(i); \
  131. TRACE_EXIT res; \
  132. }
  133. /* The following transforms the common "if(result < 0) ... " into a
  134. * one-liner.
  135. */
  136. #define _TRACE_CATCH(level, fun, action) \
  137. { \
  138. int _res = (fun); \
  139. if (_res < 0) { \
  140. do { action /* */ ; } while(0); \
  141. TRACE_ABORT(_res, level, "%s failed: %d", #fun, _res); \
  142. } \
  143. }
  144. #define TRACE_CATCH(fun, fail) _TRACE_CATCH(ft_t_err, fun, fail)
  145. /* Abort the current function when signalled. This doesn't belong here,
  146. * but rather into ftape-rw.h (maybe)
  147. */
  148. #define FT_SIGNAL_EXIT(sig_mask) \
  149. if (sigtestsetmask(&current->pending.signal, sig_mask)) { \
  150. TRACE_ABORT(-EINTR, \
  151. ft_t_warn, \
  152. "interrupted by non-blockable signal"); \
  153. }
  154. #endif /* _FTAPE_TRACING_H */