13#include "DebugServer2/Base.h"
14#include "DebugServer2/Constants.h"
15#include "DebugServer2/Core/CPUTypes.h"
16#include "DebugServer2/Core/ErrorCodes.h"
35typedef DWORD ProcessId;
36typedef DWORD ThreadId;
41typedef pid_t ProcessId;
42typedef pid_t ThreadId;
48static const ProcessId kAllProcessId =
static_cast<ProcessId
>(-1);
49static const ProcessId kAnyProcessId =
static_cast<ProcessId
>(0);
50static const ThreadId kAllThreadId =
static_cast<ThreadId
>(-1);
51static const ThreadId kAnyThreadId =
static_cast<ThreadId
>(0);
53typedef std::vector<uint8_t> ByteVector;
62 ProcessThreadId(ProcessId _pid = kAnyProcessId, ThreadId _tid = kAnyThreadId)
63 : pid(_pid), tid(_tid) {}
65 inline bool validPid()
const {
66 return pid != kAllProcessId && pid != kAnyProcessId;
69 inline bool validTid()
const {
70 return tid != kAllThreadId && tid != kAnyThreadId;
73 inline bool valid()
const {
return validPid() || validTid(); }
75 inline bool any()
const {
return !validPid() && !validTid(); }
77 inline bool all()
const {
return tid == kAllThreadId; }
89typedef std::vector<std::string> StringCollection;
90typedef std::map<std::string, std::string> EnvironmentBlock;
102 Address() : _value(0), _unset(
true) {}
104 Address(uint64_t address) : _value(address), _unset(
false) {}
107 inline operator uint64_t()
const {
return _value; }
108 inline Address &operator=(uint64_t address) {
115 inline bool valid()
const {
return !_unset; }
118 inline uint64_t value()
const {
return _value; }
121 inline void unset() {
125 inline void clear() { unset(); }
142 kReasonWriteWatchpoint,
143 kReasonReadWatchpoint,
144 kReasonAccessWatchpoint,
157 kReasonMemoryAlignment,
159 kReasonInstructionError,
162 kReasonUserException,
172 std::string debugString;
184 std::optional<Address> fault;
194 inline void clear() {
196 reason = kReasonNone;
203 watchpointAddress = 0;
204 watchpointIndex = -1;
213static uint32_t
const kInvalidCPUType =
static_cast<uint32_t
>(-2);
219 kArchFlagWatchpointExceptionsReceivedAfter = (0 << 0),
220 kArchFlagWatchpointExceptionsReceivedBefore = (1 << 0)
228 CPUSubType cpuSubType;
229 uint32_t nativeCPUType;
230 uint32_t nativeCPUSubType;
231 std::string hostName;
233 std::string osVendor;
235 std::string osKernel;
236 std::string osVersion;
240 uint32_t defaultPacketTimeout;
244 inline void clear() {
245 cpuType = kCPUTypeAny;
246 cpuSubType = kCPUSubTypeInvalid;
247 nativeCPUType = kInvalidCPUType;
248 nativeCPUSubType = kInvalidCPUType;
249 endian = kEndianUnknown;
252 defaultPacketTimeout = 0;
258inline BOOL AllocateAndCopySid(
const PSID pSid, PSID *ppSid)
noexcept {
259 if (!IsValidSid(pSid))
260 return CreateWellKnownSid(WinNullSid,
nullptr, ppSid,
nullptr);
262 UCHAR nSubAuthorityCount = *GetSidSubAuthorityCount(pSid);
263 return AllocateAndInitializeSid(GetSidIdentifierAuthority(pSid),
265 nSubAuthorityCount > 0 ? *GetSidSubAuthority(pSid, 0) : 0,
266 nSubAuthorityCount > 1 ? *GetSidSubAuthority(pSid, 1) : 0,
267 nSubAuthorityCount > 2 ? *GetSidSubAuthority(pSid, 2) : 0,
268 nSubAuthorityCount > 3 ? *GetSidSubAuthority(pSid, 3) : 0,
269 nSubAuthorityCount > 4 ? *GetSidSubAuthority(pSid, 4) : 0,
270 nSubAuthorityCount > 5 ? *GetSidSubAuthority(pSid, 5) : 0,
271 nSubAuthorityCount > 6 ? *GetSidSubAuthority(pSid, 6) : 0,
272 nSubAuthorityCount > 7 ? *GetSidSubAuthority(pSid, 7) : 0,
282 typedef std::vector<ProcessInfo> Collection;
285#if !defined(OS_WIN32)
293#if !defined(OS_WIN32)
295 GroupId effectiveGid;
299 CPUSubType cpuSubType;
300 uint32_t nativeCPUType;
301 uint32_t nativeCPUSubType;
307 std::string osVendor;
311 inline void clear() {
313#if !defined(OS_WIN32)
314 parentPid = kAnyProcessId;
329 cpuType = kCPUTypeAny;
330 cpuSubType = kCPUSubTypeInvalid;
331 nativeCPUType = kInvalidCPUType;
332 nativeCPUSubType = kInvalidCPUType;
333 endian = kEndianUnknown;
343 : pid(other.pid), name(other.name), cpuType(other.cpuType),
344 cpuSubType(other.cpuSubType), nativeCPUType(other.nativeCPUType),
345 nativeCPUSubType(other.nativeCPUSubType), endian(other.endian),
346 pointerSize(other.pointerSize), archFlags(other.archFlags),
347 osType(other.osType), osVendor(other.osVendor) {
355 AllocateAndCopySid(rhs.realUid, &realUid);
356 AllocateAndCopySid(rhs.realGid, &realGid);
357 cpuType = rhs.cpuType;
358 cpuSubType = rhs.cpuSubType;
359 nativeCPUType = rhs.nativeCPUType;
360 nativeCPUSubType = rhs.nativeCPUSubType;
362 pointerSize = rhs.pointerSize;
363 archFlags = rhs.archFlags;
365 osVendor = rhs.osVendor;
380 typedef std::vector<MemoryRegionInfo> Collection;
387 std::string backingFile;
388 uint64_t backingFileOffset;
389 uint64_t backingFileInode;
394 uint64_t protection_, std::string name_) {
398 protection = protection_;
402 inline void clear() {
409 backingFileOffset = 0;
410 backingFileInode = 0;
420 uint64_t baseAddress;
423 std::vector<uint64_t> sections;
428 uint64_t baseAddress;
435 std::string file_path;
436 uint64_t file_offset;