问题
I'm unable to create conditional breakpoint in GDB using strcmp:
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
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:
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.
You should be able to do this instead:
break x if __strcmp_sse2_unaligned(str.c_str(), "foo") == 0
来源:https://stackoverflow.com/questions/51934903/gdb-strcmp-not-working-strcmp-sse2-unaligned