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 20 std::unique_ptr<DwarfObject> DwarfObject::create(ObjFile *obj) { 21 auto dObj = std::make_unique<DwarfObject>(); 22 bool hasDwarfInfo = false; 23 // LLD only needs to extract the source file path from the debug info, so we 24 // initialize DwarfObject with just the sections necessary to get that path. 25 // The debugger will locate the debug info via the object file paths that we 26 // emit in our STABS symbols, so we don't need to process & emit them 27 // ourselves. 28 for (InputSection *isec : obj->debugSections) { 29 if (StringRef *s = StringSwitch<StringRef *>(isec->name) 30 .Case("__debug_info", &dObj->infoSection.Data) 31 .Case("__debug_abbrev", &dObj->abbrevSection) 32 .Case("__debug_str", &dObj->strSection) 33 .Default(nullptr)) { 34 *s = toStringRef(isec->data); 35 hasDwarfInfo = true; 36 } 37 } 38 39 if (hasDwarfInfo) 40 return dObj; 41 return nullptr; 42 } 43