From c9add9816de672d78e3e4e0e108747ea010d31e5 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Fri, 27 Jan 2023 14:06:00 +0000 Subject: Reduce the debugging level when emulating firmware --- gusb/gusb-context-private.h | 2 ++ gusb/gusb-context.c | 7 +++++++ gusb/gusb-context.h | 1 + gusb/gusb-device.c | 12 ++++++++---- tools/gusb-main.c | 2 ++ 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/gusb/gusb-context-private.h b/gusb/gusb-context-private.h index 9527055..42b7f77 100644 --- a/gusb/gusb-context-private.h +++ b/gusb/gusb-context-private.h @@ -19,5 +19,7 @@ const gchar * _g_usb_context_lookup_vendor(GUsbContext *self, guint16 vid, GError **error); const gchar * _g_usb_context_lookup_product(GUsbContext *self, guint16 vid, guint16 pid, GError **error); +gboolean +_g_usb_context_has_flag(GUsbContext *self, GUsbContextFlags flags); G_END_DECLS diff --git a/gusb/gusb-context.c b/gusb/gusb-context.c index 49e0384..b233209 100644 --- a/gusb/gusb-context.c +++ b/gusb/gusb-context.c @@ -826,6 +826,13 @@ g_usb_context_get_flags(GUsbContext *self) return priv->flags; } +gboolean +_g_usb_context_has_flag(GUsbContext *self, GUsbContextFlags flag) +{ + GUsbContextPrivate *priv = GET_PRIVATE(self); + return (priv->flags & flag) > 0; +} + static gpointer g_usb_context_event_thread_cb(gpointer data) { diff --git a/gusb/gusb-context.h b/gusb/gusb-context.h index b1542da..3c47b5e 100644 --- a/gusb/gusb-context.h +++ b/gusb/gusb-context.h @@ -42,6 +42,7 @@ typedef enum { G_USB_CONTEXT_FLAGS_AUTO_OPEN_DEVICES = 1 << 0, G_USB_CONTEXT_FLAGS_SAVE_EVENTS = 1 << 1, G_USB_CONTEXT_FLAGS_SAVE_REMOVED_DEVICES = 1 << 2, + G_USB_CONTEXT_FLAGS_DEBUG = 1 << 3, /*< private >*/ G_USB_CONTEXT_FLAGS_LAST } GUsbContextFlags; diff --git a/gusb/gusb-device.c b/gusb/gusb-device.c index db3a79c..b94409c 100644 --- a/gusb/gusb-device.c +++ b/gusb/gusb-device.c @@ -404,7 +404,8 @@ _g_usb_device_save(GUsbDevice *self, JsonBuilder *json_builder, GError **error) /* array of BOS descriptors */ bos_descriptors = g_usb_device_get_bos_descriptors(self, &error_bos); if (bos_descriptors == NULL) { - g_debug("%s", error_bos->message); + if (_g_usb_context_has_flag(priv->context, G_USB_CONTEXT_FLAGS_DEBUG)) + g_debug("%s", error_bos->message); } else if (bos_descriptors->len > 0) { json_builder_set_member_name(json_builder, "UsbBosDescriptors"); json_builder_begin_array(json_builder); @@ -419,7 +420,8 @@ _g_usb_device_save(GUsbDevice *self, JsonBuilder *json_builder, GError **error) /* array of interfaces */ interfaces = g_usb_device_get_interfaces(self, &error_interfaces); if (interfaces == NULL) { - g_debug("%s", error_interfaces->message); + if (_g_usb_context_has_flag(priv->context, G_USB_CONTEXT_FLAGS_DEBUG)) + g_debug("%s", error_interfaces->message); } else if (interfaces->len > 0) { json_builder_set_member_name(json_builder, "UsbInterfaces"); json_builder_begin_array(json_builder); @@ -829,7 +831,8 @@ g_usb_device_load_event(GUsbDevice *self, const gchar *id) for (guint i = priv->event_idx; i < priv->events->len; i++) { GUsbDeviceEvent *event = g_ptr_array_index(priv->events, i); if (g_strcmp0(g_usb_device_event_get_id(event), id) == 0) { - g_debug("found in-order %s at position %u", id, i); + if (_g_usb_context_has_flag(priv->context, G_USB_CONTEXT_FLAGS_DEBUG)) + g_debug("found in-order %s at position %u", id, i); priv->event_idx = i + 1; return event; } @@ -839,7 +842,8 @@ g_usb_device_load_event(GUsbDevice *self, const gchar *id) for (guint i = 0; i < priv->events->len; i++) { GUsbDeviceEvent *event = g_ptr_array_index(priv->events, i); if (g_strcmp0(g_usb_device_event_get_id(event), id) == 0) { - g_debug("found out-of-order %s at position %u", id, i); + if (_g_usb_context_has_flag(priv->context, G_USB_CONTEXT_FLAGS_DEBUG)) + g_debug("found out-of-order %s at position %u", id, i); return event; } } diff --git a/tools/gusb-main.c b/tools/gusb-main.c index 8037310..0d6a422 100644 --- a/tools/gusb-main.c +++ b/tools/gusb-main.c @@ -519,6 +519,8 @@ main(int argc, char *argv[]) priv->usb_ctx = g_usb_context_new(NULL); if (save_events) context_flags |= G_USB_CONTEXT_FLAGS_SAVE_EVENTS; + if (verbose) + context_flags |= G_USB_CONTEXT_FLAGS_DEBUG; g_usb_context_set_flags(priv->usb_ctx, context_flags); /* add commands */ -- cgit v1.2.1