Break on exception.
This commit is contained in:
parent
5f0ad86489
commit
0094a5937f
|
@ -55,15 +55,22 @@ size_t GetBreakpointHash(const std::string& section, size_t line) {
|
||||||
return ((hash<string>()(section) ^ (hash<size_t>()(line) << 1)) >> 1);
|
return ((hash<string>()(section) ^ (hash<size_t>()(line) << 1)) >> 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AngelscriptDebugger::on_exception_callback(asIScriptContext*, AngelscriptDebugger*) {
|
void AngelscriptDebugger::on_exception_callback(asIScriptContext* ctx, AngelscriptDebugger* d) {
|
||||||
return;
|
ctx->Suspend();
|
||||||
// const char* scriptSection = nullptr;
|
d->_pausedContexts.push_back(ctx);
|
||||||
// int column = 0;
|
|
||||||
// int line = ctx->GetExceptionLineNumber(&column, &scriptSection);
|
const char* scriptSection = nullptr;
|
||||||
// if (line == 0)
|
int column = 0;
|
||||||
// return;
|
int line = ctx->GetLineNumber(0, &column, &scriptSection);
|
||||||
// auto b = Breakpoint{.Section = scriptSection, .Line = line};
|
if (line == 0)
|
||||||
// d->EnterBreakpoint(ctx, b);
|
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) {
|
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);
|
_pausedContexts.push_back(ctx);
|
||||||
|
|
||||||
auto* o = new DebugAdapterProtocol::StoppedEvent(
|
auto* o = new DebugAdapterProtocol::StoppedEvent(
|
||||||
new DebugAdapterProtocol::StoppedEventBody(GetBreakpointHash(section, line)));
|
new DebugAdapterProtocol::StoppedEventBody("breakpoint", GetBreakpointHash(section, line)));
|
||||||
|
|
||||||
Send(o);
|
Send(o);
|
||||||
}
|
}
|
||||||
|
@ -244,7 +251,12 @@ void AngelscriptDebugger::OnRequest(asio::ip::tcp::socket* client, DebugAdapterP
|
||||||
auto func = ctx->GetFunction(i);
|
auto func = ctx->GetFunction(i);
|
||||||
const char* scriptSection = nullptr;
|
const char* scriptSection = nullptr;
|
||||||
int column = 0;
|
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(),
|
stackTrace.emplace_back(i, func->GetName(),
|
||||||
DebugAdapterProtocol::Source(GetResolvedScriptPath(scriptSection)), line, column);
|
DebugAdapterProtocol::Source(GetResolvedScriptPath(scriptSection)), line, column);
|
||||||
|
@ -285,6 +297,10 @@ void AngelscriptDebugger::OnRequest(asio::ip::tcp::socket* client, DebugAdapterP
|
||||||
auto c = e->CreateContext();
|
auto c = e->CreateContext();
|
||||||
|
|
||||||
if (holds_alternative<std::unique_ptr<StackScope>>(variant)) {
|
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 frameId = std::get<std::unique_ptr<StackScope>>(variant)->StackLevel;
|
||||||
// auto scopeType = get<StackScope>(variant).Type;
|
// auto scopeType = get<StackScope>(variant).Type;
|
||||||
auto varCount = ctx->GetVarCount(frameId);
|
auto varCount = ctx->GetVarCount(frameId);
|
||||||
|
|
|
@ -188,10 +188,10 @@ namespace DebugAdapterProtocol {
|
||||||
std::optional<bool> allThreadsStopped = true;
|
std::optional<bool> allThreadsStopped = true;
|
||||||
std::optional<std::vector<size_t>> hitBreakpointIds;
|
std::optional<std::vector<size_t>> hitBreakpointIds;
|
||||||
|
|
||||||
explicit StoppedEventBody(size_t breakpoint) {
|
explicit StoppedEventBody(std::string reason, size_t breakpoint)
|
||||||
reason = "breakpoint";
|
: reason(std::move(reason)), hitBreakpointIds({breakpoint}) {}
|
||||||
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 {
|
nlohmann::json ToJson() const override {
|
||||||
auto o = EventBody::ToJson();
|
auto o = EventBody::ToJson();
|
||||||
|
|
Loading…
Reference in New Issue