Skip to contentSkip to conversation

scripts/qemugdb/mtree.py: fix error of treating decimal as hexadecimal

PATCH New Hawkins Jiawei 1 participant 1 message Jul 21, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts/qemugdb/mtree.py: fix error of treating decimal as hexadecimal

The mtree command throws the following exception:
Python Exception <class 'OverflowError'>: int too big to convert Error occurred in Python: int too big to convert

The mtree command first converts ptr['size'] to a python integer using int128(), then calculates the memory end address by int(addr + (size - 1)). Considering that addr is of type gdb.TYPE_CODE_INT and size is a python integer, python tries to convert size from a python integer to gdb.TYPE_CODE_INT in order to calculate the address.

Yet the problem is that int128() incorrectly treating the deciaml as hexadecimal, resulting in ptr['size'] with 18446744073709551616 vlaue being treated as 0x18446744073709551616, which is too big to convert.

This patch solves the problem by fixing the incorrect treatment in int128(). As a result, gdb can display the output correctly as follows:
0000000000000000-ffffffffffffffff system (I/O) (@ 0x555557273400)
00000000fee00000-00000000feefffff kvm-apic-msi (I/O) (@ 0x555557354ca0)
...

Fixes 8037fa55ac ("scripts/qemugdb/mtree.py: fix up mtree dump")
---
 scripts/qemugdb/mtree.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/qemugdb/mtree.py +1 -1
index 8fe42c3c12..c1557d44fa 100644
@@ -25,7 +25,7 @@ def int128(p):
     if p.type.code == gdb.TYPE_CODE_STRUCT:
         return int(p['lo']) + (int(p['hi']) << 64)
     else:
-        return int(("%s" % p), 16)
+        return int("%s" % p)
 
 class MtreeCommand(gdb.Command):
     '''Display the memory tree hierarchy'''
Signature · 1 line
2.34.1