13#include "DebugServer2/GDBRemote/Mixins/FileOperationsMixin.h"
14#include "DebugServer2/Host/Platform.h"
26ErrorCode FileOperationsMixin<T>::onFileOpen(Session &, std::string
const &path,
27 OpenFlags flags, uint32_t mode,
29 static int fileIdx = 0;
31 Host::File file(path, flags, mode);
33 return file.lastError();
37 _openFiles.emplace(fd, std::move(file));
43ErrorCode FileOperationsMixin<T>::onFileClose(Session &session,
int fd) {
44 auto const it = _openFiles.find(fd);
45 if (it == _openFiles.end()) {
46 return kErrorInvalidHandle;
54ErrorCode FileOperationsMixin<T>::onFileRead(Session &session,
int fd,
55 uint64_t &count, uint64_t offset,
57 auto it = _openFiles.find(fd);
58 if (it == _openFiles.end()) {
59 return kErrorInvalidHandle;
62 return it->second.pread(buffer, count, offset);
66ErrorCode FileOperationsMixin<T>::onFileWrite(Session &session,
int fd,
68 ByteVector
const &buffer,
70 auto it = _openFiles.find(fd);
71 if (it == _openFiles.end()) {
72 return kErrorInvalidHandle;
75 return it->second.pwrite(buffer, nwritten, offset);
79ErrorCode FileOperationsMixin<T>::onFileCreateDirectory(Session &,
80 std::string
const &path,
82 return Host::File::createDirectory(path, flags);
86ErrorCode FileOperationsMixin<T>::onFileExists(Session &,
87 std::string
const &path) {
88 return Host::Platform::IsFilePresent(path) ? kSuccess : kErrorNotFound;
92ErrorCode FileOperationsMixin<T>::onFileGetSize(Session &session, std::string
const &path,
94 return Host::File::fileSize(path, size);
98ErrorCode FileOperationsMixin<T>::onFileGetMode(Session &session,
99 std::string
const &path,
100 uint32_t &mode)
const {
101 return Host::File::fileMode(path, mode);
105ErrorCode FileOperationsMixin<T>::onFileFstat(Session &session,
int fd,
106 ByteVector &buffer)
const {
107 auto it = _openFiles.find(fd);
108 if (it == _openFiles.end())
109 return kErrorInvalidHandle;
111 return it->second.fstat(buffer);
115ErrorCode FileOperationsMixin<T>::onFileRemove(Session &session,
116 std::string
const &path) {
117 return Host::File::unlink(path);
121ErrorCode FileOperationsMixin<T>::onFileSetPermissions(Session &session,
122 std::string
const &path,
124 return Host::File::chmod(path, mode);
128ErrorCode FileOperationsMixin<T>::onQueryModuleInfo(Session &session,
131 ModuleInfo &info)
const {
133 if (Platform::GetExecutableFileBuildID(path, buildId)) {
135 std::ostringstream ss;
136 for(
const auto b : buildId)
137 ss << std::uppercase << std::hex << std::setfill(
'0') << std::setw(2) << int(b);
139 info.uuid = ss.str();
146 auto error = File::fileSize(path, info.file_size);
147 if (error != kSuccess)
150 info.triple = triple;
151 info.file_path = path;
152 info.file_offset = 0;