Como o thrig diz , você deve compilar seu programa em C ( usando um compilador como gcc
ou clang
), use strace
para executar o binário compilado.
ek@Io:~$ cat >hello.c <<'EOF'
> #include <stdio.h>
>
> int main(void)
> {
> puts("Hello, world!");
> return 0;
> }
> EOF
ek@Io:~$ gcc -ansi -pedantic -Wall -Wextra -g -o hello hello.c
ek@Io:~$ strace ./hello
execve("./hello", ["./hello"], [/* 19 vars */]) = 0
brk(NULL) = 0x220f000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8000316000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=156046, ...}) = 0
mmap(NULL, 156046, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f80002ef000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "7ELFek@Io:~$ strace hello.c
strace: Can't stat 'hello.c': No such file or directory
ek@Io:~$ strace ./hello.c
execve("./hello.c", ["./hello.c"], [/* 19 vars */]) = -1 EACCES (Permission denied)
write(2, "strace: exec: Permission denied\n", 32strace: exec: Permission denied
) = 32
exit_group(1) = ?
+++ exited with 1 +++
ek@Io:~$ chmod +x hello.c
ek@Io:~$ strace ./hello.c
execve("./hello.c", ["./hello.c"], [/* 19 vars */]) = -1 ENOEXEC (Exec format error)
write(2, "strace: exec: Exec format error\n", 32strace: exec: Exec format error
) = 32
exit_group(1) = ?
+++ exited with 1 +++
ek@Io:~$ cat >hello.c <<'EOF'
> #include <stdio.h>
>
> int main(void)
> {
> puts("Hello, world!");
> return 0;
> }
> EOF
ek@Io:~$ gcc -ansi -pedantic -Wall -Wextra -g -o hello hello.c
ek@Io:~$ strace ./hello
execve("./hello", ["./hello"], [/* 19 vars */]) = 0
brk(NULL) = 0x220f000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8000316000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=156046, ...}) = 0
mmap(NULL, 156046, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f80002ef000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "7ELFek@Io:~$ strace hello.c
strace: Can't stat 'hello.c': No such file or directory
ek@Io:~$ strace ./hello.c
execve("./hello.c", ["./hello.c"], [/* 19 vars */]) = -1 EACCES (Permission denied)
write(2, "strace: exec: Permission denied\n", 32strace: exec: Permission denied
) = 32
exit_group(1) = ?
+++ exited with 1 +++
ek@Io:~$ chmod +x hello.c
ek@Io:~$ strace ./hello.c
execve("./hello.c", ["./hello.c"], [/* 19 vars */]) = -1 ENOEXEC (Exec format error)
write(2, "strace: exec: Exec format error\n", 32strace: exec: Exec format error
) = 32
exit_group(1) = ?
+++ exited with 1 +++
%pre%%pre%%pre%%pre%%pre%%pre%%pre%>%pre%%pre%%pre%%pre%P\t%pre%%pre%%pre%%pre%%pre%"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1864888, ...}) = 0
mmap(NULL, 3967392, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f7fffd2a000
mprotect(0x7f7fffee9000, 2097152, PROT_NONE) = 0
mmap(0x7f80000e9000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1bf000) = 0x7f80000e9000
mmap(0x7f80000ef000, 14752, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f80000ef000
close(3) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f80002ee000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f80002ed000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f80002ec000
arch_prctl(ARCH_SET_FS, 0x7f80002ed700) = 0
mprotect(0x7f80000e9000, 16384, PROT_READ) = 0
mprotect(0x600000, 4096, PROT_READ) = 0
mprotect(0x7f8000318000, 4096, PROT_READ) = 0
munmap(0x7f80002ef000, 156046) = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0
brk(NULL) = 0x220f000
brk(0x2230000) = 0x2230000
write(1, "Hello, world!\n", 14Hello, world!
) = 14
exit_group(0) = ?
+++ exited with 0 +++
%pre%%pre%%pre%%pre%%pre%%pre%>%pre%%pre%%pre%%pre%P\t%pre%%pre%%pre%%pre%%pre%"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1864888, ...}) = 0
mmap(NULL, 3967392, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f7fffd2a000
mprotect(0x7f7fffee9000, 2097152, PROT_NONE) = 0
mmap(0x7f80000e9000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1bf000) = 0x7f80000e9000
mmap(0x7f80000ef000, 14752, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f80000ef000
close(3) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f80002ee000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f80002ed000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f80002ec000
arch_prctl(ARCH_SET_FS, 0x7f80002ed700) = 0
mprotect(0x7f80000e9000, 16384, PROT_READ) = 0
mprotect(0x600000, 4096, PROT_READ) = 0
mprotect(0x7f8000318000, 4096, PROT_READ) = 0
munmap(0x7f80002ef000, 156046) = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0
brk(NULL) = 0x220f000
brk(0x2230000) = 0x2230000
write(1, "Hello, world!\n", 14Hello, world!
) = 14
exit_group(0) = ?
+++ exited with 0 +++
Você ainda pode usar as opções necessárias para strace
, como -o
.
strace
não terá êxito na execução do código-fonte C. Mesmo se você der um caminho com um /
para insistir que tente fazer isso, ele falhará:
Mesmo que você tenha marcado o arquivo .c
, ele ainda não poderá ser executado:
.c
normalmente (ou seja, ./hello.c
falha), você não pode executá-lo com strace
.