如何在 Windbg 预览中的文件之间共享 Javascript 代码? [英] How do I share Javascript code between files in Windbg preview?

查看:25
本文介绍了如何在 Windbg 预览中的文件之间共享 Javascript 代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Windbg 预览中的文件之间共享 Javascript 代码?

How do I share Javascript code between files in Windbg preview?

现在我有几个辅助方法,我已经将它们复制并粘贴到不同的 javascript 文件中.我对 javascript 不是很熟悉,所以如果这是一个愚蠢的问题,我深表歉意.

Right now I have several helper methods that I have copied and pasted into different javascript files. I'm not all that experienced with javascript, so my apologies if this is a stupid question.

举个例子,假设我想在多个文件中使用这个函数:

As an example, let's say I want to use this function in more than one file:

function GetGuid( objectPtr )
{
    return ExecuteCommandToString( "dt nt!_GUID " + objectPtr )
    .FindLineContaining("{").trim().replace("{", "").replace("}","");
}

推荐答案

我有一个 common.js,它有一些通常可重用的功能,例如host.diagnostics.debugLog()

I have a common.js which has a few functions that are normally reusable like host.diagnostics.debugLog()

我首先使用 .scriptload 加载它

i first load it using .scriptload

然后在其他js文件中我为这些函数创建一个var并使用它

then in other js files I create a var to those functions and use it

看看是否有帮助

常用函数文件内容

C:\>cat c:\wdscr\common.js
function log(instr) {
    host.diagnostics.debugLog(instr + "\n");
}
function exec (cmdstr){
    return host.namespace.Debugger.Utility.Control.ExecuteCommand(cmdstr);
}

使用common.js函数的js文件

C:\>cat c:\wdscr\usecommon.js
function foo(){
    var commonlog = host.namespace.Debugger.State.Scripts.common.Contents.log
    var commonexec = host.namespace.Debugger.State.Scripts.common.Contents.exec
    commonlog("we are using the logging function from the common.js file")

    var blah = commonexec("lma @$exentry")
    for(var a of blah) {
        commonlog(a)
    }
}

实际使用

C:\>cdb calc
Microsoft (R) Windows Debugger Version 10.0.16299.15 X86

0:000> .load jsprovider

0:000> .scriptload c:\wdscr\common.js
JavaScript script successfully loaded from 'c:\wdscr\common.js'

0:000> .scriptload c:\wdscr\usecommon.js
JavaScript script successfully loaded from 'c:\wdscr\usecommon.js'

0:000> dx @$scriptContents.foo()

we are using the logging function from the common.js file 
start    end        module name
00f10000 00fd0000   calc       (deferred)
@$scriptContents.foo()
0:000>

这篇关于如何在 Windbg 预览中的文件之间共享 Javascript 代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆