Search code examples
c++templatesgdbcgal

Formatting GDB template arguments in a backtrace


As I work with a C++ template library in GDB (through the terminal), I am trying to find a way of pretty-printing the template arguments when, for instance, viewing a backtrace.

As an example, I am visually trying to find the second (outermost) template argument in this frame that is printed in GDB as follows:

(gdb) f
#10 try_to_refine_element<CGAL::Null_mesh_visitor_level<
CGAL::Mesh_3::tets::Refine_facets_visitor<CGAL::Regular_triangulation_3
<CGAL::Robust_weighted_circumcenter_filtered_traits_3<... (+10397 char)

Gist

These are not STL templates, so STL-template-printing-tools are not applicable, and pretty-printing specific types is not my interest (i.e. custom pretty-printers) as I only want to view the hierarchy of template arguments for a wide variety of classes/methods, rather than representing their content (these use-cases are addressed in the gdb docs). There are also a few pretty-printing in-built settings in GDB but none seem to affect templates (please correct if I've missed them!).

Is there a way of getting GDB to line-break and indent these more readably, or a standard script to use? Template colour coding would be a bonus! For the moment I can cut-paste and run Python to format as desired, but it seems reasonable that a better, tested solution exists.

While I am sure a number of visual IDEs would also solve this, as my general workflow is closely tied to tmux in the terminal, it would be nice to find a compatible solution.


Solution

  • Using frame filters, I've created a GDB Python plugin to provide this: https://github.com/philtweir/gdb-pretty-frame-cpp

    It is not yet well-tested (and only with CGAL/boost/STL/VTK), but if there is interest, I can smarten it up a bit.

    While this is an answer, I would still prefer to hear about any decent, established solution, as this code is still pretty basic.