debug.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. #define STCK(x) asm volatile ("STCK 0(%1)" : "=m" (x) : "a" (&(x)) : "cc")
  44. typedef struct __debug_entry debug_entry_t;
  45. struct debug_view;
  46. typedef struct debug_info {
  47. struct debug_info* next;
  48. struct debug_info* prev;
  49. atomic_t ref_count;
  50. spinlock_t lock;
  51. int level;
  52. int nr_areas;
  53. int pages_per_area;
  54. int buf_size;
  55. int entry_size;
  56. debug_entry_t*** areas;
  57. int active_area;
  58. int *active_pages;
  59. int *active_entries;
  60. struct dentry* debugfs_root_entry;
  61. struct dentry* debugfs_entries[DEBUG_MAX_VIEWS];
  62. struct debug_view* views[DEBUG_MAX_VIEWS];
  63. char name[DEBUG_MAX_NAME_LEN];
  64. } debug_info_t;
  65. typedef int (debug_header_proc_t) (debug_info_t* id,
  66. struct debug_view* view,
  67. int area,
  68. debug_entry_t* entry,
  69. char* out_buf);
  70. typedef int (debug_format_proc_t) (debug_info_t* id,
  71. struct debug_view* view, char* out_buf,
  72. const char* in_buf);
  73. typedef int (debug_prolog_proc_t) (debug_info_t* id,
  74. struct debug_view* view,
  75. char* out_buf);
  76. typedef int (debug_input_proc_t) (debug_info_t* id,
  77. struct debug_view* view,
  78. struct file* file,
  79. const char __user *user_buf,
  80. size_t in_buf_size, loff_t* offset);
  81. int debug_dflt_header_fn(debug_info_t* id, struct debug_view* view,
  82. int area, debug_entry_t* entry, char* out_buf);
  83. struct debug_view {
  84. char name[DEBUG_MAX_NAME_LEN];
  85. debug_prolog_proc_t* prolog_proc;
  86. debug_header_proc_t* header_proc;
  87. debug_format_proc_t* format_proc;
  88. debug_input_proc_t* input_proc;
  89. void* private_data;
  90. };
  91. extern struct debug_view debug_hex_ascii_view;
  92. extern struct debug_view debug_raw_view;
  93. extern struct debug_view debug_sprintf_view;
  94. /* do NOT use the _common functions */
  95. debug_entry_t* debug_event_common(debug_info_t* id, int level,
  96. const void* data, int length);
  97. debug_entry_t* debug_exception_common(debug_info_t* id, int level,
  98. const void* data, int length);
  99. /* Debug Feature API: */
  100. debug_info_t* debug_register(char* name, int pages, int nr_areas,
  101. int buf_size);
  102. void debug_unregister(debug_info_t* id);
  103. void debug_set_level(debug_info_t* id, int new_level);
  104. void debug_stop_all(void);
  105. extern inline debug_entry_t*
  106. debug_event(debug_info_t* id, int level, void* data, int length)
  107. {
  108. if ((!id) || (level > id->level) || (id->pages_per_area == 0))
  109. return NULL;
  110. return debug_event_common(id,level,data,length);
  111. }
  112. extern inline debug_entry_t*
  113. debug_int_event(debug_info_t* id, int level, unsigned int tag)
  114. {
  115. unsigned int t=tag;
  116. if ((!id) || (level > id->level) || (id->pages_per_area == 0))
  117. return NULL;
  118. return debug_event_common(id,level,&t,sizeof(unsigned int));
  119. }
  120. extern inline debug_entry_t *
  121. debug_long_event (debug_info_t* id, int level, unsigned long tag)
  122. {
  123. unsigned long t=tag;
  124. if ((!id) || (level > id->level) || (id->pages_per_area == 0))
  125. return NULL;
  126. return debug_event_common(id,level,&t,sizeof(unsigned long));
  127. }
  128. extern inline debug_entry_t*
  129. debug_text_event(debug_info_t* id, int level, const char* txt)
  130. {
  131. if ((!id) || (level > id->level) || (id->pages_per_area == 0))
  132. return NULL;
  133. return debug_event_common(id,level,txt,strlen(txt));
  134. }
  135. extern debug_entry_t *
  136. debug_sprintf_event(debug_info_t* id,int level,char *string,...)
  137. __attribute__ ((format(printf, 3, 4)));
  138. extern inline debug_entry_t*
  139. debug_exception(debug_info_t* id, int level, void* data, int length)
  140. {
  141. if ((!id) || (level > id->level) || (id->pages_per_area == 0))
  142. return NULL;
  143. return debug_exception_common(id,level,data,length);
  144. }
  145. extern inline debug_entry_t*
  146. debug_int_exception(debug_info_t* id, int level, unsigned int tag)
  147. {
  148. unsigned int t=tag;
  149. if ((!id) || (level > id->level) || (id->pages_per_area == 0))
  150. return NULL;
  151. return debug_exception_common(id,level,&t,sizeof(unsigned int));
  152. }
  153. extern inline debug_entry_t *
  154. debug_long_exception (debug_info_t* id, int level, unsigned long tag)
  155. {
  156. unsigned long t=tag;
  157. if ((!id) || (level > id->level) || (id->pages_per_area == 0))
  158. return NULL;
  159. return debug_exception_common(id,level,&t,sizeof(unsigned long));
  160. }
  161. extern inline debug_entry_t*
  162. debug_text_exception(debug_info_t* id, int level, const char* txt)
  163. {
  164. if ((!id) || (level > id->level) || (id->pages_per_area == 0))
  165. return NULL;
  166. return debug_exception_common(id,level,txt,strlen(txt));
  167. }
  168. extern debug_entry_t *
  169. debug_sprintf_exception(debug_info_t* id,int level,char *string,...)
  170. __attribute__ ((format(printf, 3, 4)));
  171. int debug_register_view(debug_info_t* id, struct debug_view* view);
  172. int debug_unregister_view(debug_info_t* id, struct debug_view* view);
  173. /*
  174. define the debug levels:
  175. - 0 No debugging output to console or syslog
  176. - 1 Log internal errors to syslog, ignore check conditions
  177. - 2 Log internal errors and check conditions to syslog
  178. - 3 Log internal errors to console, log check conditions to syslog
  179. - 4 Log internal errors and check conditions to console
  180. - 5 panic on internal errors, log check conditions to console
  181. - 6 panic on both, internal errors and check conditions
  182. */
  183. #ifndef DEBUG_LEVEL
  184. #define DEBUG_LEVEL 4
  185. #endif
  186. #define INTERNAL_ERRMSG(x,y...) "E" __FILE__ "%d: " x, __LINE__, y
  187. #define INTERNAL_WRNMSG(x,y...) "W" __FILE__ "%d: " x, __LINE__, y
  188. #define INTERNAL_INFMSG(x,y...) "I" __FILE__ "%d: " x, __LINE__, y
  189. #define INTERNAL_DEBMSG(x,y...) "D" __FILE__ "%d: " x, __LINE__, y
  190. #if DEBUG_LEVEL > 0
  191. #define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
  192. #define PRINT_INFO(x...) printk ( KERN_INFO PRINTK_HEADER x )
  193. #define PRINT_WARN(x...) printk ( KERN_WARNING PRINTK_HEADER x )
  194. #define PRINT_ERR(x...) printk ( KERN_ERR PRINTK_HEADER x )
  195. #define PRINT_FATAL(x...) panic ( PRINTK_HEADER x )
  196. #else
  197. #define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
  198. #define PRINT_INFO(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
  199. #define PRINT_WARN(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
  200. #define PRINT_ERR(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
  201. #define PRINT_FATAL(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
  202. #endif /* DASD_DEBUG */
  203. #undef DEBUG_MALLOC
  204. #ifdef DEBUG_MALLOC
  205. void *b;
  206. #define kmalloc(x...) (PRINT_INFO(" kmalloc %p\n",b=kmalloc(x)),b)
  207. #define kfree(x) PRINT_INFO(" kfree %p\n",x);kfree(x)
  208. #define get_zeroed_page(x...) (PRINT_INFO(" gfp %p\n",b=get_zeroed_page(x)),b)
  209. #define __get_free_pages(x...) (PRINT_INFO(" gfps %p\n",b=__get_free_pages(x)),b)
  210. #endif /* DEBUG_MALLOC */
  211. #endif /* __KERNEL__ */
  212. #endif /* DEBUG_H */