[llvm] 360a053 - [Orc] Add RequireDebugSections option in the DebugObjectManagerPlugin

Stefan Gränitz via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 31 03:04:22 PDT 2023


Author: Stefan Gränitz
Date: 2023-03-31T12:03:41+02:00
New Revision: 360a05305c2a82ded3b4d5615f752f790d12845e

URL: https://github.com/llvm/llvm-project/commit/360a05305c2a82ded3b4d5615f752f790d12845e
DIFF: https://github.com/llvm/llvm-project/commit/360a05305c2a82ded3b4d5615f752f790d12845e.diff

LOG: [Orc] Add RequireDebugSections option in the DebugObjectManagerPlugin

Sometimes it's useful to be able and debug code even without actual debug info, e.g. for setting breakpoints on function names.
This patch adds a new API option to make it possible in Orc.

The existing API and behavior remains unchanged: non-debug objects are not passed to exectuors.

Added: 
    

Modified: 
    llvm/include/llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h
    llvm/lib/ExecutionEngine/Orc/DebugObjectManagerPlugin.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h b/llvm/include/llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h
index beb0a48c08f67..82bed965a68ed 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h
@@ -47,8 +47,22 @@ class DebugObject;
 ///
 class DebugObjectManagerPlugin : public ObjectLinkingLayer::Plugin {
 public:
+  // DEPRECATED - Please specify options explicitly
   DebugObjectManagerPlugin(ExecutionSession &ES,
                            std::unique_ptr<DebugObjectRegistrar> Target);
+
+  /// Create the plugin to submit DebugObjects for JITLink artifacts. For all
+  /// options the recommended setting is true.
+  ///
+  /// RequireDebugSections:
+  ///   Submit debug objects to the executor only if they contain actual debug
+  ///   info. Turning this off may allow minimal debugging based on raw symbol
+  ///   names. Note that this may cause significant memory and transport
+  ///   overhead for objects built with a release configuration.
+  ///
+  DebugObjectManagerPlugin(ExecutionSession &ES,
+                           std::unique_ptr<DebugObjectRegistrar> Target,
+                           bool RequireDebugSections);
   ~DebugObjectManagerPlugin();
 
   void notifyMaterializing(MaterializationResponsibility &MR,
@@ -77,6 +91,7 @@ class DebugObjectManagerPlugin : public ObjectLinkingLayer::Plugin {
   std::mutex RegisteredObjsLock;
 
   std::unique_ptr<DebugObjectRegistrar> Target;
+  bool RequireDebugSections;
 };
 
 } // namespace orc

diff  --git a/llvm/lib/ExecutionEngine/Orc/DebugObjectManagerPlugin.cpp b/llvm/lib/ExecutionEngine/Orc/DebugObjectManagerPlugin.cpp
index f179aac2dfa09..bd2faebc16d2c 100644
--- a/llvm/lib/ExecutionEngine/Orc/DebugObjectManagerPlugin.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/DebugObjectManagerPlugin.cpp
@@ -105,6 +105,9 @@ void ELFDebugObjectSection<ELFT>::dump(raw_ostream &OS, StringRef Name) {
 enum DebugObjectFlags : int {
   // Request final target memory load-addresses for all sections.
   ReportFinalSectionLoadAddresses = 1 << 0,
+
+  // We found sections with debug information when processing the input object.
+  HasDebugSections = 1 << 1,
 };
 
 /// The plugin creates a debug object from when JITLink starts processing the
@@ -116,7 +119,7 @@ class DebugObject {
 public:
   DebugObject(JITLinkMemoryManager &MemMgr, const JITLinkDylib *JD,
               ExecutionSession &ES)
-      : MemMgr(MemMgr), JD(JD), ES(ES) {}
+      : MemMgr(MemMgr), JD(JD), ES(ES), Flags(DebugObjectFlags{}) {}
 
   bool hasFlags(DebugObjectFlags F) const { return Flags & F; }
   void setFlags(DebugObjectFlags F) {
@@ -274,14 +277,14 @@ ELFDebugObject::CreateArchType(MemoryBufferRef Buffer,
   if (!Sections)
     return Sections.takeError();
 
-  bool HasDwarfSection = false;
   for (const SectionHeader &Header : *Sections) {
     Expected<StringRef> Name = ObjRef->getSectionName(Header);
     if (!Name)
       return Name.takeError();
     if (Name->empty())
       continue;
-    HasDwarfSection |= isDwarfSection(*Name);
+    if (isDwarfSection(*Name))
+      DebugObj->setFlags(HasDebugSections);
 
     // Only record text and data sections (i.e. no bss, comments, rel, etc.)
     if (Header.sh_type != ELF::SHT_PROGBITS &&
@@ -295,13 +298,6 @@ ELFDebugObject::CreateArchType(MemoryBufferRef Buffer,
       return std::move(Err);
   }
 
-  if (!HasDwarfSection) {
-    LLVM_DEBUG(dbgs() << "Aborting debug registration for LinkGraph \""
-                      << DebugObj->Buffer->getBufferIdentifier()
-                      << "\": input object contains no debug info\n");
-    return nullptr;
-  }
-
   return std::move(DebugObj);
 }
 
@@ -399,9 +395,15 @@ createDebugObjectFromBuffer(ExecutionSession &ES, LinkGraph &G,
   }
 }
 
+DebugObjectManagerPlugin::DebugObjectManagerPlugin(
+    ExecutionSession &ES, std::unique_ptr<DebugObjectRegistrar> Target,
+    bool RequireDebugSections)
+    : ES(ES), Target(std::move(Target)),
+      RequireDebugSections(RequireDebugSections) {}
+
 DebugObjectManagerPlugin::DebugObjectManagerPlugin(
     ExecutionSession &ES, std::unique_ptr<DebugObjectRegistrar> Target)
-    : ES(ES), Target(std::move(Target)) {}
+    : DebugObjectManagerPlugin(ES, std::move(Target), true) {}
 
 DebugObjectManagerPlugin::~DebugObjectManagerPlugin() = default;
 
@@ -415,8 +417,14 @@ void DebugObjectManagerPlugin::notifyMaterializing(
 
   if (auto DebugObj = createDebugObjectFromBuffer(ES, G, Ctx, ObjBuffer)) {
     // Not all link artifacts allow debugging.
-    if (*DebugObj != nullptr)
-      PendingObjs[&MR] = std::move(*DebugObj);
+    if (*DebugObj == nullptr)
+      return;
+    if (RequireDebugSections && !(**DebugObj).hasFlags(HasDebugSections)) {
+      LLVM_DEBUG(dbgs() << "Skipping debug registration for LinkGraph '"
+                        << G.getName() << "': no debug info\n");
+      return;
+    }
+    PendingObjs[&MR] = std::move(*DebugObj);
   } else {
     ES.reportError(DebugObj.takeError());
   }


        


More information about the llvm-commits mailing list