LLDB uses utility functions to run code in the inferior for its own internal purposes, such as reading classes from the Objective-C runtime for example. Because these expressions should be transparent to the user, we ignore breakpoints and unwind the stack on errors, which makes them hard to debug.
This patch adds a new setting target.debug-utility-expression that, when enabled, changes these options to facilitate debugging. It enables breakpoints, disables unwinding and writes out the utility function source code to disk.
Here's what this looks like in action. I added a nullptr dereference to __lldb_apple_objc_v2_get_shared_cache_class_info and used TestDataFormatterObjCNSContainer as an example:
$ lldb a.out (lldb) target create "a.out" Current executable set to 'a.out' (x86_64). (lldb) b main.m:782 Breakpoint 1: where = a.out`main + 11752 at main.m:783:4, address = 0x0000000100006838 (lldb) setting set target.debug-utility-expression true (lldb) r Process 77039 stopped * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1 frame #0: 0x0000000100006838 a.out`main(argc=1, argv=0x00007ffeefbff500) at main.m:783:4 780 forKeyPath:@"atoms" 781 options:0 782 context:NULL]; // Set break point at this line. -> 783 [newMutableDictionary addObserver:[My_KVO_Observer new] 784 forKeyPath:@"weirdKeyToKVO" 785 options:NSKeyValueObservingOptionNew 786 context:NULL]; Process 77039 launched: 'a.out' (x86_64) (lldb) frame variable newArray nsDictionary newDictionary nscfDictionary cfDictionaryRef newMutableDictionary newMutableDictionaryRef cfarray_ref mutable_array_ref warning: could not execute support code to read Objective-C class data in the process. This may reduce the quality of type information available. Process 77039 stopped * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0) frame #0: 0x00000001001df2de __lldb_apple_objc_v2_get_shared_cache_class_info`__lldb_apple_objc_v2_get_shared_cache_class_info(objc_opt_ro_ptr=0x00007fff2031bc08, class_infos_ptr=0x000000010063b000, class_infos_byte_size=1572864, should_log=0) at lldb-9f30fe.expr:68 65 uint32_t class_infos_byte_size, 66 uint32_t should_log) 67 { -> 68 int *i = 0; 69 *i = 10; 70 uint32_t idx = 0; 71 DEBUG_PRINTF ("objc_opt_ro_ptr = %p\n", objc_opt_ro_ptr);
unrelated change