From patchwork Wed May 13 17:51:33 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: 186679 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp670655ilb; Wed, 13 May 2020 10:54:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbY/IbHsdU26cEzQOiWqfZjOV9vqZFbOVb09MKNsnUa3+0D1NwC01WE2KReMJD9yqOcqo9 X-Received: by 2002:a05:6214:13d4:: with SMTP id cg20mr844564qvb.214.1589392475782; Wed, 13 May 2020 10:54:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589392475; cv=none; d=google.com; s=arc-20160816; b=Qr723KHw0oaqWQmc3eC5XszI5WHaPKU6NAqmy6RJxlXNQ8+Ra4nfwTp/92loF2kmGf 0MxsTK7H9gP7L/E8Ocxp4orxnbbLKEAL0vXWkkqAVJXb/KgPP5sNQIP+tmqsf0P8SP5j S4dUGkA5WsGWrdsOAHi3haYeS6C7MCbKTrX7mXTz+4k2nrGXU00YdU2V/rWHW/sn7LB7 njc1m63qt/ZmZX058bkA/wfNOmefomDGMMe835jhIOqQQ1fipFHdlS9heIpb4796uCxb sLYLeZcwyf6Xh0xQgDHbim8NS2vkZStlgXEiNMqPmzNskPzyC/pM9dVn5/s4oVhMcYGO ymag== 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=cOXxIq5n0K0tWjPWqLAjM36kY0q6yO5L0IxUaG95YzQ=; b=zT3v3m/AVUyTpwHicllBeNshOKwrZ6G9PKwJ/cs/X3e3AlBCUpyeL8LuU9hWqXghJQ q+UCJBdpZy20K6d/BZkFtqhaUkwJV1NnojSWhkMS9wsZG0Ra7nnMSOz3hYBsUREWtae5 zbSgX5inYqO7yc6l8qiMy3pjbTbRn+mIPLxpInxux0cfHMM6fkZDpP2x7DxCFgM9sfTv JVIt481gULjvlOd/VGdUUZLk5UFMBz87wQwjKMeg/thr9MxDNwuvCuv0f7VU5UU08o98 0BemownN0miHnjw0WE9A/vBVZgDAedVLgzD4Lz3ddAfNgb0JwTWY/NzSBpVzM/lsnGJl zkTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=thfkpzSl; 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 i3si98848qkf.251.2020.05.13.10.54.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 May 2020 10:54:35 -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=thfkpzSl; 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]:50032 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYvaV-0004Ym-8p for patch@linaro.org; Wed, 13 May 2020 13:54:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33432) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYvXp-0000yU-QM for qemu-devel@nongnu.org; Wed, 13 May 2020 13:51:49 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:34152) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jYvXo-0004yw-PL for qemu-devel@nongnu.org; Wed, 13 May 2020 13:51:49 -0400 Received: by mail-wr1-x443.google.com with SMTP id y3so568132wrt.1 for ; Wed, 13 May 2020 10:51:48 -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=cOXxIq5n0K0tWjPWqLAjM36kY0q6yO5L0IxUaG95YzQ=; b=thfkpzSlQDTHelMG2nTVFPXtE91o86V0kBkQrcPTL+8IU98HP7Rzhrg9g0MgqI2TOK /sg+hsEAm4DPxIb2jxjYL1hYGADZuN16Mz+FLni7BaxK4WF8URCIKaOI031h/krCvV8b 2GS4KAImkR3/7yUEwzH0wDtc20wUVumWSjNznS5NdTrfOO5zmG9TE3/0cljzxnR3FcPQ O4L0MTSb7lSp7OQ5CsE4Ee9R0SW5MNFRSZkWJVyLfidvVkvNoYA5iOAJvUeDu8pWRpqn Mo9jyCQEjevXDnfhUPpIJHrcM0aHZ+Dp7XctJWqjmv8+l8MnqfGK1hydSqJyDYHB65Ri L9Fw== 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=cOXxIq5n0K0tWjPWqLAjM36kY0q6yO5L0IxUaG95YzQ=; b=rYRrX2/mpxNPtPvyc2Wxp6W1iRCpZpj1AFpQcaNbQDFZpBK837g8SXrisIe3MKTaNW fwU87Be96uL6wE6uBEWXAtym9v0lvXq0uq6tAO1hrPafPWMfqZ/uOWbQAgC5vtt8QdkJ v9/8VKwQwmhSOgk1UNIk+/wLipNelL1C8pPgAIkJMDTKoxoKqAUobzKCyxzEneuYtWOs aHCCqjCLASxc7uCVmdZmmF/WDc9QgfPI8qkOhndKd+vQ7xScEe2igw0gm9TpaaKQqXKQ t6OtAqGOYQKFsxiZqUef7y/crewmyqVKyvAGQoa4nLv7/u6sWHv0mfWMFUBhpqi9v1r7 mmwA== X-Gm-Message-State: AOAM530LSnlviNlvcCTpN6nEiGsA+VZILTWFH1Iw+8KvEzZdbBcBbTjF R4K+ltEcV5Emd9q7YocLjuHK7w== X-Received: by 2002:adf:b301:: with SMTP id j1mr480997wrd.221.1589392307379; Wed, 13 May 2020 10:51:47 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id g135sm19365401wme.22.2020.05.13.10.51.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2020 10:51:41 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id B0DF61FF98; Wed, 13 May 2020 18:51:35 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 09/10] disas: add optional note support to cap_disas Date: Wed, 13 May 2020 18:51:33 +0100 Message-Id: <20200513175134.19619-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200513175134.19619-1-alex.bennee@linaro.org> References: <20200513175134.19619-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::443; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x443.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?= 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é --- v2 - always pass note down to cap_dump_insn --- disas.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) -- 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; }