GDB - strcmp not working: __strcmp_sse2_unaligned

本秂侑毒 提交于 2021-01-27 10:46:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!