[Lldb-commits] [lldb] Summarize std::string's when created from data. (PR #89110)

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Tue Apr 30 17:16:32 PDT 2024


================
@@ -287,8 +292,49 @@ bool lldb_private::formatters::LibStdcppStringSummaryProvider(
       } else
         return true;
     } break;
-    case eAddressTypeHost:
-      break;
+    case eAddressTypeHost: {
+
+      DataExtractor data;
+      Status error;
+      valobj.GetData(data, error);
+      if (error.Fail())
+        return false;
+
+      lldb::offset_t offset = 0;
+      AddressType child_addressType = valobj.GetAddressTypeOfChildren();
+      if (child_addressType == eAddressTypeLoad) {
+        // We have the host address of our std::string
+        // But we need to read the pointee data from the debugged process.
+        ProcessSP process_sp(valobj.GetProcessSP());
+        // We want to read the address from std::string, which is the first 8 bytes.
+        lldb::addr_t addr = data.GetAddress(&offset);
+        if (!addr) {
+          stream.Printf("nullptr");
+          return true;
+        }
+        std::string contents;
+        process_sp->ReadCStringFromMemory(addr, contents, error);
+        if (error.Fail())
+          return false;
+
+        stream.Printf("%s", contents.c_str());
+        return true;
+      }
+
+      if (child_addressType == eAddressTypeHost) {
+        lldb::offset_t size = data.GetByteSize();
+        const void* dataStart = data.GetData(&offset, size);
+        if (!dataStart)
+          return false;
+
+        const std::string* str = static_cast<const std::string*>(dataStart);
----------------
clayborg wrote:

We can't assume that the host std::string will match the debugee std::string. If we are remote debugging to another architecture, then we will have problems.

https://github.com/llvm/llvm-project/pull/89110


More information about the lldb-commits mailing list