diff mbox

[qom-cpu,09/59] cpus: Simplify hw_error()

Message ID 1370805206-26574-10-git-send-email-afaerber@suse.de
State New
Headers show

Commit Message

Andreas Färber June 9, 2013, 7:12 p.m. UTC
Use new qemu_for_each_cpu().

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 cpus.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

Comments

liguang June 10, 2013, 2:19 a.m. UTC | #1
Reviewed-by: liguang <lig.fnst@cn.fujitsu.com>

在 2013-06-09日的 21:12 +0200,Andreas Färber写道:
> Use new qemu_for_each_cpu().
> 
> Signed-off-by: Andreas Färber <afaerber@suse.de>
> ---
>  cpus.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/cpus.c b/cpus.c
> index 1975c5c..9195bc3 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -386,21 +386,22 @@ void configure_icount(const char *option)
>  }
>  
>  /***********************************************************/
> +
> +static void hw_one_error(CPUState *cpu, void *data)
> +{
> +    fprintf(stderr, "CPU #%d:\n", cpu->cpu_index);
> +    cpu_dump_state(cpu->env_ptr, stderr, fprintf, CPU_DUMP_FPU);
> +}
> +
>  void hw_error(const char *fmt, ...)
>  {
>      va_list ap;
> -    CPUArchState *env;
> -    CPUState *cpu;
>  
>      va_start(ap, fmt);
>      fprintf(stderr, "qemu: hardware error: ");
>      vfprintf(stderr, fmt, ap);
>      fprintf(stderr, "\n");
> -    for (env = first_cpu; env != NULL; env = env->next_cpu) {
> -        cpu = ENV_GET_CPU(env);
> -        fprintf(stderr, "CPU #%d:\n", cpu->cpu_index);
> -        cpu_dump_state(env, stderr, fprintf, CPU_DUMP_FPU);
> -    }
> +    qemu_for_each_cpu(hw_one_error, NULL);
>      va_end(ap);
>      abort();
>  }
Andreas Färber June 10, 2013, 9:48 p.m. UTC | #2
Am 09.06.2013 21:12, schrieb Andreas Färber:
> Use new qemu_for_each_cpu().
> 
> Signed-off-by: Andreas Färber <afaerber@suse.de>
> ---
>  cpus.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/cpus.c b/cpus.c
> index 1975c5c..9195bc3 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -386,21 +386,22 @@ void configure_icount(const char *option)
>  }
>  
>  /***********************************************************/
> +
> +static void hw_one_error(CPUState *cpu, void *data)
> +{
> +    fprintf(stderr, "CPU #%d:\n", cpu->cpu_index);
> +    cpu_dump_state(cpu->env_ptr, stderr, fprintf, CPU_DUMP_FPU);

This env_ptr usage is dangerous since as void* it bypasses all argument
type checks - luckily 18/59 does convert it.

If we want to go with qemu_for_each_cpu(), I better add a temporary
CPUArchState *env variable.

Andreas

> +}
> +
>  void hw_error(const char *fmt, ...)
>  {
>      va_list ap;
> -    CPUArchState *env;
> -    CPUState *cpu;
>  
>      va_start(ap, fmt);
>      fprintf(stderr, "qemu: hardware error: ");
>      vfprintf(stderr, fmt, ap);
>      fprintf(stderr, "\n");
> -    for (env = first_cpu; env != NULL; env = env->next_cpu) {
> -        cpu = ENV_GET_CPU(env);
> -        fprintf(stderr, "CPU #%d:\n", cpu->cpu_index);
> -        cpu_dump_state(env, stderr, fprintf, CPU_DUMP_FPU);
> -    }
> +    qemu_for_each_cpu(hw_one_error, NULL);
>      va_end(ap);
>      abort();
>  }
>
diff mbox

Patch

diff --git a/cpus.c b/cpus.c
index 1975c5c..9195bc3 100644
--- a/cpus.c
+++ b/cpus.c
@@ -386,21 +386,22 @@  void configure_icount(const char *option)
 }
 
 /***********************************************************/
+
+static void hw_one_error(CPUState *cpu, void *data)
+{
+    fprintf(stderr, "CPU #%d:\n", cpu->cpu_index);
+    cpu_dump_state(cpu->env_ptr, stderr, fprintf, CPU_DUMP_FPU);
+}
+
 void hw_error(const char *fmt, ...)
 {
     va_list ap;
-    CPUArchState *env;
-    CPUState *cpu;
 
     va_start(ap, fmt);
     fprintf(stderr, "qemu: hardware error: ");
     vfprintf(stderr, fmt, ap);
     fprintf(stderr, "\n");
-    for (env = first_cpu; env != NULL; env = env->next_cpu) {
-        cpu = ENV_GET_CPU(env);
-        fprintf(stderr, "CPU #%d:\n", cpu->cpu_index);
-        cpu_dump_state(env, stderr, fprintf, CPU_DUMP_FPU);
-    }
+    qemu_for_each_cpu(hw_one_error, NULL);
     va_end(ap);
     abort();
 }