Break on exception.

This commit is contained in:
Deukhoofd 2021-10-03 12:00:17 +02:00
parent 5f0ad86489
commit 0094a5937f
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 31 additions and 15 deletions

View File

@ -55,15 +55,22 @@ size_t GetBreakpointHash(const std::string& section, size_t line) {
return ((hash<string>()(section) ^ (hash<size_t>()(line) << 1)) >> 1);
}
void AngelscriptDebugger::on_exception_callback(asIScriptContext*, AngelscriptDebugger*) {
return;
// const char* scriptSection = nullptr;
// int column = 0;
// int line = ctx->GetExceptionLineNumber(&column, &scriptSection);
// if (line == 0)
// return;
// auto b = Breakpoint{.Section = scriptSection, .Line = line};
// d->EnterBreakpoint(ctx, b);
void AngelscriptDebugger::on_exception_callback(asIScriptContext* ctx, AngelscriptDebugger* d) {
ctx->Suspend();
d->_pausedContexts.push_back(ctx);
const char* scriptSection = nullptr;
int column = 0;
int line = ctx->GetLineNumber(0, &column, &scriptSection);
if (line == 0)
return;
auto exception = ctx->GetExceptionString();
auto* o = new DebugAdapterProtocol::StoppedEvent(
new DebugAdapterProtocol::StoppedEventBody("exception", "Paused on exception", exception));
d->Send(o);
}
void AngelscriptDebugger::EnterBreakpoint(asIScriptContext* ctx, const std::string& section, size_t line) {
@ -71,7 +78,7 @@ void AngelscriptDebugger::EnterBreakpoint(asIScriptContext* ctx, const std::stri
_pausedContexts.push_back(ctx);
auto* o = new DebugAdapterProtocol::StoppedEvent(
new DebugAdapterProtocol::StoppedEventBody(GetBreakpointHash(section, line)));
new DebugAdapterProtocol::StoppedEventBody("breakpoint", GetBreakpointHash(section, line)));
Send(o);
}
@ -244,7 +251,12 @@ void AngelscriptDebugger::OnRequest(asio::ip::tcp::socket* client, DebugAdapterP
auto func = ctx->GetFunction(i);
const char* scriptSection = nullptr;
int column = 0;
int line = ctx->GetLineNumber(i, &column, &scriptSection);
int line;
if (i == 0 && ctx->GetExceptionString() != nullptr) {
line = ctx->GetExceptionLineNumber(&column, &scriptSection);
} else {
line = ctx->GetLineNumber(i, &column, &scriptSection);
}
stackTrace.emplace_back(i, func->GetName(),
DebugAdapterProtocol::Source(GetResolvedScriptPath(scriptSection)), line, column);
@ -285,6 +297,10 @@ void AngelscriptDebugger::OnRequest(asio::ip::tcp::socket* client, DebugAdapterP
auto c = e->CreateContext();
if (holds_alternative<std::unique_ptr<StackScope>>(variant)) {
if (ctx->GetExceptionString() != nullptr) {
variables.push_back(
DebugAdapterProtocol::Variable("exception", ctx->GetExceptionString(), "exception", {}));
}
auto frameId = std::get<std::unique_ptr<StackScope>>(variant)->StackLevel;
// auto scopeType = get<StackScope>(variant).Type;
auto varCount = ctx->GetVarCount(frameId);

View File

@ -188,10 +188,10 @@ namespace DebugAdapterProtocol {
std::optional<bool> allThreadsStopped = true;
std::optional<std::vector<size_t>> hitBreakpointIds;
explicit StoppedEventBody(size_t breakpoint) {
reason = "breakpoint";
hitBreakpointIds = {breakpoint};
}
explicit StoppedEventBody(std::string reason, size_t breakpoint)
: reason(std::move(reason)), hitBreakpointIds({breakpoint}) {}
explicit StoppedEventBody(std::string reason, std::string description, std::string text)
: reason(std::move(reason)), description(std::move(description)), text(std::move(text)) {}
nlohmann::json ToJson() const override {
auto o = EventBody::ToJson();