Commit /bin/cc.exe (a hardlink of /bin/gcc.exe)
[msysgit.git] / include / sys / strace.h
blobe4954eb164ab3bbb4ddb50a7052c5423225e6e29
1 /* sys/strace.h
3 Copyright 1996, 1997, 1998, 1999, 2000, 2001 Red Hat, Inc.
5 This file is part of Cygwin.
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. */
11 /* sys/strace.h */
13 /* This file contains routines for tracing system calls and other internal
14 phenomenon.
16 When tracing system calls, try to use the same style throughout:
18 result = syscall (arg1, arg2, arg3) [optional extra stuff]
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.
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.
29 #ifndef _SYS_STRACE_H
30 #define _SYS_STRACE_H
32 #include <stdarg.h>
34 #ifdef __cplusplus
36 class strace
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 strace() : version(1) {}
47 void prntf (unsigned, const char *func, const char *, ...) /*__attribute__ ((regparm(3)))*/;
48 void vprntf (unsigned, const char *func, const char *, va_list ap) /*__attribute__ ((regparm(3)))*/;
49 void wm (int message, int word, int lon) __attribute__ ((regparm(3)));
52 extern strace strace;
54 #endif /* __cplusplus */
56 #define _STRACE_INTERFACE_ACTIVATE_ADDR -1
57 #define _STRACE_INTERFACE_ACTIVATE_ADDR1 -2
59 /* Bitmasks of tracing messages to print. */
61 #define _STRACE_ALL 0x00001 // so behaviour of strace=1 is unchanged
62 #define _STRACE_FLUSH 0x00002 // flush output buffer after every message
63 #define _STRACE_INHERIT 0x00004 // children inherit mask from parent
64 #define _STRACE_UHOH 0x00008 // unusual or weird phenomenon
65 #define _STRACE_SYSCALL 0x00010 // system calls
66 #define _STRACE_STARTUP 0x00020 // argc/envp printout at startup
67 #define _STRACE_DEBUG 0x00040 // info to help debugging
68 #define _STRACE_PARANOID 0x00080 // paranoid info
69 #define _STRACE_TERMIOS 0x00100 // info for debugging termios stuff
70 #define _STRACE_SELECT 0x00200 // info on ugly select internals
71 #define _STRACE_WM 0x00400 // trace windows messages (enable _strace_wm)
72 #define _STRACE_SIGP 0x00800 // trace signal and process handling
73 #define _STRACE_MINIMAL 0x01000 // very minimal strace output
74 #define _STRACE_EXITDUMP 0x04000 // dump strace cache on exit
75 #define _STRACE_SYSTEM 0x08000 // cache strace messages
76 #define _STRACE_NOMUTEX 0x10000 // don't use mutex for synchronization
77 #define _STRACE_MALLOC 0x20000 // trace malloc calls
78 #define _STRACE_THREAD 0x40000 // thread-locking calls
79 #define _STRACE_NOTALL 0x80000 // don't include if _STRACE_ALL
80 #if defined (DEBUGGING)
81 #define _STRACE_ON strace.active = 1;
82 #define _STRACE_OFF strace.active = 0;
83 #else
84 #define _STRACE_ON
85 #define _STRACE_OFF
86 #endif
88 #ifdef __cplusplus
89 extern "C" {
90 #endif
92 void small_printf (const char *, ...);
93 void strace_printf (unsigned, const char *func, const char *, ...);
95 #ifdef __cplusplus
97 #endif
99 #ifdef __cplusplus
101 #ifdef NOSTRACE
102 #define define_strace(c, f)
103 #define define_strace1(c, f)
104 #else
105 #ifdef NEW_MACRO_VARARGS
106 /* Output message to strace log */
108 #define define_strace0(c,...) \
109 do { \
110 if ((c & _STRACE_SYSTEM) || strace.active) \
111 strace.prntf (c, __PRETTY_FUNCTION__, __VA_ARGS__); \
113 while (0)
115 #define define_strace(c, ...) define_strace0 (_STRACE_ ## c, __VA_ARGS__)
116 #define define_strace1(c, ...) define_strace0 ((_STRACE_ ## c | _STRACE_NOTALL), __VA_ARGS__)
118 #define debug_printf(...) define_strace (DEBUG, __VA_ARGS__)
119 #define paranoid_printf(...) define_strace (PARANOID, __VA_ARGS__)
120 #define select_printf(...) define_strace (SELECT, __VA_ARGS__)
121 #define sigproc_printf(...) define_strace (SIGP, __VA_ARGS__)
122 #define syscall_printf(...) define_strace (SYSCALL, __VA_ARGS__)
123 #define system_printf(...) define_strace (SYSTEM, __VA_ARGS__)
124 #define termios_printf(...) define_strace (TERMIOS, __VA_ARGS__)
125 #define wm_printf(...) define_strace (WM, __VA_ARGS__)
126 #define minimal_printf(...) define_strace1 (MINIMAL, __VA_ARGS__)
127 #define malloc_printf(...) define_strace1 (MALLOC, __VA_ARGS__)
128 #define thread_printf(...) define_strace1 (THREAD, __VA_ARGS__)
129 #else
130 #define strace_printf_wrap(what, fmt, args...) \
131 ((void) ({\
132 if ((_STRACE_ ## what & _STRACE_SYSTEM) || strace.active) \
133 strace.prntf(_STRACE_ ## what, __PRETTY_FUNCTION__, fmt, ## args); \
134 0; \
136 #define strace_printf_wrap1(what, fmt, args...) \
137 ((void) ({\
138 if ((_STRACE_ ## what & _STRACE_SYSTEM) || strace.active) \
139 strace.prntf((_STRACE_ ## what) | _STRACE_NOTALL, __PRETTY_FUNCTION__, fmt, ## args); \
140 0; \
143 #define debug_printf(fmt, args...) strace_printf_wrap(DEBUG, fmt , ## args)
144 #if defined (DEBUGGING)
145 #define mdebug(mdebug_active, mdebug_function, mdebug_string) \
146 do { \
147 char mdebug_buf[2048]; \
148 sprintf (mdebug_buf, "%s [%d]: %s", mdebug_function, mdebug_active, mdebug_string); \
149 OutputDebugString (mdebug_buf); \
151 while (0)
152 #else
153 #define mdebug(mdebug_active, mdebug_function, mdebug_string)
154 #endif
155 #define paranoid_printf(fmt, args...) strace_printf_wrap(PARANOID, fmt , ## args)
156 #define select_printf(fmt, args...) strace_printf_wrap(SELECT, fmt , ## args)
157 #define sigproc_printf(fmt, args...) strace_printf_wrap(SIGP, fmt , ## args)
158 #define syscall_printf(fmt, args...) strace_printf_wrap(SYSCALL, fmt , ## args)
159 #define system_printf(fmt, args...) strace_printf_wrap(SYSTEM, fmt , ## args)
160 #define termios_printf(fmt, args...) strace_printf_wrap(TERMIOS, fmt , ## args)
161 #define wm_printf(fmt, args...) strace_printf_wrap(WM, fmt , ## args)
162 #define minimal_printf(fmt, args...) strace_printf_wrap1(MINIMAL, fmt , ## args)
163 #define malloc_printf(fmt, args...) strace_printf_wrap1(MALLOC, fmt , ## args)
164 #define thread_printf(fmt, args...) strace_printf_wrap1(THREAD, fmt , ## args)
165 #endif /*NEW_MACRO_VARARGS*/
166 #endif /*NOSTRACE*/
167 #endif /* __cplusplus */
168 #endif /* _SYS_STRACE_H */