Skip to content

Commit e6b75a6

Browse files
committed
feat: 调试器支持 DAP(WIP)
1 parent 605d2b9 commit e6b75a6

15 files changed

Lines changed: 3549 additions & 2 deletions

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,9 @@
2323
[submodule "3rdparty/angel-lsp"]
2424
path = 3rdparty/angel-lsp
2525
url = git@github.com:Wing-summer/angel-lsp.git
26+
[submodule "3rdparty/cppdap"]
27+
path = 3rdparty/cppdap
28+
url = git@github.com:Wing-summer/cppdap.git
29+
[submodule "3rdparty/fmt"]
30+
path = 3rdparty/fmt
31+
url = git@github.com:Wing-summer/fmt.git

3rdparty/AngelScript

Submodule AngelScript updated 41 files

3rdparty/as-debugger/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## as-debugger
2+
3+
提供支持 DAP 的 AngelScript 调试器,开源协议为 MIT,来源于 https://github.com/Paril/quake2-angelscript,依赖`cppdap`和`fmt`,感谢[Paril](https://github.com/Paril)的贡献。
4+
5+
Provides AngelScript debugger with DAP support, from https://github.com/Paril/quake2-angelscript. The license is MIT and its dependencies are `cppdap` and `fmt`. Thanks to [Paril](https://github.com/Paril) for his contribution.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include "as_dbg_state.h"
2+
3+
as_dbg_state &as_dbg_state::instance() {
4+
static as_dbg_state ins;
5+
return ins;
6+
}
7+
8+
void as_dbg_state::RegisterEvaluator(
9+
int typeId, std::unique_ptr<asIDBTypeEvaluator> evaluator) {
10+
typeId &= asTYPEID_MASK_OBJECT | asTYPEID_MASK_SEQNBR;
11+
evaluators.insert_or_assign(typeId, std::move(evaluator));
12+
}
13+
14+
void as_dbg_state::CheckDebugger(asIScriptContext *ctx) {
15+
auto &debugger_state = instance();
16+
17+
// TODO
18+
// check if the debugger needs to be changed
19+
// if (debugger_state.active_type != debugger_state.cvar->integer) {
20+
// debugger_state.debugger.reset();
21+
// debugger_state.workspace.reset();
22+
// debugger_state.active_type = debugger_state.cvar->integer;
23+
// }
24+
25+
// we don't want debugging
26+
// if (!debugger_state.cvar->integer)
27+
// return;
28+
29+
// create the debugger
30+
if (!debugger || debugger_state.outdated) {
31+
debugger.reset();
32+
debugger_state.workspace.reset();
33+
34+
// debugger_state.workspace = std::make_unique<asIDBFileWorkspace>(
35+
// std::filesystem::path(Q2AS_ScriptPath()).generic_string(),
36+
// std::initializer_list<asIScriptEngine *>{svas.engine,
37+
// cgas.engine});
38+
39+
// debugger = std::make_unique<q2as_asIDBDebuggerVSCode>(
40+
// debugger_state.workspace.get());
41+
debugger_state.outdated = false;
42+
}
43+
44+
// hook the context if the debugger
45+
// has work to do (breakpoints, etc)
46+
debugger->HookContext(ctx, debugger->HasWork());
47+
}
48+
49+
void as_dbg_state::DebugBreak(asIScriptContext *ctx) {
50+
if (!ctx)
51+
ctx = asGetActiveContext();
52+
53+
if (!debugger)
54+
CheckDebugger(ctx);
55+
56+
if (debugger)
57+
debugger->DebugBreak(ctx);
58+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// MIT Licensed
2+
// see https://github.com/Paril/angelscript-debugger
3+
4+
#ifndef AS_DBG_STATE_H
5+
#define AS_DBG_STATE_H
6+
7+
#include "as_debugger.h"
8+
9+
class as_dbg_state {
10+
public:
11+
static as_dbg_state &instance();
12+
13+
public:
14+
// set to true to re-set the workspace.
15+
bool outdated = false;
16+
17+
std::unique_ptr<asIDBDebugger> debugger;
18+
std::unique_ptr<asIDBWorkspace> workspace;
19+
20+
uint8_t current_tid = 0;
21+
22+
// evaluators don't take up much memory so we'll just
23+
// always keep them around.
24+
std::unordered_map<int, std::unique_ptr<asIDBTypeEvaluator>> evaluators;
25+
26+
// Register an evaluator.
27+
void RegisterEvaluator(int typeId,
28+
std::unique_ptr<asIDBTypeEvaluator> evaluator);
29+
30+
// A quick shortcut to make a templated instantiation
31+
// of T from the given type name.
32+
template <typename T>
33+
void RegisterEvaluator(asIScriptEngine *engine, const char *name) {
34+
RegisterEvaluator(engine->GetTypeInfoByName(name)->GetTypeId(),
35+
std::make_unique<T>());
36+
}
37+
38+
int active_type; // active debugger type
39+
bool suspend_immediately = true;
40+
41+
void CheckDebugger(asIScriptContext *ctx);
42+
void DebugBreak(asIScriptContext *ctx = nullptr);
43+
};
44+
45+
#endif // AS_DBG_STATE_H

0 commit comments

Comments
 (0)