1e8d8bef9SDimitry Andric //===- DWARF.cpp ----------------------------------------------------------===// 2e8d8bef9SDimitry Andric // 3e8d8bef9SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4e8d8bef9SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5e8d8bef9SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6e8d8bef9SDimitry Andric // 7e8d8bef9SDimitry Andric //===----------------------------------------------------------------------===// 8e8d8bef9SDimitry Andric 9e8d8bef9SDimitry Andric #include "Dwarf.h" 10e8d8bef9SDimitry Andric #include "InputFiles.h" 11e8d8bef9SDimitry Andric #include "InputSection.h" 12e8d8bef9SDimitry Andric #include "OutputSegment.h" 13e8d8bef9SDimitry Andric 14e8d8bef9SDimitry Andric #include <memory> 15e8d8bef9SDimitry Andric 16e8d8bef9SDimitry Andric using namespace lld; 17e8d8bef9SDimitry Andric using namespace lld::macho; 18e8d8bef9SDimitry Andric using namespace llvm; 19e8d8bef9SDimitry Andric create(ObjFile * obj)20e8d8bef9SDimitry Andricstd::unique_ptr<DwarfObject> DwarfObject::create(ObjFile *obj) { 21e8d8bef9SDimitry Andric auto dObj = std::make_unique<DwarfObject>(); 22e8d8bef9SDimitry Andric bool hasDwarfInfo = false; 2381ad6265SDimitry Andric // LLD only needs to extract the source file path and line numbers from the 2481ad6265SDimitry Andric // debug info, so we initialize DwarfObject with just the sections necessary 2581ad6265SDimitry Andric // to get that path. The debugger will locate the debug info via the object 2681ad6265SDimitry Andric // file paths that we emit in our STABS symbols, so we don't need to process & 2781ad6265SDimitry Andric // emit them ourselves. 28fe6060f1SDimitry Andric for (const InputSection *isec : obj->debugSections) { 29fe6060f1SDimitry Andric if (StringRef *s = 30fe6060f1SDimitry Andric StringSwitch<StringRef *>(isec->getName()) 31fe6060f1SDimitry Andric .Case(section_names::debugInfo, &dObj->infoSection.Data) 3281ad6265SDimitry Andric .Case(section_names::debugLine, &dObj->lineSection.Data) 33*bdd1243dSDimitry Andric .Case(section_names::debugStrOffs, &dObj->strOffsSection.Data) 34fe6060f1SDimitry Andric .Case(section_names::debugAbbrev, &dObj->abbrevSection) 35fe6060f1SDimitry Andric .Case(section_names::debugStr, &dObj->strSection) 36e8d8bef9SDimitry Andric .Default(nullptr)) { 37e8d8bef9SDimitry Andric *s = toStringRef(isec->data); 38e8d8bef9SDimitry Andric hasDwarfInfo = true; 39e8d8bef9SDimitry Andric } 40e8d8bef9SDimitry Andric } 41e8d8bef9SDimitry Andric 42e8d8bef9SDimitry Andric if (hasDwarfInfo) 43e8d8bef9SDimitry Andric return dObj; 44e8d8bef9SDimitry Andric return nullptr; 45e8d8bef9SDimitry Andric } 46