I have a couple of JavaScript scripts to house my functions (for modularity and reuse). I load them both from the windbg script I'm running. From within one script, how do I call a function defined in the other?
This engine doesn't seem to support the import/export feature employed by browsers.
From within the debugger script, I have to use @$scriptContents
to access JavaScript functions.
How do I accomplish something similar from within one of the JavaScript functions?
Experiment
I was hoping there would be some sort of global namespace for all JavaScript functions, but it appears not.
Consider
// t1.js
function func1() {
host.diagnostics.debugLog('func1()...\n');
}
and
// t2.js
function func2() {
host.diagnostics.debugLog('func2()...\n');
func1();
}
In my cdb session
0:000> .load jsprovider.dll
0:000> .scriptload t1.js
JavaScript script successfully loaded from 't1.js'
0:000> .scriptload t2.js
JavaScript script successfully loaded from 't2.js'
0:000> dx @$scriptContents.func1()
func1()...
@$scriptContents.func1()
0:000> dx @$scriptContents.func2()
func2()...
Error: 'func1' is not defined [at t2 (line 3 col 5)]
Edit
Per @Mosè Raguzzini's comment and this answer, I went looking for some way to reference "foreign" functions. I eventually unearthed this
host.namespace.Debugger.State.DebuggerVariables.scriptContents
as a container for all functions. Is this documented somewhere? Is there no simpler way to get there? (I realize I can just assign a short variable to that object; I'm just suspicious this this is more of a backdoor into something with a very simple front door, but I don't know where the front door is.)