Files
pioarduino-vscode-debug/dist/extension.js
T
2026-03-11 16:18:55 +01:00

1 line
48 KiB
JavaScript

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@vscode/debugadapter"),require("vscode"),require("xml2js")):"function"==typeof define&&define.amd?define(["@vscode/debugadapter","vscode","xml2js"],t):"object"==typeof exports?exports["pioarduino-vscode-debug"]=t(require("@vscode/debugadapter"),require("vscode"),require("xml2js")):e["pioarduino-vscode-debug"]=t(e["@vscode/debugadapter"],e.vscode,e.xml2js)}(global,(e,t,r)=>(()=>{"use strict";var i={799(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.SymbolScope=t.SymbolType=t.TelemetryEvent=t.StoppedEvent=t.AdapterOutputEvent=t.NumberFormat=void 0;const i=r(161);var s,n,o;!function(e){e[e.Auto=0]="Auto",e[e.Hexidecimal=1]="Hexidecimal",e[e.Decimal=2]="Decimal",e[e.Binary=3]="Binary"}(s||(t.NumberFormat=s={}));class a extends i.Event{constructor(e,t){super("adapter-output",{content:e,type:t})}}t.AdapterOutputEvent=a;class d extends i.Event{constructor(e,t,r){super("stopped",{reason:e,threadId:t,allThreadsStopped:r})}}t.StoppedEvent=d;class h extends i.Event{constructor(e,t,r,i={}){super("record-event",{category:e,action:t,label:r,parameters:i})}}t.TelemetryEvent=h,function(e){e[e.Function=0]="Function",e[e.File=1]="File",e[e.Object=2]="Object",e[e.Normal=3]="Normal"}(n||(t.SymbolType=n={})),function(e){e[e.Local=0]="Local",e[e.Global=1]="Global",e[e.Neither=2]="Neither",e[e.Both=3]="Both"}(o||(t.SymbolScope=o={}))},265(e,t,r){var i,s=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var s=Object.getOwnPropertyDescriptor(t,r);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,s)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||(i=function(e){return i=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},i(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=i(e),o=0;o<r.length;o++)"default"!==r[o]&&s(t,e,r[o]);return n(t,e),t}),a=this&&this.__awaiter||function(e,t,r,i){return new(r||(r=Promise))(function(s,n){function o(e){try{d(i.next(e))}catch(e){n(e)}}function a(e){try{d(i.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(o,a)}d((i=i.apply(e,t||[])).next())})};Object.defineProperty(t,"__esModule",{value:!0}),t.activate=function(e){return new y(e)},t.deactivate=function(){};const d=o(r(850)),h=r(799),l=r(185),u=r(22),c=r(675),m=r(414),p=r(578),f=r(485),g=r(413),b=r(307);class y{constructor(e){this.adapterOutputChannel=null,this.functionSymbols=null,this.context=e,this.registerProvider=new b.RegisterTreeProvider,this.peripheralProvider=new g.PeripheralTreeProvider,this.memoryTreeProvider=new f.MemoryTreeProvider,this.disassemblyTreeProvider=new m.DisassemblyTreeProvider,this.memoryContentProvider=new p.MemoryContentProvider;const t=d.window.createTreeView("platformio-debug.peripherals",{treeDataProvider:this.peripheralProvider});e.subscriptions.push(d.debug.registerDebugConfigurationProvider("platformio-debug",new u.PlatformIODebugConfigurationProvider),t,t.onDidExpandElement(this.peripheralProvider.onDidExpandElement.bind(this.peripheralProvider)),t.onDidCollapseElement(this.peripheralProvider.onDidCollapseElement.bind(this.peripheralProvider)),d.window.registerTreeDataProvider("platformio-debug.registers",this.registerProvider),d.window.registerTreeDataProvider("platformio-debug.memory",this.memoryTreeProvider),d.window.registerTreeDataProvider("platformio-debug.disassembly",this.disassemblyTreeProvider),d.workspace.registerTextDocumentContentProvider("examinememory",this.memoryContentProvider),d.workspace.registerTextDocumentContentProvider("disassembly",new c.DisassemblyContentProvider),d.commands.registerCommand("platformio-debug.peripherals.updateNode",this.peripheralsUpdateNode.bind(this)),d.commands.registerCommand("platformio-debug.peripherals.selectedNode",this.peripheralsSelectedNode.bind(this)),d.commands.registerCommand("platformio-debug.peripherals.copyValue",this.peripheralsCopyValue.bind(this)),d.commands.registerCommand("platformio-debug.peripherals.setFormat",this.peripheralsSetFormat.bind(this)),d.commands.registerCommand("platformio-debug.registers.selectedNode",this.registersSelectedNode.bind(this)),d.commands.registerCommand("platformio-debug.registers.copyValue",this.registersCopyValue.bind(this)),d.commands.registerCommand("platformio-debug.registers.setFormat",this.registersSetFormat.bind(this)),d.commands.registerCommand("platformio-debug.memory.deleteHistoryItem",this.memoryDeleteHistoryItem.bind(this)),d.commands.registerCommand("platformio-debug.memory.clearHistory",this.memoryClearHistory.bind(this)),d.commands.registerCommand("platformio-debug.examineMemory",this.examineMemory.bind(this)),d.commands.registerCommand("platformio-debug.viewDisassembly",this.showDisassembly.bind(this)),d.commands.registerCommand("platformio-debug.setForceDisassembly",this.setForceDisassembly.bind(this)),d.debug.onDidReceiveDebugSessionCustomEvent(this.receivedCustomEvent.bind(this)),d.debug.onDidStartDebugSession(this.debugSessionStarted.bind(this)),d.debug.onDidTerminateDebugSession(this.debugSessionTerminated.bind(this)),d.window.onDidChangeActiveTextEditor(this.activeEditorChanged.bind(this)),d.window.onDidChangeTextEditorSelection(e=>{e&&e.textEditor.document.fileName.endsWith(".dbgmem")&&this.memoryContentProvider.handleSelection(e)}))}isPIODebugSession(){return d.debug.activeDebugSession&&"platformio-debug"===d.debug.activeDebugSession.type}activeEditorChanged(e){if(!e||!this.isPIODebugSession())return;const t=e.document.uri;"file"===t.scheme?d.debug.activeDebugSession.customRequest("set-active-editor",{path:t.path}):"disassembly"===t.scheme&&d.debug.activeDebugSession.customRequest("set-active-editor",{path:`${t.scheme}://${t.authority}${t.path}`})}showDisassembly(){return a(this,void 0,void 0,function*(){if(this.isPIODebugSession()){if(!this.functionSymbols)try{const e=yield d.debug.activeDebugSession.customRequest("load-function-symbols");this.functionSymbols=e.functionSymbols}catch(e){d.window.showErrorMessage("Unable to load symbol table. Disassembly view unavailable.")}try{const e=yield d.window.showInputBox({placeHolder:"main",ignoreFocusOut:!0,prompt:"Function Name to Disassemble"}),t=this.functionSymbols.filter(t=>t.name===e);let r;if(1===t.length)r=(0,l.encodeDisassembly)(t[0].name,t[0].file);else{if(!(t.length>1))return void d.window.showErrorMessage(`No function with name ${e} found.`);{const e=yield d.window.showQuickPick(t.map(e=>({label:e.name,name:e.name,file:e.file,scope:e.scope,description:e.scope===h.SymbolScope.Global?"Global Scope":`Static in ${e.file}`})),{ignoreFocusOut:!0});r=(0,l.encodeDisassembly)(e.name,e.file)}}r&&d.window.showTextDocument(d.Uri.parse(r))}catch(e){d.window.showErrorMessage("Unable to show disassembly.")}}else d.window.showErrorMessage("No debugging session available")})}setForceDisassembly(e){const t=e=>{const t="Forced"===e;return this.disassemblyTreeProvider.updateForcedState(t),d.debug.activeDebugSession.customRequest("set-force-disassembly",{force:t})};if(e)return t(e);d.window.showQuickPick([{label:"Auto",description:"Show disassembly for functions when source cannot be located."},{label:"Forced",description:"Always show disassembly for functions."}],{matchOnDescription:!0,ignoreFocusOut:!0}).then(e=>{t(e.label)},e=>{})}memoryDeleteHistoryItem(e){const[t,r]=e.label.split("+");this.memoryTreeProvider.deleteHistory(t,r)}memoryClearHistory(){this.memoryTreeProvider.clearHistory()}examineMemory(e,t){function r(e){return/^0x[0-9a-f]{1,8}$/i.test(e)||/^[0-9]+$/i.test(e)?e:null}if(this.isPIODebugSession())return e&&t?this.showMemoryContent(e,t):void d.window.showInputBox({placeHolder:"Prefix with 0x for hexidecimal format",ignoreFocusOut:!0,prompt:"A start memory address"}).then(e=>{r(e)?d.window.showInputBox({placeHolder:"Prefix with 0x for hexidecimal format",ignoreFocusOut:!0,prompt:"How many bytes to read?"}).then(t=>{r(t)?(this.memoryTreeProvider.pushHistory(e,t),this.showMemoryContent(e,t)):d.window.showErrorMessage("Invalid length entered")},e=>{}):d.window.showErrorMessage("Invalid memory address entered")},e=>{});d.window.showErrorMessage("No debugging session available")}showMemoryContent(e,t){d.workspace.openTextDocument(d.Uri.parse(`examinememory:///Memory%20[${e}+${t}].dbgmem?address=${e}&length=${t}&timestamp=${(new Date).getTime()}`)).then(e=>{d.window.showTextDocument(e,{viewColumn:2,preview:!1})},e=>{d.window.showErrorMessage(`Failed to examine memory: ${e}`)})}peripheralsUpdateNode(e){e.node.performUpdate().then(e=>{e&&this.peripheralProvider.refresh()},e=>{d.window.showErrorMessage(`Unable to update value: ${e.toString()}`)})}peripheralsSelectedNode(e){e.recordType!==g.RecordType.Field&&(e.expanded=!e.expanded),e.selected().then(e=>{e&&this.peripheralProvider.refresh()},e=>{})}peripheralsCopyValue(e){const t=e.node.getCopyValue();t&&d.env.clipboard.writeText(t)}peripheralsSetFormat(e){return a(this,void 0,void 0,function*(){const t=yield d.window.showQuickPick([{label:"Auto",description:"Automatically choose format (Inherits from parent)",value:h.NumberFormat.Auto},{label:"Hex",description:"Format value in hexidecimal",value:h.NumberFormat.Hexidecimal},{label:"Decimal",description:"Format value in decimal",value:h.NumberFormat.Decimal},{label:"Binary",description:"Format value in binary",value:h.NumberFormat.Binary}]);e.node.setFormat(t.value),this.peripheralProvider.refresh()})}registersSelectedNode(e){e.recordType!==b.RecordType.Field&&(e.expanded=!e.expanded)}registersCopyValue(e){const t=e.node.getCopyValue();t&&d.env.clipboard.writeText(t)}registersSetFormat(e){return a(this,void 0,void 0,function*(){const t=yield d.window.showQuickPick([{label:"Auto",description:"Automatically choose format (Inherits from parent)",value:h.NumberFormat.Auto},{label:"Hex",description:"Format value in hexidecimal",value:h.NumberFormat.Hexidecimal},{label:"Decimal",description:"Format value in decimal",value:h.NumberFormat.Decimal},{label:"Binary",description:"Format value in binary",value:h.NumberFormat.Binary}]);e.node.setFormat(t.value),this.registerProvider.refresh()})}debugSessionStarted(e){"platformio-debug"===e.type&&(this.functionSymbols=null,e.customRequest("get-arguments").then(e=>{this.registerProvider.debugSessionStarted(this.context.workspaceState.get("debugRegistersTreeState")),this.peripheralProvider.debugSessionStarted(e.svdPath,this.context.workspaceState.get("debugPeripheralsTreeState")),this.memoryTreeProvider.debugSessionStarted(this.context.workspaceState.get("debugMemoryTreeState")),this.disassemblyTreeProvider.debugSessionStarted()},e=>{console.error(e)}))}debugSessionTerminated(e){"platformio-debug"===e.type&&(this.context.workspaceState.update("debugRegistersTreeState",this.registerProvider.dumpSettings()),this.context.workspaceState.update("debugPeripheralsTreeState",this.peripheralProvider.dumpSettings()),this.context.workspaceState.update("debugMemoryTreeState",this.memoryTreeProvider.dumpSettings()),this.registerProvider.debugSessionTerminated(),this.peripheralProvider.debugSessionTerminated(),this.memoryTreeProvider.debugSessionTerminated(),this.disassemblyTreeProvider.debugSessionTerminated())}receivedCustomEvent(e){if(this.isPIODebugSession())switch(e.event){case"custom-stop":this.receivedStopEvent(e);break;case"custom-continued":this.receivedContinuedEvent(e);break;case"adapter-output":this.receivedAdapterOutput(e);break;case"record-event":this.receivedEvent(e)}}receivedStopEvent(e){this.peripheralProvider.debugStopped(),this.registerProvider.debugStopped(),d.workspace.textDocuments.filter(e=>e.fileName.endsWith(".dbgmem")).forEach(e=>{this.memoryContentProvider.update(e)})}receivedContinuedEvent(e){this.peripheralProvider.debugContinued(),this.registerProvider.debugContinued()}receivedEvent(e){}receivedAdapterOutput(e){this.adapterOutputChannel||(this.adapterOutputChannel=d.window.createOutputChannel("Adapter Output"));let t=e.body.content;t.endsWith("\n")||(t+="\n"),this.adapterOutputChannel.append(t)}}},22(e,t,r){var i,s=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var s=Object.getOwnPropertyDescriptor(t,r);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,s)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||(i=function(e){return i=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},i(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=i(e),o=0;o<r.length;o++)"default"!==r[o]&&s(t,e,r[o]);return n(t,e),t}),a=this&&this.__awaiter||function(e,t,r,i){return new(r||(r=Promise))(function(s,n){function o(e){try{d(i.next(e))}catch(e){n(e)}}function a(e){try{d(i.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(o,a)}d((i=i.apply(e,t||[])).next())})};Object.defineProperty(t,"__esModule",{value:!0}),t.PlatformIODebugConfigurationProvider=void 0;const d=o(r(850));t.PlatformIODebugConfigurationProvider=class{constructor(){}resolveDebugConfiguration(e,t,r){return a(this,void 0,void 0,function*(){return t.cwd=e?e.uri.fsPath:d.workspace.rootPath,t})}}},675(e,t,r){var i,s=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var s=Object.getOwnPropertyDescriptor(t,r);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,s)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||(i=function(e){return i=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},i(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=i(e),o=0;o<r.length;o++)"default"!==r[o]&&s(t,e,r[o]);return n(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.DisassemblyContentProvider=void 0;const a=o(r(850)),d=r(185);t.DisassemblyContentProvider=class{provideTextDocumentContent(e,t){return new Promise((t,r)=>{const i=(0,d.parseQuery)(e.query);a.debug.activeDebugSession.customRequest("disassemble",{function:i.func,file:i.file}).then(e=>{const r=e.instructions;let i="";r.forEach(e=>{i+=`${e.address}: ${this.padEnd(15,e.opcodes)} \t${e.instruction}\n`}),t(i)},e=>{a.window.showErrorMessage(e.message),r(e.message)})})}padEnd(e,t){for(let r=t.length;r<e;r++)t+=" ";return t}}},414(e,t,r){var i,s=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var s=Object.getOwnPropertyDescriptor(t,r);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,s)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||(i=function(e){return i=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},i(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=i(e),o=0;o<r.length;o++)"default"!==r[o]&&s(t,e,r[o]);return n(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.DisassemblyTreeProvider=void 0;const a=o(r(850));t.DisassemblyTreeProvider=class{constructor(){this._onDidChangeTreeData=new a.EventEmitter,this.onDidChangeTreeData=this._onDidChangeTreeData.event,this.forced=!1}refresh(){this._onDidChangeTreeData.fire()}getChildren(e){if(!a.debug.activeDebugSession)return[];const t=new a.TreeItem("Disassemble function");t.command={title:"Disassemble function",command:"platformio-debug.viewDisassembly"};const r="Switch to "+(this.forced?"code":"assembly"),i=new a.TreeItem(r);return i.command={title:r,command:"platformio-debug.setForceDisassembly",arguments:[this.forced?"Auto":"Forced"]},[t,i]}getTreeItem(e){return e}updateForcedState(e){this.forced=e,this.refresh()}debugSessionStarted(){this.refresh()}debugSessionTerminated(){this.updateForcedState(!1)}}},578(e,t,r){var i,s=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var s=Object.getOwnPropertyDescriptor(t,r);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,s)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||(i=function(e){return i=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},i(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=i(e),o=0;o<r.length;o++)"default"!==r[o]&&s(t,e,r[o]);return n(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.MemoryContentProvider=void 0;const a=o(r(850)),d=r(185);t.MemoryContentProvider=class{constructor(){this._onDidChange=new a.EventEmitter,this.onDidChange=this._onDidChange.event,this.firstBytePos=10,this.lastBytePos=this.firstBytePos+48-1,this.firstAsciiPos=this.lastBytePos+3,this.lastAsciiPos=this.firstAsciiPos+16,this.smallDecorationType=a.window.createTextEditorDecorationType({borderWidth:"1px",borderStyle:"solid",overviewRulerColor:"blue",overviewRulerLane:a.OverviewRulerLane.Right,light:{borderColor:"darkblue"},dark:{borderColor:"lightblue"}})}provideTextDocumentContent(e){return new Promise((t,r)=>{const i=(0,d.parseQuery)(e.query),s=i.address.startsWith("0x")?parseInt(i.address.substring(2),16):parseInt(i.address,10),n=i.length.startsWith("0x")?parseInt(i.length.substring(2),16):parseInt(i.length,10);a.debug.activeDebugSession.customRequest("read-memory",{address:s,length:n||32}).then(e=>{const r=e.bytes;let i=s-s%16;const o=s-i;let a="";a+=" Offset: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F \t\n",a+=(0,d.hexFormat)(i,8,!1)+": ";let h="";for(let e=0;e<o;e++)a+=" ",h+=" ";for(let e=0;e<n;e++){const t=r[e];a+=(0,d.hexFormat)(t,2,!1).toUpperCase()+" ",h+=t<=32||t>=127&&t<=159?".":String.fromCharCode(r[e]),(s+e)%16==15&&e<n-1&&(a+=" "+h,h="",a+="\n",i+=16,a+=(0,d.hexFormat)(i,8,!1)+": ")}const l=(16-(s+n)%16)%16;for(let e=0;e<l;e++)a+=" ";a+=" "+h,a+="\n",t(a)},e=>{a.window.showErrorMessage(`Unable to read memory from ${(0,d.hexFormat)(s,8)} to ${(0,d.hexFormat)(s+n,8)}`),r(e.toString())})})}update(e){this._onDidChange.fire(e.uri)}getOffset(e){if(e.line<1||e.character<this.firstBytePos)return;let t=16*(e.line-1);const r=e.character-this.firstBytePos;return e.character>=this.firstBytePos&&e.character<=this.lastBytePos?t+=Math.floor(r/3):e.character>=this.firstAsciiPos&&(t+=e.character-this.firstAsciiPos),t}getPosition(e,t=!1){const r=1+Math.floor(e/16);let i=e%16;return t?i+=this.firstAsciiPos:i=this.firstBytePos+3*i,new a.Position(r,i)}getRanges(e,t,r){const i=this.getPosition(e,r);let s=this.getPosition(t,r);s=new a.Position(s.line,s.character+(r?1:2));const n=[],o=r?this.firstAsciiPos:this.firstBytePos,d=r?this.lastAsciiPos:this.lastBytePos;for(let e=i.line;e<=s.line;++e){const t=new a.Position(e,e===i.line?i.character:o),r=new a.Position(e,e===s.line?s.character:d);n.push(new a.Range(t,r))}return n}handleSelection(e){const t=e.textEditor.document.lineCount;if(e.selections[0].start.line+1===t||e.selections[0].end.line+1===t)return void e.textEditor.setDecorations(this.smallDecorationType,[]);const r=this.getOffset(e.selections[0].start),i=this.getOffset(e.selections[0].end);if(void 0===r||void 0===i)return void e.textEditor.setDecorations(this.smallDecorationType,[]);let s=this.getRanges(r,i,!1);s=s.concat(this.getRanges(r,i,!0)),e.textEditor.setDecorations(this.smallDecorationType,s)}}},485(e,t,r){var i,s=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var s=Object.getOwnPropertyDescriptor(t,r);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,s)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||(i=function(e){return i=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},i(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=i(e),o=0;o<r.length;o++)"default"!==r[o]&&s(t,e,r[o]);return n(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.MemoryTreeProvider=void 0;const a=o(r(850));t.MemoryTreeProvider=class{constructor(){this._onDidChangeTreeData=new a.EventEmitter,this.onDidChangeTreeData=this._onDidChangeTreeData.event,this.history=[]}refresh(){this._onDidChangeTreeData.fire()}dumpSettings(){return this.history}getChildren(e){if(!a.debug.activeDebugSession)return[];if(this.history.length)return this.getHistoryNodes();const t=new a.TreeItem("Enter address...");return t.command={title:"Enter memory address...",command:"platformio-debug.examineMemory"},[t]}getHistoryNodes(){return this.history.map(e=>{const t=new a.TreeItem(e);return t.command={title:`Examine memory at ${e}`,command:"platformio-debug.examineMemory",arguments:e.split("+")},t})}getTreeItem(e){return e}pushHistory(e,t){const r=`${e}+${t}`;this.history.includes(r)||(this.history.push(r),this.refresh())}deleteHistory(e,t){const r=`${e}+${t}`;this.history.includes(r)&&(this.history=this.history.filter(e=>e!==r),this.refresh())}clearHistory(){this.history=[],this.refresh()}debugSessionStarted(e){this.history=e||[],this.refresh()}debugSessionTerminated(){this.history=[],this.refresh()}}},413(e,t,r){var i,s=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var s=Object.getOwnPropertyDescriptor(t,r);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,s)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||(i=function(e){return i=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},i(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=i(e),o=0;o<r.length;o++)"default"!==r[o]&&s(t,e,r[o]);return n(t,e),t}),a=this&&this.__awaiter||function(e,t,r,i){return new(r||(r=Promise))(function(s,n){function o(e){try{d(i.next(e))}catch(e){n(e)}}function a(e){try{d(i.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(o,a)}d((i=i.apply(e,t||[])).next())})};Object.defineProperty(t,"__esModule",{value:!0}),t.PeripheralTreeProvider=t.FieldNode=t.RegisterNode=t.ClusterNode=t.PeripheralNode=t.BaseNode=t.TreeNode=t.AccessType=t.RecordType=void 0;const d=o(r(896)),h=o(r(850)),l=o(r(602)),u=r(799),c=r(185);var m,p;!function(e){e[e.Peripheral=1]="Peripheral",e[e.Register=2]="Register",e[e.Field=3]="Field",e[e.Cluster=4]="Cluster"}(m||(t.RecordType=m={})),function(e){e[e.ReadOnly=1]="ReadOnly",e[e.ReadWrite=2]="ReadWrite",e[e.WriteOnly=3]="WriteOnly"}(p||(t.AccessType=p={}));const f={"read-only":p.ReadOnly,"write-only":p.WriteOnly,"read-write":p.ReadWrite,writeOnce:p.WriteOnly,"read-writeOnce":p.ReadWrite};class g extends h.TreeItem{constructor(e,t,r,i){super(e,t),this.label=e,this.collapsibleState=t,this.contextValue=r,this.node=i,this.command={command:"platformio-debug.peripherals.selectedNode",arguments:[i],title:"Selected Node"},this.tooltip=(i?i.description:void 0)||e}}t.TreeNode=g;class b{constructor(e){this.recordType=e,this.expanded=!1,this.format=u.NumberFormat.Auto}selected(){return Promise.resolve(!1)}update(){return Promise.resolve(!1)}performUpdate(){return Promise.resolve(!1)}getChildren(){return[]}getTreeNode(){return null}getCopyValue(){return null}setFormat(e){this.format=e}}function y(e){return/^0b([01]+)$/i.test(e)?parseInt(e.substring(2),2):/^0x([0-9a-f]+)$/i.test(e)?parseInt(e.substring(2),16):/^[0-9]+/i.test(e)?parseInt(e,10):/^#[0-1]+/i.test(e)?parseInt(e.substring(1),2):void 0}function v(e,t){if(-1!==e.indexOf(",")){const r=e.split(",").map(e=>e.trim());if(r.length!==t)throw new Error("dimIndex Element has invalid specification.");return r}if(/^([0-9]+)\-([0-9]+)$/i.test(e)){const r=e.split("-").map(e=>y(e)),i=r[0];if(r[1]-i+1<t)throw new Error("dimIndex Element has invalid specification.");const s=[];for(let e=0;e<t;e++)s.push(`${i+e}`);return s}if(/^[a-zA-Z]\-[a-zA-Z]$/.test(e)){const r=e.charCodeAt(0);if(e.charCodeAt(2)-r+1<t)throw new Error("dimIndex Element has invalid specification.");const i=[];for(let e=0;e<t;e++)i.push(String.fromCharCode(r+e));return i}return[]}t.BaseNode=b;class w{constructor(e,t,r){this.name=e,this.description=t,this.value=r}}class x extends b{constructor(e){super(m.Peripheral),this.children=[],this.name=e.name,this.description=e.description,this.baseAddress=e.baseAddress,this.totalLength=e.totalLength,this.groupName=e.groupName||"",this.resetValue=e.resetValue||0,this.size=e.size||32}getTreeNode(){const e=this.name+" ["+(0,c.hexFormat)(this.baseAddress)+"]";return new g(e,this.expanded?h.TreeItemCollapsibleState.Expanded:h.TreeItemCollapsibleState.Collapsed,"peripheral",this)}getChildren(){return this.children}setChildren(e){this.children=e,this.children.sort((e,t)=>e.offset>t.offset?1:-1)}addChild(e){this.children.push(e),this.children.sort((e,t)=>e.offset>t.offset?1:-1)}getBytes(e,t){try{return new Uint8Array(this.currentValue.slice(e,e+t))}catch(e){return new Uint8Array(0)}}getAddress(e){return this.baseAddress+e}getFormat(){return this.format}update(){return new Promise((e,t)=>{this.expanded?h.debug.activeDebugSession.customRequest("read-memory",{address:this.baseAddress,length:this.totalLength>32768?32768:this.totalLength}).then(t=>{this.currentValue=t.bytes,this.children.forEach(e=>e.update()),e(!0)},e=>{t(e)}):e(!1)})}selected(){return this.update()}dumpSettings(){const e=[];return(this.format!==u.NumberFormat.Auto||this.expanded)&&e.push({node:`${this.name}`,expanded:this.expanded,format:this.format}),this.children.forEach(t=>{e.push(...t.dumpSettings(`${this.name}`))}),e}_findByPath(e){if(0===e.length)return this;const t=this.children.find(t=>t.name===e[0]);return t?t._findByPath(e.slice(1)):null}}t.PeripheralNode=x;class P extends b{constructor(e,t){super(m.Cluster),this.parent=e,this.children=[],this.name=t.name,this.description=t.description,this.offset=t.addressOffset,this.accessType=t.accessType||p.ReadWrite,this.size=t.size||e.size,this.resetValue=t.resetValue||e.resetValue,this.parent.addChild(this)}getTreeNode(){const e=`${this.name} [${(0,c.hexFormat)(this.offset,0)}]`;return new g(e,this.expanded?h.TreeItemCollapsibleState.Expanded:h.TreeItemCollapsibleState.Collapsed,"cluster",this)}getChildren(){return this.children}setChildren(e){this.children=e.slice(0,e.length),this.children.sort((e,t)=>e.offset>t.offset?1:-1)}addChild(e){this.children.push(e),this.children.sort((e,t)=>e.offset>t.offset?1:-1)}getBytes(e,t){return this.parent.getBytes(this.offset+e,t)}getAddress(e){return this.parent.getAddress(this.offset+e)}getFormat(){return this.format!==u.NumberFormat.Auto?this.format:this.parent.getFormat()}update(){return Promise.resolve(!0)}dumpSettings(e){const t=[];return(this.format!==u.NumberFormat.Auto||this.expanded)&&t.push({node:`${e}.${this.name}`,expanded:this.expanded,format:this.format}),this.children.forEach(r=>{t.push(...r.dumpSettings(`${e}.${this.name}`))}),t}_findByPath(e){if(0===e.length)return this;const t=this.children.find(t=>t.name===e[0]);return t?t._findByPath(e.slice(1)):null}}t.ClusterNode=P;class S extends b{constructor(e,t){super(m.Register),this.parent=e,this.children=[],this.name=t.name,this.description=t.description,this.offset=t.addressOffset,this.accessType=t.accessType||e.accessType,this.size=t.size||e.size,this.resetValue=void 0!==t.resetValue?t.resetValue:e.resetValue,this.currentValue=this.resetValue,this.hexLength=Math.ceil(this.size/4),this.maxValue=Math.pow(2,this.size),this.binaryRegex=new RegExp(`^0b[01]{1,${this.size}}$`,"i"),this.hexRegex=new RegExp(`^0x[0-9a-f]{1,${this.hexLength}}$`,"i"),this.parent,this.parent.addChild(this)}reset(){this.currentValue=this.resetValue}extractBits(e,t){return(0,c.extractBits)(this.currentValue,e,t)}updateBits(e,t,r){return new Promise((i,s)=>{const n=Math.pow(2,t);if(r>n)return s(`Value entered is invalid. Maximum value for this field is ${n-1} (${(0,c.hexFormat)(n-1,0)})`);const o=(0,c.createMask)(e,t),a=r<<e,d=this.currentValue&~o|a;this.updateValueInternal(d).then(i,s)})}getTreeNode(){let e="registerRW";this.accessType===p.ReadOnly?e="registerRO":this.accessType===p.WriteOnly&&(e="registerWO");let t=`${this.name} [${(0,c.hexFormat)(this.offset,0)}]`;if(this.accessType===p.WriteOnly)t+=" - <Write Only>";else switch(this.getFormat()){case u.NumberFormat.Decimal:t+=` = ${this.currentValue.toString()}`;break;case u.NumberFormat.Binary:t+=` = ${(0,c.binaryFormat)(this.currentValue,4*this.hexLength,!1,!0)}`;break;default:t+=` = ${(0,c.hexFormat)(this.currentValue,this.hexLength)}`}const r=this.children&&this.children.length>0?this.expanded?h.TreeItemCollapsibleState.Expanded:h.TreeItemCollapsibleState.Collapsed:h.TreeItemCollapsibleState.None;return new g(t,r,e,this)}getChildren(){return this.children||[]}setChildren(e){this.children=e.slice(0,e.length),this.children.sort((e,t)=>e.offset>t.offset?1:-1)}addChild(e){this.children.push(e),this.children.sort((e,t)=>e.offset>t.offset?1:-1)}getFormat(){return this.format!==u.NumberFormat.Auto?this.format:this.parent.getFormat()}getCopyValue(){switch(this.getFormat()){case u.NumberFormat.Decimal:return this.currentValue.toString();case u.NumberFormat.Binary:return(0,c.binaryFormat)(this.currentValue,4*this.hexLength);default:return(0,c.hexFormat)(this.currentValue,this.hexLength)}}performUpdate(){return new Promise((e,t)=>{h.window.showInputBox({prompt:"Enter new value: (prefix hex with 0x, binary with 0b)"}).then(r=>{let i;if(r.match(this.hexRegex))i=parseInt(r.substr(2),16);else if(r.match(this.binaryRegex))i=parseInt(r.substr(2),2);else{if(!r.match(/^[0-9]+/))return t("Value entered is not a valid format.");if(i=parseInt(r,10),i>=this.maxValue)return t(`Value entered (${i}) is greater than the maximum value of ${this.maxValue}`)}this.updateValueInternal(i).then(e,t)})})}updateValueInternal(e){const t=this.parent.getAddress(this.offset),r=[],i=this.size/8;for(let t=0;t<i;t++){const i=255&e;e>>>=8;let s=i.toString(16);1===s.length&&(s="0"+s),r[t]=s}return new Promise((e,i)=>{h.debug.activeDebugSession.customRequest("write-memory",{address:t,data:r.join("")}).then(t=>{this.parent.update().then(()=>{},()=>{}),e(!0)},i)})}update(){const e=this.size/8,t=this.parent.getBytes(this.offset,e),r=Buffer.from(t);switch(e){case 1:this.currentValue=r.readUInt8(0);break;case 2:this.currentValue=r.readUInt16LE(0);break;case 4:this.currentValue=r.readUInt32LE(0);break;default:h.window.showErrorMessage(`Register ${this.name} has invalid size: ${this.size}. Should be 8, 16 or 32.`)}return this.children.forEach(e=>e.update()),Promise.resolve(!0)}dumpSettings(e){const t=[];return(this.format!==u.NumberFormat.Auto||this.expanded)&&t.push({node:`${e}.${this.name}`,expanded:this.expanded,format:this.format}),this.children.forEach(r=>{t.push(...r.dumpSettings(`${e}.${this.name}`))}),t}_findByPath(e){return 0===e.length?this:1===e.length?this.children.find(t=>t.name===e[0]):null}}t.RegisterNode=S;class O extends b{constructor(e,t){if(super(m.Field),this.parent=e,this.name=t.name,this.description=t.description,this.offset=t.offset,this.width=t.width,t.accessType?e.accessType===p.ReadOnly&&t.accessType!==p.ReadOnly?this.accessType=p.ReadOnly:e.accessType===p.WriteOnly&&t.accessType!==p.WriteOnly?this.accessType=p.WriteOnly:this.accessType=t.accessType:this.accessType=e.accessType,t.enumeration){this.enumeration=t.enumeration,this.enumerationMap={},this.enumerationValues=[];for(const e in t.enumeration){const r=t.enumeration[e].name;this.enumerationValues.push(r),this.enumerationMap[r]=e}}this.parent.addChild(this)}getTreeNode(){const e=this.parent.extractBits(this.offset,this.width);let t=null,r=this.name;const i=this.offset;let s="field";if(r+=`[${this.offset+this.width-1}:${i}]`,"reserved"===this.name.toLowerCase())s="field-res";else if(this.accessType===p.WriteOnly)r+=" - <Write Only>";else{let i="";switch(this.getFormat()){case u.NumberFormat.Decimal:i=e.toString();break;case u.NumberFormat.Binary:i=(0,c.binaryFormat)(e,this.width);break;case u.NumberFormat.Hexidecimal:i=(0,c.hexFormat)(e,Math.ceil(this.width/4),!0);break;default:i=this.width>=4?(0,c.hexFormat)(e,Math.ceil(this.width/4),!0):(0,c.binaryFormat)(e,this.width)}this.enumeration&&this.enumeration[e]?(t=this.enumeration[e],r+=` = ${t.name} (${i})`):r+=` = ${i}`}return this.parent.accessType===p.ReadOnly&&(s="field-ro"),new g(r,h.TreeItemCollapsibleState.None,s,this)}performUpdate(){return new Promise((e,t)=>{this.enumeration?h.window.showQuickPick(this.enumerationValues).then(r=>{if(void 0===r)return t("Input not selected");const i=this.enumerationMap[r];this.parent.updateBits(this.offset,this.width,i).then(e,t)}):h.window.showInputBox({prompt:"Enter new value: (prefix hex with 0x, binary with 0b)"}).then(r=>{const i=y(r);if(void 0===i)return t("Unable to parse input value.");this.parent.updateBits(this.offset,this.width,i).then(e,t)})})}getCopyValue(){const e=this.parent.extractBits(this.offset,this.width);switch(this.getFormat()){case u.NumberFormat.Decimal:return e.toString();case u.NumberFormat.Binary:return(0,c.binaryFormat)(e,this.width);case u.NumberFormat.Hexidecimal:return(0,c.hexFormat)(e,Math.ceil(this.width/4),!0);default:return this.width>=4?(0,c.hexFormat)(e,Math.ceil(this.width/4),!0):(0,c.binaryFormat)(e,this.width)}}getFormat(){return this.format!==u.NumberFormat.Auto?this.format:this.parent.getFormat()}dumpSettings(e){return this.format!==u.NumberFormat.Auto?[{node:`${e}.${this.name}`,format:this.format}]:[]}_findByPath(e){return 0===e.length?this:null}}t.FieldNode=O,t.PeripheralTreeProvider=class{constructor(){this._onDidChangeTreeData=new h.EventEmitter,this.onDidChangeTreeData=this._onDidChangeTreeData.event,this.peripherials=[],this.loaded=!1,this.viewExpanded=!1}refresh(){this._onDidChangeTreeData.fire()}dumpSettings(){const e=[];return this.peripherials.forEach(t=>{e.push(...t.dumpSettings())}),e}_parseFields(e,t){const r=[];return e.map(e=>{let i,s;const n=e.description?e.description[0]:"";if(e.bitOffset&&e.bitWidth)i=y(e.bitOffset[0]),s=y(e.bitWidth[0]);else if(e.bitRange){let t=e.bitRange[0];t=t.substring(1,t.length-1),t=t.split(":");const r=y(t[0]),n=y(t[1]);s=r-n+1,i=n}else{if(!e.msb||!e.lsb)throw new Error(`Unable to parse SVD file: field ${e.name[0]} must have either bitOffset and bitWidth elements, bitRange Element, or msb and lsb elements.`);{const t=y(e.msb[0]),r=y(e.lsb[0]);s=t-r+1,i=r}}let o=null;e.enumeratedValues&&(o={},e.enumeratedValues[0].enumeratedValue.map(e=>{if(e.value&&e.value.length>0){const t=e.name[0],r=e.description?e.description[0]:t,i=y(e.value[0].toLowerCase());o[i]=new w(t,r,i)}}));const a={name:e.name[0],description:n,offset:i,width:s,enumeration:o};if(e.dim){if(!e.dimIncrement)throw new Error(`Unable to parse SVD file: field ${e.name[0]} has dim element, with no dimIncrement element.`);const s=y(e.dim[0]),n=y(e.dimIncrement[0]);let o=[];if(e.dimIndex)o=v(e.dimIndex[0],s);else for(let e=0;e<s;e++)o.push(`${e}`);const d=e.name[0],h=i;for(let e=0;e<s;e++){const i=d.replace("%s",o[e]);r.push(new O(t,Object.assign(Object.assign({},a),{name:i,offset:h+n*e})))}}else r.push(new O(t,Object.assign({},a)))}),r}_parseRegisters(e,t){const r=[];return e.forEach(e=>{const i={};if(e.description&&(i.description=e.description[0]),e.access&&(i.accessType=f[e.access[0]]),e.size&&(i.size=y(e.size[0])),e.resetValue&&(i.resetValue=y(e.resetValue[0])),e.dim){if(!e.dimIncrement)throw new Error(`Unable to parse SVD file: register ${e.name[0]} has dim element, with no dimIncrement element.`);const s=y(e.dim[0]),n=y(e.dimIncrement[0]);let o=[];if(e.dimIndex)o=v(e.dimIndex[0],s);else for(let e=0;e<s;e++)o.push(`${e}`);const a=e.name[0],d=y(e.addressOffset[0]);for(let h=0;h<s;h++){const s=a.replace("%s",o[h]),l=new S(t,Object.assign(Object.assign({},i),{name:s,addressOffset:d+n*h}));e.fields&&1===e.fields.length&&this._parseFields(e.fields[0].field,l),r.push(l)}}else{const s=new S(t,Object.assign(Object.assign({},i),{name:e.name[0],addressOffset:y(e.addressOffset[0])}));e.fields&&1===e.fields.length&&this._parseFields(e.fields[0].field,s),r.push(s)}}),r.sort((e,t)=>e.offset<t.offset?-1:e.offset>t.offset?1:0),r}_parseClusters(e,t){const r=[];return e?(e.forEach(e=>{const i={};if(e.description&&(i.description=e.description[0]),e.access&&(i.accessType=f[e.access[0]]),e.size&&(i.size=y(e.size[0])),e.resetValue&&(i.resetValue=y(e.resetValue)),e.dim){if(!e.dimIncrement)throw new Error(`Unable to parse SVD file: cluster ${e.name[0]} has dim element, with no dimIncrement element.`);const s=y(e.dim[0]),n=y(e.dimIncrement[0]);let o=[];if(e.dimIndex)o=v(e.dimIndex[0],s);else for(let e=0;e<s;e++)o.push(`${e}`);const a=e.name[0],d=y(e.addressOffset[0]);for(let h=0;h<s;h++){const s=a.replace("%s",o[h]),l=new P(t,Object.assign(Object.assign({},i),{name:s,addressOffset:d+n*h}));e.register&&this._parseRegisters(e.register,l),r.push(l)}}else{const s=new P(t,Object.assign(Object.assign({},i),{name:e.name[0],addressOffset:y(e.addressOffset[0])}));e.register&&(this._parseRegisters(e.register,s),r.push(s))}}),r):[]}_parsePeripheral(e,t){const r=y(e.addressBlock[0].size[0]),i={name:e.name[0],baseAddress:y(e.baseAddress[0]),description:e.description[0],totalLength:r};e.access&&(i.accessType=f[e.access[0]]),e.size&&(i.size=y(e.size[0])),e.resetValue&&(i.resetValue=y(e.resetValue[0])),e.groupName&&(i.groupName=e.groupName[0]);const s=new x(i);return e.registers[0].register&&this._parseRegisters(e.registers[0].register,s),e.registers[0].cluster&&this._parseClusters(e.registers[0].cluster,s),s}_loadSVD(e){return new Promise((t,r)=>{d.readFile(e,"utf8",(e,i)=>{if(e)return r(e);l.parseString(i,(e,i)=>{if(e)return r(e);try{const e={},r={accessType:p.ReadWrite,size:32,resetValue:0};i.device.resetValue&&(r.resetValue=y(i.device.resetValue[0])),i.device.size&&(r.size=y(i.device.size[0])),i.device.access&&(r.accessType=f[i.device.access[0]]),i.device.peripherals[0].peripheral.forEach(t=>{const r=t.name[0];e[r]=t});for(const t in e){const r=e[t];if(r.$&&r.$.derivedFrom){const i=e[r.$.derivedFrom];e[t]=Object.assign(Object.assign({},i),r)}}this.peripherials=[];for(const t in e)this.peripherials.push(this._parsePeripheral(e[t],r));return this.peripherials.sort((e,t)=>e.groupName>t.groupName?1:e.groupName<t.groupName?-1:e.name>t.name?1:e.name<t.name?-1:0),t(!0)}catch(e){return r(e)}})})})}_findNodeByPath(e){const t=e.split("."),r=this.peripherials.find(e=>e.name===t[0]);return r?r._findByPath(t.slice(1)):null}getTreeItem(e){return e}getChildren(e){return this.viewExpanded=!0,h.debug.activeDebugSession?this.peripherials.length>0?e?e.node.getChildren().map(e=>e.getTreeNode()):this.peripherials.map(e=>e.getTreeNode()):(this.loaded||this._update(),[new g(this.svdPath?"Loading...":"No Information",h.TreeItemCollapsibleState.None,"message",null)]):[]}_load(){return a(this,void 0,void 0,function*(){if(this.svdPath)return this.loaded=!0,this.peripherials=[],new Promise(e=>{setTimeout(()=>a(this,void 0,void 0,function*(){try{yield this._loadSVD(this.svdPath),this.initialSettings&&this.initialSettings.forEach(e=>{const t=this._findNodeByPath(e.node);t&&(t.expanded=e.expanded||!1,t.format=e.format)})}catch(e){this.peripherials=[],h.window.showErrorMessage(`Unable to parse SVD file: ${e.toString()}`)}e(!0)}),1e3)})})}_update(){return a(this,void 0,void 0,function*(){if(this.viewExpanded){this.loaded||(yield this._load());try{yield Promise.all(this.peripherials.map(e=>e.update()))}catch(e){}this.refresh()}})}onDidExpandElement(e){e.element.node.expanded=!0,e.element.node.update(),this.refresh()}onDidCollapseElement(e){e.element.node.expanded=!1}debugSessionStarted(e,t){this.peripherials=[],this.loaded=!1,this.svdPath=e,this.initialSettings=t}debugSessionTerminated(){this.peripherials=[],this.loaded=!1,this.refresh()}debugStopped(){return this._update()}debugContinued(){}}},307(e,t,r){var i,s=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var s=Object.getOwnPropertyDescriptor(t,r);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,s)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||(i=function(e){return i=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},i(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=i(e),o=0;o<r.length;o++)"default"!==r[o]&&s(t,e,r[o]);return n(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.RegisterTreeProvider=t.FieldNode=t.RegisterNode=t.BaseNode=t.TreeNode=t.RecordType=void 0;const a=o(r(850)),d=r(799),h=r(185);var l;!function(e){e[e.Register=0]="Register",e[e.Field=1]="Field"}(l||(t.RecordType=l={}));class u extends a.TreeItem{constructor(e,t,r,i){super(e,t),this.label=e,this.collapsibleState=t,this.contextValue=r,this.node=i,this.command={command:"platformio-debug.registers.selectedNode",arguments:[i],title:"Selected Node"}}}t.TreeNode=u;class c{constructor(e){this.recordType=e,this.format=d.NumberFormat.Auto,this.expanded=!1}getChildren(){return[]}getTreeNode(){return null}getCopyValue(){return null}setFormat(e){this.format=e}}t.BaseNode=c;class m extends c{constructor(e,t){super(l.Register),this.name=e,this.index=t,"XPSR"===e.toUpperCase()||"CPSR"===e.toUpperCase()?this.fields=[new p("Negative Flag (N)",31,1,this),new p("Zero Flag (Z)",30,1,this),new p("Carry or borrow flag (C)",29,1,this),new p("Overflow Flag (V)",28,1,this),new p("Saturation Flag (Q)",27,1,this),new p("GE",16,4,this),new p("Interrupt Number",0,8,this),new p("ICI/IT",25,2,this),new p("ICI/IT",10,6,this),new p("Thumb State (T)",24,1,this)]:"CONTROL"===e.toUpperCase()&&(this.fields=[new p("FPCA",2,1,this),new p("SPSEL",1,1,this),new p("nPRIV",0,1,this)]),this.currentValue=0}extractBits(e,t){return(0,h.extractBits)(this.currentValue,e,t)}getTreeNode(){let e=`${this.name} = `;switch(this.getFormat()){case d.NumberFormat.Decimal:e+=this.currentValue.toString();break;case d.NumberFormat.Binary:e+=(0,h.binaryFormat)(this.currentValue,32,!1,!0);break;default:e+=(0,h.hexFormat)(this.currentValue,8)}return this.fields&&this.fields.length>0?new u(e,this.expanded?a.TreeItemCollapsibleState.Expanded:a.TreeItemCollapsibleState.Collapsed,"register",this):new u(e,a.TreeItemCollapsibleState.None,"register",this)}getChildren(){return this.fields}setValue(e){this.currentValue=e}getCopyValue(){switch(this.getFormat()){case d.NumberFormat.Decimal:return this.currentValue.toString();case d.NumberFormat.Binary:return(0,h.binaryFormat)(this.currentValue,32);default:return(0,h.hexFormat)(this.currentValue,8)}}getFormat(){return this.format}dumpSettings(){const e=[];return(this.expanded||this.format!==d.NumberFormat.Auto)&&e.push({node:this.name,format:this.format,expanded:this.expanded}),this.fields&&e.push(...this.fields.map(e=>e.dumpSettings()).filter(e=>null!==e)),e}}t.RegisterNode=m;class p extends c{constructor(e,t,r,i){super(l.Field),this.name=e,this.offset=t,this.size=r,this.register=i}getTreeNode(){const e=this.register.extractBits(this.offset,this.size);let t=`${this.name} = `;switch(this.getFormat()){case d.NumberFormat.Decimal:t+=e.toString();break;case d.NumberFormat.Binary:t+=(0,h.binaryFormat)(e,this.size,!1,!0);break;case d.NumberFormat.Hexidecimal:t+=(0,h.hexFormat)(e,Math.ceil(this.size/4),!0);break;default:t+=this.size>=4?(0,h.hexFormat)(e,Math.ceil(this.size/4),!0):(0,h.binaryFormat)(e,this.size,!1,!0)}return new u(t,a.TreeItemCollapsibleState.None,"field",this)}getCopyValue(){const e=this.register.extractBits(this.offset,this.size);switch(this.getFormat()){case d.NumberFormat.Decimal:return e.toString();case d.NumberFormat.Binary:return(0,h.binaryFormat)(e,this.size);case d.NumberFormat.Hexidecimal:return(0,h.hexFormat)(e,Math.ceil(this.size/4),!0);default:return this.size>=4?(0,h.hexFormat)(e,Math.ceil(this.size/4),!0):(0,h.binaryFormat)(e,this.size)}}getFormat(){return this.format===d.NumberFormat.Auto?this.register.getFormat():this.format}dumpSettings(){return this.format!==d.NumberFormat.Auto?{node:`${this.register.name}.${this.name}`,format:this.format}:null}}t.FieldNode=p,t.RegisterTreeProvider=class{constructor(){this._onDidChangeTreeData=new a.EventEmitter,this.onDidChangeTreeData=this._onDidChangeTreeData.event,this.loaded=!1,this.viewExpanded=!1,this.registers=[],this.registerMap={}}refresh(){this._onDidChangeTreeData.fire()}dumpSettings(){const e=[];return this.registers.forEach(t=>{e.push(...t.dumpSettings())}),e}fetchRegisterList(){a.debug.activeDebugSession&&(this.loaded?this._fetchRegisterValues():a.debug.activeDebugSession.customRequest("read-register-list").then(e=>{this.loaded=!0,this.createRegisters(e),this._fetchRegisterValues()}))}_fetchRegisterValues(){a.debug.activeDebugSession.customRequest("read-registers").then(e=>{e.forEach(e=>{const t=parseInt(e.number,10),r=parseInt(e.value,16),i=this.registerMap[t];i&&i.setValue(r)}),this.refresh()})}getTreeItem(e){return e}createRegisters(e){this.registerMap={},this.registers=[],e.forEach((e,t)=>{if(e){const r=new m(e,t);this.registers.push(r),this.registerMap[t]=r}}),this.initialSettings&&this.initialSettings.forEach(e=>{if(-1===e.node.indexOf(".")){const t=this.registers.find(t=>t.name===e.node);t&&(e.expanded&&(t.expanded=e.expanded),e.format&&t.setFormat(e.format))}else{const[t,r]=e.node.split("."),i=this.registers.find(e=>e.name===t);if(i){const t=i.getChildren().find(e=>e.name===r);t&&e.format&&t.setFormat(e.format)}}}),this.refresh()}updateRegisterValues(e){e.forEach(e=>{this.registerMap[e.number].setValue(e.value)}),this.refresh()}getChildren(e){return this.viewExpanded=!0,a.debug.activeDebugSession?this.registers.length>0?e?e.node.getChildren().map(e=>e.getTreeNode()):this.registers.map(e=>e.getTreeNode()):(this.loaded||setTimeout(()=>this.fetchRegisterList(),1e3),[new u("Loading...",a.TreeItemCollapsibleState.None,"message",null)]):[]}debugSessionTerminated(){this.loaded=!1,this.registers=[],this.registerMap={},this.refresh()}debugSessionStarted(e){this.loaded=!1,this.registers=[],this.registerMap={},this.initialSettings=e}debugStopped(){this.viewExpanded&&this.fetchRegisterList()}debugContinued(){}}},185(e,t){function r(e,t){let r=0;const i=e+t-1;for(let t=e;t<=i;t++)r=(r|1<<t)>>>0;return r}Object.defineProperty(t,"__esModule",{value:!0}),t.hexFormat=function(e,t=8,r=!0){let i=e.toString(16);for(;i.length<t;)i="0"+i;return r?"0x"+i:i},t.binaryFormat=function(e,t=0,r=!0,i=!1){let s=(e>>>0).toString(2);for(;s.length<t;)s="0"+s;if(i){const e=4-s.length%4;for(let t=0;t<e;t++)s="0"+s;const t=s.match(/[01]{4}/g);s=t.join(" "),s=s.substring(e)}return r?"0b"+s:s},t.createMask=r,t.extractBits=function(e,t,i){return(e&r(t,i))>>>t>>>0},t.parseQuery=function(e){const t={},r=("?"===e[0]?e.substr(1):e).split("&");for(const e of r){const r=e.split("=");t[decodeURIComponent(r[0])]=decodeURIComponent(r[1]||"")}return t},t.encodeDisassembly=function(e,t){let r="disassembly:///";return t&&(r+=`${t}:`),r+=`${e}.dbgasm?func=${e}&file=${t||""}`,r}},896(e){e.exports=require("fs")},161(t){t.exports=e},850(e){e.exports=t},602(e){e.exports=r}},s={};return function e(t){var r=s[t];if(void 0!==r)return r.exports;var n=s[t]={exports:{}};return i[t].call(n.exports,n,n.exports,e),n.exports}(265)})());