Add ioctl_tree library

This provides a more efficient and flexible format than a simple list of
ioctls, and is also less invasive to extend with more ioctls.
Move ioctl recording to ioctl_tree

Keep the tree in memory during recording and write it out on closing the
recorded file descriptor. Note, at some point the writing also needs to happen
in an atexit(), in case the traced program does not properly close the fd
itself.