Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 40a74f73af16f144bef9f4a567de0fa0655f0268 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*******************************************************************************
 * Copyright (c) 2019 Kichwa Coders and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *******************************************************************************/
package org.eclipse.cdt.debug.dap;

import java.util.Objects;

import org.eclipse.lsp4j.debug.DisassembleArguments;
import org.eclipse.lsp4j.debug.services.IDebugProtocolServer;
import org.eclipse.lsp4j.debug.util.Preconditions;
import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
import org.eclipse.xtext.xbase.lib.Pure;
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;

public class CDTDebugProtocol {

	/**
	 * https://github.com/eclipse-cdt/cdt-gdb-adapter/blob/5d788cbbc6ace142b0930375fcd931b4241eddbb/src/GDBDebugSession.ts#L73
	 * export interface MemoryResponse extends Response {
	 *    body: MemoryContents;
	 * }
	 */
	public static class MemoryRequestResponse {
		@NonNull
		private MemoryContents body;

		@Pure
		@NonNull
		public MemoryContents getBody() {
			return this.body;
		}

		public void setBody(@NonNull final MemoryContents body) {
			this.body = Preconditions.checkNotNull(body, "body"); //$NON-NLS-1$
		}

		@Override
		@Pure
		public String toString() {
			ToStringBuilder b = new ToStringBuilder(this);
			b.add("body", this.body); //$NON-NLS-1$
			return b.toString();
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + ((body == null) ? 0 : body.hashCode());
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			MemoryRequestResponse other = (MemoryRequestResponse) obj;
			if (body == null) {
				if (other.body != null)
					return false;
			} else if (!body.equals(other.body))
				return false;
			return true;
		}
	}

	/**
	 * https://github.com/eclipse-cdt/cdt-gdb-adapter/blob/5d788cbbc6ace142b0930375fcd931b4241eddbb/src/GDBDebugSession.ts#L67
	 * export interface MemoryContents {
	 *     /\* Hex-encoded string of bytes.  *\/
	 *     data: string;
	 *     address: string;
	 * }
	 */
	public static class MemoryContents {
		@NonNull
		private String data;
		@NonNull
		private String address;

		@Pure
		@NonNull
		public String getData() {
			return this.data;
		}

		public void setData(@NonNull final String data) {
			this.data = Preconditions.checkNotNull(data, "data"); //$NON-NLS-1$
		}

		@Pure
		@NonNull
		public String getAddress() {
			return this.address;
		}

		public void setAddress(@NonNull final String address) {
			this.address = Preconditions.checkNotNull(address, "address"); //$NON-NLS-1$
		}

		@Override
		@Pure
		public String toString() {
			ToStringBuilder b = new ToStringBuilder(this);
			b.add("data", this.data); //$NON-NLS-1$
			b.add("address", this.address); //$NON-NLS-1$
			return b.toString();
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + ((address == null) ? 0 : address.hashCode());
			result = prime * result + ((data == null) ? 0 : data.hashCode());
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			MemoryContents other = (MemoryContents) obj;
			if (address == null) {
				if (other.address != null)
					return false;
			} else if (!address.equals(other.address))
				return false;
			if (data == null) {
				if (other.data != null)
					return false;
			} else if (!data.equals(other.data))
				return false;
			return true;
		}
	}

	/**
	 * https://github.com/eclipse-cdt/cdt-gdb-adapter/blob/5d788cbbc6ace142b0930375fcd931b4241eddbb/src/GDBDebugSession.ts#L58
	 * export interface MemoryRequestArguments {
	 *     address: string;
	 *     length: number;
	 *     offset?: number;
	 * }
	 *
	 */
	public static class MemoryRequestArguments {
		@NonNull
		private String address;
		@NonNull
		private Long length;
		private Long offset;

		@Pure
		@NonNull
		public String getAddress() {
			return this.address;
		}

		public void setAddress(@NonNull final String address) {
			this.address = Preconditions.checkNotNull(address, "address"); //$NON-NLS-1$
		}

		@Pure
		@NonNull
		public Long getLength() {
			return this.length;
		}

		public void setLength(@NonNull final Long length) {
			this.length = Preconditions.checkNotNull(length, "length"); //$NON-NLS-1$
		}

		@Pure
		public Long getOffset() {
			return this.offset;
		}

		public void setOffset(final Long offset) {
			this.offset = offset;
		}

		@Override
		@Pure
		public String toString() {
			ToStringBuilder b = new ToStringBuilder(this);
			b.add("address", this.address); //$NON-NLS-1$
			b.add("length", this.length); //$NON-NLS-1$
			b.add("offset", this.offset); //$NON-NLS-1$
			return b.toString();
		}

		@Override
		@Pure
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + ((address == null) ? 0 : address.hashCode());
			result = prime * result + ((length == null) ? 0 : length.hashCode());
			result = prime * result + ((offset == null) ? 0 : offset.hashCode());
			return result;
		}

		@Override
		@Pure
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			MemoryRequestArguments other = (MemoryRequestArguments) obj;
			if (address == null) {
				if (other.address != null)
					return false;
			} else if (!address.equals(other.address))
				return false;
			if (length == null) {
				if (other.length != null)
					return false;
			} else if (!length.equals(other.length))
				return false;
			if (offset == null) {
				if (other.offset != null)
					return false;
			} else if (!offset.equals(other.offset))
				return false;
			return true;
		}
	}

	/**
	 * An extension to standard {@link DisassembleArguments} that can
	 * be passed to {@link IDebugProtocolServer#disassemble(DisassembleArguments)}
	 *
	 * When endMemoryReference is provided, the disassemble command will return
	 * the minimum number of instructions to get to the end address or number
	 * of lines (instructionCount), whichever is smaller.
	 */
	public static class CDTDisassembleArguments extends DisassembleArguments {

		private String endMemoryReference;

		@Pure
		public String getEndMemoryReference() {
			return this.endMemoryReference;
		}

		public void setEndMemoryReference(final String endMemoryReference) {
			this.endMemoryReference = endMemoryReference;
		}

		@Override
		@Pure
		public String toString() {
			ToStringBuilder b = new ToStringBuilder(this);
			b.add("memoryReference", this.getMemoryReference()); //$NON-NLS-1$
			b.add("offset", this.getOffset()); //$NON-NLS-1$
			b.add("instructionOffset", this.getInstructionOffset()); //$NON-NLS-1$
			b.add("instructionCount", this.getInstructionCount()); //$NON-NLS-1$
			b.add("resolveSymbols", this.getResolveSymbols()); //$NON-NLS-1$
			b.add("endMemoryReference", this.endMemoryReference); //$NON-NLS-1$
			return b.toString();
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = super.hashCode();
			result = prime * result + Objects.hash(endMemoryReference);
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (!super.equals(obj))
				return false;
			if (getClass() != obj.getClass())
				return false;
			CDTDisassembleArguments other = (CDTDisassembleArguments) obj;
			return Objects.equals(endMemoryReference, other.endMemoryReference);
		}
	}
}

Back to the top