Permalink
Browse files

Debugger: Include assembler API.

  • Loading branch information...
unknownbrackets committed May 2, 2018
1 parent 2f3b6c1 commit 65feb5f09ce2e86603bc2e796c81d5b4f613d1b2
Showing with 26 additions and 3 deletions.
  1. +1 −1 Core/Debugger/WebSocket/CPUCoreSubscriber.cpp
  2. +25 −2 Core/Debugger/WebSocket/DisasmSubscriber.cpp
@@ -271,7 +271,7 @@ void WebSocketCPUGetReg(DebuggerRequest &req) {
json.writeString("floatValue", RegValueAsFloat(val));
}
// Retrieve the value of a single register (cpu.getReg)
// Update the value of a single register (cpu.setReg)
//
// Parameters (by name):
// - name: string name of register to lookup.
@@ -17,11 +17,13 @@
#include <algorithm>
#include "base/stringutil.h"
#include "util/text/utf8.h"
#include "Core/Debugger/Breakpoints.h"
#include "Core/Debugger/DisassemblyManager.h"
#include "Core/Debugger/WebSocket/DisasmSubscriber.h"
#include "Core/Debugger/WebSocket/WebSocketUtils.h"
#include "Core/MemMap.h"
#include "Core/MIPS/MIPSAsm.h"
#include "Core/MIPS/MIPSDebugInterface.h"
struct WebSocketDisasmState {
@@ -31,6 +33,7 @@ struct WebSocketDisasmState {
void Base(DebuggerRequest &req);
void Disasm(DebuggerRequest &req);
void Assemble(DebuggerRequest &req);
protected:
void WriteDisasmLine(JsonWriter &json, const DisassemblyLineInfo &l);
@@ -43,6 +46,7 @@ void *WebSocketDisasmInit(DebuggerEventHandlerMap &map) {
auto p = new WebSocketDisasmState();
map["memory.base"] = std::bind(&WebSocketDisasmState::Base, p, std::placeholders::_1);
map["memory.disasm"] = std::bind(&WebSocketDisasmState::Disasm, p, std::placeholders::_1);
map["memory.assemble"] = std::bind(&WebSocketDisasmState::Assemble, p, std::placeholders::_1);
return p;
}
@@ -285,8 +289,8 @@ void WebSocketDisasmState::Disasm(DebuggerRequest &req) {
json.pushArray("lines");
DisassemblyLineInfo line;
u32 addr = start;
for (u32 i = 0; i < count; ++i) {
uint32_t addr = start;
for (uint32_t i = 0; i < count; ++i) {
disasm_.getLine(addr, displaySymbols, line);
WriteDisasmLine(json, line);
addr += line.totalSize;
@@ -303,3 +307,22 @@ void WebSocketDisasmState::Disasm(DebuggerRequest &req) {
WriteBranchGuide(json, bl);
json.pop();
}
void WebSocketDisasmState::Assemble(DebuggerRequest &req) {
if (!currentDebugMIPS->isAlive() || !Memory::IsActive()) {
return req.Fail("CPU not started");
}
uint32_t address;
if (!req.ParamU32("address", &address))
return;
std::string code;
if (!req.ParamString("code", &code))
return;
if (!MIPSAsm::MipsAssembleOpcode(code.c_str(), currentDebugMIPS, address))
return req.Fail(StringFromFormat("Could not assemble: %s", ConvertWStringToUTF8(MIPSAsm::GetAssembleError()).c_str()));
JsonWriter &json = req.Respond();
json.writeUint("encoding", Memory::Read_Instruction(address).encoding);
}

0 comments on commit 65feb5f

Please sign in to comment.