From: "Alex Bennée" <alex.bennee@linaro.org>
To: Yodel Eldar <yodel.eldar@gmail.com>
Cc: qemu-devel@nongnu.org, richard.henderson@linaro.org, laurent@vivier.eu
Subject: Re: [PATCH 1/2] contrib/plugins/execlog: Add tab to the separator search of insn_disas
Date: Mon, 30 Jun 2025 09:42:49 +0100 [thread overview]
Message-ID: <87zfdpfwmu.fsf@draig.linaro.org> (raw)
In-Reply-To: <4932277d-ae7c-469a-93bb-db44913c1a1b@gmail.com> (Yodel Eldar's message of "Sun, 29 Jun 2025 17:49:02 -0500")
Yodel Eldar <yodel.eldar@gmail.com> writes:
> On 6/29/25 1:50 PM, Alex Bennée wrote:
>> Yodel Eldar <yodel.eldar@gmail.com> writes:
>>
>>> Currently, execlog searches for a space separator between the
>>> instruction mnemonic and operands, but some disassemblers, e.g. Alpha's,
>>> use a tab separator instead; this results in a null pointer being passed
>>> as the haystack in g_strstr during a subsequent register search, i.e.
>>> undefined behavior, because of a missing null check.
>>>
>>> This patch adds tab to the separator search and a null check on the
>>> result.
>>>
>>> Also, existing, affected pointers are changed to const.
>>>
>>> Lastly, a break statement was added to immediately terminate the
>>> register search when a user-requested register is found in the current
>>> instruction as a trivial optimization, because searching for the
>>> remaining requested registers is unnecessary once one is found.
>>>
>>> Signed-off-by: Yodel Eldar <yodel.eldar@gmail.com>
>>> ---
>>> contrib/plugins/execlog.c | 15 +++++++++------
>>> 1 file changed, 9 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/contrib/plugins/execlog.c b/contrib/plugins/execlog.c
>>> index d67d010761..08fc1f12d4 100644
>>> --- a/contrib/plugins/execlog.c
>>> +++ b/contrib/plugins/execlog.c
>>> @@ -232,12 +232,15 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
>>> */
>>> if (disas_assist && rmatches) {
>>> check_regs_next = false;
>>> - gchar *args = g_strstr_len(insn_disas, -1, " ");
>>> - for (int n = 0; n < all_reg_names->len; n++) {
>>> - gchar *reg = g_ptr_array_index(all_reg_names, n);
>>> - if (g_strrstr(args, reg)) {
>>> - check_regs_next = true;
>>> - skip = false;
>>> + const gchar *args = strpbrk(insn_disas, " \t");
>> We have a general preference for glib here, could we use g_strsplit_set?
>>
>> Something like:
>>
>> modified contrib/plugins/execlog.c
>> @@ -232,12 +232,14 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
>> */
>> if (disas_assist && rmatches) {
>> check_regs_next = false;
>> - gchar *args = g_strstr_len(insn_disas, -1, " ");
>> - for (int n = 0; n < all_reg_names->len; n++) {
>> - gchar *reg = g_ptr_array_index(all_reg_names, n);
>> - if (g_strrstr(args, reg)) {
>> - check_regs_next = true;
>> - skip = false;
>> + g_auto(GStrv) args = g_strsplit_set(insn_disas, " \t", 2);
>> + if (args && args[1]) {
>> + for (int n = 0; n < all_reg_names->len; n++) {
>> + gchar *reg = g_ptr_array_index(all_reg_names, n);
>> + if (g_strrstr(args[1], reg)) {
>> + check_regs_next = true;
>> + skip = false;
>> + }
>>
>
> Certainly, and thanks for the suggestion! May I credit you with a
> "Suggested-by" or "Co-authored-by" tag in v2 of the patch?
Suggested-by is fine ;-)
>
>
>>> + if (args) {
>>> + for (int n = 0; n < all_reg_names->len; n++) {
>>> + const gchar *reg = g_ptr_array_index(all_reg_names, n);
>>> + if (g_strrstr(args, reg)) {
>>> + check_regs_next = true;
>>> + skip = false;
>>> + break;
>>> + }
>>> }
>>> }
>>> }
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
next prev parent reply other threads:[~2025-06-30 8:43 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-27 20:47 [PATCH 0/2] target/alpha: Add TCG plugin register tracking support Yodel Eldar
2025-06-27 20:47 ` [PATCH 1/2] contrib/plugins/execlog: Add tab to the separator search of insn_disas Yodel Eldar
2025-06-29 18:50 ` Alex Bennée
2025-06-29 22:49 ` Yodel Eldar
2025-06-30 8:42 ` Alex Bennée [this message]
2025-06-27 20:47 ` [PATCH 2/2] target/alpha: Add GDB XML feature file Yodel Eldar
2025-06-28 10:09 ` Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87zfdpfwmu.fsf@draig.linaro.org \
--to=alex.bennee@linaro.org \
--cc=laurent@vivier.eu \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=yodel.eldar@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).