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
33private:
34 // vFile paths are frequently relative (e.g. a bare filename an inferior
35 // writes into its own working directory); unlike qPlatform_shell, the
36 // vFile packets carry no separate working-directory field, so ds2 has to
37 // apply the platform session's own configured working directory itself.
38 // This has to stay session-local rather than mutating ds2's actual
39 // process cwd: platform mode serves each connected client on its own
40 // thread with its own session (see PlatformMain in Sources/main.cpp), and
41 // the process cwd is shared state across all of them.
42 std::string resolvePath(Session &session, std::string const &path) const;
43
44protected:
45 ErrorCode onFileOpen(Session &session, std::string const &path,
46 OpenFlags flags, uint32_t mode, int &fd) override;
47 ErrorCode onFileClose(Session &session, int fd) override;
48 ErrorCode onFileRead(Session &session, int fd, uint64_t &count,
49 uint64_t offset, ByteVector &buffer) override;
50 ErrorCode onFileWrite(Session &session, int fd, uint64_t offset,
51 const ByteVector &buffer, uint64_t &nwritten) override;
52
53protected:
54 ErrorCode onFileCreateDirectory(Session &session, std::string const &path,
55 uint32_t mode) override;
56
57protected:
58 ErrorCode onFileExists(Session &session, std::string const &path) override;
59 ErrorCode onFileGetSize(Session &session, std::string const &path,
60 uint64_t &size) override;
61 ErrorCode onFileGetMode(Session &session, std::string const &path,
62 uint32_t &mode) const override;
63 ErrorCode onFileFstat(Session &session, int fd, ByteVector &buffer) const override;
64 ErrorCode onFileRemove(Session &session, std::string const &path) override;
65
66protected:
67 ErrorCode onFileSetPermissions(Session &session, std::string const &path,
68 uint32_t mode) override;
69 ErrorCode onQueryModuleInfo(Session &session, std::string &path,
70 std::string &triple,
71 ModuleInfo &info) const override;
72
73#if 0
74 // more F packets:
75 // https://sourceware.org/gdb/onlinedocs/gdb/List-of-Supported-Calls.html#List-of-Supported-Calls
76 virtual ErrorCode onGetCurrentTime(Session &session, TimeValue &tv);
77
78 virtual ErrorCode onFileIsATTY(Session &session, int fd);
79 virtual ErrorCode onFileRename(Session &session,
80 std::string const &oldPath, std::string const &newPath);
81
82 virtual ErrorCode onFileGetStat(Session &session, std::string const &path,
83 FileStat &stat);
84 virtual ErrorCode onFileGetStat(Session &session, int fd,
85 FileStat &stat);
86
87 virtual ErrorCode onFileSeek(Session &session, int fd,
88 int64_t offset, int whence, int64_t &newOffset);
89#endif
90};
91} // namespace GDBRemote
92} // namespace ds2
93
94#include "../Sources/GDBRemote/Mixins/FileOperationsMixin.hpp"
Definition FileOperationsMixin.h:24
Definition Session.h:22
Definition Types.h:34