输入新代码块时,windbg 别名真的会扩展吗?

Does windbg aliases really be expanded when a new block of code is entered?

"An alias consists of an alias name and an alias equivalent. When you use an alias name as part of a debugger command, the name is automatically replaced by the alias equivalent. This replacement occurs immediately, before the command is parsed or executed." 以上均来自windbg帮助文档。以下是我的windbg脚本文件内容

ad /q *
;aS MyVar 0x7b;
.block
{
    ;aS /x ${/v:MyVar}  ${MyVar}+0x1;
    .block
    {
        .printf "MyVar1=0x%x\n",${MyVar};
        .block
        {
            .printf "MyVar2=0x%x\n",${MyVar};
        }
        .printf "MyVar3=0x%x\n",${MyVar};
    }

    .block
    {
        .printf "MyVar4=0x%x\n",${MyVar};
    }

}
.block
{
    .printf "MyVar5=0x%x\n",${MyVar};
}

al;

下面是执行该脚本的结果。

0:000> $$><c:\windbg.wds
MyVar1=0x7b
MyVar2=0x7b
MyVar3=0x7b
MyVar4=0x7b
MyVar5=0x7c
  Alias            Value  
 -------          ------- 
 MyVar            0x7c

不知道为什么会出现前四行的结果,特来求助

来自 WinDbg aS 帮助:

Note that if the portion of the line after the semicolon requires expansion of the alias, you must enclose that second portion of the line in a new block.

来自 WinDbg .block 帮助:

When each block is entered, all aliases within the block are evaluated. If you alter the value of an alias at some point within a command block, commands subsequent to that point will not use the new alias value unless they are within a subordinate block.

其中subordinate显然有following的意思而不是nested.

是的,您发现了 WinDbg 脚本语言的另一个限制。我建议查看 PyKd 或类似的替代方案。