From c062c772e78c5d41c3903ea306491992057925db Mon Sep 17 00:00:00 2001 From: Philip Langer Date: Tue, 27 Feb 2024 21:34:17 +0100 Subject: [PATCH 1/4] Make memory address padding configurable Introduces VS Code setting for memory address padding with the values * Unpadded * Minimal padding * 32 bit padding * 64 bit padding Fixes #76 --- package.json | 17 ++++++++++++ src/common/memory-range.ts | 7 +++-- src/plugin/manifest.ts | 2 ++ src/plugin/memory-webview-main.ts | 5 ++-- src/webview/columns/address-column.tsx | 8 +++--- src/webview/components/memory-table.tsx | 1 + src/webview/components/memory-widget.tsx | 4 +++ src/webview/components/options-widget.tsx | 24 +++++++++++++--- src/webview/memory-webview-view.tsx | 34 ++++++++++++++++++++++- src/webview/utils/view-types.ts | 11 +++++++- 10 files changed, 99 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index b5cc14b..efaa4fd 100644 --- a/package.json +++ b/package.json @@ -220,6 +220,23 @@ ], "description": "Behavior when adding more memory beyond the current view." }, + "memory-inspector.addressPadding": { + "type": "string", + "enum": [ + "Minimal", + "Unpadded", + "32bit", + "64bit" + ], + "default": "Minimal", + "enumDescriptions": [ + "Minimal padding based on the longest address in range.", + "Disables padding, presenting addresses as-is.", + "Pads addresses to fit within a 32-bit address space.", + "Pads addresses to fit within a 64-bit address space." + ], + "description": "Controls the padding with 0s for memory addresses, enhancing readability by aligning them within a specified bit-width context." + }, "memory-inspector.addressRadix": { "type": "number", "enum": [ diff --git a/src/common/memory-range.ts b/src/common/memory-range.ts index 13061da..a76df7d 100644 --- a/src/common/memory-range.ts +++ b/src/common/memory-range.ts @@ -85,11 +85,14 @@ export function getRadixMarker(radix: Radix): string { return radixPrefixMap[radix]; } -export function getAddressString(address: bigint, radix: Radix, architecture: Architecture = 32, addPadding = false): string { - const paddedLength = addPadding ? Math.ceil(architecture / Math.log2(radix)) : 0; +export function getAddressString(address: bigint, radix: Radix, paddedLength: number = 0): string { return address.toString(radix).padStart(paddedLength, '0'); } +export function getAddressLength(padding: number, radix: Radix): number { + return Math.ceil(padding / Math.log2(radix)); +} + export function toHexStringWithRadixMarker(target: bigint): string { return `${getRadixMarker(Radix.Hexadecimal)}${getAddressString(target, Radix.Hexadecimal)}`; } diff --git a/src/plugin/manifest.ts b/src/plugin/manifest.ts index 46487ff..62b5d7c 100644 --- a/src/plugin/manifest.ts +++ b/src/plugin/manifest.ts @@ -48,6 +48,8 @@ export const DEFAULT_GROUPS_PER_ROW: GroupsPerRowOption = 4; // Scroll export const CONFIG_SCROLLING_BEHAVIOR = 'scrollingBehavior'; export const DEFAULT_SCROLLING_BEHAVIOR = 'Paginate'; +export const CONFIG_ADDRESS_PADDING = 'addressPadding'; +export const DEFAULT_ADDRESS_PADDING = 'Minimal'; export const CONFIG_ADDRESS_RADIX = 'addressRadix'; export const DEFAULT_ADDRESS_RADIX = 16; export const CONFIG_SHOW_RADIX_PREFIX = 'showRadixPrefix'; diff --git a/src/plugin/memory-webview-main.ts b/src/plugin/memory-webview-main.ts index 643d9ef..89ac77c 100644 --- a/src/plugin/memory-webview-main.ts +++ b/src/plugin/memory-webview-main.ts @@ -35,7 +35,7 @@ import { import { MemoryProvider } from './memory-provider'; import { outputChannelLogger } from './logger'; import { VariableRange } from '../common/memory-range'; -import { MemoryViewSettings, ScrollingBehavior } from '../webview/utils/view-types'; +import { AddressPaddingOptions, MemoryViewSettings, ScrollingBehavior } from '../webview/utils/view-types'; interface Variable { name: string; @@ -225,9 +225,10 @@ export class MemoryWebview implements vscode.CustomReadonlyEditorProvider { const visibleColumns = CONFIGURABLE_COLUMNS .filter(column => vscode.workspace.getConfiguration(manifest.PACKAGE_NAME).get(column, false)) .map(columnId => columnId.replace('columns.', '')); + const addressPadding = AddressPaddingOptions[memoryInspectorConfiguration.get(manifest.CONFIG_ADDRESS_PADDING, manifest.DEFAULT_ADDRESS_PADDING)]; const addressRadix = memoryInspectorConfiguration.get(manifest.CONFIG_ADDRESS_RADIX, manifest.DEFAULT_ADDRESS_RADIX); const showRadixPrefix = memoryInspectorConfiguration.get(manifest.CONFIG_SHOW_RADIX_PREFIX, manifest.DEFAULT_SHOW_RADIX_PREFIX); - return { title, bytesPerWord, wordsPerGroup, groupsPerRow, scrollingBehavior, visibleColumns, addressRadix, showRadixPrefix }; + return { title, bytesPerWord, wordsPerGroup, groupsPerRow, scrollingBehavior, visibleColumns, addressPadding, addressRadix, showRadixPrefix }; } protected async readMemory(request: DebugProtocol.ReadMemoryArguments): Promise { diff --git a/src/webview/columns/address-column.tsx b/src/webview/columns/address-column.tsx index 382b48a..ec84f0c 100644 --- a/src/webview/columns/address-column.tsx +++ b/src/webview/columns/address-column.tsx @@ -16,8 +16,8 @@ import React, { ReactNode } from 'react'; import { BigIntMemoryRange, getAddressString, getRadixMarker } from '../../common/memory-range'; -import { ColumnContribution, ColumnFittingType } from './column-contribution-service'; -import { Memory, MemoryDisplayConfiguration } from '../utils/view-types'; +import { ColumnContribution, ColumnFittingType, TableRenderOptions } from './column-contribution-service'; +import { Memory } from '../utils/view-types'; export class AddressColumn implements ColumnContribution { static ID = 'address'; @@ -28,10 +28,10 @@ export class AddressColumn implements ColumnContribution { fittingType: ColumnFittingType = 'content-width'; - render(range: BigIntMemoryRange, _: Memory, options: MemoryDisplayConfiguration): ReactNode { + render(range: BigIntMemoryRange, _: Memory, options: TableRenderOptions): ReactNode { return {options.showRadixPrefix && {getRadixMarker(options.addressRadix)}} - {getAddressString(range.startAddress, options.addressRadix)} + {getAddressString(range.startAddress, options.addressRadix, options.effectiveAddressLength)} ; } } diff --git a/src/webview/components/memory-table.tsx b/src/webview/components/memory-table.tsx index 01fa471..76465ad 100644 --- a/src/webview/components/memory-table.tsx +++ b/src/webview/components/memory-table.tsx @@ -101,6 +101,7 @@ interface MemoryTableProps extends TableRenderOptions, MemoryDisplayConfiguratio decorations: Decoration[]; offset: number; count: number; + effectiveAddressLength: number; fetchMemory(partialOptions?: Partial): Promise; isMemoryFetching: boolean; isFrozen: boolean; diff --git a/src/webview/components/memory-widget.tsx b/src/webview/components/memory-widget.tsx index 4d75877..179ae2d 100644 --- a/src/webview/components/memory-widget.tsx +++ b/src/webview/components/memory-widget.tsx @@ -29,6 +29,7 @@ interface MemoryWidgetProps extends MemoryDisplayConfiguration { memoryReference: string; offset: number; count: number; + effectiveAddressLength: number; isMemoryFetching: boolean; refreshMemory: () => void; updateMemoryArguments: (memoryArguments: Partial) => void; @@ -72,6 +73,7 @@ export class MemoryWidget extends React.Component, + extends Omit, Required { title: string; updateRenderOptions: (options: Partial) => void; @@ -58,6 +56,7 @@ const enum InputId { BytesPerWord = 'word-size', WordsPerGroup = 'words-per-group', GroupsPerRow = 'groups-per-row', + AddressPadding = 'address-padding', AddressRadix = 'address-radix', ShowRadixPrefix = 'show-radix-prefix', } @@ -321,6 +320,20 @@ export class OptionsWidget extends React.Component

Address Format

+ + + ({ label, value }))} + className="advanced-options-dropdown" /> +