2001-03-06 05:29:24 +08:00
|
|
|
/* sys/strace.h
|
|
|
|
|
2013-01-21 12:38:31 +08:00
|
|
|
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2008,
|
|
|
|
2010, 2011 Red Hat, Inc.
|
2001-03-06 05:29:24 +08:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* This file contains routines for tracing system calls and other internal
|
|
|
|
phenomenon.
|
|
|
|
|
|
|
|
When tracing system calls, try to use the same style throughout:
|
|
|
|
|
|
|
|
result = syscall (arg1, arg2, arg3) [optional extra stuff]
|
|
|
|
|
|
|
|
If a system call can block (eg: read, write, wait), print another message
|
|
|
|
before hanging so the user will know why the program has stopped.
|
|
|
|
|
|
|
|
Note: __seterrno will also print a trace message. Have that printed
|
|
|
|
*first*. This will make it easy to always know what __seterrno is
|
|
|
|
refering to. For the same reason, try not to have __seterrno messages
|
|
|
|
printed alone.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _SYS_STRACE_H
|
|
|
|
#define _SYS_STRACE_H
|
|
|
|
|
2000-03-07 13:33:09 +08:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2001-02-26 17:50:24 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
2005-12-30 04:46:34 +08:00
|
|
|
class child_info;
|
2000-03-07 13:33:09 +08:00
|
|
|
class strace
|
|
|
|
{
|
2000-08-03 03:26:01 +08:00
|
|
|
int vsprntf (char *buf, const char *func, const char *infmt, va_list ap);
|
2000-03-07 13:33:09 +08:00
|
|
|
void write (unsigned category, const char *buf, int count);
|
2005-12-30 04:46:34 +08:00
|
|
|
unsigned char _active;
|
2000-03-07 13:33:09 +08:00
|
|
|
public:
|
2011-11-24 10:17:55 +08:00
|
|
|
void activate (bool) __attribute__ ((regparm (2)));;
|
|
|
|
strace () {}
|
2000-10-17 07:55:58 +08:00
|
|
|
int microseconds ();
|
2000-03-07 13:33:09 +08:00
|
|
|
int version;
|
|
|
|
int lmicrosec;
|
2005-12-30 04:46:34 +08:00
|
|
|
bool execing;
|
2011-06-17 16:30:27 +08:00
|
|
|
void dll_info () __attribute__ ((regparm (1)));
|
2001-04-03 10:53:25 +08:00
|
|
|
void prntf (unsigned, const char *func, const char *, ...) /*__attribute__ ((regparm(3)))*/;
|
|
|
|
void vprntf (unsigned, const char *func, const char *, va_list ap) /*__attribute__ ((regparm(3)))*/;
|
|
|
|
void wm (int message, int word, int lon) __attribute__ ((regparm(3)));
|
2011-11-25 05:36:53 +08:00
|
|
|
void write_childpid (unsigned long) __attribute__ ((regparm (3)));
|
2005-12-30 04:46:34 +08:00
|
|
|
bool attached () const {return _active == 3;}
|
|
|
|
bool active () const {return _active & 1;}
|
|
|
|
unsigned char& active_val () {return _active;}
|
2000-03-07 13:33:09 +08:00
|
|
|
};
|
|
|
|
|
2000-08-02 11:42:31 +08:00
|
|
|
extern strace strace;
|
|
|
|
|
2001-02-26 17:50:24 +08:00
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2000-03-07 13:33:09 +08:00
|
|
|
#define _STRACE_INTERFACE_ACTIVATE_ADDR -1
|
|
|
|
#define _STRACE_INTERFACE_ACTIVATE_ADDR1 -2
|
2005-12-30 04:46:34 +08:00
|
|
|
#define _STRACE_CHILD_PID -3
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* Bitmasks of tracing messages to print. */
|
|
|
|
|
2010-02-23 04:36:04 +08:00
|
|
|
#define _STRACE_ALL 0x000001 // so behaviour of strace=1 is unchanged
|
|
|
|
#define _STRACE_FLUSH 0x000002 // flush output buffer after every message
|
|
|
|
#define _STRACE_INHERIT 0x000004 // children inherit mask from parent
|
|
|
|
#define _STRACE_UHOH 0x000008 // unusual or weird phenomenon
|
|
|
|
#define _STRACE_SYSCALL 0x000010 // system calls
|
|
|
|
#define _STRACE_STARTUP 0x000020 // argc/envp printout at startup
|
|
|
|
#define _STRACE_DEBUG 0x000040 // info to help debugging
|
|
|
|
#define _STRACE_PARANOID 0x000080 // paranoid info
|
|
|
|
#define _STRACE_TERMIOS 0x000100 // info for debugging termios stuff
|
|
|
|
#define _STRACE_SELECT 0x000200 // info on ugly select internals
|
|
|
|
#define _STRACE_WM 0x000400 // trace windows messages (enable _strace_wm)
|
|
|
|
#define _STRACE_SIGP 0x000800 // trace signal and process handling
|
|
|
|
#define _STRACE_MINIMAL 0x001000 // very minimal strace output
|
|
|
|
#define _STRACE_PTHREAD 0x002000 // pthread calls
|
|
|
|
#define _STRACE_EXITDUMP 0x004000 // dump strace cache on exit
|
|
|
|
#define _STRACE_SYSTEM 0x008000 // cache strace messages
|
|
|
|
#define _STRACE_NOMUTEX 0x010000 // don't use mutex for synchronization
|
|
|
|
#define _STRACE_MALLOC 0x020000 // trace malloc calls
|
|
|
|
#define _STRACE_THREAD 0x040000 // cygthread calls
|
|
|
|
#define _STRACE_NOTALL 0x080000 // don't include if _STRACE_ALL
|
|
|
|
#define _STRACE_SPECIAL 0x100000 // special case, only for debugging - do not check in
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-02-26 17:50:24 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void small_printf (const char *, ...);
|
|
|
|
void strace_printf (unsigned, const char *func, const char *, ...);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-08-02 11:42:31 +08:00
|
|
|
#ifdef NOSTRACE
|
2010-02-23 04:36:04 +08:00
|
|
|
#define strace_printf_wrap(what, fmt, args...)
|
|
|
|
#define strace_printf_wrap1(what, fmt, args...)
|
2000-08-02 11:42:31 +08:00
|
|
|
#else
|
2000-02-18 03:38:33 +08:00
|
|
|
#define strace_printf_wrap(what, fmt, args...) \
|
|
|
|
((void) ({\
|
2005-12-30 04:46:34 +08:00
|
|
|
if ((_STRACE_ ## what & _STRACE_SYSTEM) || strace.active ()) \
|
2000-08-03 03:26:01 +08:00
|
|
|
strace.prntf(_STRACE_ ## what, __PRETTY_FUNCTION__, fmt, ## args); \
|
2000-02-18 03:38:33 +08:00
|
|
|
0; \
|
|
|
|
}))
|
|
|
|
#define strace_printf_wrap1(what, fmt, args...) \
|
|
|
|
((void) ({\
|
2005-12-30 04:46:34 +08:00
|
|
|
if ((_STRACE_ ## what & _STRACE_SYSTEM) || strace.active ()) \
|
2000-08-03 03:26:01 +08:00
|
|
|
strace.prntf((_STRACE_ ## what) | _STRACE_NOTALL, __PRETTY_FUNCTION__, fmt, ## args); \
|
2000-02-18 03:38:33 +08:00
|
|
|
0; \
|
|
|
|
}))
|
2011-05-29 02:17:09 +08:00
|
|
|
#define strace_vprintf(what, fmt, arg) \
|
|
|
|
((void) ({\
|
|
|
|
if ((_STRACE_ ## what & _STRACE_SYSTEM) || strace.active ()) \
|
2011-08-04 01:58:59 +08:00
|
|
|
strace.vprntf((_STRACE_ ## what), __PRETTY_FUNCTION__, fmt, arg); \
|
2011-05-29 02:17:09 +08:00
|
|
|
0; \
|
|
|
|
}))
|
2010-02-23 04:36:04 +08:00
|
|
|
#endif /*NOSTRACE*/
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2011-10-30 12:50:36 +08:00
|
|
|
#ifdef DEBUGGING
|
|
|
|
#define debug_only_printf(fmt, args...) debug_printf (fmt , ## args)
|
|
|
|
#else
|
|
|
|
#define debug_only_printf(fmt, args...) do {} while (0)
|
|
|
|
#endif
|
2000-02-18 03:38:33 +08:00
|
|
|
#define debug_printf(fmt, args...) strace_printf_wrap(DEBUG, fmt , ## args)
|
2010-02-20 01:55:27 +08:00
|
|
|
#define malloc_printf(fmt, args...) strace_printf_wrap1(MALLOC, fmt , ## args)
|
|
|
|
#define minimal_printf(fmt, args...) strace_printf_wrap1(MINIMAL, fmt , ## args)
|
2003-01-26 13:38:38 +08:00
|
|
|
#define paranoid_printf(fmt, args...) strace_printf_wrap1(PARANOID, fmt , ## args)
|
2010-02-20 01:55:27 +08:00
|
|
|
#define pthread_printf(fmt, args...) strace_printf_wrap1(PTHREAD, fmt , ## args)
|
2000-02-18 03:38:33 +08:00
|
|
|
#define select_printf(fmt, args...) strace_printf_wrap(SELECT, fmt , ## args)
|
|
|
|
#define sigproc_printf(fmt, args...) strace_printf_wrap(SIGP, fmt , ## args)
|
2000-08-02 11:42:31 +08:00
|
|
|
#define syscall_printf(fmt, args...) strace_printf_wrap(SYSCALL, fmt , ## args)
|
|
|
|
#define system_printf(fmt, args...) strace_printf_wrap(SYSTEM, fmt , ## args)
|
|
|
|
#define termios_printf(fmt, args...) strace_printf_wrap(TERMIOS, fmt , ## args)
|
2000-02-18 03:38:33 +08:00
|
|
|
#define thread_printf(fmt, args...) strace_printf_wrap1(THREAD, fmt , ## args)
|
2010-02-23 04:36:04 +08:00
|
|
|
#define special_printf(fmt, args...) strace_printf_wrap1(SPECIAL, fmt , ## args)
|
2010-02-20 01:55:27 +08:00
|
|
|
#define wm_printf(fmt, args...) strace_printf_wrap(WM, fmt , ## args)
|
2001-02-26 17:50:24 +08:00
|
|
|
#endif /* __cplusplus */
|
2000-02-18 03:38:33 +08:00
|
|
|
#endif /* _SYS_STRACE_H */
|