mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Organize the MemoryReader interface headers to better support
multiple clients.
This commit is contained in:
78
include/swift/Remote/CMemoryReader.h
Normal file
78
include/swift/Remote/CMemoryReader.h
Normal file
@@ -0,0 +1,78 @@
|
||||
//===- CMemoryReader.h - MemoryReader wrapper for C impls -------*- C++ -*-===//
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See http://swift.org/LICENSE.txt for license information
|
||||
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file declares an implementation of MemoryReader that wraps the
|
||||
// C interface provided by SwiftRemoteMirror.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef SWIFT_REMOTE_CMEMORYREADER_H
|
||||
#define SWIFT_REMOTE_CMEMORYREADER_H
|
||||
|
||||
#include "swift/SwiftRemoteMirror/MemoryReaderInterface.h"
|
||||
#include "swift/Remote/MemoryReader.h"
|
||||
|
||||
namespace swift {
|
||||
namespace remote {
|
||||
|
||||
/// An implementation of MemoryReader which wraps the C interface offered
|
||||
/// by SwiftRemoteMirror.
|
||||
class CMemoryReader final : public MemoryReader {
|
||||
MemoryReaderImpl Impl;
|
||||
|
||||
public:
|
||||
CMemoryReader(MemoryReaderImpl Impl) : Impl(Impl) {
|
||||
assert(this->Impl.getPointerSize && "No getPointerSize implementation");
|
||||
assert(this->Impl.getStringLength && "No stringLength implementation");
|
||||
assert(this->Impl.readBytes && "No readBytes implementation");
|
||||
assert(this->Impl.getPointerSize() != 0 && "Invalid target pointer size");
|
||||
}
|
||||
|
||||
uint8_t getPointerSize() override {
|
||||
return Impl.getPointerSize();
|
||||
}
|
||||
|
||||
uint8_t getSizeSize() override {
|
||||
return Impl.getSizeSize();
|
||||
}
|
||||
|
||||
RemoteAddress getSymbolAddress(const std::string &name) override {
|
||||
auto addressData = Impl.getSymbolAddress(name.c_str(), name.size());
|
||||
return RemoteAddress(addressData);
|
||||
}
|
||||
|
||||
uint64_t getStringLength(RemoteAddress address) {
|
||||
return Impl.getStringLength(address.getAddressData());
|
||||
}
|
||||
|
||||
bool readString(RemoteAddress address, std::string &dest) override {
|
||||
auto length = getStringLength(address);
|
||||
if (!length)
|
||||
return false;
|
||||
|
||||
auto buffer = std::unique_ptr<uint8_t>(new uint8_t[length + 1]);
|
||||
if (!readBytes(address, buffer.get(), length + 1))
|
||||
return false;
|
||||
|
||||
dest = std::string(reinterpret_cast<const char *>(buffer.get()));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool readBytes(RemoteAddress address, uint8_t *dest, uint64_t size) override {
|
||||
return Impl.readBytes(address.getAddressData(), dest, size);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user