From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46793) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aji1B-00009p-VU for qemu-devel@nongnu.org; Sat, 26 Mar 2016 02:48:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aji17-00036p-U8 for qemu-devel@nongnu.org; Sat, 26 Mar 2016 02:48:17 -0400 Received: from mail-wm0-x231.google.com ([2a00:1450:400c:c09::231]:37107) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aji17-00036l-MU for qemu-devel@nongnu.org; Sat, 26 Mar 2016 02:48:13 -0400 Received: by mail-wm0-x231.google.com with SMTP id p65so42856054wmp.0 for ; Fri, 25 Mar 2016 23:48:12 -0700 (PDT) References: <7A168ABF-EB8A-43E5-9821-F4D8AD9B6E53@gmail.com> From: Alex =?utf-8?Q?Benn=C3=A9e?= In-reply-to: <7A168ABF-EB8A-43E5-9821-F4D8AD9B6E53@gmail.com> Date: Sat, 26 Mar 2016 06:48:09 +0000 Message-ID: <87io09viom.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH 3/3] hid.c: Add debug support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Programmingkid Cc: Peter Maydell , Gerd Hoffmann , qemu-devel qemu-devel Programmingkid writes: > Add debug macros to the code for easier debugging. > > Signed-off-by: John Arbuckle > --- > 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