Skip to content

Commit 336c9be

Browse files
committed
修复一个崩溃问题
1 parent 80d9402 commit 336c9be

File tree

8 files changed

+28
-35
lines changed

8 files changed

+28
-35
lines changed

emmy_debugger/include/emmy_debugger/debugger/emmy_debugger.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,4 @@ class Debugger: public std::enable_shared_from_this<Debugger>
129129

130130
std::mutex evalMtx;
131131
std::queue<std::shared_ptr<EvalContext>> evalQueue;
132-
133-
Arena<Variable> _variableArena;
134132
};

emmy_debugger/include/emmy_debugger/debugger/extension_point.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ class ExtensionPoint {
88
public:
99
static std::string ExtensionTable;
1010

11+
static Arena<Variable> *Arena;
12+
1113
ExtensionPoint();
1214

1315
void Initialize(lua_State *L);
1416
//
1517
bool QueryVariable(lua_State *L, Idx<Variable> variable, const char *typeName, int object, int depth);
1618

1719
lua_State *QueryParentThread(lua_State *L);
18-
1920
};

emmy_debugger/include/emmy_debugger/proto/proto.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,12 @@ class EvalContext : public JsonProtocol {
152152
Idx<Variable> result;
153153
bool success = false;
154154
bool setValue = false;
155-
std::shared_ptr<Arena<Variable>> variableArena;
156155

157156
nlohmann::json Serialize() override;
158157

159158
void Deserialize(nlohmann::json json) override;
159+
private:
160+
Arena<Variable> _arena;
160161
};
161162

162163
class EvalParams : public JsonProtocol {

emmy_debugger/include/emmy_debugger/util.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ struct CaseInsensitiveLess final {
1111
// 直到C++ 20才有endwith,这里自己写一个
1212
bool EndWith(const std::string &source, const std::string &end);
1313

14-
std::string BaseName(const std::string &filePath);
1514

emmy_debugger/src/debugger/emmy_debugger.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ void Debugger::SetHookState(std::shared_ptr<HookState> newState) {
789789
}
790790
}
791791

792-
EmmyDebuggerManager* Debugger::GetEmmyDebuggerManager() {
792+
EmmyDebuggerManager *Debugger::GetEmmyDebuggerManager() {
793793
return manager;
794794
}
795795

@@ -963,6 +963,18 @@ struct LogMessageReplaceExpress {
963963
bool NeedEval;
964964
};
965965

966+
std::string BaseName(const std::string &filePath) {
967+
std::size_t sepIndex = filePath.find_last_of('/');
968+
if (sepIndex == std::string::npos) {
969+
sepIndex = filePath.find_last_of('\\');
970+
if (sepIndex != std::string::npos) {
971+
return filePath.substr(sepIndex + 1);
972+
}
973+
return filePath;
974+
} else {
975+
return filePath.substr(sepIndex + 1);
976+
}
977+
}
966978

967979
void Debugger::DoLogMessage(std::shared_ptr<BreakPoint> bp) {
968980
std::string &logMessage = bp->logMessage;

emmy_debugger/src/debugger/extension_point.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "emmy_debugger/emmy_facade.h"
33

44
std::string ExtensionPoint::ExtensionTable = "emmyHelper";
5-
5+
Arena<Variable> *ExtensionPoint::Arena = nullptr;
66

77
int metaQuery(lua_State *L) {
88
const int argN = lua_gettop(L);
@@ -79,20 +79,14 @@ void pushVariable(lua_State *L, Idx<Variable> variable) {
7979
lua_setmetatable(L, -2);
8080
}
8181

82-
void setArena(lua_State *L, Arena<Variable> *arena) {
83-
lua_pushstring(L, "EMMY_ARENA");
84-
lua_pushlightuserdata(L, arena);
85-
lua_rawset(L, LUA_REGISTRYINDEX);
86-
}
87-
8882
int createNode(lua_State *L) {
89-
lua_pushstring(L, "EMMY_ARENA");
90-
lua_rawget(L, LUA_REGISTRYINDEX);
91-
auto arena = (Arena<Variable>*) lua_touserdata(L, -1);
92-
lua_pop(L, 1);
93-
auto idx = arena->Alloc();
94-
pushVariable(L, idx);
95-
return 1;
83+
if (ExtensionPoint::Arena) {
84+
auto idx = ExtensionPoint::Arena->Alloc();
85+
pushVariable(L, idx);
86+
return 1;
87+
} else {
88+
return 0;
89+
}
9690
}
9791

9892
ExtensionPoint::ExtensionPoint() {
@@ -137,6 +131,7 @@ bool ExtensionPoint::QueryVariable(lua_State *L, Idx<Variable> variable, const c
137131
if (lua_istable(L, -1)) {
138132
lua_getfield(L, -1, "queryVariable");
139133
if (lua_isfunction(L, -1)) {
134+
ExtensionPoint::Arena = variable.GetArena();
140135
pushVariable(L, variable);
141136
lua_pushvalue(L, object);
142137
lua_pushstring(L, typeName);

emmy_debugger/src/proto/proto.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,8 @@ void Stack::Deserialize(nlohmann::json json) {
174174
JsonProtocol::Deserialize(json);
175175
}
176176

177-
EvalContext::EvalContext()
178-
: variableArena(std::make_shared<Arena<Variable>>()) {
179-
result = variableArena->Alloc();
177+
EvalContext::EvalContext() {
178+
result = _arena.Alloc();
180179
}
181180

182181
nlohmann::json EvalContext::Serialize() {

emmy_debugger/src/util.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,4 @@ bool EndWith(const std::string &source, const std::string &end) {
4949
return strncmp(end.data(), source.data() + (sourceSize - endSize), endSize) == 0;
5050
}
5151

52-
std::string BaseName(const std::string &filePath) {
53-
std::size_t sepIndex = filePath.find_last_of('/');
54-
if (sepIndex == std::string::npos) {
55-
sepIndex = filePath.find_last_of('\\');
56-
if (sepIndex != std::string::npos) {
57-
return filePath.substr(sepIndex + 1);
58-
}
59-
return filePath;
60-
} else {
61-
return filePath.substr(sepIndex + 1);
62-
}
63-
}
6452

0 commit comments

Comments
 (0)