我在分析一个崩溃转储,其中我实现了Python插件pretty-printer
(“/usr/share/gdb/Python/libstdcxx/v6)/打印机.py)在以下行中崩溃
return self.val['_M_dataplus']['_M_p'].string (encoding, length = len)
LookupError: unknown encoding: UCS-4
如下图所示
^{pr2}$我开始分析代码
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
或{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
我强烈地感觉到这是一个错误,有什么线索或想法吗?在
这取决于Python是如何构建的。您可以从gdb执行此操作以了解:
我以前没见过这个版本;我想大多数发行版都是用UCS-4支持构建的。在
同样值得考虑的是,您的系统中有哪些wchar_t。也许UCS-4也错了。您可以在gdb中使用“settargetwidecharset”来更改这一点。一般情况下,gdb不可能猜出正确的值。在
相关问题 更多 >
编程相关推荐