Skip to content

Commit

Permalink
Added ExecuteCode command
Browse files Browse the repository at this point in the history
Fixes #8
  • Loading branch information
dedmen committed Feb 20, 2020
1 parent 8004483 commit 260ddbd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
20 changes: 20 additions & 0 deletions BIDebugEngine/BIDebugEngine/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,26 @@ void Debugger::dumpStackToRPT(GameState* gs) {
intercept::sqf::system_chat("ArmaDebugEngine: Stack Dumped");
}

void Debugger::executeScriptInHalt(r_string script) {
auto rtn = breakStateInfo.instruction->context->callstack.back()->EvaluateExpression(script.c_str(), 10);

JsonArchive ar;
if (rtn.is_null()) {
ar.Serialize("error", "compile failed");
return;
}

//We get a ptr to the IDebugValue of GameData. But we wan't the GameData vtable.
auto gdRtn = reinterpret_cast<GameData*>(rtn.get() - 2); //#TODO warning : 'reinterpret_cast' to class 'GameData *' from its base at non-zero offset 'IDebugValue *' behaves differently from 'static_cast' -- use static_cast and remove ptr math


ar.Serialize("command", static_cast<int>(NC_OutgoingCommandType::ExecuteCodeResult));
ar.Serialize("data", *gdRtn);

auto text = ar.to_string();
nController.sendMessage(text);
}

auto_array<std::pair<r_string, uint32_t>> Debugger::getCallstackRaw(GameState* gs) {
auto_array<std::pair<r_string, uint32_t>> res;

Expand Down
1 change: 1 addition & 0 deletions BIDebugEngine/BIDebugEngine/Debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class Debugger {
void writeFrameToFile(uint32_t frameCounter);
void onInstruction(DebuggerInstructionInfo& instructionInfo);
void dumpStackToRPT(GameState* gs);
void executeScriptInHalt(r_string script);
static auto_array<std::pair<r_string, uint32_t>> getCallstackRaw(GameState* gs);
void onScriptError(GameState* gs);
void onScriptAssert(GameState* gs);
Expand Down
11 changes: 11 additions & 0 deletions BIDebugEngine/BIDebugEngine/NetworkController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ void NetworkController::incomingMessage(const std::string& message) {
GlobalDebugger.state = DebuggerState::waitForHalt;
} break;

case NC_CommandType::ExecuteCode: {
//I don't verify that debugger is halted... please be nice.
//#TODO ^
JsonArchive ar(packet["data"]);

r_string script;
ar.Serialize("script", script);


GlobalDebugger.executeScriptInHalt(script);
} break;

}
}
Expand Down
6 changes: 4 additions & 2 deletions BIDebugEngine/BIDebugEngine/NetworkController.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ enum class NC_CommandType {
getCurrentCode, //While in breakState returns full preproced code of last Instructions script file
getAllScriptCommands,
getAvailableVariables,
haltNow //Triggers halt on next possible instruction
haltNow, //Triggers halt on next possible instruction
ExecuteCode //Executes code while halted, in current context and returns result
};

enum class NC_OutgoingCommandType {
Expand All @@ -30,7 +31,8 @@ enum class NC_OutgoingCommandType {
VariableReturn, //returning from getVariable
AvailableVariablesReturn, //returning from getAvailableVariables
BreakpointLog, //A log breakpoint was triggered
LogMessage //A log message from the game, for example from echo script command
LogMessage, //A log message from the game, for example from echo script command
ExecuteCodeResult //Result of ExecuteCode command
};

class NetworkController {
Expand Down

0 comments on commit 260ddbd

Please sign in to comment.