Skip to content

Commit

Permalink
Introduce scheduled onDidMemoryWriteEvent after write operations
Browse files Browse the repository at this point in the history
  • Loading branch information
haydar-metin committed Mar 21, 2024
1 parent 70a9c01 commit d69eeb6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
27 changes: 13 additions & 14 deletions src/plugin/memory-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ export class MemoryProvider {

protected readonly sessionDebugCapabilities = new Map<string, DebugProtocol.Capabilities | undefined>();
protected readonly sessionClientCapabilities = new Map<string, DebugProtocol.InitializeRequestArguments | undefined>();

/**
* Debug adapters can use the 'memory' event to indicate that the contents of a memory range has changed due to some request but do not specify which requests.
* We therefore track explicitly whether the debug adapter actually sends 'memory' events to know whether we should mimic the event ourselves.
*/
protected adapterSupportsMemoryEvent = false;
protected scheduledOnDidMemoryWriteEvents: { [memoryReference: string]: ((response: WriteMemoryResult) => void) | undefined } = {};

constructor(protected adapterRegistry: AdapterRegistry) {
}
Expand Down Expand Up @@ -76,7 +71,7 @@ export class MemoryProvider {
} else if (isDebugEvent('stopped', message)) {
this._onDidStopDebug.fire(session);
} else if (isDebugEvent('memory', message)) {
this.adapterSupportsMemoryEvent = true;
delete this.scheduledOnDidMemoryWriteEvents[message.body.memoryReference];
this._onDidWriteMemory.fire(message.body);
}
contributedTracker?.onDidSendMessage?.(message);
Expand Down Expand Up @@ -154,14 +149,18 @@ export class MemoryProvider {

public async writeMemory(args: DebugProtocol.WriteMemoryArguments): Promise<WriteMemoryResult> {
const session = this.assertCapability('supportsWriteMemoryRequest', 'write memory');
// Schedule a emit in case we don't retrieve a memory event
this.scheduledOnDidMemoryWriteEvents[args.memoryReference] = response => {
// We only send out a custom event if we don't expect the client to handle the memory event
// since our client is VS Code we can assume that they will always support this but better to be safe
const offset = response?.offset ? (args.offset ?? 0) + response.offset : args.offset;
const count = response?.bytesWritten ?? stringToBytesMemory(args.data).length;
this._onDidWriteMemory.fire({ memoryReference: args.memoryReference, offset, count });
};

return sendRequest(session, 'writeMemory', args).then(response => {
if (!this.adapterSupportsMemoryEvent || !this.hasClientCapabilitiy(session, 'supportsMemoryEvent')) {
// we only send out a custom event if we don't expect the client to handle the memory event
// since our client is VS Code we can assume that they will always support this but better to be safe
const offset = response?.offset ? (args.offset ?? 0) + response.offset : args.offset;
const count = response?.bytesWritten ?? stringToBytesMemory(args.data).length;
this._onDidWriteMemory.fire({ memoryReference: args.memoryReference, offset, count });
}
// The memory event is handled before we got here, if the scheduled event still exists, we need to handle it
this.scheduledOnDidMemoryWriteEvents[args.memoryReference]?.(response);
return response;
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/webview/columns/data-column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export class EditableDataColumnRow extends React.Component<EditableDataColumnRow
const characters = toOffset(editedRange.startAddress, editedRange.endAddress, this.props.options.bytesPerWord * 8) * 2;
// Revert Endianness
if (this.props.options.endianness === Endianness.Little) {
const chunks = data.padStart(characters, '0').match(/.{1,2}/g) || [];
const chunks = data.padStart(characters, '0').match(/.{2}/g) || [];
return chunks.reverse().join('');
}

Expand Down

0 comments on commit d69eeb6

Please sign in to comment.