dis

Provides tools for disassembling bytecode.

Code Disassembly in Kuroko

The dis module contains functions for dealing with code objects which represent the compiled bytecode of a Kuroko function. The bytecode compilation process is entirely static and bytecode analysis can be performed without calling into the VM to run dynamic code.

Debugger Breakpoints

Kuroko interpreters can provide a debugger hook through the C API's krk_debug_registerCallback() function. Breakpoints can be managed both from the C API and from this module's addbreakpoint, delbreakpoint, enablebreakpoint, and disablebreakpoint methods.

Functions

_addbreakpoint(func, line)

Attach a breakpoint to a code object.

func may be a filename string, or a function, method, or code object. Returns the new breakpoint index, or raises Exception if a breakpoint code not be added.

_build(code)

Compile a string to a code object.

Compiles the string code and returns a code object. If a syntax error is encountered, it will be raised.

_delbreakpoint(handle)

Delete a breakpoint.

Delete the breakpoint specified by handle, disabling it if it was enabled. May raise IndexError if handle is not a valid breakpoint handle.

_dis(obj)

Disassemble an object.

Dumps a disassembly of the bytecode in the code object associated with obj. If obj can not be disassembled, a TypeError is raised.

_disablebreakpoint(handle)

Disable a breakpoint.

Disable the breakpoint specified by handle. May raise IndexError if handle is not a valid breakpoint handle.

_enablebreakpoint(handle)

Enable a breakpoint.

Enable the breakpoint specified by handle. May raise IndexError if handle is not a valid breakpoint handle.

_examine(func)

Convert a code object to a list of instructions.

Examines the code object func and returns a list representation of its instructions. Each instruction entry is a tuple of the opcode, total instruction size in bytes, and the operand of the argument, either as an integer for jump offsets, the actual value for constant operands, or the name of a local or global variable if available.

_ip_to_expression(func,ip)

Map an IP in a codeobject or function to an expression span.

For various reasons, the instruction pointer ip must be the last byte of an opcode.

Constants

let BREAKPOINT_ONCE = 1

let BREAKPOINT_REPEAT = 2

let OP_ADD = 39

let OP_ANNOTATE = 70

let OP_BEGIN_FINALLY = 2

let OP_BITAND = 72

let OP_BITNEGATE = 137

let OP_BITOR = 12

let OP_BITXOR = 95

let OP_BREAKPOINT = 43

let OP_CALL = 100

let OP_CALL_ITER = 149

let OP_CALL_LONG = 101

let OP_CALL_METHOD = 41

let OP_CALL_METHOD_LONG = 42

let OP_CLEANUP_WITH = 52

let OP_CLOSE_MANY = 10

let OP_CLOSE_MANY_LONG = 11

let OP_CLOSE_UPVALUE = 20

let OP_CLOSURE = 15

let OP_CLOSURE_LONG = 16

let OP_CONSTANT = 0

let OP_CONSTANT_LONG = 1

let OP_DEFINE_GLOBAL = 92

let OP_DEFINE_GLOBAL_LONG = 93

let OP_DEL_GLOBAL = 119

let OP_DEL_GLOBAL_LONG = 120

let OP_DEL_PROPERTY = 133

let OP_DEL_PROPERTY_LONG = 134

let OP_DICT_SET = 77

let OP_DICT_SET_LONG = 78

let OP_DICT_SET_TOP = 156

let OP_DICT_UPDATE_TOP = 155

let OP_DIVIDE = 53

let OP_DUP = 131

let OP_DUP_LONG = 132

let OP_END_FINALLY = 112

let OP_ENTER_EXCEPT = 162

let OP_EQUAL = 58

let OP_EXIT_LOOP = 34

let OP_EXIT_LOOP_LONG = 35

let OP_EXPAND_ARGS = 147

let OP_EXPAND_ARGS_LONG = 148

let OP_FALSE = 129

let OP_FILTER_EXCEPT = 71

let OP_FLOORDIV = 130

let OP_FORMAT_VALUE = 50

let OP_FORMAT_VALUE_LONG = 51

let OP_GET_GLOBAL = 44

let OP_GET_GLOBAL_LONG = 45

let OP_GET_LOCAL = 144

let OP_GET_LOCAL_LONG = 145

let OP_GET_METHOD = 107

let OP_GET_METHOD_LONG = 108

let OP_GET_NAME = 109

let OP_GET_NAME_LONG = 110

let OP_GET_PROPERTY = 126

let OP_GET_PROPERTY_LONG = 127

let OP_GET_SUPER = 84

let OP_GET_SUPER_LONG = 85

let OP_GET_UPVALUE = 7

let OP_GET_UPVALUE_LONG = 8

let OP_GREATER = 128

let OP_GREATER_EQUAL = 103

let OP_IMPORT = 21

let OP_IMPORT_FROM = 75

let OP_IMPORT_FROM_LONG = 76

let OP_IMPORT_LONG = 22

let OP_INPLACE_ADD = 106

let OP_INPLACE_BITAND = 30

let OP_INPLACE_BITOR = 89

let OP_INPLACE_BITXOR = 117

let OP_INPLACE_DIVIDE = 83

let OP_INPLACE_FLOORDIV = 29

let OP_INPLACE_MATMUL = 118

let OP_INPLACE_MODULO = 90

let OP_INPLACE_MULTIPLY = 146

let OP_INPLACE_POW = 140

let OP_INPLACE_SHIFTLEFT = 27

let OP_INPLACE_SHIFTRIGHT = 121

let OP_INPLACE_SUBTRACT = 96

let OP_INVOKE_AWAIT = 38

let OP_INVOKE_CONTAINS = 81

let OP_INVOKE_DELETE = 66

let OP_INVOKE_GETTER = 80

let OP_INVOKE_ITER = 49

let OP_INVOKE_SETTER = 82

let OP_IS = 3

let OP_JUMP = 23

let OP_JUMP_IF_FALSE_OR_POP = 24

let OP_JUMP_IF_TRUE_OR_POP = 150

let OP_KWARGS = 56

let OP_KWARGS_LONG = 57

let OP_LESS = 94

let OP_LESS_EQUAL = 111

let OP_LIST_APPEND = 25

let OP_LIST_APPEND_LONG = 26

let OP_LIST_APPEND_TOP = 154

let OP_LIST_EXTEND_TOP = 153

let OP_LOOP = 136

let OP_LOOP_ITER = 60

let OP_MAKE_DICT = 115

let OP_MAKE_DICT_LONG = 116

let OP_MAKE_LIST = 142

let OP_MAKE_LIST_LONG = 143

let OP_MAKE_SET = 18

let OP_MAKE_SET_LONG = 19

let OP_MAKE_STRING = 36

let OP_MAKE_STRING_LONG = 37

let OP_MATMUL = 113

let OP_MISSING_KW = 151

let OP_MISSING_KW_LONG = 152

let OP_MODULO = 114

let OP_MULTIPLY = 135

let OP_NEGATE = 48

let OP_NONE = 73

let OP_NOT = 99

let OP_OVERLONG_JUMP = 164

let OP_POP = 74

let OP_POP_JUMP_IF_FALSE = 69

let OP_POP_MANY = 4

let OP_POP_MANY_LONG = 5

let OP_POS = 91

let OP_POW = 139

let OP_PUSH_BUILD_CLASS = 165

let OP_PUSH_TRY = 6

let OP_PUSH_WITH = 102

let OP_RAISE = 33

let OP_RAISE_FROM = 67

let OP_RETURN = 138

let OP_REVERSE = 124

let OP_REVERSE_LONG = 125

let OP_SET_ADD = 13

let OP_SET_ADD_LONG = 14

let OP_SET_ADD_TOP = 158

let OP_SET_GLOBAL = 31

let OP_SET_GLOBAL_LONG = 32

let OP_SET_LOCAL = 64

let OP_SET_LOCAL_LONG = 65

let OP_SET_LOCAL_POP = 46

let OP_SET_LOCAL_POP_LONG = 47

let OP_SET_NAME = 104

let OP_SET_NAME_LONG = 105

let OP_SET_PROPERTY = 61

let OP_SET_PROPERTY_LONG = 62

let OP_SET_UPDATE_TOP = 157

let OP_SET_UPVALUE = 54

let OP_SET_UPVALUE_LONG = 55

let OP_SHIFTLEFT = 68

let OP_SHIFTRIGHT = 17

let OP_SLICE = 97

let OP_SLICE_LONG = 98

let OP_SUBTRACT = 40

let OP_SWAP = 9

let OP_SWAP_POP = 163

let OP_TEST_ARG = 79

let OP_TRUE = 28

let OP_TRY_ELSE = 63

let OP_TUPLE = 87

let OP_TUPLE_FROM_LIST = 159

let OP_TUPLE_LONG = 88

let OP_UNPACK = 122

let OP_UNPACK_EX = 160

let OP_UNPACK_EX_LONG = 161

let OP_UNPACK_LONG = 123

let OP_UNSET = 59

let OP_YIELD = 86

let OP_YIELD_FROM = 141