C++ 漂亮的打印boost::mpl::string<&燃气轮机;gdb中的类型
我广泛使用C++ 漂亮的打印boost::mpl::string<&燃气轮机;gdb中的类型,c++,boost,gdb,metaprogramming,boost-mpl,C++,Boost,Gdb,Metaprogramming,Boost Mpl,我广泛使用boost::mpl::string类型。。。足够让这些类型在gdb中漂亮地打印出来,这将真正有助于调试 所以。。。与当前显示单个(多字符文字)组件的gdb不同 boost::mpl::string<1668248165, 778856802, 778858343, ..., ..., 0, 0, 0, 0, 0, 0> boost::mpl::string 它将显示等效的字符串值,而不是 boost::mpl::string<"The way out is th
boost::mpl::string
类型。。。足够让这些类型在gdb
中漂亮地打印出来,这将真正有助于调试
所以。。。与当前显示单个(多字符文字)组件的gdb不同
boost::mpl::string<1668248165, 778856802, 778858343, ..., ..., 0, 0, 0, 0, 0, 0>
boost::mpl::string
它将显示等效的字符串值,而不是
boost::mpl::string<"The way out is through">
boost::mpl::string
我在gdb
中看到了用于漂亮地打印STL容器的gdb
宏和python脚本,但是我找不到用于漂亮地打印boost::mpl
字符串的脚本。有人能帮忙吗
更新:我添加了一个+100赏金。。。我正在寻找一种解决方案,它利用最新的GDB支持通过python进行漂亮的打印(如STL容器所述)。这是我利用Boost pretty Printer()的解决方案: 文件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
- 在目录中安装printers.py和上述mpl_printers.py /usr/local/share/gdb/python/boost
- 确保您在/usr/local/share/gdb/python/boost中有一个_uinit__; py.py(一个空文件就可以了)
- 安装上述组件 在/usr/local/share/gdb中“register_printers.gdb”李>
- 在.gdbinit中添加“source/usr/local/share/gdb/register_printers.gdb”
#包括
int main(){
boost::mpl::string s;
返回0;
}
gdb测试-ex'b main'-ex'r'-ex'p s'-ex'c'-ex'q'
$1=(boost::mpl::string)hello world就像一个魔咒!现在我可以使用同样的方法用python轻松地美化其他类型名。谢谢。@etherice请有朝一日发布您的打印机。为了澄清说明中的几个部分:
printers.py
和mpl\u printers.py
应该放在boost
子目录中(即/usr/local/share/gdb/python/boost
),因此register\u printers.gdb
中的模块名称是有效的。另外,boost
子目录必须包含一个\uuu init\uu uuu.py
文件(可以是空的),以便python将其识别为包含模块的目录(否则,您将得到一个ImportError:没有名为boost.printers的模块)。再次感谢您提供了一个优雅的解决方案,它完全符合要求。
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
#include <boost/mpl/string.hpp>
int main() {
boost::mpl::string<'hell','o wo','rld'> s;
return 0;
}