blob: c142cc1b169f6be8e44baa3c4c0284c1e5b79f3b [file] [log] [blame]
Jez Ng3fcb0ee2020-12-01 22:45:011//===- 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;
Nico Weber0cc7ad42022-06-20 23:15:5723 // 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.
Greg McGary98fe9e42021-03-10 05:41:3428 for (const InputSection *isec : obj->debugSections) {
Greg McGary465204d2021-04-27 19:22:4429 if (StringRef *s =
Jez Ngf6b6e722021-07-02 00:33:5530 StringSwitch<StringRef *>(isec->getName())
Greg McGary465204d2021-04-27 19:22:4431 .Case(section_names::debugInfo, &dObj->infoSection.Data)
Greg McGary465204d2021-04-27 19:22:4432 .Case(section_names::debugAbbrev, &dObj->abbrevSection)
33 .Case(section_names::debugStr, &dObj->strSection)
34 .Default(nullptr)) {
Jez Ng863f7a72020-12-09 01:47:1935 *s = toStringRef(isec->data);
36 hasDwarfInfo = true;
Jez Ng3fcb0ee2020-12-01 22:45:0137 }
38 }
39
40 if (hasDwarfInfo)
41 return dObj;
42 return nullptr;
43}