Sharing memory.
This commit is contained in:
@@ -60,14 +60,13 @@ Debugger::~Debugger() {
|
||||
bool Debugger::StartSession() {
|
||||
std::wstring session_path = xe::to_wstring(FLAGS_debug_session_path);
|
||||
|
||||
std::wstring functions_path = xe::join_paths(session_path, L"functions");
|
||||
functions_path_ = xe::join_paths(session_path, L"functions");
|
||||
functions_file_ =
|
||||
ChunkedMappedMemoryWriter::Open(functions_path, 32 * 1024 * 1024, false);
|
||||
ChunkedMappedMemoryWriter::Open(functions_path_, 32 * 1024 * 1024, false);
|
||||
|
||||
std::wstring functions_trace_path =
|
||||
xe::join_paths(session_path, L"functions.trace");
|
||||
functions_trace_path_ = xe::join_paths(session_path, L"functions.trace");
|
||||
functions_trace_file_ = ChunkedMappedMemoryWriter::Open(
|
||||
functions_trace_path, 32 * 1024 * 1024, true);
|
||||
functions_trace_path_, 32 * 1024 * 1024, true);
|
||||
|
||||
listen_socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
if (listen_socket_ < 1) {
|
||||
@@ -195,9 +194,12 @@ void Debugger::OnMessage(std::vector<uint8_t> buffer) {
|
||||
case proto::RequestData_AttachRequest: {
|
||||
// Send debug info.
|
||||
response_data_type = proto::ResponseData_AttachResponse;
|
||||
auto response_data = proto::AttachResponseBuilder(fbb);
|
||||
//
|
||||
response_data_offset = response_data.Finish().Union();
|
||||
response_data_offset =
|
||||
proto::CreateAttachResponse(
|
||||
fbb, fbb.CreateString(
|
||||
xe::to_string(emulator()->memory()->file_name())),
|
||||
fbb.CreateString(xe::to_string(functions_path_)),
|
||||
fbb.CreateString(xe::to_string(functions_trace_path_))).Union();
|
||||
|
||||
// Allow continuation if we were blocked waiting for a client.
|
||||
accept_fence_.Signal();
|
||||
|
||||
@@ -116,7 +116,9 @@ class Debugger {
|
||||
UINT_PTR client_socket_;
|
||||
std::thread receive_thread_;
|
||||
|
||||
std::wstring functions_path_;
|
||||
std::unique_ptr<ChunkedMappedMemoryWriter> functions_file_;
|
||||
std::wstring functions_trace_path_;
|
||||
std::unique_ptr<ChunkedMappedMemoryWriter> functions_trace_file_;
|
||||
|
||||
std::mutex threads_lock_;
|
||||
|
||||
@@ -26,8 +26,9 @@ table AttachRequest {
|
||||
//
|
||||
}
|
||||
table AttachResponse {
|
||||
// file paths
|
||||
// mmap name
|
||||
memory_file:string;
|
||||
functions_file:string;
|
||||
functions_trace_file:string;
|
||||
}
|
||||
|
||||
union RequestData {
|
||||
|
||||
@@ -167,8 +167,17 @@ inline flatbuffers::Offset<AttachRequest> CreateAttachRequest(flatbuffers::FlatB
|
||||
}
|
||||
|
||||
struct AttachResponse FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
const flatbuffers::String *memory_file() const { return GetPointer<const flatbuffers::String *>(4); }
|
||||
const flatbuffers::String *functions_file() const { return GetPointer<const flatbuffers::String *>(6); }
|
||||
const flatbuffers::String *functions_trace_file() const { return GetPointer<const flatbuffers::String *>(8); }
|
||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<flatbuffers::uoffset_t>(verifier, 4 /* memory_file */) &&
|
||||
verifier.Verify(memory_file()) &&
|
||||
VerifyField<flatbuffers::uoffset_t>(verifier, 6 /* functions_file */) &&
|
||||
verifier.Verify(functions_file()) &&
|
||||
VerifyField<flatbuffers::uoffset_t>(verifier, 8 /* functions_trace_file */) &&
|
||||
verifier.Verify(functions_trace_file()) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
@@ -176,16 +185,25 @@ struct AttachResponse FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
struct AttachResponseBuilder {
|
||||
flatbuffers::FlatBufferBuilder &fbb_;
|
||||
flatbuffers::uoffset_t start_;
|
||||
void add_memory_file(flatbuffers::Offset<flatbuffers::String> memory_file) { fbb_.AddOffset(4, memory_file); }
|
||||
void add_functions_file(flatbuffers::Offset<flatbuffers::String> functions_file) { fbb_.AddOffset(6, functions_file); }
|
||||
void add_functions_trace_file(flatbuffers::Offset<flatbuffers::String> functions_trace_file) { fbb_.AddOffset(8, functions_trace_file); }
|
||||
AttachResponseBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
||||
AttachResponseBuilder &operator=(const AttachResponseBuilder &);
|
||||
flatbuffers::Offset<AttachResponse> Finish() {
|
||||
auto o = flatbuffers::Offset<AttachResponse>(fbb_.EndTable(start_, 0));
|
||||
auto o = flatbuffers::Offset<AttachResponse>(fbb_.EndTable(start_, 3));
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline flatbuffers::Offset<AttachResponse> CreateAttachResponse(flatbuffers::FlatBufferBuilder &_fbb) {
|
||||
inline flatbuffers::Offset<AttachResponse> CreateAttachResponse(flatbuffers::FlatBufferBuilder &_fbb,
|
||||
flatbuffers::Offset<flatbuffers::String> memory_file = 0,
|
||||
flatbuffers::Offset<flatbuffers::String> functions_file = 0,
|
||||
flatbuffers::Offset<flatbuffers::String> functions_trace_file = 0) {
|
||||
AttachResponseBuilder builder_(_fbb);
|
||||
builder_.add_functions_trace_file(functions_trace_file);
|
||||
builder_.add_functions_file(functions_file);
|
||||
builder_.add_memory_file(memory_file);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include "xenia/base/logging.h"
|
||||
#include "xenia/base/math.h"
|
||||
#include "xenia/base/threading.h"
|
||||
#include "xenia/cpu/mmio_handler.h"
|
||||
|
||||
// TODO(benvanik): move xbox.h out
|
||||
@@ -114,13 +115,17 @@ Memory::~Memory() {
|
||||
}
|
||||
|
||||
int Memory::Initialize() {
|
||||
wchar_t file_name[256];
|
||||
wsprintf(file_name, L"Local\\xenia_memory_%p", xe::threading::ticks());
|
||||
file_name_ = file_name;
|
||||
|
||||
// Create main page file-backed mapping. This is all reserved but
|
||||
// uncommitted (so it shouldn't expand page file).
|
||||
#if XE_PLATFORM_WIN32
|
||||
mapping_ = CreateFileMapping(INVALID_HANDLE_VALUE, NULL,
|
||||
PAGE_READWRITE | SEC_RESERVE,
|
||||
// entire 4gb space + 512mb physical:
|
||||
1, 0x1FFFFFFF, NULL);
|
||||
1, 0x1FFFFFFF, file_name_.c_str());
|
||||
#else
|
||||
char mapping_path[] = "/xenia/mapping/XXXXXX";
|
||||
mktemp(mapping_path);
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "xenia/base/platform.h"
|
||||
@@ -158,6 +159,8 @@ class Memory {
|
||||
|
||||
int Initialize();
|
||||
|
||||
const std::wstring& file_name() const { return file_name_; }
|
||||
|
||||
inline uint8_t* virtual_membase() const { return virtual_membase_; }
|
||||
inline uint8_t* TranslateVirtual(uint32_t guest_address) const {
|
||||
return virtual_membase_ + guest_address;
|
||||
@@ -211,6 +214,7 @@ class Memory {
|
||||
void UnmapViews();
|
||||
|
||||
private:
|
||||
std::wstring file_name_;
|
||||
uint32_t system_page_size_;
|
||||
uint8_t* virtual_membase_;
|
||||
uint8_t* physical_membase_;
|
||||
|
||||
Reference in New Issue
Block a user