DebugServer2
Loading...
Searching...
No Matches
Mach.h
1//
2// Copyright (c) 2015 Corentin Derbois <cderbois@gmail.com>
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/Architecture/CPUState.h"
14
15#include <mach/mach.h>
16#include <mach/mach_vm.h>
17#include <mach/thread_info.h>
18#include <sys/types.h>
19
20namespace ds2 {
21namespace Host {
22namespace Darwin {
23
24class Mach {
25public:
26 virtual ~Mach() = default;
27
28public:
29 ErrorCode readMemory(ProcessThreadId const &ptid, Address const &address,
30 void *buffer, size_t length, size_t *nread = nullptr);
31 ErrorCode writeMemory(ProcessThreadId const &ptid, Address const &address,
32 void const *buffer, size_t length,
33 size_t *nwritten = nullptr);
34
35public:
36 // Flushes the instruction cache (and unifies it with the data cache) for
37 // `address`..+`length` in `ptid`'s address space. Needed after writing
38 // executable code into another process on architectures where
39 // instruction fetches aren't automatically coherent with data writes
40 // (e.g. AArch64 -- unlike x86, which guarantees this in hardware).
41 ErrorCode flushInstructionCache(ProcessThreadId const &ptid,
42 Address const &address, size_t length);
43
44public:
45 ErrorCode readCPUState(ProcessThreadId const &ptid, ProcessInfo const &info,
46 Architecture::CPUState &state);
47 ErrorCode writeCPUState(ProcessThreadId const &ptid, ProcessInfo const &info,
48 Architecture::CPUState const &state);
49
50public:
51 ErrorCode suspend(ProcessThreadId const &ptid);
52
53public:
54 ErrorCode step(ProcessThreadId const &ptid, ProcessInfo const &pinfo,
55 int signal = 0, Address const &address = Address());
56 ErrorCode resume(ProcessThreadId const &ptid, ProcessInfo const &pinfo,
57 int signal = 0, Address const &address = Address());
58
59public:
60 // AArch64-only: arms/disarms the MDSCR_EL1.SS hardware single-step trap.
61 // Implemented in MachARM64.cpp; unused (and undefined) on other
62 // architectures, which single-step through other means.
63 ErrorCode setSingleStep(ProcessThreadId const &ptid, bool enable);
64
65public:
66 ErrorCode getProcessDylbInfo(ProcessId pid, Address &address);
67 ErrorCode getProcessMemoryRegion(ProcessId pid, Address const &address,
68 MemoryRegionInfo &info);
69
70public:
71 ErrorCode getThreadInfo(ProcessThreadId const &tid, thread_basic_info_t info);
72 ErrorCode getThreadIdentifierInfo(ProcessThreadId const &tid,
73 thread_identifier_info_data_t *threadID);
74
75private:
76 task_t getMachTask(ProcessId pid);
77 thread_t getMachThread(ProcessThreadId const &tid);
78};
79} // namespace Darwin
80} // namespace Host
81} // namespace ds2
Definition Types.h:95
Definition Mach.h:24
Definition Types.h:361
Definition Types.h:263
Definition Types.h:57