gdb/python: generalize serialize_mi_result()

This commit generalizes serialize_mi_result() to make usable in
different contexts than printing result of custom MI command.

To do so, the check whether passed Python object is a dictionary has been
moved to the caller - at the very least, different uses require different
error messages.  Also it has been renamed to serialize_mi_results() to better
match GDB/MI output syntax (see corresponding section in documentation,
in particular rules 'result-record' and 'async-output'.

Since it is now more generic function, it has been moved to py-mi.c.

This is a preparation for implementing Python support for sending custom
MI async events.

Approved-By: Andrew Burgess <aburgess@redhat.com>
This commit is contained in:
Jan Vrany
2023-10-10 11:22:56 +01:00
parent 1fb3cdd87e
commit 80a3485f81
3 changed files with 181 additions and 176 deletions

View File

@@ -486,6 +486,19 @@ struct gdbarch *arch_object_to_gdbarch (PyObject *obj);
extern PyObject *gdbpy_execute_mi_command (PyObject *self, PyObject *args,
PyObject *kw);
/* Serialize RESULTS and print it in MI format to the current_uiout.
This function handles the top-level results passed as a dictionary.
The caller is responsible for ensuring that. The values within this
dictionary can be a wider range of types. Handling the values of the top-level
dictionary is done by serialize_mi_result_1, see that function for more
details.
If anything goes wrong while parsing and printing the MI output then an
error is thrown. */
extern void serialize_mi_results (PyObject *results);
/* Convert Python object OBJ to a program_space pointer. OBJ must be a
gdb.Progspace reference. Return nullptr if the gdb.Progspace is not
valid (see gdb.Progspace.is_valid), otherwise return the program_space