divendres, 23 de març de 2012

Strace, eixa gran utilitat

A voltes estem configurant una aplicació i quan l'executem l'aplicació fa un crash i no podem obtenir informació de que esta passant.

El que podem fer es interceptar les cridades al sistema i tratar d'entendre que produeix el crash a l'aplicació. Aquesta funcionalitat ens la proporciona strace.

En aquest example l'aplicació sqldeveloper falla i no es veu perquè.

strace sqldeveloper 

Que mostra la següent eixida:

execve("/usr/bin/sqldeveloper", ["sqldeveloper"], [/* 44 vars */]) = 0
brk(0)                                  = 0x1722000
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) = 0x7f107a464000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=78060, ...}) = 0
mmap(NULL, 78060, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f107a450000
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) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0 \24\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1685816, ...}) = 0
mmap(NULL, 3801960, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f1079ea5000
mprotect(0x7f107a03c000, 2093056, PROT_NONE) = 0
mmap(0x7f107a23b000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x196000) = 0x7f107a23b000
mmap(0x7f107a240000, 21352, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f107a240000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f107a44f000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f107a44d000
arch_prctl(ARCH_SET_FS, 0x7f107a44d720) = 0
mprotect(0x7f107a23b000, 16384, PROT_READ) = 0
mprotect(0x619000, 4096, PROT_READ)     = 0
mprotect(0x7f107a466000, 4096, PROT_READ) = 0
munmap(0x7f107a450000, 78060)           = 0
getpid()                                = 27105
rt_sigaction(SIGCHLD, {SIG_DFL, [CHLD], SA_RESTORER|SA_RESTART, 0x7f1079edb420}, {SIG_DFL, [], 0}, 8) = 0
geteuid()                               = 1000
brk(0)                                  = 0x1722000
brk(0x1743000)                          = 0x1743000
getppid()                               = 27104
stat("/home/melkor", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat(".", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
open("/usr/bin/sqldeveloper", O_RDONLY) = 3
fcntl(3, F_DUPFD, 10)                   = 10
close(3)                                = 0
fcntl(10, F_SETFD, FD_CLOEXEC)          = 0
rt_sigaction(SIGINT, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGINT, {0x40f050, ~[RTMIN RT_1], SA_RESTORER, 0x7f1079edb420}, NULL, 8) = 0
rt_sigaction(SIGQUIT, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGQUIT, {SIG_DFL, ~[RTMIN RT_1], SA_RESTORER, 0x7f1079edb420}, NULL, 8) = 0
rt_sigaction(SIGTERM, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGTERM, {SIG_DFL, ~[RTMIN RT_1], SA_RESTORER, 0x7f1079edb420}, NULL, 8) = 0
read(10, "#!/bin/sh\nset -e\n\n# sqldeveloper"..., 8192) = 3041
pipe([3, 4])                            = 0
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f107a44d9f0) = 27106
close(4)                                = 0
read(3, "sqldeveloper\n", 128)          = 13
read(3, "", 128)                        = 0
close(3)                                = 0
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 27106
--- SIGCHLD (Child exited) @ 0 (0) ---
stat("/home/melkor/.sqldeveloper/jdk", {st_mode=S_IFREG|0664, st_size=33, ...}) = 0
pipe([3, 4])                            = 0
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f107a44d9f0) = 27107
close(4)                                = 0
read(3, "/usr/lib/jvm/java-6-openjdk/jre/"..., 128) = 33
read(3, "", 128)                        = 0
close(3)                                = 0
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 27107
--- SIGCHLD (Child exited) @ 0 (0) ---
stat("/usr/lib/jvm/java-6-openjdk/jre//bin/javac", 0x7fffd27b6d70) = -1 ENOENT (No such file or directory)
stat("/usr/bin/x-terminal-emulator", {st_mode=S_IFREG|0755, st_size=1394, ...}) = 0
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f107a44d9f0) = 27108
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 27108
--- SIGCHLD (Child exited) @ 0 (0) ---
read(10, "", 8192)                      = 0
exit_group(0)                           = ?
[7]+  Hecho                   sqldeveloper

Si analitzem aquesta eixida podem deduïr que el que esta fallant es la ruta al jdk que està mal configurada.

stat("/usr/lib/jvm/java-6-openjdk/jre//bin/javac", 0x7fffd27b6d70) = -1 ENOENT (No such file or directory)

1 comentari:

  1. Una característica molt útil de strace es que pot fer un attach/detach a un proces que esta corrent:
    strace -ttT -p

    ResponElimina