Last Updated: 2022-05-26
What would you do if
strace does not give you the info you need for debugging, if it seems
like it's hiding some of the action from you?
Advi Grim in his Ruby Tapas screencasts wanted to use
strace to see the calls
getenv (a command for getting environment variables) when running ruby
But this failed to surface any useful info? Why?
getenv is a library call, not a system call.
System calls and library calls are similar in that their functionality is provided to your application by the execution environment. The difference is that system calls are implemented in kernel, whereas library calls are implemented in user space.
Thus the distinction:
stracejust gives system calls.
ltrace(l stands for library) gives library calls
Basically you need to tell it what library call to monitor and then the binary in question.
$ ltrace -e LIBCALL YOUR_BINARY ARGS
ltrace -e genenv bundle
Gotcha: If you try running with
bundle as above (the bundle command being
written in Ruby) it will fail since
ltrace wants a binary.
How to get around this? Well the
ruby command is a binary, so we modify
the call to
ltrace to use Ruby with the
bundle command as an argument:
$ ltrace -e getenv ruby /usr/local/bin/bundle