From 661a9f5cd72ddf4dc526bfaa32b339cecf71575d Mon Sep 17 00:00:00 2001 From: Peli Date: Sat, 18 Apr 2020 19:55:13 -0700 Subject: [PATCH 1/2] injecting envornment globals in debugger --- localtypings/pxtparts.d.ts | 1 + pxtsim/debugger.ts | 11 ++++++++++ pxtsim/runtime.ts | 5 ++++- webapp/src/debuggerVariables.tsx | 35 +++++++++++++++++++++++--------- 4 files changed, 41 insertions(+), 11 deletions(-) diff --git a/localtypings/pxtparts.d.ts b/localtypings/pxtparts.d.ts index 418c501b4885..f73f4a194270 100644 --- a/localtypings/pxtparts.d.ts +++ b/localtypings/pxtparts.d.ts @@ -179,6 +179,7 @@ declare namespace pxsim { export interface DebuggerBreakpointMessage extends DebuggerMessage { breakpointId: number; globals: Variables; + environmentGlobals?: Variables; stackframes: StackFrameInfo[]; exceptionMessage?: string; exceptionStack?: string; diff --git a/pxtsim/debugger.ts b/pxtsim/debugger.ts index aae9c13d94e7..badc622a00f9 100644 --- a/pxtsim/debugger.ts +++ b/pxtsim/debugger.ts @@ -177,6 +177,17 @@ namespace pxsim { return stackFrame.retval; } + export function injectEnvironmentGlobals(msg: DebuggerBreakpointMessage, heap: Map) { + const environmentGlobals = runtime.environmentGlobals; + const keys = Object.keys(environmentGlobals); + if (!keys.length) + return; + + const envVars: Variables = msg.environmentGlobals = {}; + Object.keys(environmentGlobals) + .forEach(n => envVars[n] = valToJSON(runtime.environmentGlobals[n], heap)) + } + export function getBreakpointMsg(s: pxsim.StackFrame, brkId: number, userGlobals?: string[]): { msg: DebuggerBreakpointMessage, heap: Map } { const heap: pxsim.Map = {}; diff --git a/pxtsim/runtime.ts b/pxtsim/runtime.ts index 8edb85c52c02..9db434878846 100644 --- a/pxtsim/runtime.ts +++ b/pxtsim/runtime.ts @@ -633,6 +633,7 @@ namespace pxsim { lastPauseTimestamp = 0; id: string; globals: any = {}; + environmentGlobals: any = {}; currFrame: StackFrame; otherFrames: StackFrame[] = []; entry: LabelFn; @@ -1135,6 +1136,7 @@ namespace pxsim { const { msg, heap } = getBreakpointMsg(s, brkId, userGlobals); dbgHeap = heap; + injectEnvironmentGlobals(msg, heap); Runtime.postMessage(msg) breakpoints[0] = 0; breakFrame = null; @@ -1276,7 +1278,8 @@ namespace pxsim { __this.errorHandler(e) else { console.error("Simulator crashed, no error handler", e.stack) - const { msg } = getBreakpointMsg(p, p.lastBrkId, userGlobals) + const { msg, heap } = getBreakpointMsg(p, p.lastBrkId, userGlobals) + injectEnvironmentGlobals(msg, heap); msg.exceptionMessage = e.message msg.exceptionStack = e.stack Runtime.postMessage(msg) diff --git a/webapp/src/debuggerVariables.tsx b/webapp/src/debuggerVariables.tsx index f3182fca7ee0..58513897605c 100644 --- a/webapp/src/debuggerVariables.tsx +++ b/webapp/src/debuggerVariables.tsx @@ -19,7 +19,7 @@ interface Variable { children?: Variable[]; } -interface DebuggerVariablesProps { +interface DebuggerVariablesProps { apis: pxt.Map; sequence: number; breakpoint?: pxsim.DebuggerBreakpointMessage; @@ -67,7 +67,7 @@ export class DebuggerVariables extends data.Component - { tableRows } + {tableRows} } @@ -137,8 +137,12 @@ export class DebuggerVariables extends data.Component filters.indexOf(v.name) !== -1) } - + // inject unfiltered environment variables + if (environmentGlobals) + updatedGlobals.variables = updatedGlobals.variables.concat(variablesToVariableList(environmentGlobals)); + assignVarIds(updatedGlobals.variables); let updatedFrames: ScopeVariables[]; - if (stackFrames) { + if (stackframes) { const oldFrames = this.state.stackFrames; - updatedFrames = stackFrames.map((sf, index) => { + updatedFrames = stackframes.map((sf, index) => { const key = sf.breakpointId + "_" + index; for (const frame of oldFrames) { @@ -219,7 +226,7 @@ export class DebuggerVariables extends data.Component { result.push(v); if (v.children) { @@ -261,8 +268,16 @@ export class DebuggerVariables extends data.Component ({ + name: fixVarName(varName), + value: newVars[varName] + })); + return current; +} + function updateScope(lastScope: ScopeVariables, newVars: pxsim.Variables, params?: Variable[]): ScopeVariables { - let current = Object.keys(newVars).map(varName => ({ name: fixVarName(varName), value: newVars[varName] })); + let current = variablesToVariableList(newVars); if (params) { current = params.concat(current); From a913b40c9e39484d793c4b4cb0761ee9dca5c657 Mon Sep 17 00:00:00 2001 From: peli Date: Mon, 20 Apr 2020 08:04:09 -0700 Subject: [PATCH 2/2] lint --- webapp/src/debuggerVariables.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/src/debuggerVariables.tsx b/webapp/src/debuggerVariables.tsx index 58513897605c..fa8b49cd70d9 100644 --- a/webapp/src/debuggerVariables.tsx +++ b/webapp/src/debuggerVariables.tsx @@ -157,7 +157,7 @@ export class DebuggerVariables extends data.Component