public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Use field_signed from Python MI commands
@ 2023-05-23 19:47 Tom Tromey
0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2023-05-23 19:47 UTC (permalink / raw)
To: gdb-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d5ad08d77c92e50f24798f357dd688b9060c6f68
commit d5ad08d77c92e50f24798f357dd688b9060c6f68
Author: Tom Tromey <tromey@adacore.com>
Date: Thu Mar 23 11:54:46 2023 -0600
Use field_signed from Python MI commands
If an MI command written in Python includes a number in its output,
currently that is simply emitted as a string. However, it's
convenient for a later patch if these are emitted using field_signed.
This does not make a difference to ordinary MI clients.
Diff:
---
gdb/python/py-micmd.c | 15 +++++++++++++++
gdb/python/python-internal.h | 2 ++
2 files changed, 17 insertions(+)
diff --git a/gdb/python/py-micmd.c b/gdb/python/py-micmd.c
index e86807d049f..d7d95918cb4 100644
--- a/gdb/python/py-micmd.c
+++ b/gdb/python/py-micmd.c
@@ -293,6 +293,21 @@ serialize_mi_result_1 (PyObject *result, const char *field_name)
}
else
{
+ if (PyLong_Check (result))
+ {
+ int overflow = 0;
+ gdb_py_longest val = gdb_py_long_as_long_and_overflow (result,
+ &overflow);
+ if (PyErr_Occurred () != nullptr)
+ gdbpy_handle_exception ();
+ if (overflow == 0)
+ {
+ uiout->field_signed (field_name, val);
+ return;
+ }
+ /* Fall through to the string case on overflow. */
+ }
+
gdb::unique_xmalloc_ptr<char> string (gdbpy_obj_to_string (result));
if (string == nullptr)
gdbpy_handle_exception ();
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index dbd33570a78..1142e0e739d 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -110,6 +110,7 @@
typedef PY_LONG_LONG gdb_py_longest;
typedef unsigned PY_LONG_LONG gdb_py_ulongest;
#define gdb_py_long_as_ulongest PyLong_AsUnsignedLongLong
+#define gdb_py_long_as_long_and_overflow PyLong_AsLongLongAndOverflow
#else /* HAVE_LONG_LONG */
@@ -118,6 +119,7 @@ typedef unsigned PY_LONG_LONG gdb_py_ulongest;
typedef long gdb_py_longest;
typedef unsigned long gdb_py_ulongest;
#define gdb_py_long_as_ulongest PyLong_AsUnsignedLong
+#define gdb_py_long_as_long_and_overflow PyLong_AsLongAndOverflow
#endif /* HAVE_LONG_LONG */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-05-23 19:47 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-23 19:47 [binutils-gdb] Use field_signed from Python MI commands Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).