Patchwork [RFC,2/2] qemu-log: Interrupt the GDB session on guest-errors

login
register
mail settings
Submitter Edgar Iglesias
Date May 22, 2013, 10:38 a.m.
Message ID <1369219105-9111-3-git-send-email-edgar.iglesias@gmail.com>
Download mbox | patch
Permalink /patch/245584/
State New
Headers show

Comments

Edgar Iglesias - May 22, 2013, 10:38 a.m.
From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com>

Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
---
 qemu-log.c |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
Peter Maydell - May 22, 2013, 10:45 a.m.
On 22 May 2013 11:38,  <edgar.iglesias@gmail.com> wrote:
> From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com>
> @@ -45,6 +46,25 @@ void qemu_log_mask(int mask, const char *fmt, ...)
>          vfprintf(qemu_logfile, fmt, ap);
>      }
>      va_end(ap);
> +
> +    /*
> +     * Break the GDB session (if connected) so that the user can inspect the
> +     * guest state.
> +     *
> +     * TODO: Consider conditionalizing this on a cmdline option.
> +     */

This is definitely way too intrusive to be unconditional -- it can
happen really frequently (for instance Linux on OMAP3 will access
a nonexistent register every time it takes an interrupt).

thanks
-- PMM
Edgar Iglesias - May 22, 2013, 2:04 p.m.
On Wed, May 22, 2013 at 11:45:46AM +0100, Peter Maydell wrote:
> On 22 May 2013 11:38,  <edgar.iglesias@gmail.com> wrote:
> > From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com>
> > @@ -45,6 +46,25 @@ void qemu_log_mask(int mask, const char *fmt, ...)
> >          vfprintf(qemu_logfile, fmt, ap);
> >      }
> >      va_end(ap);
> > +
> > +    /*
> > +     * Break the GDB session (if connected) so that the user can inspect the
> > +     * guest state.
> > +     *
> > +     * TODO: Consider conditionalizing this on a cmdline option.
> > +     */
> 
> This is definitely way too intrusive to be unconditional -- it can
> happen really frequently (for instance Linux on OMAP3 will access
> a nonexistent register every time it takes an interrupt).

Ye, I figured this would be the case.

Maybe a qemu monitor flag controllable from the gdb client itself might be
the most useful, default off. Then one can turn the breaks on/off on
the fly while debugging.

monitor gdb_break_on_guest_errors or something like that.

Cheers,
Edgar

Patch

diff --git a/qemu-log.c b/qemu-log.c
index 797f2af..693bc94 100644
--- a/qemu-log.c
+++ b/qemu-log.c
@@ -19,6 +19,7 @@ 
 
 #include "qemu-common.h"
 #include "qemu/log.h"
+#include "exec/gdbstub.h"
 
 static char *logfilename;
 FILE *qemu_logfile;
@@ -45,6 +46,25 @@  void qemu_log_mask(int mask, const char *fmt, ...)
         vfprintf(qemu_logfile, fmt, ap);
     }
     va_end(ap);
+
+    /*
+     * Break the GDB session (if connected) so that the user can inspect the
+     * guest state.
+     *
+     * TODO: Consider conditionalizing this on a cmdline option.
+     */
+    if (mask & LOG_GUEST_ERROR) {
+        char *msg;
+
+        va_start(ap, fmt);
+        if (vasprintf(&msg, fmt, ap) < 0) {
+            msg = NULL;
+        }
+        va_end(ap);
+
+        gdbserver_break(msg);
+        g_free(msg);
+    }
 }
 
 /* enable or disable low levels log */