【问题标题】:Lldb : Setting conditional breakpoint with string equality as conditionLldb:以字符串相等作为条件设置条件断点
【发布时间】:2016-09-09 07:53:38
【问题描述】:

我想用 lldb 设置一个条件断点。这通常使用-c 选项来完成:

breakpoint set -f myFile.cpp -l 123 -c 'a==3'

但是,就我而言,我想测试 std::string 对象是否等于某个字符串值,但这样做

breakpoint set -f myFile.cpp -l 123 -c 'a=="hello"'

不起作用... Lldb 不会抱怨(虽然 gdb 会返回错误)但它会在到达断点时忽略条件字符串并且过早中断...

这个问题类似于this one,但使用的是 lldb 而不是 gdb。那里提出的解决方案

breakpoint set -f myFile.cpp -l 123 if strcmp(a, "hello")==0

似乎对 lldb 无效

使用的 Lldb 版本:3.4

【问题讨论】:

    标签: breakpoints lldb conditional-breakpoint


    【解决方案1】:
    (lldb) br s -n main -c '(int)strcmp("test", var)==0'
    Breakpoint 1: where = a.out`main + 11 at a.c:3, address = 0x0000000100000f8b
    (lldb) br li
    Current breakpoints:
    1: name = 'main', locations = 1
    Condition: (int)strcmp("test", var)==0
    
      1.1: where = a.out`main + 11 at a.c:3, address = a.out[0x0000000100000f8b], unresolved, hit count = 0 
    
    (lldb) 
    

    您可以在事后添加条件表达式。喜欢

    (lldb) br s -n main
    Breakpoint 1: where = a.out`main + 11 at a.c:3, address = 0x0000000100000f8b
    (lldb) br mod -c '(int) strcmp("test", var) == 0'
    (lldb) br li
    Current breakpoints:
    1: name = 'main', locations = 1
    Condition: (int) strcmp("test", var) == 0
    
      1.1: where = a.out`main + 11 at a.c:3, address = a.out[0x0000000100000f8b], unresolved, hit count = 0 
    
    (lldb) 
    

    breakpoint modify 在末尾接受一个断点编号/断点编号列表,如果没有指定,则默认为最新的断点(这是我在这里所做的)。

    【讨论】:

      猜你喜欢
      • 2019-12-18
      • 2013-01-02
      • 2013-02-24
      • 2014-07-30
      • 1970-01-01
      • 2014-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多