lldb hangs when breaking on programmatically added symbolic breakpoint with attached action

Originator:igeek1
Number:rdar://43975320 Date Originated:August 31 2018, 11:38 PM
Status:Open Resolved:
Product:Developer Tools | Xcode Product Version:Xcode 9.4.1 (9F2000) on macOS 10.13.6 (17G2307)
Classification:Crash/Hang/Data Loss Reproducible:Always
 
Summary:
If you create a symbolic breakpoint, and add a command to call a custom python function, lldb-rpc-server hangs when the breakpoint is hit.

Steps to Reproduce:
1. Create a python script. Here’s a simplified example (also in attached file):

```
import lldb

def example_function(debugger, command, result, dict):
  print("Printed by custom python script. You will see this unless lldb is hanging.")

def __lldb_init_module(debugger, dict):
  debugger.HandleCommand('command script add -f lldb_hang_repro.example_function try_to_print_a_thing')
```

2. Save this into a file. For example, ~/Desktop/lldb_hang_repro.py.
3. Import the script into lldb with the following line in ~/.lldbinit:

command script import ~/Desktop/lldb_hang_repro.py

4. Open the attached project.
5. Look at the embedded breakpoints in the project. If they don’t appear on your machine, you can find them inside the project at SimpleApp/SimpleApp.xcodeproj/xcuserdata/zeisenberg.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist. You’ll find several that work perfectly, and one that causes the problem. I’ll discuss the working cases later. Here’s how to reproduce the hang issue:

6. Create a Symbolic Breakpoint.
7. Set the symbol to UIApplicationMain.
8. Add the following debugger command:

br set -n viewDidLoad --command 'try_to_print_a_thing'

9. Run the app on an iOS simulator. I’m using an iPhone 5s running iOS 11.4, but have also confirmed that this is reproducible in Xcode 10 beta 6.

Expected Results:
When viewDidLoad is hit, it triggers the symbolic breakpoint, which runs the try_to_print_a_thing function. You can tell it works if the app hits a breakpoint and the message from the Python script is printed to the console: "Printed by custom python script. You will see this unless lldb is hanging."

Actual Results:
The app hangs. The Xcode Stop and Run buttons fail to respond. You can only continue by force-quitting Xcode or by killing the lldb-rpc-server process.

Version/Build:
Xcode 9.4.1 (9F2000) on macOS 10.13.6 (17G2307)

Configuration:
The attached crash log was generated with killall -5 lldb-rpc-server. It seems to point to a deadlock related to locking a temp file and then never unlocking it, but I’m not sure of the specifics.

Here are some cases that are similar to the failing case, but they work, and they help to narrow down the scope of the problem. They are reflected in order in the breakpoints included in the project, but they are all disabled by default. These breakpoints are numbered in their Log Message section, corresponding to this list. I recommend enabling one at a time and confirming that all but #3 work correctly.

<descriptions moved to Appendix-A.txt, attached, to reduce character count>

Thanks to Aijaz Ansari, Jay Freeman, and Derek Selander for help debugging and isolating this.

Attached file also posted at https://cl.ly/ab3b7a533523

Also attached a sysdiagnose, which I am not posting to Open Radar.

Comments

Prior art: someone else found a similar issue. I don't know whether they filed a radar. https://gist.github.com/woolsweater/8c421b44f6be14d299102d5c84558e15


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!