4 ms·
Nice work! I wonder if it would be possible to use this infrastructure to write a trace command that I've always wanted, which is one that records internal fun
by cjbprime 9y ago
Nice work!
I wonder if it would be possible to use this infrastructure to write a trace command that I've always wanted, which is one that records internal function calls in the binary.
When I'm feeling overwhelmed with a new codebase, one of the things I like to do to get a handle on the code is to just run some representative command (or make a connection, if it's a server) and see a log of every function that's called with its arguments.
We have strace to do that for system calls, and ltrace to do it for libraries, but nothing that just.. traces. It's shocking to me to think about how many person-years have been lost to debugging by such a command not existing in the C world!
I've seen some hacky and unstable scripts that use gdb to set tracepoints on "*" to get this done, but having a native binary that could do it would be amazing.
- elcritch 9y agoLong ago, in the time before React, I’d forked and fixed an older perl program that prettied up trace output from C programs. The binaries need(ed) to be instrumented using function call hooks feature in GCC (or most any other C compiler) but it’s pretty handy for doing what you described. Faster than GDB tracing usually. I forget the exact details but you can see the setup on my GitHub if you want to try it: https://github.com/elcritch/etrace https://github.com/elcritch/etrace Edit: grammar
- jvns 9y agoyeah I think this would be very possible! I think the hardest part would be the "with its arguments" part. But there's a really useful Rust crate called gimli for parsing DWARF (I found it a lot easier than the C DWARF libraries I looked into).
- elcritch 9y agoThat’d be pretty nifty! Having a program that could show the arguments would be very useful. On a related note, do you know if it’d be possible to store non-exec data in a dwarf binary and parse/load it with the rust libraries? Seems it’d be easier than doing the same in C. P.S. Great article!
- jen20 9y agoThe DTrace PID provider will do exactly that, provided the binary was compiled with frame pointers.