Skip to contentSkip to conversation

misc: Improve error reporting on Windows

PATCH Superseded Philippe Mathieu-Daudé 4 participants 8 messages Feb 27, 2020

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover misc: Improve error reporting on Windows

Two patches to improve bug reports on Windows. (i.e. https://bugs.launchpad.net/qemu/+bug/1657841)

Philippe Mathieu-Daudé (2):
chardev: Improve error report by calling error_setg_win32() util/oslib-win32: Improve error report by calling error_setg_win32()

 chardev/char-pipe.c | 2 +-
 chardev/char-win.c  | 2 +-
 util/oslib-win32.c  | 3 ++-
 3 files changed, 4 insertions(+), 3 deletions(-)
Signature · 1 line
2.21.1
#1 lore raw

PATCH 1/2 chardev: Improve error report by calling error_setg_win32()

Use error_setg_win32() which adds a hint similar to strerror(errno)).

---
 chardev/char-pipe.c | 2 +-
 chardev/char-win.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
chardev/char-pipe.c +1 -1
index 94d714ffcd..fd12c9e63b 100644
@@ -70,7 +70,7 @@ static int win_chr_pipe_init(Chardev *chr, const char *filename,
                               MAXCONNECT, NSENDBUF, NRECVBUF, NTIMEOUT, NULL);
     g_free(openname);
     if (s->file == INVALID_HANDLE_VALUE) {
-        error_setg(errp, "Failed CreateNamedPipe (%lu)", GetLastError());
+        error_setg_win32(errp, GetLastError(), "Failed CreateNamedPipe");
         s->file = NULL;
         goto fail;
     }
chardev/char-win.c +1 -1
index 34825f683d..d4fb44c4dc 100644
@@ -96,7 +96,7 @@ int win_chr_serial_init(Chardev *chr, const char *filename, Error **errp)
     s->file = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
                       OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
     if (s->file == INVALID_HANDLE_VALUE) {
-        error_setg(errp, "Failed CreateFile (%lu)", GetLastError());
+        error_setg_win32(errp, GetLastError(), "Failed CreateFile");
         s->file = NULL;
         goto fail;
     }
Signature · 1 line
2.21.1
#4 lore raw

PATCH 2/2 util/oslib-win32: Improve error report by calling error_setg_win32()

In reply to Philippe Mathieu-Daudé

Use error_setg_win32() which adds a hint similar to strerror(errno)).

---
 util/oslib-win32.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
util/oslib-win32.c +2 -1
index e9b14ab178..d2fca1808d 100644
@@ -46,7 +46,8 @@
 void *qemu_oom_check(void *ptr)
 {
     if (ptr == NULL) {
-        fprintf(stderr, "Failed to allocate memory: %lu\n", GetLastError());
+        g_autofree gchar *emsg = g_win32_error_message(GetLastError());
+        fprintf(stderr, "Failed to allocate memory: %s\n", emsg);
         abort();
     }
     return ptr;
Signature · 1 line
2.21.1
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] util/oslib-win32: Improve error report by calling error_setg_win32()

Quoted 6 lines · Philippe Mathieu-Daudé

Use error_setg_win32() which adds a hint similar to strerror(errno)).

---
 util/oslib-win32.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] chardev: Improve error report by calling error_setg_win32()

In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

Use error_setg_win32() which adds a hint similar to strerror(errno)).

---
 chardev/char-pipe.c | 2 +-
 chardev/char-win.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] chardev: Improve error report by calling error_setg_win32()

In reply to Philippe Mathieu-Daudé
Quoted 36 lines · Philippe Mathieu-Daudé

Use error_setg_win32() which adds a hint similar to strerror(errno)).

---
 chardev/char-pipe.c | 2 +-
 chardev/char-win.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
chardev/char-pipe.c +1 -1
index 94d714ffcd..fd12c9e63b 100644
@@ -70,7 +70,7 @@ static int win_chr_pipe_init(Chardev *chr, const char *filename,
                               MAXCONNECT, NSENDBUF, NRECVBUF, NTIMEOUT, NULL);
     g_free(openname);
     if (s->file == INVALID_HANDLE_VALUE) {
-        error_setg(errp, "Failed CreateNamedPipe (%lu)", GetLastError());
+        error_setg_win32(errp, GetLastError(), "Failed CreateNamedPipe");
         s->file = NULL;
         goto fail;
     }
chardev/char-win.c +1 -2
index 34825f683d..d4fb44c4dc 100644
@@ -96,7 +96,7 @@ int win_chr_serial_init(Chardev *chr, const char *filename, Error **errp)
     s->file = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
                       OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
     if (s->file == INVALID_HANDLE_VALUE) {
-        error_setg(errp, "Failed CreateFile (%lu)", GetLastError());
+        error_setg_win32(errp, GetLastError(), "Failed CreateFile");
         s->file = NULL;
         goto fail;
     }
--
Quoted 2 lines

2.21.1

Daniel, do you mind queuing this with the qio patch?

#6 lore raw

Re: [PATCH 2/2] util/oslib-win32: Improve error report by calling error_setg_win32()

In reply to Philippe Mathieu-Daudé
Quoted 12 lines · Philippe Mathieu-Daudé

Use error_setg_win32() which adds a hint similar to strerror(errno)).

---
 util/oslib-win32.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
util/oslib-win32.c +0 -0
index e9b14ab178..d2fca1808d 100644

util/oslib-win32.c line 49

Quoted 5 lines
util/oslib-win32.c +1 -1
@@ -46,7 +46,8 @@
 void *qemu_oom_check(void *ptr)
 {
     if (ptr == NULL) {
-        fprintf(stderr, "Failed to allocate memory: %lu\n", GetLastError());
+        g_autofree gchar *emsg = g_win32_error_message(GetLastError());

Since we're on a path to abort(), I wouldn't bother with g_autofree.

util/oslib-win32.c line 50

Quoted 1 line
util/oslib-win32.c +1 -0
+        fprintf(stderr, "Failed to allocate memory: %s\n", emsg);

Any particular reason not to use error_report()?

Quoted 3 lines
util/oslib-win32.c +0 -0
         abort();
     }
     return ptr;
#7 lore raw

Re: [PATCH 2/2] util/oslib-win32: Improve error report by calling error_setg_win32()

Quoted 9 lines · Markus Armbruster
Quoted 7 lines · Philippe Mathieu-Daudé

Use error_setg_win32() which adds a hint similar to strerror(errno)).

---
  util/oslib-win32.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 12 lines

util/oslib-win32.c line 49

Quoted 10 lines
util/oslib-win32.c +1 -1
index e9b14ab178..d2fca1808d 100644
@@ -46,7 +46,8 @@
  void *qemu_oom_check(void *ptr)
  {
      if (ptr == NULL) {
-        fprintf(stderr, "Failed to allocate memory: %lu\n", GetLastError());
+        g_autofree gchar *emsg = g_win32_error_message(GetLastError());

Since we're on a path to abort(), I wouldn't bother with g_autofree.\

This is in case other developers copy that elsewhere.

Quoted 4 lines

util/oslib-win32.c line 50

Quoted 2 lines
util/oslib-win32.c +1 -0
+        fprintf(stderr, "Failed to allocate memory: %s\n", emsg);

Any particular reason not to use error_report()?

Pre-existing call, but I can change.

Quoted 5 lines
Quoted 4 lines
util/oslib-win32.c +0 -0
          abort();
      }
      return ptr;