-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support storing and applying of memory content #96
Merged
colin-grant-work
merged 7 commits into
eclipse-cdt-cloud:main
from
eclipsesource:issues/50
Mar 13, 2024
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
281c374
Support storing and applying of memory content
martin-fleck-at 04b97a9
Consider PR feedback
martin-fleck-at 53248da
PR Feedback: Disable store/apply memory buttons if not possible
martin-fleck-at 4b0c003
Further enhancements: Context menu, memory event, PR feedback
martin-fleck-at 83c51b5
Add further PR feedback
martin-fleck-at 175a330
Unify usage of hex address conversion
martin-fleck-at edf986d
Improve address handling and support decimal addresses
martin-fleck-at File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2018 Red Hat, Inc. and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
// inspired by https://github.com/eclipse-theia/theia/blob/master/packages/debug/src/browser/debug-session-connection.ts | ||
|
||
import type { DebugProtocol } from '@vscode/debugprotocol'; | ||
import type { DebugSession } from 'vscode'; | ||
|
||
export interface DebugRequestTypes { | ||
'evaluate': [DebugProtocol.EvaluateArguments, DebugProtocol.EvaluateResponse['body']] | ||
'initialize': [DebugProtocol.InitializeRequestArguments, DebugProtocol.InitializeResponse['body']] | ||
'readMemory': [DebugProtocol.ReadMemoryArguments, DebugProtocol.ReadMemoryResponse['body']] | ||
'scopes': [DebugProtocol.ScopesArguments, DebugProtocol.ScopesResponse['body']] | ||
'variables': [DebugProtocol.VariablesArguments, DebugProtocol.VariablesResponse['body']] | ||
'writeMemory': [DebugProtocol.WriteMemoryArguments, DebugProtocol.WriteMemoryResponse['body']] | ||
} | ||
|
||
export interface DebugEvents { | ||
'memory': DebugProtocol.MemoryEvent, | ||
'stopped': DebugProtocol.StoppedEvent | ||
} | ||
|
||
export type DebugRequest<COMMAND, ARGS> = Omit<DebugProtocol.Request, 'command' | 'arguments'> & { command: COMMAND, arguments: ARGS }; | ||
export type DebugResponse<COMMAND, BODY> = Omit<DebugProtocol.Response, 'command' | 'body'> & { command: COMMAND, body: BODY }; | ||
colin-grant-work marked this conversation as resolved.
Show resolved
Hide resolved
|
||
export type DebugEvent<T> = DebugProtocol.Event & { body: T }; | ||
|
||
export async function sendRequest<K extends keyof DebugRequestTypes>(session: DebugSession, | ||
command: K, args: DebugRequestTypes[K][0]): Promise<DebugRequestTypes[K][1]> { | ||
return session.customRequest(command, args); | ||
} | ||
|
||
export function isDebugVariable(variable: DebugProtocol.Variable | unknown): variable is DebugProtocol.Variable { | ||
const assumed = variable ? variable as DebugProtocol.Variable : undefined; | ||
return typeof assumed?.name === 'string' && typeof assumed?.value === 'string'; | ||
} | ||
|
||
export function isDebugScope(scope: DebugProtocol.Scope | unknown): scope is DebugProtocol.Scope { | ||
const assumed = scope ? scope as DebugProtocol.Scope : undefined; | ||
return typeof assumed?.name === 'string' && typeof assumed?.variablesReference === 'number'; | ||
} | ||
|
||
export function isDebugEvaluateArguments(args: DebugProtocol.EvaluateArguments | unknown): args is DebugProtocol.EvaluateArguments { | ||
const assumed = args ? args as DebugProtocol.EvaluateArguments : undefined; | ||
return typeof assumed?.expression === 'string'; | ||
} | ||
|
||
export function isDebugRequest<K extends keyof DebugRequestTypes>(command: K, message: unknown): message is DebugRequest<K, DebugRequestTypes[K][0]> { | ||
const assumed = message ? message as DebugProtocol.Request : undefined; | ||
return !!assumed && assumed.type === 'request' && assumed.command === command; | ||
} | ||
|
||
export function isDebugResponse<K extends keyof DebugRequestTypes>(command: K, message: unknown): message is DebugResponse<K, DebugRequestTypes[K][1]> { | ||
const assumed = message ? message as DebugProtocol.Response : undefined; | ||
return !!assumed && assumed.type === 'response' && assumed.command === command; | ||
} | ||
|
||
export function isDebugEvent<K extends keyof DebugEvents>(event: K, message: unknown): message is DebugEvents[K] { | ||
const assumed = message ? message as DebugProtocol.Event : undefined; | ||
return !!assumed && assumed.type === 'event' && assumed.event === event; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2024 EclipseSource. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { URI, Utils } from 'vscode-uri'; | ||
|
||
export namespace IntelHEX { | ||
export namespace FileExtensions { | ||
export const All = [ | ||
// General | ||
'hex', 'mcs', 'int', 'ihex', 'ihe', 'ihx', | ||
// Platform-specific | ||
'h80', 'h86', 'a43', 'a90', | ||
// Binary or Intel hex | ||
'obj', 'obl', 'obh', 'rom', 'eep' | ||
]; | ||
export const Default = 'hex'; | ||
|
||
export function applyIfMissing(file: URI): URI { | ||
const extWithDot = Utils.extname(file); | ||
if (extWithDot.length === 0 || !IntelHEX.FileExtensions.All.includes(extWithDot.slice(1))) { | ||
return URI.file(file.fsPath + '.' + IntelHEX.FileExtensions.Default); | ||
} | ||
return file; | ||
}; | ||
}; | ||
export const DialogFilters = { | ||
'Intel HEX Files': IntelHEX.FileExtensions.All, | ||
'All Files': ['*'] | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2024 EclipseSource. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { ReadMemoryArguments, ReadMemoryResult } from './messaging'; | ||
|
||
export interface Memory { | ||
address: bigint; | ||
bytes: Uint8Array; | ||
} | ||
|
||
export function createMemoryFromRead(result: ReadMemoryResult, request?: ReadMemoryArguments): Memory { | ||
if (!result?.data) { | ||
const message = request ? `No memory provided for address ${request.memoryReference}` | ||
+ `, offset ${request.offset} and count ${request.count}!` : 'No memory provided.'; | ||
throw new Error(message); | ||
} | ||
const address = BigInt(result.address); | ||
const bytes = stringToBytesMemory(result.data); | ||
return { bytes, address }; | ||
} | ||
|
||
export function stringToBytesMemory(data: string): Uint8Array { | ||
return Uint8Array.from(Buffer.from(data, 'base64')); | ||
} | ||
|
||
export function bytesToStringMemory(data: Uint8Array): string { | ||
return Buffer.from(data).toString('base64'); | ||
} | ||
|
||
export function validateMemoryReference(reference: string): string | undefined { | ||
const asNumber = Number(reference); | ||
// we allow an address that is not a number, e.g., an expression, but if it is a number it must be >= 0 | ||
return !isNaN(asNumber) && asNumber < 0 ? 'Value must be >= 0' : undefined; | ||
} | ||
|
||
export function validateOffset(offset: string): string | undefined { | ||
const asNumber = Number(offset); | ||
return isNaN(asNumber) ? 'Must be number' : undefined; | ||
} | ||
|
||
export function validateCount(count: string): string | undefined { | ||
const asNumber = Number(count); | ||
if (isNaN(asNumber)) { | ||
return 'Must be number'; | ||
} else if (asNumber <= 0) { | ||
return 'Value must be > 0'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never quite sure what to do with headers in copied code. Feels funny to have a header date older than the repo, though :-).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, that is a very interesting observation! I try to opt for the safest option but this really results in this slight repository paradox. If you want me to change it, let me know or maybe @planger knows whether there are any particular rules for the project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I'd say that you've rewritten fairly thoroughly, so it likely makes sense to put your company and the current date in here.