0

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.

1
  • Using pyparsing, for now have a proof-of-concept standalone script to run against a 1-line file containing a frame description (example output). If the answer here is no solid alternative exists, I will try coupling with frame filters and Github it, but as parsing is not my strong-suit, it will be a work-in-progress :) Commented Mar 18, 2016 at 10:03

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

That's about the best you can do. I also wrote a colorizing frame filter :-)
Cool, thanks @tom - I take it that is the one in github.com/tromey/gdb-helpers ? Looks like you have a nice set of gdb extension repos, will have to explore :)
Yeah, that's the one. Be sure to try gdb-gui.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.