From: "Alex Bennée" <alex.bennee@linaro.org>
To: Programmingkid <programmingkidx@gmail.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
Gerd Hoffmann <kraxel@redhat.com>,
qemu-devel qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH 3/3] hid.c: Add debug support
Date: Sat, 26 Mar 2016 06:48:09 +0000 [thread overview]
Message-ID: <87io09viom.fsf@linaro.org> (raw)
In-Reply-To: <7A168ABF-EB8A-43E5-9821-F4D8AD9B6E53@gmail.com>
Programmingkid <programmingkidx@gmail.com> writes:
> Add debug macros to the code for easier debugging.
>
> Signed-off-by: John Arbuckle <programmingkidx@gmail.com>
> ---
> hw/input/hid.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/hw/input/hid.c b/hw/input/hid.c
> index 329a27b..42ca592 100644
> --- a/hw/input/hid.c
> +++ b/hw/input/hid.c
> @@ -37,6 +37,13 @@
> #define RELEASED -1
> #define PUSHED -2
>
> +/* #define DEBUG_HID_CODE */
> +#ifdef DEBUG_HID_CODE
> + #define DEBUG_HID(fmt, ...) printf(fmt, __VA_ARGS__)
> +#else
> + #define DEBUG_HID(fmt, ...) (void)0
> +#endif
> +
This style of debug setup is discouraged these days as its prone to
bitrot. It's better to define like this:
#define DEBUG_HID(fmt, ...) \
if (DEBUG_HID_CODE) { \
printf(fmt, __VA_ARGS);\
}
This means you get the benefit of the compiler checking your format
strings even if the code gets optimised away when DEBUG_HID_CODE isn't
defined.
> /* Translates a QKeyCode to USB HID value */
> static const uint8_t qcode_to_usb_hid[] = {
> [Q_KEY_CODE_SHIFT] = USB_HID_LEFT_SHIFT,
> @@ -331,6 +338,7 @@ static void hid_keyboard_event(DeviceState *dev, QemuConsole *src,
> return;
> }
> keycode = qcode_to_usb_hid[qcode];
> + DEBUG_HID("keycode = 0x%x qcode:%d\n", keycode, qcode);
>
> count = 2;
> if (evt->u.key.data->down == false) { /* if key up event */
> @@ -381,6 +389,9 @@ static void hid_keyboard_process_keycode(HIDState *hs)
> slot = hs->head & QUEUE_MASK; QUEUE_INCR(hs->head); hs->n--;
> keycode = hs->kbd.keycodes[slot];
>
> + DEBUG_HID("keycode:0x%x status:%s\n", keycode, (status == PUSHED ? "Pushed"
> + : "Released"));
> +
> /* handle Control, Option, GUI/Windows/Command, and Shift keys */
> if (keycode >= 0xe0) {
> process_modifier_key(status, keycode, &(hs->kbd.modifiers));
--
Alex Bennée
next prev parent reply other threads:[~2016-03-26 6:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-25 16:10 [Qemu-devel] [PATCH 3/3] hid.c: Add debug support Programmingkid
2016-03-26 6:48 ` Alex Bennée [this message]
2016-03-27 14:30 ` Programmingkid
2016-03-27 17:59 ` Alex Bennée
-- strict thread matches above, loose matches on Subject: below --
2016-06-30 21:32 [Qemu-devel] [PATCH 0/3] Switch USB HID to QKeyCode John Arbuckle
2016-06-30 21:32 ` [Qemu-devel] [PATCH 3/3] hid.c: Add debug support John Arbuckle
2016-07-01 14:44 ` Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87io09viom.fsf@linaro.org \
--to=alex.bennee@linaro.org \
--cc=kraxel@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=programmingkidx@gmail.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.