debugging c++ template metaprograms. structure template metaprogramming (tmp) debugging –in...

23
Debugging C++ template metaprograms

Upload: melinda-chambers

Post on 17-Jan-2016

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Debugging C++ template metaprograms. Structure Template metaprogramming (TMP) Debugging –In general –TMP Templight framework –Idea –implementation Results

Debugging C++ template metaprograms

Page 2: Debugging C++ template metaprograms. Structure Template metaprogramming (TMP) Debugging –In general –TMP Templight framework –Idea –implementation Results

Structure

• Template metaprogramming (TMP)

• Debugging– In general– TMP

• Templight framework– Idea– implementation

• Results

Page 3: Debugging C++ template metaprograms. Structure Template metaprogramming (TMP) Debugging –In general –TMP Templight framework –Idea –implementation Results

Template metaprogramming

• C++ generics are Turing complete, we can implement algorithms that run in compile time

• Factorial example

Page 4: Debugging C++ template metaprograms. Structure Template metaprogramming (TMP) Debugging –In general –TMP Templight framework –Idea –implementation Results

Comparison

• Run time vs. compile time

<table>

Page 5: Debugging C++ template metaprograms. Structure Template metaprogramming (TMP) Debugging –In general –TMP Templight framework –Idea –implementation Results

TMP ontology 1

• Ill-formed and well-formed programswell-formed = according to language rules

Page 6: Debugging C++ template metaprograms. Structure Template metaprogramming (TMP) Debugging –In general –TMP Templight framework –Idea –implementation Results

TMP ontology 2

Page 7: Debugging C++ template metaprograms. Structure Template metaprogramming (TMP) Debugging –In general –TMP Templight framework –Idea –implementation Results

Debugging in general

Page 8: Debugging C++ template metaprograms. Structure Template metaprogramming (TMP) Debugging –In general –TMP Templight framework –Idea –implementation Results

Debugging TMP

Page 9: Debugging C++ template metaprograms. Structure Template metaprogramming (TMP) Debugging –In general –TMP Templight framework –Idea –implementation Results

Today’s possibilities

• Compiler support (preferred long term solution)

• Language elementsSince we don’t have compiler support, use the existing language elements and the analogue between run time and metaprograms

Page 10: Debugging C++ template metaprograms. Structure Template metaprogramming (TMP) Debugging –In general –TMP Templight framework –Idea –implementation Results

If we had a trace file?

• We can debug a program a posteriori if we have a trace of the run

• Therefore if we had such a trace file for template metaprograms then we would be able to debug them

Page 11: Debugging C++ template metaprograms. Structure Template metaprogramming (TMP) Debugging –In general –TMP Templight framework –Idea –implementation Results

Warnings are talkative

• Today’s compilers usually display warning messages that contain essential contextual information

• Artificially generate such warnings

Page 12: Debugging C++ template metaprograms. Structure Template metaprogramming (TMP) Debugging –In general –TMP Templight framework –Idea –implementation Results

Portable warning

• Consider the following line:…

Build outputsG++ Watcom

MSVC 7.1, 8.0 Comeau

Etc.

Page 13: Debugging C++ template metaprograms. Structure Template metaprogramming (TMP) Debugging –In general –TMP Templight framework –Idea –implementation Results

Step #1: preprocessing

• Use the existing preprocessor to obtain a single source file

Page 14: Debugging C++ template metaprograms. Structure Template metaprogramming (TMP) Debugging –In general –TMP Templight framework –Idea –implementation Results

Step #2: instrumentation

• Insert our specially designed warnings to the interested positions

Page 15: Debugging C++ template metaprograms. Structure Template metaprogramming (TMP) Debugging –In general –TMP Templight framework –Idea –implementation Results

Step #3: Build -> warnings

• Feed the compiler with this modified source and save the warnings

Page 16: Debugging C++ template metaprograms. Structure Template metaprogramming (TMP) Debugging –In general –TMP Templight framework –Idea –implementation Results

Step #4: warnings -> trace file

• Gather the information from the warnings and create a trace file for further use

Page 17: Debugging C++ template metaprograms. Structure Template metaprogramming (TMP) Debugging –In general –TMP Templight framework –Idea –implementation Results

Results: TMP debugger IDE

• How it looks like in real

Page 18: Debugging C++ template metaprograms. Structure Template metaprogramming (TMP) Debugging –In general –TMP Templight framework –Idea –implementation Results

Ideal compiler support

• Special output to migrate these hacks into the compiler

Page 19: Debugging C++ template metaprograms. Structure Template metaprogramming (TMP) Debugging –In general –TMP Templight framework –Idea –implementation Results

Limitations

• Different levels (no output, only partial info)

• Simple pattern matching is not strong enough, ambiguity

Page 20: Debugging C++ template metaprograms. Structure Template metaprogramming (TMP) Debugging –In general –TMP Templight framework –Idea –implementation Results

Related work

• Profiling

• TMP book efficieny measurements

• Tracer

• Mpl::print

• archetype

Page 21: Debugging C++ template metaprograms. Structure Template metaprogramming (TMP) Debugging –In general –TMP Templight framework –Idea –implementation Results

Future directions

• Eliminate limitations

• Profiling

• IDE integration

• Compiler support

Page 22: Debugging C++ template metaprograms. Structure Template metaprogramming (TMP) Debugging –In general –TMP Templight framework –Idea –implementation Results

Conclusion

• This is a prototype that works with limitations

• With compiler support useful tools could be easily created

Page 23: Debugging C++ template metaprograms. Structure Template metaprogramming (TMP) Debugging –In general –TMP Templight framework –Idea –implementation Results

Contact

• Home page