Debugger: Include assembler API.

This commit is contained in:
Unknown W. Brackets 2018-05-01 20:17:12 -07:00
parent 2f3b6c19d0
commit 65feb5f09c
2 changed files with 26 additions and 3 deletions

View File

@ -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.

View File

@ -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);
}