GDB - strcmp 不工作:__strcmp_sse2_unaligned

Mas*_* Wo 4 c++ gdb breakpoints strcmp conditional-breakpoint

我无法使用 strcmp 在 GDB 中创建条件断点:

break x if strcmp(str.c_str(), "foo") == 0
Run Code Online (Sandbox Code Playgroud)

你为什么问?

因为:

print strcmp("hello", "hello")
Run Code Online (Sandbox Code Playgroud)

产量

(int (*)(const char *, const char *)) 0x7ffff76ffe70 <__strcmp_sse2_unaligned> 
Run Code Online (Sandbox Code Playgroud)

即使将其转换为整数:

print (int)strcmp("hello", "hello")
Run Code Online (Sandbox Code Playgroud)

它返回一些无意义的值,如 -143655312

这是“解决”我的问题的一种不太优雅的方法。我可以在自己的代码中定义一个函数:

int mystrcmp(const char *str1, const char* str2){
    return strcmp(str1, str2);                   
}                                                
Run Code Online (Sandbox Code Playgroud)

现在我可以使用这个函数来代替我的条件断点。但这不是真正的调试,是吗?当您必须更改原始代码以进行调试时,您就输了!

那么我错过了什么?

Emp*_*ian 6

strcmp特殊的——它是一个运行时函数选择器 ( IFUNC ),它返回strcmp要在当前处理器上使用的(几种可能的)实现的地址。

您应该可以这样做:

break x if __strcmp_sse2_unaligned(str.c_str(), "foo") == 0
Run Code Online (Sandbox Code Playgroud)