llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.49k stars 11.78k forks source link

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

Open chenhuimao opened 1 day ago

chenhuimao commented 1 day ago

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

llvmbot commented 22 hours ago

@llvm/issue-subscribers-lldb

Author: mao2020 (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