From patchwork Thu Dec 10 19:15:57 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 40875 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A1229B6F04 for ; Fri, 11 Dec 2009 06:34:06 +1100 (EST) Received: from localhost ([127.0.0.1]:37940 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NIom3-0007c4-H7 for incoming@patchwork.ozlabs.org; Thu, 10 Dec 2009 14:34:03 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NIoVG-0006j1-13 for qemu-devel@nongnu.org; Thu, 10 Dec 2009 14:16:42 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NIoVA-0006Zw-8M for qemu-devel@nongnu.org; Thu, 10 Dec 2009 14:16:40 -0500 Received: from [199.232.76.173] (port=56468 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NIoVA-0006Zn-12 for qemu-devel@nongnu.org; Thu, 10 Dec 2009 14:16:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47059) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NIoV9-0001CW-JB for qemu-devel@nongnu.org; Thu, 10 Dec 2009 14:16:35 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nBAJGYnT011302 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 10 Dec 2009 14:16:34 -0500 Received: from localhost (vpn-9-38.rdu.redhat.com [10.11.9.38]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nBAJGXk7017206; Thu, 10 Dec 2009 14:16:34 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Thu, 10 Dec 2009 17:15:57 -0200 Message-Id: <1260472570-13973-8-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1260472570-13973-1-git-send-email-lcapitulino@redhat.com> References: <1260472570-13973-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: aliguori@us.ibm.com Subject: [Qemu-devel] [PATCH 07/20] monitor: do_info_cpus(): Use QBool X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org While there update the documentation as well. Signed-off-by: Luiz Capitulino --- monitor.c | 38 +++++++++++++++++++++++++------------- 1 files changed, 25 insertions(+), 13 deletions(-) diff --git a/monitor.c b/monitor.c index 5010ce4..49db7cf 100644 --- a/monitor.c +++ b/monitor.c @@ -635,8 +635,9 @@ static void print_cpu_iter(QObject *obj, void *opaque) assert(qobject_type(obj) == QTYPE_QDICT); cpu = qobject_to_qdict(obj); - if (strcmp(qdict_get_str(cpu, "current"), "yes") == 0) + if (qdict_get_bool(cpu, "current")) { active = '*'; + } monitor_printf(mon, "%c CPU #%d: ", active, (int)qdict_get_int(cpu, "CPU")); @@ -656,8 +657,9 @@ static void print_cpu_iter(QObject *obj, void *opaque) (target_long) qdict_get_int(cpu, "PC")); #endif - if (strcmp(qdict_get_str(cpu, "halted"), "yes") == 0) + if (qdict_get_bool(cpu, "halted")) { monitor_printf(mon, " (halted)"); + } monitor_printf(mon, "\n"); } @@ -674,12 +676,21 @@ static void monitor_print_cpus(Monitor *mon, const QObject *data) /** * do_info_cpus(): Show CPU information * - * Return a QList with a QDict for each CPU. + * Return a QList. Each CPU is represented by a QDict, which contains: * - * For example: + * - "cpu": CPU index + * - "current": true if this is the current CPU, false otherwise + * - "halted": true if the cpu is halted, false otherwise + * - Current program counter. The key's name depends on the architecture: + * "pc": i386/x86)64 + * "nip": PPC + * "pc" and "npc": sparc + * "PC": mips * - * [ { "CPU": 0, "current": "yes", "pc": 0x..., "halted": "no" }, - * { "CPU": 1, "current": "no", "pc": 0x..., "halted": "yes" } ] + * Example: + * + * [ { "CPU": 0, "current": true, "halted": false, "pc": 3227107138 }, + * { "CPU": 1, "current": false, "halted": true, "pc": 7108165 } ] */ static void do_info_cpus(Monitor *mon, QObject **ret_data) { @@ -692,14 +703,17 @@ static void do_info_cpus(Monitor *mon, QObject **ret_data) mon_get_cpu(); for(env = first_cpu; env != NULL; env = env->next_cpu) { - const char *answer; - QDict *cpu = qdict_new(); + QDict *cpu; + QObject *obj; cpu_synchronize_state(env); - qdict_put(cpu, "CPU", qint_from_int(env->cpu_index)); - answer = (env == mon->mon_cpu) ? "yes" : "no"; - qdict_put(cpu, "current", qstring_from_str(answer)); + obj = qobject_from_jsonf("{ 'CPU': %d, 'current': %i, 'halted': %i }", + env->cpu_index, env == mon->mon_cpu, + env->halted); + assert(obj != NULL); + + cpu = qobject_to_qdict(obj); #if defined(TARGET_I386) qdict_put(cpu, "pc", qint_from_int(env->eip + env->segs[R_CS].base)); @@ -711,8 +725,6 @@ static void do_info_cpus(Monitor *mon, QObject **ret_data) #elif defined(TARGET_MIPS) qdict_put(cpu, "PC", qint_from_int(env->active_tc.PC)); #endif - answer = env->halted ? "yes" : "no"; - qdict_put(cpu, "halted", qstring_from_str(answer)); qlist_append(cpu_list, cpu); }