17db96d56Sopenharmony_ci#ifndef Py_INTERNAL_TRACEBACK_H
27db96d56Sopenharmony_ci#define Py_INTERNAL_TRACEBACK_H
37db96d56Sopenharmony_ci#ifdef __cplusplus
47db96d56Sopenharmony_ciextern "C" {
57db96d56Sopenharmony_ci#endif
67db96d56Sopenharmony_ci
77db96d56Sopenharmony_ci#ifndef Py_BUILD_CORE
87db96d56Sopenharmony_ci#  error "this header requires Py_BUILD_CORE define"
97db96d56Sopenharmony_ci#endif
107db96d56Sopenharmony_ci
117db96d56Sopenharmony_ci/* Write the Python traceback into the file 'fd'. For example:
127db96d56Sopenharmony_ci
137db96d56Sopenharmony_ci       Traceback (most recent call first):
147db96d56Sopenharmony_ci         File "xxx", line xxx in <xxx>
157db96d56Sopenharmony_ci         File "xxx", line xxx in <xxx>
167db96d56Sopenharmony_ci         ...
177db96d56Sopenharmony_ci         File "xxx", line xxx in <xxx>
187db96d56Sopenharmony_ci
197db96d56Sopenharmony_ci   This function is written for debug purpose only, to dump the traceback in
207db96d56Sopenharmony_ci   the worst case: after a segmentation fault, at fatal error, etc. That's why,
217db96d56Sopenharmony_ci   it is very limited. Strings are truncated to 100 characters and encoded to
227db96d56Sopenharmony_ci   ASCII with backslashreplace. It doesn't write the source code, only the
237db96d56Sopenharmony_ci   function name, filename and line number of each frame. Write only the first
247db96d56Sopenharmony_ci   100 frames: if the traceback is truncated, write the line " ...".
257db96d56Sopenharmony_ci
267db96d56Sopenharmony_ci   This function is signal safe. */
277db96d56Sopenharmony_ci
287db96d56Sopenharmony_ciPyAPI_FUNC(void) _Py_DumpTraceback(
297db96d56Sopenharmony_ci    int fd,
307db96d56Sopenharmony_ci    PyThreadState *tstate);
317db96d56Sopenharmony_ci
327db96d56Sopenharmony_ci/* Write the traceback of all threads into the file 'fd'. current_thread can be
337db96d56Sopenharmony_ci   NULL.
347db96d56Sopenharmony_ci
357db96d56Sopenharmony_ci   Return NULL on success, or an error message on error.
367db96d56Sopenharmony_ci
377db96d56Sopenharmony_ci   This function is written for debug purpose only. It calls
387db96d56Sopenharmony_ci   _Py_DumpTraceback() for each thread, and so has the same limitations. It
397db96d56Sopenharmony_ci   only write the traceback of the first 100 threads: write "..." if there are
407db96d56Sopenharmony_ci   more threads.
417db96d56Sopenharmony_ci
427db96d56Sopenharmony_ci   If current_tstate is NULL, the function tries to get the Python thread state
437db96d56Sopenharmony_ci   of the current thread. It is not an error if the function is unable to get
447db96d56Sopenharmony_ci   the current Python thread state.
457db96d56Sopenharmony_ci
467db96d56Sopenharmony_ci   If interp is NULL, the function tries to get the interpreter state from
477db96d56Sopenharmony_ci   the current Python thread state, or from
487db96d56Sopenharmony_ci   _PyGILState_GetInterpreterStateUnsafe() in last resort.
497db96d56Sopenharmony_ci
507db96d56Sopenharmony_ci   It is better to pass NULL to interp and current_tstate, the function tries
517db96d56Sopenharmony_ci   different options to retrieve this information.
527db96d56Sopenharmony_ci
537db96d56Sopenharmony_ci   This function is signal safe. */
547db96d56Sopenharmony_ci
557db96d56Sopenharmony_ciPyAPI_FUNC(const char*) _Py_DumpTracebackThreads(
567db96d56Sopenharmony_ci    int fd,
577db96d56Sopenharmony_ci    PyInterpreterState *interp,
587db96d56Sopenharmony_ci    PyThreadState *current_tstate);
597db96d56Sopenharmony_ci
607db96d56Sopenharmony_ci/* Write a Unicode object into the file descriptor fd. Encode the string to
617db96d56Sopenharmony_ci   ASCII using the backslashreplace error handler.
627db96d56Sopenharmony_ci
637db96d56Sopenharmony_ci   Do nothing if text is not a Unicode object. The function accepts Unicode
647db96d56Sopenharmony_ci   string which is not ready (PyUnicode_WCHAR_KIND).
657db96d56Sopenharmony_ci
667db96d56Sopenharmony_ci   This function is signal safe. */
677db96d56Sopenharmony_ciPyAPI_FUNC(void) _Py_DumpASCII(int fd, PyObject *text);
687db96d56Sopenharmony_ci
697db96d56Sopenharmony_ci/* Format an integer as decimal into the file descriptor fd.
707db96d56Sopenharmony_ci
717db96d56Sopenharmony_ci   This function is signal safe. */
727db96d56Sopenharmony_ciPyAPI_FUNC(void) _Py_DumpDecimal(
737db96d56Sopenharmony_ci    int fd,
747db96d56Sopenharmony_ci    size_t value);
757db96d56Sopenharmony_ci
767db96d56Sopenharmony_ci/* Format an integer as hexadecimal with width digits into fd file descriptor.
777db96d56Sopenharmony_ci   The function is signal safe. */
787db96d56Sopenharmony_ciPyAPI_FUNC(void) _Py_DumpHexadecimal(
797db96d56Sopenharmony_ci    int fd,
807db96d56Sopenharmony_ci    uintptr_t value,
817db96d56Sopenharmony_ci    Py_ssize_t width);
827db96d56Sopenharmony_ci
837db96d56Sopenharmony_ciPyAPI_FUNC(PyObject*) _PyTraceBack_FromFrame(
847db96d56Sopenharmony_ci    PyObject *tb_next,
857db96d56Sopenharmony_ci    PyFrameObject *frame);
867db96d56Sopenharmony_ci
877db96d56Sopenharmony_ci#define EXCEPTION_TB_HEADER "Traceback (most recent call last):\n"
887db96d56Sopenharmony_ci#define EXCEPTION_GROUP_TB_HEADER "Exception Group Traceback (most recent call last):\n"
897db96d56Sopenharmony_ci
907db96d56Sopenharmony_ci/* Write the traceback tb to file f. Prefix each line with
917db96d56Sopenharmony_ci   indent spaces followed by the margin (if it is not NULL). */
927db96d56Sopenharmony_ciPyAPI_FUNC(int) _PyTraceBack_Print_Indented(
937db96d56Sopenharmony_ci    PyObject *tb, int indent, const char* margin,
947db96d56Sopenharmony_ci    const char *header_margin, const char *header, PyObject *f);
957db96d56Sopenharmony_ciPyAPI_FUNC(int) _Py_WriteIndentedMargin(int, const char*, PyObject *);
967db96d56Sopenharmony_ciPyAPI_FUNC(int) _Py_WriteIndent(int, PyObject *);
977db96d56Sopenharmony_ci
987db96d56Sopenharmony_ci#ifdef __cplusplus
997db96d56Sopenharmony_ci}
1007db96d56Sopenharmony_ci#endif
1017db96d56Sopenharmony_ci#endif /* !Py_INTERNAL_TRACEBACK_H */
102