qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 1/9] error: New convenience function error_repor


From: Eduardo Habkost
Subject: Re: [Qemu-devel] [PATCH 1/9] error: New convenience function error_report_err()
Date: Tue, 10 Feb 2015 20:04:34 -0200
User-agent: Mutt/1.5.23 (2014-03-12)

On Tue, Feb 10, 2015 at 05:44:59PM +0100, Paolo Bonzini wrote:
> 
> 
> On 10/02/2015 17:34, Markus Armbruster wrote:
> > I've typed error_report("%s", error_get_pretty(ERR)) too many times
> > already, and I've fixed too many instances of qerror_report_err(ERR)
> > to error_report("%s", error_get_pretty(ERR)) as well.  Capture the
> > pattern in a convenience function.
> > 
> > Since it's almost invariably followed by error_free(), stuff that into
> > the convenience function as well.
> > 
> > Put it to use with this Coccinelle semantic patch:
> 
> For your "no good deed goes unpunished" record, can you prepare a Wiki
> page on how to use Coccinelle?  My attempts always saw it confused by
> qemu/queue.h macros.

I assume you are asking about how to use/apply a semantic patch, not
about writing one[1]. I do this:

$ cat /tmp/error_report.spatch 
@@
expression E;
@@
-    error_report("%s", error_get_pretty(E));
-    error_free(E);
+    error_report_err(E);
@@
expression E, S;
@@
-    error_report("%s", error_get_pretty(E));
+    error_report_err(E);
(
     exit(S);
|
     abort();
)
$ spatch --sp-file /tmp/error_report.spatch $(git grep -l error_report) > 
/tmp/error_report.patch
init_defs_builtins: /usr/share/coccinelle/standard.h
HANDLING: arch_init.c audio/spiceaudio.c audio/wavcapture.c balloon.c block.c 
block/archipelago.c block/dmg.c block/iscsi.c block/nfs.c 
block/qcow2-snapshot.c block/qcow2.c block/rbd.c block/sheepdog.c block/ssh.c 
block/vhdx-log.c block/vmdk.c blockdev.c bootdevice.c device_tree.c exec.c 
hw/9pfs/virtio-9p-proxy.c hw/9pfs/virtio-9p.c hw/arm/armv7m.c 
hw/arm/cubieboard.c hw/arm/digic_boards.c hw/arm/exynos4210.c hw/arm/highbank.c 
hw/arm/integratorcp.c hw/arm/realview.c hw/arm/strongarm.c hw/arm/versatilepb.c 
hw/arm/vexpress.c hw/arm/virt.c hw/arm/xilinx_zynq.c hw/audio/milkymist-ac97.c 
hw/block/onenand.c hw/block/tc58128.c hw/block/virtio-blk.c hw/char/lm32_uart.c 
hw/char/milkymist-uart.c hw/char/sclpconsole-lm.c hw/char/sclpconsole.c 
hw/char/serial-pci.c hw/char/serial.c hw/char/virtio-serial-bus.c 
hw/core/machine.c hw/core/qdev-properties-system.c hw/core/qdev-properties.c 
hw/core/qdev.c hw/display/cg3.c hw/display/cirrus_vga.c hw/display/g364fb.c 
hw/display/milkymist-tmu2.c hw/display/milkymist-vgafb.c hw/display/qxl.c 
hw/display/tcx.c hw/i386/acpi-build.c hw/i386/kvm/pci-assign.c hw/i386/pc.c 
hw/i386/pc_piix.c hw/i386/pc_q35.c hw/i386/pc_sysfw.c hw/i386/smbios.c 
hw/ide/ahci.c hw/ide/core.c hw/ide/pci.c hw/ide/qdev.c 
hw/input/milkymist-softusb.c hw/intc/s390_flic.c hw/intc/s390_flic_kvm.c 
hw/intc/xics.c hw/intc/xics_kvm.c hw/isa/pc87312.c hw/microblaze/boot.c 
hw/mips/mips_fulong2e.c hw/mips/mips_jazz.c hw/mips/mips_malta.c 
hw/mips/mips_mipssim.c hw/misc/ivshmem.c hw/misc/milkymist-hpdmc.c 
hw/misc/milkymist-pfpu.c hw/net/milkymist-minimac2.c hw/net/vhost_net.c 
hw/net/virtio-net.c hw/nvram/fw_cfg.c hw/pci/pci-hotplug-old.c hw/pci/pci.c 
hw/pci/slotid_cap.c hw/ppc/e500.c hw/ppc/mpc8544ds.c hw/ppc/ppc.c 
hw/ppc/ppc405_boards.c hw/ppc/spapr.c hw/ppc/spapr_pci.c hw/ppc/virtex_ml507.c 
hw/s390x/s390-pci-inst.c hw/s390x/virtio-ccw.c hw/scsi/scsi-bus.c 
hw/scsi/vhost-scsi.c hw/scsi/virtio-scsi.c hw/sd/milkymist-memcard.c 
hw/sh4/shix.c hw/sparc/sun4m.c hw/timer/lm32_timer.c 
hw/timer/milkymist-sysctl.c hw/tpm/tpm_passthrough.c 
hw/tricore/tricore_testboard.c hw/usb/bus.c hw/usb/ccid-card-passthru.c 
hw/usb/dev-bluetooth.c hw/usb/dev-network.c hw/usb/dev-serial.c 
hw/usb/dev-smartcard-reader.c hw/usb/dev-storage.c hw/usb/dev-uas.c 
hw/usb/hcd-ehci.c hw/usb/host-libusb.c hw/usb/redirect.c hw/vfio/common.c 
hw/vfio/pci.c hw/virtio/dataplane/vring.c hw/virtio/vhost-backend.c 
hw/virtio/vhost-user.c hw/virtio/virtio-pci.c hw/virtio/virtio.c 
hw/xtensa/sim.c hw/xtensa/xtfpga.c include/qapi/qmp/qerror.h 
include/qemu/error-report.h migration/block.c migration/migration.c 
migration/qemu-file-buf.c migration/rdma.c migration/tcp.c migration/unix.c 
migration/vmstate.c monitor.c net/dump.c net/l2tpv3.c net/net.c net/netmap.c 
net/slirp.c net/socket.c net/tap-bsd.c net/tap-linux.c net/tap-solaris.c 
net/tap-win32.c net/tap.c net/vhost-user.c numa.c qdev-monitor.c qemu-char.c 
qemu-img.c qemu-io-cmds.c qemu-io.c qemu-nbd.c qmp.c qobject/qerror.c qom/cpu.c 
savevm.c scripts/qapi-commands.py slirp/misc.c target-i386/cpu.c 
target-mips/kvm.c target-ppc/translate_init.c target-s390x/cpu.c 
target-s390x/kvm.c target-sparc/cpu.c tests/test-aio.c tests/test-thread-pool.c 
tests/test-throttle.c tpm.c trace/control.c ui/input.c ui/spice-core.c ui/vnc.c 
util/error.c util/osdep.c util/qemu-config.c util/qemu-error.c 
util/qemu-option.c vl.c
[...]
Note: processing took    59.7s: arch_init.c audio/spiceaudio.c 
audio/wavcapture.c balloon.c block.c block/archipelago.c block/dmg.c 
block/iscsi.c block/nfs.c block/qcow2-snapshot.c block/qcow2.c block/rbd.c 
block/sheepdog.c block/ssh.c block/vhdx-log.c block/vmdk.c blockdev.c 
bootdevice.c device_tree.c exec.c hw/9pfs/virtio-9p-proxy.c hw/9pfs/virtio-9p.c 
hw/arm/armv7m.c hw/arm/cubieboard.c hw/arm/digic_boards.c hw/arm/exynos4210.c 
hw/arm/highbank.c hw/arm/integratorcp.c hw/arm/realview.c hw/arm/strongarm.c 
hw/arm/versatilepb.c hw/arm/vexpress.c hw/arm/virt.c hw/arm/xilinx_zynq.c 
hw/audio/milkymist-ac97.c hw/block/onenand.c hw/block/tc58128.c 
hw/block/virtio-blk.c hw/char/lm32_uart.c hw/char/milkymist-uart.c 
hw/char/sclpconsole-lm.c hw/char/sclpconsole.c hw/char/serial-pci.c 
hw/char/serial.c hw/char/virtio-serial-bus.c hw/core/machine.c 
hw/core/qdev-properties-system.c hw/core/qdev-properties.c hw/core/qdev.c 
hw/display/cg3.c hw/display/cirrus_vga.c hw/display/g364fb.c 
hw/display/milkymist-tmu2.c hw/display/milkymist-vgafb.c hw/display/qxl.c 
hw/display/tcx.c hw/i386/acpi-build.c hw/i386/kvm/pci-assign.c hw/i386/pc.c 
hw/i386/pc_piix.c hw/i386/pc_q35.c hw/i386/pc_sysfw.c hw/i386/smbios.c 
hw/ide/ahci.c hw/ide/core.c hw/ide/pci.c hw/ide/qdev.c 
hw/input/milkymist-softusb.c hw/intc/s390_flic.c hw/intc/s390_flic_kvm.c 
hw/intc/xics.c hw/intc/xics_kvm.c hw/isa/pc87312.c hw/microblaze/boot.c 
hw/mips/mips_fulong2e.c hw/mips/mips_jazz.c hw/mips/mips_malta.c 
hw/mips/mips_mipssim.c hw/misc/ivshmem.c hw/misc/milkymist-hpdmc.c 
hw/misc/milkymist-pfpu.c hw/net/milkymist-minimac2.c hw/net/vhost_net.c 
hw/net/virtio-net.c hw/nvram/fw_cfg.c hw/pci/pci-hotplug-old.c hw/pci/pci.c 
hw/pci/slotid_cap.c hw/ppc/e500.c hw/ppc/mpc8544ds.c hw/ppc/ppc.c 
hw/ppc/ppc405_boards.c hw/ppc/spapr.c hw/ppc/spapr_pci.c hw/ppc/virtex_ml507.c 
hw/s390x/s390-pci-inst.c hw/s390x/virtio-ccw.c hw/scsi/scsi-bus.c 
hw/scsi/vhost-scsi.c hw/scsi/virtio-scsi.c hw/sd/milkymist-memcard.c 
hw/sh4/shix.c hw/sparc/sun4m.c hw/timer/lm32_timer.c 
hw/timer/milkymist-sysctl.c hw/tpm/tpm_passthrough.c 
hw/tricore/tricore_testboard.c hw/usb/bus.c hw/usb/ccid-card-passthru.c 
hw/usb/dev-bluetooth.c hw/usb/dev-network.c hw/usb/dev-serial.c 
hw/usb/dev-smartcard-reader.c hw/usb/dev-storage.c hw/usb/dev-uas.c 
hw/usb/hcd-ehci.c hw/usb/host-libusb.c hw/usb/redirect.c hw/vfio/common.c 
hw/vfio/pci.c hw/virtio/dataplane/vring.c hw/virtio/vhost-backend.c 
hw/virtio/vhost-user.c hw/virtio/virtio-pci.c hw/virtio/virtio.c 
hw/xtensa/sim.c hw/xtensa/xtfpga.c include/qapi/qmp/qerror.h 
include/qemu/error-report.h migration/block.c migration/migration.c 
migration/qemu-file-buf.c migration/rdma.c migration/tcp.c migration/unix.c 
migration/vmstate.c monitor.c net/dump.c net/l2tpv3.c net/net.c net/netmap.c 
net/slirp.c net/socket.c net/tap-bsd.c net/tap-linux.c net/tap-solaris.c 
net/tap-win32.c net/tap.c net/vhost-user.c numa.c qdev-monitor.c qemu-char.c 
qemu-img.c qemu-io-cmds.c qemu-io.c qemu-nbd.c qmp.c qobject/qerror.c qom/cpu.c 
savevm.c scripts/qapi-commands.py slirp/misc.c target-i386/cpu.c 
target-mips/kvm.c target-ppc/translate_init.c target-s390x/cpu.c 
target-s390x/kvm.c target-sparc/cpu.c tests/test-aio.c tests/test-thread-pool.c 
tests/test-throttle.c tpm.c trace/control.c ui/input.c ui/spice-core.c ui/vnc.c 
util/error.c util/osdep.c util/qemu-config.c util/qemu-error.c 
util/qemu-option.c vl.c
$ diffstat /tmp/error_report.patch 
 cocci-output-11381-08fbd5-arch_init.c       |  600 +++---
 cocci-output-11381-0f7074-vexpress.c        |  314 +--
 cocci-output-11381-162164-realview.c        |  212 +-
 cocci-output-11381-219b63-host-libusb.c     |  899 ++++-----
 cocci-output-11381-2417f9-sheepdog.c        | 1559 ++++++++--------
 cocci-output-11381-260c6a-blockdev.c        | 1736 +++++++++---------
 cocci-output-11381-2c3742-redirect.c        | 1426 +++++++--------
 cocci-output-11381-2eec3c-qemu-char.c       | 2616 +++++++++++++---------------
 cocci-output-11381-2f6baa-pci-assign.c      | 1077 +++++------
 cocci-output-11381-353382-virtio-blk.c      |  467 ++--
 cocci-output-11381-35d629-exynos4210.c      |  108 -
 cocci-output-11381-427134-qemu-config.c     |  267 +-
 cocci-output-11381-4a0b4a-smbios.c          |  759 ++++----
 cocci-output-11381-50f054-versatilepb.c     |  210 +-
 cocci-output-11381-5f8ab0-vl.c              | 2020 ++++++++++-----------
 cocci-output-11381-66581d-qemu-io.c         |  197 +-
 cocci-output-11381-69640d-highbank.c        |  199 +-
 cocci-output-11381-6f68f2-cpu.c             | 2419 ++++++++++++-------------
 cocci-output-11381-714f3f-dev-network.c     |  900 ++++-----
 cocci-output-11381-85678e-error.c           |  115 -
 cocci-output-11381-8c3a4d-serial.c          |  640 +++---
 cocci-output-11381-96591b-integratorcp.c    |  284 +--
 cocci-output-11381-a7fe63-cpu.c             |  231 +-
 cocci-output-11381-adb67b-qdev.c            |  219 +-
 cocci-output-11381-affb2c-qemu-img.c        | 1739 +++++++++---------
 cocci-output-11381-b34641-qemu-nbd.c        |  337 +--
 cocci-output-11381-b71e7c-cpu.c             | 1001 +++++-----
 cocci-output-11381-b9a744-pc.c              | 1031 +++++------
 cocci-output-11381-bddd78-pci-hotplug-old.c |  125 -
 cocci-output-11381-fa9822-xilinx_zynq.c     |  134 -
 cocci-output-11381-fcda25-pci.c             | 1436 +++++++--------
 31 files changed, 12602 insertions(+), 12675 deletions(-)
$ 

(Don't ask me why the weird filenames. The patch applies cleanly if I
use "patch -p0")


[1] If you are talking about writing them, I think the best way to learn
    it is to read some examples[2]. If you want something slightly more
    detailed, there's the tutorial[3].

    Now, if you want additional details, you can read the
    specification[4], learn everything about the SmPL grammar and be
    completely confused about its semantics. I don't see the language
    semantics explained anywhere except on the incomplete tutorial and
    list of examples. :(

[2] http://coccinelle.lip6.fr/rules/
[3] http://coccinelle.lip6.fr/papers/ols07-padioleau.pdf
[4] http://coccinelle.lip6.fr/docs/index.html

-- 
Eduardo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]