AngelScript

Debugger

Path: /sdk/add_on/debugger/

The `CDebugger` implements common debugging functionality for scripts, e.g. setting breakpoints, stepping through the code, examining values of variables, etc.

To use the debugger the line callback should be set in the context. This will allow the debugger to take over whenever a breakpoint is reached, so the script can be debugged.

By default the debugger uses the standard in and standard out streams to interact with the user, but this can be easily overloaded by deriving from the `CDebugger` class and implementing the methods `TakeCommands` and `Output`. With this it is possible to implement a graphical interface, or even remote debugging for an application.

The application developer may also be interested in overriding the default `ToString` method to implement ways to visualize application registered types in an easier way.

See Also
  The sample Commandline runner for a complete example of how to use the debugger

# Public C++ interface

class CDebugger
{
public:
CDebugger();
virtual ~CDebugger();
// User interaction
virtual void TakeCommands(asIScriptContext *ctx);
virtual void Output(const std::string &str);
// Line callback invoked by context
virtual void LineCallback(asIScriptContext *ctx);
// Commands
virtual void PrintHelp();
virtual void AddFileBreakPoint(const std::string &file, int lineNbr);
virtual void AddFuncBreakPoint(const std::string &func);
virtual void ListBreakPoints();
virtual void ListLocalVariables(asIScriptContext *ctx);
virtual void ListGlobalVariables(asIScriptContext *ctx);
virtual void ListMemberProperties(asIScriptContext *ctx);
virtual void ListStatistics(asIScriptContext *ctx);
virtual void PrintCallstack(asIScriptContext *ctx);
virtual void PrintValue(const std::string &expr, asIScriptContext *ctx);
// Helpers
virtual bool InterpretCommand(const std::string &cmd, asIScriptContext *ctx);
virtual bool CheckBreakPoint(asIScriptContext *ctx);
virtual std::string ToString(void *value, asUINT typeId, bool expandMembers, asIScriptEngine *engine);
};

# Example usage

CDebugger dbg;
int ExecuteWithDebug(asIScriptContext *ctx)
{
// Tell the context to invoke the debugger's line callback
ctx->SetLineCallback(asMETHOD(CDebugger, LineCallback), dbg, asCALL_THISCALL);
// Allow the user to initialize the debugging before moving on
dbg.TakeCommands(ctx);
// Execute the script normally. If a breakpoint is reached the
// debugger will take over the control loop.
return ctx->Execute();
}