diff mbox series

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

Message ID 20240721065047.192558-1-yin31149@gmail.com (mailing list archive)
State New, archived
Headers show
Series scripts/qemugdb/mtree.py: fix error of treating decimal as hexadecimal | expand

Commit Message

Hawkins Jiawei July 21, 2024, 6:50 a.m. UTC
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")
Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
---
 scripts/qemugdb/mtree.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/scripts/qemugdb/mtree.py b/scripts/qemugdb/mtree.py
index 8fe42c3c12..c1557d44fa 100644
--- a/scripts/qemugdb/mtree.py
+++ b/scripts/qemugdb/mtree.py
@@ -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'''