augusto2112 created this revision.
augusto2112 added a reviewer: aprantl.
Herald added a project: All.
augusto2112 requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Implement SymbolFile::ContainsCompileOption, which returns true if the
string option was used when compiling the binary.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147748

Files:
  lldb/include/lldb/Symbol/SymbolFile.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h

Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
@@ -153,6 +153,8 @@
   // Statistics overrides.
   lldb_private::ModuleList GetDebugInfoModules() override;
 
+  bool ContainsCompileOption(const char *option) override;
+
 protected:
   enum { kHaveInitializedOSOs = (1 << 0), kNumFlags };
 
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
@@ -1549,3 +1549,12 @@
   }
   return Status();
 }
+
+bool SymbolFileDWARFDebugMap::ContainsCompileOption(const char *option) {
+  bool success = false;
+  ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
+    success |= oso_dwarf->ContainsCompileOption(option);
+    return success;
+  });
+  return success;
+}
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -340,6 +340,8 @@
     m_file_index = file_index;
   }
 
+  bool ContainsCompileOption(const char *option) override;
+
 protected:
   typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb_private::Type *>
       DIEToTypePtr;
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -4255,3 +4255,36 @@
   return Status("no variable information is available in debug info for this "
                 "compile unit");
 }
+
+bool SymbolFileDWARF::ContainsCompileOption(const char *option) {
+  auto check_in_dwarf_cu = [&option](DWARFUnit *dwarf_cu) {
+    const DWARFBaseDIE die = dwarf_cu->GetUnitDIEOnly();
+    if (!die)
+      return false;
+    const char *flags = die.GetAttributeValueAsString(DW_AT_APPLE_flags, NULL);
+
+    if (!flags)
+      return false;
+    if (!strstr(flags, option))
+      return false;
+    Args compiler_args(flags);
+    for (auto &arg : compiler_args.GetArgumentArrayRef())
+      if (strcmp(arg, option) == 0)
+        return true;
+
+    return false;
+  };
+
+  DWARFDebugInfo &debug_info = DebugInfo();
+  const uint32_t num_compile_units = GetNumCompileUnits();
+
+  for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) {
+    DWARFUnit *dwarf_cu = debug_info.GetUnitAtIndex(cu_idx);
+    if (dwarf_cu) {
+      if (check_in_dwarf_cu(dwarf_cu))
+        return true;
+    }
+  }
+
+  return false;
+}
Index: lldb/include/lldb/Symbol/SymbolFile.h
===================================================================
--- lldb/include/lldb/Symbol/SymbolFile.h
+++ lldb/include/lldb/Symbol/SymbolFile.h
@@ -435,6 +435,12 @@
 
   virtual lldb::TypeSP CopyType(const lldb::TypeSP &other_type) = 0;
 
+  /// Returns true if the option exists in the compile options encoded in 
+  /// the symbol file.
+  virtual bool ContainsCompileOption(const char *option) {
+    return false;
+  }
+
 protected:
   void AssertModuleLock();
 
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to