Overview: When attempting to cast a gdb.Value object to a 128bit python integer, the following error is seen: Python Exception <class 'gdb.error'>: Value cannot be represented as integer of 8 bytes. This issue is encountered with gdb 16.3 only when used without client/server mode. This error has been encountered on arm64. NOTE: This bug may be related to a similar bug I filed here: https://sourceware.org/bugzilla/show_bug.cgi?id=33365 Steps to reproduce: Below are the steps to reproduce this issue with gdb 16.3: 1) Begin a gdb debugging session (without client server mode) with any test binary using the above specified version of gdb. 2) Add a breakpoint. 3) Run the program. 4) Once the breakpoint is hit, enter the following commands: python reg = "$v0.q.u[0]" v = gdb.parse_and_eval(reg) int(v) end Actual Results: Upon running the above commands, gdb printed out the following error message: Python Exception <class 'gdb.error'>: Value cannot be represented as integer of 8 bytes. Error occurred in Python: Value cannot be represented as integer of 8 bytes. Expected Results: The expected result is for gdb to successfully perform the cast and return the gdb prompt. Build Date and Hardware: Release 16.3 on Ubuntu 22.04.5 LTS
*** Bug 33365 has been marked as a duplicate of this bug. ***
Confirmed. The fix is probably https://docs.python.org/3/c-api/long.html#c.PyLong_FromNativeBytes. (There's also an unsigned variant.) However that's from 3.13 so we need the workaround mentioned here: https://docs.python.org/3/c-api/long.html#c.PyLong_FromString ... probably conditionally so that someday we can remove the old style.
Meant to say, the fix would be in python/py-value.c:valpy_long
https://sourceware.org/pipermail/gdb-patches/2025-September/220538.html
The master branch has been updated by Tom Tromey <tromey@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=27697103012d289fe279e46a5222308959fe4290 commit 27697103012d289fe279e46a5222308959fe4290 Author: Tom Tromey <tom@tromey.com> Date: Fri Sep 5 05:31:34 2025 -0600 Allow conversion of 128-bit integers to Python Currently, trying to convert a 128-bit integer from a gdb.Value to a Python integer will fail. This is surprising because Python uses bigints internally. The bug here is that valpy_long uses value_as_long, which fails for anything wider than LONGEST. This patch fixes the problem by using the recommended Python API. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33366 Approved-By: Simon Marchi <simon.marchi@efficios.com>
Fixed.