Template metaprogramming is an emerging new direction in C++ programming in which template definitions are used to control the compilation process so that during compile-time a (meta)program is executed. Template metaprograms are used for compile-time code optimisation, static interface checking, enhancing the type system, and for language embedding.
Unfortunately, template metaprogramming is not yet supported with sufficient software tools (e.g. debugger, profiler, etc.).
We would like to demonstrate Templight, a research prototype debugging framework that reveals the steps executed by the compiler during the compilation of C++ programs with templates. Templight's features include following the instantiation chain, setting breakpoints, and inspecting metaprogram information. This framework aims to take a step forward to help template metaprogramming become more accepted in the software industry.
Templight's approach is to create a trace file that contains all template instantiations, the appropriate template parameters, the inner definitions, timestamps for a profiler etc. Doing this step by step along the compilation process we can apply the tools to analyse the behaviour of our template metaprograms. Our Templight utility is capable of gathering this information. Templight's working process is as follows.
First Templight preprocesses the source code, then annotates it generating an XML file with important structural information about the source code (including beginning/end of class templates, typedefs, etc). Next using this XML file Templight instruments the code with code segments that generate some well-defined warning messages when being compiled (these messages may vary from compiler to compiler). The compilation output is then processed, resulting in another XML file containing information about the compilation and the instantiation chain itself. This file can now be analysed for a post-mortem debugging process. On the other hand, the result XML file may be used for profiling if timestamps are also recorded for the relevant items.
A recently developed IDE front-end extension provides user friendly interface for Templight. This includes the placing and removing of breakpoints, following the compilation process, and examination of the instantiation stack.
Templight currently working with Microsoft Visual Studio, but there is an undergoing development for porting it for the gnu g++ compiler.