简体   繁体   English

gdb PrettyPrinter插件例程StdStringPrinter在处理std :: basic_string时崩溃 <wchar_t(,.*)?> $

[英]gdb PrettyPrinter Plugin routine StdStringPrinter crashing when dealing with std::basic_string<wchar_t(,.*)?>$

I was analyzing a crash dump where I realized the Python plugin pretty-printer ("/usr/share/gdb/python/libstdcxx/v6/printers.py") has crashed in the following line 我正在分析故障转储,在那我意识到Python插件pretty-printer (“ /usr/share/gdb/python/libstdcxx/v6/printers.py”)在以下行中崩溃了

return self.val['_M_dataplus']['_M_p'].string (encoding, length = len)
LookupError: unknown encoding: UCS-4

as shown below 如下所示

#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

I started analyzing the Code 我开始分析《守则》

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)

and realized there is a call to gdb.parameter with parameters ['gdb.parameter', 'gdb.parameter'] which returns 并实现有呼叫到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

The encoding is passed to self.val['_M_dataplus']['_M_p'].string (encoding, length = len) and my best guess is, it calls str.encode or unicode.encode , but none of them seems to support UCS-4 . 编码被传递给self.val['_M_dataplus']['_M_p'].string (encoding, length = len) ,我最好的猜测是,它调用了str.encodeunicode.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

I strongly feel this is a Bug, any clue or Idea? 我强烈认为这是Bug,有任何线索或想法吗?

It depends on how your Python was built. 这取决于您的Python是如何构建的。 You can do this from gdb to find out: 您可以从gdb执行此操作以找出:

python import sys
python print sys.maxunicode

I haven't seen this one before; 我以前没看过 I would guess most distros build with UCS-4 support. 我想大多数发行版都带有UCS-4支持。

It's also worth considering what wchar_t is on your system. 还值得考虑一下系统上的wchar_t。 Perhaps UCS-4 is wrong there too. 也许UCS-4在那里也是错误的。 You can use "set target-wide-charset" to change this in gdb. 您可以使用“ set target-wide-charset”在gdb中进行更改。 IIRC it's not normally possible for gdb to guess the correct value. IIRC,gdb通常不可能猜测正确的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM