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
17#include <vector>
18
19namespace ds2 {
20namespace Host {
21namespace Linux {
22
23struct PTracePrivateData;
24
25class PTrace : public POSIX::PTrace {
26public:
27 ErrorCode wait(ProcessThreadId const &ptid, int *status = nullptr) override;
28
29public:
30 ErrorCode traceMe(bool disableASLR) override;
31 ErrorCode traceThat(ProcessId pid) override;
32
33public:
34 ErrorCode kill(ProcessThreadId const &ptid, int signal) override;
35
36protected:
37 virtual ErrorCode readBytes(ProcessThreadId const &ptid,
38 Address const &address, void *buffer,
39 size_t length, size_t *count, bool nullTerm);
40
41public:
42 ErrorCode readString(ProcessThreadId const &ptid, Address const &address,
43 std::string &str, size_t length,
44 size_t *count = nullptr) override;
45 ErrorCode readMemory(ProcessThreadId const &ptid, Address const &address,
46 void *buffer, size_t length,
47 size_t *count = nullptr) override;
48 ErrorCode writeMemory(ProcessThreadId const &ptid, Address const &address,
49 void const *buffer, size_t length,
50 size_t *count = nullptr) override;
51
52public:
53 ErrorCode readCPUState(ProcessThreadId const &ptid, ProcessInfo const &pinfo,
54 Architecture::CPUState &state) override;
55 ErrorCode writeCPUState(ProcessThreadId const &ptid, ProcessInfo const &pinfo,
56 Architecture::CPUState const &state) override;
57
58private:
59 ErrorCode prepareAddressForResume(ProcessThreadId const &ptid,
60 ProcessInfo const &pinfo,
61 Address const &address);
62
63public:
64 ErrorCode step(ProcessThreadId const &ptid, ProcessInfo const &pinfo,
65 int signal = 0, Address const &address = Address()) override;
66 ErrorCode resume(ProcessThreadId const &ptid, ProcessInfo const &pinfo,
67 int signal = 0, Address const &address = Address()) override;
68
69public:
70 ErrorCode getSigInfo(ProcessThreadId const &ptid, siginfo_t &si) override;
71 ErrorCode getEventMessage(ProcessThreadId const &ptid, unsigned long &data);
72
73protected:
74 virtual ErrorCode readRegisterSet(ProcessThreadId const &ptid, int regSetCode,
75 void *buffer, size_t length);
76 virtual ErrorCode writeRegisterSet(ProcessThreadId const &ptid,
77 int regSetCode, void const *buffer,
78 size_t length);
79
80#if defined(ARCH_X86) || defined(ARCH_X86_64)
81protected:
82 uintptr_t readUserData(ProcessThreadId const &ptid, uint64_t offset);
83 ErrorCode writeUserData(ProcessThreadId const &ptid, uint64_t offset,
84 uintptr_t val);
85#endif
86
87// Debug register ptrace APIs only exist for Linux ARM
88#if defined(ARCH_ARM) || defined(ARCH_ARM64)
89public:
90 int getMaxHardwareBreakpoints(ProcessThreadId const &ptid) override;
91 int getMaxHardwareWatchpoints(ProcessThreadId const &ptid) override;
92#endif
93
94#if defined(ARCH_ARM)
95protected:
96 uint32_t getStoppointData(ProcessThreadId const &ptid);
97
98public:
99 int getMaxWatchpointSize(ProcessThreadId const &ptid) override;
100
101protected:
102 ErrorCode writeStoppoint(ProcessThreadId const &ptid, size_t idx,
103 uint32_t *val);
104
105public:
106 ErrorCode writeHardwareBreakpoint(ProcessThreadId const &ptid, uint32_t addr,
107 uint32_t ctrl, size_t idx) override;
108 ErrorCode writeHardwareWatchpoint(ProcessThreadId const &ptid, uint32_t addr,
109 uint32_t ctrl, size_t idx) override;
110#endif
111
112#if defined(ARCH_ARM64)
113protected:
114 int getMaxStoppoints(ProcessThreadId const &ptid, int regSet);
115
116public:
117 // Reads/writes the DBGWVRn_EL1/DBGWCRn_EL1 hardware watchpoint value/control
118 // register pairs (accessed via PTRACE_GETREGSET/SETREGSET with
119 // NT_ARM_HW_WATCH, i.e. `struct user_hwdebug_state`), one entry per
120 // hardware-supported watchpoint slot. `addresses`/`controls` are resized by
121 // readHardwareWatchpointControl() to the number of watchpoint slots the
122 // target actually supports (as reported by dbg_info), which callers should
123 // treat as the authoritative slot count instead of assuming a fixed value.
124 ErrorCode readHardwareWatchpointControl(ProcessThreadId const &ptid,
125 std::vector<uint64_t> &addresses,
126 std::vector<uint32_t> &controls);
127 ErrorCode
128 writeHardwareWatchpointControl(ProcessThreadId const &ptid,
129 std::vector<uint64_t> const &addresses,
130 std::vector<uint32_t> const &controls);
131#endif
132};
133} // namespace Linux
134} // namespace Host
135} // namespace ds2
Definition Types.h:96
Definition PTrace.h:25
Definition PTrace.h:28
Definition Types.h:281
Definition Types.h:58