Durante desenvolvimento do projeto que faço parte aqui na empresa, tive necessidade de fazer uma depuração de todas as funções chamadas externamente a partir de bibliotecas dinâmicas. Então para aqueles que não conhecem tal recurso existente na glibc, abaixo um exemplo utilizando o comando ls como alvo da depuração.
1) Devemos utilizar a variável de ambiente LD_DEBUG, primeiramente iremos utilizar passando o parâmetro help para em seguida utilizar de acordo com a necessidade!
[root@jiraya ~]# export LD_DEBUG=help [root@jiraya ~]# ls Valid options for the LD_DEBUG environment variable are: libs display library search paths reloc display relocation processing files display progress for input file symbols display symbol table processing bindings display information about symbol binding versions display version dependencies all all previous options combined statistics display relocation statistics unused determined unused DSOs help display this help message and exit To direct the debugging output into a file instead of standard output a filename can be specified using the LD_DEBUG_OUTPUT environment variable. [root@localhost ~]# export LD_DEBUG=libs [root@localhost ~]# ls 5957: find library=librt.so.1 [0]; searching 5957: search cache=/etc/ld.so.cache 5957: trying file=/lib/i686/librt.so.1 5957: 5957: find library=libacl.so.1 [0]; searching 5957: search cache=/etc/ld.so.cache 5957: trying file=/lib/libacl.so.1 5957: 5957: find library=libc.so.6 [0]; searching 5957: search cache=/etc/ld.so.cache 5957: trying file=/lib/i686/libc.so.6 5957: 5957: find library=libpthread.so.0 [0]; searching 5957: search cache=/etc/ld.so.cache 5957: trying file=/lib/i686/libpthread.so.0 5957: 5957: find library=libattr.so.1 [0]; searching 5957: search cache=/etc/ld.so.cache 5957: trying file=/lib/libattr.so.1 5957: 5957: 5957: calling init: /lib/i686/libpthread.so.0 5957: 5957: 5957: calling init: /lib/i686/libc.so.6 5957: 5957: 5957: calling init: /lib/libattr.so.1 5957: 5957: 5957: calling init: /lib/libacl.so.1 5957: 5957: 5957: calling init: /lib/i686/librt.so.1 5957: 5957: 5957: initialize program: ls 5957: 5957: 5957: transferring control: ls 5957: 5957: find library=libnss_files.so.2 [0]; searching 5957: search cache=/etc/ld.so.cache 5957: trying file=/lib/libnss_files.so.2 5957: 5957: 5957: calling init: /lib/libnss_files.so.2 5957: bin get hdparm.sh he he.c seeker src tmp [root@localhost ~]#
2) Caso queira enviar a saída da depuração para um arquivo, basta utilizar a variável de ambiente LD_DEBUG_OUTPUT, abaixo um exemplo de uma depuração completa com o modo all seguido de toda saída sendo enviada para o arquivo ls-debug-calls.log
[root@jiraya ~]# export LD_DEBUG_OUTPUT=ls-debug-calls.log
[root@jiraya ~]# export LD_DEBUG=all
[root@jiraya ~]# ls
3) Para desativar, basta simplesmente remover a variável de ambiente LD_DEBUG e se for o caso também a LD_DEBUG_OUTPUT
[root@jiraya ~]# unset LD_DEBUG
[root@jiraya ~]# unset LD_DEBUG_OUTPUT
[root@jiraya ~]# ls
Mais informações podem ser encontradas em Program-Library-HOWTO






Opa!
Interessante… Não conhecia LD_DEBUG. O link também é muito bom.
Abraço,
Leandro.