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