xeus-cling icon indicating copy to clipboard operation
xeus-cling copied to clipboard

Feature request: traceback on segfaults or exceptions (dreaming aloud)

Open nthiery opened this issue 6 years ago • 5 comments

Currently, a segmentation fault in the code results in the kernel dying. While this is a fair enough behavior (after all, this is a segfault of the whole kernel process, and there is not much to do to recover from it), some clue for the reader would be helpful. A minimum would be something like "Segmentation fault" or "the code run by the kernel triggered a segmentation fault". In case of an exception, a printout of the exception itself. Really nice would be a stack trace. Full dream would be a (optional?, post-mortem) debugger prompt.

Of course this is much lower-level, and thus presumably harder than in IPython. In particular there is the question of whether to systematicaclly interpret with debugging symbols on. And once again, this might really be a cling issue rather than xeus-cling.

Context: our students where learning 2D vectors this week, and got a lot of such segfaults. They had no clue on what to do when the kernel crashed. A stacktrace would be a super useful information for them to analyse their code and fix the bug.

nthiery avatar Oct 29 '17 12:10 nthiery

It is not as crazy as it sounds. I have been looking into how to do that, which should be doable in the case of exceptions, less so for segfaults.

SylvainCorlay avatar Oct 29 '17 14:10 SylvainCorlay

On linux, the segmentation fault triggers a sigsegv signal which should result in a core dump containing all the info you need. Some reasons may prevent this core dump to be generated (option disabled in the kernel, redirection to a directory that is not writable); if that cannot be fixed, a solution is to set our own signal handler to generate some information, but there are limitations on what can be done inside such a signal handler.

JohanMabille avatar Oct 29 '17 21:10 JohanMabille

The core dump is actually printed out by the kernel, but I am not sure how we could generate a traceback from it.

SylvainCorlay avatar Oct 29 '17 22:10 SylvainCorlay

ROOT's interpreter (meaning the actual C++ prompt) does it. I think they trap SIGSEV and execute backtrace and print the result before exiting, as explained here

eguiraud avatar Nov 30 '17 17:11 eguiraud

Could https://github.com/bombela/backward-cpp be used? How can I view crash message for now?

xgdgsc avatar Dec 24 '20 08:12 xgdgsc