Re-apply "[ORC] Add N_SO and N_OSO stabs entries to MachO debug..." with fixes.

This re-applies db51e57289, which was reverted in 05b1a2cb3e due to bot
failures. The DebuggerSupportPlugin now depends on DWARF, so it has been moved
to the new OrcDebugging library (as has the enableDebuggerSupport API).
This commit is contained in:
Lang Hames
2023-09-28 17:55:44 -07:00
parent ab472cd4ea
commit b2518971d8
11 changed files with 73 additions and 12 deletions

View File

@@ -4,6 +4,7 @@ set(LLVM_LINK_COMPONENTS
MC
Option
OrcJit
OrcDebugging
OrcShared
OrcTargetProcess
Support

View File

@@ -17,7 +17,7 @@
#include "clang/Interpreter/PartialTranslationUnit.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
#include "llvm/ExecutionEngine/Orc/DebuggerSupport.h"
#include "llvm/ExecutionEngine/Orc/Debugging/DebuggerSupport.h"
#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
#include "llvm/ExecutionEngine/Orc/LLJIT.h"

View File

@@ -13,8 +13,6 @@ add_llvm_component_library(LLVMOrcJIT
CompileUtils.cpp
Core.cpp
DebugObjectManagerPlugin.cpp
DebuggerSupport.cpp
DebuggerSupportPlugin.cpp
DebugUtils.cpp
EPCDynamicLibrarySearchGenerator.cpp
EPCDebugObjectRegistrar.cpp

View File

@@ -4,6 +4,8 @@ endif()
add_llvm_component_library(LLVMOrcDebugging
DebugInfoSupport.cpp
DebuggerSupport.cpp
DebuggerSupportPlugin.cpp
PerfSupportPlugin.cpp
ADDITIONAL_HEADER_DIRS

View File

@@ -6,9 +6,9 @@
//
//===----------------------------------------------------------------------===//
#include "llvm/ExecutionEngine/Orc/DebuggerSupport.h"
#include "llvm/ExecutionEngine/Orc/Debugging/DebuggerSupport.h"
#include "llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h"
#include "llvm/ExecutionEngine/Orc/DebuggerSupportPlugin.h"
#include "llvm/ExecutionEngine/Orc/Debugging/DebuggerSupportPlugin.h"
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
#define DEBUG_TYPE "orc"

View File

@@ -9,13 +9,17 @@
//
//===----------------------------------------------------------------------===//
#include "llvm/ExecutionEngine/Orc/DebuggerSupportPlugin.h"
#include "llvm/ExecutionEngine/Orc/Debugging/DebuggerSupportPlugin.h"
#include "llvm/ExecutionEngine/Orc/MachOBuilder.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/BinaryFormat/MachO.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
#include <chrono>
#define DEBUG_TYPE "orc"
@@ -97,8 +101,6 @@ public:
<< "\n";
});
auto &SDOSec = G.createSection(SynthDebugSectionName, MemProt::Read);
for (auto &Sec : G.sections()) {
if (Sec.blocks().empty())
continue;
@@ -114,6 +116,10 @@ public:
NonDebugSections.push_back({&Sec, nullptr});
}
// Bail out early if no debug sections.
if (DebugSections.empty())
return Error::success();
// Write MachO header and debug section load commands.
Builder.Header.filetype = MachO::MH_OBJECT;
switch (G.getTargetTriple().getArch()) {
@@ -131,16 +137,65 @@ public:
Seg = &Builder.addSegment("");
StringMap<std::unique_ptr<MemoryBuffer>> DebugSectionMap;
StringRef DebugLineSectionData;
for (auto &DSec : DebugSections) {
auto [SegName, SecName] = DSec.GraphSec->getName().split(',');
DSec.BuilderSec = &Seg->addSection(SecName, SegName);
SectionRange SR(*DSec.GraphSec);
DSec.BuilderSec->Content.Size = SR.getSize();
if (!SR.empty())
if (!SR.empty()) {
DSec.BuilderSec->align = Log2_64(SR.getFirstBlock()->getAlignment());
StringRef SectionData(SR.getFirstBlock()->getContent().data(),
SR.getFirstBlock()->getSize());
DebugSectionMap[SecName] =
MemoryBuffer::getMemBuffer(SectionData, G.getName(), false);
if (SecName == "__debug_line")
DebugLineSectionData = SectionData;
}
}
std::optional<std::string> FileName;
if (!DebugLineSectionData.empty()) {
auto DWARFCtx = DWARFContext::create(DebugSectionMap, G.getPointerSize(),
G.getEndianness());
DWARFDataExtractor DebugLineData(
DebugLineSectionData,
G.getEndianness() == support::endianness::little, G.getPointerSize());
uint64_t Offset = 0;
DWARFDebugLine::LineTable LineTable;
// Try to parse line data. Consume error on failure.
if (auto Err = LineTable.parse(DebugLineData, &Offset, *DWARFCtx, nullptr,
consumeError)) {
handleAllErrors(
std::move(Err),
[&](ErrorInfoBase &EIB) {
LLVM_DEBUG({
dbgs() << "Cannot parse line table for \"" << G.getName() << "\": ";
EIB.log(dbgs());
dbgs() << "\n";
});
});
} else {
if (!LineTable.Prologue.FileNames.empty())
FileName = *dwarf::toString(LineTable.Prologue.FileNames[0].Name);
}
}
// If no line table (or unable to use) then use graph name.
// FIXME: There are probably other debug sections we should look in first.
if (!FileName)
FileName = G.getName();
Builder.addSymbol("", MachO::N_SO, 0, 0, 0);
Builder.addSymbol(*FileName, MachO::N_SO, 0, 0, 0);
auto TimeStamp = std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();
Builder.addSymbol("", MachO::N_OSO, 3, 1, TimeStamp);
for (auto &NDSP : NonDebugSections) {
auto [SegName, SecName] = NDSP.GraphSec->getName().split(',');
NDSP.BuilderSec = &Seg->addSection(SecName, SegName);
@@ -164,8 +219,12 @@ public:
}
}
Builder.addSymbol("", MachO::N_SO, 1, 0, 0);
// Lay out the debug object, create a section and block for it.
size_t DebugObjectSize = Builder.layout();
auto &SDOSec = G.createSection(SynthDebugSectionName, MemProt::Read);
MachOContainerBlock = &G.createMutableContentBlock(
SDOSec, G.allocateBuffer(DebugObjectSize), orc::ExecutorAddr(), 8, 0);

View File

@@ -12,8 +12,9 @@ set(LLVM_LINK_COMPONENTS
MC
MCJIT
Object
OrcShared
OrcJIT
OrcDebugging
OrcShared
OrcTargetProcess
Passes
RuntimeDyld

View File

@@ -26,7 +26,7 @@
#include "llvm/ExecutionEngine/MCJIT.h"
#include "llvm/ExecutionEngine/ObjectCache.h"
#include "llvm/ExecutionEngine/Orc/DebugUtils.h"
#include "llvm/ExecutionEngine/Orc/DebuggerSupport.h"
#include "llvm/ExecutionEngine/Orc/Debugging/DebuggerSupport.h"
#include "llvm/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.h"
#include "llvm/ExecutionEngine/Orc/EPCEHFrameRegistrar.h"
#include "llvm/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.h"

View File

@@ -18,8 +18,8 @@
#include "llvm/ExecutionEngine/Orc/COFFPlatform.h"
#include "llvm/ExecutionEngine/Orc/COFFVCRuntimeSupport.h"
#include "llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h"
#include "llvm/ExecutionEngine/Orc/DebuggerSupportPlugin.h"
#include "llvm/ExecutionEngine/Orc/Debugging/DebugInfoSupport.h"
#include "llvm/ExecutionEngine/Orc/Debugging/DebuggerSupportPlugin.h"
#include "llvm/ExecutionEngine/Orc/Debugging/PerfSupportPlugin.h"
#include "llvm/ExecutionEngine/Orc/ELFNixPlatform.h"
#include "llvm/ExecutionEngine/Orc/EPCDebugObjectRegistrar.h"