DebugServer2
Loading...
Searching...
No Matches
PTrace.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/Architecture/CPUState.h"
14#include "DebugServer2/Host/POSIX/PTrace.h"
15#include "DebugServer2/Utils/Log.h"
16
17namespace ds2 {
18namespace Host {
19namespace Linux {
20
21struct PTracePrivateData;
22
23class PTrace : public POSIX::PTrace {
24public:
25 ErrorCode wait(ProcessThreadId const &ptid, int *status = nullptr) override;
26
27public:
28 ErrorCode traceMe(bool disableASLR) override;
29 ErrorCode traceThat(ProcessId pid) override;
30
31public:
32 ErrorCode kill(ProcessThreadId const &ptid, int signal) override;
33
34protected:
35 virtual ErrorCode readBytes(ProcessThreadId const &ptid,
36 Address const &address, void *buffer,
37 size_t length, size_t *count, bool nullTerm);
38
39public:
40 ErrorCode readString(ProcessThreadId const &ptid, Address const &address,
41 std::string &str, size_t length,
42 size_t *count = nullptr) override;
43 ErrorCode readMemory(ProcessThreadId const &ptid, Address const &address,
44 void *buffer, size_t length,
45 size_t *count = nullptr) override;
46 ErrorCode writeMemory(ProcessThreadId const &ptid, Address const &address,
47 void const *buffer, size_t length,
48 size_t *count = nullptr) override;
49
50public:
51 ErrorCode readCPUState(ProcessThreadId const &ptid, ProcessInfo const &pinfo,
52 Architecture::CPUState &state) override;
53 ErrorCode writeCPUState(ProcessThreadId const &ptid, ProcessInfo const &pinfo,
54 Architecture::CPUState const &state) override;
55
56private:
57 ErrorCode prepareAddressForResume(ProcessThreadId const &ptid,
58 ProcessInfo const &pinfo,
59 Address const &address);
60
61public:
62 ErrorCode step(ProcessThreadId const &ptid, ProcessInfo const &pinfo,
63 int signal = 0, Address const &address = Address()) override;
64 ErrorCode resume(ProcessThreadId const &ptid, ProcessInfo const &pinfo,
65 int signal = 0, Address const &address = Address()) override;
66
67public:
68 ErrorCode getSigInfo(ProcessThreadId const &ptid, siginfo_t &si) override;
69 ErrorCode getEventMessage(ProcessThreadId const &ptid, unsigned long &data);
70
71protected:
72 virtual ErrorCode readRegisterSet(ProcessThreadId const &ptid, int regSetCode,
73 void *buffer, size_t length);
74 virtual ErrorCode writeRegisterSet(ProcessThreadId const &ptid,
75 int regSetCode, void const *buffer,
76 size_t length);
77
78#if defined(ARCH_X86) || defined(ARCH_X86_64)
79protected:
80 uintptr_t readUserData(ProcessThreadId const &ptid, uint64_t offset);
81 ErrorCode writeUserData(ProcessThreadId const &ptid, uint64_t offset,
82 uintptr_t val);
83#endif
84
85// Debug register ptrace APIs only exist for Linux ARM
86#if defined(ARCH_ARM) || defined(ARCH_ARM64)
87public:
88 int getMaxHardwareBreakpoints(ProcessThreadId const &ptid) override;
89 int getMaxHardwareWatchpoints(ProcessThreadId const &ptid) override;
90#endif
91
92#if defined(ARCH_ARM)
93protected:
94 uint32_t getStoppointData(ProcessThreadId const &ptid);
95
96public:
97 int getMaxWatchpointSize(ProcessThreadId const &ptid) override;
98
99protected:
100 ErrorCode writeStoppoint(ProcessThreadId const &ptid, size_t idx,
101 uint32_t *val);
102
103public:
104 ErrorCode writeHardwareBreakpoint(ProcessThreadId const &ptid, uint32_t addr,
105 uint32_t ctrl, size_t idx) override;
106 ErrorCode writeHardwareWatchpoint(ProcessThreadId const &ptid, uint32_t addr,
107 uint32_t ctrl, size_t idx) override;
108#endif
109
110#if defined(ARCH_ARM64)
111protected:
112 int getMaxStoppoints(ProcessThreadId const &ptid, int regSet);
113#endif
114};
115} // namespace Linux
116} // namespace Host
117} // namespace ds2
Definition Types.h:95
Definition PTrace.h:23
Definition PTrace.h:28
Definition Types.h:263
Definition Types.h:57