From patchwork Tue Oct 4 13:01:17 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: 612248 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp185057pvb; Tue, 4 Oct 2022 06:48:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5uKMVBsC0itrzEtIp9axPwKhXbp092v7lXHjaExbw3G3ahfe7uxWGVLLwIkFaHACqAqxnE X-Received: by 2002:a05:6214:ca4:b0:4b1:b08e:9de9 with SMTP id s4-20020a0562140ca400b004b1b08e9de9mr2417567qvs.122.1664891286769; Tue, 04 Oct 2022 06:48:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664891286; cv=none; d=google.com; s=arc-20160816; b=hKji6Nh9baiaRxiA+ttbY+3sAZdRvgjdRjhtocG9hvZPyjWEV2V6WsKx8QebpkAIGi J7YR1PriPzGC+xvVXfjQF36mbPX2iGxWaYI+vaA9AHGEiIwlf0KRQxgmu8B/Ktk0NYtm tlDyEWVlCwKFeU/FaZczuq7x7KxE5KcSt/fcyyRhi7vnNfxFx9hWsPYH1NupHY/A422U 6jVnapBMEsjxHCZq/7RJZN3zaYrWZ3sY4hBh6qDr9VAvyttKNCZI7tCQ7BoyO89VL3+A 2UxT3R23nKUT3MEztU0+G5g1aH47VRN9TLISvu+ZiRH4oZf/Gsz+/ME7xrnpbK9oFc22 oXzw== 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=QGFbk8C97GoJjmbyu+s1VozFZFy9/GCuckImbZ7pktg=; b=uCPZMqFJlIxi0VSyqYT/Q9qSgiNqjE+I5Imqq+QFq2W24uLKtngLYli4/a5XOYp8NU 35r6Ei0rMVCwjIZ3nvz/c9KBr11meku5EdsJqeu38YVj2uQ5dwOeiymeknQrmADtsaxm RbLTgualF1k/RreTh4GFOePnmGhCzTomt1Dxsp+oUYMkdmKyGPmfjAVIDcXnfv0CxjjP ERyaxmLyAMWvSNSwMO5EI+789ZCLxuN8Qyo6vlMeJMBrrFS8TiPV4mhXAyIxBqV1VHeq x0h2WYO66BSbAoGoFPAFlh4e87er9k7bFe91dOh8WjqaTb4d9oF5sekd739lOIT536aa RyXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ncc4d5QX; 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 fv14-20020a056214240e00b004b17a7ed4a7si985724qvb.263.2022.10.04.06.48.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Oct 2022 06:48:06 -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=ncc4d5QX; 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]:41940 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofiHG-0002Rn-A5 for patch@linaro.org; Tue, 04 Oct 2022 09:48:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54816) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofhgR-0007YU-Od for qemu-devel@nongnu.org; Tue, 04 Oct 2022 09:10:03 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]:45041) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ofhgP-0000AI-RV for qemu-devel@nongnu.org; Tue, 04 Oct 2022 09:10:03 -0400 Received: by mail-wr1-x436.google.com with SMTP id c11so21255406wrp.11 for ; Tue, 04 Oct 2022 06:10:01 -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=QGFbk8C97GoJjmbyu+s1VozFZFy9/GCuckImbZ7pktg=; b=ncc4d5QXJWKqOg5BL0rF7BlNr+3LkhXPKVr+TTfeKnKY2sdBicNW7PQYXCtSIqJyl6 VX37pXfCQV+j2cpjuLsxObUurUFt57nBgM8BBnshmRWYtMyqCbv7+p28evPNHczA0W+p sXeeabMKDBl9+hdnNcXUeQzH8JWVx3xFiva7Qlo197DP155BrIa18ogc7kl/cH2isJQV d+JUVVNZLAjiVYHKQrD10tNMFNKnkn3I3w9aaeQyEJXHtsDg8C82HblBmUKq0ZWc+lt5 OTjvrgT5Vp4kRIoRHQbXa+x6nK+mIJzze1b1wX02ZNPODkqIusBjWVLb9XjM060XyQu5 EztA== 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=QGFbk8C97GoJjmbyu+s1VozFZFy9/GCuckImbZ7pktg=; b=Ohofe7uZOjKTuJ2u95vsHu8doLeFnADAw5qQNESpdQKMJGrodKnfMTRmqy7P6YOFQB T1p4Nnzsk/dBpwq3K/83SdDR22sgvwRwfz2JUaNvflX/3txveXQefDPvUnUsT2aHf7LE cnrCykrqIe+PhROtXQubFNJ2HpkR8ulyISI9kwrytWm9x2JzPJzWMcYn9Ydlmg0lcs9H PbxD0og71hlyK6gPi8+q3DRVdHYbgBvvf9IzRUK0ieTyWhfk0kIrDbEo8m0SiyvcM+oP uHdcOnS1HZ+p+hWqtuM3tJvLT9aPhppNFTNTDHUtHaYmbyobdIAUT/KWNj316ZMAU0iw 0BSQ== X-Gm-Message-State: ACrzQf0lV+nSmxHF6pUK3rFeJmq310fQvCFxlV9/bbbhj32EqQpF9k8f 0L/L7kfMxXaJHlSpJzb382aBkvP5LZnmig== X-Received: by 2002:adf:fb50:0:b0:22a:e4e9:a6b3 with SMTP id c16-20020adffb50000000b0022ae4e9a6b3mr15887355wrs.467.1664889000407; Tue, 04 Oct 2022 06:10:00 -0700 (PDT) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id l13-20020a5d4bcd000000b00226dba960b4sm12441446wrt.3.2022.10.04.06.09.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 06:09:54 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 1EDAB1FFD5; Tue, 4 Oct 2022 14:01:42 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson Subject: [PULL 33/54] disas: generalise plugin_printf and use for monitor_disas Date: Tue, 4 Oct 2022 14:01:17 +0100 Message-Id: <20221004130138.2299307-34-alex.bennee@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004130138.2299307-1-alex.bennee@linaro.org> References: <20221004130138.2299307-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x436.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: <20220929114231.583801-34-alex.bennee@linaro.org> 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