I'm unable to create conditional breakpoint in GDB using strcmp:
我无法使用strcmp在GDB中创建条件断点:
break x if strcmp(str.c_str(), "foo") == 0
Why you ask?
你为什么问?
Because:
因为:
print strcmp("hello", "hello")
Yield's
产量的
(int (*)(const char *, const char *)) 0x7ffff76ffe70 <__strcmp_sse2_unaligned>
Even when casting it to an integer:
即使将其转换为整数:
print (int)strcmp("hello", "hello")
It returns some nonsensical value like -143655312
它返回一些无意义的值,如-143655312
Here's a less graceful way to "solve" my problem. I can define a function in my own code:
这是一种不太优雅的方式来“解决”我的问题。我可以在自己的代码中定义一个函数:
int mystrcmp(const char *str1, const char* str2){
return strcmp(str1, str2);
}
And now I'm able to use this function instead for my conditional breakpoint. But this isn't really debugging is it? When you have to change your original code to debug it you have lost the game!
现在我可以使用此函数代替我的条件断点。但这不是真正的调试吗?当您必须更改原始代码以进行调试时,您就丢失了游戏!
So what am I missing?
那么我错过了什么?
1 个解决方案
#1
2
The strcmp
is special -- it's a runtime function selector (IFUNC) which returns an address of (one of several possible) implementations of strcmp
to be used on the current processor.
strcmp是特殊的 - 它是一个运行时函数选择器(IFUNC),它返回当前处理器上使用的strcmp的(几种可能的)一种实现的地址。
You should be able to do this instead:
您应该能够这样做:
break x if __strcmp_sse2_unaligned(str.c_str(), "foo") == 0
#1
2
The strcmp
is special -- it's a runtime function selector (IFUNC) which returns an address of (one of several possible) implementations of strcmp
to be used on the current processor.
strcmp是特殊的 - 它是一个运行时函数选择器(IFUNC),它返回当前处理器上使用的strcmp的(几种可能的)一种实现的地址。
You should be able to do this instead:
您应该能够这样做:
break x if __strcmp_sse2_unaligned(str.c_str(), "foo") == 0