From patchwork Thu Sep 29 11:42:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 610602 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp906864pvb; Thu, 29 Sep 2022 06:57:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7DsXG+Jk56pKve3Yt944efOEvvPi8wOOzdWVKkJE+hi9VtBHhNoMg1+kwBt5mxl0BPCYPP X-Received: by 2002:a05:6214:2342:b0:473:e142:f758 with SMTP id hu2-20020a056214234200b00473e142f758mr2605688qvb.83.1664459836881; Thu, 29 Sep 2022 06:57:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664459836; cv=none; d=google.com; s=arc-20160816; b=mt6vscHJmRag3aYrkMfk6k9uiMqUk8mrZsvBUJMFGLZF3IrOrPvQC/U5TJD0pMtxi6 nvNl8FxzAXD6dhzMnMaKCtqIESXK0InwG8BH6klezpdpv1bna19i3kk2k1+vm91qoHHt MDL5bk76QMJILg2p/hu6DaahG6+D1Olk11ISpgPOJahnxqwVviWMKm2YNAgmSYsCsr7R gJQwx+6Iv92TLZtfr7wmkGxoyyq1Q77Ajq1fQrJfBos7Abxan3+qPQlksjLXORzUObJS l2ssSuY2Lfu6EzBgh7rwv+bZTIgPvnr+9pT7y8TVSZGFKvG5yLFcGW+Q/Wkv1tm1khHu IyUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=H5kZ4c1YNKUDywETs44GyEUgqI/uwgZp+WVffoscGxk=; b=KwNJh3OtIFMbe5Vx12n5GZnb17/lhXrl5R1x58p2X0zGeuH6a0mXRqZyXpn4gZd7YR +R7kMmtzYkx6YsMfxq2Gb8M4Sd+LpScQkpw2twofNAAhzakYApm48Pr+g7eOGUc6QF8t TB6OIZ0Pv1Kwt2ZkuLD/EbAzlbAtG3QE2PJ+hQYDP9QC+cQjIrwzCGvPs+k0nd904n9f mZDmLrWgJSfLKNngVrsBJ6malcoCDx7xTeFXEDJIGNLhtEufe1zrNsNnBmlTppXY6/IN cU/D8Z42SnpolGfzT6Nr7RvpnaIWbfM45EOwrGAR1S1tM2BX+L44sz+YBsRM6ToRdj3A kpXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SNLbo+tn; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c3-20020ac80083000000b0035baeff5046si1272504qtg.502.2022.09.29.06.57.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Sep 2022 06:57:16 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SNLbo+tn; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46436 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odu2O-0004DU-8a for patch@linaro.org; Thu, 29 Sep 2022 09:57:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48706) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ods3O-0000XF-57 for qemu-devel@nongnu.org; Thu, 29 Sep 2022 07:50:10 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:42525) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ods3I-0002OP-Ta for qemu-devel@nongnu.org; Thu, 29 Sep 2022 07:50:09 -0400 Received: by mail-wr1-x432.google.com with SMTP id l18so1768347wrw.9 for ; Thu, 29 Sep 2022 04:49:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=H5kZ4c1YNKUDywETs44GyEUgqI/uwgZp+WVffoscGxk=; b=SNLbo+tn/S7aI+KGepavX0Y4TIsKkEasGL+Y0p1dDOkSyqYaKwk1rQHD1e4HbIsn3c IPpiFCIfhHkELi+N+k/c5BkLHfO/tbR8evos1c9EwlTHEPEFNTR+WbJCsWfpDbUStkQQ 5uoCPr96O/TU0b4ONNt8TKGdo3I3S/Rplpdp5F7JJWchELg2gJvbY7KnOKz/w5WwPNin Ltd3tRuMIDlrEi+qKZsaDk8SAwM6cl690sP/t9enrMXC5Bohs6m9u6XE0kic0RiUH9El h/52GvFBTS6v+O69LPJZjp8+Qz1ejXgRXJvbHKy7zKmdNjI6Ppzzr2Zkn8pN0C3PnzS9 IMSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=H5kZ4c1YNKUDywETs44GyEUgqI/uwgZp+WVffoscGxk=; b=WeSG8LfzKPVrUaIWwr65kMTkK0GoZELZJfIrgv/A//cV7lkGrXx4MwmHF2pjABkXZ+ a6D7154wcgl4Qg9FTpkxsiEpUbenIk0N1g4BJX6aar0vGZcuykl/JALp5/duLXa957u2 Zb+tZBMQxwh/oLQ0su2PUPCRm2rGlNa4ofWk5MkaFUu2jCktxiSrgDi/lnR2nvlpOJzn f/ciZPu9BW2nIybifxa+ayO0Hco6e24pdjZ4JLDk7L/bb9gdb0UtZ1YhEqUjgcjx2I0n 0kCCRmJr4nmcPMB4Wxv2U0s+Ffe4fx/LVaDm4Cql/GUzqbI/gx5Uspuu0BuCum3B0JVK iqxA== X-Gm-Message-State: ACrzQf1kZ79mJiE9AdOrWieMtmmVZ51vYV+mRaGrVP4A3MLG9/Dokkm2 itbkbrNl4yYu+5/KFDMhIDrbmQ== X-Received: by 2002:adf:ef4c:0:b0:22c:c043:174e with SMTP id c12-20020adfef4c000000b0022cc043174emr2099537wrp.50.1664452197189; Thu, 29 Sep 2022 04:49:57 -0700 (PDT) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id x4-20020adfdcc4000000b0022b11a27e39sm6568013wrm.1.2022.09.29.04.49.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 04:49:54 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 178541FFD4; Thu, 29 Sep 2022 12:42:35 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: fam@euphon.net, berrange@redhat.com, f4bug@amsat.org, aurelien@aurel32.net, pbonzini@redhat.com, stefanha@redhat.com, crosa@redhat.com, minyihh@uci.edu, ma.mandourr@gmail.com, Luke.Craig@ll.mit.edu, cota@braap.org, aaron@os.amperecomputing.com, kuhn.chenqun@huawei.com, robhenry@microsoft.com, mahmoudabdalghany@outlook.com, =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson Subject: [PATCH v1 33/51] disas: generalise plugin_printf and use for monitor_disas Date: Thu, 29 Sep 2022 12:42:13 +0100 Message-Id: <20220929114231.583801-34-alex.bennee@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220929114231.583801-1-alex.bennee@linaro.org> References: <20220929114231.583801-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x432.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_PDS_OTHER_BAD_TLD=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Rather than assembling our output piecemeal lets use the same approach as the plugin disas interface to build the disassembly string before printing it. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson Message-Id: <20220921160801.1490125-3-alex.bennee@linaro.org> --- disas.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/disas.c b/disas.c index e31438f349..f07b6e760b 100644 --- a/disas.c +++ b/disas.c @@ -239,7 +239,7 @@ void target_disas(FILE *out, CPUState *cpu, target_ulong code, } } -static int plugin_printf(FILE *stream, const char *fmt, ...) +static int gstring_printf(FILE *stream, const char *fmt, ...) { /* We abuse the FILE parameter to pass a GString. */ GString *s = (GString *)stream; @@ -270,7 +270,7 @@ char *plugin_disas(CPUState *cpu, uint64_t addr, size_t size) GString *ds = g_string_new(NULL); initialize_debug_target(&s, cpu); - s.info.fprintf_func = plugin_printf; + s.info.fprintf_func = gstring_printf; s.info.stream = (FILE *)ds; /* abuse this slot */ s.info.buffer_vma = addr; s.info.buffer_length = size; @@ -358,15 +358,19 @@ void monitor_disas(Monitor *mon, CPUState *cpu, { int count, i; CPUDebug s; + g_autoptr(GString) ds = g_string_new(""); initialize_debug_target(&s, cpu); - s.info.fprintf_func = qemu_fprintf; + s.info.fprintf_func = gstring_printf; + s.info.stream = (FILE *)ds; /* abuse this slot */ + if (is_physical) { s.info.read_memory_func = physical_read_memory; } s.info.buffer_vma = pc; if (s.info.cap_arch >= 0 && cap_disas_monitor(&s.info, pc, nb_insn)) { + monitor_puts(mon, ds->str); return; } @@ -376,13 +380,16 @@ void monitor_disas(Monitor *mon, CPUState *cpu, return; } - for(i = 0; i < nb_insn; i++) { - monitor_printf(mon, "0x" TARGET_FMT_lx ": ", pc); + for (i = 0; i < nb_insn; i++) { + g_string_append_printf(ds, "0x" TARGET_FMT_lx ": ", pc); count = s.info.print_insn(pc, &s.info); - monitor_printf(mon, "\n"); - if (count < 0) - break; + g_string_append_c(ds, '\n'); + if (count < 0) { + break; + } pc += count; } + + monitor_puts(mon, ds->str); } #endif