GDB breakpoints with multiple conditions on non-native types

寵の児 提交于 2020-12-06 12:56:27

问题


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

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