Re: A lean way for getting the size of the instruction at a given address

Luis Machado via Gdb
2021-04-05T13:02:11Z

Hi Zied,

On 4/4/21 4:59 AM, Zied Guermazi wrote:
> hi
>
> I need to get the size of the instruction at a given address. I am
> currently using gdb_insn_length (struct gdbarch *gdbarch, CORE_ADDR
> addr) which calls gdb_print_insn (struct gdbarch *gdbarch, CORE_ADDR
> memaddr, struct ui_file *stream, int *branch_delay_insns). and this is
> consuming a huge time, considering that this is used in branch tracing
> and this gets repeated up to few millions times.
>
>
> Is there a lean way for getting the size of the instruction at a given
> address, I am using it for aarch64 and arm targets.

At the moment I don't think there is an optimal solution for this. The
instruction length is calculated as part of the disassemble process, and
is tied to the function that prints instructions.

One way to speed things up is to have a new member function in "class
gdb_disassembler" to calculate the instruction length only.

Another way is to have a new gdbarch hook that calculates the size of an
instruction based on the current PC, mapping symbols etc.

>
> Kind Regards
>
> Zied Guermazi
>
>