我在分析一个崩溃转储时发现Python插件("/usr/share/gdb/python/libstdcxx/v6/printers.py") pretty-printer在下面的代码行中崩溃了
return self.val['_M_dataplus']['_M_p'].string (encoding, length = len)
LookupError: unknown encoding: UCS-4如下所示
#22 0x00002b25639bb01b in Function(PTR *, const ._210::wstring &, const ._210::wstring &, const ._210::wstring &, bool) (
pPjmDefn=0x2aaab7409e70, pszRepositoryName=
Traceback (most recent call last):
File "/usr/share/gdb/python/libstdcxx/v6/printers.py", line 469, in to_string
return self.val['_M_dataplus']['_M_p'].string (encoding, length = len)
LookupError: unknown encoding: UCS-4我开始分析代码
class StdStringPrinter:
"Print a std::basic_string of some kind"
def __init__(self, encoding, val):
self.encoding = encoding
self.val = val
def to_string(self):
# Look up the target encoding as late as possible.
encoding = self.encoding
if encoding == 0:
encoding = gdb.parameter('target-charset')
elif encoding == 1:
encoding = gdb.parameter('target-wide-charset')
# Make sure &string works, too.
type = self.val.type
if type.code == gdb.TYPE_CODE_REF:
type = type.target ()
# Calculate the length of the string so that to_string returns
# the string according to length, not according to first null
# encountered.
ptr = self.val ['_M_dataplus']['_M_p']
realtype = type.unqualified ().strip_typedefs ()
reptype = gdb.lookup_type (str (realtype) + '::_Rep').pointer ()
header = ptr.cast(reptype) - 1
len = header.dereference ()['_M_length']
return self.val['_M_dataplus']['_M_p'].string (encoding, length = len)并意识到有一个带有参数['gdb.parameter', 'gdb.parameter']的对gdb.parameter的调用,它返回
(gdb) python print gdb.parameter('target-wide-charset')
UCS-4
(gdb) python print gdb.parameter('target-charset')
ANSI_X3.4-1968编码被传递给self.val['_M_dataplus']['_M_p'].string (encoding, length = len),我最好的猜测是,它调用str.encode或unicode.encode,但它们都不是seems to support UCS-4。
>>> u'data'.encode('UCS-4')
Traceback (most recent call last):
File "<pyshell#529>", line 1, in <module>
u'data'.encode('UCS-4')
LookupError: unknown encoding: UCS-4我强烈地感觉到这是一个Bug,有什么线索或想法吗?
发布于 2014-01-24 08:41:20
这取决于Python是如何构建的。您可以在gdb中执行此操作,以了解:
python import sys
python print sys.maxunicode我以前没有见过这个;我猜大多数发行版都是使用UCS-4支持构建的。
同样值得考虑的是您系统上的wchar_t是什么。也许UCS-4在这方面也是错误的。您可以在gdb中使用"set target-wide-charset“来更改此设置。IIRC通常不可能让gdb猜测正确的值。
https://stackoverflow.com/questions/21304973
复制相似问题