public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: binutils@sourceware.org
Subject: Re: [PATCHv2] libopcodes: extend the styling within the i386 disassembler
Date: Thu, 26 May 2022 13:48:59 +0100	[thread overview]
Message-ID: <874k1cihms.fsf@redhat.com> (raw)
In-Reply-To: <0afe6d6b-08a4-b1b5-80a3-98e3b232dbc5@suse.com>

Jan Beulich via Binutils <binutils@sourceware.org> writes:

> On 09.05.2022 14:54, Andrew Burgess via Binutils wrote:
>> @@ -248,6 +254,8 @@ struct instr_info
>>  
>>    enum x86_64_isa isa64;
>>  
>> +  int (*printf) (instr_info *ins, enum disassembler_style style,
>> +		 const char *fmt, ...) ATTRIBUTE_FPTR_PRINTF_3;
>>  };
>
> Why do you go through a function pointer? Afaics it's only ever set
> to i386_dis_printf(), so I don't see why you couldn't call the
> function directly.
>
>> @@ -9748,24 +9839,28 @@ print_insn (bfd_vma pc, instr_info *ins)
>>  	if (name == NULL)
>>  	  abort ();
>>  	prefix_length += strlen (name) + 1;
>> -	(*ins->info->fprintf_styled_func)
>> -	  (ins->info->stream, dis_style_mnemonic, "%s ", name);
>> +	ins->printf (ins, dis_style_mnemonic, "%s ", name);
>>        }
>>  
>>    /* Check maximum code length.  */
>>    if ((ins->codep - ins->start_codep) > MAX_CODE_LENGTH)
>>      {
>> -      (*ins->info->fprintf_styled_func)
>> -	(ins->info->stream, dis_style_text, "(bad)");
>> +      ins->printf (ins, dis_style_text, "(bad)");
>>        return MAX_CODE_LENGTH;
>>      }
>>  
>> -  ins->obufp = ins->mnemonicendp;
>> -  for (i = strlen (ins->obuf) + prefix_length; i < 6; i++)
>> -    oappend (ins, " ");
>> -  oappend (ins, " ");
>> -  (*ins->info->fprintf_styled_func)
>> -    (ins->info->stream, dis_style_mnemonic, "%s", ins->obuf);
>> +  i = strlen (ins->obuf);
>> +  if (ins->mnemonicendp == ins->obuf + i)
>
> What is this condition for? It doesn't look to match any of what the
> original code does. In particular it's unclear to me ...
>
>> +    {
>> +      i += prefix_length;
>> +      if (i < 6)
>> +	i = 6 - i + 1;
>> +      else
>> +	i = 1;
>> +    }
>> +  else
>> +    i = 0;
>
> ... what this "else" would cover.

This whole nonsense was a convoluted method of maintaining compatibility
with the existing disassembler when it comes to emitting trailing
whitespace.

I've now posted this separate patch:

  https://sourceware.org/pipermail/binutils/2022-May/121054.html

which fixes what I think are some inconsistencies in how the existing
disassembler handles whitespace.

With that patch merged this whole hunk will disappear from this patch.

I'm in the process of addressing the remaining points that you and
H.J. have raised.

Thanks,
Andrew


>
>> @@ -10224,8 +10314,11 @@ static void
>>  OP_STi (instr_info *ins, int bytemode ATTRIBUTE_UNUSED,
>>  	int sizeflag ATTRIBUTE_UNUSED)
>>  {
>> -  sprintf (ins->scratchbuf, "%%st(%d)", ins->modrm.rm);
>> -  oappend_maybe_intel (ins, ins->scratchbuf);
>> +  oappend_maybe_intel (ins, "%st");
>> +  oappend (ins, "(");
>
> Any reason these last two aren't simply
>
>   oappend_maybe_intel (ins, "%st(");
>
> ?
>
>> +  sprintf (ins->scratchbuf, "%d", ins->modrm.rm);
>> +  oappend_with_style (ins, ins->scratchbuf, dis_style_immediate);
>
> This is not an immediate. The entire %st(N) is a register name (like
> anything that starts with % in AT&T mode).
>
>> @@ -10772,12 +10865,64 @@ putop (instr_info *ins, const char *in_template, int sizeflag)
>>    return 0;
>>  }
>>  
>> +/* Add a style marker to *INS->obufp that encodes STYLE.  This assumes that
>> +   the buffer pointed to by INS->obufp has space.  A style marker is made
>> +   from the STYLE_MARKER_CHAR followed by STYLE converted to a single hex
>> +   digit, followed by another STYLE_MARKER_CHAR.  This function assumes
>> +   that the number of styles is not greater than 16.  */
>> +
>>  static void
>> -oappend (instr_info *ins, const char *s)
>> +oappend_insert_style (instr_info *ins, enum disassembler_style style)
>>  {
>> +  int num = (int) style;
>> +
>> +  /* We currently assume that STYLE can be encoded as a single hex
>> +     character.  If more styles are added then this might start to fail,
>> +     and we'll need to expand this code.  */
>> +  if (num > 0xf)
>> +    abort ();
>
> You want to either also check for negative values or make "num" unsigned.
>
>> @@ -10789,26 +10934,27 @@ append_seg (instr_info *ins)
>>    switch (ins->active_seg_prefix)
>>      {
>>      case PREFIX_CS:
>> -      oappend_maybe_intel (ins, "%cs:");
>> +      oappend_maybe_intel_with_style (ins, "%cs", dis_style_register);
>
> I was about to ask why dis_style_register needs specifying here, but I
> notice the comment ahead of the function is misleading. There also are
> cases where a leading '$' would be skipped. I wonder though whether it
> wouldn't yield better readable code if those used a separate function,
> thus eliminating the need for the explicit style parameter. E.g.
> oappend_register() and oappend_immediate(). The "maybe_intel" part of
> the name isn't really useful imo.
>
>> @@ -13352,7 +13502,7 @@ OP_VexI4 (instr_info *ins, int bytemode ATTRIBUTE_UNUSED,
>>  {
>>    ins->scratchbuf[0] = '$';
>>    print_operand_value (ins, ins->scratchbuf + 1, 1, ins->codep[-1] & 0xf);
>> -  oappend_maybe_intel (ins, ins->scratchbuf);
>> +  oappend_maybe_intel_with_style (ins, ins->scratchbuf, dis_style_text);
>>  }
>>  
>>  static void
>> @@ -13397,7 +13547,7 @@ VPCMP_Fixup (instr_info *ins, int bytemode ATTRIBUTE_UNUSED,
>>        /* We have a reserved extension byte.  Output it directly.  */
>>        ins->scratchbuf[0] = '$';
>>        print_operand_value (ins, ins->scratchbuf + 1, 1, cmp_type);
>> -      oappend_maybe_intel (ins, ins->scratchbuf);
>> +      oappend_maybe_intel_with_style (ins, ins->scratchbuf, dis_style_text);
>>        ins->scratchbuf[0] = '\0';
>>      }
>>  }
>> @@ -13449,7 +13599,7 @@ VPCOM_Fixup (instr_info *ins, int bytemode ATTRIBUTE_UNUSED,
>>        /* We have a reserved extension byte.  Output it directly.  */
>>        ins->scratchbuf[0] = '$';
>>        print_operand_value (ins, ins->scratchbuf + 1, 1, cmp_type);
>> -      oappend_maybe_intel (ins, ins->scratchbuf);
>> +      oappend_maybe_intel_with_style (ins, ins->scratchbuf, dis_style_text);
>>        ins->scratchbuf[0] = '\0';
>>      }
>>  }
>
> Why "text" for these three immediates, but ...
>
>> @@ -13497,7 +13647,8 @@ PCLMUL_Fixup (instr_info *ins, int bytemode ATTRIBUTE_UNUSED,
>>        /* We have a reserved extension byte.  Output it directly.  */
>>        ins->scratchbuf[0] = '$';
>>        print_operand_value (ins, ins->scratchbuf + 1, 1, pclmul_type);
>> -      oappend_maybe_intel (ins, ins->scratchbuf);
>> +      oappend_maybe_intel_with_style (ins, ins->scratchbuf,
>> +				      dis_style_immediate);
>>        ins->scratchbuf[0] = '\0';
>>      }
>>  }
>
> ... "immediate" here?
>
> Jan


  reply	other threads:[~2022-05-26 12:49 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-29 13:42 [PATCH 0/2] Disassembler styling for i386-dis.c Andrew Burgess
2022-04-29 13:42 ` [PATCH 1/2] objdump: fix styled printing of addresses Andrew Burgess
2022-05-02  7:14   ` Jan Beulich
2022-05-03  9:52     ` Andrew Burgess
2022-04-29 13:42 ` [PATCH 2/2] libopcodes: extend the styling within the i386 disassembler Andrew Burgess
2022-04-29 18:16   ` Vladimir Mezentsev
2022-05-03 13:15     ` Andrew Burgess
2022-04-29 18:57   ` H.J. Lu
2022-05-03 13:14     ` Andrew Burgess
2022-05-02  7:28   ` Jan Beulich
2022-05-03 13:12     ` Andrew Burgess
2022-05-03 15:47       ` H.J. Lu
2022-05-04  7:58       ` Jan Beulich
2022-05-09  9:48         ` Andrew Burgess
2022-05-09 12:54           ` [PATCHv2] " Andrew Burgess
2022-05-18 12:27             ` Jan Beulich
2022-05-26 12:48               ` Andrew Burgess [this message]
2022-05-18 21:23             ` H.J. Lu
2022-05-27 17:44             ` [PATCHv3] " Andrew Burgess
2022-05-30  8:19               ` Jan Beulich
2022-05-31 17:20                 ` Andrew Burgess
2022-06-01  5:59                   ` Jan Beulich
2022-06-01 15:56                     ` H.J. Lu
2022-06-08 16:03                       ` Andrew Burgess
2022-06-10 10:56               ` Jan Beulich
2022-06-10 13:01                 ` Andrew Burgess
2022-05-18  7:06           ` [PATCH 2/2] " Jan Beulich
2022-05-18 10:41             ` Andrew Burgess
2022-05-18 10:46               ` Jan Beulich

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=874k1cihms.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=binutils@sourceware.org \
    --cc=jbeulich@suse.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 read-only IMAP folder(s) and NNTP newsgroup(s).