Hacker News 中文摘要

RSS订阅

Strace-macOS:适用于macOS的strace命令克隆版 -- Strace-macOS: A clone of the strace command for macOS

文章摘要

这是一个为macOS开发的系统调用追踪工具strace-macos,基于LLDB调试器API实现。主要特点包括:无需关闭系统完整性保护(SIP)、纯Python实现、支持多种输出格式和系统调用过滤、提供符号解码和彩色输出等功能。目前处于测试阶段,可通过Nix或手动安装使用。

文章总结

项目名称:strace-macos - macOS系统调用追踪工具

项目地址:https://github.com/Mic92/strace-macos

项目简介: strace-macos是基于LLDB调试器API开发的macOS系统调用追踪工具,是Linux strace命令的macOS实现版本。该项目目前处于Beta测试阶段,核心功能已实现,部分功能仍在开发中。

核心特性: 1. 无需关闭系统完整性保护(SIP) 2. 纯Python实现,无需内核扩展 3. 支持多种输出格式(JSON Lines和strace兼容文本) 4. 系统调用过滤功能(按名称或类别) 5. 自动解码标志位、错误码和结构体字段 6. 终端彩色输出 7. 统计摘要功能

安装方式: 1. 通过Nix Flakes安装: - 直接运行:nix run github:Mic92/strace-macos -- ls - 安装到配置:nix profile install github:Mic92/strace-macos

  1. 手动安装:
    • 使用系统Python安装:/usr/bin/python3 -m pip install --user git+https://github.com/Mic92/strace-macos
    • 从源码直接运行:git clone后使用/usr/bin/python3 -m strace_macos执行

使用示例: 1. 追踪命令:strace /usr/local/bin/git status 2. 附加到运行进程:strace -p 1234 3. 获取统计摘要:strace -c /usr/local/bin/git status

系统调用过滤: 支持按名称(如open,close)或预定义类别(file,network,process等)进行过滤。提供12个预定义类别,涵盖文件操作、网络通信、进程管理等不同领域。

与Linux strace对比: 在基本追踪、PID附加、系统调用过滤等核心功能上保持一致,但在正则过滤、路径过滤等高级功能上仍有差距。strace-macos新增了JSON输出和彩色输出等特色功能。

系统要求: - macOS 12+(Monterey或更新版本) - 优先支持Apple Silicon(ARM64) - 需要Xcode命令行工具 - 必须使用系统Python(/usr/bin/python3)

项目优势: 相比macOS自带的dtruss工具,strace-macos具有无需关闭SIP、功能更丰富等优势。项目采用MIT开源协议,欢迎开发者贡献代码。

当前开发状态: 已完成基本功能实现,包括进程追踪、参数解码等。计划中的功能包括多线程支持、正则过滤等高级特性。

[注:原文中的安装命令、使用示例等具体技术细节已保留,删减了重复的对比表格和部分实现细节描述]

评论总结

总结评论内容:

  1. 正面评价:
  • 认为解决了SIP导致的追踪问题,是受欢迎的改进 "it's been an irritant that SIP broke tracing so this is a welcome development"(sandbags)
  • 相比dtruss更稳定实用 "I've never successfully used dtruss without hardlocking my system"(CGamesPlay)
  1. 实用性质疑:
  • 性能可能较慢 "I'm guessing it's pretty slow"(comex) "it's really slow"(burnt-resistor)
  • 安装和使用存在技术门槛 "Failed to load LLDB Python module"(burnt-resistor) "requires system Python and Xcode Command Line Tools"(burnt-resistor)
  1. 功能比较:
  • 与现有工具(dtruss)的比较讨论 "doesn't macos ship with dtrace? So why not use dtruss?"(cyberpunk)
  • 替代方案建议 "eslogger lookup/exec will give you what you need"(comex)
  1. 使用体验问题:
  • 存在输出格式和颜色问题 "it colorizes output even when piping, and the colors are terrible"(burnt-resistor)
  • 对系统要求较高 "doesn't work with built-in binaries without SIP disabled"(burnt-resistor)
  1. 其他讨论:
  • 关于macOS生态的延伸讨论 "TIL Nix flakes work on macos - is this a legit alternative to homebrew?"(gkfasdfasdf)
  • 对苹果服务器历史的怀念 "I really miss the days when Apple made real effort toward servers"(BirAdam)

注:所有评论均无评分(None),因此无法评估认可度。评论呈现了工具的实际使用体验、技术比较和macOS生态讨论等多角度观点。