debug.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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/string.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 1 /* version of debug feature */
  28. #ifdef __KERNEL__
  29. #include <linux/spinlock.h>
  30. #include <linux/kernel.h>
  31. #include <linux/time.h>
  32. #include <linux/proc_fs.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_PROCF_LEN 64 /* max length for a proc 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. #define STCK(x) asm volatile ("STCK 0(%1)" : "=m" (x) : "a" (&(x)) : "cc")
  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 page_order;
  53. int buf_size;
  54. int entry_size;
  55. debug_entry_t** areas;
  56. int active_area;
  57. int *active_entry;
  58. struct proc_dir_entry* proc_root_entry;
  59. struct proc_dir_entry* proc_entries[DEBUG_MAX_VIEWS];
  60. struct debug_view* views[DEBUG_MAX_VIEWS];
  61. char name[DEBUG_MAX_PROCF_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_PROCF_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_index, 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. extern inline debug_entry_t*
  104. debug_event(debug_info_t* id, int level, void* data, int length)
  105. {
  106. if ((!id) || (level > id->level)) return NULL;
  107. return debug_event_common(id,level,data,length);
  108. }
  109. extern inline debug_entry_t*
  110. debug_int_event(debug_info_t* id, int level, unsigned int tag)
  111. {
  112. unsigned int t=tag;
  113. if ((!id) || (level > id->level)) return NULL;
  114. return debug_event_common(id,level,&t,sizeof(unsigned int));
  115. }
  116. extern inline debug_entry_t *
  117. debug_long_event (debug_info_t* id, int level, unsigned long tag)
  118. {
  119. unsigned long t=tag;
  120. if ((!id) || (level > id->level)) return NULL;
  121. return debug_event_common(id,level,&t,sizeof(unsigned long));
  122. }
  123. extern inline debug_entry_t*
  124. debug_text_event(debug_info_t* id, int level, const char* txt)
  125. {
  126. if ((!id) || (level > id->level)) return NULL;
  127. return debug_event_common(id,level,txt,strlen(txt));
  128. }
  129. extern debug_entry_t *
  130. debug_sprintf_event(debug_info_t* id,int level,char *string,...)
  131. __attribute__ ((format(printf, 3, 4)));
  132. extern inline debug_entry_t*
  133. debug_exception(debug_info_t* id, int level, void* data, int length)
  134. {
  135. if ((!id) || (level > id->level)) return NULL;
  136. return debug_exception_common(id,level,data,length);
  137. }
  138. extern inline debug_entry_t*
  139. debug_int_exception(debug_info_t* id, int level, unsigned int tag)
  140. {
  141. unsigned int t=tag;
  142. if ((!id) || (level > id->level)) return NULL;
  143. return debug_exception_common(id,level,&t,sizeof(unsigned int));
  144. }
  145. extern inline debug_entry_t *
  146. debug_long_exception (debug_info_t* id, int level, unsigned long tag)
  147. {
  148. unsigned long t=tag;
  149. if ((!id) || (level > id->level)) return NULL;
  150. return debug_exception_common(id,level,&t,sizeof(unsigned long));
  151. }
  152. extern inline debug_entry_t*
  153. debug_text_exception(debug_info_t* id, int level, const char* txt)
  154. {
  155. if ((!id) || (level > id->level)) return NULL;
  156. return debug_exception_common(id,level,txt,strlen(txt));
  157. }
  158. extern debug_entry_t *
  159. debug_sprintf_exception(debug_info_t* id,int level,char *string,...)
  160. __attribute__ ((format(printf, 3, 4)));
  161. int debug_register_view(debug_info_t* id, struct debug_view* view);
  162. int debug_unregister_view(debug_info_t* id, struct debug_view* view);
  163. /*
  164. define the debug levels:
  165. - 0 No debugging output to console or syslog
  166. - 1 Log internal errors to syslog, ignore check conditions
  167. - 2 Log internal errors and check conditions to syslog
  168. - 3 Log internal errors to console, log check conditions to syslog
  169. - 4 Log internal errors and check conditions to console
  170. - 5 panic on internal errors, log check conditions to console
  171. - 6 panic on both, internal errors and check conditions
  172. */
  173. #ifndef DEBUG_LEVEL
  174. #define DEBUG_LEVEL 4
  175. #endif
  176. #define INTERNAL_ERRMSG(x,y...) "E" __FILE__ "%d: " x, __LINE__, y
  177. #define INTERNAL_WRNMSG(x,y...) "W" __FILE__ "%d: " x, __LINE__, y
  178. #define INTERNAL_INFMSG(x,y...) "I" __FILE__ "%d: " x, __LINE__, y
  179. #define INTERNAL_DEBMSG(x,y...) "D" __FILE__ "%d: " x, __LINE__, y
  180. #if DEBUG_LEVEL > 0
  181. #define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
  182. #define PRINT_INFO(x...) printk ( KERN_INFO PRINTK_HEADER x )
  183. #define PRINT_WARN(x...) printk ( KERN_WARNING PRINTK_HEADER x )
  184. #define PRINT_ERR(x...) printk ( KERN_ERR PRINTK_HEADER x )
  185. #define PRINT_FATAL(x...) panic ( PRINTK_HEADER x )
  186. #else
  187. #define PRINT_DEBUG(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
  188. #define PRINT_INFO(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
  189. #define PRINT_WARN(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
  190. #define PRINT_ERR(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
  191. #define PRINT_FATAL(x...) printk ( KERN_DEBUG PRINTK_HEADER x )
  192. #endif /* DASD_DEBUG */
  193. #undef DEBUG_MALLOC
  194. #ifdef DEBUG_MALLOC
  195. void *b;
  196. #define kmalloc(x...) (PRINT_INFO(" kmalloc %p\n",b=kmalloc(x)),b)
  197. #define kfree(x) PRINT_INFO(" kfree %p\n",x);kfree(x)
  198. #define get_zeroed_page(x...) (PRINT_INFO(" gfp %p\n",b=get_zeroed_page(x)),b)
  199. #define __get_free_pages(x...) (PRINT_INFO(" gfps %p\n",b=__get_free_pages(x)),b)
  200. #endif /* DEBUG_MALLOC */
  201. #endif /* __KERNEL__ */
  202. #endif /* DEBUG_H */