GME  13
apr_dbg_win32_handles.h
Go to the documentation of this file.
00001 /* Licensed to the Apache Software Foundation (ASF) under one or more
00002  * contributor license agreements.  See the NOTICE file distributed with
00003  * this work for additional information regarding copyright ownership.
00004  * The ASF licenses this file to You under the Apache License, Version 2.0
00005  * (the "License"); you may not use this file except in compliance with
00006  * the License.  You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef APR_DBG_WIN32_HANDLES_H
00018 #define APR_DBG_WIN32_HANDLES_H
00019 
00020 #ifdef __cplusplus
00021 extern "C" {
00022 #endif
00023 
00024 /* USAGE:
00025  * 
00026  * Add the following include to apr_private.h for internal debugging,
00027  * or copy this header into apr/include add the include below to apr.h
00028  * for really global debugging;
00029  *
00030  *   #include "apr_dbg_win32_handles.h"
00031  *
00032  * apr_dbg_log is the crux of this function ... it uses Win32 API and
00033  * no apr calls itself to log all activity to a file named for the
00034  * executing application with a .pid suffix.  Ergo several instances
00035  * may be executing and logged at once.
00036  *
00037  * HANDLE apr_dbg_log(char* fn, HANDLE ha, char* fl, int ln, int nh 
00038  *                           [, HANDLE *hv, char *dsc...])
00039  *
00040  * returns: the handle passed in ha, which is cast back to the real return type.
00041  *
00042  * formats one line into the debug log file if nh is zero;
00043  * ha (hex) seq(hex) tid(hex) fn     fl         ln
00044  * xxxxxxxx xxxxxxxx xxxxxxxx func() sourcefile:lineno
00045  * The macro apr_dbg_rv makes this simple to implement for many APIs
00046  * that simply take args that don't interest us, and return a handle.
00047  *
00048  * formats multiple lines (nh) into the debug log file for each hv/dsc pair
00049  * (nh must correspond to the number of pairs);
00050  * hv (hex) seq(hex) tid(hex) fn   dsc  fl         ln
00051  * xxxxxxxx xxxxxxxx xxxxxxxx func(arg) sourcefile:lineno
00052  * In this later usage, hv is the still the return value but is not
00053  * treated as a handle.
00054  */
00055 
00056 APR_DECLARE_NONSTD(HANDLE) apr_dbg_log(char* fn, HANDLE ha, char* fl, int ln, 
00057                                        int nh,/* HANDLE *hv, char *dsc */...);
00058 
00059 #define apr_dbg_rv(fn, args) (apr_dbg_log(#fn,(fn) args,__FILE__,__LINE__,0))
00060 
00061 #define CloseHandle(h) \
00062     ((BOOL)apr_dbg_log("CloseHandle", \
00063                        (HANDLE)(CloseHandle)(h), \
00064                        __FILE__,__LINE__,1, \
00065                        &(h),""))
00066 
00067 #define CreateEventA(sd,b1,b2,nm) apr_dbg_rv(CreateEventA,(sd,b1,b2,nm))
00068 #define CreateEventW(sd,b1,b2,nm) apr_dbg_rv(CreateEventW,(sd,b1,b2,nm))
00069 
00070 #define CreateFileA(nm,d1,d2,sd,d3,d4,h) apr_dbg_rv(CreateFileA,(nm,d1,d2,sd,d3,d4,h))
00071 #define CreateFileW(nm,d1,d2,sd,d3,d4,h) apr_dbg_rv(CreateFileW,(nm,d1,d2,sd,d3,d4,h))
00072 
00073 #define CreateFileMappingA(fh,sd,d1,d2,d3,nm) apr_dbg_rv(CreateFileMappingA,(fh,sd,d1,d2,d3,nm))
00074 #define CreateFileMappingW(fh,sd,d1,d2,d3,nm) apr_dbg_rv(CreateFileMappingW,(fh,sd,d1,d2,d3,nm))
00075 
00076 #define CreateMutexA(sd,b,nm) apr_dbg_rv(CreateMutexA,(sd,b,nm))
00077 #define CreateMutexW(sd,b,nm) apr_dbg_rv(CreateMutexW,(sd,b,nm))
00078 
00079 #define CreateIoCompletionPort(h1,h2,pd1,d2) apr_dbg_rv(CreateIoCompletionPort,(h1,h2,pd1,d2))
00080 
00081 #define CreateNamedPipeA(nm,d1,d2,d3,d4,d5,d6,sd) apr_dbg_rv(CreateNamedPipeA,(nm,d1,d2,d3,d4,d5,d6,sd))
00082 #define CreateNamedPipeW(nm,d1,d2,d3,d4,d5,d6,sd) apr_dbg_rv(CreateNamedPipeW,(nm,d1,d2,d3,d4,d5,d6,sd))
00083 
00084 #define CreatePipe(ph1,ph2,sd,d) \
00085     ((BOOL)apr_dbg_log("CreatePipe", \
00086                        (HANDLE)(CreatePipe)(ph1,ph2,sd,d), \
00087                        __FILE__,__LINE__,2, \
00088                        (ph1),"hRead", \
00089                        (ph2),"hWrite"))
00090 
00091 #define CreateProcessA(s1,s2,sd1,sd2,b,d1,s3,s4,pd2,hr) \
00092     ((BOOL)apr_dbg_log("CreateProcessA", \
00093                        (HANDLE)(CreateProcessA)(s1,s2,sd1,sd2,b,d1,s3,s4,pd2,hr), \
00094                        __FILE__,__LINE__,2, \
00095                        &((hr)->hProcess),"hProcess", \
00096                        &((hr)->hThread),"hThread"))
00097 #define CreateProcessW(s1,s2,sd1,sd2,b,d1,s3,s4,pd2,hr) \
00098     ((BOOL)apr_dbg_log("CreateProcessW", \
00099                        (HANDLE)(CreateProcessW)(s1,s2,sd1,sd2,b,d1,s3,s4,pd2,hr), \
00100                        __FILE__,__LINE__,2, \
00101                        &((hr)->hProcess),"hProcess", \
00102                        &((hr)->hThread),"hThread"))
00103 
00104 #define CreateSemaphoreA(sd,d1,d2,nm) apr_dbg_rv(CreateSemaphoreA,(sd,d1,d2,nm))
00105 #define CreateSemaphoreW(sd,d1,d2,nm) apr_dbg_rv(CreateSemaphoreW,(sd,d1,d2,nm))
00106 
00107 #define CreateThread(sd,d1,fn,pv,d2,pd3) apr_dbg_rv(CreateThread,(sd,d1,fn,pv,d2,pd3))
00108 
00109 #define DeregisterEventSource(h) \
00110     ((BOOL)apr_dbg_log("DeregisterEventSource", \
00111                        (HANDLE)(DeregisterEventSource)(h), \
00112                        __FILE__,__LINE__,1, \
00113                        &(h),""))
00114 
00115 #define DuplicateHandle(h1,h2,h3,ph4,d1,b,d2) \
00116     ((BOOL)apr_dbg_log("DuplicateHandle", \
00117                        (HANDLE)(DuplicateHandle)(h1,h2,h3,ph4,d1,b,d2), \
00118                        __FILE__,__LINE__,2, \
00119                        (ph4),((h3)==GetCurrentProcess()) \
00120                                    ? "Target" : "EXTERN Target", \
00121                        &(h2),((h1)==GetCurrentProcess()) \
00122                                  ? "Source" : "EXTERN Source"))
00123 
00124 #define GetCurrentProcess() \
00125     (apr_dbg_log("GetCurrentProcess", \
00126                  (GetCurrentProcess)(),__FILE__,__LINE__,0))
00127 
00128 #define GetCurrentThread() \
00129     (apr_dbg_log("GetCurrentThread", \
00130                  (GetCurrentThread)(),__FILE__,__LINE__,0))
00131 
00132 #define GetModuleHandleA(nm) apr_dbg_rv(GetModuleHandleA,(nm))
00133 #define GetModuleHandleW(nm) apr_dbg_rv(GetModuleHandleW,(nm))
00134 
00135 #define GetStdHandle(d) apr_dbg_rv(GetStdHandle,(d))
00136 
00137 #define LoadLibraryA(nm) apr_dbg_rv(LoadLibraryA,(nm))
00138 #define LoadLibraryW(nm) apr_dbg_rv(LoadLibraryW,(nm))
00139 
00140 #define LoadLibraryExA(nm,h,d) apr_dbg_rv(LoadLibraryExA,(nm,h,d))
00141 #define LoadLibraryExW(nm,h,d) apr_dbg_rv(LoadLibraryExW,(nm,h,d))
00142 
00143 #define OpenEventA(d,b,nm) apr_dbg_rv(OpenEventA,(d,b,nm))
00144 #define OpenEventW(d,b,nm) apr_dbg_rv(OpenEventW,(d,b,nm))
00145 
00146 #define OpenFileMappingA(d,b,nm) apr_dbg_rv(OpenFileMappingA,(d,b,nm))
00147 #define OpenFileMappingW(d,b,nm) apr_dbg_rv(OpenFileMappingW,(d,b,nm))
00148 
00149 #define RegisterEventSourceA(s1,s2) apr_dbg_rv(RegisterEventSourceA,(s1,s2))
00150 #define RegisterEventSourceW(s1,s2) apr_dbg_rv(RegisterEventSourceW,(s1,s2))
00151 
00152 #define SetEvent(h) \
00153     ((BOOL)apr_dbg_log("SetEvent", \
00154                        (HANDLE)(SetEvent)(h), \
00155                        __FILE__,__LINE__,1, \
00156                        &(h),""))
00157 
00158 #define SetStdHandle(d,h) \
00159     ((BOOL)apr_dbg_log("SetStdHandle", \
00160                        (HANDLE)(SetStdHandle)(d,h), \
00161                        __FILE__,__LINE__,1,&(h),""))
00162 
00163 #define socket(i1,i2,i3) \
00164     ((SOCKET)apr_dbg_log("socket", \
00165                          (HANDLE)(socket)(i1,i2,i3), \
00166                        __FILE__,__LINE__,0))
00167 
00168 #define WaitForSingleObject(h,d) \
00169     ((DWORD)apr_dbg_log("WaitForSingleObject", \
00170                         (HANDLE)(WaitForSingleObject)(h,d), \
00171                         __FILE__,__LINE__,1,&(h),"Signaled"))
00172 
00173 #define WaitForSingleObjectEx(h,d,b) \
00174     ((DWORD)apr_dbg_log("WaitForSingleObjectEx", \
00175                         (HANDLE)(WaitForSingleObjectEx)(h,d,b), \
00176                         __FILE__,__LINE__,1,&(h),"Signaled"))
00177 
00178 #define WaitForMultipleObjects(d1,ah,b,d2) \
00179     ((DWORD)apr_dbg_log("WaitForMultipleObjects", \
00180                         (HANDLE)(WaitForMultipleObjects)(d1,ah,b,d2), \
00181                         __FILE__,__LINE__,1,ah,"Signaled"))
00182 
00183 #define WaitForMultipleObjectsEx(d1,ah,b1,d2,b2) \
00184     ((DWORD)apr_dbg_log("WaitForMultipleObjectsEx", \
00185                         (HANDLE)(WaitForMultipleObjectsEx)(d1,ah,b1,d2,b2), \
00186                         __FILE__,__LINE__,1,ah,"Signaled"))
00187 
00188 #define WSASocketA(i1,i2,i3,pi,g,dw) \
00189     ((SOCKET)apr_dbg_log("WSASocketA", \
00190                          (HANDLE)(WSASocketA)(i1,i2,i3,pi,g,dw), \
00191                        __FILE__,__LINE__,0))
00192 
00193 #define WSASocketW(i1,i2,i3,pi,g,dw) \
00194     ((SOCKET)apr_dbg_log("WSASocketW", \
00195                          (HANDLE)(WSASocketW)(i1,i2,i3,pi,g,dw), \
00196                        __FILE__,__LINE__,0))
00197 
00198 #define closesocket(sh) \
00199     ((int)apr_dbg_log("closesocket", \
00200                       (HANDLE)(closesocket)(sh), \
00201                       __FILE__,__LINE__,1,&(sh),""))
00202 
00203 #define _beginthread(fn,d,pv) \
00204     ((unsigned long)apr_dbg_log("_beginthread", \
00205                                 (HANDLE)(_beginthread)(fn,d,pv), \
00206                                 __FILE__,__LINE__,0))
00207 
00208 #define _beginthreadex(sd,d1,fn,pv,d2,pd3) \
00209     ((unsigned long)apr_dbg_log("_beginthreadex", \
00210                                 (HANDLE)(_beginthreadex)(sd,d1,fn,pv,d2,pd3), \
00211                                 __FILE__,__LINE__,0))
00212 
00213 #ifdef __cplusplus
00214 }
00215 #endif
00216 
00217 #endif /* !defined(APR_DBG_WIN32_HANDLES_H) */