In order to actually do something with the CTF data, we must first obtain it. The location – if everything was compiled and converted appropriately – is the ELF section named “.SUNW_ctf”. Hence I started my today’s research by listing all the sections one by one and for each comparing the name stored in the ELF string table to our searched section name. After a successful match, we proceed to get hold of the actual data. Luckily, the libelf API is well designed and all this was really straightforward. The important part of the code:

The whole code can be found here: elfctf.c (disclaimer: the code is nowhere near ideal state, there are no comments and no error checking, it is just a proof of concept).

After fixing the absence of the elements mentioned above, this code may be used in the rewrite of the CTF toolset, starting with the ctfdump. I would like to keep the libelf code out of the libctf for a simple-enough reason: keeping the library as light as possible when it comes to dependencies.

A small thought near the end: since there is no real connection anymore with the Sun Microsystems or Solaris, it might be suitable to rename this section to pure “.ctf”. There are not that many consumers of the CTF data that would need to change, most notably the D-Trace and the CTF toolset (ctfdump, ctfconvert and ctfmerge).