how to create conditional breakpoint with std::string

前端 未结 11 995
粉色の甜心
粉色の甜心 2020-12-07 12:54

Suppose I have this function:

std::string Func1(std::string myString)
{
   //do some string processing 
   std::string newString = Func2(myString)
   return          


        
相关标签:
11条回答
  • 2020-12-07 13:32

    In VS2015 you can do

    newstring[0]=='x' && newString[1]=='y' && newString[2]=='z'
    
    0 讨论(0)
  • 2020-12-07 13:38

    In VS2017 you can do

    strcmp(newString._Mypair._Myval2._Bx._Buf,"myvalue")==0
    
    0 讨论(0)
  • 2020-12-07 13:41

    Tried to use strcmp in gdb8.1 under ubuntu18.04, but it doesn't work:

    (ins)(gdb) p strcmp("a", "b")
    $20 = (int (*)(const char *, const char *)) 0x7ffff5179d60 <__strcmp_ssse3>
    

    According to this answer, strcmp, is a special IFUNC, one can setup condition like this:

    condition 1 __strcmp_ssse3(camera->_name.c_str(), "ping")==0
    

    It's pretty ugly, don't want to do it the second time.

    This answer gives a much better solution, it use std::string::compare :

    condition 1 camera->_name.compare("ping") == 0
    
    0 讨论(0)
  • 2020-12-07 13:43

    In VS2017, I was able to set the condition as:

    strcmp(&newString[0], "my value") == 0
    
    0 讨论(0)
  • 2020-12-07 13:45

    Comparing string works better than comparing characters

    strcmp(name._Mypair._Myval2._Bx._Buf, "foo")==0
    

    This works, but is very inconvenient to use and error prone.

    name._Mypair._Myval2._Bx._Buf[0] == 'f' && 
    name._Mypair._Myval2._Bx._Buf[1] == '0' && 
    name._Mypair._Myval2._Bx._Buf[2] == '0'
    
    0 讨论(0)
  • 2020-12-07 13:49

    @OBWANDO (almost) has the solution, but as multiple comments rightly point out, the actual buffer depends on the string size; I see 16 to be the threshold. Prepending a size check to the strcmp on the appropriate buffer works.

    newString._Mysize < 16 && strcmp(newString._Bx._Buf, "test value") == 0
    

    or

    newString._Mysize >= 16 && strcmp(newString._Bx._Ptr, "ultra super long test value") == 0
    
    0 讨论(0)
提交回复
热议问题