From ad8062afa525af31624dff46060239ea737ed7f1 Mon Sep 17 00:00:00 2001 From: Haydar Metin Date: Wed, 21 Aug 2024 12:55:08 +0200 Subject: [PATCH] Disable breakpoint functionality --- package.json | 57 +------- src/common/breakpoint.ts | 8 +- src/plugin/breakpoints/README.md | 70 +++++++++ src/plugin/breakpoints/breakpoint-tracker.ts | 22 +-- src/plugin/session-tracker.ts | 4 - src/webview/breakpoints/README.md | 138 ++++++++++++++++++ src/webview/columns/address-column.tsx | 8 - src/webview/columns/data-column.tsx | 6 +- src/webview/memory-webview-view.tsx | 8 +- src/webview/utils/vscode-contexts.ts | 11 +- src/webview/variables/variable-decorations.ts | 9 +- 11 files changed, 235 insertions(+), 106 deletions(-) create mode 100644 src/plugin/breakpoints/README.md create mode 100644 src/webview/breakpoints/README.md diff --git a/package.json b/package.json index 0354ca9..1eacbdc 100644 --- a/package.json +++ b/package.json @@ -92,36 +92,6 @@ "title": "Go to value in Memory Inspector", "category": "Memory" }, - { - "command": "memory-inspector.data-breakpoint.set.read", - "title": "Break on Value Read", - "enablement": "memory-inspector.canWrite", - "category": "Memory" - }, - { - "command": "memory-inspector.data-breakpoint.set.readWrite", - "title": "Break on Value Access", - "enablement": "memory-inspector.canWrite", - "category": "Memory" - }, - { - "command": "memory-inspector.data-breakpoint.set.write", - "title": "Break on Value Change", - "enablement": "memory-inspector.canWrite", - "category": "Memory" - }, - { - "command": "memory-inspector.data-breakpoint.remove", - "title": "Remove Breakpoint", - "enablement": "memory-inspector.canWrite", - "category": "Memory" - }, - { - "command": "memory-inspector.data-breakpoint.remove-all", - "title": "Remove All Breakpoints", - "enablement": "memory-inspector.canWrite", - "category": "Memory" - }, { "command": "memory-inspector.toggle-variables-column", "title": "Toggle Variables Column", @@ -267,31 +237,6 @@ "command": "memory-inspector.reset-display-options", "group": "a_reset@2", "when": "webviewId === memory-inspector.memory && optionsMenu" - }, - { - "command": "memory-inspector.data-breakpoint.set.read", - "group": "breakpoints@1", - "when": "webviewId === memory-inspector.memory && memory-inspector.breakpoint.isBreakable" - }, - { - "command": "memory-inspector.data-breakpoint.set.write", - "group": "breakpoints@2", - "when": "webviewId === memory-inspector.memory && memory-inspector.breakpoint.isBreakable" - }, - { - "command": "memory-inspector.data-breakpoint.set.readWrite", - "group": "breakpoints@3", - "when": "webviewId === memory-inspector.memory && memory-inspector.breakpoint.isBreakable" - }, - { - "command": "memory-inspector.data-breakpoint.remove", - "group": "breakpoints@4", - "when": "webviewId === memory-inspector.memory && memory-inspector.breakpoint.type === 'internal'" - }, - { - "command": "memory-inspector.data-breakpoint.remove-all", - "group": "breakpoints@5", - "when": "webviewId === memory-inspector.memory && memory-inspector.breakpoint.type === 'internal'" } ] }, @@ -501,4 +446,4 @@ "extensionKind": [ "ui" ] -} \ No newline at end of file +} diff --git a/src/common/breakpoint.ts b/src/common/breakpoint.ts index cc02f47..9fe438c 100644 --- a/src/common/breakpoint.ts +++ b/src/common/breakpoint.ts @@ -23,9 +23,12 @@ export interface TrackedDataBreakpoint { /** * The respective response for the breakpoint. */ - response: DebugProtocol.SetDataBreakpointsResponse['body']['breakpoints'][0] + response: DebugProtocol.Breakpoint; } +/** + * Temp. workaround till we have a proper API for this within VSCode. + */ export interface TrackedDataBreakpoints { /** * Breakpoints set from external contributors. @@ -37,6 +40,9 @@ export interface TrackedDataBreakpoints { internal: TrackedDataBreakpoint[] } +/** + * Temp. workaround till we have a proper API for this within VSCode. + */ export type TrackedBreakpointType = 'internal' | 'external'; export type DataBreakpointInfoArguments = DebugRequestTypes['dataBreakpointInfo'][0]; diff --git a/src/plugin/breakpoints/README.md b/src/plugin/breakpoints/README.md new file mode 100644 index 0000000..2f51cce --- /dev/null +++ b/src/plugin/breakpoints/README.md @@ -0,0 +1,70 @@ +# Steps to enable the breakpoint service again: + +This service has been disabled for now, as it is not used. +It is kept here until VSCode extends the breakpoints API. + +- package.json + +```json + "commands": [ + { + "command": "memory-inspector.data-breakpoint.set.read", + "title": "Break on Value Read", + "enablement": "memory-inspector.canWrite", + "category": "Memory" + }, + { + "command": "memory-inspector.data-breakpoint.set.readWrite", + "title": "Break on Value Access", + "enablement": "memory-inspector.canWrite", + "category": "Memory" + }, + { + "command": "memory-inspector.data-breakpoint.set.write", + "title": "Break on Value Change", + "enablement": "memory-inspector.canWrite", + "category": "Memory" + }, + { + "command": "memory-inspector.data-breakpoint.remove", + "title": "Remove Breakpoint", + "enablement": "memory-inspector.canWrite", + "category": "Memory" + }, + { + "command": "memory-inspector.data-breakpoint.remove-all", + "title": "Remove All Breakpoints", + "enablement": "memory-inspector.canWrite", + "category": "Memory" + }, + ] + + "webview/context": [ + ... + { + "command": "memory-inspector.data-breakpoint.set.read", + "group": "breakpoints@1", + "when": "false && webviewId === memory-inspector.memory && memory-inspector.breakpoint.isBreakable" + }, + { + "command": "memory-inspector.data-breakpoint.set.write", + "group": "breakpoints@2", + "when": "false && webviewId === memory-inspector.memory && memory-inspector.breakpoint.isBreakable" + }, + { + "command": "memory-inspector.data-breakpoint.set.readWrite", + "group": "breakpoints@3", + "when": "false && webviewId === memory-inspector.memory && memory-inspector.breakpoint.isBreakable" + }, + { + "command": "memory-inspector.data-breakpoint.remove", + "group": "breakpoints@4", + "when": "false && webviewId === memory-inspector.memory && memory-inspector.breakpoint.type === 'internal'" + }, + { + "command": "memory-inspector.data-breakpoint.remove-all", + "group": "breakpoints@5", + "when": "false && webviewId === memory-inspector.memory && memory-inspector.breakpoint.type === 'internal'" + } + ] +``` diff --git a/src/plugin/breakpoints/breakpoint-tracker.ts b/src/plugin/breakpoints/breakpoint-tracker.ts index e7a4032..c2274e4 100644 --- a/src/plugin/breakpoints/breakpoint-tracker.ts +++ b/src/plugin/breakpoints/breakpoint-tracker.ts @@ -20,6 +20,12 @@ import { SetDataBreakpointsResult, TrackedDataBreakpoint, TrackedDataBreakpoints import { isDebugRequest, isDebugResponse } from '../../common/debug-requests'; import { isSessionEvent, SessionContinuedEvent, SessionEvent, SessionRequest, SessionResponse, SessionStoppedEvent, SessionTracker } from '../session-tracker'; +/** + * Tracks data breakpoints and provides events for changes. + * + * Currently the webview part is disabled and does not react to the changes. + * It will be enabled again after VSCode extends the breakpoint API. + */ export class BreakpointTracker { protected _dataBreakpoints: TrackedDataBreakpoints = { external: [], internal: [] }; protected _stoppedEvent?: SessionStoppedEvent; @@ -84,20 +90,8 @@ export class BreakpointTracker { } if (isSessionEvent('stopped', event)) { - // TODO: Only for demo purposes - // Reason: The debugger does not set the hitBreakpointIds property - const demoEvent: SessionStoppedEvent = { - ...event, - data: { - ...event.data, - body: { - ...event.data.body, - hitBreakpointIds: this.externalDataBreakpoints.map(bp => bp.response.id ?? -1) - } - } - }; - this._stoppedEvent = demoEvent; - this._onStopped.fire(demoEvent); + this._stoppedEvent = event; + this._onStopped.fire(event); } else if (isSessionEvent('continued', event)) { this._stoppedEvent = undefined; this._onContinued.fire(event); diff --git a/src/plugin/session-tracker.ts b/src/plugin/session-tracker.ts index 780bb7f..38b94aa 100644 --- a/src/plugin/session-tracker.ts +++ b/src/plugin/session-tracker.ts @@ -145,8 +145,6 @@ export class SessionTracker implements vscode.DebugAdapterTrackerFactory { } protected willSendClientMessage(session: vscode.DebugSession, message: unknown): void { - // TODO: ONLY FOR DEMO PURPOSES - console.log('[SEND] ==>', message); if (isDebugRequest('initialize', message)) { this.sessionInfo(session).clientCapabilities = message.arguments; } @@ -157,8 +155,6 @@ export class SessionTracker implements vscode.DebugAdapterTrackerFactory { } protected adapterMessageReceived(session: vscode.DebugSession, message: unknown): void { - // TODO: ONLY FOR DEMO PURPOSES - console.log('[RECV] <==', message); if (isDebugResponse('initialize', message)) { this.sessionInfo(session).debugCapabilities = message.body; } else if (isDebugEvent('stopped', message)) { diff --git a/src/webview/breakpoints/README.md b/src/webview/breakpoints/README.md new file mode 100644 index 0000000..c9f5caa --- /dev/null +++ b/src/webview/breakpoints/README.md @@ -0,0 +1,138 @@ +# Steps to enable the breakpoint service again: + +This service has been disabled for now, as it is not used. +It is kept here until VSCode extends the breakpoints API. + +1. src/webview/memory-webview-view.tsx + +```typescript +componentDidMount() { + ... + breakpointService.activate(); + breakpointService.onDidChange(() => this.forceUpdate()); +} + +doFetchMemory() { + ... + await Promise.all(Array.from( + new Set(columnContributionService + .getUpdateExecutors() + .concat(decorationService.getUpdateExecutors()) + .concat(breakpointService)), + executor => executor.fetchData(memoryOptions) + )); +} +``` + +2. src/webview/columns/address-column.tsx + +Extend rendering (Should be done through a decorator) + +```typescript + render(columnIndex: number, row: MemoryRowData, config: ColumnRenderProps): ReactNode { + const selectionProps: SelectionProps = { + createSelection: (event, position) => createDefaultSelection(event, position, AddressColumn.ID, row), + getSelection: () => config.selection, + setSelection: config.setSelection + }; + + const breakpointMetadata = breakpointService.inRange(row) + .map(bp => breakpointService.metadata(bp)) + .filter((bp): bp is BreakpointMetadata => bp !== undefined); + const statusClasses = BreakpointService.statusClasses(breakpointMetadata); + + const groupProps = groupAttributes({ columnIndex, rowIndex: row.rowIndex, groupIndex: 0, maxGroupIndex: 0 }, selectionProps); + return + {statusClasses.length > 0 && } + {config.tableConfig.showRadixPrefix && {getRadixMarker(config.tableConfig.addressRadix)}} + {getAddressString(row.startAddress, config.tableConfig.addressRadix, config.tableConfig.effectiveAddressLength)} + ; + } +``` + +3. src/webview/columns/data-column.tsx + +Extend Context (Should be done through a contribution) + +```typescript + protected renderGroup(maus: React.ReactNode, startAddress: bigint, endAddress: bigint, idx: number): React.ReactNode { + const { config, row, columnIndex } = this.props; + const groupProps = groupAttributes({ + rowIndex: row.rowIndex, + columnIndex: columnIndex, + groupIndex: idx, + maxGroupIndex: this.props.config.groupsPerRowToRender - 1 + }, this.selectionProps); + const breakpointMetadata = breakpointService.metadata(toHexStringWithRadixMarker(startAddress)); + + return + {maus} + ; + } +``` + +4. src/webview/utils/vscode-contexts.ts + +```typescript +export function createGroupVscodeContext( + startAddress: bigint, + length: number, + breakpoint?: BreakpointMetadata +): VscodeContext { + return createVscodeContext({ + memoryData: { group: { startAddress, length } }, + breakpoint: { ...breakpoint, isBreakable: true }, + }); +} + +export function createVariableVscodeContext( + variable: BigIntVariableRange, + breakpoint?: BreakpointMetadata +): VscodeContext { + const { name, type, value, parentVariablesReference, isPointer } = variable; + return createVscodeContext({ + variable: { name, type, value, parentVariablesReference, isPointer }, + breakpoint: { ...breakpoint, isBreakable: true }, + }); +} +``` + +5. src/webview/variables/variable-decorations.ts + +Extend rendering (Should be done through a decorator) + +```typescript + render(columnIndex: number, row: MemoryRowData, config: ColumnRenderProps): ReactNode { + const selectionProps: SelectionProps = { + createSelection: (event, position) => createDefaultSelection(event, position, VariableDecorator.ID, row), + getSelection: () => config.selection, + setSelection: config.setSelection + }; + const variables = this.getVariablesInRange(row); + return variables?.reduce((result, current, index) => { + if (index > 0) { result.push(', '); } + const breakpointMetadata = breakpointService.metadata(current.variable.name); + result.push(React.createElement('span', { + style: { color: current.color }, + key: current.variable.name, + className: classNames('hoverable', ...BreakpointService.inlineClasses(breakpointMetadata)), + 'data-column': 'variables', + 'data-variables': stringifyWithBigInts(current.variable), + ...createVariableVscodeContext(current.variable, breakpointMetadata), + ...groupAttributes({ columnIndex, rowIndex: row.rowIndex, groupIndex: index, maxGroupIndex: variables.length - 1 }, selectionProps) + }, current.variable.name)); + return result; + }, []); + } +``` diff --git a/src/webview/columns/address-column.tsx b/src/webview/columns/address-column.tsx index 4a81af0..bf54fd4 100644 --- a/src/webview/columns/address-column.tsx +++ b/src/webview/columns/address-column.tsx @@ -14,10 +14,8 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ -import { classNames } from 'primereact/utils'; import React, { ReactNode } from 'react'; import { getAddressString, getRadixMarker } from '../../common/memory-range'; -import { BreakpointMetadata, BreakpointService, breakpointService } from '../breakpoints/breakpoint-service'; import { MemoryRowData } from '../components/memory-table'; import { ColumnContribution, ColumnFittingType, ColumnRenderProps } from './column-contribution-service'; import { createDefaultSelection, groupAttributes, SelectionProps } from './table-group'; @@ -40,14 +38,8 @@ export class AddressColumn implements ColumnContribution { setSelection: config.setSelection }; - const breakpointMetadata = breakpointService.inRange(row) - .map(bp => breakpointService.metadata(bp)) - .filter((bp): bp is BreakpointMetadata => bp !== undefined); - const statusClasses = BreakpointService.statusClasses(breakpointMetadata); - const groupProps = groupAttributes({ columnIndex, rowIndex: row.rowIndex, groupIndex: 0, maxGroupIndex: 0 }, selectionProps); return - {statusClasses.length > 0 && } {config.tableConfig.showRadixPrefix && {getRadixMarker(config.tableConfig.addressRadix)}} {getAddressString(row.startAddress, config.tableConfig.addressRadix, config.tableConfig.effectiveAddressLength)} ; diff --git a/src/webview/columns/data-column.tsx b/src/webview/columns/data-column.tsx index fb78b1b..7a0a3ff 100644 --- a/src/webview/columns/data-column.tsx +++ b/src/webview/columns/data-column.tsx @@ -22,7 +22,6 @@ import { HOST_EXTENSION } from 'vscode-messenger-common'; import { Memory } from '../../common/memory'; import { BigIntMemoryRange, isWithin, toHexStringWithRadixMarker, toOffset } from '../../common/memory-range'; import { writeMemoryType } from '../../common/messaging'; -import { BreakpointService, breakpointService } from '../breakpoints/breakpoint-service'; import type { MemoryRowData, MemorySizeOptions, MemoryTableSelection, MemoryTableState } from '../components/memory-table'; import { decorationService } from '../decorations/decoration-service'; import { Disposable, FullNodeAttributes } from '../utils/view-types'; @@ -156,11 +155,10 @@ export class EditableDataColumnRow extends React.Component {maus} ; diff --git a/src/webview/memory-webview-view.tsx b/src/webview/memory-webview-view.tsx index 6101dcf..537cf1f 100644 --- a/src/webview/memory-webview-view.tsx +++ b/src/webview/memory-webview-view.tsx @@ -43,7 +43,6 @@ import { } from '../common/messaging'; import { Change, hasChanged, hasChangedTo } from '../common/typescript'; import { MemoryDisplaySettings, MemoryViewSettings } from '../common/webview-configuration'; -import { breakpointService } from './breakpoints/breakpoint-service'; import { AddressColumn } from './columns/address-column'; import { AsciiColumn } from './columns/ascii-column'; import { columnContributionService, ColumnStatus } from './columns/column-contribution-service'; @@ -135,8 +134,6 @@ class App extends React.Component<{}, MemoryAppState> { messenger.onRequest(getWebviewSelectionType, () => this.getWebviewSelection()); messenger.onNotification(showAdvancedOptionsType, () => this.showAdvancedOptions()); messenger.sendNotification(readyType, HOST_EXTENSION, undefined); - breakpointService.activate(); - breakpointService.onDidChange(() => this.forceUpdate()); this.updatePeriodicRefresh(); } @@ -294,10 +291,7 @@ class App extends React.Component<{}, MemoryAppState> { try { const response = await messenger.sendRequest(readMemoryType, HOST_EXTENSION, memoryOptions); await Promise.all(Array.from( - new Set(columnContributionService - .getUpdateExecutors() - .concat(decorationService.getUpdateExecutors()) - .concat(breakpointService)), + new Set(columnContributionService.getUpdateExecutors().concat(decorationService.getUpdateExecutors())), executor => executor.fetchData(memoryOptions) )); diff --git a/src/webview/utils/vscode-contexts.ts b/src/webview/utils/vscode-contexts.ts index f0f8ebc..9ea3206 100644 --- a/src/webview/utils/vscode-contexts.ts +++ b/src/webview/utils/vscode-contexts.ts @@ -16,7 +16,6 @@ import { BigIntVariableRange } from '../../common/memory-range'; import { WebviewContext } from '../../common/webview-context'; -import { BreakpointMetadata } from '../breakpoints/breakpoint-service'; /** * Custom data property used by VSCode to provide additional context info when opening a webview context menu * The data property needs to represent a valid JSON object. Data context properties up the parent chain are merged into the child context. @@ -65,13 +64,13 @@ export function createAppVscodeContext(context: Omit((result, current, index) => { if (index > 0) { result.push(', '); } - const breakpointMetadata = breakpointService.metadata(current.variable.name); result.push(React.createElement('span', { style: { color: current.color }, key: current.variable.name, - className: classNames('hoverable', ...BreakpointService.inlineClasses(breakpointMetadata)), + className: 'hoverable', 'data-column': 'variables', 'data-variables': stringifyWithBigInts(current.variable), - ...createVariableVscodeContext(current.variable, breakpointMetadata), + ...createVariableVscodeContext(current.variable), ...groupAttributes({ columnIndex, rowIndex: row.rowIndex, groupIndex: index, maxGroupIndex: variables.length - 1 }, selectionProps) }, current.variable.name)); return result;