diff --git a/package.json b/package.json index 2637789..ed82fa1 100644 --- a/package.json +++ b/package.json @@ -273,6 +273,14 @@ "minimum": -1, "maximum": 32, "description": "If the gap between registers is less than this threshold (multiple of 8), combine into a single read from device. -1 means never combine registers and is very slow" + }, + "mcu-debug.peripheral-viewer.debugLevel": { + "type": "number", + "default": 0, + "minimum": 0, + "maximum": 2, + "multipleOf": 1, + "description": "Enable debug output in the OUTPUT Tab (Peripheral Viewer section). Some debug output may also be found in the `Mcu-debug Tracker` section which is controlled separately. Changing this value requires a Reload of the window" } } } diff --git a/src/debug-tracker-wrapper.ts b/src/debug-tracker-wrapper.ts index 59f52f2..cb4bd6e 100644 --- a/src/debug-tracker-wrapper.ts +++ b/src/debug-tracker-wrapper.ts @@ -6,11 +6,13 @@ */ import * as vscode from 'vscode'; +import * as manifest from './manifest'; import { DebugSessionStatus, DebugTracker, IDebuggerTrackerEvent, IDebugTracker, TRACKER_EXT_ID } from 'debug-tracker-vscode'; -import { logOutputChannel, logToOutputWindow } from './vscode-utils'; +import { setLogOutput, logOutputChannel, logToOutputWindow } from './vscode-utils'; export class DebugTrackerWrapper { private isLocalTracker = false; + private dbgLevel: 0 | 1 | 2 = 0; public constructor(private debugType = '*') { } @@ -28,6 +30,14 @@ export class DebugTrackerWrapper { private sessionIdMap: {[id: string]: vscode.DebugSession} = {}; public async activate(context: vscode.ExtensionContext): Promise { + // TODO: Make this dynamic so reloads are needed if setting changes + const dbgLevel = vscode.workspace.getConfiguration(manifest.PACKAGE_NAME).get(manifest.DEBUG_LEVEL, 0); + if ((dbgLevel >= 0) && (dbgLevel <= 2)) { + this.dbgLevel = dbgLevel as 0 | 1 | 2; + } + if (this.dbgLevel > 0) { + setLogOutput(true); + } logToOutputWindow('activating debug tracker'); const debugtracker = await this.getTracker(context); if (debugtracker) { @@ -37,7 +47,7 @@ export class DebugTrackerWrapper { body: { debuggers: '*', handler: async (event: IDebuggerTrackerEvent) => { - if (!this.isLocalTracker) { + if (!this.isLocalTracker || (this.dbgLevel > 1)) { logToOutputWindow(JSON.stringify(event)); } const session = this.sessionIdMap[event.sessionId]; @@ -78,7 +88,7 @@ export class DebugTrackerWrapper { // We could use our own channel in the future for debug this.isLocalTracker = true; logToOutputWindow('Using local debug tracker'); - ret = new DebugTracker(context, logOutputChannel, 1); + ret = new DebugTracker(context, logOutputChannel, this.dbgLevel); } else { logToOutputWindow('Using shared debug tracker'); } diff --git a/src/manifest.ts b/src/manifest.ts index 21c9686..80caaac 100644 --- a/src/manifest.ts +++ b/src/manifest.ts @@ -13,3 +13,4 @@ export const CONFIG_ADDRGAP = 'svdAddrGapThreshold'; export const DEFAULT_ADDRGAP = 16; export const CONFIG_ASSET_PATH = 'packAssetUrl'; export const DEFAULT_ASSET_PATH = 'https://pack-asset-service.keil.arm.com'; +export const DEBUG_LEVEL = 'debugLevel'; diff --git a/src/vscode-utils.ts b/src/vscode-utils.ts index c77660d..26bfcf2 100644 --- a/src/vscode-utils.ts +++ b/src/vscode-utils.ts @@ -53,10 +53,11 @@ export const getSelection = async (title: string, items: QuickPickItem[], value? } }; - +let enableLogOutput = false; export let logOutputChannel: vscode.OutputChannel | undefined; -// eslint-disable-next-line prefer-const -export let enableLogOutput = false; // TODO: This should be an extension option +export function setLogOutput(val: boolean) { + enableLogOutput = val; +} export function logToOutputWindow(msg: string) { if (enableLogOutput) { if (!logOutputChannel) {