任意类型(例如C ++ std :: string相等)上的GDB条件断点 [英] GDB conditional breakpoint on arbitrary types such as C++ std::string equality

查看:618
本文介绍了任意类型(例如C ++ std :: string相等)上的GDB条件断点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在条件表达式包含任意类类型的对象的GDB中设置条件断点?

Is it possible to set a conditional breakpoint in GDB where the the condition expression contains objects of arbitrary class types?

我需要在函数内部设置一个断点,条件将检查条件是否是对象的成员字符串变量等于"foo".所以,像这样:

I need to set a breakpoint inside a function where the condition will check whether a member string variable of an object equals to say "foo". So, something like:

condition 1 myObject->myStringVar == "foo"

但是它不起作用. GDB是否只允许在基本类型和char *类型上使用条件断点?有什么办法可以在非原始类型上设置条件断点?

But it's not working. Does GDB only allow conditional breakpoints on primitive and char* types? Is there any way I could set a conditional breakpoint on non-primitive types?

推荐答案

有什么办法可以在非基本类型上设置条件断点 类型?

Is there any way I could set a conditional breakpoint on non-primitive types?

是的,一种实现方法是将非原始类型转换为原始类型,在您的情况下转换为char*,并使用strcmp比较字符串.

Yes, one way to do it is to convert non-primitive type to primitive one, in your case to char*, and use strcmp to compare strings.

condition 1 strcmp(myObject->myStringVar.c_str(),"foo") == 0

这篇关于任意类型(例如C ++ std :: string相等)上的GDB条件断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆