lguest: debugging patch to dump device state
---
 Documentation/lguest/lguest.c |   26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff -r cb860c7e59a1 Documentation/lguest/lguest.c
--- a/Documentation/lguest/lguest.c	Mon May 05 08:49:10 2008 +1000
+++ b/Documentation/lguest/lguest.c	Mon May 05 09:20:25 2008 +1000
@@ -777,6 +777,28 @@ struct console_abort
 	struct timeval start;
 };
 
+static void dump_devices(void)
+{
+	struct device *i;
+	struct virtqueue *vq;
+
+	/* Check each virtqueue. */
+	for (i = devices.dev; i; i = i->next) {
+		printf("Device %s:\n", i->name);
+		for (vq = i->vq; vq; vq = vq->next) {
+			printf("  Virtqueue %p:\n", vq);
+			printf("   num = %u\n", vq->vring.num);
+			printf("   avail: flags=%u idx=%u (last=%u)\n",
+			       vq->vring.avail->flags,
+			       vq->vring.avail->idx,
+			       vring_last_avail(&vq->vring));
+			printf("   used: flags=%u idx=%u\n",
+			       vq->vring.used->flags,
+			       vq->vring.used->idx);
+		}
+	}
+}
+
 /* This is the routine which handles console input (ie. stdin). */
 static bool handle_console_input(int fd, struct device *dev)
 {
@@ -833,10 +855,12 @@ static bool handle_console_input(int fd,
 				/* Just in case waker is blocked in BREAK, send
 				 * unbreak now. */
 				write(fd, args, sizeof(args));
+				dump_devices();
 				exit(2);
 			}
 			abort->count = 0;
-		}
+		} else if (abort->count == 2)
+			dump_devices();
 	} else
 		/* Any other key resets the abort counter. */
 		abort->count = 0;
