home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 June / PCWorld_2005-06_cd.bin / software / vyzkuste / firewally / firewally.exe / framework-2.3.exe / strace.h < prev    next >
C/C++ Source or Header  |  2004-01-30  |  6KB  |  159 lines

  1. /* sys/strace.h
  2.  
  3.    Copyright 1996, 1997, 1998, 1999, 2000, 2001 Red Hat, Inc.
  4.  
  5. This file is part of Cygwin.
  6.  
  7. This software is a copyrighted work licensed under the terms of the
  8. Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
  9. details. */
  10.  
  11. /* sys/strace.h */
  12.  
  13. /* This file contains routines for tracing system calls and other internal
  14.    phenomenon.
  15.  
  16.    When tracing system calls, try to use the same style throughout:
  17.  
  18.    result = syscall (arg1, arg2, arg3) [optional extra stuff]
  19.  
  20.    If a system call can block (eg: read, write, wait), print another message
  21.    before hanging so the user will know why the program has stopped.
  22.  
  23.    Note: __seterrno will also print a trace message.  Have that printed
  24.    *first*.  This will make it easy to always know what __seterrno is
  25.    refering to.  For the same reason, try not to have __seterrno messages
  26.    printed alone.
  27. */
  28.  
  29. #ifndef _SYS_STRACE_H
  30. #define _SYS_STRACE_H
  31.  
  32. #include <stdarg.h>
  33.  
  34. #ifdef __cplusplus
  35.  
  36. class strace
  37. {
  38.   int vsprntf (char *buf, const char *func, const char *infmt, va_list ap);
  39.   void write (unsigned category, const char *buf, int count);
  40. public:
  41.   int microseconds ();
  42.   int version;
  43.   int active;
  44.   int lmicrosec;
  45.   int execing;
  46.   int inited;
  47.   void hello ();
  48.   void prntf (unsigned, const char *func, const char *, ...) /*__attribute__ ((regparm(3)))*/;
  49.   void vprntf (unsigned, const char *func, const char *, va_list ap) /*__attribute__ ((regparm(3)))*/;
  50.   void wm (int message, int word, int lon) __attribute__ ((regparm(3)));
  51. };
  52.  
  53. extern strace strace;
  54.  
  55. #endif /* __cplusplus */
  56.  
  57. #define _STRACE_INTERFACE_ACTIVATE_ADDR  -1
  58. #define _STRACE_INTERFACE_ACTIVATE_ADDR1 -2
  59.  
  60. /* Bitmasks of tracing messages to print.  */
  61.  
  62. #define _STRACE_ALL     0x00001 // so behaviour of strace=1 is unchanged
  63. #define _STRACE_FLUSH     0x00002 // flush output buffer after every message
  64. #define _STRACE_INHERIT  0x00004 // children inherit mask from parent
  65. #define _STRACE_UHOH     0x00008 // unusual or weird phenomenon
  66. #define _STRACE_SYSCALL     0x00010 // system calls
  67. #define _STRACE_STARTUP     0x00020 // argc/envp printout at startup
  68. #define _STRACE_DEBUG    0x00040 // info to help debugging
  69. #define _STRACE_PARANOID 0x00080 // paranoid info
  70. #define _STRACE_TERMIOS     0x00100 // info for debugging termios stuff
  71. #define _STRACE_SELECT     0x00200 // info on ugly select internals
  72. #define _STRACE_WM     0x00400 // trace windows messages (enable _strace_wm)
  73. #define _STRACE_SIGP     0x00800 // trace signal and process handling
  74. #define _STRACE_MINIMAL     0x01000 // very minimal strace output
  75. #define _STRACE_EXITDUMP 0x04000 // dump strace cache on exit
  76. #define _STRACE_SYSTEM     0x08000 // cache strace messages
  77. #define _STRACE_NOMUTEX     0x10000 // don't use mutex for synchronization
  78. #define _STRACE_MALLOC     0x20000 // trace malloc calls
  79. #define _STRACE_THREAD     0x40000 // thread-locking calls
  80. #define _STRACE_NOTALL     0x80000 // don't include if _STRACE_ALL
  81. #if defined (DEBUGGING)
  82. # define _STRACE_ON strace.active = 1;
  83. # define _STRACE_OFF strace.active = 0;
  84. #else
  85. # define _STRACE_ON
  86. # define _STRACE_OFF
  87. #endif
  88.  
  89. #ifdef __cplusplus
  90. extern "C" {
  91. #endif
  92.  
  93. void small_printf (const char *, ...);
  94. void strace_printf (unsigned, const char *func, const char *, ...);
  95.  
  96. #ifdef __cplusplus
  97. }
  98. #endif
  99.  
  100. #ifdef __cplusplus
  101.  
  102. #ifdef NOSTRACE
  103. #define define_strace(c, f)
  104. #define define_strace1(c, f)
  105. #else
  106. #ifdef NEW_MACRO_VARARGS
  107. /* Output message to strace log */
  108.  
  109. #define define_strace0(c,...) \
  110.   do { \
  111.       if ((c & _STRACE_SYSTEM) || strace.active) \
  112.     strace.prntf (c, __PRETTY_FUNCTION__, __VA_ARGS__); \
  113.     } \
  114.   while (0)
  115.  
  116. #define define_strace(c, ...) define_strace0 (_STRACE_ ## c, __VA_ARGS__)
  117. #define define_strace1(c, ...) define_strace0 ((_STRACE_ ## c | _STRACE_NOTALL), __VA_ARGS__)
  118.  
  119. #define debug_printf(...)    define_strace (DEBUG, __VA_ARGS__)
  120. #define paranoid_printf(...)    define_strace (PARANOID, __VA_ARGS__)
  121. #define select_printf(...)    define_strace (SELECT, __VA_ARGS__)
  122. #define sigproc_printf(...)    define_strace (SIGP, __VA_ARGS__)
  123. #define syscall_printf(...)    define_strace (SYSCALL, __VA_ARGS__)
  124. #define system_printf(...)    define_strace (SYSTEM, __VA_ARGS__)
  125. #define termios_printf(...)    define_strace (TERMIOS, __VA_ARGS__)
  126. #define wm_printf(...)        define_strace (WM, __VA_ARGS__)
  127. #define minimal_printf(...)    define_strace1 (MINIMAL, __VA_ARGS__)
  128. #define malloc_printf(...)    define_strace1 (MALLOC, __VA_ARGS__)
  129. #define thread_printf(...)    define_strace1 (THREAD, __VA_ARGS__)
  130. #else
  131. #define strace_printf_wrap(what, fmt, args...) \
  132.    ((void) ({\
  133.     if ((_STRACE_ ## what & _STRACE_SYSTEM) || strace.active) \
  134.       strace.prntf(_STRACE_ ## what, __PRETTY_FUNCTION__, fmt, ## args); \
  135.     0; \
  136.     }))
  137. #define strace_printf_wrap1(what, fmt, args...) \
  138.     ((void) ({\
  139.     if ((_STRACE_ ## what & _STRACE_SYSTEM) || strace.active) \
  140.       strace.prntf((_STRACE_ ## what) | _STRACE_NOTALL, __PRETTY_FUNCTION__, fmt, ## args); \
  141.     0; \
  142.     }))
  143.  
  144. #define debug_printf(fmt, args...) strace_printf_wrap(DEBUG, fmt , ## args)
  145. #define paranoid_printf(fmt, args...) strace_printf_wrap1(PARANOID, fmt , ## args)
  146. #define select_printf(fmt, args...) strace_printf_wrap(SELECT, fmt , ## args)
  147. #define sigproc_printf(fmt, args...) strace_printf_wrap(SIGP, fmt , ## args)
  148. #define syscall_printf(fmt, args...) strace_printf_wrap(SYSCALL, fmt , ## args)
  149. #define system_printf(fmt, args...) strace_printf_wrap(SYSTEM, fmt , ## args)
  150. #define termios_printf(fmt, args...) strace_printf_wrap(TERMIOS, fmt , ## args)
  151. #define wm_printf(fmt, args...) strace_printf_wrap(WM, fmt , ## args)
  152. #define minimal_printf(fmt, args...) strace_printf_wrap1(MINIMAL, fmt , ## args)
  153. #define malloc_printf(fmt, args...) strace_printf_wrap1(MALLOC, fmt , ## args)
  154. #define thread_printf(fmt, args...) strace_printf_wrap1(THREAD, fmt , ## args)
  155. #endif /*NEW_MACRO_VARARGS*/
  156. #endif /*NOSTRACE*/
  157. #endif /* __cplusplus */
  158. #endif /* _SYS_STRACE_H */
  159.