dynamorio
dynamorio copied to clipboard
Add new whole-instr register iterator
Currently we don't have a way to iterate over the register operands of an instr_t directly. To do so, we have to:
- obtain the number of src (
instr_num_srcs()) and dst (instr_num_dsts()) operands; - iterate over and obtain the operand (with
instr_get_src()andinstr_get_dst()); - obtain the number of registers of every operand with
opnd_num_regs_used(); - iterate over and obtain the
reg_id_tregister withopnd_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.