Client-specific debug state.
This commit is contained in:
@@ -16,8 +16,14 @@ using namespace xe;
|
||||
using namespace xe::debug;
|
||||
|
||||
|
||||
uint32_t DebugClient::next_client_id_ = 1;
|
||||
|
||||
|
||||
DebugClient::DebugClient(DebugServer* debug_server) :
|
||||
debug_server_(debug_server) {
|
||||
debug_server_(debug_server),
|
||||
readied_(false) {
|
||||
client_id_ = next_client_id_++;
|
||||
debug_server_->AddClient(this);
|
||||
}
|
||||
|
||||
DebugClient::~DebugClient() {
|
||||
@@ -25,5 +31,9 @@ DebugClient::~DebugClient() {
|
||||
}
|
||||
|
||||
void DebugClient::MakeReady() {
|
||||
debug_server_->AddClient(this);
|
||||
if (readied_) {
|
||||
return;
|
||||
}
|
||||
debug_server_->ReadyClient(this);
|
||||
readied_ = true;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ public:
|
||||
DebugClient(DebugServer* debug_server);
|
||||
virtual ~DebugClient();
|
||||
|
||||
uint32_t client_id() const { return client_id_; }
|
||||
|
||||
virtual int Setup() = 0;
|
||||
virtual void Close() = 0;
|
||||
|
||||
@@ -33,7 +35,11 @@ protected:
|
||||
void MakeReady();
|
||||
|
||||
protected:
|
||||
static uint32_t next_client_id_;
|
||||
|
||||
DebugServer* debug_server_;
|
||||
uint32_t client_id_;
|
||||
bool readied_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#include <xenia/emulator.h>
|
||||
#include <xenia/debug/debug_client.h>
|
||||
#include <xenia/debug/debug_target.h>
|
||||
#include <xenia/debug/protocol.h>
|
||||
#include <xenia/debug/protocols/gdb/gdb_protocol.h>
|
||||
#include <xenia/debug/protocols/ws/ws_protocol.h>
|
||||
@@ -144,14 +145,26 @@ void DebugServer::AddClient(DebugClient* debug_client) {
|
||||
|
||||
clients_.push_back(debug_client);
|
||||
|
||||
xe_mutex_unlock(lock_);
|
||||
// Notify targets.
|
||||
for (auto it = targets_.begin(); it != targets_.end(); ++it) {
|
||||
it->second->OnDebugClientConnected(debug_client->client_id());
|
||||
}
|
||||
|
||||
xe_mutex_unlock(lock_);
|
||||
}
|
||||
|
||||
void DebugServer::ReadyClient(DebugClient* debug_client) {
|
||||
SetEvent(client_event_);
|
||||
}
|
||||
|
||||
void DebugServer::RemoveClient(DebugClient* debug_client) {
|
||||
xe_mutex_lock(lock_);
|
||||
|
||||
// Notify targets.
|
||||
for (auto it = targets_.begin(); it != targets_.end(); ++it) {
|
||||
it->second->OnDebugClientDisconnected(debug_client->client_id());
|
||||
}
|
||||
|
||||
for (std::vector<DebugClient*>::iterator it = clients_.begin();
|
||||
it != clients_.end(); ++it) {
|
||||
if (*it == debug_client) {
|
||||
|
||||
@@ -47,6 +47,7 @@ public:
|
||||
|
||||
private:
|
||||
void AddClient(DebugClient* debug_client);
|
||||
void ReadyClient(DebugClient* debug_client);
|
||||
void RemoveClient(DebugClient* debug_client);
|
||||
|
||||
friend class DebugClient;
|
||||
|
||||
@@ -30,8 +30,11 @@ public:
|
||||
|
||||
DebugServer* debug_server() const { return debug_server_; }
|
||||
|
||||
virtual void OnDebugClientConnected(uint32_t client_id) {}
|
||||
virtual void OnDebugClientDisconnected(uint32_t client_id) {}
|
||||
virtual json_t* OnDebugRequest(
|
||||
const char* command, json_t* request, bool& succeeded) = 0;
|
||||
uint32_t client_id, const char* command, json_t* request,
|
||||
bool& succeeded) = 0;
|
||||
|
||||
protected:
|
||||
DebugServer* debug_server_;
|
||||
|
||||
@@ -428,11 +428,7 @@ void WSClient::Write(const uint8_t** buffers, size_t* lengths, size_t count,
|
||||
}
|
||||
|
||||
void WSClient::OnMessage(const uint8_t* data, size_t length) {
|
||||
//
|
||||
const char* s = (const char*)data;
|
||||
printf(s);
|
||||
// command
|
||||
// requestId
|
||||
|
||||
json_error_t error;
|
||||
json_t* request = json_loadb(
|
||||
@@ -522,5 +518,6 @@ json_t* WSClient::HandleMessage(const char* command, json_t* request,
|
||||
}
|
||||
|
||||
// Dispatch.
|
||||
return target->OnDebugRequest(sub_command, request, succeeded);
|
||||
return target->OnDebugRequest(
|
||||
client_id(), sub_command, request, succeeded);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user