py-spy icon indicating copy to clipboard operation
py-spy copied to clipboard

[WIP] Python 3.13 Support

Open benfred opened this issue 1 year ago • 2 comments

Initial support for python 3.13 . This works as far as getting basic stack traces from python 3.13 programs, but there are still some remaining tasks:

  • [x] Line numbers are broken
  • [ ] Leverage pyruntime.debug_offsets for figuring out interpreter head location
  • [ ] Fix cases where PyInterpreterFrame.f_executable doesn't point to a PyCodeObject
  • [ ] Thread names

benfred avatar Oct 19 '24 00:10 benfred

Exciting! Happy to review this when it's ready, if you want.

zanieb avatar Oct 19 '24 04:10 zanieb

@zanieb - that would be great, I'd appreciate it! I'll ping you when its ready

benfred avatar Oct 19 '24 04:10 benfred

This doesn't fully handle freethreaded/nogil python interpreters - but I'm leaning towards handling that in a separate PR and getting this merged in first - tracked in https://github.com/benfred/py-spy/issues/711 .

One other issue is that the f_executable pointer on the FrameObject can be any arbitrary python object in python3.13 - and not just a PyCodeObject like in older versions of python. This PR is currently just skipping frames where we can't read the filename and function name (indicating a f_executable that isn't a PyCodeObject) -but maybe should instead be checking if the f_executable->ob_type == &PyCode_Type like PyCode_Check does in cpython (?). (The downside to checking the type is that we'd have to figure out the address of PyCode_Type in the target process and pass along to the get_stack_traces function - which might be a bit difficult right now)

@zanieb fyi

benfred avatar Oct 23 '24 06:10 benfred

Cool I'll review this week.

zanieb avatar Oct 28 '24 19:10 zanieb