c++ - pretty printing boost::mpl::string<...> types in gdb -


i use boost::mpl::string<...> types extensively... enough really debugging have types pretty-printed in gdb.

so... instead of gdb showing individual (multicharacter literal) components ...

boost::mpl::string<1668248165, 778856802, 778858343, ..., ..., 0, 0, 0, 0, 0, 0> 

it display equivalent string value instead ...

boost::mpl::string<"the way out through"> 

i've seen gdb macros , python scripts pretty-printing stl containers in gdb, couldn't find 1 pretty-printing boost::mpl strings. can this?


update: i've added +100 bounty... i'm looking solution utilizes latest gdb support pretty-printing via python (as described here stl containers).

here solution utilizing boost-pretty-printer (https://github.com/ruediger/boost-pretty-printer/wiki):

file mpl_printers.py:

import printers import re import string import struct  @printers.register_pretty_printer class boostmplstring:     "pretty printer boost::mpl::string"     regex = re.compile('^boost::mpl::string<(.*)>$')      @printers.static     def supports(typename):         return boostmplstring.regex.search(typename)      def __init__(self, typename, value):         self.typename = typename         self.value = value      def to_string(self):             s = ''             try:                 m = boostmplstring.regex.match(self.typename)                 args = string.split(m.group(1), ', ')                 packed in args:                      = int(packed)                     if == 0:                          break                     r = ''                     while != 0:                         i, c = divmod(i, 0x100)                         r += chr(c)                     s += r[::-1]             except runtimeerror:                 s = '[exception]'             return '(boost::mpl::string) %s' % (s)  def register_boost_mpl_printers(obj):     "register boost pretty printers."     pass 

file register_printers.gdb:

python  # add following line in .gdbinit: # source /usr/local/share/gdb/register_printers.gdb  import sys sys.path.insert(0, '/usr/local/share/gdb/python') # might have these, # libstdcxx.v6.printers import register_libstdcxx_printers boost.printers import register_boost_printers boost.mpl_printers import register_boost_mpl_printers  # register_libstdcxx_printers(none) register_boost_printers(none) register_boost_mpl_printers(none)  end 
  • install printers.py , above mpl_printers.py in directory /usr/local/share/gdb/python/boost.
  • ensure have __init__.py in /usr/local/share/gdb/python/boost (an empty file it)
  • install above 'register_printers.gdb' in /usr/local/share/gdb.
  • add 'source /usr/local/share/gdb/register_printers.gdb' in .gdbinit

(you might choose different directories)

test:

#include <boost/mpl/string.hpp> int main() {     boost::mpl::string<'hell','o wo','rld'> s;     return 0; } 

gdb test -ex 'b main' -ex 'r' -ex 'p s' -ex 'c' -ex 'q'

$1 = (boost::mpl::string) hello world


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -