Logging C Functions
It&#x27;s not hard to make an ftrace facility for C functions. I did it with [1] and [2] (using a concept I call &quot;stackpools&quot;) for this comment since I&#x27;ve had it in mind for a while, and this post pushed me to do it.<p>What jart&#x27;s does better than mine is that hers is not opt-in; you don&#x27;t have to put special macros for it. Mine requires that. Hers also can instrument all functions; mine does not get external functions.<p>What mine does better is that it is not a security issue wrt W^X, and it also implements scope- and function-based RAII. For example, now that I have implemented it, I can change all of my direct calls to unlock mutexes at the end of a function into destructors, and change the lock calls to use the stackpools. After doing that, then any function that buys into the system I have, and that takes a lock, will release the lock by the end of the function without anything special, just like using RAII with locks in C++.<p>I can turn ftracing on and off at build time as well. [3]<p>Using the tests&#x2F;gaml&#x2F;gaml_fuzz program, which is still incomplete, you can see this. Assuming the build directory is `build&#x2F;`, running:<p><pre><code>    cat ..&#x2F;build.gaml | tests&#x2F;gaml&#x2F;gaml_fuzz
</code></pre>
with ftracing turned on will give you an ftrace that looks like:<p><pre><code>    main()
      y_fs_filebytes_fread()
        y_strucon_handleError()
        y_strucon_handleError()
      y_fs_filebytes_fread()
      y_strucon_status()
      y_strucon_status()
      y_exit()
</code></pre>
I could make it prettier, and I probably will in subsequent commits.<p>In other words, it&#x27;s not magic, and in my opinion, it&#x27;s not really a good idea because of the security implications because while you could argue that it&#x27;s only for development, it&#x27;s still another route to gain access to a developer&#x27;s machine or a CI machine.<p>[1]: <a href="https:&#x2F;&#x2F;git.yzena.com&#x2F;Yzena&#x2F;Yc&#x2F;src&#x2F;commit&#x2F;80713280c4298505539fd0c1402585a7d8ba0456&#x2F;src&#x2F;pool&#x2F;stackpool.c#L496-L561" rel="nofollow">https:&#x2F;&#x2F;git.yzena.com&#x2F;Yzena&#x2F;Yc&#x2F;src&#x2F;commit&#x2F;80713280c429850553...</a><p>[2]: <a href="https:&#x2F;&#x2F;git.yzena.com&#x2F;Yzena&#x2F;Yc&#x2F;src&#x2F;commit&#x2F;80713280c4298505539fd0c1402585a7d8ba0456&#x2F;src&#x2F;concurrency&#x2F;strucon.h#L403-L523" rel="nofollow">https:&#x2F;&#x2F;git.yzena.com&#x2F;Yzena&#x2F;Yc&#x2F;src&#x2F;commit&#x2F;80713280c429850553...</a><p>[3]: <a href="https:&#x2F;&#x2F;git.yzena.com&#x2F;Yzena&#x2F;Yc&#x2F;src&#x2F;commit&#x2F;80713280c4298505539fd0c1402585a7d8ba0456&#x2F;CMakeLists.txt#L64-L70" rel="nofollow">https:&#x2F;&#x2F;git.yzena.com&#x2F;Yzena&#x2F;Yc&#x2F;src&#x2F;commit&#x2F;80713280c429850553...</a>