如何在 mac 上调用等效的命令来跟踪 - 最好是从 python



自包含可重现示例

我需要通过 python 跟踪任何命令的输出。但我只需要将以下 amd linux 命令转换为 mac m1/arm 命令(因此 python 可能无关紧要):

strace -e trace=execve -v -s 100000000 -xx -ttt -ff -o output.txt sh -c 'echo hi'

我该怎么做?

这对我来说失败了:

❯ sudo dtruss -t execve -f sh -c 'echo hi'
dtrace: system integrity protection is on, some features will not be available
dtrace: failed to execute sh: Operation not permitted

注意:

  • 我可以完全控制输入,所以我可以在我的 mac 中执行 sudo 和相关命令(它主要用于调试我的代码,因此它可以在 pycharm 上运行)
<小时 />

来自酿造的跟踪失败

我似乎无法从brew安装strace:

❯ brew install strace
Running `brew update --auto-update`...
strace: Linux is required for this software.
linux-headers@5.15: Linux is required for this software.
Error: strace: Unsatisfied requirements failed this build.

Execsnoop 也失败

❯ sudo execsnoop sh -c 'echo hi'
dtrace: system integrity protection is on, some features will not be available
dtrace: invalid probe specifier 
/*
* Command line arguments
*/
inline int OPT_dump    = 0;
inline int OPT_cmd     = 0;
inline int OPT_time    = 0;
inline int OPT_timestr = 0;
inline int OPT_zone    = 0;
inline int OPT_safe    = 0;
inline int OPT_proj    = 0;
inline int FILTER      = 0;
inline string COMMAND  = ".";

#pragma D option quiet
#pragma D option switchrate=10hz

/*
* Print header
*/
dtrace:::BEGIN 
{
/* print optional headers */
OPT_time    ? printf("%-14s ", "TIME") : 1;
OPT_timestr ? printf("%-20s ", "STRTIME") : 1;
OPT_zone    ? printf("%-10s ", "ZONE") : 1;
OPT_proj    ? printf("%5s ", "PROJ") : 1;
/* print main headers */
/* APPLE: Removed "ZONE" header, it has no meaning in darwin */
OPT_dump    ? printf("%s %s %s %s %s %s %sn",
"TIME", "PROJ", "UID", "PID", "PPID", "COMM", "ARGS") :
printf("%5s %6s %6s %sn", "UID", "PID", "PPID", "ARGS");
}
/*
* Print exec event
*/
/* SOLARIS: syscall::exec:return, syscall::exece:return */
proc:::exec-success
/(FILTER == 0) || (OPT_cmd == 1 && COMMAND == strstr(COMMAND, execname)) || (OPT_cmd == 1 && execname == strstr(execname, COMMAND))/ 
{
/* print optional fields */
OPT_time ? printf("%-14d ", timestamp/1000) : 1;
OPT_timestr ? printf("%-20Y ", walltimestamp) : 1;
OPT_zone ? printf("%-10s ", zonename) : 1;
OPT_proj ? printf("%5d ", curpsinfo->pr_projid) : 1;
/* print main data */
/* APPLE: Removed the zonename output, it has no meaning in darwin */
OPT_dump ? printf("%d %d %d %d %d %s ", timestamp/1000,
curpsinfo->pr_projid, uid, pid, ppid, execname) :
printf("%5d %6d %6d ", uid, pid, ppid);
OPT_safe ? printf("%Sn", curpsinfo->pr_psargs) :
printf("%sn", curpsinfo->pr_psargs);
}
: probe description proc:::exec-success does not match any probes. System Integrity Protection is on

我继承了这段代码,并在其中从python中调用strace。特别是它调用:

def strace_build(executable: str,
regex: str,
workdir: Optional[str],
command: List[str],
strace_logdir=None) -> List[str]:
''' trace calls of executable during access to files that match regex
in workdir while executing the command and  returns the list of pycoq_context 
file names
In the simplest case strace runs the specified command until it
exits.  It intercepts and records the system calls which are
called by a process and the signals which are received by a
process.  The name of each system call, its arguments and its
return value are printed on standard error or to the file
specified with the -o option.
https://stackoverflow.com/questions/73724074/how-to-call-an-equivalent-command-to-strace-on-mac-ideally-from-python
'''
print('---- Calling strace_build ----')
def _strace_build(executable, regex, workdir, command, logdir):
logfname = os.path.join(logdir, 'strace.log')
logging.info(f"pycoq: tracing {executable} accesing {regex} while "
f"executing {command} from {workdir} with "
f"curdir {os.getcwd()}")
print(f"pycoq: tracing {executable} accesing {regex} while "
f"executing {command} from {workdir} with "
f"curdir {os.getcwd()}")
with subprocess.Popen(['strace', '-e', 'trace=execve',
'-v', '-ff', '-s', '100000000',
'-xx', '-ttt',
'-o', logfname] + command,
cwd=workdir,
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE) as proc:
for line in iter(proc.stdout.readline, ''):
logging.debug(f"strace stdout: {line}")
print(f"strace stdout: {line=}")
logging.info(f"strace stderr: {proc.stderr.read()}"
"waiting strace to finish...")
proc.wait()
logging.info('strace finished')
res: list[str] = parse_strace_logdir(logdir, executable, regex)
print('---- Done with strace_build ----')
return res
if strace_logdir is None:
with tempfile.TemporaryDirectory() as _logdir:
return _strace_build(executable, regex, workdir, command, _logdir)
else:
os.makedirs(strace_logdir, exist_ok=True)
strace_logdir_cur = tempfile.mkdtemp(dir=strace_logdir)
return _strace_build(executable, regex, workdir, command, strace_logdir_cur)

但是因为它调用strace所以它只适用于Linux。我希望它在我的Mac上运行 - 理想情况下,如果可能的话,以最pythonic的方式。我相信它所做的是跟踪从 python 中调用的终端命令。

在mac 上使用相同的标志调用此命令的等效方法是什么,以便它(理想情况下)工作相同?

不确定这是否重要,但我使用的是 m1 Mac。

使用上述函数时

一些输出:

--done with make attempt--
---- Calling strace_build ----
pycoq: tracing /home/bot/.opam/ocaml-variants.4.07.1+flambda_coq-serapi.8.11.0+0.11.1/bin/coqc accesing .*.v$ while executing ['opam', 'reinstall', '--yes', '--switch', 'ocaml-variants.4.07.1+flambda_coq-serapi.8.11.0+0.11.1', '--keep-build-dir', 'debug_proj'] from None with curdir /home/bot
strace stdout: line='n'
strace stdout: line='<><> Synchronising pinned packages ><><><><><><><><><><><><><><><><><><><><><><>n'
strace stdout: line='[debug_proj.~dev] no changes from file:///home/bot/iit-term-synthesis/coq_projects/debug_projn'
strace stdout: line='n'
strace stdout: line='debug_proj is not installed. Install it? [Y/n] yn'
strace stdout: line='Sorry, no solution found: there seems to be a problem with your request.n'
strace stdout: line='n'
strace stdout: line='No solution found, exitingn'
---- Done with strace_build ----
...
---- Calling strace_build ----
pycoq: tracing /home/bot/.opam/ocaml-variants.4.07.1+flambda_coq-serapi.8.11.0+0.11.1/bin/coqc accesing .*.v$ while executing ['make', '-C', '/home/bot/iit-term-synthesis/coq_projects/debug_proj'] from None with curdir /home/bot
strace stdout: line="make: Entering directory '/home/bot/iit-term-synthesis/coq_projects/debug_proj'n"
strace stdout: line='coq_makefile -f _CoqProject -o CoqMakefilen'
strace stdout: line='make --no-print-directory -f CoqMakefile n'
strace stdout: line='COQDEP VFILESn'
strace stdout: line='COQC debug_0_plus_n_eq_n.vn'
strace stdout: line='COQC debug1_n_plus_1_greater_than_n.vn'
strace stdout: line='COQC debug2_n_plus_0_eq_n.vn'
strace stdout: line="make: Leaving directory '/home/bot/iit-term-synthesis/coq_projects/debug_proj'n"
---- Done with strace_build ----
<小时 />
def strace_build_mac_m1(executable: str,
regex: str,
workdir: Optional[str],
command: List[str],
strace_logdir=None) -> List[str]:
''' trace calls of executable during access to files that match regex
in workdir while executing the command and  returns the list of pycoq_context
file names
In the simplest case strace runs the specified command until it
exits.  It intercepts and records the system calls which are
called by a process and the signals which are received by a
process.  The name of each system call, its arguments and its
return value are printed on standard error or to the file
specified with the -o option.
https://stackoverflow.com/questions/73724074/how-to-call-an-equivalent-command-to-strace-on-mac-ideally-from-python
plan:
- get the command we are running
- pip push my pycoq with no name changes so code doesn't break
- pull the rest of the repos needed, I don't think anything else since lf is here
- harcode test
- actually, look at commands...we need to provide for reproducibility a way to install opam and all this stuff
without docker but in the mac since we are trying to do a mac install. Argh...
COMMANDS:
pycoq: tracing /home/bot/.opam/ocaml-variants.4.07.1+flambda_coq-serapi.8.11.0+0.11.1/bin/coqc accesing .*.v$ while executing ['opam', 'reinstall', '--yes', '--switch', 'ocaml-variants.4.07.1+flambda_coq-serapi.8.11.0+0.11.1', '--keep-build-dir', 'lf'] from None with curdir /home/bot
executable='/home/bot/.opam/ocaml-variants.4.07.1+flambda_coq-serapi.8.11.0+0.11.1/bin/coqc'
regex='.*\.v$'
workdir=None
command=['opam', 'reinstall', '--yes', '--switch', 'ocaml-variants.4.07.1+flambda_coq-serapi.8.11.0+0.11.1', '--keep-build-dir', 'lf']
curdir: os.getcwd()='/home/bot'
'''
print('---- Calling strace_build_mac_m1 ----')
def _strace_build(executable, regex, workdir, command, logdir):
logfname = os.path.join(logdir, 'strace.log')
logging.info(f"pycoq: tracing {executable} accesing {regex} while "
f"executing {command} from {workdir} with "
f"curdir {os.getcwd()}")
print(f"pycoq: tracing {executable} accesing {regex} while "
f"executing {command} from {workdir} with "
f"curdir {os.getcwd()}")
print(f'{executable=}')
print(f'{regex=}')
print(f'{workdir=}')
print(f'{command=}')
print(f'curdir: {os.getcwd()=}')
with subprocess.Popen(['dtruss', '-e', 'trace=execve',
'-v', '-ff', '-s', '100000000',
'-xx', '-ttt',
'-o', logfname] + command,
cwd=workdir,
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE) as proc:
for line in iter(proc.stdout.readline, ''):
logging.debug(f"strace stdout: {line}")
print(f"strace stdout: {line=}")
logging.info(f"strace stderr: {proc.stderr.read()}"
"waiting strace to finish...")
proc.wait()
logging.info('strace finished')
res: list[str] = parse_strace_logdir(logdir, executable, regex)
print('---- Done with strace_build_mac_m1 ----')
return res
if strace_logdir is None:
with tempfile.TemporaryDirectory() as _logdir:
return _strace_build(executable, regex, workdir, command, _logdir)
else:
os.makedirs(strace_logdir, exist_ok=True)
strace_logdir_cur = tempfile.mkdtemp(dir=strace_logdir)
return _strace_build(executable, regex, workdir, command, strace_logdir_cur)

# -
def code_for_mac_m1():
coq_package = 'lf'
coq_package_pin = '~/pycoq/pycoq/test/lf'
coq_package_pin = os.path.expanduser(coq_package_pin)
print(f'coq_package: {coq_package=}')
print(f'coq_package_pin: {coq_package_pin=}')

### pycoq: tracing /home/bot/.opam/ocaml-variants.4.07.1+flambda_coq-serapi.8.11.0+0.11.1/bin/coqc accesing .*.v$ while executing ['opam', 'reinstall', '--yes', '--switch', 'ocaml-variants.4.07.1+flambda_coq-serapi.8.11.0+0.11.1', '--keep-build-dir', 'lf'] from None with curdir /home/bot
# executable='/home/bot/.opam/ocaml-variants.4.07.1+flambda_coq-serapi.8.11.0+0.11.1/bin/coqc'
# regex='.*\.v$'
# workdir=None
# command=['opam', 'reinstall', '--yes', '--switch', 'ocaml-variants.4.07.1+flambda_coq-serapi.8.11.0+0.11.1', '--keep-build-dir', 'lf']
# curdir: os.getcwd()='/home/bot'
# - get the filename in split
# path2filenames: list[str] = pycoq.opam.opam_strace_build(coq_proj, coq_proj_pin)
path2filenames_raw: list[str] = strace_build_mac_m1()
path2filenames_raw.sort()
print(f'n====----> Populate coq pkg/proj data with files: {path2filenames_raw=}')

if __name__ == '__main__':
code_for_mac_m1()
print('Done!na')

为什么这不符合 SO 准则?我没有明确要求软件请求。从讨论中,在 python 中运行要困难得多 + 根据需要设置 mac + 具有等效标志的工具适用于 mac。


google用于替换Mac OS的strace功能(模拟),并修改解析该"mac-strace"的strace输出的解析器 strace 功能用于检查 Coq 构建系统,以记录 coqc 的所有选项、参数和环境,其中每个单独的 .v 文件在构建过程中都已由 coqc 处理。Coq 构建系统很复杂,我没有解析,而是决定只通过 strace 观察实际 Coq 的作用,并且 strace 只是记录实际 Coq 所做的所有选项和参数(如 -R 等),以便 pycoq 可以使用完全相同的选项和参数调用 coqc


使用修改后的 dtruss.sh

菲利普的回答不起作用:

(meta_learning) brandomiranda~ ❯ cat dtruss.sh
#!/bin/bash
file=$(type -P $1); shift
c=/tmp/$(basename "$file")
cp "$file" "$c"
codesign --remove-signature "$c"
sudo dtruss "$c" "$@"
(meta_learning) brandomiranda~ ❯ chmod +x dtruss.sh
(meta_learning) brandomiranda~ ❯ ./dtruss.sh echo hi
dtrace: system integrity protection is on, some features will not be available
dtrace: failed to execute /tmp/echo: Could not create symbolicator for task

要修复 sudo 不提示输入密码,请参阅:

# root and users in group wheel can run anything on any machine as any user
root        ALL = (ALL) ALL
%admin      ALL = (ALL) NOPASSWD: ALL
#%admin     ALL = (ALL) ALL
<小时 />

相关:

  • 是否可以在不做这里建议的奇怪事情的情况下运行 dtruss?
  • Cross, unix reddit.
  • 克罗斯,苹果开发者Reddit。

问题中的大多数答案和解决方法都试图在 Linux 安全模型中工作。多年来,苹果一直在稳步提高其安全性,超越其Mach/BSD根源。他们增加了硬件安全性,即从开机到完整macOS负载的硬件信任根。安全隔区还处理面部和指纹数据。文件保险箱可以加密您的整个磁盘。系统完整性保护提供了一个无根系统,其中 root 的权限比 none 用户多一点。例如,在 Ventura 13.2 系统上,根目录无法看到每个文件或目录(sudo find / -print|wc会产生许多"不允许操作"错误)。

简而言之,像这样跟踪执行的唯一可行方法有许多苛刻的要求:

  • 您必须使用 Apple 的 EndpointSecurity 框架。
  • 您的代码必须在 Xcode 中编译为应用程序捆绑包(Program.app 安装在/Applications 中)。
  • 您需要 Apple 授予您的开发者帐户"com.apple.developer.endpoint-security.client"权利。
  • 您需要分配预配配置文件以与授予的权利进行协同设计。
  • 如果您尚未获得授权,则必须在恢复模式下禁用SIP 并禁用 Apple 移动文件完整性 (AMFI)。强烈建议不要执行这两种操作,因为它们主要负责阻止您运行 dtruss/strace。
  • 应用程序必须以根用户身份运行。
  • 您的应用程序必须从"安全性与隐私"系统偏好设置面板中授予"完全磁盘访问权限"。

然后,您可以编写一个完整的 strace 替换作为应用程序包 (/Application/strace.app) 并按以下方式使用它:

/Applications/strace.app/Contents/MacOS/strace -e trace=execve -v -s 100000000 -xx -ttt -ff -o output.txt sh -c 'echo hi'

其他答案中的各种建议由于不同的原因而失败:

  • 现在,使用dtrace需要禁用 SIP。
  • 如果您可以将strace移植到macOS,则还需要禁用SIP。
  • 同样在 13.2 中,execsnoop需要 SIP:

%sudo execsnoop -a -c ./test
probe 说明 proc:::exec-success 与任何探测器都不匹配。系统完整性保护已打开

  • 使用 LD_PRELOAD 具有挑战性,请参阅此开发人员论坛主题。
  • 现在,使用codesign --remove-signature删除签名会导致进程被终止。

    ASP:安全策略不允许进程

我的建议:

重写代码以不在 Linux 或 macOS 上使用strace,并构建一个框架以直接在构建过程中获取所需的信息。在某些时候,Linux 会添加这些类型的安全功能。也许不是今年,但我肯定会在十年结束之前考虑。

奖金:

如果您希望实现我上面建议的应用程序,这个要点是一个开始。查尔斯·达菲(Charles Duffy)在上面链接了该要点的衍生物。

您不想用csrutil禁用SIP,似乎唯一的选择是删除带有codesign的签名。

我做了一个小脚本来简化过程,保存以下内容 dtruss.sh

#!/bin/bash
file=$(type -P $1); shift
c=/tmp/$(basename "$file")
cp "$file" "$c"
codesign --remove-signature "$c"
sudo dtruss "$c" "$@"

然后

chmod +x dtruss.sh
./dtruss.sh echo hi
./dtruss.sh find /etc/ -name bashrc

更新

  1. 请参阅Enable sudo without a password on MacOS

  2. 它适用于我的文图拉 13.1 英特尔

$ ./dtruss.sh echo "Hello, World!"
dtrace: system integrity protection is on, some features will not be available
SYSCALL(args)        = return
Hello, World!
mprotect(0x1105F0000, 0x8000, 0x1)       = 0 0
thread_selfid(0x0, 0x0, 0x0)         = 19299 0
shared_region_check_np(0x7FF7BAE92940, 0x0, 0x0)         = 0 0
thread_selfid(0x0, 0x0, 0x0)         = 19299 0
...

Sudo without a passowrd mac

第一百万次,我将macOS升级到下一个主要版本(蒙特雷),我不得不搜索如何重新启用无密码sudo'ing(不要评判我)。

编辑/etc/sudoers

sudo visudo

然后找到管理员组权限部分:

%admin          ALL = (ALL) ALL

更改以添加 NOPASSWD:

%admin          ALL = (ALL) NOPASSWD: ALL

利润到明年。

简短而简单的答案是MacOS的安全模型本质上是不同的。在基于 BSD 的系统上跟踪系统调用(以及更多)的标准工具是dtruss,但它与strace完全不同;对于初学者来说,它要求您root甚至开始探索可能性。

由于不清楚这是否是您想要采取的路线,我将简要链接到一些资源以获取更多信息。

  • https://etcnotes.com/posts/system-call/- 非常简短的中式快速介绍
  • Mac OSX:使用dtruss?有一些细节和放大(我看到你已经在那里评论过了)
  • http://dtrace.org/blogs/brendan/2011/10/10/top-10-dtrace-scripts-for-mac-os-x/是一个更详细的介绍;作者在他们的个人博客上有更多关于这个主题的文章。
  • https://mohit.io/blog/fs_usage-trace-file-system-calls-on-mac-os-x/声称他们有一个类似于strace的工具,但名称表明它特定于文件系统调用;我没有进一步探讨这个问题。有一个相关的命令sc_usage但是我无法通过快速鸭鸭去找到任何进一步的信息。

因此,简而言之,您不太可能轻松地扩展此代码以在 Linux 和 MacOS 之间移植。

也许一个合理的替代方案是扩展您尝试strace的软件,改为提供某种内部调试模式,以便在每次调度"有趣"系统调用时发出事件或打印消息。根据"有趣"的内容,这可以是从中等琐碎到极具挑战性的任何地方。

另一种可能的探索途径是您感兴趣的系统调用的包装器。您可以简单地打印出参数,然后继续调用正确的系统调用。例如,DYLD_LIBRARY_PATH & DYLD_INSERT_LIBRARIES 不起作用(Linux 上的等效工具称为LD_PRELOAD.)

请根据本书查看以下两个脚本。我相信这两者结合起来会给你一个与原始代码类似的结果。

我修复了脚本以与新版本兼容。它在我的 M1 上运行。不确定我是否得到了预期的输出。请阅读本书以获取更多信息。

#openproc.py ( Fixed to newer_version)
#!/usr/bin/env python
import re
import sys
# ----------------------------
# openproc.py - Collect data from opentrace.py and merge :entry and :return →
# Open trace file or use stdin
try:
inf = file(sys.argv[1], 'r')
except OSError as ose:
print(ose)
print('''openproc.py [filename]''')
sys.exit(1)
except IndexError:
inf = sys.stdin
# Convert time to human time
def human_time(ns):
ns = float(ns)
for unit in ['ns', 'us', 'ms']:
if abs(ns) == 0:
print('ERROR %d' % ret)
else:
print('OPEN %s %d %s => %s [%s]' % (users.get(uid, str(uid)),
pid, state[pid][1], status,
human_time(tm - state[pid][0])))
del state[pid]
#opentrace.py (Fixed syntax)
#!/usr/bin/env python
import sys, os, subprocess, platform
from optparse import OptionParser
# ----------------------------
# opentrace.py - Trace open syscalls via SystemTap or DTrace
# supports filtering per UID or PID
optparser = OptionParser()
optparser.add_option('-S', '--stap', action='store_true',
dest='systemtap', help='Run SystemTap')
optparser.add_option('-D', '--dtrace', action='store_true',
dest='dtrace', help='Run DTrace')
optparser.add_option('-p', '--pid', action='store', type='int',
dest='pid', default='-1', metavar='PID',
help='Trace process with specified PID')
optparser.add_option('-u', '--uid', action='store', type='int',
dest='uid', default='-1', metavar='UID',
help='Filter traced processes by UID')
optparser.add_option('-c', '--command', action='store', type='string',
dest='command', metavar='CMD',
help='Run specified command CMD and trace it')
(opts, args) = optparser.parse_args()
if opts.pid >= 0 and opts.command is not None:
optparser.error('-p and -c are mutually exclusive')
if (opts.pid >= 0 or opts.command is not None) and opts.uid >= 0:
optparser.error('-p or -c are mutually exclusive with -u')
if opts.systemtap and opts.dtrace:
optparser.error('-S and -D are mutually exclusive')
if not opts.systemtap and not opts.dtrace:
# Try to guess based on operating system
opts.systemtap = sys.platform == 'linux2'
opts.dtrace = sys.platform == 'sunos5'
if not opts.systemtap and not opts.dtrace:
optparser.error('DTrace or SystemTap are non-standard for your platform,please specify -S or -D option')
def run_tracer(entry, ret, cond_proc, cond_user, cond_default,
env_bin_var, env_bin_path,
opt_pid, opt_command, args, fmt_probe):
cmdargs = [os.getenv(env_bin_var, env_bin_path)]
if opts.pid >= 0:
cmdargs.extend([opt_pid, str(opts.pid)])
entry['cond'] = ret['cond'] = cond_proc
elif opts.command is not None:
cmdargs.extend([opt_command, opts.command])
entry['cond'] = ret['cond'] = cond_proc
elif opts.uid >= 0:
entry['cond'] = ret['cond'] = cond_user % opts.uid
else:
entry['cond'] = ret['cond'] = cond_default
cmdargs.extend(args)
proc = subprocess.Popen(cmdargs, stdin=subprocess.PIPE)
proc.stdin.write(fmt_probe % entry)
proc.stdin.write(fmt_probe % ret)
proc.stdin.close()
proc.wait()
if opts.systemtap:
entry = {'name': 'syscall.open',
'dump': '''printf("=> uid: %d pid: %d open: %s %d\n",
uid(), pid(), filename, gettimeofday_ns());'''}
ret =   {'name': 'syscall.open.return',
'dump': '''printf(" uid: %%d pid: %%d open: %%s %%lld\n",
uid, pid, copyinstr(%s), (long long) timestamp); ''' % fn_arg}

我没有这方面的经验,但我会尽力而为。

您可以使用DTrace.

下面是来自 Oracle 文档 - DTrace 命令行的一些命令:

dtrace [-CeFGhHlqSvVwZ]
[-b bufsz] [-c command] [-D name[=value]] [-I pathname] [-L pathname]
[-o pathname] [-p PID] [-s source_pathname]
[-U name] [-x option[=value]][-X[a|c|s|t]]
[-P provider[[predicate]action]]
[-m [[provider:]module[[predicate]action]]]
[-f [[provider:]module:]function[[predicate]action]]
[-n [[[provider:]module:]function:]name[[predicate]action]]
[-i probe-id[[predicate]action]]

现在显然这只在 D 语言中运行,但网上有很多 github 可以用 python 处理这个问题。

@paulross有一个特定的Github,其中准备在~/venvs目录(或任何你喜欢的地方)中创建Python的dtrace版本和虚拟环境:

cd ~/tmp
curl -o Python-3.7.0.tgz https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
tar -xzf Python-3.7.0.tgz
cd Python-3.7.0
./configure --with-dtrace
make
python.exe -m venv ~/venvs/dtrace

不幸的是,由于我在这方面缺乏经验,我无法使用与 strace 一起使用的 dtrace 提供确切的代码。

这是一本关于DTrace的非常长而全面的书

参见:https://stackoverflow.com/a/75567397/1601580


mac 中不再更改密码 sudo

源语言:

# root and users in group wheel can run anything on any machine as any user
root            ALL = (ALL) ALL
%admin          ALL = (ALL) ALL

改变

%admin          ALL = (ALL) NOPASSWD: ALL

最新更新