UNIX debugging

[problem]

  1. You want to debug a running process on Solaris?
  2. You want to debug running process on Linux?

[/problem]

[solution]

See the example for debugging processes on Solaris or Linux – the syntax shows all system executes and reads.

[/solution]

[example]

  1. truss -xall -vall -rall -t'read' -p PID #

    To run a command and have it produce debug info, run it prefix with the truss syntax:

    truss -xall -vall -rall -t'read' your command #

    Another good option when debugging, is to run truss and look at the opens. Or more specifically the failures – as this often highlights missing libraries or permissions issues.

    truss -t'open' -p PID #

  2. On Linux use strace, which takes basically the same options. You just use -e, like this:

    strace -e'open' ls
    open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/etc/ld.so.cache", O_RDONLY) = 3
    open("/lib/tls/librt.so.1", O_RDONLY) = 3
    open("/lib/libtermcap.so.2", O_RDONLY) = 3
    open("/lib/libacl.so.1", O_RDONLY) = 3
    open("/lib/tls/libc.so.6", O_RDONLY) = 3
    open("/lib/tls/libpthread.so.0", O_RDONLY) = 3
    open("/lib/libattr.so.1", O_RDONLY) = 3
    open("/usr/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE) = 3
    open(".", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY) = 3
    open("/etc/mtab", O_RDONLY) = 3
    open("/proc/meminfo", O_RDONLY) = 3

[/example]

[reference]

[tags]UNIX Debugging, Solaris Debugging, Linux Debugging, truss, strace, Unix Coding School[/tags]

[/reference]

If you have found my website useful, please consider buying me a coffee below 😉

Leave a Reply

Your email address will not be published. Required fields are marked *