Skip to content

Commit 99302f5

Browse files
committed
Move ReadMemory/WriteMemory into adapter-capabilities
Since the ReadMemory/WriteMemory may be dependent upon the DAPs, move into the adapter-capabilities.ts file. Signed-off-by: Thor Thayer <thor.thayer@ericsson.com>
1 parent 4aa581b commit 99302f5

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/plugin/adapter-registry/adapter-capabilities.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { DebugProtocol } from '@vscode/debugprotocol';
1818
import * as vscode from 'vscode';
1919
import { isDebugRequest, isDebugResponse } from '../../common/debug-requests';
2020
import { VariableRange } from '../../common/memory-range';
21+
import { ReadMemoryArguments, ReadMemoryResult, WriteMemoryArguments, WriteMemoryResult } from '../../common/messaging';
2122
import { MemoryDisplaySettingsContribution } from '../../common/webview-configuration';
2223
import { Logger } from '../logger';
2324

@@ -35,6 +36,8 @@ export interface AdapterCapabilities {
3536
getMemoryDisplaySettings?(session: vscode.DebugSession): Promise<Partial<MemoryDisplaySettingsContribution>>;
3637
/** Initialize the trackers of this adapter's for the debug session. */
3738
initializeAdapterTracker?(session: vscode.DebugSession): vscode.DebugAdapterTracker | undefined;
39+
readMemory?(session: vscode.DebugSession, params: ReadMemoryArguments): Promise<ReadMemoryResult>;
40+
writeMemory?(session: vscode.DebugSession, params: WriteMemoryArguments): Promise<WriteMemoryResult>;
3841
}
3942

4043
export type WithChildren<Original> = Original & { children?: Array<WithChildren<DebugProtocol.Variable>> };
@@ -135,6 +138,10 @@ export class AdapterVariableTracker implements vscode.DebugAdapterTracker {
135138

136139
/** Resolves the size of a given variable in bytes within the current context. */
137140
getSizeOfVariable?(variableName: string, session: vscode.DebugSession): Promise<bigint | undefined>;
141+
142+
readMemory?(session: vscode.DebugSession, params: ReadMemoryArguments): Promise<ReadMemoryResult>;
143+
144+
writeMemory?(session: vscode.DebugSession, params: WriteMemoryArguments): Promise<WriteMemoryResult>;
138145
}
139146

140147
export class VariableTracker implements AdapterCapabilities {

src/plugin/memory-provider.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ export class MemoryProvider {
4949
}
5050

5151
public async readMemory(args: DebugProtocol.ReadMemoryArguments): Promise<ReadMemoryResult> {
52-
return sendRequest(this.sessionTracker.assertDebugCapability(this.sessionTracker.activeSession, 'supportsReadMemoryRequest', 'read memory'), 'readMemory', args);
52+
const session = this.sessionTracker.assertDebugCapability(this.sessionTracker.activeSession, 'supportsReadMemoryRequest', 'read memory');
53+
const handler = this.adapterRegistry?.getHandlerForSession(session.type);
54+
if (handler?.readMemory) { return handler.readMemory(session, args); }
55+
return sendRequest(session, 'readMemory', args);
5356
}
5457

5558
public async writeMemory(args: DebugProtocol.WriteMemoryArguments): Promise<WriteMemoryResult> {
@@ -63,6 +66,14 @@ export class MemoryProvider {
6366
// if our custom handler is active, let's fire the event ourselves
6467
this.sessionTracker.fireSessionEvent(session, 'memory-written', { memoryReference: args.memoryReference, offset, count });
6568
};
69+
const handler = this.adapterRegistry?.getHandlerForSession(session.type);
70+
if (handler?.writeMemory) {
71+
return handler.writeMemory(session, args).then(response => {
72+
// The memory event is handled before we got here, if the scheduled event still exists, we need to handle it
73+
this.scheduledOnDidMemoryWriteEvents[args.memoryReference]?.(response);
74+
return response;
75+
});
76+
};
6677

6778
return sendRequest(session, 'writeMemory', args).then(response => {
6879
// The memory event is handled before we got here, if the scheduled event still exists, we need to handle it

0 commit comments

Comments
 (0)