DebugServer2
Loading...
Searching...
No Matches
DebugSessionImpl.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/GDBRemote/DummySessionDelegateImpl.h"
14#include "DebugServer2/GDBRemote/Mixins/FileOperationsMixin.h"
15#include "DebugServer2/Host/ProcessSpawner.h"
16#include "DebugServer2/Target/Process.h"
17#include "DebugServer2/Target/Thread.h"
18#include "DebugServer2/Utils/MPL.h"
19
20#include <mutex>
21
22namespace ds2 {
23namespace GDBRemote {
25protected:
26 Target::Process *_process;
27 std::vector<int> _programmedSignals;
28 std::map<uint64_t, size_t> _allocations;
29 std::map<uint64_t, Architecture::CPUState> _savedRegisters;
30 Host::ProcessSpawner _spawner;
31
32protected:
33 // a struct to help iterate over the thread list for onQueryThreadList
34 mutable IterationState<ThreadId> _threadIterationState;
35
36protected:
37 std::mutex _resumeSessionLock;
38 Session *_resumeSession;
39 std::string _consoleBuffer;
40
41public:
42 DebugSessionImplBase(StringCollection const &args,
43 EnvironmentBlock const &env);
44 DebugSessionImplBase(int attachPid);
46 ~DebugSessionImplBase() override;
47
48protected:
49 size_t getGPRSize() const override;
50
51protected:
52 ErrorCode onInterrupt(Session &session) override;
53
54protected:
55 ErrorCode onQuerySupported(Session &session,
56 Feature::Collection const &remoteFeatures,
57 Feature::Collection &localFeatures) const override;
58 ErrorCode onPassSignals(Session &session,
59 std::vector<int> const &signals) override;
60 ErrorCode onProgramSignals(Session &session,
61 std::vector<int> const &signals) override;
62 ErrorCode onNonStopMode(Session &session, bool enable) override;
63 ErrorCode onSendInput(Session &session, ByteVector const &buf) override;
64
65protected:
66 ErrorCode onQueryCurrentThread(Session &session,
67 ProcessThreadId &ptid) const override;
68 ErrorCode onThreadIsAlive(Session &session,
69 ProcessThreadId const &ptid) override;
70 ErrorCode onQueryAttached(Session &session, ProcessId pid,
71 bool &attachedProcess) const override;
72 ErrorCode onQueryProcessInfo(Session &session,
73 ProcessInfo &info) const override;
74 ErrorCode onQueryHardwareWatchpointCount(Session &session,
75 size_t &count) const override;
76 ErrorCode onQueryThreadStopInfo(Session &session, ProcessThreadId const &ptid,
77 StopInfo &stop) const override;
78
79 ErrorCode onQueryThreadList(Session &session, ProcessId pid, ThreadId lastTid,
80 ThreadId &tid) const override;
81
82 ErrorCode onQueryFileLoadAddress(Session &session,
83 std::string const &file_path,
84 Address &address) override;
85
86protected:
87 ErrorCode onQueryRegisterInfo(Session &session, uint32_t regno,
88 RegisterInfo &info) const override;
89
90protected:
91 ErrorCode onQuerySharedLibrariesInfoAddress(Session &session,
92 Address &address) const override;
93
94protected:
95 ErrorCode onXferRead(Session &session, std::string const &object,
96 std::string const &annex, uint64_t offset,
97 uint64_t length, std::string &buffer,
98 bool &last) override;
99
100protected:
101 ErrorCode onSetStdFile(Session &session, int fileno,
102 std::string const &path) override;
103
104protected:
105 ErrorCode
106 onReadGeneralRegisters(Session &session, ProcessThreadId const &ptid,
107 Architecture::GPRegisterValueVector &regs) override;
108 ErrorCode onWriteGeneralRegisters(Session &session,
109 ProcessThreadId const &ptid,
110 std::vector<uint64_t> const &regs) override;
111
112 ErrorCode onSaveRegisters(Session &session, ProcessThreadId const &ptid,
113 uint64_t &id) override;
114 ErrorCode onRestoreRegisters(Session &session, ProcessThreadId const &ptid,
115 uint64_t id) override;
116
117 ErrorCode onReadRegisterValue(Session &session, ProcessThreadId const &ptid,
118 uint32_t regno, std::string &value) override;
119 ErrorCode onWriteRegisterValue(Session &session, ProcessThreadId const &ptid,
120 uint32_t regno,
121 std::string const &value) override;
122
123protected:
124 ErrorCode onReadMemory(Session &session, Address const &address,
125 size_t length, ByteVector &data) override;
126 ErrorCode onWriteMemory(Session &session, Address const &address,
127 ByteVector const &data, size_t &nwritten) override;
128
129 ErrorCode onAllocateMemory(Session &session, size_t size,
130 uint32_t permissions, Address &address) override;
131 ErrorCode onDeallocateMemory(Session &session,
132 Address const &address) override;
133
134 ErrorCode onQueryMemoryRegionInfo(Session &session, Address const &address,
135 MemoryRegionInfo &info) const override;
136
137protected:
138 ErrorCode onSetEnvironmentVariable(Session &session, std::string const &name,
139 std::string const &value) override;
140 ErrorCode onSetProgramArguments(Session &session,
141 StringCollection const &args) override;
142 ErrorCode onQueryLaunchSuccess(Session &session,
143 ProcessId pid) const override;
144
145protected:
146 ErrorCode onAttach(Session &session, ProcessId pid, AttachMode mode,
147 StopInfo &stop) override;
148 ErrorCode onRunAttach(Session &session, std::string const &filename,
149 StringCollection const &arguments,
150 StopInfo &stop) override;
151
152protected:
153 ErrorCode onResume(Session &session,
154 ThreadResumeAction::Collection const &actions,
155 StopInfo &stop) override;
156 ErrorCode onTerminate(Session &session, ProcessThreadId const &ptid,
157 StopInfo &stop) override;
158 ErrorCode onDetach(Session &session, ProcessId pid, bool stopped) override;
159 ErrorCode onExitServer(Session &session) override;
160
161protected:
162 ErrorCode onInsertBreakpoint(Session &session, BreakpointType type,
163 Address const &address, uint32_t size,
164 StringCollection const &conditions,
165 StringCollection const &commands,
166 bool persistentCommands) override;
167 ErrorCode onRemoveBreakpoint(Session &session, BreakpointType type,
168 Address const &address, uint32_t kind) override;
169
170protected:
171 Target::Thread *findThread(ProcessThreadId const &ptid) const;
172 ErrorCode queryStopInfo(Session &session, Target::Thread *thread,
173 StopInfo &stop) const;
174 ErrorCode queryStopInfo(Session &session, ProcessThreadId const &ptid,
175 StopInfo &stop) const;
176
177protected:
178 ErrorCode fetchStopInfoForAllThreads(Session &session,
179 std::vector<StopInfo> &stops,
180 StopInfo &processStop) override;
181 ErrorCode createThreadsStopInfo(Session &session,
182 JSArray &threadsStopInfo) override;
183
184private:
185 ErrorCode spawnProcess(StringCollection const &args,
186 EnvironmentBlock const &env);
187 void appendOutput(char const *buf, size_t size);
188};
189
190using DebugSessionImpl =
192} // namespace GDBRemote
193} // namespace ds2
Definition Types.h:95
Definition DebugSessionImpl.h:24
Definition DummySessionDelegateImpl.h:20
Definition Session.h:22
Definition ProcessSpawner.h:20
Definition MPL.h:18
Definition Types.h:220
Definition Types.h:179
Definition Types.h:23
Definition Types.h:123
Definition Types.h:38