[lldb-dev] Callback API question

Greg Clayton gclayton at apple.com
Wed Apr 24 11:33:33 PDT 2013


You don't use the callback directly, you actually tell the breakpoint that is should call a python function:

(lldb) breakpoint command add -F my_module.breakpoint_hit

The signature for the python callback is:

def breakpoint_callback(frame, bp_loc, dict):
  # Your code goes here

So you don't get the specify a baton for the callback, but you can get python to be called when a breakpoint does get hit. You can always make a global variable (dictionary) that can track which breakpoints map to which baton ("self" in your case) and then you could manually call your other functions.

Greg Clayton


On Apr 24, 2013, at 11:00 AM, "Malea, Daniel" <daniel.malea at intel.com> wrote:

> Hi Greg, or whoever reads this first,
> 
> I have a question about the python API lldb.SBBreakpoint.SetCallback function. According to the docs, the signature is:
> 
> SetCallback(self, *args) unbound lldb.SBBreakpoint method
>    SetCallback(self, BreakpointHitCallback callback, void baton)
> 
> However, I am not sure how to create an instance of the BreakpointHitCallback type that is required for the second parameter. I'm not seeing any class in the Python API that is named that; only the C++ API has a typedef of that name:
> 
> typedef bool (*BreakpointHitCallback) (void *baton,
>                                       SBProcess &process,
>                                       SBThread &thread,
>                                       lldb::SBBreakpointLocation &location);
> 
> 
> I tried passing a function that has (what I believe is) the correct signature:
> 
> class MyTestCase(TestBase):
>  def bp_callback(self, process, thread, breakpoint_loc):
>    Pass
> 
>  def register_callback(self, target)
>    breakpoint = target.BreakpointCreateByLocation('main.c', self.line1)
>    breakpoint.SetCallback(self.bp_callback, self)
> 
> 
> But I am getting a python error:
> 
> TypeError: in method 'SBBreakpoint_SetCallback', argument 2 of type 'lldb::SBBreakpoint::BreakpointHitCallback'
> 
> So, my question is: is it possible to register a callback to be called when a breakpoint is hit using that function? If so, what am I doing wrong? If not, is it preferable to create an SBListener for this purpose, or is the "target stop-hook add" command the only way to do what I'm trying to do? I'm trying to avoid using the built-in script interpreter..
> 
> 
> 
> Thanks,
> Dan




More information about the lldb-dev mailing list