-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Context for cdt-amalgamator and other DAPs
Populate the Context Dropdown from the different debug Contexts if available so different DAPs can be addressed. Add an optional Context to queries so the query can be directed to the appropriate handler. Add support for cdt-amalgamator. Signed-off-by: Thor Thayer <[email protected]>
- Loading branch information
Showing
13 changed files
with
302 additions
and
73 deletions.
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,110 @@ | ||
/******************************************************************************** | ||
* 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 { Context, 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 Contexts { | ||
children?: Context[]; | ||
} | ||
export interface GetContextsResponse extends DebugProtocol.Response { | ||
body: Contexts; | ||
} | ||
export type GetContextsResult = GetContextsResponse['body']; | ||
|
||
export interface AmalgamatorReadArgs extends ReadMemoryArguments { | ||
child: Context; | ||
} | ||
|
||
export class AmalgamatorSessionManager extends VariableTracker implements AdapterCapabilities { | ||
async getContexts(session: vscode.DebugSession): Promise<Context[]> { | ||
return this.sessions.get(session.id)?.getContexts?.(session) || []; | ||
} | ||
|
||
async readMemory(session: vscode.DebugSession, args: ReadMemoryArguments, context: Context): 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: Context): Promise<WriteMemoryResult> { | ||
return this.sessions.get(session.id)?.writeMemory?.(session, args, context); | ||
} | ||
|
||
async getCurrentContext(session: vscode.DebugSession): Promise<Context | undefined> { | ||
return this.sessions.get(session.id)?.getCurrentContext?.(session); | ||
} | ||
} | ||
|
||
export class AmalgamatorGdbVariableTransformer extends AdapterVariableTracker { | ||
protected contexts?: Context[]; | ||
protected currentContext?: Context; | ||
|
||
onWillReceiveMessage(message: unknown): void { | ||
if (isStacktraceRequest(message)) { | ||
if (typeof(message.arguments.threadId) !== 'undefined') { | ||
this.currentContext = { | ||
id: message.arguments.threadId, | ||
name: message.arguments.threadId.toString() | ||
}; | ||
} else { | ||
this.logger.warn('Invalid ThreadID in stackTrace'); | ||
this.currentContext = undefined; | ||
} | ||
} else { | ||
super.onWillReceiveMessage(message); | ||
} | ||
} | ||
|
||
get frame(): number | undefined { return this.currentFrame; } | ||
|
||
async getContexts(session: vscode.DebugSession): Promise<Context[]> { | ||
if (!this.contexts) { | ||
const contexts: GetContextsResult = (await session.customRequest('cdt-amalgamator/getChildDaps')); | ||
this.contexts = contexts.children?.map(({ name, id }) => ({ name, id })) ?? []; | ||
} | ||
return Promise.resolve(this.contexts); | ||
} | ||
|
||
async getCurrentContext(_session: vscode.DebugSession): Promise<Context | undefined> { | ||
return Promise.resolve(this.currentContext); | ||
} | ||
|
||
readMemory(session: vscode.DebugSession, args: ReadMemoryArguments, context: Context): 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.