Skip to content

gh-148925: Add PyUnstable_CollectCallStack and PyUnstable_PrintCallStack#148930

Open
danielsn wants to merge 1 commit intopython:mainfrom
danielsn:dsn/c-stracktrace
Open

gh-148925: Add PyUnstable_CollectCallStack and PyUnstable_PrintCallStack#148930
danielsn wants to merge 1 commit intopython:mainfrom
danielsn:dsn/c-stracktrace

Conversation

@danielsn
Copy link
Copy Markdown

@danielsn danielsn commented Apr 23, 2026

#145559 proposes a signal-safe mechanism to print backtraces. This is useful for human debugging, but not ideal for tools because it requires parsing human-readable text. For example, a crash-tracker may wish to export and analyze structured backtraces. Similarly, a profiler can benefit from the ability to generate structure stack-traces in pure C, without needing to reason about the safety of reentering the python interpreter.


📚 Documentation preview 📚: https://cpython-previews--148930.org.readthedocs.build/

@python-cla-bot
Copy link
Copy Markdown

python-cla-bot Bot commented Apr 23, 2026

All commit authors signed the Contributor License Agreement.

CLA signed


/* Buffer size for the filename and name fields in PyUnstable_FrameInfo:
up to 500 content bytes plus '\0' (1). */
#define Py_UNSTABLE_FRAMEINFO_STRSIZE 501
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used 500 because that was what the print to fd version used, https://github.com/danielsn/cpython/blob/main/Python/traceback.c#L56C9-L56C26 but this seems larger than we'd need in practice.

the respective string was longer than Py_UNSTABLE_FRAMEINFO_STRSIZE-1
bytes and was truncated. */
typedef struct {
int lineno;
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code object has other fields (e.g. column), would these be worth collecting as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant