QEMU user emulation gdbstub emits incorrect file descriptor and errno values

Hi,

There are two bugs in the QEMU user emulation gdbstub code that I co-developed (e282010b2e1):

  1. We render file descriptor and errno integers into GDB remote protocol using "%d" format which is incorrect as GDB expects those values encoded in hexadecimal format. A patch for this has been sent to qemu-devel here (with cc to trivial-devel here).
  2. The errno values should be mapped from host system errno value to a GDB fileio errno value. GDB maps those values with the host_to_fileio_error function called from hostio_error. The values are mmaped via the fileio_error enum defined in the GDB's gdbsupport/fileio.h file.

Additionally, we should probably implement a qGDBServerVersion packet which could be used by clients to detect the QEMU version and use workarounds for known bugs.

PS: Thanks to patryk4815 who found this bug and reported this initially on https://github.com/pwndbg/pwndbg/issues/2648.

Edited by Disconnect3d
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information