I'm designing a small utility to help out with build systems. The idea is that the utility will launch each instance of each compiler and output a log of all the files that the compiler opens during the compilation. Something like:
track-files cc -c -o foo.o foo.c
Then track-files
executes cc
and outputs all the .h
(and other) files that cc
opened. But cc
might be any compiler (or even an interpreter or just a program that does some kind of text transformation).
A similar idea is described in Paul D Smith's Advanced Auto-Dependency tutorial and attributed to Han-Wen Nienhuys.
On Linux, FreeBSD, Solaris and HPUX I think I can use LD_PRELOAD
. On AIX I can use LDR_PRELOAD
and on OSX I can use DYLD_INSERT_LIBRARIES
. On most of those systems I can also use strace
if LD_PRELOAD
-like tricks don't work.
The one OS where I have no clue how to proceed is Windows. I've been looking around and everything I've found so far seems, ..., unsatisfactory.
The only answer to LD_PRELOAD equivalent for Windows to preload shared libraries suggests AppInit_DLLs, but points out they are deprecated and/or disabled after Vista (because they were broken).
The accepted answer on interposers on Windows points to Microsoft Research's Detours but that is proprietary (and they charge big bucks (USD10000!!!) for 64-bit support) so that would make my utility worthless for just about everyone (including me). The other answer mentions something called WinAPI Override, but that's apparently 32-bit only.
There's surely some dependable, non-proprietary, programmatic way to do this on Windows. Some tracing API perhaps? I'd be happy with support only for more recent versions of Windows (Windows 7 and 8, for example).