Routing messages to debug targets.
This commit is contained in:
@@ -106,6 +106,25 @@ void DebugServer::Shutdown() {
|
||||
xe_mutex_unlock(lock_);
|
||||
}
|
||||
|
||||
void DebugServer::AddTarget(const char* name, DebugTarget* target) {
|
||||
xe_mutex_lock(lock_);
|
||||
targets_[name] = target;
|
||||
xe_mutex_unlock(lock_);
|
||||
}
|
||||
|
||||
void DebugServer::RemoveTarget(const char* name) {
|
||||
xe_mutex_lock(lock_);
|
||||
targets_[name] = NULL;
|
||||
xe_mutex_unlock(lock_);
|
||||
}
|
||||
|
||||
DebugTarget* DebugServer::GetTarget(const char* name) {
|
||||
xe_mutex_lock(lock_);
|
||||
DebugTarget* target = targets_[name];
|
||||
xe_mutex_unlock(lock_);
|
||||
return target;
|
||||
}
|
||||
|
||||
int DebugServer::WaitForClient() {
|
||||
while (!has_clients()) {
|
||||
WaitForSingleObject(client_event_, INFINITE);
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
XEDECLARECLASS1(xe, Emulator);
|
||||
XEDECLARECLASS2(xe, debug, DebugClient);
|
||||
XEDECLARECLASS2(xe, debug, DebugTarget);
|
||||
XEDECLARECLASS2(xe, debug, Protocol);
|
||||
|
||||
|
||||
@@ -38,6 +39,10 @@ public:
|
||||
int BeforeEntry();
|
||||
void Shutdown();
|
||||
|
||||
void AddTarget(const char* name, DebugTarget* target);
|
||||
void RemoveTarget(const char* name);
|
||||
DebugTarget* GetTarget(const char* name);
|
||||
|
||||
int WaitForClient();
|
||||
|
||||
private:
|
||||
@@ -51,6 +56,8 @@ private:
|
||||
std::vector<Protocol*> protocols_;
|
||||
|
||||
xe_mutex_t* lock_;
|
||||
typedef std::unordered_map<std::string, DebugTarget*> TargetMap;
|
||||
TargetMap targets_;
|
||||
std::vector<DebugClient*> clients_;
|
||||
HANDLE client_event_;
|
||||
};
|
||||
|
||||
45
src/xenia/debug/debug_target.h
Normal file
45
src/xenia/debug/debug_target.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2013 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef XENIA_DEBUG_DEBUG_TARGET_H_
|
||||
#define XENIA_DEBUG_DEBUG_TARGET_H_
|
||||
|
||||
#include <xenia/common.h>
|
||||
#include <xenia/core.h>
|
||||
#include <xenia/debug/debug_server.h>
|
||||
|
||||
|
||||
struct json_t;
|
||||
|
||||
|
||||
namespace xe {
|
||||
namespace debug {
|
||||
|
||||
|
||||
class DebugTarget {
|
||||
public:
|
||||
DebugTarget(DebugServer* debug_server) :
|
||||
debug_server_(debug_server) {}
|
||||
virtual ~DebugTarget() {}
|
||||
|
||||
DebugServer* debug_server() const { return debug_server_; }
|
||||
|
||||
virtual json_t* OnDebugRequest(
|
||||
const char* command, json_t* request, bool& succeeded) = 0;
|
||||
|
||||
protected:
|
||||
DebugServer* debug_server_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace debug
|
||||
} // namespace xe
|
||||
|
||||
|
||||
#endif // XENIA_DEBUG_DEBUG_TARGET_H_
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include <xenia/emulator.h>
|
||||
#include <xenia/debug/debug_server.h>
|
||||
#include <xenia/debug/debug_target.h>
|
||||
#include <xenia/debug/protocols/ws/simple_sha1.h>
|
||||
#include <xenia/kernel/xboxkrnl/kernel_state.h>
|
||||
#include <xenia/kernel/xboxkrnl/xboxkrnl_module.h>
|
||||
@@ -494,17 +495,22 @@ json_t* WSClient::HandleMessage(const char* command, json_t* request,
|
||||
// Get target.
|
||||
char target_name[16] = { 0 };
|
||||
const char* dot = xestrchra(command, '.');
|
||||
if (dot) {
|
||||
if (dot - command > XECOUNT(target_name)) {
|
||||
return NULL;
|
||||
}
|
||||
xestrncpya(target_name, XECOUNT(target_name),
|
||||
command, dot - command);
|
||||
if (!dot) {
|
||||
return json_string("No debug target specified.");
|
||||
}
|
||||
if (dot - command > XECOUNT(target_name)) {
|
||||
return NULL;
|
||||
}
|
||||
xestrncpya(target_name, XECOUNT(target_name),
|
||||
command, dot - command);
|
||||
const char* sub_command = command + (dot - command + 1);
|
||||
|
||||
// Lookup target and dispatch.
|
||||
// Lookup target.
|
||||
DebugTarget* target = debug_server_->GetTarget(target_name);
|
||||
if (!target) {
|
||||
return json_string("Unknown debug target prefix.");
|
||||
}
|
||||
|
||||
succeeded = true;
|
||||
return json_null();
|
||||
// Dispatch.
|
||||
return target->OnDebugRequest(sub_command, request, succeeded);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
'debug_client.h',
|
||||
'debug_server.cc',
|
||||
'debug_server.h',
|
||||
'debug_target.h',
|
||||
'protocol.cc',
|
||||
'protocol.h',
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user