From patchwork Fri Apr 8 16:47:34 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: 558849 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp495151map; Fri, 8 Apr 2022 09:50:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3Tse0SE9vGHFnkgNi5cqabcscrow+yKICtvbQVnHSte5hvDx7Hd7kfmhAmU8cmfriJLvc X-Received: by 2002:a25:abed:0:b0:641:19bc:b03c with SMTP id v100-20020a25abed000000b0064119bcb03cmr752440ybi.483.1649436610664; Fri, 08 Apr 2022 09:50:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649436610; cv=none; d=google.com; s=arc-20160816; b=cZ5E0bwRb6jApMoExXFFiGRcAZdQAj7nSshi9JCNYhlZd3wCvM/Pa0QniQMnNQDO+g 8ZvKMyVws4Owf5nYl51HZKNhlBHWzlujMyAE0hppUYOZ36sG5t7fKW9Gur7onPFwyb3J D4cURVUUtGTbHpIkqZVi2Jc5mJve8OYII1LWEboPPKsDZD7loYX5HWrcg0n68Cw64T02 4BT5WyLkF1LZEgUH/ZPGLtZ+1QJCu6auWZgdmLrA37C8etfn+S77Q1v4W2keTnZ7PxCX KHQJoVQDNvpnVjTl8uzDNqqopVkA3OPaDwrWa3f8k7sSn+pY9RBSN2sDGw+bWvihrjcj /qAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from :dkim-signature; bh=T2K0RiSpFnjP2SPW78zxgqkyT920bbP6nlXCBG7skz0=; b=LTOz3EyIsiNDOMf5e8y2FLwsEoiTeEUD9KJaQIyi+8g1mm4Mg2J/04h03iNw3lUKoK QIxXCIglgrmS5wlCGyK+tbjxnA4tiZ5K1+V/SCNm7fct+0bZ+bNQmOSgsZ4fO+Iqhujk u1jqCktiwG/XLjo90PImkxNh+4skPrJR6FG/KpdsByKsd+b7Gd6MgZ2y1itWsksy8cYl ZLP1SQuu62UFEGUO8FSXr6FFtfWg7C/nMqka2HwSkMzF74jp0tn03brsJ379wOjjL945 alyqu4zBO6i9fJIDiF/FjgfaRoXbQZgD6Z4UlWi9fgWFdOQuzzNFNkSjd2IXf0015URa tbnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=d9gzI9h7; 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=fail (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 l187-20020a2525c4000000b0063dab7fe7e8si868530ybl.187.2022.04.08.09.50.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 08 Apr 2022 09:50:10 -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=fail header.i=@linaro.org header.s=google header.b=d9gzI9h7; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54734 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncroI-0007EK-7T for patch@linaro.org; Fri, 08 Apr 2022 12:50:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49932) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncrmK-000786-R0 for qemu-devel@nongnu.org; Fri, 08 Apr 2022 12:48:08 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]:46802) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ncrmI-00032I-HT for qemu-devel@nongnu.org; Fri, 08 Apr 2022 12:48:08 -0400 Received: by mail-wr1-x433.google.com with SMTP id i20so685344wrb.13 for ; Fri, 08 Apr 2022 09:47:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=T2K0RiSpFnjP2SPW78zxgqkyT920bbP6nlXCBG7skz0=; b=d9gzI9h7ehjTtg2PFriyt9B/IYiBeK+7Lk5iR7wL72W/dIIHtBilq1P+rMN99nnjGB SssKFzQux2hDyy3xvLe7Rm78Q/Ox4Y4KCsWk6ratUJ9Sx9NPzP8EGjQVsVrBiuawsDCT 0BNjJXcCOn/JhYbEie9UvWTD9Lqq0aSeJ0XDqsaytrOyIAukFvLi+L4GVCfkb+ADgpia vl7kAHNviudIU5MESkfGNnmUetIQ9jD70z5vWNKRrIUoencOylNcuz8XQovq3WjMQaT8 h/z04U9xWV8SI2Ji7BuKjPniucgkvMaABUh1hPc7XNLuuN8iwBOF4X15l5QsCyIa7gbh kOSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=T2K0RiSpFnjP2SPW78zxgqkyT920bbP6nlXCBG7skz0=; b=F0Jt6Y6qTEb4sMCXkFBMNaCHhTgl+NnX2Me8LihrtLnQ9cBVMdvcwgKGJF1fXHh/sD y5A3ny1T7IHQrDwcx2SdZq+9oIh071SaIWrHAxtziMaG7oXLFn1W4vr+h40LL3oGuEAb /zcwGC7SPJsyHXujZXvavpYvMachtS7WqlSlJy6usPC/06joF5OPwoZy/12TvtOVPlnt 8NmHNBmESfNTTfWf4kJAwrKSZvLy+y6u9XxxirjKsFMhV+8HTDnqnaFN24VZYnK3ENsk 77aFb5XoJmvhUW4qcoiDLYilcBuu114+c/IsayTtfF3glSkBVmWoQRHbWAE7vE+957Uz V7Kw== X-Gm-Message-State: AOAM531vXVTpp45b9kd33bIdsFdK7Ne9JSpcVwAZwOVKQUf9EUWxGPqN 1+yabnU8Fo/dpXO+n3OFxngizA== X-Received: by 2002:a5d:64a7:0:b0:205:fb7a:50ee with SMTP id m7-20020a5d64a7000000b00205fb7a50eemr15306727wrp.185.1649436476505; Fri, 08 Apr 2022 09:47:56 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id r14-20020a0560001b8e00b00205918bd86esm19694439wru.78.2022.04.08.09.47.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Apr 2022 09:47:49 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 30B501FFBF; Fri, 8 Apr 2022 17:47:44 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 07/15] disas: generalise plugin_printf and use for monitor_disas Date: Fri, 8 Apr 2022 17:47:34 +0100 Message-Id: <20220408164742.2844631-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220408164742.2844631-1-alex.bennee@linaro.org> References: <20220408164742.2844631-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x433.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.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, PDS_OTHER_BAD_TLD=1.997, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: fam@euphon.net, berrange@redhat.com, stefanha@redhat.com, crosa@redhat.com, aaron@os.amperecomputing.com, robhenry@microsoft.com, f4bug@amsat.org, mahmoudabdalghany@outlook.com, minyihh@uci.edu, cota@braap.org, Luke.Craig@ll.mit.edu, pbonzini@redhat.com, kuhn.chenqun@huawei.com, ma.mandourr@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= , aurelien@aurel32.net 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 --- disas.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/disas.c b/disas.c index 3dab4482d1..9b52b2fa93 100644 --- a/disas.c +++ b/disas.c @@ -248,7 +248,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; @@ -279,7 +279,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; @@ -367,15 +367,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; } @@ -385,13 +389,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