这是自己没事在家调试程序的一个小需求。

有时候比如IE这样的程序,线程实在是非常的多,我想操作某个特殊线程就比较麻烦,需要先找到线程然后再实行命令,为了偷懒就写了这个脚本。

$$ If a frame of a thread has the target symbol, we execute the command.
$$ Author: nighxie 
$$ Blog: 0cch.net

.if (${/d:$arg1} & ${/d:$arg2} & ${/d:$arg3}) {
    .for (r @$t0 = 0; @$t0 < 0n${$arg1}; r @$t0 = @$t0 + 1) {
        r @$t1 = 0;
        ~[@$t0]s;
        !for_each_frame .if($spat("${@#SymbolName}", "${$arg2}")) {r @$t1 = 1}
        .if (@$t1 == 1) {
            ${$arg3};
        }
    }
}
.else {
    .echo "Usage $$>a<${$arg0} thread_count pattern cmd";
    .echo "e.g. $$>a<${$arg0} 5 ntdll* ~n";
}
 

就如同上面的例子指定线程数量,要匹配的符号,最后就是要执行的命令。
$$>a<${$arg0} 5 ntdll* n就表示在前5个线程里寻找栈回溯有关ntdll的线程,然后执行n命令挂起线程。