DebugServer2
Loading...
Searching...
No Matches
FileOperationsMixin.h
1//
2// Copyright (c) 2014-present, Facebook, Inc.
3// All rights reserved.
4//
5// This source code is licensed under the University of Illinois/NCSA Open
6// Source License found in the LICENSE file in the root directory of this
7// source tree. An additional grant of patent rights can be found in the
8// PATENTS file in the same directory.
9//
10
11#pragma once
12
13#include "DebugServer2/GDBRemote/DummySessionDelegateImpl.h"
14#include "DebugServer2/Host/File.h"
15#include "DebugServer2/Host/ProcessSpawner.h"
16#include "DebugServer2/Target/Process.h"
17#include "DebugServer2/Target/Thread.h"
18
19#include <utility>
20
21namespace ds2 {
22namespace GDBRemote {
23
24template <typename T> class FileOperationsMixin : public T {
25protected:
26 std::unordered_map<int, Host::File> _openFiles;
27
28public:
29 template <typename... Args>
30 explicit FileOperationsMixin(Args &&... args)
31 : T(std::forward<Args>(args)...) {}
32
33protected:
34 ErrorCode onFileOpen(Session &session, std::string const &path,
35 OpenFlags flags, uint32_t mode, int &fd) override;
36 ErrorCode onFileClose(Session &session, int fd) override;
37 ErrorCode onFileRead(Session &session, int fd, uint64_t &count,
38 uint64_t offset, ByteVector &buffer) override;
39 ErrorCode onFileWrite(Session &session, int fd, uint64_t offset,
40 const ByteVector &buffer, uint64_t &nwritten) override;
41
42protected:
43 ErrorCode onFileCreateDirectory(Session &session, std::string const &path,
44 uint32_t mode) override;
45
46protected:
47 ErrorCode onFileExists(Session &session, std::string const &path) override;
48 ErrorCode onFileGetSize(Session &session, std::string const &path,
49 uint64_t &size) override;
50 ErrorCode onFileGetMode(Session &session, std::string const &path,
51 uint32_t &mode) const override;
52 ErrorCode onFileFstat(Session &session, int fd, ByteVector &buffer) const override;
53 ErrorCode onFileRemove(Session &session, std::string const &path) override;
54
55protected:
56 ErrorCode onFileSetPermissions(Session &session, std::string const &path,
57 uint32_t mode) override;
58 ErrorCode onQueryModuleInfo(Session &session, std::string &path,
59 std::string &triple,
60 ModuleInfo &info) const override;
61
62#if 0
63 // more F packets:
64 // https://sourceware.org/gdb/onlinedocs/gdb/List-of-Supported-Calls.html#List-of-Supported-Calls
65 virtual ErrorCode onGetCurrentTime(Session &session, TimeValue &tv);
66
67 virtual ErrorCode onFileIsATTY(Session &session, int fd);
68 virtual ErrorCode onFileRename(Session &session,
69 std::string const &oldPath, std::string const &newPath);
70
71 virtual ErrorCode onFileGetStat(Session &session, std::string const &path,
72 FileStat &stat);
73 virtual ErrorCode onFileGetStat(Session &session, int fd,
74 FileStat &stat);
75
76 virtual ErrorCode onFileSeek(Session &session, int fd,
77 int64_t offset, int whence, int64_t &newOffset);
78#endif
79};
80} // namespace GDBRemote
81} // namespace ds2
82
83#include "../Sources/GDBRemote/Mixins/FileOperationsMixin.hpp"
Definition FileOperationsMixin.h:24
Definition Session.h:22
Definition Types.h:34