Sharing memory.

This commit is contained in:
Ben Vanik
2015-05-24 00:02:47 -07:00
parent 576d6492dc
commit da655d15b3
12 changed files with 373 additions and 18 deletions

View File

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

View File

@@ -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_;

View File

@@ -26,8 +26,9 @@ table AttachRequest {
//
}
table AttachResponse {
// file paths
// mmap name
memory_file:string;
functions_file:string;
functions_trace_file:string;
}
union RequestData {

View File

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