pretty印刷的boost :: MPL ::字符串< ...>类型GDB [英] pretty printing boost::mpl::string<...> types in gdb

查看:162
本文介绍了pretty印刷的boost :: MPL ::字符串< ...>类型GDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用的boost :: MPL ::字符串< ...> 类型广泛......以至于它会的真正的帮助,调试有各类$ p $印刷ptty在 GDB

I use boost::mpl::string<...> types extensively... enough that it would really help with debugging to have the types pretty-printed in gdb.

所以...而不是 GDB 显示个人(多字符常量),如目前它的组件...

So... instead of gdb showing the individual (multicharacter literal) components like it currently does ...

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

这将显示等效的字符串值,而不是...

It would display the equivalent string value instead ...

boost::mpl::string<"The way out is through">

我见过 GDB GDB 宏和Python脚本为pretty印刷STL容器,但我无法找到一个为pretty印刷的boost :: MPL 字符串。任何人都可以帮助呢?

I've seen gdb macros and python scripts for pretty-printing STL containers in gdb, but I couldn't find one for pretty-printing boost::mpl strings. Can anyone help with this?

更新:我添加了一个 +100 赏金......我在寻找,利用为pretty印刷的最新GDB支持的解决办法通过Python(如描述这里 STL容器)。

UPDATE: I've added a +100 bounty... I'm looking for a solution that utilizes the latest GDB support for pretty-printing via python (as described here for STL containers).

推荐答案

下面是一个使用助推pretty - 打印机我的解决方案(<一个href=\"https://github.com/ruediger/Boost-$p$ptty-Printer/wiki\">https://github.com/ruediger/Boost-$p$ptty-Printer/wiki):

Here is my solution utilizing Boost-Pretty-Printer (https://github.com/ruediger/Boost-Pretty-Printer/wiki):

文件mpl_printers.py:

File mpl_printers.py:

import printers
import re
import string
import struct

@printers.register_pretty_printer
class BoostMplString:
    "Pretty Printer for 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), ', ')
                for packed in args: 
                    i = int(packed)
                    if i == 0: 
                        break
                    r = ''
                    while i != 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

文件register_printers.gdb:

File register_printers.gdb:

python

# Add the following line in your .gdbinit:
# source /usr/local/share/gdb/register_printers.gdb

import sys
sys.path.insert(0, '/usr/local/share/gdb/python')
# You might have these, too
# from libstdcxx.v6.printers import register_libstdcxx_printers
from boost.printers import register_boost_printers
from boost.mpl_printers import register_boost_mpl_printers

# register_libstdcxx_printers(None)
register_boost_printers(None)
register_boost_mpl_printers(None)

end


  • 安装printers.py和目录上面mpl_printers.py
    在/ usr / local / share下/ GDB /蟒蛇/增强。

  • 确保您有在/ usr / local / share下/ GDB /蟒蛇/升压一个__init__.py(一个空文件将做到这一点)

  • 安装上述
    在/ usr / local / share下/ GDB'register_printers.gdb。

  • 添加源/usr/local/share/gdb/register_printers.gdb在.gdbinit

  • (您可以选择不同的目录)

    (You might choose different directories)

    测试:

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

    gdb的测试-EXB主要-exR-EX'P S'-ex'C'-exQ

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

    $ 1 =(升压:: MPL ::字符串)的Hello World

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

    这篇关于pretty印刷的boost :: MPL ::字符串&LT; ...&GT;类型GDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆