c - 基于字符串参数的 WinDBG 条件断点

标签 c windbg

我想在第 4 个参数的值等于“abc”时设置条件断点。

void FunctionA(char* a, char* b, char* c, char* d)
{
`enter code here`//some code here
}

我使用以下命令但它不起作用。你能帮忙吗?

bp app!FunctionA "as /mu ${/v:MyAlias} poi(d);.block{.if ($spat(\"${MyAlias}\", \"abc\") == 0)  { } .else { gc } }"

注意:app.exe是我的应用名。

最佳答案

你不能在 char * 上使用 /mu/mu 用于null terminated unicode string 而不是 ascii string对于 ascii 字符串 use/ma

我假设你有描述性的参数名称而不是像 d 这样的参数 这显然会与 0xd aka 0n13
冲突 d 是数字、字符串还是符号??

poi(d) 在您的情况下会解决什么是 poi(0x13) 这显然是一个糟糕的取消引用
或一个本地符号不合逻辑地命名为 d ??

当你中断时别名也不会被解释 使用别名时,您应该始终将它们填充到脚本文件中并执行 每次中断时的脚本文件

这是一个脚本文件的例子

as /ma ${/v:MyAlias} poi(k)
.block {
    r $t0 = $spat("${MyAlias}" , "tiger")
    .printf "%x\t${MyAlias}\n" , @$t0 
    .if(@$t0 != 1) {gc}
}

这是在关闭优化的 Debug模式下运行的代码
在 Release模式下,编译器将足够智能以内联 printf() 调用

#include <stdio.h>
#include <stdlib.h> //msvc _countof
void func(char* h,char* i,char* j,char* k ) {
    printf( "%s %s %s %s\n" ,h,i,j,k );
    return;
}
int main(void) {
    char* foo[] = {"goat","dog","sheep","cat","lion","tiger",0,"vampire"};
    for(int x=0;x<_countof(foo);x++) {
        func("this" , "is" , "a" , foo[x]);
    }
    return 0;    
}

用法

windbg 应用程序.exe

设置中断和运行
请记住这一点或任何使用别名的脚本都将失败
评估 char * vampire
之前的空条目 如果你想打破“吸血鬼”,你可能需要即兴发挥而不使用别名

0:000> bl
0:000> bp strbp!func "$$>a< strbpcond.txt"
0:000> bl
 0 e 00171260     0001 (0001)  0:**** strbp!func "$$>a< strbpcond.txt"
0:000> g
ModLoad: 72670000 72673000   C:\Windows\system32\api-ms-win-core-synch-l1-2-0.DLL
0   goat
0   dog
0   sheep
0   cat
0   lion
1   tiger
eax=00000005 ebx=7ffd7000 ecx=00000005 edx=001ac1e0 esi=001b6678 edi=001b667c
eip=00171260 esp=002bfa54 ebp=002bfa90 iopl=0         nv up ei ng nz ac po cy
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000293
strbp!func:
00171260 55              push    ebp
0:000> dv
              h = 0x001ac1f8 "this"
              i = 0x001ac1f4 "is"
              j = 0x001ac1f0 "a"
              k = 0x001ac1e0 "tiger"

关于c - 基于字符串参数的 WinDBG 条件断点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39612816/

相关文章:

.net-3.5 - 进程突然崩溃,没有错误

c - 如何使具有多个输入的 scanf() 忽略其他输入?

debugging - 如何让 WinDbg 在遇到断点时播放声音?

assembly - mov dword ptr [rsp],eax ss :00000000`0011ddc0=00000060 mean? 是什么意思

c - 硬链接(hard link)与其在 C 中的程序之间的区别

windows - Windbg !heap -s 和 !heap -stat 命令在输出上不一致

c++ - Visual Studio 2012 的 Windows 用户模式调试器传输

用 C 创建 Python 字典

c - 断线对象 - Arduino

将 c 中的成本寻址指针从 unsigned char * 转换为 const char *?