Skip to content

lldb: Calling SBBreakpoint.SetScriptCallbackFunction does not work when using Python scripts #112186

@chenhuimao

Description

@chenhuimao

When I use lldb python script, calling SBBreakpoint.SetScriptCallbackFunction does not work in some cases.
This is my script:

# MyScript.py

import lldb

def __lldb_init_module(debugger, internal_dict):
    debugger.HandleCommand(f'command script add -f MyScript.custom_command custom_command -h "Demo for SetScriptCallbackFunction API"')

def custom_command(debugger, command, exe_ctx, result, internal_dict):
    address_int = int(command, 16)
    bp = exe_ctx.GetTarget().BreakpointCreateByAddress(address_int)
    bp.SetScriptCallbackFunction("MyScript.breakpoint_function_wrapper")

def breakpoint_function_wrapper(frame, bp_loc, extra_args, internal_dict):
    print("hit breakpoint")
    return True

I made sure that the address entered is valid, but the breakpoint_function_wrapper function is not executed after hitting the breakpoint.
In addition, when I create a breakpoint using another interface BreakpointCreateByName, SetScriptCallbackFunction worked:

bp = exe_ctx.GetTarget().BreakpointCreateByName("objc_msgSend", "libobjc.A.dylib")
bp.SetScriptCallbackFunction("MyScript.breakpoint_function_wrapper")

Environment:
[sys version] macOS 15.0 Python 3.9.6 (default, Aug 9 2024, 14:24:13) [Clang 16.0.0 (clang-1600.0.26.3)]
[LLDB version] lldb-1600.0.36.3 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
[Target triple] arm64-apple-ios-
[Xcode version] 1600 (16A242d)
[Model identifier] iPhone13,2
[iOS version] iOS 18.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions