https://github.com/kastiglione updated 
https://github.com/llvm/llvm-project/pull/187792

>From 03fe88c5497655a0c8273f3c1bdd8382f2728a19 Mon Sep 17 00:00:00 2001
From: Dave Lee <[email protected]>
Date: Fri, 20 Mar 2026 13:50:43 -0700
Subject: [PATCH 1/3] [lldb][bytecode] Add setting to disable loading
 formatters from user (non-system) binaries

---
 lldb/include/lldb/Target/Target.h      |  2 ++
 lldb/source/Target/Target.cpp          | 17 ++++++++++++++++-
 lldb/source/Target/TargetProperties.td |  3 +++
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/lldb/include/lldb/Target/Target.h 
b/lldb/include/lldb/Target/Target.h
index 7907ed2f1a5f6..bbfe27adb1d81 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -278,6 +278,8 @@ class TargetProperties : public Properties {
 
   bool GetDebugUtilityExpression() const;
 
+  bool GetLoadFormattersFromUserBinaries() const;
+
 private:
   std::optional<bool>
   GetExperimentalPropertyValue(size_t prop_idx,
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 296a18f89dba2..3e691bd787833 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -44,6 +44,7 @@
 #include "lldb/Interpreter/Property.h"
 #include "lldb/Symbol/Function.h"
 #include "lldb/Symbol/ObjectFile.h"
+#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h"
 #include "lldb/Symbol/Symbol.h"
 #include "lldb/Target/ABI.h"
 #include "lldb/Target/ExecutionContext.h"
@@ -1542,6 +1543,13 @@ Module *Target::GetExecutableModulePointer() {
   return GetExecutableModule().get();
 }
 
+static bool IsSystemBinary(const ModuleSP &module_sp) {
+  if (auto *objfile = module_sp->GetObjectFile())
+    if (auto *macho = llvm::dyn_cast<ObjectFileMachO>(objfile))
+      return macho->IsSharedCacheBinary();
+  return false;
+}
+
 static void LoadScriptingResourceForModule(const ModuleSP &module_sp,
                                            Target *target) {
   Status error;
@@ -1861,7 +1869,8 @@ void Target::ModulesDidLoad(ModuleList &module_list) {
       ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
       LoadScriptingResourceForModule(module_sp, this);
       LoadTypeSummariesForModule(module_sp);
-      LoadFormattersForModule(module_sp);
+      if (GetLoadFormattersFromUserBinaries() || IsSystemBinary(module_sp))
+        LoadFormattersForModule(module_sp);
     }
     m_breakpoint_list.UpdateBreakpoints(module_list, true, false);
     m_internal_breakpoint_list.UpdateBreakpoints(module_list, true, false);
@@ -5256,6 +5265,12 @@ void TargetProperties::SetDebugUtilityExpression(bool 
debug) {
   SetPropertyAtIndex(idx, debug);
 }
 
+bool TargetProperties::GetLoadFormattersFromUserBinaries() const {
+  const uint32_t idx = ePropertyLoadFormattersFromUserBinaries;
+  return GetPropertyAtIndexAs<bool>(
+      idx, g_target_properties[idx].default_uint_value != 0);
+}
+
 // Target::TargetEventData
 
 Target::TargetEventData::TargetEventData(const lldb::TargetSP &target_sp)
diff --git a/lldb/source/Target/TargetProperties.td 
b/lldb/source/Target/TargetProperties.td
index 2361314d506ac..15619f036afdb 100644
--- a/lldb/source/Target/TargetProperties.td
+++ b/lldb/source/Target/TargetProperties.td
@@ -176,6 +176,9 @@ let Definition = "target", Path = "target" in {
   def UseFastStepping: Property<"use-fast-stepping", "Boolean">,
     DefaultTrue,
     Desc<"Use a fast stepping algorithm based on running from branch to branch 
rather than instruction single-stepping.">;
+  def LoadFormattersFromUserBinaries: 
Property<"load-formatters-from-user-binaries", "Boolean">,
+    DefaultTrue,
+    Desc<"Load formatter bytecode embedded in user (non-system) binaries.">;
   def LoadScriptFromSymbolFile: Property<"load-script-from-symbol-file", 
"Enum">,
     DefaultEnumValue<"eLoadScriptFromSymFileWarn">,
     EnumValues<"OptionEnumValues(g_load_script_from_sym_file_values)">,

>From beb04821074987f18c4fa28a45522f93395e1299 Mon Sep 17 00:00:00 2001
From: Dave Lee <[email protected]>
Date: Fri, 20 Mar 2026 16:32:31 -0700
Subject: [PATCH 2/3] [lldb] Introduce Module::IsSystem

This `IsSystem` predicate can be used to help determine some level of trust of 
the
binary.

This function will be consulted when loading bytecode data formatters embedded 
in
binaries. Formatters from system binaries are always trusted, while formatters 
from user
binaries will be subject to the `load-formatters-from-user-binaries` setting.
---
 lldb/include/lldb/Symbol/ObjectFile.h         | 23 +++++++++++++++++++
 .../Plugins/ObjectFile/ELF/ObjectFileELF.h    |  2 ++
 .../ObjectFile/Mach-O/ObjectFileMachO.h       |  2 ++
 .../ObjectFile/PECOFF/ObjectFilePECOFF.h      | 18 +++++++++++++++
 .../ObjectFile/XCOFF/ObjectFileXCOFF.h        |  2 ++
 5 files changed, 47 insertions(+)

diff --git a/lldb/include/lldb/Symbol/ObjectFile.h 
b/lldb/include/lldb/Symbol/ObjectFile.h
index 2cdcadd262622..07576b7304da5 100644
--- a/lldb/include/lldb/Symbol/ObjectFile.h
+++ b/lldb/include/lldb/Symbol/ObjectFile.h
@@ -22,6 +22,7 @@
 #include "lldb/Utility/StructuredData.h"
 #include "lldb/Utility/UUID.h"
 #include "lldb/lldb-private.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Threading.h"
 #include "llvm/Support/VersionTuple.h"
 #include <optional>
@@ -262,6 +263,13 @@ class ObjectFile : public 
std::enable_shared_from_this<ObjectFile>,
   ///     \b true if it is, \b false otherwise.
   virtual bool IsExecutable() const = 0;
 
+  /// Tells whether this object file is a system binary - one provided by the
+  /// OS rather than by the user installed files.
+  ///
+  /// \return
+  ///     \b true if this is a system binary, \b false otherwise.
+  virtual bool IsSystem() const { return false; }
+
   /// Returns the offset into a file at which this object resides.
   ///
   /// Some files contain many object files, and this function allows access to
@@ -755,6 +763,21 @@ class ObjectFile : public 
std::enable_shared_from_this<ObjectFile>,
   std::string GetObjectName() const;
 
 protected:
+  /// Returns true if the object file's path is under a known OS system
+  /// directory. For use by IsSystem() implementations on platforms that lack a
+  /// "system binary" flag (ex. ELF, XCOFF).
+  bool IsUnixSystemPath() const {
+    std::string path_str = m_file.GetPath();
+    llvm::StringRef path = path_str;
+    // Linux / glibc multiarch, FreeBSD, AIX
+    if (path.starts_with("/lib") || path.starts_with("/usr/lib"))
+      return true;
+    // Android system partition
+    if (path.starts_with("/system/"))
+      return true;
+    return false;
+  }
+
   typedef NonNullSharedPtr<lldb_private::DataExtractor> DataExtractorNSP;
 
   // Member variables.
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h 
b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
index 866ef270fa731..a2d81e0a69187 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -108,6 +108,8 @@ class ObjectFileELF : public lldb_private::ObjectFile {
 
   bool IsExecutable() const override;
 
+  bool IsSystem() const override { return IsUnixSystemPath(); }
+
   uint32_t GetAddressByteSize() const override;
 
   lldb_private::AddressClass GetAddressClass(lldb::addr_t file_addr) override;
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
index d4c3a1f613ad2..df0192e76afd5 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
@@ -102,6 +102,8 @@ class ObjectFileMachO : public lldb_private::ObjectFile {
 
   bool IsStripped() override;
 
+  bool IsSystem() const override { return IsSharedCacheBinary(); }
+
   void CreateSections(lldb_private::SectionList &unified_section_list) 
override;
 
   void Dump(lldb_private::Stream *s) override;
diff --git a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h 
b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
index 30bd672dc68f8..7774cfe4e29d1 100644
--- a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
+++ b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
@@ -14,6 +14,7 @@
 
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Symbol/SaveCoreOptions.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/Object/COFF.h"
 
 class ObjectFilePECOFF : public lldb_private::ObjectFile {
@@ -109,6 +110,23 @@ class ObjectFilePECOFF : public lldb_private::ObjectFile {
 
   bool IsExecutable() const override;
 
+  bool IsSystem() const override {
+    std::string path_str = m_file.GetPath();
+    if (path_str.empty())
+      return false;
+    std::replace(path_str.begin(), path_str.end(), '\\', '/');
+    llvm::StringRef path = path_str;
+
+    // Skip past drive letter.
+    if (!llvm::isAlpha(path[0]))
+      return false;
+    path = path.substr(1);
+
+    return path.starts_with_insensitive(":/windows/system32/") ||
+           path.starts_with_insensitive(":/windows/syswow64/") ||
+           path.starts_with_insensitive(":/windows/winsxs/");
+  }
+
   uint32_t GetAddressByteSize() const override;
 
   //    virtual lldb_private::AddressClass
diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h 
b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h
index b3b9229cfd208..dbc0737059a39 100644
--- a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h
+++ b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h
@@ -67,6 +67,8 @@ class ObjectFileXCOFF : public lldb_private::ObjectFile {
 
   bool IsExecutable() const override;
 
+  bool IsSystem() const override { return IsUnixSystemPath(); }
+
   uint32_t GetAddressByteSize() const override;
 
   lldb_private::AddressClass GetAddressClass(lldb::addr_t file_addr) override;

>From fa5f3564064e03e77b9c5f505389cd4d20e3e3bd Mon Sep 17 00:00:00 2001
From: Dave Lee <[email protected]>
Date: Fri, 20 Mar 2026 16:47:17 -0700
Subject: [PATCH 3/3] Use Module::IsSystem

---
 lldb/source/Target/Target.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 3e691bd787833..799b2bb5cad03 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -1545,8 +1545,7 @@ Module *Target::GetExecutableModulePointer() {
 
 static bool IsSystemBinary(const ModuleSP &module_sp) {
   if (auto *objfile = module_sp->GetObjectFile())
-    if (auto *macho = llvm::dyn_cast<ObjectFileMachO>(objfile))
-      return macho->IsSharedCacheBinary();
+    return objfile->IsSystem();
   return false;
 }
 

_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to