如何在一个命令中禁用cdb中显式命名的异常?

时间:2011-04-29 10:32:57

标签: windbg

sx系列命令接受异常/事件的名称,如av,异常代码或*。

事情是*捕获所有未命名的异常。如果我想在发生任何异常时执行命令,无论是否明确命名,该怎么办?

例如,

sxe -c "bla-bla-bla" -c2 "ku-ku-ku" av
sxe -c "bla-bla-bla" -c2 "ku-ku-ku" dz
sxe -c "bla-bla-bla" -c2 "ku-ku-ku" *

指示调试器:

  • 第一次机会访问违规时执行bla-bla-bla命令
  • 第二次机会访问违规执行ku-ku-ku命令
  • 执行bla-bla-bla命令对第一次机会除零
  • 在第二次机会分区上执行ku-ku-ku命令
  • 对任何未命名的第一次机会异常执行bla-bla-bla命令
  • 对任何未命名的第二次机会异常执行ku-ku-ku命令

但是,大约有两十个命名异常,如果我希望在每个异常执行这些命令,我​​似乎应该为每个异常重复相同的sxe语句,只更改异常名称

有更好的方法吗?

感谢。

EDIT1

这是实际的CDB脚本,我使用命令:

as AdpDumpDir C:\Logs\Crash
!adplusext.adpextstart AdpDumpDir
as /c AdpProcID !adplusext.adpprocid
as /c AdpHostComputer !adplusext.adphostcomputer
as /c AdpTargetComputer !adplusext.adptargetcomputer
as /c AdpProcName !adplusext.adpprocname
.logopen /t ${AdpDumpDir}\${AdpProcName}.log
version
al
.symfix+ C:\Users\markk\AppData\Local\Temp\SymbolCache
.sympath
.reload
as ExcCode av
as ExcName AccessViolation
sxe -c @".dump /u /ma /c FirstChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_FirstChance_${ExcCode}_${ExcName}_.dmp;GN" -c2 @".dump /u /ma /c SecondChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_SecondChance_${ExcCode}_${ExcName}_.dmp;GN" ${ExcCode}
as ExcCode asrt
as ExcName AssertionFailure
sxe -c @".dump /u /ma /c FirstChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_FirstChance_${ExcCode}_${ExcName}_.dmp;GN" -c2 @".dump /u /ma /c SecondChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_SecondChance_${ExcCode}_${ExcName}_.dmp;GN" ${ExcCode}
as ExcCode aph
as ExcName ApplicationHang
sxe -c @".dump /u /ma /c FirstChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_FirstChance_${ExcCode}_${ExcName}_.dmp;GN" -c2 @".dump /u /ma /c SecondChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_SecondChance_${ExcCode}_${ExcName}_.dmp;GN" ${ExcCode}
as ExcCode eh
as ExcName C++EH
sxe -c "gn" -c2 @".dump /u /ma /c SecondChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_SecondChance_${ExcCode}_${ExcName}_.dmp;GN" ${ExcCode}
as ExcCode clr
as ExcName CLR
sxe -c "gn" -c2 @".dump /u /ma /c SecondChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_SecondChance_${ExcCode}_${ExcName}_.dmp;GN" ${ExcCode}
as ExcCode clrn
as ExcName CLRNotification
sxe -c "gn" -c2 @".dump /u /ma /c SecondChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_SecondChance_${ExcCode}_${ExcName}_.dmp;GN" ${ExcCode}
as ExcCode dm
as ExcName DataMisaligned
sxe -c @".dump /u /ma /c FirstChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_FirstChance_${ExcCode}_${ExcName}_.dmp;GN" -c2 @".dump /u /ma /c SecondChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_SecondChance_${ExcCode}_${ExcName}_.dmp;GN" ${ExcCode}
as ExcCode gp
as ExcName GuardPageViolation
sxe -c @".dump /u /ma /c FirstChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_FirstChance_${ExcCode}_${ExcName}_.dmp;GN" -c2 @".dump /u /ma /c SecondChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_SecondChance_${ExcCode}_${ExcName}_.dmp;GN" ${ExcCode}
as ExcCode ii
as ExcName IllegalInstruction
sxe -c "gn" -c2 @".dump /u /ma /c SecondChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_SecondChance_${ExcCode}_${ExcName}_.dmp;GN" ${ExcCode}
as ExcCode ip
as ExcName InPageIOError
sxe -c "gn" -c2 @".dump /u /ma /c SecondChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_SecondChance_${ExcCode}_${ExcName}_.dmp;GN" ${ExcCode}
as ExcCode dz
as ExcName DivideByZero
sxe -c @".dump /u /ma /c FirstChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_FirstChance_${ExcCode}_${ExcName}_.dmp;GN" -c2 @".dump /u /ma /c SecondChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_SecondChance_${ExcCode}_${ExcName}_.dmp;GN" ${ExcCode}
as ExcCode iov
as ExcName IntegerOverflow
sxe -c @".dump /u /ma /c FirstChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_FirstChance_${ExcCode}_${ExcName}_.dmp;GN" -c2 @".dump /u /ma /c SecondChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_SecondChance_${ExcCode}_${ExcName}_.dmp;GN" ${ExcCode}
as ExcCode ch
as ExcName InvalidHandle
sxe -c @".dump /u /ma /c FirstChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_FirstChance_${ExcCode}_${ExcName}_.dmp;GN" -c2 @".dump /u /ma /c SecondChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_SecondChance_${ExcCode}_${ExcName}_.dmp;GN" ${ExcCode}
as ExcCode lsq
as ExcName InvalidLockSequence
sxe -c @".dump /u /ma /c FirstChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_FirstChance_${ExcCode}_${ExcName}_.dmp;GN" -c2 @".dump /u /ma /c SecondChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_SecondChance_${ExcCode}_${ExcName}_.dmp;GN" ${ExcCode}
as ExcCode isc
as ExcName InvalidSystemCall
sxe -c @".dump /u /ma /c FirstChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_FirstChance_${ExcCode}_${ExcName}_.dmp;GN" -c2 @".dump /u /ma /c SecondChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_SecondChance_${ExcCode}_${ExcName}_.dmp;GN" ${ExcCode}
as ExcCode 3c
as ExcName PortDisconnected
sxe -c "gn" -c2 @".dump /u /ma /c SecondChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_SecondChance_${ExcCode}_${ExcName}_.dmp;GN" ${ExcCode}
as ExcCode svh
as ExcName ServiceHang
sxe -c @".dump /u /ma /c FirstChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_FirstChance_${ExcCode}_${ExcName}_.dmp;GN" -c2 @".dump /u /ma /c SecondChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_SecondChance_${ExcCode}_${ExcName}_.dmp;GN" ${ExcCode}
as ExcCode sov
as ExcName StackOverflow
sxe -c @".dump /u /ma /c FirstChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_FirstChance_${ExcCode}_${ExcName}_.dmp;GN" -c2 @".dump /u /ma /c SecondChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_SecondChance_${ExcCode}_${ExcName}_.dmp;GN" ${ExcCode}
as ExcCode vs
as ExcName VerifierStop
sxe -c @".dump /u /ma /c FirstChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_FirstChance_${ExcCode}_${ExcName}_.dmp;GN" -c2 @".dump /u /ma /c SecondChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_SecondChance_${ExcCode}_${ExcName}_.dmp;GN" ${ExcCode}
as ExcCode vcpp
as ExcName VisualC++
sxe -c "gn" -c2 @".dump /u /ma /c SecondChance_${ExcCode}_${ExcName} ${AdpDumpDir}\MINIDUMP_${AdpProcName}_SecondChance_${ExcCode}_${ExcName}_.dmp;GN" ${ExcCode}
sxi bpe
sxi wob
sxi e06d7363
sxi e0434352
sxe -c "gn" -c2 @".dump /u /ma /c SecondChance ${AdpDumpDir}\MINIDUMP_SecondChance_${AdpProcName}_.dmp;GN" *
sx
g
.logclose
q

如果可能的话,我正在寻找使其更短更简单的方法。

1 个答案:

答案 0 :(得分:1)

据我所知,没有好的解决方案,但你可以使用这个黑客:

.foreach(code {sx}) {.catch{sxe -c "bla-bla-bla" -c2 "ku-ku-ku" ${code}}}

其中{sx}列出所有已命名的异常代码及其设置(稍后将跳过)。 code只是变量的名称。 .foreach(...) {...}将输出处理为单个单词。 sxe ... ${code}执行预期的命令,.catch{...}忽略所有错误(即跳过不需要的令牌)。

使用PyKD,您可以编写一个Python脚本,使其更直接:

from pykd import *

str = dbgCommand("sx")
lines = str.split("\n")
for line in lines:
    if ("-" in line) and not("Command:" in line):
        code = line.split("-")[0].strip()
        dbgCommand("sxe -c \"bla-bla-bla\" -c2 \"ku-ku-ku\" " + code)