<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Chris Ball: Tag c</title>
    <link>http://blog.printf.net/articles/tag/c</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Tracing internal function calls in a binary</title>
      <description>&lt;p&gt;Dear everyone who likes Unix,&lt;/p&gt;

&lt;p&gt;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 &lt;code&gt;ltrace(1)&lt;/code&gt;, but for function calls rather than dynamic library calls.  I am bored of adding   &lt;code&gt;g_debug("%s", G_STRFUNC);&lt;/code&gt; to the top of all my functions.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Any ideas?  Thanks!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Update&lt;/em&gt;: &lt;a href="http://superadditive.com"&gt;jmbr&lt;/a&gt; wins, with the only solution that doesn't require anything more than gdb, and no recompile.  Here's his script:  &lt;a href="http://superadditive.com/software/callgraph"&gt;http://superadditive.com/software/callgraph&lt;/a&gt;.  I'd like to work on it to add support for modules loaded with &lt;code&gt;dlopen()&lt;/code&gt;.&lt;/p&gt;</description>
      <pubDate>Fri, 30 Nov 2007 20:27:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:bb5862a9-05e1-48fc-bc29-b6e373cd548a</guid>
      <author>Chris Ball</author>
      <link>http://blog.printf.net/articles/2007/11/30/tracing-internal-function-calls-in-a-binary</link>
      <category>linux</category>
      <category>c</category>
    </item>
  </channel>
</rss>
