简体   繁体   中英

gdb python pretty printer uint64_t is interpreted signed

When I try to use:

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"))

It prints
2929725441843584891:28a879c45a82df7b
But also
9918728419520062851:-7659990ddaef5a7d

When the most significant bit is set for val , it is interpreted as signed.

fData[] is uint64_t .

How can I avoid that? All my values should be unsigned.

At least as a workaround this works for me:

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])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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