1 //===- DWARF.cpp ----------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "Dwarf.h" 10 #include "InputFiles.h" 11 #include "InputSection.h" 12 #include "OutputSegment.h" 13 14 #include <memory> 15 16 using namespace lld; 17 using namespace lld::macho; 18 using namespace llvm; 19 create(ObjFile * obj)20std::unique_ptr<DwarfObject> DwarfObject::create(ObjFile *obj) { 21 auto dObj = std::make_unique<DwarfObject>(); 22 bool hasDwarfInfo = false; 23 for (SubsectionMap subsecMap : obj->subsections) { 24 for (auto it : subsecMap) { 25 InputSection *isec = it.second; 26 if (!(isDebugSection(isec->flags) && 27 isec->segname == segment_names::dwarf)) 28 continue; 29 30 if (isec->name == "__debug_info") { 31 dObj->infoSection.Data = toStringRef(isec->data); 32 hasDwarfInfo = true; 33 continue; 34 } 35 36 if (StringRef *s = StringSwitch<StringRef *>(isec->name) 37 .Case("__debug_abbrev", &dObj->abbrevSection) 38 .Case("__debug_str", &dObj->strSection) 39 .Default(nullptr)) { 40 *s = toStringRef(isec->data); 41 hasDwarfInfo = true; 42 } 43 } 44 } 45 46 if (hasDwarfInfo) 47 return dObj; 48 return nullptr; 49 } 50