-
-
Couldn't load subscription status.
- Fork 47
Open
Description
Here's the situation - you want to find the bytecode that was just executed in a frame, possibly in a trace func. Here are a pair of things you could want:
-
The current
ConcreteInstrobject corresponding tof_lasti:def get_concrete_index(concrete_bc, code_index): at = 0 concrete_index = 0 for c in concrete_bc: at += c.size if at < code_index: concrete_index += 1 return concrete_index
Which can be used as:
concrete_bc = ConcreteBytecode.from_code(frame.code) ci = get_concrete_index(concrete_bc, frame.f_lasti) concrete_instr = concrete_bc[ci]
-
the current
Instrobject corresponding tociorflasti:def promote_concrete_index(bc, concrete_index): index = None at = 0 for i, b in enumerate(bc): if at == concrete_index: index = i if isinstance(b, bytecode.instr.BaseInstr): at += 1 return index
Used as
bc = concrete_bc.to_bytecode() i = promote_concrete_index(bc, ci) instr = bc[concrete_bc]
- Does this code look correct for all cases?
- Does this make sense as a library addition? If so, how are these operations best exposed in the API?
thautwarm
Metadata
Metadata
Assignees
Labels
No labels