{"id":1882138,"url":"http://patchwork.ozlabs.org/api/patches/1882138/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20240103173349.398526-42-alex.bennee@linaro.org/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20240103173349.398526-42-alex.bennee@linaro.org>","list_archive_url":null,"date":"2024-01-03T17:33:47","name":"[v2,41/43] contrib/plugins: optimise the register value tracking","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"dd9a43f53aa1a1c8d05ad1610e48eba6a4cf36de","submitter":{"id":39532,"url":"http://patchwork.ozlabs.org/api/people/39532/?format=json","name":"Alex Bennée","email":"alex.bennee@linaro.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20240103173349.398526-42-alex.bennee@linaro.org/mbox/","series":[{"id":388742,"url":"http://patchwork.ozlabs.org/api/series/388742/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=388742","date":"2024-01-03T17:33:08","name":"testing and plugin updates for 9.0 (pre-PR)","version":2,"mbox":"http://patchwork.ozlabs.org/series/388742/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/1882138/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/1882138/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256\n header.s=google header.b=d3AYzN6E;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists.gnu.org (lists.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4T4xyJ0gfYz1yQ5\n\tfor <incoming@patchwork.ozlabs.org>; Thu,  4 Jan 2024 04:47:52 +1100 (AEDT)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1rL5DN-0007VN-1D; Wed, 03 Jan 2024 12:39:37 -0500","from eggs.gnu.org ([2001:470:142:3::10])\n by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <alex.bennee@linaro.org>)\n id 1rL5DG-0006xs-Ve\n for qemu-devel@nongnu.org; Wed, 03 Jan 2024 12:39:31 -0500","from mail-wm1-x334.google.com ([2a00:1450:4864:20::334])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\n (Exim 4.90_1) (envelope-from <alex.bennee@linaro.org>)\n id 1rL5D0-0000hj-3g\n for qemu-devel@nongnu.org; Wed, 03 Jan 2024 12:39:30 -0500","by mail-wm1-x334.google.com with SMTP id\n 5b1f17b1804b1-40d2e56f3a6so4406075e9.1\n for <qemu-devel@nongnu.org>; Wed, 03 Jan 2024 09:39:13 -0800 (PST)","from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id\n z1-20020a05600c0a0100b0040c3953cda5sm2984624wmp.45.2024.01.03.09.39.06\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Wed, 03 Jan 2024 09:39:08 -0800 (PST)","from draig.lan (localhost [IPv6:::1])\n by draig.lan (Postfix) with ESMTP id 83FBF5F9D6;\n Wed,  3 Jan 2024 17:33:53 +0000 (GMT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=linaro.org; s=google; t=1704303552; x=1704908352; darn=nongnu.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=ctlsx5qTTsFuiHpWia+LYNCfPNohh0GYQvm+lOAMVvc=;\n b=d3AYzN6Ekg+phIcyH9LAeWmm94jZkKA0VOxQN0j5ix3CEpG3rkx4fMD/uqxQbAYFbW\n cY3cCufJnyBYDYuYdM59I9gSV+6AsWiGLUYqJGpHvCY4HN3/9Tg5Sic0AH+odkx+S2gj\n HvFRNwEkrwr60K4hVI1DSwyoW+re6TP1pGvEIAQMeztSo+ezBwIWsTephN7hgFmYnT7V\n PvY5ujZbbUcijbtNtVQYxrvSV0qiw8r1yZYPakQtRZN7e6259s0y4kInRFzFxGs6Io2r\n vPzu96sfKDWEEZhJHw2eefUc66l+eQRRivr7RNsk4AZeiDJJMX8OUEUTEATQ+C/DI8Hq\n Db0Q==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20230601; t=1704303552; x=1704908352;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n :subject:date:message-id:reply-to;\n bh=ctlsx5qTTsFuiHpWia+LYNCfPNohh0GYQvm+lOAMVvc=;\n b=wZX8zhLfSqgtTKW9hACZBLzWFYN6ksCOZXIXxuCg5bWVJQZwdhDVxOiFnbWZLr3dJI\n 6gj3tcrtIlwfYrEUV/B2fyhygwcXNSeF9Py86GlJIUnYq4xo3SYYJlA63OcnjMtmX+Vo\n jnTAAvybg9sIbibEpudOUYAG+ncHdvyWcoCJIMb+00eWZ2BQ6rHn8/0Xpqhf9nZ2ZYk5\n CKeisuDosLFEHdY5xtLUzn/JJXTydQSHEDrQP13LKTnXSoE3QThEO9NlTk0I0DAgkiY6\n jxK2x9qYjXel74YvlsHE0aNWHxaJfsmu4/pZIiD+f8YVf7pKyIIdKnGLBYSh5s6J6xNO\n 8sIg==","X-Gm-Message-State":"AOJu0YzVkIcoPXZkH1CnspSOPBckYrEg5YVA3nJh0+Il57uyxA/kuI7W\n eRi52LFq0GhuijCMbieaetNh/yQdZk6hUQ==","X-Google-Smtp-Source":"\n AGHT+IEuHutLYteo6vG6WlNBeXWADd3eSquGtGu+n6EBwY95PnWE283bmkTL7IK2oAEJ7tDzHj2jSw==","X-Received":"by 2002:a05:600c:3b08:b0:40d:8586:82c5 with SMTP id\n m8-20020a05600c3b0800b0040d858682c5mr706985wms.12.1704303552097;\n Wed, 03 Jan 2024 09:39:12 -0800 (PST)","From":"=?utf-8?q?Alex_Benn=C3=A9e?= <alex.bennee@linaro.org>","To":"qemu-devel@nongnu.org","Cc":"qemu-s390x@nongnu.org, qemu-ppc@nongnu.org,\n Richard Henderson <richard.henderson@linaro.org>,\n Song Gao <gaosong@loongson.cn>,\n =?utf-8?q?Marc-Andr=C3=A9_Lureau?= <marcandre.lureau@redhat.com>,\n David Hildenbrand <david@redhat.com>, Aurelien Jarno <aurelien@aurel32.net>,\n Yoshinori Sato <ysato@users.sourceforge.jp>,\n Yanan Wang <wangyanan55@huawei.com>, Bin Meng <bin.meng@windriver.com>,\n Laurent Vivier <lvivier@redhat.com>, Michael Rolnik <mrolnik@gmail.com>,\n Alexandre Iooss <erdnaxe@crans.org>, David Woodhouse <dwmw2@infradead.org>,\n Laurent Vivier <laurent@vivier.eu>, Paolo Bonzini <pbonzini@redhat.com>,\n Brian Cain <bcain@quicinc.com>,\n Daniel Henrique Barboza <danielhb413@gmail.com>,\n Beraldo Leal <bleal@redhat.com>, Paul Durrant <paul@xen.org>,\n Mahmoud Mandour <ma.mandourr@gmail.com>, Thomas Huth <thuth@redhat.com>,\n Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Cleber Rosa <crosa@redhat.com>,\n kvm@vger.kernel.org, Peter Maydell <peter.maydell@linaro.org>,\n Wainer dos Santos Moschetta <wainersm@redhat.com>, =?utf-8?q?Alex_Benn?=\n\t=?utf-8?q?=C3=A9e?= <alex.bennee@linaro.org>, qemu-arm@nongnu.org,\n Weiwei Li <liwei1518@gmail.com>,\n =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= <philmd@linaro.org>,\n John Snow <jsnow@redhat.com>,\n Daniel Henrique Barboza <dbarboza@ventanamicro.com>,\n Nicholas Piggin <npiggin@gmail.com>, Palmer Dabbelt <palmer@dabbelt.com>,\n Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,\n Ilya Leoshkevich <iii@linux.ibm.com>,\n =?utf-8?q?C=C3=A9dric_Le_Goater?= <clg@kaod.org>,\n \"Edgar E. Iglesias\" <edgar.iglesias@gmail.com>,\n Eduardo Habkost <eduardo@habkost.net>,\n Pierrick Bouvier <pierrick.bouvier@linaro.org>, qemu-riscv@nongnu.org,\n Alistair Francis <alistair.francis@wdc.com>","Subject":"[PATCH v2 41/43] contrib/plugins: optimise the register value\n tracking","Date":"Wed,  3 Jan 2024 17:33:47 +0000","Message-Id":"<20240103173349.398526-42-alex.bennee@linaro.org>","X-Mailer":"git-send-email 2.39.2","In-Reply-To":"<20240103173349.398526-1-alex.bennee@linaro.org>","References":"<20240103173349.398526-1-alex.bennee@linaro.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Received-SPF":"pass client-ip=2a00:1450:4864:20::334;\n envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x334.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,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01,\n T_SPF_HELO_TEMPERROR=0.01 autolearn=unavailable autolearn_force=no","X-Spam_action":"no action","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"},"content":"This adds an additional flag which attempts to optimise the register\ntracking by only instrumenting instructions which are likely to change\nits value. This relies on the disassembler showing up the register\nnames in disassembly so is only enabled when asked for.\n\nSigned-off-by: Alex Bennée <alex.bennee@linaro.org>\n---\n docs/devel/tcg-plugins.rst |  10 +-\n contrib/plugins/execlog.c  | 189 ++++++++++++++++++++++++++++++-------\n 2 files changed, 165 insertions(+), 34 deletions(-)","diff":"diff --git a/docs/devel/tcg-plugins.rst b/docs/devel/tcg-plugins.rst\nindex 3a0962723d7..fa7421279f5 100644\n--- a/docs/devel/tcg-plugins.rst\n+++ b/docs/devel/tcg-plugins.rst\n@@ -503,7 +503,15 @@ registers with multiple ``reg`` options. You can also use glob style matching if\n   $ qemu-system-arm $(QEMU_ARGS) \\\n     -plugin ./contrib/plugins/libexeclog.so,reg=\\*_el2,reg=sp -d plugin\n \n-Be aware that each additional register to check will slow down execution quite considerably.\n+Be aware that each additional register to check will slow down\n+execution quite considerably. You can optimise the number of register\n+checks done by using the rdisas option. This will only instrument\n+instructions that mention the registers in question in disassembly.\n+This is not foolproof as some instructions implicitly change\n+instructions. You can use the ifilter to catch these cases:\n+\n+  $ qemu-system-arm $(QEMU_ARGS) \\\n+    -plugin ./contrib/plugins/libexeclog.so,ifilter=msr,ifilter=blr,reg=x30,reg=\\*_el1,rdisas=on\n \n - contrib/plugins/cache.c\n \ndiff --git a/contrib/plugins/execlog.c b/contrib/plugins/execlog.c\nindex c20e88a6941..a5269baf067 100644\n--- a/contrib/plugins/execlog.c\n+++ b/contrib/plugins/execlog.c\n@@ -27,6 +27,7 @@ typedef struct CPU {\n     GString *last_exec;\n     /* Ptr array of Register */\n     GPtrArray *registers;\n+    int index;\n } CPU;\n \n QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;\n@@ -38,6 +39,9 @@ static GRWLock expand_array_lock;\n static GPtrArray *imatches;\n static GArray *amatches;\n static GPtrArray *rmatches;\n+static bool disas_assist;\n+static GMutex add_reg_name_lock;\n+static GPtrArray *all_reg_names;\n \n /**\n  * Add memory read or write information to current instruction log\n@@ -72,9 +76,14 @@ static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t info,\n }\n \n /**\n- * Log instruction execution\n+ * Log instruction execution, outputting the last one.\n+ *\n+ * vcpu_insn_exec() is a copy and paste of vcpu_insn_exec_with_regs()\n+ * without the checking of register values when we've attempted to\n+ * optimise with disas_assist.\n  */\n-static void vcpu_insn_exec(unsigned int cpu_index, void *udata)\n+\n+static CPU *get_cpu(int cpu_index)\n {\n     CPU *cpu;\n \n@@ -83,39 +92,87 @@ static void vcpu_insn_exec(unsigned int cpu_index, void *udata)\n     cpu = &cpus[cpu_index];\n     g_rw_lock_reader_unlock(&expand_array_lock);\n \n+    return cpu;\n+}\n+\n+static void insn_check_regs(CPU *cpu) {\n+    for (int n = 0; n < cpu->registers->len; n++) {\n+        Register *reg = cpu->registers->pdata[n];\n+        int sz;\n+\n+        g_byte_array_set_size(reg->new, 0);\n+        sz = qemu_plugin_read_register(cpu->index, reg->handle, reg->new);\n+        g_assert(sz == reg->last->len);\n+\n+        if (memcmp(reg->last->data, reg->new->data, sz)) {\n+            GByteArray *temp = reg->last;\n+            g_string_append_printf(cpu->last_exec, \", %s -> 0x\", reg->name);\n+            /* TODO: handle BE properly */\n+            for (int i = sz; i >= 0; i--) {\n+                g_string_append_printf(cpu->last_exec, \"%02x\",\n+                                       reg->new->data[i]);\n+            }\n+            reg->last = reg->new;\n+            reg->new = temp;\n+        }\n+    }\n+}\n+\n+/* Log last instruction while checking registers */\n+static void vcpu_insn_exec_with_regs(unsigned int cpu_index, void *udata)\n+{\n+    CPU *cpu = get_cpu(cpu_index);\n+\n     /* Print previous instruction in cache */\n     if (cpu->last_exec->len) {\n         if (cpu->registers) {\n-            for (int n = 0; n < cpu->registers->len; n++) {\n-                Register *reg = cpu->registers->pdata[n];\n-                int sz;\n-\n-                g_byte_array_set_size(reg->new, 0);\n-                sz = qemu_plugin_read_register(cpu_index, reg->handle, reg->new);\n-                g_assert(sz == reg->last->len);\n-\n-                if (memcmp(reg->last->data, reg->new->data, sz)) {\n-                    GByteArray *temp = reg->last;\n-                    g_string_append_printf(cpu->last_exec, \", %s -> 0x\", reg->name);\n-                    /* TODO: handle BE properly */\n-                    for (int i = sz; i >= 0; i--) {\n-                        g_string_append_printf(cpu->last_exec, \"%02x\",\n-                                               reg->new->data[i]);\n-                    }\n-                    reg->last = reg->new;\n-                    reg->new = temp;\n-                }\n-            }\n+            insn_check_regs(cpu);\n+        }\n+\n+        qemu_plugin_outs(cpu->last_exec->str);\n+        qemu_plugin_outs(\"\\n\");\n+    }\n+\n+    /* Store new instruction in cache */\n+    /* vcpu_mem will add memory access information to last_exec */\n+    g_string_printf(cpu->last_exec, \"%u, \", cpu_index);\n+    g_string_append(cpu->last_exec, (char *)udata);\n+}\n+\n+/* Log last instruction while checking registers, ignore next */\n+static void vcpu_insn_exec_only_regs(unsigned int cpu_index, void *udata)\n+{\n+    CPU *cpu = get_cpu(cpu_index);\n+\n+    /* Print previous instruction in cache */\n+    if (cpu->last_exec->len) {\n+        if (cpu->registers) {\n+            insn_check_regs(cpu);\n         }\n \n         qemu_plugin_outs(cpu->last_exec->str);\n         qemu_plugin_outs(\"\\n\");\n     }\n \n+    /* reset */\n+    cpu->last_exec->len = 0;\n+}\n+\n+/* Log last instruction without checking regs, setup next */\n+static void vcpu_insn_exec(unsigned int cpu_index, void *udata)\n+{\n+    CPU *cpu = get_cpu(cpu_index);\n+\n+    /* Print previous instruction in cache */\n+    if (cpu->last_exec->len) {\n+        qemu_plugin_outs(cpu->last_exec->str);\n+        qemu_plugin_outs(\"\\n\");\n+    }\n+\n     /* Store new instruction in cache */\n     /* vcpu_mem will add memory access information to last_exec */\n-    g_string_printf(cpus[cpu_index].last_exec, \"%u, \", cpu_index);\n-    g_string_append(cpus[cpu_index].last_exec, (char *)udata);\n+    g_string_printf(cpu->last_exec, \"%u, \", cpu_index);\n+    g_string_append(cpu->last_exec, (char *)udata);\n }\n \n /**\n@@ -128,6 +185,8 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)\n {\n     struct qemu_plugin_insn *insn;\n     bool skip = (imatches || amatches);\n+    bool check_regs_this = rmatches;\n+    bool check_regs_next = false;\n \n     size_t n = qemu_plugin_tb_n_insns(tb);\n     for (size_t i = 0; i < n; i++) {\n@@ -148,7 +207,8 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)\n         /*\n          * If we are filtering we better check out if we have any\n          * hits. The skip \"latches\" so we can track memory accesses\n-         * after the instruction we care about.\n+         * after the instruction we care about. Also enable register\n+         * checking on the next instruction.\n          */\n         if (skip && imatches) {\n             int j;\n@@ -156,6 +216,7 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)\n                 char *m = g_ptr_array_index(imatches, j);\n                 if (g_str_has_prefix(insn_disas, m)) {\n                     skip = false;\n+                    check_regs_next = rmatches;\n                 }\n             }\n         }\n@@ -170,8 +231,38 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)\n             }\n         }\n \n+        /*\n+         * Check the disassembly to see if a register we care about\n+         * will be affected by this instruction. This relies on the\n+         * dissembler doing something sensible for the registers we\n+         * care about.\n+         */\n+        if (disas_assist && rmatches) {\n+            check_regs_next = false;\n+            gchar *args = g_strstr_len(insn_disas, -1, \" \");\n+            for (int n = 0; n < all_reg_names->len; n++) {\n+                gchar *reg = g_ptr_array_index(all_reg_names, n);\n+                if (g_strrstr(args, reg)) {\n+                    check_regs_next = true;\n+                    skip = false;\n+                }\n+            }\n+        }\n+\n+        /*\n+         * We now have 3 choices:\n+         *\n+         * Log this instruction normally\n+         * Log this instruction checking for register changes\n+         * Don't log this instruction but check for register changes from the last one\n+         */\n+\n         if (skip) {\n-            g_free(insn_disas);\n+            if (check_regs_this) {\n+                qemu_plugin_register_vcpu_insn_exec_cb(insn,\n+                                                       vcpu_insn_exec_only_regs,\n+                                                       QEMU_PLUGIN_CB_R_REGS, NULL);\n+            }\n         } else {\n             uint32_t insn_opcode;\n             insn_opcode = *((uint32_t *)qemu_plugin_insn_data(insn));\n@@ -184,15 +275,28 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)\n                                              QEMU_PLUGIN_MEM_RW, NULL);\n \n             /* Register callback on instruction */\n-            qemu_plugin_register_vcpu_insn_exec_cb(\n-                insn, vcpu_insn_exec,\n-                rmatches ? QEMU_PLUGIN_CB_R_REGS : QEMU_PLUGIN_CB_NO_REGS,\n-                output);\n+            if (check_regs_this) {\n+                qemu_plugin_register_vcpu_insn_exec_cb(\n+                    insn, vcpu_insn_exec_with_regs,\n+                    QEMU_PLUGIN_CB_R_REGS,\n+                    output);\n+            } else {\n+                qemu_plugin_register_vcpu_insn_exec_cb(\n+                    insn, vcpu_insn_exec,\n+                    QEMU_PLUGIN_CB_NO_REGS,\n+                    output);\n+            }\n \n             /* reset skip */\n             skip = (imatches || amatches);\n         }\n \n+        /* set regs for next */\n+        if (disas_assist && rmatches) {\n+            check_regs_this = check_regs_next;\n+        }\n+\n+        g_free(insn_disas);\n     }\n }\n \n@@ -200,10 +304,11 @@ static Register *init_vcpu_register(int vcpu_index,\n                                     qemu_plugin_reg_descriptor *desc)\n {\n     Register *reg = g_new0(Register, 1);\n+    g_autofree gchar *lower = g_utf8_strdown(desc->name, -1);\n     int r;\n \n     reg->handle = desc->handle;\n-    reg->name = g_strdup(desc->name);\n+    reg->name = g_intern_string(lower);\n     reg->last = g_byte_array_new();\n     reg->new = g_byte_array_new();\n \n@@ -213,7 +318,7 @@ static Register *init_vcpu_register(int vcpu_index,\n     return reg;\n }\n \n-static registers_init(int vcpu_index)\n+static void registers_init(int vcpu_index)\n {\n     GPtrArray *registers = g_ptr_array_new();\n     g_autoptr(GArray) reg_list = qemu_plugin_get_registers(vcpu_index);\n@@ -228,9 +333,20 @@ static registers_init(int vcpu_index)\n                 reg_list, qemu_plugin_reg_descriptor, r);\n             for (int p = 0; p < rmatches->len; p++) {\n                 g_autoptr(GPatternSpec) pat = g_pattern_spec_new(rmatches->pdata[p]);\n-                if (g_pattern_match_string(pat, rd->name)) {\n+                g_autofree gchar *rd_lower = g_utf8_strdown(rd->name, -1);\n+                if (g_pattern_match_string(pat, rd->name) ||\n+                    g_pattern_match_string(pat, rd_lower)) {\n                     Register *reg = init_vcpu_register(vcpu_index, rd);\n                     g_ptr_array_add(registers, reg);\n+\n+                    /* we need a list of regnames at TB translation time */\n+                    if (disas_assist) {\n+                        g_mutex_lock(&add_reg_name_lock);\n+                        if (!g_ptr_array_find(all_reg_names, reg->name, NULL)) {\n+                            g_ptr_array_add(all_reg_names, reg->name);\n+                        }\n+                        g_mutex_unlock(&add_reg_name_lock);\n+                    }\n                 }\n             }\n         }\n@@ -254,6 +370,7 @@ static void vcpu_init(qemu_plugin_id_t id, unsigned int vcpu_index)\n     if (vcpu_index >= num_cpus) {\n         cpus = g_realloc_n(cpus, vcpu_index + 1, sizeof(*cpus));\n         while (vcpu_index >= num_cpus) {\n+            cpus[num_cpus].index = vcpu_index;\n             cpus[num_cpus].last_exec = g_string_new(NULL);\n \n             /* Any registers to track? */\n@@ -336,6 +453,12 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,\n             parse_vaddr_match(tokens[1]);\n         } else if (g_strcmp0(tokens[0], \"reg\") == 0) {\n             add_regpat(tokens[1]);\n+        } else if (g_strcmp0(tokens[0], \"rdisas\") == 0) {\n+            if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &disas_assist)) {\n+                fprintf(stderr, \"boolean argument parsing failed: %s\\n\", opt);\n+                return -1;\n+            }\n+            all_reg_names = g_ptr_array_new();\n         } else {\n             fprintf(stderr, \"option parsing failed: %s\\n\", opt);\n             return -1;\n","prefixes":["v2","41/43"]}