2

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)

ginginsha
  • 142
  • 1
  • 11

2 Answers2

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
ryyker
  • 22,849
  • 3
  • 43
  • 87
  • Unfortunately it still doesn't work, gdb returns the error 'No symbol "operator==" in current context.' I should mention that bar and i are not native c types (they are defined strong types). Is there a form of casting I should do? i.e. if ((bar == (A) 3) && (i == (B) 5)? – ginginsha Jul 24 '17 at 18:54
  • @ginginsha - Provide more information about how exactly these variables are created/typed. Edit your original post if needed so all will see it. – ryyker Jul 24 '17 at 19:23
0

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
Abhishek Sagar
  • 1,189
  • 4
  • 20
  • 44