All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] qom/object: Display more helpful message when an interface is missing
@ 2020-01-18 16:23 Philippe Mathieu-Daudé
  2020-01-18 21:26 ` Paolo Bonzini
  2020-01-20  8:58 ` Cornelia Huck
  0 siblings, 2 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-01-18 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé,
	Eduardo Habkost, Cornelia Huck, Paolo Bonzini,
	Philippe Mathieu-Daudé,
	Stefano Garzarella

When adding new devices implementing QOM interfaces, we might
forgot to add the Kconfig dependency that pulls the required
objects in when building.

Since QOM dependencies are resolved at runtime, we don't get any
link-time failures, and QEMU aborts while starting:

  $ qemu ...
  Segmentation fault (core dumped)

  (gdb) bt
  #0  0x00007ff6e96b1e35 in raise () from /lib64/libc.so.6
  #1  0x00007ff6e969c895 in abort () from /lib64/libc.so.6
  #2  0x00005572bc5051cf in type_initialize (ti=0x5572be6f1200) at qom/object.c:323
  #3  0x00005572bc505074 in type_initialize (ti=0x5572be6f1800) at qom/object.c:301
  #4  0x00005572bc505074 in type_initialize (ti=0x5572be6e48e0) at qom/object.c:301
  #5  0x00005572bc506939 in object_class_by_name (typename=0x5572bc56109a) at qom/object.c:959
  #6  0x00005572bc503dd5 in cpu_class_by_name (typename=0x5572bc56109a, cpu_model=0x5572be6d9930) at hw/core/cpu.c:286

Since the caller has access to the qdev parent/interface names,
we can simply display them to avoid starting a debugger:

  $ qemu ...
  qemu: missing interface 'fancy-if' for object 'fancy-dev'
  Aborted (core dumped)

This commit is similar to e02bdf1cecd2 ("Display more helpful message
when an object type is missing").

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
Cc: Cornelia Huck <cohuck@redhat.com>
Cc: Stefano Garzarella <sgarzare@redhat.com>
Cc: Daniel P. Berrangé <berrange@redhat.com>
---
 qom/object.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/qom/object.c b/qom/object.c
index 0d971ca897..36123fb330 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -317,6 +317,11 @@ static void type_initialize(TypeImpl *ti)
 
         for (i = 0; i < ti->num_interfaces; i++) {
             TypeImpl *t = type_get_by_name(ti->interfaces[i].typename);
+            if (!t) {
+                error_report("missing interface '%s' for object '%s'",
+                             ti->interfaces[i].typename, parent->name);
+                abort();
+            }
             for (e = ti->class->interfaces; e; e = e->next) {
                 TypeImpl *target_type = OBJECT_CLASS(e->data)->type;
 
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] qom/object: Display more helpful message when an interface is missing
  2020-01-18 16:23 [PATCH] qom/object: Display more helpful message when an interface is missing Philippe Mathieu-Daudé
@ 2020-01-18 21:26 ` Paolo Bonzini
  2020-01-20  8:58 ` Cornelia Huck
  1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2020-01-18 21:26 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Cornelia Huck, Daniel P. Berrangé,
	Eduardo Habkost, Stefano Garzarella

On 18/01/20 17:23, Philippe Mathieu-Daudé wrote:
> When adding new devices implementing QOM interfaces, we might
> forgot to add the Kconfig dependency that pulls the required
> objects in when building.
> 
> Since QOM dependencies are resolved at runtime, we don't get any
> link-time failures, and QEMU aborts while starting:
> 
>   $ qemu ...
>   Segmentation fault (core dumped)
> 
>   (gdb) bt
>   #0  0x00007ff6e96b1e35 in raise () from /lib64/libc.so.6
>   #1  0x00007ff6e969c895 in abort () from /lib64/libc.so.6
>   #2  0x00005572bc5051cf in type_initialize (ti=0x5572be6f1200) at qom/object.c:323
>   #3  0x00005572bc505074 in type_initialize (ti=0x5572be6f1800) at qom/object.c:301
>   #4  0x00005572bc505074 in type_initialize (ti=0x5572be6e48e0) at qom/object.c:301
>   #5  0x00005572bc506939 in object_class_by_name (typename=0x5572bc56109a) at qom/object.c:959
>   #6  0x00005572bc503dd5 in cpu_class_by_name (typename=0x5572bc56109a, cpu_model=0x5572be6d9930) at hw/core/cpu.c:286
> 
> Since the caller has access to the qdev parent/interface names,
> we can simply display them to avoid starting a debugger:
> 
>   $ qemu ...
>   qemu: missing interface 'fancy-if' for object 'fancy-dev'
>   Aborted (core dumped)
> 
> This commit is similar to e02bdf1cecd2 ("Display more helpful message
> when an object type is missing").
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> Cc: Cornelia Huck <cohuck@redhat.com>
> Cc: Stefano Garzarella <sgarzare@redhat.com>
> Cc: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  qom/object.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/qom/object.c b/qom/object.c
> index 0d971ca897..36123fb330 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -317,6 +317,11 @@ static void type_initialize(TypeImpl *ti)
>  
>          for (i = 0; i < ti->num_interfaces; i++) {
>              TypeImpl *t = type_get_by_name(ti->interfaces[i].typename);
> +            if (!t) {
> +                error_report("missing interface '%s' for object '%s'",
> +                             ti->interfaces[i].typename, parent->name);
> +                abort();
> +            }
>              for (e = ti->class->interfaces; e; e = e->next) {
>                  TypeImpl *target_type = OBJECT_CLASS(e->data)->type;
>  
> 

Queued, thanks.

Paolo



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] qom/object: Display more helpful message when an interface is missing
  2020-01-18 16:23 [PATCH] qom/object: Display more helpful message when an interface is missing Philippe Mathieu-Daudé
  2020-01-18 21:26 ` Paolo Bonzini
@ 2020-01-20  8:58 ` Cornelia Huck
  1 sibling, 0 replies; 3+ messages in thread
From: Cornelia Huck @ 2020-01-20  8:58 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Paolo Bonzini, Stefano Garzarella, Daniel P. Berrangé,
	qemu-devel, Eduardo Habkost

On Sat, 18 Jan 2020 17:23:48 +0100
Philippe Mathieu-Daudé <philmd@redhat.com> wrote:

> When adding new devices implementing QOM interfaces, we might
> forgot to add the Kconfig dependency that pulls the required
> objects in when building.
> 
> Since QOM dependencies are resolved at runtime, we don't get any
> link-time failures, and QEMU aborts while starting:
> 
>   $ qemu ...
>   Segmentation fault (core dumped)
> 
>   (gdb) bt
>   #0  0x00007ff6e96b1e35 in raise () from /lib64/libc.so.6
>   #1  0x00007ff6e969c895 in abort () from /lib64/libc.so.6
>   #2  0x00005572bc5051cf in type_initialize (ti=0x5572be6f1200) at qom/object.c:323
>   #3  0x00005572bc505074 in type_initialize (ti=0x5572be6f1800) at qom/object.c:301
>   #4  0x00005572bc505074 in type_initialize (ti=0x5572be6e48e0) at qom/object.c:301
>   #5  0x00005572bc506939 in object_class_by_name (typename=0x5572bc56109a) at qom/object.c:959
>   #6  0x00005572bc503dd5 in cpu_class_by_name (typename=0x5572bc56109a, cpu_model=0x5572be6d9930) at hw/core/cpu.c:286
> 
> Since the caller has access to the qdev parent/interface names,
> we can simply display them to avoid starting a debugger:
> 
>   $ qemu ...
>   qemu: missing interface 'fancy-if' for object 'fancy-dev'
>   Aborted (core dumped)
> 
> This commit is similar to e02bdf1cecd2 ("Display more helpful message
> when an object type is missing").
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> Cc: Cornelia Huck <cohuck@redhat.com>
> Cc: Stefano Garzarella <sgarzare@redhat.com>
> Cc: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  qom/object.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/qom/object.c b/qom/object.c
> index 0d971ca897..36123fb330 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -317,6 +317,11 @@ static void type_initialize(TypeImpl *ti)
>  
>          for (i = 0; i < ti->num_interfaces; i++) {
>              TypeImpl *t = type_get_by_name(ti->interfaces[i].typename);
> +            if (!t) {
> +                error_report("missing interface '%s' for object '%s'",
> +                             ti->interfaces[i].typename, parent->name);
> +                abort();
> +            }
>              for (e = ti->class->interfaces; e; e = e->next) {
>                  TypeImpl *target_type = OBJECT_CLASS(e->data)->type;
>  

Reviewed-by: Cornelia Huck <cohuck@redhat.com>

...but I'm wondering if there are more cases like this? Just to avoid
playing whack-a-mole.



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-01-20  8:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-18 16:23 [PATCH] qom/object: Display more helpful message when an interface is missing Philippe Mathieu-Daudé
2020-01-18 21:26 ` Paolo Bonzini
2020-01-20  8:58 ` Cornelia Huck

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.