gdb python pretty printer uint64\t被解释为有符号的

2024-10-01 11:27:43 发布

您现在位置:Python中文网/ 问答频道 /正文

当我尝试使用:

class MyPrinter:
        def __init__(self, val):
                self.val = val

        def to_string(self):
                return str(self.val['fData'][0]) + ":" + "%016x" % (self.val['fData'][0]).cast(gdb.lookup_type("uint64_t"))

打印
2929725441843584891:28a879c45a82df7b
但也
9918728419520062851:-7659990ddaef5a7d

当为val设置最高有效位时,它被解释为有符号的。你知道吗

fData[]uint64_t。你知道吗

我怎样才能避免呢?我所有的值都应该是无符号的。你知道吗


Tags: toselfstringreturninitdef符号val
1条回答
网友
1楼 · 发布于 2024-10-01 11:27:43

至少作为一种解决方法,这对我来说是可行的:

class MyPrinter:
        def __init__(self, val):
                self.val = val

        def to_hex(self, val):
                s = ''
                x = 7
                while (x >= 0):
                        s = s + "%02x" % ((val>>(x*8))&255)
                        x -= 1

                return s

        def to_string(self):
                return self.to_hex(self.val['fData'][0]) + self.to_hex(self.val['fData'][1])

相关问题 更多 >