27 enum { kFlagNewProcess = (1 << 0), kFlagAttachedProcess = (1 << 1) };
28 enum Extension : uint32_t {
29 kExtensionForkEvents = (1u << 0),
30 kExtensionVForkEvents = (1u << 1),
32 typedef std::map<ThreadId, Thread *> IdentityMap;
37 uint32_t _enabledExtensions = 0;
43 Thread *_currentThread;
44 mutable std::unique_ptr<SoftwareBreakpointManager> _softwareBreakpointManager;
45 mutable std::unique_ptr<HardwareBreakpointManager> _hardwareBreakpointManager;
52 inline ProcessId pid()
const {
return _pid; }
55 inline bool attached()
const {
return (_flags & kFlagAttachedProcess) != 0; }
62 inline bool hasExtension(Extension extension)
const {
63 return (_enabledExtensions & extension) != 0;
65 inline uint32_t enabledExtensions()
const {
return _enabledExtensions; }
66 inline bool forkEventsEnabled()
const {
67 return hasExtension(kExtensionForkEvents);
69 inline bool vforkEventsEnabled()
const {
70 return hasExtension(kExtensionVForkEvents);
72 inline void setEnabledExtensions(uint32_t extensions) {
73 _enabledExtensions = extensions;
75 inline void setForkEventsEnabled(
bool fork,
bool vfork) {
76 uint32_t extensions = 0;
78 extensions |= kExtensionForkEvents;
81 extensions |= kExtensionVForkEvents;
83 setEnabledExtensions(extensions);
87 inline Address const &loadBase()
const {
return _loadBase; }
88 inline Address const &entryPoint()
const {
return _entryPoint; }
91 inline Thread *currentThread()
const {
92 return const_cast<ProcessBase *
>(
this)->_currentThread;
94 Thread *thread(ThreadId tid)
const;
97 virtual ErrorCode initialize(ProcessId pid, uint32_t flags);
103 virtual ErrorCode getAuxiliaryVector(std::string &auxv);
104 virtual uint64_t getAuxiliaryVectorValue(uint64_t type);
107 virtual void cleanup();
110 virtual ErrorCode detach(
bool stopped) = 0;
113 virtual ErrorCode suspend();
115 resume(
int signal = 0,
116 std::set<Thread *>
const &excluded = std::set<Thread *>());
119 virtual ErrorCode interrupt() = 0;
120 virtual ErrorCode terminate() = 0;
121 virtual bool isAlive()
const = 0;
125 enumerateThreads(std::function<
void(Thread *)>
const &cb)
const;
128 virtual ErrorCode readString(
Address const &address, std::string &str,
129 size_t length,
size_t *nread =
nullptr) = 0;
130 virtual ErrorCode readMemory(
Address const &address,
void *buffer,
131 size_t length,
size_t *nread =
nullptr) = 0;
132 virtual ErrorCode writeMemory(
Address const &address,
void const *buffer,
133 size_t length,
size_t *nwritten =
nullptr) = 0;
136 virtual ErrorCode enumerateSharedLibraries(
139 enumerateMappedFiles(std::function<
void(
MappedFileInfo const &)>
const &cb);
142 ErrorCode readMemoryBuffer(
Address const &address,
size_t length,
144 ErrorCode writeMemoryBuffer(
Address const &address, ByteVector
const &buffer,
145 size_t *nwritten =
nullptr);
146 ErrorCode writeMemoryBuffer(
Address const &address, ByteVector
const &buffer,
147 size_t length,
size_t *nwritten =
nullptr);
150 virtual ErrorCode wait() = 0;
153 virtual ErrorCode allocateMemory(
size_t size, uint32_t protection,
154 uint64_t *address) = 0;
155 virtual ErrorCode deallocateMemory(uint64_t address,
size_t size) = 0;
158 virtual ErrorCode getMemoryRegionInfo(
Address const &address,
162 virtual void getThreadIds(std::vector<ThreadId> &tids);
165 virtual ErrorCode updateInfo() = 0;
172 virtual void prepareForDetach();
173 virtual ErrorCode beforeResume();
174 virtual ErrorCode afterResume();
177 virtual int getMaxBreakpoints()
const {
return 0; }
178 virtual int getMaxWatchpoints()
const {
return 0; }
179 virtual int getMaxWatchpointSize()
const {
return 0; }
184 getGDBRegistersDescriptor()
const final;
186 getLLDBRegistersDescriptor()
const final;
192 virtual void removeThread(ThreadId tid);