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

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

问题描述

是否可以在条件表达式包含任意类类型对象的 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

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

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