DebugServer2
Loading...
Searching...
No Matches
ProcessBase.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/Core/HardwareBreakpointManager.h"
14#include "DebugServer2/Core/SoftwareBreakpointManager.h"
15#include "DebugServer2/Target/ProcessDecl.h"
16#include "DebugServer2/Target/ThreadBase.h"
17
18#include <functional>
19#include <memory>
20#include <set>
21
22namespace ds2 {
23namespace Target {
24
26public:
27 enum { kFlagNewProcess = (1 << 0), kFlagAttachedProcess = (1 << 1) };
28 typedef std::map<ThreadId, Thread *> IdentityMap;
29
30protected:
31 bool _terminated;
32 uint32_t _flags;
33 ProcessId _pid;
34 ProcessInfo _info;
35 Address _loadBase;
36 Address _entryPoint;
37 IdentityMap _threads;
38 Thread *_currentThread;
39 mutable std::unique_ptr<SoftwareBreakpointManager> _softwareBreakpointManager;
40 mutable std::unique_ptr<HardwareBreakpointManager> _hardwareBreakpointManager;
41
42protected:
44 virtual ~ProcessBase();
45
46public:
47 inline ProcessId pid() const { return _pid; }
48
49public:
50 inline bool attached() const { return (_flags & kFlagAttachedProcess) != 0; }
51
52public:
53 inline Address const &loadBase() const { return _loadBase; }
54 inline Address const &entryPoint() const { return _entryPoint; }
55
56public:
57 inline Thread *currentThread() const {
58 return const_cast<ProcessBase *>(this)->_currentThread;
59 }
60 Thread *thread(ThreadId tid) const;
61
62protected:
63 virtual ErrorCode initialize(ProcessId pid, uint32_t flags);
64
65public:
66 virtual ErrorCode getInfo(ProcessInfo &info);
67
68public: // ELF only
69 virtual ErrorCode getAuxiliaryVector(std::string &auxv);
70 virtual uint64_t getAuxiliaryVectorValue(uint64_t type);
71
72protected:
73 virtual void cleanup();
74
75public:
76 virtual ErrorCode detach() = 0;
77
78public:
79 virtual ErrorCode suspend();
80 virtual ErrorCode
81 resume(int signal = 0,
82 std::set<Thread *> const &excluded = std::set<Thread *>());
83
84public:
85 virtual ErrorCode interrupt() = 0;
86 virtual ErrorCode terminate() = 0;
87 virtual bool isAlive() const = 0;
88
89public:
90 virtual ErrorCode
91 enumerateThreads(std::function<void(Thread *)> const &cb) const;
92
93public:
94 virtual ErrorCode readString(Address const &address, std::string &str,
95 size_t length, size_t *nread = nullptr) = 0;
96 virtual ErrorCode readMemory(Address const &address, void *buffer,
97 size_t length, size_t *nread = nullptr) = 0;
98 virtual ErrorCode writeMemory(Address const &address, void const *buffer,
99 size_t length, size_t *nwritten = nullptr) = 0;
100
101public:
102 virtual ErrorCode enumerateSharedLibraries(
103 std::function<void(SharedLibraryInfo const &)> const &cb) = 0;
104 virtual ErrorCode
105 enumerateMappedFiles(std::function<void(MappedFileInfo const &)> const &cb);
106
107public:
108 ErrorCode readMemoryBuffer(Address const &address, size_t length,
109 ByteVector &buffer);
110 ErrorCode writeMemoryBuffer(Address const &address, ByteVector const &buffer,
111 size_t *nwritten = nullptr);
112 ErrorCode writeMemoryBuffer(Address const &address, ByteVector const &buffer,
113 size_t length, size_t *nwritten = nullptr);
114
115public:
116 virtual ErrorCode wait() = 0;
117
118public:
119 virtual ErrorCode allocateMemory(size_t size, uint32_t protection,
120 uint64_t *address) = 0;
121 virtual ErrorCode deallocateMemory(uint64_t address, size_t size) = 0;
122
123public:
124 virtual ErrorCode getMemoryRegionInfo(Address const &address,
125 MemoryRegionInfo &info) = 0;
126
127public:
128 virtual void getThreadIds(std::vector<ThreadId> &tids);
129
130protected:
131 virtual ErrorCode updateInfo() = 0;
132
133public:
134 virtual SoftwareBreakpointManager *softwareBreakpointManager() const final;
135 virtual HardwareBreakpointManager *hardwareBreakpointManager() const final;
136
137public:
138 virtual void prepareForDetach();
139 virtual ErrorCode beforeResume();
140 virtual ErrorCode afterResume();
141
142public:
143 virtual int getMaxBreakpoints() const { return 0; }
144 virtual int getMaxWatchpoints() const { return 0; }
145 virtual int getMaxWatchpointSize() const { return 0; }
146
147public:
148 // There shouldn't be any reason for these to be overridden.
149 virtual Architecture::GDBDescriptor const *
150 getGDBRegistersDescriptor() const final;
151 virtual Architecture::LLDBDescriptor const *
152 getLLDBRegistersDescriptor() const final;
153
154protected:
155 friend class ThreadBase;
156 virtual void insert(ThreadBase *thread);
157 virtual void remove(ThreadBase *thread);
158 virtual void removeThread(ThreadId tid);
159};
160} // namespace Target
161} // namespace ds2
Definition Types.h:95
Definition HardwareBreakpointManager.h:19
Definition SoftwareBreakpointManager.h:16
Definition ProcessBase.h:25
Definition ThreadBase.h:22
Definition RegisterLayout.h:151
Definition RegisterLayout.h:158
Definition Types.h:408
Definition Types.h:361
Definition Types.h:263
Definition Types.h:397