dynamorio icon indicating copy to clipboard operation
dynamorio copied to clipboard

Add new whole-instr register iterator

Open edeiana opened this issue 1 year ago • 0 comments

Currently we don't have a way to iterate over the register operands of an instr_t directly. To do so, we have to:

  1. obtain the number of src (instr_num_srcs()) and dst (instr_num_dsts()) operands;
  2. iterate over and obtain the operand (with instr_get_src() and instr_get_dst());
  3. obtain the number of registers of every operand with opnd_num_regs_used();
  4. iterate over and obtain the reg_id_t register with opnd_get_reg_used().

We find this operation common enough to warrant its own APIs in core/ir/instr_shared.c to avoid code duplication.

Since we still want to distinguish between source register operands and destination register operands of an instr_t, we'd want the following 4 APIs:

uint instr_num_src_reg(instr_t *instr);
uint instr_num_dst_reg(instr_t *instr);
reg_id_t instr_get_src_reg(instr_t *instr, uint index);
reg_id_t instr_get_dst_reg(instr_t *instr, uint index);

Note that registers in destination operands that are memory references are still being read, hence they should be counted among the source register operands of an instruction.

edeiana avatar Mar 23 '24 01:03 edeiana