How do I set a conditional breakpoint in gdb, when char* x points to a string whose value equals "hello"?

341008 picture 341008 · Nov 15, 2010 · Viewed 132.2k times · Source

Can I specify that I want gdb to break at line x when char* x points to a string whose value equals "hello"? If yes, how?

Answer

Nathan Fellman picture Nathan Fellman · Nov 15, 2010

You can use strcmp:

break x:20 if strcmp(y, "hello") == 0

20 is line number, x can be any filename and y can be any variable.