debug.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. * include/asm-s390/debug.h
  3. * S/390 debug facility
  4. *
  5. * Copyright (C) 1999, 2000 IBM Deutschland Entwicklung GmbH,
  6. * IBM Corporation
  7. */
  8. #ifndef DEBUG_H
  9. #define DEBUG_H
  10. #include <linux/fs.h>
  11. /* Note:
  12. * struct __debug_entry must be defined outside of #ifdef __KERNEL__
  13. * in order to allow a user program to analyze the 'raw'-view.
  14. */
  15. struct __debug_entry{
  16. union {
  17. struct {
  18. unsigned long long clock:52;
  19. unsigned long long exception:1;
  20. unsigned long long level:3;
  21. unsigned long long cpuid:8;
  22. } fields;
  23. unsigned long long stck;
  24. } id;
  25. void* caller;
  26. } __attribute__((packed));
  27. #define __DEBUG_FEATURE_VERSION 2 /* version of debug feature */
  28. #ifdef __KERNEL__
  29. #include <linux/string.h>
  30. #include <linux/spinlock.h>
  31. #include <linux/kernel.h>
  32. #include <linux/time.h>
  33. #define DEBUG_MAX_LEVEL 6 /* debug levels range from 0 to 6 */
  34. #define DEBUG_OFF_LEVEL -1 /* level where debug is switched off */
  35. #define DEBUG_FLUSH_ALL -1 /* parameter to flush all areas */
  36. #define DEBUG_MAX_VIEWS 10 /* max number of views in proc fs */
  37. #define DEBUG_MAX_NAME_LEN 64 /* max length for a debugfs file name */
  38. #define DEBUG_DEFAULT_LEVEL 3 /* initial debug level */
  39. #define DEBUG_DIR_ROOT "s390dbf" /* name of debug root directory in proc fs */
  40. #define DEBUG_DATA(entry) (char*)(entry + 1) /* data is stored behind */
  41. /* the entry information */
  42. typedef struct __debug_entry debug_entry_t;
  43. struct debug_view;
  44. typedef struct debug_info {
  45. struct debug_info* next;
  46. struct debug_info* prev;
  47. atomic_t ref_count;
  48. spinlock_t lock;
  49. int level;
  50. int nr_areas;
  51. int pages_per_area;
  52. int buf_size;
  53. int entry_size;
  54. debug_entry_t*** areas;
  55. int active_area;
  56. int *active_pages;
  57. int *active_entries;
  58. struct dentry* debugfs_root_entry;
  59. struct dentry* debugfs_entries[DEBUG_MAX_VIEWS];
  60. struct debug_view* views[DEBUG_MAX_VIEWS];
  61. char name[DEBUG_MAX_NAME_LEN];
  62. } debug_info_t;
  63. typedef int (debug_header_proc_t) (debug_info_t* id,
  64. struct debug_view* view,
  65. int area,
  66. debug_entry_t* entry,
  67. char* out_buf);
  68. typedef int (debug_format_proc_t) (debug_info_t* id,
  69. struct debug_view* view, char* out_buf,
  70. const char* in_buf);
  71. typedef int (debug_prolog_proc_t) (debug_info_t* id,
  72. struct debug_view* view,
  73. char* out_buf);
  74. typedef int (debug_input_proc_t) (debug_info_t* id,
  75. struct debug_view* view,
  76. struct file* file,
  77. const char __user *user_buf,
  78. size_t in_buf_size, loff_t* offset);
  79. int debug_dflt_header_fn(debug_info_t* id, struct debug_view* view,
  80. int area, debug_entry_t* entry, char* out_buf);
  81. struct debug_view {
  82. char name[DEBUG_MAX_NAME_LEN];
  83. debug_prolog_proc_t* prolog_proc;
  84. debug_header_proc_t* header_proc;
  85. debug_format_proc_t* format_proc;
  86. debug_input_proc_t* input_proc;
  87. void* private_data;
  88. };
  89. extern struct debug_view debug_hex_ascii_view;
  90. extern struct debug_view debug_raw_view;
  91. extern struct debug_view debug_sprintf_view;
  92. /* do NOT use the _common functions */
  93. debug_entry_t* debug_event_common(debug_info_t* id, int level,
  94. const void* data, int length);
  95. debug_entry_t* debug_exception_common(debug_info_t* id, int level,
  96. const void* data, int length);
  97. /* Debug Feature API: */
  98. debug_info_t* debug_register(char* name, int pages, int nr_areas,
  99. int buf_size);
  100. void debug_unregister(debug_info_t* id);
  101. void debug_set_level(debug_info_t* id, int new_level);
  102. void debug_stop_all(void);
  103. static inline debug_entry_t*
  104. debug_event(debug_info_t* id, int level, void* data, int length)
  105. {
  106. if ((!id) || (level > id->level) || (id->pages_per_area == 0))
  107. return NULL;
  108. return debug_event_common(id,level,data,length);
  109. }
  110. static inline debug_entry_t*
  111. debug_int_event(debug_info_t* id, int level, unsigned int tag)
  112. {
  113. unsigned int t=tag;
  114. if ((!id) || (level > id->level) || (id->pages_per_area == 0))
  115. return NULL;
  116. return debug_event_common(id,level,&t,sizeof(unsigned int));
  117. }
  118. static inline debug_entry_t *
  119. debug_long_event (debug_info_t* id, int level, unsigned long tag)
  120. {
  121. unsigned long t=tag;
  122. if ((!id) || (level > id->level) || (id->pages_per_area == 0))
  123. return NULL;
  124. return debug_event_common(id,level,&t,sizeof(unsigned long));
  125. }
  126. static inline debug_entry_t*
  127. debug_text_event(debug_info_t* id, int level, const char* txt)
  128. {
  129. if ((!id) || (level > id->level) || (id->pages_per_area == 0))
  130. return NULL;
  131. return debug_event_common(id,level,txt,strlen(txt));
  132. }
  133. extern debug_entry_t *
  134. debug_sprintf_event(debug_info_t* id,int level,char *string,...)
  135. __attribute__ ((format(printf, 3, 4)));
  136. static inline debug_entry_t*
  137. debug_exception(debug_info_t* id, int level, void* data, int length)
  138. {
  139. if ((!id) || (level > id->level) || (id->pages_per_area == 0))
  140. return NULL;
  141. return debug_exception_common(id,level,data,length);
  142. }
  143. static inline debug_entry_t*
  144. debug_int_exception(debug_info_t* id, int level, unsigned int tag)
  145. {
  146. unsigned int t=tag;
  147. if ((!id) || (level > id->level) || (id->pages_per_area == 0))
  148. return NULL;
  149. return debug_exception_common(id,level,&t,sizeof(unsigned int));
  150. }
  151. static inline debug_entry_t *
  152. debug_long_exception (debug_info_t* id, int level, unsigned long tag)
  153. {
  154. unsigned long t=tag;
  155. if ((!id) || (level > id->level) || (id->pages_per_area == 0))
  156. return NULL;
  157. return debug_exception_common(id,level,&t,sizeof(unsigned long));
  158. }
  159. static inline debug_entry_t*
  160. debug_text_exception(debug_info_t* id, int level, const char* txt)
  161. {
  162. if ((!id) || (level > id->level) || (id->pages_per_area == 0))
  163. return NULL;
  164. return debug_exception_common(id,level,txt,strlen(txt));
  165. }
  166. extern debug_entry_t *
  167. debug_sprintf_exception(debug_info_t* id,int level,char *string,...)
  168. __attribute__ ((format(printf, 3, 4)));
  169. int debug_register_view(debug_info_t* id, struct debug_view* view);
  170. int debug_unregister_view(debug_info_t* id, struct debug_view* view);
  171. /*
  172. define the debug levels:
  173. - 0 No debugging output to console or syslog
  174. - 1 Log internal errors to syslog, ignore check conditions
  175. - 2 Log internal errors and check conditions to syslog
  176. - 3 Log internal errors to console, log check conditions to syslog
  177. - 4 Log internal errors and check conditions to console
  178. - 5 panic on internal errors, log check conditions to console
  179. - 6 panic on both, internal errors and check conditions
  180. */
  181. #ifndef DEBUG_LEVEL
  182. #define DEBUG_LEVEL 4
  183. #endif
  184. #define INTERNAL_ERRMSG(x,y...) "E" __FILE__ "%d: " x, __LINE__, y
  185. #define INTERNAL_WRNMSG(x,y...) "W" __FILE__ "%d: " x, __LINE__, y
  186. #define INTERNAL_INFMSG(x,y...) "I" __FILE__ "%d: " x, __LINE__, y
  187. #define INTERNAL_DEBMSG(x,y...) "D" __FILE__ "%d: " x, __LINE__, y
  188. #if DEBUG_LEVEL > 0
  189. #define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
  190. #define PRINT_INFO(x...) printk ( KERN_INFO PRINTK_HEADER x )
  191. #define PRINT_WARN(x...) printk ( KERN_WARNING PRINTK_HEADER x )
  192. #define PRINT_ERR(x...) printk ( KERN_ERR PRINTK_HEADER x )
  193. #define PRINT_FATAL(x...) panic ( PRINTK_HEADER x )
  194. #else
  195. #define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
  196. #define PRINT_INFO(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
  197. #define PRINT_WARN(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
  198. #define PRINT_ERR(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
  199. #define PRINT_FATAL(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
  200. #endif /* DASD_DEBUG */
  201. #undef DEBUG_MALLOC
  202. #ifdef DEBUG_MALLOC
  203. void *b;
  204. #define kmalloc(x...) (PRINT_INFO(" kmalloc %p\n",b=kmalloc(x)),b)
  205. #define kfree(x) PRINT_INFO(" kfree %p\n",x);kfree(x)
  206. #define get_zeroed_page(x...) (PRINT_INFO(" gfp %p\n",b=get_zeroed_page(x)),b)
  207. #define __get_free_pages(x...) (PRINT_INFO(" gfps %p\n",b=__get_free_pages(x)),b)
  208. #endif /* DEBUG_MALLOC */
  209. #endif /* __KERNEL__ */
  210. #endif /* DEBUG_H */