Does ChaiScript support debugger-like behavior? For instance, can I set breakpoints at which should the execution pause, and allow me to inspect the stack before resuming? If so, how?
-
From a very brief glance at this ChaiScript thing, based on what it is and how it works, I seriously doubt it. Beyond that, why don't you try _reading_ the documentation and find out for yourself?? – Lightness Races in Orbit Jan 18 '15 at 23:24
-
1I did read the docs, but the guide is rather short, and the class docs won't help much if I don't really know what I'm looking for, so I thought I'd ask someone more experienced. – Tomáš M. Jan 19 '15 at 00:23
-
Mmmm okay borderline but okay. Good luck – Lightness Races in Orbit Jan 19 '15 at 00:27
1 Answers
It is not possible to break into ChaiScript currently.
You have two options. You could cause an error to occur (say eval('**');
) which would cause an eval error exception and could generate a stack error to show you were you are.
See here: https://github.com/ChaiScript/ChaiScript/blob/develop/src/main.cpp#L344 for how you might display the stack and call information for what went wrong.
Another option would be to cause the debugger to break inside your code. It might go something like: (see: Is there a portable equivalent to DebugBreak()/__debugbreak?)
Function definition
void debugbreak()
{
#ifdef _MSC_VER
__debugbreak()
#else
raise(SIGTRAP);
#endif
}
Adding it to ChaiScript
chai.add(fun(&debugbreak), "debugbreak");
Triggering it
//inside chaicript code
for (var i = 0; i < 1000; ++i)
{
if (i == 980) {
// should cause your C++ debugger to break
debugbreak();
}
}
The problem at this point would be actually understanding the C++ stack that you see. It will take some getting used to, but the AST node names should be fairly descriptive.
-
I think that adding easily accessible debugging features to ChaiScript would be immensely beneficial to this awesome scripting system. In fact, it can be argued that any programming tool without debugging ability, be it script or native code, it almost useless for large or even medium purposes. And ChaiScript deserves to not be un-debuggable :) – Marius Myburg May 08 '18 at 13:44