From patchwork Fri May 15 14:44:00 2020 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: 186849 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp503711ilb; Fri, 15 May 2020 07:50:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJweGa74mPOiI9Pp3+2FoSgcWRGAzFTTj7EizuGzLxFzKMLFF22w8+jv24CwMRKre5ePRE+d X-Received: by 2002:ac8:1622:: with SMTP id p31mr3768176qtj.256.1589554204590; Fri, 15 May 2020 07:50:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589554204; cv=none; d=google.com; s=arc-20160816; b=D5qi/4ojknLMBpFu9tHreQYTpUu635TuzCGNIuLSE9aoLRBZDslWnAK3n5U/ttKTKm xe7wskBz/w8axthMmQzw9Ci5UT/6+iPdUwEqP7xcgK5mFQhFzY1hhibWMwQ6u13Aq/n0 Pf3YYlciyNJ+bBz/ee1d76n1IXngZLiJiIkQ/brtQyMdHw5zYW3MtHunI11vfmCAIkO1 CC0E37dOjcYw8qQZFl2hVAkllMKBP4xaNnlC/wFBOpEk+ZXOPlPGWH5s/BExrS4Crjqz E4gH35wNQ1HhHouz+sIsl83euuyf2cPUpxf9EK9Zw2elCNjbdGEtFWHzmQCiDInCE8jM 6J0A== 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=nJshK4Gmxn9NtKVYQkApWjq7ip9+eMHY3X093/AxgHA=; b=n37lJV9+5bq80HIUKpKjXeL2ek6mUm1LPlGQmLd2PlwgVIpDw0+fPym23CodT4RicF TtpnxWUOOY/0MRRxNvgG1fTeO8jd9Qv6sEWAVvx4AEn4wAuIUWaCOw1WFoBkyZdm526I zELGq31+Dxq4czce/6KZ9S5PYqhotJx3MJVoUA4AUbMWvts87LG5lwGPj4GMzl0uwWRQ bjgbVRKmUPqZe5ZckzQIfvkpRS1kllKR3kuBqtwIBY7Utm0SK71pwX7nL0nrDDwqZW+h DXl44XbRNMQXBGCcTh5gXjjwTc9dJ/PnrKhQNkI/mJ4WZHXGNzzsRCDz1fAYHQPKAn+i uKwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=w685uZIu; 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 q43si1416340qte.23.2020.05.15.07.50.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 May 2020 07:50:04 -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=w685uZIu; 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]:36322 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZbf2-0002Cn-3Y for patch@linaro.org; Fri, 15 May 2020 10:50:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44532) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZbZU-0002Qk-9P for qemu-devel@nongnu.org; Fri, 15 May 2020 10:44:22 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]:46002) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jZbZT-0000zD-0p for qemu-devel@nongnu.org; Fri, 15 May 2020 10:44:20 -0400 Received: by mail-wr1-x434.google.com with SMTP id v12so3800570wrp.12 for ; Fri, 15 May 2020 07:44:18 -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=nJshK4Gmxn9NtKVYQkApWjq7ip9+eMHY3X093/AxgHA=; b=w685uZIuhvpWnqw5ymPY9UXQaJCskyBrSZhLrhHbDYBNOAo/gt9I6kxVROzPe7co8I Zq9ES3UJAyu3phgtUqQwwXkdDUp1dXCGiFPf6DbN2tAtGsbLr//J0iPJVe/fDZ1Wl6xK 9EcHJ6LOwwHmL+mgI7i9Kp5GMYqW/08yn7FKKyeUqPkfpMQIYqoGRbv6xi+4ScGDOOcF fbH2GA43WVelP/rS0XpvVgso4jjqO6VUBCPA/QoUcXeOHXnsvOM8cXrs2kpB3cvfURNU gZHIF5jbBCZOeiQWiQYlHDo4Chu5PVWikXAICZ1e4uvxgNEUrIlgi6OzV322tfroSt7B 5jVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nJshK4Gmxn9NtKVYQkApWjq7ip9+eMHY3X093/AxgHA=; b=VIRuHmhZDgKAgLK1dIThKhI8ceOYX7pUn2xJP0sXFSQJYRx5NGEKk2fxCVwXB7svPS uQv5NWvRj6bbt4w+byILmXoMXZsmTgNVRkJU7d85aTUH2cVFLL5SNLAnvOiXzlMGUREI /4ZiWFoKJOKDcSAZQ+LE5Fejyv7LJpptsyWgT4BrjH+PDdOOg+W2Iyy4E7R9iKe43Cex qP6099vYAwcuH+0pGfZPOCQsmjQIO0helSSy1IcmN+2omiB72GPaw/4Ozb88USOstP/0 rLZB7QI3IjcH/feU9/ORyTGh9vspWDJY6u8AggSvXotVu3cRON0HB3gDdcRfjU8xdnV+ y2pA== X-Gm-Message-State: AOAM530qciOB1C7K3N3oqE5q0pu1RZ1OrV8HgOgbOTh7nfk1aTAZ4JgU cnWA4ay5jKOoB1gI+onX0c8hClJ7wU8= X-Received: by 2002:adf:d089:: with SMTP id y9mr4592371wrh.26.1589553857656; Fri, 15 May 2020 07:44:17 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id x17sm3872693wrp.71.2020.05.15.07.44.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2020 07:44:12 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id E696F1FF96; Fri, 15 May 2020 15:44:05 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Subject: [PULL v2 08/13] disas: add optional note support to cap_disas Date: Fri, 15 May 2020 15:44:00 +0100 Message-Id: <20200515144405.20580-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200515144405.20580-1-alex.bennee@linaro.org> References: <20200515144405.20580-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x434.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Include support for outputting a note at the top of a chunk of disassembly to capstone as well. Signed-off-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20200513175134.19619-10-alex.bennee@linaro.org> -- 2.20.1 diff --git a/disas.c b/disas.c index 7e8692de301..45285d3f63f 100644 --- a/disas.c +++ b/disas.c @@ -260,7 +260,8 @@ static void cap_dump_insn_units(disassemble_info *info, cs_insn *insn, } } -static void cap_dump_insn(disassemble_info *info, cs_insn *insn) +static void cap_dump_insn(disassemble_info *info, cs_insn *insn, + const char *note) { fprintf_function print = info->fprintf_func; int i, n, split; @@ -281,7 +282,11 @@ static void cap_dump_insn(disassemble_info *info, cs_insn *insn) } /* Print the actual instruction. */ - print(info->stream, " %-8s %s\n", insn->mnemonic, insn->op_str); + print(info->stream, " %-8s %s", insn->mnemonic, insn->op_str); + if (note) { + print(info->stream, "\t\t%s", note); + } + print(info->stream, "\n"); /* Dump any remaining part of the insn on subsequent lines. */ for (i = split; i < n; i += split) { @@ -313,7 +318,7 @@ static bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t size) size -= tsize; while (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) { - cap_dump_insn(info, insn); + cap_dump_insn(info, insn, NULL); } /* If the target memory is not consumed, go back for more... */ @@ -342,7 +347,8 @@ static bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t size) } /* Disassemble SIZE bytes at CODE for the host. */ -static bool cap_disas_host(disassemble_info *info, void *code, size_t size) +static bool cap_disas_host(disassemble_info *info, void *code, size_t size, + const char *note) { csh handle; const uint8_t *cbuf; @@ -358,7 +364,8 @@ static bool cap_disas_host(disassemble_info *info, void *code, size_t size) pc = (uintptr_t)code; while (cs_disasm_iter(handle, &cbuf, &size, &pc, insn)) { - cap_dump_insn(info, insn); + cap_dump_insn(info, insn, note); + note = NULL; } if (size != 0) { (*info->fprintf_func)(info->stream, @@ -402,7 +409,7 @@ static bool cap_disas_monitor(disassemble_info *info, uint64_t pc, int count) csize += tsize; if (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) { - cap_dump_insn(info, insn); + cap_dump_insn(info, insn, NULL); if (--count <= 0) { break; } @@ -416,7 +423,7 @@ static bool cap_disas_monitor(disassemble_info *info, uint64_t pc, int count) #endif /* !CONFIG_USER_ONLY */ #else # define cap_disas_target(i, p, s) false -# define cap_disas_host(i, p, s) false +# define cap_disas_host(i, p, s, n) false # define cap_disas_monitor(i, p, c) false # define cap_disas_plugin(i, p, c) false #endif /* CONFIG_CAPSTONE */ @@ -664,7 +671,7 @@ void disas(FILE *out, void *code, unsigned long size, const char *note) print_insn = print_insn_hppa; #endif - if (s.info.cap_arch >= 0 && cap_disas_host(&s.info, code, size)) { + if (s.info.cap_arch >= 0 && cap_disas_host(&s.info, code, size, note)) { return; }