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
16using namespace lld;
17using namespace lld::macho;
18using namespace llvm;
19
20std::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 and line numbers from the
24 // debug info, so we initialize DwarfObject with just the sections necessary
25 // to get that path. The debugger will locate the debug info via the object
26 // file paths that we emit in our STABS symbols, so we don't need to process &
27 // emit them ourselves.
28 for (const InputSection *isec : obj->debugSections) {
29 if (StringRef *s =
30 StringSwitch<StringRef *>(isec->getName())
31 .Case(S: section_names::debugInfo, Value: &dObj->infoSection.Data)
32 .Case(S: section_names::debugLine, Value: &dObj->lineSection.Data)
33 .Case(S: section_names::debugStrOffs, Value: &dObj->strOffsSection.Data)
34 .Case(S: section_names::debugAbbrev, Value: &dObj->abbrevSection)
35 .Case(S: section_names::debugStr, Value: &dObj->strSection)
36 .Default(Value: nullptr)) {
37 *s = toStringRef(Input: isec->data);
38 hasDwarfInfo = true;
39 }
40 }
41
42 if (hasDwarfInfo)
43 return dObj;
44 return nullptr;
45}
46

source code of lld/MachO/Dwarf.cpp