Skip to content

Commit

Permalink
Unify usage of hex address conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-fleck-at committed Mar 13, 2024
1 parent 83c51b5 commit 175a330
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/plugin/adapter-registry/adapter-capabilities.ts
Expand Up @@ -38,6 +38,10 @@ export type VariablesTree = Record<number, WithChildren<DebugProtocol.Scope | De
export const hexAddress = /0x[0-9a-f]+/i;
export const notADigit = /[^0-9]/;

export function findHexAddress(text?: string): string | undefined {
return text ? hexAddress.exec(text)?.[0] : undefined;
}

/** This class implements some of the basic elements of tracking adapter sessions in order to maintain a list of variables. */
export class AdapterVariableTracker implements vscode.DebugAdapterTracker {
protected currentFrame?: number;
Expand Down
7 changes: 3 additions & 4 deletions src/plugin/adapter-registry/c-tracker.ts
Expand Up @@ -16,7 +16,7 @@

import * as vscode from 'vscode';
import { DebugProtocol } from '@vscode/debugprotocol';
import { AdapterVariableTracker, hexAddress, notADigit } from './adapter-capabilities';
import { AdapterVariableTracker, findHexAddress, notADigit } from './adapter-capabilities';
import { toHexStringWithRadixMarker, VariableRange } from '../../common/memory-range';
import { sendRequest } from '../../common/debug-requests';

Expand All @@ -43,7 +43,7 @@ export class CTracker extends AdapterVariableTracker {
}
try {
const [variableAddress, variableSize] = await Promise.all([
variable.memoryReference && hexAddress.test(variable.memoryReference) ? variable.memoryReference : this.getAddressOfVariable(variable.name, session),
findHexAddress(variable.memoryReference) ?? this.getAddressOfVariable(variable.name, session),
this.getSizeOfVariable(variable.name, session)
]);
if (!variableAddress) { return undefined; }
Expand All @@ -66,8 +66,7 @@ export class CTracker extends AdapterVariableTracker {

async getAddressOfVariable(variableName: string, session: vscode.DebugSession): Promise<string | undefined> {
const response = await sendRequest(session, 'evaluate', { expression: CEvaluateExpression.addressOf(variableName), context: 'watch', frameId: this.currentFrame });
const addressPart = hexAddress.exec(response.result);
return addressPart ? addressPart[0] : undefined;
return findHexAddress(response.result);
}

async getSizeOfVariable(variableName: string, session: vscode.DebugSession): Promise<bigint | undefined> {
Expand Down

0 comments on commit 175a330

Please sign in to comment.