debug.h 8.0 KB

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