<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/104897>104897</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[lldb] The registered function with SetScriptCallbackFunction doesn't continue execution after calling StepOut() inside
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kohnakagawa
</td>
</tr>
</table>
<pre>
I posted this issue at [Stack Overflow](https://stackoverflow.com/questions/78860541/the-registered-function-with-setscriptcallbackfunction-doesnt-continue-executio), but this issue seems a bug of LLDB, so I created this issue.
I'm running [a sample script from the book "Advanced Apple Debugging & Reverse Engineering"](https://github.com/kodecocodes/dbg-materials/blob/editions/4.0/22-script-bridging-classes-and-hierarchy/projects/final/BreakAfterRegex.py). This script defines a command called bar, which does the following:
1. Creates a breakpoint for a function using a regular expression
2. When the breakpoint is hit, it steps out to the function's return
3. Evaluates the return value using the expression command and outputs the result to stdout
4. Continues execution automatically (because the breakpointHandler function registered with SetScriptCallbackFunction returns False)
However, when I load this script in LLDB (lldb-1500.0.22.8 on macOS Sonoma 14.5) and execute the command, step 4 doesn't occur. The execution doesn't continue unless I manually enter the c command in LLDB. If I remove the thread.StepOver() call, step 4 works correctly.
Steps to reproduced are as follows.
```
$ lldb --version
lldb-1500.0.22.8
Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)
$ cat test.m
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSString *filePath = @"/tmp/hoge.txt";
NSString *content = @"Hello World";
NSError *error;
BOOL success = [content writeToFile:filePath
atomically:YES
encoding:NSUTF8StringEncoding
error:&error];
if (success) {
NSLog(@"Success");
} else {
NSLog(@"Error");
}
}
return 0;
}
$ clang -framework Foundation test.m -o test
$ lldb ./test
(lldb) target create "./test"
Current executable set to '/Users/user/test' (x86_64).
(lldb) command script import ./lldb/BreakAfterRegex.py
(lldb) bar NSObject.init\] SBBreakpoint: id = 1, regex = 'NSObject.init\]', locations = 2
(lldb) r
Process 2754 launched: '/Users/user/test' (x86_64)
(lldb) ********************************************************************************
breakpoint: -[NSObject init]
object: <_NSThreadData: 0x600002fe8000>
stopped:-[_NSThreadData init]
Process 2754 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step out
frame #0: 0x00007ff8130211c2 Foundation`-[_NSThreadData init] + 55
Foundation`-[_NSThreadData init]:
-> 0x7ff8130211c2 <+55>: movq 0x411c5737(%rip), %rcx
0x7ff8130211c9 <+62>: movq (%rcx), %rcx
0x7ff8130211cc <+65>: cmpq -0x8(%rbp), %rcx
0x7ff8130211d0 <+69>: jne 0x7ff8130211d8 ; <+77>
Target 0: (test) stopped.
(lldb) c
Process 2754 resuming
(lldb) ********************************************************************************
breakpoint: -[NSObject init]
object: <NSProcessInfo: 0x6000010e0000>
stopped:__28+[NSProcessInfo processInfo]_block_invoke
Process 2754 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step out
frame #0: 0x00007ff81284b59b Foundation`__28+[NSProcessInfo processInfo]_block_invoke + 32
Foundation`:
-> 0x7ff81284b59b <+32>: movq %rax, 0x4080027e(%rip) ; processInfoCache
0x7ff81284b5a2 <+39>: popq %rbp
0x7ff81284b5a3 <+40>: retq
Foundation`-[NSProcessInfo arguments]:
0x7ff81284b5a4 <+0>: pushq %rbp
Target 0: (test) stopped.
(lldb) c
Process 2754 resuming
2024-08-12 16:43:30.871560+0900 test[2754:88642] Success
Process 2754 exited with status = 0 (0x00000000)
```
Since [the breakpointHandler function returns False](https://github.com/kodecocodes/dbg-materials/blob/e8a1f1d0a40c6d45da866ab2e414e947896675e8/22-script-bridging-classes-and-hierarchy/projects/final/BreakAfterRegex.py#L70), the program execution should automatically continue, but it does not.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWF1v27jS_jXMzUACRUm2fJELO4mxAYp2se5i8V4VlDSyuJFEl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