11cf9926bSpatrick //===- DWARF.cpp ----------------------------------------------------------===// 21cf9926bSpatrick // 31cf9926bSpatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 41cf9926bSpatrick // See https://llvm.org/LICENSE.txt for license information. 51cf9926bSpatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 61cf9926bSpatrick // 71cf9926bSpatrick //===----------------------------------------------------------------------===// 81cf9926bSpatrick 91cf9926bSpatrick #include "Dwarf.h" 101cf9926bSpatrick #include "InputFiles.h" 111cf9926bSpatrick #include "InputSection.h" 121cf9926bSpatrick #include "OutputSegment.h" 131cf9926bSpatrick 141cf9926bSpatrick #include <memory> 151cf9926bSpatrick 161cf9926bSpatrick using namespace lld; 171cf9926bSpatrick using namespace lld::macho; 181cf9926bSpatrick using namespace llvm; 191cf9926bSpatrick create(ObjFile * obj)201cf9926bSpatrickstd::unique_ptr<DwarfObject> DwarfObject::create(ObjFile *obj) { 211cf9926bSpatrick auto dObj = std::make_unique<DwarfObject>(); 221cf9926bSpatrick bool hasDwarfInfo = false; 23*dfe94b16Srobert // LLD only needs to extract the source file path and line numbers from the 24*dfe94b16Srobert // debug info, so we initialize DwarfObject with just the sections necessary 25*dfe94b16Srobert // to get that path. The debugger will locate the debug info via the object 26*dfe94b16Srobert // file paths that we emit in our STABS symbols, so we don't need to process & 27*dfe94b16Srobert // emit them ourselves. 281cf9926bSpatrick for (const InputSection *isec : obj->debugSections) { 291cf9926bSpatrick if (StringRef *s = 301cf9926bSpatrick StringSwitch<StringRef *>(isec->getName()) 311cf9926bSpatrick .Case(section_names::debugInfo, &dObj->infoSection.Data) 32*dfe94b16Srobert .Case(section_names::debugLine, &dObj->lineSection.Data) 33*dfe94b16Srobert .Case(section_names::debugStrOffs, &dObj->strOffsSection.Data) 341cf9926bSpatrick .Case(section_names::debugAbbrev, &dObj->abbrevSection) 351cf9926bSpatrick .Case(section_names::debugStr, &dObj->strSection) 361cf9926bSpatrick .Default(nullptr)) { 371cf9926bSpatrick *s = toStringRef(isec->data); 381cf9926bSpatrick hasDwarfInfo = true; 391cf9926bSpatrick } 401cf9926bSpatrick } 411cf9926bSpatrick 421cf9926bSpatrick if (hasDwarfInfo) 431cf9926bSpatrick return dObj; 441cf9926bSpatrick return nullptr; 451cf9926bSpatrick } 46