[issue17916] Provide dis.Bytecode based equivalent of dis.distb

Nick Coghlan report at bugs.python.org
Thu Oct 24 15:48:06 CEST 2013


Nick Coghlan added the comment:

It's not quite that simple - the instruction responsible for the exception also needs to be recorded, and Bytecode doesn't currently allow for that (look at the way the "lasti" arg to disassemble is used in disttb, and then how that gets passed to the "mark_as_current" flag in Instruction._disassemble by _disassemble_bytes).

So, on reflection, I think a TracebackBytecode class may be a better idea, exposing "bytecode" and "last_offset" attributes.

Rather than iteration just producing instructions, it would produce (instruction, is_current) 2-tuples, and display_code would call through to "self.bytecode.display_code(self.last_offset)" (there would be no show_info() or info() methods on TracebackBytecode).

Bytecode.display_code would gain a new "current_offset" parameter, which it would pass through to _disassemble_bytes as the "lasti" parameter.

Reviewing this also made me realise "line_offset" in dis.get_instructions is misnamed - see issue 19378.

----------
dependencies: +Rename "line_offset" parameter in dis.get_instructions to "first_line"

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17916>
_______________________________________


More information about the Python-bugs-list mailing list