xref: /freebsd/contrib/llvm-project/lld/MachO/Dwarf.cpp (revision 81ad626541db97eb356e2c1d4a20eb2a26a766ab)
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 
20e8d8bef9SDimitry Andric std::unique_ptr<DwarfObject> DwarfObject::create(ObjFile *obj) {
21e8d8bef9SDimitry Andric   auto dObj = std::make_unique<DwarfObject>();
22e8d8bef9SDimitry Andric   bool hasDwarfInfo = false;
23*81ad6265SDimitry Andric   // LLD only needs to extract the source file path and line numbers from the
24*81ad6265SDimitry Andric   // debug info, so we initialize DwarfObject with just the sections necessary
25*81ad6265SDimitry Andric   // to get that path. The debugger will locate the debug info via the object
26*81ad6265SDimitry Andric   // file paths that we emit in our STABS symbols, so we don't need to process &
27*81ad6265SDimitry 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)
32*81ad6265SDimitry Andric                 .Case(section_names::debugLine, &dObj->lineSection.Data)
33fe6060f1SDimitry Andric                 .Case(section_names::debugAbbrev, &dObj->abbrevSection)
34fe6060f1SDimitry Andric                 .Case(section_names::debugStr, &dObj->strSection)
35e8d8bef9SDimitry Andric                 .Default(nullptr)) {
36e8d8bef9SDimitry Andric       *s = toStringRef(isec->data);
37e8d8bef9SDimitry Andric       hasDwarfInfo = true;
38e8d8bef9SDimitry Andric     }
39e8d8bef9SDimitry Andric   }
40e8d8bef9SDimitry Andric 
41e8d8bef9SDimitry Andric   if (hasDwarfInfo)
42e8d8bef9SDimitry Andric     return dObj;
43e8d8bef9SDimitry Andric   return nullptr;
44e8d8bef9SDimitry Andric }
45