为什么 strace 在 gcc -c 上不起作用

为什么 strace 在 gcc -c 上不起作用
>echo > foobar.c
>strace gcc -c foobar.c 2>&1 | grep foobar.o
>

(无) -foobar.o显然是写入的,但我在 strace 上没有看到它。为什么?

答案1

这是因为gcc创建子进程,并且strace除非您指定标志,否则不会查看子进程-ff

查看strace -ff本例中标志的实际作用:

deltik@workstation [~/Desktop]# echo > foobar.c
deltik@workstation [~/Desktop]# strace -ff gcc -c foobar.c 2>&1 | grep foobar.o
[pid 14220] execve("/usr/local/sbin/as", ["as", "--64", "-o", "foobar.o", "/tmp/ccJhzHTZ.s"], [/* 66 vars */]) = -1 ENOENT (No such file or directory)
[pid 14220] execve("/usr/local/bin/as", ["as", "--64", "-o", "foobar.o", "/tmp/ccJhzHTZ.s"], [/* 66 vars */]) = -1 ENOENT (No such file or directory)
[pid 14220] execve("/usr/sbin/as", ["as", "--64", "-o", "foobar.o", "/tmp/ccJhzHTZ.s"], [/* 66 vars */]) = -1 ENOENT (No such file or directory)
[pid 14220] execve("/usr/bin/as", ["as", "--64", "-o", "foobar.o", "/tmp/ccJhzHTZ.s"], [/* 66 vars */] <unfinished ...>
[pid 14220] stat("foobar.o", 0x7ffed65b3850) = -1 ENOENT (No such file or directory)
[pid 14220] open("foobar.o", O_RDWR|O_CREAT|O_TRUNC, 0666) = 3

相关内容