我正在尝试在 OSX 10.9的这个要点上构建示例:
cd /tmp
git clone https://gist.github.com/ecfd80885b9ddf6734192c056cf48bf4.git fopentest
cd fopentest
bash buildrun.sh
构建成功 - 此外,我可以在终端输出中看到以下内容:
...
+ DYLD_BIND_AT_LAUNCH=YES
+ ./fopentest.exe ./mytestfile.txt
This is a wrapper function for fopen.
=== this is mytestfile.txt ===
Second line here...
Third line here...
这意味着调用DYLD_BIND_AT_LAUNCH=YES ./fopentest.exe ./mytestfile.txt
成功地找到了包装库和函数。
dtruss
现在,作为一个测试,我想通过OSX “strace”等价物运行这个可执行文件——我也sudo chmod u+s /usr/sbin/dtrace
按照该链接中的建议进行了操作。所以我在/tmp
文件夹中尝试:
$ DYLD_BIND_AT_LAUNCH=YES dtruss ./fopentest.exe ./mytestfile.txt 2>&1 | grep wrap
This is a wrapper function for fopen.
stat64("libwrapper.dylib\0", 0x7FFF5A7DF248, 0x7FFF5A7E00E0) = 0 0
open("libwrapper.dylib\0", 0x0, 0x0) = 3 0
write_nocancel(0x1, "This is a wrapper function for fopen.\n=== this is mytestfile.txt ===\nSecond line here...\nThird line here...\n\0", 0x6C) = 108 0
所以,显然dtruss
这里有效。但是,我在不同的目录中有完全相同的文件,为什么我尝试运行相同的命令dtruss
失败了:
$ DYLD_BIND_AT_LAUNCH=YES dtruss ./fopentest.exe ./mytestfile.txt 2>&1 | grep wrap
dyld: Library not loaded: libwrapper.dylib
stat64("libwrapper.dylib\0", 0x7FFF4FD85228, 0x7FFF4FD860C0) = 0 0
open("libwrapper.dylib\0", 0x0, 0x0) = -1 Err#2
stat64("/Users/MYNAME/lib/libwrapper.dylib\0", 0x7FFF4FD85A08, 0x7FFF4FD860C0) = -1 Err#2
stat64("/usr/local/lib/libwrapper.dylib\0", 0x7FFF4FD85A08, 0x7FFF4FD860C0) = -1 Err#2
stat64("/usr/lib/libwrapper.dylib\0", 0x7FFF4FD85A18, 0x7FFF4FD860C0) = -1 Err#2
这可能是什么原因?