-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add Debug Context Selector #133
Open
WyoTwT
wants to merge
4
commits into
eclipse-cdt-cloud:main
Choose a base branch
from
WyoTwT:tt_add_child_selector
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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,114 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2024 Ericsson, Arm 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 | ||
********************************************************************************/ | ||
|
||
import { DebugProtocol } from '@vscode/debugprotocol'; | ||
import * as vscode from 'vscode'; | ||
import { ConnectionContext, ReadMemoryArguments, ReadMemoryResult, WriteMemoryArguments, WriteMemoryResult } from '../../common/messaging'; | ||
import { AdapterCapabilities, AdapterVariableTracker, VariableTracker } from './adapter-capabilities'; | ||
|
||
// Copied from cdt-amalgamator [AmalgamatorSession.d.ts] file | ||
/** | ||
* Response for our custom 'cdt-amalgamator/getChildDaps' request. | ||
*/ | ||
export interface ConnectionContexts { | ||
children?: ConnectionContext[]; | ||
} | ||
export interface GetContextsResponse extends DebugProtocol.Response { | ||
body: ConnectionContexts; | ||
} | ||
export type GetContextsResult = GetContextsResponse['body']; | ||
|
||
export interface AmalgamatorReadArgs extends ReadMemoryArguments { | ||
child: ConnectionContext; | ||
} | ||
|
||
export class AmalgamatorSessionManager extends VariableTracker implements AdapterCapabilities { | ||
async getConnectionContexts(session: vscode.DebugSession): Promise<ConnectionContext[]> { | ||
return this.sessions.get(session.id)?.getConnectionContexts?.(session) || []; | ||
} | ||
|
||
async readMemory(session: vscode.DebugSession, args: ReadMemoryArguments, context: ConnectionContext): Promise<ReadMemoryResult> { | ||
if (!context) { | ||
vscode.window.showErrorMessage('Invalid context for Amalgamator. Select Context in Dropdown'); | ||
return { | ||
address: args.memoryReference | ||
}; | ||
} | ||
return this.sessions.get(session.id)?.readMemory?.(session, args, context); | ||
} | ||
|
||
async writeMemory(session: vscode.DebugSession, args: WriteMemoryArguments, context: ConnectionContext): Promise<WriteMemoryResult> { | ||
return this.sessions.get(session.id)?.writeMemory?.(session, args, context); | ||
} | ||
|
||
async getCurrentConnectionContext(session: vscode.DebugSession): Promise<ConnectionContext | undefined> { | ||
return this.sessions.get(session.id)?.getCurrentConnectionContext?.(session); | ||
} | ||
} | ||
|
||
export class AmalgamatorGdbVariableTransformer extends AdapterVariableTracker { | ||
protected connectionContexts?: ConnectionContext[]; | ||
protected currentConnectionContext?: ConnectionContext; | ||
|
||
onWillReceiveMessage(message: unknown): void { | ||
if (isStacktraceRequest(message)) { | ||
if (typeof (message.arguments.threadId) !== 'undefined') { | ||
this.currentConnectionContext = { | ||
id: message.arguments.threadId, | ||
name: message.arguments.threadId.toString() | ||
}; | ||
} else { | ||
this.logger.warn('Invalid ThreadID in stackTrace'); | ||
this.currentConnectionContext = undefined; | ||
} | ||
} else { | ||
super.onWillReceiveMessage(message); | ||
} | ||
} | ||
|
||
get frame(): number | undefined { return this.currentFrame; } | ||
|
||
async getConnectionContexts(session: vscode.DebugSession): Promise<ConnectionContext[]> { | ||
if (!this.connectionContexts) { | ||
const contexts: GetContextsResult = (await session.customRequest('cdt-amalgamator/getChildDaps')); | ||
this.connectionContexts = contexts.children?.map(({ name, id }) => ({ name, id })) ?? []; | ||
} | ||
return Promise.resolve(this.connectionContexts); | ||
} | ||
|
||
async getCurrentConnectionContext(_session: vscode.DebugSession): Promise<ConnectionContext | undefined> { | ||
const curConnectionContext = this.connectionContexts?.length ? | ||
(this.connectionContexts?.filter(context => context.id === this.currentConnectionContext?.id).shift() ?? | ||
this.currentConnectionContext) : | ||
this.currentConnectionContext; | ||
return Promise.resolve(curConnectionContext); | ||
} | ||
|
||
readMemory(session: vscode.DebugSession, args: ReadMemoryArguments, context: ConnectionContext): Promise<ReadMemoryResult> { | ||
const amalReadArgs: AmalgamatorReadArgs = { ...args, child: context }; | ||
return Promise.resolve(session.customRequest('cdt-amalgamator/readMemory', amalReadArgs)); | ||
} | ||
} | ||
|
||
export function isStacktraceRequest(message: unknown): message is DebugProtocol.StackTraceRequest { | ||
const candidate = message as DebugProtocol.StackTraceRequest; | ||
return !!candidate && candidate.command === 'stackTrace'; | ||
} | ||
|
||
export function isStacktraceResponse(message: unknown): message is DebugProtocol.StackTraceResponse { | ||
const candidate = message as DebugProtocol.StackTraceResponse; | ||
return !!candidate && candidate.command === 'stackTrace' && Array.isArray(candidate.body.stackFrames); | ||
} |
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.
It sounds like we likely want to move this over to the Amalgamator repository and make it dependent on this plugin (or at least propose it).
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.
I agree with @colin-grant-work . I think this is a great example of how a custom adapter implementation could look like.
But ideally it would be contributed by the debug adapter. Or was the intention to use it in a downstream version of the Memory Inspector, @WyoTwT ?
Maybe we can build some "how to implement your own adapter contribution" docs around it in https://github.com/eclipse-cdt-cloud/vscode-memory-inspector?tab=readme-ov-file#the-memory-provider ? It could be a nice story to demonstrate this with two Eclipse CDT Cloud components.
Another thing this PR shows me is that we may want to consider to somehow provide access to the default adapter implementation for reuse in custom implementations. Beyond asking developers to include the according sources from this repo.
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.
It doesn't appear there is an easy way to get access to the AdapterCapabilities, AdapterVariableTracker, and VariableTracker if this code is moved to the Amalgamator repository.
I could duplicate the interfaces in Amalgamator which is what I did with the Context because that wasn't shared from the Amalgamator. Would restructuring the code differently facilitate future movement of some parts into a form that could be reused for custom implementations?
I'm rather new to this so all suggestions to better structure the code are welcome but I may need additional clarification.