[Lldb-commits] [PATCH] D97249: [lldb] Support debugging utility functions

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Feb 22 20:32:57 PST 2021


JDevlieghere created this revision.
JDevlieghere added a reviewer: jingham.
Herald added a subscriber: pengfei.
JDevlieghere requested review of this revision.

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);


https://reviews.llvm.org/D97249

Files:
  lldb/include/lldb/Expression/UtilityFunction.h
  lldb/include/lldb/Symbol/TypeSystem.h
  lldb/include/lldb/Target/Target.h
  lldb/source/Expression/FunctionCaller.cpp
  lldb/source/Expression/UtilityFunction.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.h
  lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
  lldb/source/Symbol/TypeSystem.cpp
  lldb/source/Target/Target.cpp
  lldb/source/Target/TargetProperties.td

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97249.325658.patch
Type: text/x-patch
Size: 11886 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210223/6156ad73/attachment.bin>


More information about the lldb-commits mailing list