问题
I'm debugging a C/C++ program where I want to set a single break point with a condition depending on multiple variables.
break foo.cpp:60 if (bar == 3 && i == 5)
This doesn't seem to work, as it stops whenever it hits foo.cpp:60 instead of whenever both of the conditions match (it doesn't even match one of the conditions). Is there an easy way to do what I'm trying to achieve?
Edit: bar and i are not native C types, they are strongly typed.
break foo.cpp:60 if ((A) bar == 3 && (B) i == 5)
回答1:
Resolve your condition statement and place its result into its own BOOL variable, then set your break point statement to evaluate the single variable. This puts the form squarely in-line with examples shown in the GDB. documentation:
eg:
BOOL x = FALSE;
x = ((bar == 3) && (i == 5));
(gdb)   break foo.cpp:60 if x
    回答2:
This works for me.
(gdb) b dump_route_info if (strncmp(route->rt_key.prefix, "192.168.0.2", 15) == 0) && route->rt_key.mask == 32
    来源:https://stackoverflow.com/questions/45287838/gdb-breakpoints-with-multiple-conditions-on-non-native-types