• Home
  • Raw
  • Download

Lines Matching +full:code +full:- +full:frame

1 /* Frame object implementation */
30 PyObject *locals = f->f_frame->f_locals; in frame_getlocals()
39 if (f->f_lineno != 0) { in PyFrame_GetLineNumber()
40 return f->f_lineno; in PyFrame_GetLineNumber()
43 return _PyInterpreterFrame_GetLine(f->f_frame); in PyFrame_GetLineNumber()
62 int lasti = _PyInterpreterFrame_LASTI(f->f_frame); in frame_getlasti()
64 return PyLong_FromLong(-1); in frame_getlasti()
72 PyObject *globals = f->f_frame->f_globals; in frame_getglobals()
83 PyObject *builtins = f->f_frame->f_builtins; in frame_getbuiltins()
111 // with EXTENDED_ARG. This only works correctly with *unquickened* code,
118 if (i >= 1 && _Py_OPCODE(word = codestr[i-1]) == EXTENDED_ARG) { in get_arg()
120 if (i >= 2 && _Py_OPCODE(word = codestr[i-2]) == EXTENDED_ARG) { in get_arg()
122 if (i >= 3 && _Py_OPCODE(word = codestr[i-3]) == EXTENDED_ARG) { in get_arg()
160 #define UNINITIALIZED -2
161 #define OVERFLOWED -1
164 #define WILL_OVERFLOW (1ULL<<((MAX_STACK_ENTRIES-1)*BITS_PER_BLOCK))
185 #define MASK ((1<<BITS_PER_BLOCK)-1)
197 return (stack>>(BITS_PER_BLOCK*(n-1))) & MASK; in peek()
206 int shift = BITS_PER_BLOCK*(n-1); in stack_swap()
217 int64_t max_item = (1<<BITS_PER_BLOCK) - 1; in pop_to_level()
218 int64_t level_max_stack = max_item << ((level-1) * BITS_PER_BLOCK); in pop_to_level()
226 /* These functions are useful for debugging the stack marking code */
249 printf("---");
283 _Py_CODEUNIT *code = (_Py_CODEUNIT *)PyBytes_AS_STRING(co_code); in mark_stacks() local
296 if (code_obj->co_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR)) in mark_stacks()
310 opcode = _Py_OPCODE(code[i]); in mark_stacks()
320 int j = get_arg(code, i); in mark_stacks()
331 j = i + 1 - j; in mark_stacks()
353 j = get_arg(code, i) + i + 1; in mark_stacks()
360 j = get_arg(code, i) + i + 1; in mark_stacks()
367 j = i + 1 - get_arg(code, i); in mark_stacks()
385 j = get_arg(code, i) + i + 1; in mark_stacks()
419 if (_Py_OPARG(code[i]) & 1) { in mark_stacks()
441 int n = get_arg(code, i); in mark_stacks()
448 int n = get_arg(code, i); in mark_stacks()
455 int delta = PyCompile_OpcodeStackEffect(opcode, get_arg(code, i)); in mark_stacks()
463 delta--; in mark_stacks()
470 unsigned char *start = (unsigned char *)PyBytes_AS_STRING(code_obj->co_exceptiontable); in mark_stacks()
471 unsigned char *end = start + PyBytes_GET_SIZE(code_obj->co_exceptiontable); in mark_stacks()
531 return "can't jump into an exception handler, or code may be unreachable"; in explain_incompatible_stack()
538 return "can't jump into a re-raising block as there's no location"; in explain_incompatible_stack()
550 marklines(PyCodeObject *code, int len) in marklines() argument
553 _PyCode_InitAddressRange(code, &bounds); in marklines()
555 int last_line = -1; in marklines()
562 linestarts[i] = -1; in marklines()
567 if (bounds.ar_line != last_line && bounds.ar_line != -1) { in marklines()
585 return -1; in first_line_not_before()
591 _PyFrame_GetState(PyFrameObject *frame) in _PyFrame_GetState() argument
593 assert(!_PyFrame_IsIncomplete(frame->f_frame)); in _PyFrame_GetState()
594 if (frame->f_frame->stacktop == 0) { in _PyFrame_GetState()
597 switch(frame->f_frame->owner) { in _PyFrame_GetState()
600 PyGenObject *gen = _PyFrame_GetGenerator(frame->f_frame); in _PyFrame_GetState()
601 return gen->gi_frame_state; in _PyFrame_GetState()
605 if (_PyInterpreterFrame_LASTI(frame->f_frame) < 0) { in _PyFrame_GetState()
608 switch (_PyOpcode_Deopt[_Py_OPCODE(*frame->f_frame->prev_instr)]) in _PyFrame_GetState()
613 /* Frame not fully initialized */ in _PyFrame_GetState()
626 /* Setter for f_lineno - you can set f_lineno from within a trace function in
627 * order to jump to a given line of code, subject to some restrictions. Most
629 * state of the stack (obvious because you could remove the line and the code
645 return -1; in frame_setlineno()
651 return -1; in frame_setlineno()
656 * This code preserves the historical restrictions on in frame_setlineno()
657 * setting the line number of a frame. in frame_setlineno()
663 switch(PyThreadState_GET()->tracing_what) { in frame_setlineno()
667 return -1; in frame_setlineno()
670 "can't jump from the 'call' trace event of a new frame"); in frame_setlineno()
671 return -1; in frame_setlineno()
682 return -1; in frame_setlineno()
684 if (!f->f_trace) { in frame_setlineno()
687 return -1; in frame_setlineno()
692 /* Fail if the line falls outside the code block and in frame_setlineno()
693 select first line with actual code. */ in frame_setlineno()
704 return -1; in frame_setlineno()
708 if (new_lineno < f->f_frame->f_code->co_firstlineno) { in frame_setlineno()
710 "line %d comes before the current code block", in frame_setlineno()
712 return -1; in frame_setlineno()
717 int len = (int)Py_SIZE(f->f_frame->f_code); in frame_setlineno()
718 int *lines = marklines(f->f_frame->f_code, len); in frame_setlineno()
720 return -1; in frame_setlineno()
726 "line %d comes after the current code block", in frame_setlineno()
729 return -1; in frame_setlineno()
732 int64_t *stacks = mark_stacks(f->f_frame->f_code, len); in frame_setlineno()
735 return -1; in frame_setlineno()
739 int best_addr = -1; in frame_setlineno()
740 int64_t start_stack = stacks[_PyInterpreterFrame_LASTI(f->f_frame)]; in frame_setlineno()
741 int err = -1; in frame_setlineno()
758 msg = "can't jump from unreachable code"; in frame_setlineno()
771 return -1; in frame_setlineno()
781 _PyErr_StackItem *exc_info = tstate->exc_info; in frame_setlineno()
782 PyObject *value = exc_info->exc_value; in frame_setlineno()
783 PyObject *exc = _PyFrame_StackPop(f->f_frame); in frame_setlineno()
785 exc_info->exc_value = exc; in frame_setlineno()
789 PyObject *v = _PyFrame_StackPop(f->f_frame); in frame_setlineno()
795 f->f_lineno = 0; in frame_setlineno()
796 f->f_frame->prev_instr = _PyCode_CODE(f->f_frame->f_code) + best_addr; in frame_setlineno()
803 PyObject* trace = f->f_trace; in frame_gettrace()
820 Py_XSETREF(f->f_trace, v); in frame_settrace()
842 allocated in a special way -- see floatobject.c). When a stack
843 frame is on the free list, only the following members have a meaning:
854 assert(f->f_frame->owner != FRAME_OWNED_BY_GENERATOR || in frame_dealloc()
855 _PyFrame_GetGenerator(f->f_frame)->gi_frame_state == FRAME_CLEARED); in frame_dealloc()
865 if (f->f_frame->owner == FRAME_OWNED_BY_FRAME_OBJECT) { in frame_dealloc()
866 assert(f->f_frame == (_PyInterpreterFrame *)f->_f_frame_data); in frame_dealloc()
867 _PyInterpreterFrame *frame = (_PyInterpreterFrame *)f->_f_frame_data; in frame_dealloc() local
868 /* Don't clear code object until the end */ in frame_dealloc()
869 co = frame->f_code; in frame_dealloc()
870 frame->f_code = NULL; in frame_dealloc()
871 Py_CLEAR(frame->f_func); in frame_dealloc()
872 Py_CLEAR(frame->f_locals); in frame_dealloc()
873 PyObject **locals = _PyFrame_GetLocalsArray(frame); in frame_dealloc()
874 for (int i = 0; i < frame->stacktop; i++) { in frame_dealloc()
878 Py_CLEAR(f->f_back); in frame_dealloc()
879 Py_CLEAR(f->f_trace); in frame_dealloc()
888 Py_VISIT(f->f_back); in frame_traverse()
889 Py_VISIT(f->f_trace); in frame_traverse()
890 if (f->f_frame->owner != FRAME_OWNED_BY_FRAME_OBJECT) { in frame_traverse()
893 assert(f->f_frame->frame_obj == NULL); in frame_traverse()
894 return _PyFrame_Traverse(f->f_frame, visit, arg); in frame_traverse()
900 Py_CLEAR(f->f_trace); in frame_tp_clear()
903 PyObject **locals = _PyFrame_GetLocalsArray(f->f_frame); in frame_tp_clear()
904 assert(f->f_frame->stacktop >= 0); in frame_tp_clear()
905 for (int i = 0; i < f->f_frame->stacktop; i++) { in frame_tp_clear()
908 f->f_frame->stacktop = 0; in frame_tp_clear()
915 if (f->f_frame->owner == FRAME_OWNED_BY_GENERATOR) { in frame_clear()
916 PyGenObject *gen = _PyFrame_GetGenerator(f->f_frame); in frame_clear()
917 if (gen->gi_frame_state == FRAME_EXECUTING) { in frame_clear()
922 else if (f->f_frame->owner == FRAME_OWNED_BY_THREAD) { in frame_clear()
926 assert(f->f_frame->owner == FRAME_OWNED_BY_FRAME_OBJECT); in frame_clear()
932 "cannot clear an executing frame"); in frame_clear()
937 "F.clear(): clear most references held by the frame");
944 PyCodeObject *code = f->f_frame->f_code; in frame_sizeof() local
945 res += (code->co_nlocalsplus+code->co_stacksize) * sizeof(PyObject *); in frame_sizeof()
950 "F.__sizeof__() -> size of F in memory, in bytes");
956 PyCodeObject *code = f->f_frame->f_code; in frame_repr() local
958 "<frame at %p, file %R, line %d, code %S>", in frame_repr()
959 f, code->co_filename, lineno, code->co_name); in frame_repr()
972 "frame",
1007 init_frame(_PyInterpreterFrame *frame, PyFunctionObject *func, PyObject *locals) in init_frame() argument
1011 PyCodeObject *code = (PyCodeObject *)func->func_code; in init_frame() local
1012 _PyFrame_InitializeSpecials(frame, func, locals, code->co_nlocalsplus); in init_frame()
1013 frame->previous = NULL; in init_frame()
1014 for (Py_ssize_t i = 0; i < code->co_nlocalsplus; i++) { in init_frame()
1015 frame->localsplus[i] = NULL; in init_frame()
1020 _PyFrame_New_NoTrack(PyCodeObject *code) in _PyFrame_New_NoTrack() argument
1023 int slots = code->co_nlocalsplus + code->co_stacksize; in _PyFrame_New_NoTrack()
1028 f->f_back = NULL; in _PyFrame_New_NoTrack()
1029 f->f_trace = NULL; in _PyFrame_New_NoTrack()
1030 f->f_trace_lines = 1; in _PyFrame_New_NoTrack()
1031 f->f_trace_opcodes = 0; in _PyFrame_New_NoTrack()
1032 f->f_fast_as_locals = 0; in _PyFrame_New_NoTrack()
1033 f->f_lineno = 0; in _PyFrame_New_NoTrack()
1039 PyFrame_New(PyThreadState *tstate, PyCodeObject *code, in PyFrame_New() argument
1049 .fc_name = code->co_name, in PyFrame_New()
1050 .fc_qualname = code->co_name, in PyFrame_New()
1051 .fc_code = (PyObject *)code, in PyFrame_New()
1060 PyFrameObject *f = _PyFrame_New_NoTrack(code); in PyFrame_New()
1065 init_frame((_PyInterpreterFrame *)f->_f_frame_data, func, locals); in PyFrame_New()
1066 f->f_frame = (_PyInterpreterFrame *)f->_f_frame_data; in PyFrame_New()
1067 f->f_frame->owner = FRAME_OWNED_BY_FRAME_OBJECT; in PyFrame_New()
1068 // This frame needs to be "complete", so pretend that the first RESUME ran: in PyFrame_New()
1069 f->f_frame->prev_instr = _PyCode_CODE(code) + code->_co_firsttraceable; in PyFrame_New()
1070 assert(!_PyFrame_IsIncomplete(f->f_frame)); in PyFrame_New()
1077 _PyFrame_OpAlreadyRan(_PyInterpreterFrame *frame, int opcode, int oparg) in _PyFrame_OpAlreadyRan() argument
1079 // This only works when opcode is a non-quickened form: in _PyFrame_OpAlreadyRan()
1082 for (_Py_CODEUNIT *instruction = _PyCode_CODE(frame->f_code); in _PyFrame_OpAlreadyRan()
1083 instruction < frame->prev_instr; instruction++) in _PyFrame_OpAlreadyRan()
1102 _PyFrame_FastToLocalsWithError(_PyInterpreterFrame *frame) { in _PyFrame_FastToLocalsWithError() argument
1103 /* Merge fast locals into f->f_locals */ in _PyFrame_FastToLocalsWithError()
1107 locals = frame->f_locals; in _PyFrame_FastToLocalsWithError()
1109 locals = frame->f_locals = PyDict_New(); in _PyFrame_FastToLocalsWithError()
1111 return -1; in _PyFrame_FastToLocalsWithError()
1113 co = frame->f_code; in _PyFrame_FastToLocalsWithError()
1114 fast = _PyFrame_GetLocalsArray(frame); in _PyFrame_FastToLocalsWithError()
1117 int lasti = _PyInterpreterFrame_LASTI(frame); in _PyFrame_FastToLocalsWithError()
1119 /* Free vars have not been initialized -- Do that */ in _PyFrame_FastToLocalsWithError()
1120 PyCodeObject *co = frame->f_code; in _PyFrame_FastToLocalsWithError()
1121 PyObject *closure = frame->f_func->func_closure; in _PyFrame_FastToLocalsWithError()
1122 int offset = co->co_nlocals + co->co_nplaincellvars; in _PyFrame_FastToLocalsWithError()
1123 for (int i = 0; i < co->co_nfreevars; ++i) { in _PyFrame_FastToLocalsWithError()
1126 frame->localsplus[offset + i] = o; in _PyFrame_FastToLocalsWithError()
1129 frame->prev_instr = _PyCode_CODE(frame->f_code); in _PyFrame_FastToLocalsWithError()
1131 for (int i = 0; i < co->co_nlocalsplus; i++) { in _PyFrame_FastToLocalsWithError()
1132 _PyLocals_Kind kind = _PyLocals_GetKind(co->co_localspluskinds, i); in _PyFrame_FastToLocalsWithError()
1137 uses import * or is a top-level namespace. in _PyFrame_FastToLocalsWithError()
1142 if (kind & CO_FAST_FREE && !(co->co_flags & CO_OPTIMIZED)) { in _PyFrame_FastToLocalsWithError()
1146 PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, i); in _PyFrame_FastToLocalsWithError()
1148 if (frame->stacktop) { in _PyFrame_FastToLocalsWithError()
1161 _PyFrame_OpAlreadyRan(frame, MAKE_CELL, i)) { in _PyFrame_FastToLocalsWithError()
1166 // with the initial value set when the frame was created... in _PyFrame_FastToLocalsWithError()
1181 return -1; in _PyFrame_FastToLocalsWithError()
1187 return -1; in _PyFrame_FastToLocalsWithError()
1197 assert(!_PyFrame_IsIncomplete(f->f_frame)); in PyFrame_FastToLocalsWithError()
1200 return -1; in PyFrame_FastToLocalsWithError()
1202 int err = _PyFrame_FastToLocalsWithError(f->f_frame); in PyFrame_FastToLocalsWithError()
1204 f->f_fast_as_locals = 1; in PyFrame_FastToLocalsWithError()
1213 assert(!_PyFrame_IsIncomplete(f->f_frame)); in PyFrame_FastToLocals()
1222 _PyFrame_LocalsToFast(_PyInterpreterFrame *frame, int clear) in _PyFrame_LocalsToFast() argument
1229 locals = frame->f_locals; in _PyFrame_LocalsToFast()
1233 fast = _PyFrame_GetLocalsArray(frame); in _PyFrame_LocalsToFast()
1234 co = frame->f_code; in _PyFrame_LocalsToFast()
1237 for (int i = 0; i < co->co_nlocalsplus; i++) { in _PyFrame_LocalsToFast()
1238 _PyLocals_Kind kind = _PyLocals_GetKind(co->co_localspluskinds, i); in _PyFrame_LocalsToFast()
1241 if (kind & CO_FAST_FREE && !(co->co_flags & CO_OPTIMIZED)) { in _PyFrame_LocalsToFast()
1244 PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, i); in _PyFrame_LocalsToFast()
1256 // The cell was set when the frame was created from in _PyFrame_LocalsToFast()
1264 _PyFrame_OpAlreadyRan(frame, MAKE_CELL, i)) { in _PyFrame_LocalsToFast()
1291 assert(!_PyFrame_IsIncomplete(f->f_frame)); in PyFrame_LocalsToFast()
1292 if (f && f->f_fast_as_locals && _PyFrame_GetState(f) != FRAME_CLEARED) { in PyFrame_LocalsToFast()
1293 _PyFrame_LocalsToFast(f->f_frame, clear); in PyFrame_LocalsToFast()
1294 f->f_fast_as_locals = 0; in PyFrame_LocalsToFast()
1299 int _PyFrame_IsEntryFrame(PyFrameObject *frame) in _PyFrame_IsEntryFrame() argument
1301 assert(frame != NULL); in _PyFrame_IsEntryFrame()
1302 assert(!_PyFrame_IsIncomplete(frame->f_frame)); in _PyFrame_IsEntryFrame()
1303 return frame->f_frame->is_entry; in _PyFrame_IsEntryFrame()
1308 PyFrame_GetCode(PyFrameObject *frame) in PyFrame_GetCode() argument
1310 assert(frame != NULL); in PyFrame_GetCode()
1311 assert(!_PyFrame_IsIncomplete(frame->f_frame)); in PyFrame_GetCode()
1312 PyCodeObject *code = frame->f_frame->f_code; in PyFrame_GetCode() local
1313 assert(code != NULL); in PyFrame_GetCode()
1314 Py_INCREF(code); in PyFrame_GetCode()
1315 return code; in PyFrame_GetCode()
1320 PyFrame_GetBack(PyFrameObject *frame) in PyFrame_GetBack() argument
1322 assert(frame != NULL); in PyFrame_GetBack()
1323 assert(!_PyFrame_IsIncomplete(frame->f_frame)); in PyFrame_GetBack()
1324 PyFrameObject *back = frame->f_back; in PyFrame_GetBack()
1326 _PyInterpreterFrame *prev = frame->f_frame->previous; in PyFrame_GetBack()
1328 prev = prev->previous; in PyFrame_GetBack()
1339 PyFrame_GetLocals(PyFrameObject *frame) in PyFrame_GetLocals() argument
1341 assert(!_PyFrame_IsIncomplete(frame->f_frame)); in PyFrame_GetLocals()
1342 return frame_getlocals(frame, NULL); in PyFrame_GetLocals()
1346 PyFrame_GetGlobals(PyFrameObject *frame) in PyFrame_GetGlobals() argument
1348 assert(!_PyFrame_IsIncomplete(frame->f_frame)); in PyFrame_GetGlobals()
1349 return frame_getglobals(frame, NULL); in PyFrame_GetGlobals()
1353 PyFrame_GetBuiltins(PyFrameObject *frame) in PyFrame_GetBuiltins() argument
1355 assert(!_PyFrame_IsIncomplete(frame->f_frame)); in PyFrame_GetBuiltins()
1356 return frame_getbuiltins(frame, NULL); in PyFrame_GetBuiltins()
1360 PyFrame_GetLasti(PyFrameObject *frame) in PyFrame_GetLasti() argument
1362 assert(!_PyFrame_IsIncomplete(frame->f_frame)); in PyFrame_GetLasti()
1363 int lasti = _PyInterpreterFrame_LASTI(frame->f_frame); in PyFrame_GetLasti()
1365 return -1; in PyFrame_GetLasti()
1371 PyFrame_GetGenerator(PyFrameObject *frame) in PyFrame_GetGenerator() argument
1373 assert(!_PyFrame_IsIncomplete(frame->f_frame)); in PyFrame_GetGenerator()
1374 if (frame->f_frame->owner != FRAME_OWNED_BY_GENERATOR) { in PyFrame_GetGenerator()
1377 PyGenObject *gen = _PyFrame_GetGenerator(frame->f_frame); in PyFrame_GetGenerator()