13#include "DebugServer2/Base.h"
14#include "DebugServer2/Constants.h"
15#include "DebugServer2/Core/CPUTypes.h"
16#include "DebugServer2/Core/ErrorCodes.h"
34typedef DWORD ProcessId;
35typedef DWORD ThreadId;
40typedef pid_t ProcessId;
41typedef pid_t ThreadId;
47static const ProcessId kAllProcessId =
static_cast<ProcessId
>(-1);
48static const ProcessId kAnyProcessId =
static_cast<ProcessId
>(0);
49static const ThreadId kAllThreadId =
static_cast<ThreadId
>(-1);
50static const ThreadId kAnyThreadId =
static_cast<ThreadId
>(0);
52typedef std::vector<uint8_t> ByteVector;
61 ProcessThreadId(ProcessId _pid = kAnyProcessId, ThreadId _tid = kAnyThreadId)
62 : pid(_pid), tid(_tid) {}
64 inline bool validPid()
const {
65 return pid != kAllProcessId && pid != kAnyProcessId;
68 inline bool validTid()
const {
69 return tid != kAllThreadId && tid != kAnyThreadId;
72 inline bool valid()
const {
return validPid() || validTid(); }
74 inline bool any()
const {
return !validPid() && !validTid(); }
76 inline bool all()
const {
return tid == kAllThreadId; }
88typedef std::vector<std::string> StringCollection;
89typedef std::map<std::string, std::string> EnvironmentBlock;
101 Address() : _value(0), _unset(
true) {}
103 Address(uint64_t address) : _value(address), _unset(
false) {}
106 inline operator uint64_t()
const {
return _value; }
107 inline Address &operator=(uint64_t address) {
114 inline bool valid()
const {
return !_unset; }
117 inline uint64_t value()
const {
return _value; }
120 inline void unset() {
124 inline void clear() { unset(); }
141 kReasonWriteWatchpoint,
142 kReasonReadWatchpoint,
143 kReasonAccessWatchpoint,
153 kReasonMemoryAlignment,
155 kReasonInstructionError,
158 kReasonUserException,
168 std::string debugString;
178 inline void clear() {
180 reason = kReasonNone;
187 watchpointAddress = 0;
188 watchpointIndex = -1;
195static uint32_t
const kInvalidCPUType =
static_cast<uint32_t
>(-2);
201 kArchFlagWatchpointExceptionsReceivedAfter = (0 << 0),
202 kArchFlagWatchpointExceptionsReceivedBefore = (1 << 0)
210 CPUSubType cpuSubType;
211 uint32_t nativeCPUType;
212 uint32_t nativeCPUSubType;
213 std::string hostName;
215 std::string osVendor;
217 std::string osKernel;
218 std::string osVersion;
222 uint32_t defaultPacketTimeout;
226 inline void clear() {
227 cpuType = kCPUTypeAny;
228 cpuSubType = kCPUSubTypeInvalid;
229 nativeCPUType = kInvalidCPUType;
230 nativeCPUSubType = kInvalidCPUType;
231 endian = kEndianUnknown;
234 defaultPacketTimeout = 0;
240inline BOOL AllocateAndCopySid(
const PSID pSid, PSID *ppSid)
noexcept {
241 if (!IsValidSid(pSid))
242 return CreateWellKnownSid(WinNullSid,
nullptr, ppSid,
nullptr);
244 UCHAR nSubAuthorityCount = *GetSidSubAuthorityCount(pSid);
245 return AllocateAndInitializeSid(GetSidIdentifierAuthority(pSid),
247 nSubAuthorityCount > 0 ? *GetSidSubAuthority(pSid, 0) : 0,
248 nSubAuthorityCount > 1 ? *GetSidSubAuthority(pSid, 1) : 0,
249 nSubAuthorityCount > 2 ? *GetSidSubAuthority(pSid, 2) : 0,
250 nSubAuthorityCount > 3 ? *GetSidSubAuthority(pSid, 3) : 0,
251 nSubAuthorityCount > 4 ? *GetSidSubAuthority(pSid, 4) : 0,
252 nSubAuthorityCount > 5 ? *GetSidSubAuthority(pSid, 5) : 0,
253 nSubAuthorityCount > 6 ? *GetSidSubAuthority(pSid, 6) : 0,
254 nSubAuthorityCount > 7 ? *GetSidSubAuthority(pSid, 7) : 0,
264 typedef std::vector<ProcessInfo> Collection;
267#if !defined(OS_WIN32)
275#if !defined(OS_WIN32)
277 GroupId effectiveGid;
281 CPUSubType cpuSubType;
282 uint32_t nativeCPUType;
283 uint32_t nativeCPUSubType;
289 std::string osVendor;
293 inline void clear() {
295#if !defined(OS_WIN32)
296 parentPid = kAnyProcessId;
311 cpuType = kCPUTypeAny;
312 cpuSubType = kCPUSubTypeInvalid;
313 nativeCPUType = kInvalidCPUType;
314 nativeCPUSubType = kInvalidCPUType;
315 endian = kEndianUnknown;
325 : pid(other.pid), name(other.name), cpuType(other.cpuType),
326 cpuSubType(other.cpuSubType), nativeCPUType(other.nativeCPUType),
327 nativeCPUSubType(other.nativeCPUSubType), endian(other.endian),
328 pointerSize(other.pointerSize), archFlags(other.archFlags),
329 osType(other.osType), osVendor(other.osVendor) {
337 AllocateAndCopySid(rhs.realUid, &realUid);
338 AllocateAndCopySid(rhs.realGid, &realGid);
339 cpuType = rhs.cpuType;
340 cpuSubType = rhs.cpuSubType;
341 nativeCPUType = rhs.nativeCPUType;
342 nativeCPUSubType = rhs.nativeCPUSubType;
344 pointerSize = rhs.pointerSize;
345 archFlags = rhs.archFlags;
347 osVendor = rhs.osVendor;
362 typedef std::vector<MemoryRegionInfo> Collection;
369 std::string backingFile;
370 uint64_t backingFileOffset;
371 uint64_t backingFileInode;
376 uint64_t protection_, std::string name_) {
380 protection = protection_;
384 inline void clear() {
391 backingFileOffset = 0;
392 backingFileInode = 0;
402 uint64_t baseAddress;
405 std::vector<uint64_t> sections;
410 uint64_t baseAddress;
417 std::string file_path;
418 uint64_t file_offset;