| 167 | } |
| 168 | |
| 169 | FrameInfoPtr get_frameinfo_from_pyframe(PyFrameObject* frame) { |
| 170 | auto* cache = FrameInfoCache::get_instance(); |
| 171 | auto&& [cur_info, key] = FrameInfo::make(frame, cache); |
| 172 | auto rst = cur_info; |
| 173 | SmallVector<std::pair<PyFrameObject*, FrameInfoPtr>, 100> frames; |
| 174 | py::object cur_frame = py::reinterpret_borrow<py::object>((PyObject*)frame); |
| 175 | while (key == -1) { |
| 176 | if (((PyFrameObject*)cur_frame.ptr())->f_gen == NULL) |
| 177 | frames.push_back({(PyFrameObject*)cur_frame.ptr(), cur_info}); |
| 178 | auto prev_frame = py::getattr(py::handle(cur_frame), "f_back"); |
| 179 | if (prev_frame.is_none()) |
| 180 | break; |
| 181 | auto&& [prev_info, prev_key] = |
| 182 | FrameInfo::make((PyFrameObject*)prev_frame.ptr(), cache); |
| 183 | cur_info->prev_frame = prev_info; |
| 184 | cur_info = prev_info, key = prev_key; |
| 185 | cur_frame = std::move(prev_frame); |
| 186 | } |
| 187 | if (cache != nullptr) |
| 188 | cache->update_cache(key, frames); |
| 189 | return rst; |
| 190 | } |
| 191 | |
| 192 | bool set_python_backtrace_enabled(bool enabled) { |
| 193 | std::swap(enable_py_bt, enabled); |
no test coverage detected