[Lldb-commits] [lldb] 9d9f3e0 - [lldb] Remove ProcessStructReader from NSStringSummaryProvider (NFC)

Dave Lee via lldb-commits lldb-commits at lists.llvm.org
Sun Jan 9 12:09:13 PST 2022


Author: Dave Lee
Date: 2022-01-09T12:09:02-08:00
New Revision: 9d9f3e0ec773c6a2c570c8bc7484367bff73190c

URL: https://github.com/llvm/llvm-project/commit/9d9f3e0ec773c6a2c570c8bc7484367bff73190c
DIFF: https://github.com/llvm/llvm-project/commit/9d9f3e0ec773c6a2c570c8bc7484367bff73190c.diff

LOG: [lldb] Remove ProcessStructReader from NSStringSummaryProvider (NFC)

Simplify getting the length of `NSPathStore2` strings.

`NSStringSummaryProvider` uses a single field from `NSPathStore2` instances,
its first ivar: `_lengthAndRefCount`. This change uses
`GetSyntheticChildAtOffset` to replace the use of `ProcessStructReader`, and
removes the hard coded `CompilerType` definition of `NSPathStore2`.

Differential Revision: https://reviews.llvm.org/D116461

Added: 
    

Modified: 
    lldb/source/Plugins/Language/ObjC/NSString.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/Language/ObjC/NSString.cpp b/lldb/source/Plugins/Language/ObjC/NSString.cpp
index 2b5161e781f23..61705c866778c 100644
--- a/lldb/source/Plugins/Language/ObjC/NSString.cpp
+++ b/lldb/source/Plugins/Language/ObjC/NSString.cpp
@@ -8,14 +8,13 @@
 
 #include "NSString.h"
 
-#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "lldb/Core/ValueObject.h"
 #include "lldb/Core/ValueObjectConstResult.h"
 #include "lldb/DataFormatters/FormattersHelpers.h"
 #include "lldb/DataFormatters/StringPrinter.h"
 #include "lldb/Target/Language.h"
-#include "lldb/Target/ProcessStructReader.h"
 #include "lldb/Target/Target.h"
+#include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/DataBufferHeap.h"
 #include "lldb/Utility/Endian.h"
 #include "lldb/Utility/Status.h"
@@ -31,24 +30,6 @@ NSString_Additionals::GetAdditionalSummaries() {
   return g_map;
 }
 
-static CompilerType GetNSPathStore2Type(Target &target) {
-  static ConstString g_type_name("__lldb_autogen_nspathstore2");
-
-  TypeSystemClang *ast_ctx = ScratchTypeSystemClang::GetForTarget(target);
-
-  if (!ast_ctx)
-    return CompilerType();
-
-  CompilerType voidstar =
-      ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType();
-  CompilerType uint32 =
-      ast_ctx->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 32);
-
-  return ast_ctx->GetOrCreateStructForIdentifier(
-      g_type_name,
-      {{"isa", voidstar}, {"lengthAndRef", uint32}, {"buffer", voidstar}});
-}
-
 bool lldb_private::formatters::NSStringSummaryProvider(
     ValueObject &valobj, Stream &stream,
     const TypeSummaryOptions &summary_options) {
@@ -229,11 +210,17 @@ bool lldb_private::formatters::NSStringSummaryProvider(
     return StringPrinter::ReadStringAndDumpToStream<
         StringPrinter::StringElementType::UTF16>(options);
   } else if (is_path_store) {
-    ProcessStructReader reader(valobj.GetProcessSP().get(),
-                               valobj.GetValueAsUnsigned(0),
-                               GetNSPathStore2Type(*valobj.GetTargetSP()));
-    explicit_length =
-        reader.GetField<uint32_t>(ConstString("lengthAndRef")) >> 20;
+    // _lengthAndRefCount is the first ivar of NSPathStore2 (after the isa).
+    uint64_t length_ivar_offset = 1 * ptr_size;
+    CompilerType length_type = valobj.GetCompilerType().GetBasicTypeFromAST(
+        lldb::eBasicTypeUnsignedInt);
+    ValueObjectSP length_valobj_sp =
+        valobj.GetSyntheticChildAtOffset(length_ivar_offset, length_type, true,
+                                         ConstString("_lengthAndRefCount"));
+    if (!length_valobj_sp)
+      return false;
+    // Get the length out of _lengthAndRefCount.
+    explicit_length = length_valobj_sp->GetValueAsUnsigned(0) >> 20;
     lldb::addr_t location = valobj.GetValueAsUnsigned(0) + ptr_size + 4;
 
     options.SetLocation(location);


        


More information about the lldb-commits mailing list