blob: 47dc51e6196d12099731880203bfad82f8bad6fc [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;
Daniel Bertalan57927972022-06-21 20:40:2723 // 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.
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)
Daniel Bertalan57927972022-06-21 20:40:2732 .Case(section_names::debugLine, &dObj->lineSection.Data)
Daniel Bertalanf2c7f752022-07-26 10:06:3933 .Case(section_names::debugStrOffs, &dObj->strOffsSection.Data)
Greg McGary465204d2021-04-27 19:22:4434 .Case(section_names::debugAbbrev, &dObj->abbrevSection)
35 .Case(section_names::debugStr, &dObj->strSection)
36 .Default(nullptr)) {
Jez Ng863f7a72020-12-09 01:47:1937 *s = toStringRef(isec->data);
38 hasDwarfInfo = true;
Jez Ng3fcb0ee2020-12-01 22:45:0139 }
40 }
41
42 if (hasDwarfInfo)
43 return dObj;
44 return nullptr;
45}