Boost logo

Boost :

Subject: [boost] GDB-like debugger for template metaprograms
From: Abel Sinkovics (abel_at_[hidden])
Date: 2014-11-26 15:22:18


Hi,

Metashell 2.0.0 has a template metaprogram debugger with a GDB-like
interface (thanks to András Kucsma), which can be useful for Boost
developers. It can show you how your metaprogram is executed
step-by-step. You can set breakpoints, step into or over the
metafunction calls and inspect the "template metaprogramming stack
trace" at any point during this: the chain of recursive template
instantiations that lead to that point. Here is an example:

> #include <boost/mpl/transform.hpp>
> #include <boost/mpl/vector_c.hpp>
> #include <boost/mpl/plus.hpp>
> #include <boost/mpl/lambda.hpp>
> #include <boost/mpl/int.hpp>
> using namespace boost::mpl;
> #msh mdb transform<vector_c<int, 1, 2, 3, 4, 5>, plus<_1, int_<1>>>::type
For help, type "help".
Metaprogram started
(mdb) rbreak ^boost::mpl::plus
Breakpoint "^boost::mpl::plus" will stop the execution on 25 locations
(mdb) continue
Breakpoint "^boost::mpl::plus" reached
boost::mpl::plus<mpl_::integral_c<int, 1>, mpl_::int_<1>, mpl_::na,
mpl_::na, mpl_::na> (Memoization)
(mdb) bt
#0 boost::mpl::plus<mpl_::integral_c<int, 1>, mpl_::int_<1>, mpl_::na,
mpl_::na, mpl_::na> (Memoization)
#1 boost::mpl::quote_impl<boost::mpl::plus<mpl_::integral_c<int, 1>,
mpl_::int_<1>, mpl_::na, mpl_::na, mpl_::na>, true> (TemplateInstantiation)
#2 boost::mpl::quote5<plus, mpl_::void_>::apply<mpl_::integral_c<int,
1>, mpl_::int_<1>, mpl_::na, mpl_::na, mpl_::na> (TemplateInstantiation)
#3 boost::mpl::apply_wrap5<boost::mpl::quote5<plus, mpl_::void_>,
mpl_::integral_c<int, 1>, mpl_::int_<1>, mpl_::na, mpl_::na, mpl_::na>
(TemplateInstantiation)
...
#19 transform<vector_c<int, 1, 2, 3, 4, 5>, plus<_1, int_<1>>>::type

You can try Metashell from your browser: http://abel.web.elte.hu/shell
Or you can install it on your computer:
https://github.com/sabel83/metashell#version-200

Binary installers are available for a number of Linux distributions,
Windows and Mac OS X.

Feedback is welcome.

Regards,
   Ãbel


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk