Tracing internal function calls in a binary

Dear everyone who likes Unix,

I have a binary (which uses glib and was compiled from C) and I’d like to get output with the function name each time any function in that binary is called. So, I’d like the output of ltrace(1), but for function calls rather than dynamic library calls. I am bored of adding g_debug("%s", G_STRFUNC); to the top of all my functions.

You’d think this would be easy, given that incredibly similar tools have existed for twenty years, but so far the shortest answer I’ve heard starts “well, you could write a gcc profile function stub that..”. It would be nice not have to recompile, since gdb certainly doesn’t have to, but I’d welcome the way to achieve this with a recompile as well.

Any ideas? Thanks!

Update: jmbr wins, with the only solution that doesn’t require anything more than gdb, and no recompile. Here’s his script: http://superadditive.com/software/callgraph. I’d like to work on it to add support for modules loaded with dlopen().

Spherical cows

Madeleine just started up a webcomic site — everyone should go over to Tipping The Spherical Cow and leave her comments telling her to keep going with it.

We had a tofu turkey for Thanksgiving this year, for the first time. The visible seams were a little disturbing, and it was not entirely tasty though not bad when cold. The dog managed to pull it off the counter the next morning and ate all of the rest of it, which at least saved us from Tofurkey sandwiches for the next week. Here’s a photo:

Mass production

I spent a week (my first time in Asia) in Changshu, China the week before last, in preparation for this:



Congratulations to everyone involved with OLPC. You’re all heroes.