Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
CppCXY committed Jul 12, 2023
1 parent 336c9be commit bf00b9c
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 19 deletions.
27 changes: 18 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,42 @@ jobs:
- { os: macos-latest, target: darwin, platform: darwin-x64}
- { os: macos-latest, target: darwin, platform: darwin-arm64}
steps:
- uses: actions/checkout@v2
- name: Env
run: |
if [[ ${{ github.ref }} == refs/tags/* ]]; then
TAG=${{ github.ref }}
TAG=${TAG#refs/tags/}
echo echo "TAG=$TAG" >> $GITHUB_ENV
else
echo echo "TAG=DEV" >> $GITHUB_ENV
fi
- uses: actions/checkout@v2
- name: Build-windows
if: startsWith(matrix.os, 'windows')
run: |
mkdir build
cd build
cmake .. ${{ matrix.cmake_arch }} -G "Visual Studio 17 2022" -DCMAKE_USER_MAKE_RULES_OVERRIDE="${{ github.workspace }}/cmake/flags_override.cmake"
cmake --build . --config RelWithDebInfo
cmake --install . --config RelWithDebInfo --prefix ${{ github.workspace }}/artifact/
cmake .. ${{ matrix.cmake_arch }} -G "Visual Studio 17 2022" -DCMAKE_USER_MAKE_RULES_OVERRIDE="${{ github.workspace }}/cmake/flags_override.cmake" -DEMMY_CORE_VERSION=${{env.TAG}}
cmake --build . --config Release
cmake --install . --config Release --prefix ${{ github.workspace }}/artifact/
- name: Build-linux
if: startsWith(matrix.os, 'ubuntu')
run: |
mkdir build
cd build
cmake ..
cmake --build . --config RelWithDebInfo
cmake --install . --config RelWithDebInfo --prefix ${{ github.workspace }}/artifact/
cmake .. -DCMAKE_BUILD_TYPE=Release -DEMMY_CORE_VERSION=${{env.TAG}}
cmake --build . --config Release
cmake --install . --config Release --prefix ${{ github.workspace }}/artifact/
- name: Build-macosx
if: startsWith(matrix.os, 'macos')
run: |
mkdir build
cd build
if [[ "${{ matrix.platform }}" = darwin-arm64 ]]; then
cmake .. -DCMAKE_OSX_ARCHITECTURES=arm64
cmake .. -DCMAKE_OSX_ARCHITECTURES=arm64 -DCMAKE_BUILD_TYPE=Release -DEMMY_CORE_VERSION=${{env.TAG}}
else
cmake .. -DCMAKE_OSX_ARCHITECTURES=x86_64
cmake .. -DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_BUILD_TYPE=Release -DEMMY_CORE_VERSION=${{env.TAG}}
fi
cmake --build . --config Release
cmake --install . --config Release --prefix ${{ github.workspace }}/artifact/
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(CMAKE_INSTALL_PREFIX install)
set(CMAKE_CXX_STANDARD 11)

set(EMMY_LUA_VERSION "54" CACHE STRING "Lua version: jit/51/52/53/54")
set(EMMY_CORE_VERSION "DEV" CACHE STRING "Emmy core version: DEV/version number")

if(${EMMY_LUA_VERSION} STREQUAL "54")
set(EMMY_LUA_DIR "lua-5.4.0")
Expand All @@ -26,7 +27,7 @@ elseif(${EMMY_LUA_VERSION} STREQUAL "jit")
#add_definitions(-DEMMY_LUA_JIT_SUPPORT_LUA_SETFUNCS)
endif()

add_definitions(-DEMMY_CORE_VERSION="1.5.2")
add_definitions(-DEMMY_CORE_VERSION="${EMMY_CORE_VERSION}")

if(EMMY_USE_LUA_SOURCE)
add_definitions(-DEMMY_USE_LUA_SOURCE)
Expand Down
8 changes: 8 additions & 0 deletions emmy_debugger/include/emmy_debugger/debugger/emmy_debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ class Debugger: public std::enable_shared_from_this<Debugger>
void SetHookState(std::shared_ptr<HookState> newState);
EmmyDebuggerManager* GetEmmyDebuggerManager();

void SetVariableArena(Arena<Variable> *arena);

Arena<Variable> *GetVariableArena();

void ClearVariableArenaRef();

private:
std::shared_ptr<BreakPoint> FindBreakPoint(lua_Debug* ar);
std::shared_ptr<BreakPoint> FindBreakPoint(const std::string& file, int line);
Expand Down Expand Up @@ -129,4 +135,6 @@ class Debugger: public std::enable_shared_from_this<Debugger>

std::mutex evalMtx;
std::queue<std::shared_ptr<EvalContext>> evalQueue;

Arena<Variable> *arenaRef;
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ class ExtensionPoint {
public:
static std::string ExtensionTable;

static Arena<Variable> *Arena;

ExtensionPoint();

void Initialize(lua_State *L);
Expand Down
2 changes: 0 additions & 2 deletions emmy_debugger/include/emmy_debugger/emmy_facade.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ class EmmyFacade

void OnReceiveMessage(nlohmann::json document);

// void Remove

// Start hook 作为成员存在
std::function<void()> StartHook;

Expand Down
23 changes: 22 additions & 1 deletion emmy_debugger/src/debugger/emmy_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ Debugger::Debugger(lua_State *L, EmmyDebuggerManager *manager)
hookState(nullptr),
running(false),
skipHook(false),
blocking(false) {
blocking(false),
arenaRef(nullptr) {
}

Debugger::~Debugger() {
Expand Down Expand Up @@ -200,7 +201,9 @@ bool Debugger::GetStacks(std::vector<Stack> &stacks) {
// add local variable
auto var = stack.variableArena->Alloc();
var->name = name;
SetVariableArena(stack.variableArena.get());
GetVariable(L, var, -1, 1);
ClearVariableArenaRef();
lua_pop(L, 1);
stack.localVariables.push_back(var);
}
Expand All @@ -216,7 +219,9 @@ bool Debugger::GetStacks(std::vector<Stack> &stacks) {
// add up variable
auto var = stack.variableArena->Alloc();
var->name = name;
SetVariableArena(stack.variableArena.get());
GetVariable(L, var, -1, 1);
ClearVariableArenaRef();
lua_pop(L, 1);
stack.upvalueVariables.push_back(var);
}
Expand Down Expand Up @@ -793,6 +798,18 @@ EmmyDebuggerManager *Debugger::GetEmmyDebuggerManager() {
return manager;
}

void Debugger::SetVariableArena(Arena<Variable> *arena) {
arenaRef = arena;
}

Arena<Variable> * Debugger::GetVariableArena() {
return arenaRef;
}

void Debugger::ClearVariableArenaRef() {
arenaRef = nullptr;
}

int Debugger::GetStackLevel(bool skipC) const {
if (!currentL) {
return 0;
Expand Down Expand Up @@ -898,7 +915,9 @@ bool Debugger::DoEval(std::shared_ptr<EvalContext> evalContext) {
lua_getfield(L, LUA_REGISTRYINDEX, CACHE_TABLE_NAME);// 1: cacheTable|nil
if (lua_type(L, -1) == LUA_TTABLE) {
lua_getfield(L, -1, std::to_string(evalContext->cacheId).c_str());// 1: cacheTable, 2: value
SetVariableArena(evalContext->result.GetArena());
GetVariable(L, evalContext->result, -1, evalContext->depth);
ClearVariableArenaRef();
lua_pop(L, 2);
return true;
}
Expand Down Expand Up @@ -937,7 +956,9 @@ bool Debugger::DoEval(std::shared_ptr<EvalContext> evalContext) {
r = lua_pcall(L, 0, 1, 0);
if (r == LUA_OK) {
evalContext->result->name = evalContext->expr;
SetVariableArena(evalContext->result.GetArena());
GetVariable(L, evalContext->result, -1, evalContext->depth);
ClearVariableArenaRef();
lua_pop(L, 1);
return true;
}
Expand Down
7 changes: 3 additions & 4 deletions emmy_debugger/src/debugger/extension_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "emmy_debugger/emmy_facade.h"

std::string ExtensionPoint::ExtensionTable = "emmyHelper";
Arena<Variable> *ExtensionPoint::Arena = nullptr;

int metaQuery(lua_State *L) {
const int argN = lua_gettop(L);
Expand Down Expand Up @@ -80,8 +79,9 @@ void pushVariable(lua_State *L, Idx<Variable> variable) {
}

int createNode(lua_State *L) {
if (ExtensionPoint::Arena) {
auto idx = ExtensionPoint::Arena->Alloc();
auto arenaRef = EmmyFacade::Get().GetDebugger(L)->GetVariableArena();
if (arenaRef) {
auto idx = arenaRef->Alloc();
pushVariable(L, idx);
return 1;
} else {
Expand Down Expand Up @@ -131,7 +131,6 @@ bool ExtensionPoint::QueryVariable(lua_State *L, Idx<Variable> variable, const c
if (lua_istable(L, -1)) {
lua_getfield(L, -1, "queryVariable");
if (lua_isfunction(L, -1)) {
ExtensionPoint::Arena = variable.GetArena();
pushVariable(L, variable);
lua_pushvalue(L, object);
lua_pushstring(L, typeName);
Expand Down

0 comments on commit bf00b9c

Please sign in to comment.