How can I setup an LLDB breakpoint firing every 10th time?

巧了我就是萌 提交于 2019-12-12 09:40:04

问题


To debug the values of high frequency timers or sensors it would be useful to configure a breakpoint that only fires every x times. What's the best way to accomplish this?

I tried the "Ignore x times before stopping" option in Xcode but that only works for the first time. Can I reset this counter using an LLDB command?


回答1:


You can reset the ignore counter at any time with:

(lldb) break modify -i <NEW_VALUE> <BKPT_SPECIFICATION>

Note, a breakpoint which doesn't satisfy its "ignore count" is not considered to be hit, so its breakpoint command does NOT get run. So if you wanted to stop every tenth the time you hit the breakpoint automatically, just do:

    (lldb) break set -l 10 -i 10 -N my_bkpt
    Breakpoint 1: where = foo`main + 46 at foo.c:10, address = 0x0000000100000f5e
    (lldb) break com add
    Enter your debugger command(s).  Type 'DONE' to end.
    > break modify -i 10 my_bkpt 
    > DONE
    (lldb)

Then just hit "continue" at each stop and you will hit the breakpoint once every 10 times.

Note, I used the ability to name the breakpoint (the -N option) so I didn't have to know the breakpoint number in the breakpoint command that I added. That's convenient if you're going to store these breakpoints in a command file, etc.


Ref: Apple docs on Managing breakpoints. You can also do help breakpoint set command for a complete list of available options




回答2:


I'm not sure you can define a persistent variable(counter) in lldb. You can always have one global var that you use as a counter helper and simply not include it in the release builds.

class BrCounter{
     static var freq = 10
} 

Edit the breakpoint and add the following condition:

BrCounter.freq--; 
if(BrCounter.freq == 0){ 
    BrCounter.freq = 10; 
    return true; 
}else{ 
    return false; 
}

Oneliner:

BrCounter.freq--; if(BrCounter.freq == 0){ BrCounter.freq = 10; return true; }else{ return false; }


来源:https://stackoverflow.com/questions/40615222/how-can-i-setup-an-lldb-breakpoint-firing-every-10th-time

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