<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/132473>132473</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
LLDB breaks on adding a breakpoint using python
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
abocquet
</td>
</tr>
</table>
<pre>
Hello,
I wanted a LLDB breakpoint callback to add another breakpoint on the next frame in the callstack, but LLDB raises an exception on running the next breakpoint. Here is a minimal working example.
I have a file trace_mvp.py with the following code:
```
import lldb
def syscall_callback(frame: lldb.SBFrame, bp_loc, internal_dict):
print("[+] Entering syscall_callback")
thread = frame.GetThread()
# print backtrace for debug
for frame in thread.get_thread_frames():
print(frame)
# address of the next frame
next_frame_pc = thread.get_thread_frames()[1].GetPC()
print("[+] Add breakpoint at : ", hex(next_frame_pc))
target = thread.GetProcess().GetTarget()
bp = target.BreakpointCreateByAddress(next_frame_pc)
bp.SetScriptCallbackFunction("trace_mvp.bp_callback")
print(bp)
def bp_callback(frame: lldb.SBFrame, bp_loc, internal_dict):
print("[+] Hello from bp_callback")
def __lldb_init_module(debugger, internal_dict):
debugger.HandleCommand('breakpoint set -n write')
debugger.HandleCommand('breakpoint command add -s python -F trace_mvp.syscall_callback')
debugger.HandleCommand('run')
```
This code adds a breakpoint on all write syscall. Then, at each stop it is supposed to add another breakpoint on the frame above in the stack, and print a message when it reaches it.
On the side I have a small Python file with a single print
```
print("Hello world")
```
In the terminal I run
```
# in bash
lldb python hello_world.py
# inside LLDB
command script import trace_mvp.py
```
On running the syscall_callback the breakpoint is added to the right address (here 0x101328b74) but LLDB still raises an error
```
Breakpoint 1: 137 locations.
Process 8128 launched: '/Users/macm1/.venv/bin/python' (arm64)
14 locations added to breakpoint 1
frame #0: 0x0000000188f758ec libsystem_kernel.dylib`write
frame #1: 0x0000000101328b74 libpython3.11.dylib`_Py_write_impl + 128
[rest of the stack]
[+] Add breakpoint at : 0x101328b74
SBBreakpoint: id = 2, address = libpython3.11.dylib[0x0000000000174b74], locations = 1
Traceback (most recent call last):
File "<string>", line 8, in lldb_autogen_python_bp_callback_func__0
KeyError: 'lldb_autogen_python_bp_callback_func__1'
Process 8128 stopped
```
When I set the wrong function name on purpose, the error is not raised.
I'm running on macOS 15.1 with LLDB lldb-1600.0.39.109
This is a repost from https://stackoverflow.com/questions/79520679/lldb-breaks-on-adding-a-breakpoint-using-python, where [Jim Ingham](https://stackoverflow.com/users/2465073/jim-ingham) told me this was likely a bug and that I should open an issue.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysV01v4zgS_TX0pWBBoqzYPvhgJ-3t7A7QDaQXexQoqWRxQpEakorjf78oUv5KZ7vnsEaA2BLr69WrV5JwTh404oYVO1Y8zcToO2M3ojL1XyP6WWWa0-YrKmUYfwSWblm6fYaj0B4bEPDHH087qCyK18FI7aEWSlWifgVvQDQNCG18h_b2iNHgOwSN7x5aK3oEGa-QrfOifqVI1eijcyukQwdCA77XOHhpNLmwo9ZSH66urhES-IoWQToQ0Este6HgaOwrHcd30Q8Kk3MhnXhDENBKheCtqLHs34ZkOMFR-i44b41S5ki2tWmQ5WTHHtLpL93KfjDWg1JNFZ022II7OaqmPMPB-CqUyvJtOJm87PbhN1U6lMrU9E1qj1YLVTay9oyvYzAYrNSe8RXjnJrEqU_whc5SVj-H4mSabgEAfGdRNMDypwh18g_0P8K14G8dMwbG8xgFyEPAAVpjocFqPEyu6PdNu8hHckBfxq9luOUmrzHv6XNOPwJwiQkQwoqmsegcmPYDK6YzdCE6L4c6FPKb2MUuY8UTFfr98VIkBftfSG6b5paewgN1KcD4CB2-M766S4I8XgEW9oD-Ni8KbE2NbkooQB5O3WYD1RCNwp1kd4n_aFF43J22EZfPgqdbqIbkBf1LbeXgH6fG70dd03TE-q5kroZPuHFGohouHZmoe3f8_83aICTQWtPDZ2lNKZQlRSullr7sTTMqZHwVuH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