Diff between 441ab748ccb51a4199fe2ae1535b40f8d854bc6c and 17e208f6a63fdd888066a83948be99672c62173b

Changed Files

File Additions Deletions Status
emulator/main.c +19 -1 modified

Full Patch

diff --git a/emulator/main.c b/emulator/main.c
index cb77025..aa269c3 100644
--- a/emulator/main.c
+++ b/emulator/main.c
@@ -19,6 +19,8 @@
 #include <getopt.h>
 
 #include "src/shared/mainloop.h"
+#include "src/shared/util.h"
+
 #include "serial.h"
 #include "server.h"
 #include "vhci.h"
@@ -41,6 +43,7 @@ static void usage(void)
 		"Usage:\n");
 	printf("\tbtvirt [options]\n");
 	printf("options:\n"
+		"\t-d                    Enable debug\n"
 		"\t-S                    Create local serial port\n"
 		"\t-s                    Create local server sockets\n"
 		"\t-l[num]               Number of local controllers\n"
@@ -53,6 +56,7 @@ static void usage(void)
 }
 
 static const struct option main_options[] = {
+	{ "debug",   no_argument,       NULL, 'd' },
 	{ "serial",  no_argument,       NULL, 'S' },
 	{ "server",  no_argument,       NULL, 's' },
 	{ "local",   optional_argument, NULL, 'l' },
@@ -66,6 +70,13 @@ static const struct option main_options[] = {
 	{ }
 };
 
+static void vhci_debug(const char *str, void *user_data)
+{
+	int i = PTR_TO_UINT(user_data);
+
+	printf("vhci%u: %s\n", i, str);
+}
+
 int main(int argc, char *argv[])
 {
 	struct server *server1;
@@ -73,6 +84,7 @@ int main(int argc, char *argv[])
 	struct server *server3;
 	struct server *server4;
 	struct server *server5;
+	bool debug_enabled = false;
 	bool server_enabled = false;
 	bool serial_enabled = false;
 	int letest_count = 0;
@@ -86,12 +98,15 @@ int main(int argc, char *argv[])
 	for (;;) {
 		int opt;
 
-		opt = getopt_long(argc, argv, "Ssl::LBAU::T::vh",
+		opt = getopt_long(argc, argv, "dSsl::LBAU::T::vh",
 						main_options, NULL);
 		if (opt < 0)
 			break;
 
 		switch (opt) {
+		case 'd':
+			debug_enabled = true;
+			break;
 		case 'S':
 			serial_enabled = true;
 			break;
@@ -172,6 +187,9 @@ int main(int argc, char *argv[])
 			fprintf(stderr, "Failed to open Virtual HCI device\n");
 			return EXIT_FAILURE;
 		}
+
+		if (debug_enabled)
+			vhci_set_debug(vhci, vhci_debug, UINT_TO_PTR(i), NULL);
 	}
 
 	if (serial_enabled) {