This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Allow traceback analysis from C/C++...
Type: enhancement Stage:
Components: Interpreter Core Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, marcinkasperski, nbastin
Priority: low Keywords:

Created on 2001-12-27 16:13 by marcinkasperski, last changed 2022-04-10 16:04 by admin. This issue is now closed.

Messages (3)
msg8495 - (view) Author: Marcin Kasperski (marcinkasperski) Date: 2001-12-27 16:13
I write C++ applications which embed python 
interpreter as script engine. And I would like to 
perform traceback analysis during error handling 
(imagine for instance that I would like to include 
python traceback info inside some exception which 
will be handled outside library I write, maybe by 
sending error description to log server via network)

What I found? PyErr_Fetch gets traceback object and 
gives it to me. There are methods which print 
traceback to standard error. But if I want to do 
something different ... there is no way 
to analyze traceback  without utilizing some dirty 
tricks. Two main problems:
- struct tracebackobject is not present in python 
headers, it is only in traceback.c
- it is of course not documented at all.

I finally managed to do what I wanted by copying 
tracebackobject definition from traceback.c and by 
copying tb_printinternal and suiting it to my needs. 
But what will happen if you change this structure 
some time in the future?

What exactly do I request? Choose one of the two:

1) Either publish struct tracebackobject inside some 
Python headers (traceback.h?), mention in PyErr_Fetch 
documentation that the last parameter is of this type 
and describe its structure somewhere in python-embed

2) Or keep it secret but add some API which would 
allow to navigate traceback without presenting its 
internals, say the function like 
PyTrace_AnalyzeTraceBack which - given traceback 
object - would return file, line, name and next 
traceback (or the flag telling that there is no more).

msg8496 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2001-12-27 16:35
Logged In: YES 
user_id=6380

I agree that this API should be published in a header file.

The Python API to the traceback object is documented so you
can always use PyObject_GetAttrString(tb, "tb_frame") and so
on.
msg8497 - (view) Author: Nick Bastin (nbastin) * (Python committer) Date: 2004-03-21 18:48
Logged In: YES 
user_id=430343

Fixed in:
Include/traceback.h 2.21
Python/traceback.c 2.42
Misc/NEWS 1.955
History
Date User Action Args
2022-04-10 16:04:49adminsetgithub: 35831
2001-12-27 16:13:51marcinkasperskicreate