【问题标题】:How to trace system calls of a program in Mac OS X?如何在 Mac OS X 中跟踪程序的系统调用?
【发布时间】:2015-09-11 18:40:40
【问题描述】:

我想跟踪 find 命令to debug some performance issues 进行的系统调用,但是我不知道如何在 Mac OS X Yosemite 上执行此操作。我怎样才能像 strace 在 FreeBSD 上那样跟踪任意程序的系统调用?我对跟踪文件系统相关调用特别感兴趣。

【问题讨论】:

  • 快速搜索 strace osx 给了我this four year old blog post。使用相同的搜索应该很容易找到其他替代品。
  • @JoachimPileborg 好点。我采取了另一种方式,从 apropos trace 开始并从中进行搜索。我忽略了 dtrussdtrace,因为我发现的所有结果都是关于 D 语言的跟踪实用程序。
  • 请注意,FreeBSD 附带 truss(1),而不是 strace。

标签: macos strace truss dtruss


【解决方案1】:

你可以像在

中一样使用dtruss
sudo dtruss find ~/repo -depth 2 -type d -name '.git'

该实用程序的manual page 将帮助您根据需要调整该工具的使用。

【讨论】:

【解决方案2】:

在当前版本的 macOS 下,无法跟踪 SIP 覆盖的路径下的可执行文件(如 /usr/bin)。

您可以通过在主目录中制作可执行文件的副本并跟踪副本来绕过此问题:

cp /usr/bin/find find
codesign --remove-signature ./find
sudo dtruss ./find …

您需要从新的 find 可执行文件中删除代码签名,否则 SIP 仍会注意到正在访问系统文件(来源:@Anmol Singh Jaggi)。

【讨论】:

  • 在复制可执行文件后,我想调试的错误停止发生..(
  • 可能我的错误确实与 SIP 相关,所以这也是成功的。
  • 不适用于 macOS 10.15.4。必须先执行codesign --remove-signature ./find
猜你喜欢
  • 1970-01-01
  • 2016-10-22
  • 1970-01-01
  • 2010-09-05
  • 2012-06-20
  • 1970-01-01
  • 1970-01-01
  • 2015-07-02
  • 2023-04-06
相关资源
最近更新 更多