Skeleton of the debugger host.

This commit is contained in:
Ben Vanik
2013-02-01 05:37:42 -08:00
parent b6a9dfe7e0
commit c2fbafdc28
20 changed files with 679 additions and 2 deletions

27
src/dbg/client.cc Normal file
View File

@@ -0,0 +1,27 @@
/**
******************************************************************************
* 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. *
******************************************************************************
*/
#include <xenia/dbg/client.h>
using namespace xe;
using namespace xe::dbg;
Client::Client() {
}
Client::~Client() {
}
void Client::Write(const uint8_t* buffer, const size_t length) {
const uint8_t* buffers[] = {buffer};
const size_t lengths[] = {length};
Write(buffers, lengths, 1);
}

27
src/dbg/content_source.cc Normal file
View File

@@ -0,0 +1,27 @@
/**
******************************************************************************
* 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. *
******************************************************************************
*/
#include <xenia/dbg/content_source.h>
using namespace xe;
using namespace xe::dbg;
ContentSource::ContentSource(Type type) :
type_(type) {
}
ContentSource::~ContentSource() {
}
ContentSource::Type ContentSource::type() {
return type_;
}

80
src/dbg/debugger.cc Normal file
View File

@@ -0,0 +1,80 @@
/**
******************************************************************************
* 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. *
******************************************************************************
*/
#include <xenia/dbg/debugger.h>
#include <gflags/gflags.h>
#include <xenia/dbg/content_source.h>
#include "dbg/ws_listener.h"
using namespace xe;
using namespace xe::dbg;
DEFINE_bool(wait_for_debugger, false,
"Whether to wait for the debugger to attach before launching.");
DEFINE_int32(remote_debug_port, 6200,
"Websocket port to listen for debugger connections on.");
Debugger::Debugger(xe_pal_ref pal) {
pal_ = xe_pal_retain(pal);
listener_ = auto_ptr<Listener>(new WsListener(
pal_, FLAGS_remote_debug_port));
}
Debugger::~Debugger() {
for (std::map<char*, ContentSource*>::iterator it = content_sources_.begin();
it != content_sources_.end(); ++it) {
xe_free(it->first);
delete it->second;
}
content_sources_.clear();
xe_pal_release(pal_);
}
void Debugger::RegisterContentSource(std::string& name,
ContentSource* content_source) {
content_sources_.insert(std::pair<char*, ContentSource*>(
xestrdupa(name.c_str()), content_source));
}
int Debugger::Startup() {
// Start listener.
// This may launch a thread and such.
if (listener_->Setup()) {
return 1;
}
// If desired, wait until the first client connects.
if (FLAGS_wait_for_debugger) {
XELOGI(XT("Waiting for debugger on port %d..."), FLAGS_remote_debug_port);
if (listener_->WaitForClient()) {
return 1;
}
XELOGI(XT("Debugger attached, continuing..."));
}
return 0;
}
int Debugger::DispatchRequest(Client* client, const char* source_name,
const uint8_t* data, size_t length) {
std::map<char*, ContentSource*>::iterator it =
content_sources_.find((char*)source_name);
if (it == content_sources_.end()) {
return 1;
}
return it->second->DispatchRequest(client, data, length);
}

View File

@@ -0,0 +1,28 @@
/**
******************************************************************************
* 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. *
******************************************************************************
*/
#include <xenia/dbg/indexed_content_source.h>
using namespace xe;
using namespace xe::dbg;
IndexedContentSource::IndexedContentSource() :
ContentSource(kTypeIndexed) {
}
IndexedContentSource::~IndexedContentSource() {
}
int IndexedContentSource::DispatchRequest(Client* client,
const uint8_t* data, size_t length) {
//
return 1;
}

23
src/dbg/listener.cc Normal file
View File

@@ -0,0 +1,23 @@
/**
******************************************************************************
* 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. *
******************************************************************************
*/
#include "dbg/listener.h"
using namespace xe;
using namespace xe::dbg;
Listener::Listener(xe_pal_ref pal) {
pal_ = xe_pal_retain(pal);
}
Listener::~Listener() {
xe_pal_release(pal_);
}

38
src/dbg/listener.h Normal file
View File

@@ -0,0 +1,38 @@
/**
******************************************************************************
* 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_KERNEL_DBG_LISTENER_H_
#define XENIA_KERNEL_DBG_LISTENER_H_
#include <xenia/common.h>
#include <xenia/core.h>
namespace xe {
namespace dbg {
class Listener {
public:
Listener(xe_pal_ref pal);
virtual ~Listener();
virtual int Setup() = 0;
virtual int WaitForClient() = 0;
protected:
xe_pal_ref pal_;
};
} // namespace dbg
} // namespace xe
#endif // XENIA_KERNEL_DBG_LISTENER_H_

12
src/dbg/sources.gypi Normal file
View File

@@ -0,0 +1,12 @@
# Copyright 2013 Ben Vanik. All Rights Reserved.
{
'sources': [
'client.cc',
'content_source.cc',
'debugger.cc',
'indexed_content_source.cc',
'listener.cc',
'ws_client.cc',
'ws_listener.cc',
],
}

29
src/dbg/ws_client.cc Normal file
View File

@@ -0,0 +1,29 @@
/**
******************************************************************************
* 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. *
******************************************************************************
*/
#include "dbg/ws_client.h"
using namespace xe;
using namespace xe::dbg;
WsClient::WsClient(int socket_id) :
Client(),
socket_id_(socket_id) {
}
WsClient::~WsClient() {
close(socket_id_);
}
void WsClient::Write(const uint8_t** buffers, const size_t* lengths,
size_t count) {
//
}

40
src/dbg/ws_client.h Normal file
View File

@@ -0,0 +1,40 @@
/**
******************************************************************************
* 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_KERNEL_DBG_WS_CLIENT_H_
#define XENIA_KERNEL_DBG_WS_CLIENT_H_
#include <xenia/common.h>
#include <xenia/core.h>
#include <xenia/dbg/client.h>
namespace xe {
namespace dbg {
class WsClient : public Client {
public:
WsClient(int socket_id);
virtual ~WsClient();
virtual void Write(const uint8_t** buffers, const size_t* lengths,
size_t count);
protected:
int socket_id_;
};
} // namespace dbg
} // namespace xe
#endif // XENIA_KERNEL_DBG_WS_CLIENT_H_

86
src/dbg/ws_listener.cc Normal file
View File

@@ -0,0 +1,86 @@
/**
******************************************************************************
* 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. *
******************************************************************************
*/
#include "dbg/ws_listener.h"
#include <arpa/inet.h>
#include <netinet/tcp.h>
#include <sys/socket.h>
#include "dbg/ws_client.h"
using namespace xe;
using namespace xe::dbg;
WsListener::WsListener(xe_pal_ref pal, uint32_t port) :
Listener(pal),
port_(port) {
}
WsListener::~WsListener() {
if (socket_id_) {
close(socket_id_);
}
}
int WsListener::Setup() {
socket_id_ = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (socket_id_ < 1) {
return 1;
}
int opt_value;
opt_value = 1;
setsockopt(socket_id_, SOL_SOCKET, SO_KEEPALIVE,
&opt_value, sizeof(opt_value));
opt_value = 0;
setsockopt(socket_id_, IPPROTO_TCP, TCP_NODELAY,
&opt_value, sizeof(opt_value));
struct sockaddr_in socket_addr;
socket_addr.sin_family = AF_INET;
socket_addr.sin_addr.s_addr = htonl(INADDR_ANY);
socket_addr.sin_port = htons(port_);
if (bind(socket_id_, (struct sockaddr*)&socket_addr,
sizeof(socket_addr)) < 0) {
return 1;
}
if (listen(socket_id_, 5) < 0) {
close(socket_id_);
return 1;
}
return 0;
}
int WsListener::WaitForClient() {
// Accept the first connection we get.
struct sockaddr_in client_addr;
socklen_t client_count = sizeof(client_addr);
int client_socket_id = accept(socket_id_, (struct sockaddr*)&client_addr,
&client_count);
if (client_socket_id < 0) {
return 1;
}
int client_ip = client_addr.sin_addr.s_addr;
char client_ip_str[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &client_ip, client_ip_str, XECOUNT(client_ip_str));
XELOGI(XT("Debugger connected from %s"), client_ip_str);
//WsClient* client = new WsClient(client_socket_id);
// TODO(benvanik): add to list for cleanup
return 0;
}

42
src/dbg/ws_listener.h Normal file
View File

@@ -0,0 +1,42 @@
/**
******************************************************************************
* 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_KERNEL_DBG_WS_LISTENER_H_
#define XENIA_KERNEL_DBG_WS_LISTENER_H_
#include <xenia/common.h>
#include <xenia/core.h>
#include "dbg/listener.h"
namespace xe {
namespace dbg {
class WsListener : public Listener {
public:
WsListener(xe_pal_ref pal, uint32_t port);
virtual ~WsListener();
virtual int Setup();
virtual int WaitForClient();
protected:
uint32_t port_;
int socket_id_;
};
} // namespace dbg
} // namespace xe
#endif // XENIA_KERNEL_DBG_WS_LISTENER_H_