annotate lld/MachO/Dwarf.cpp @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents
children 5f17cb93ff66
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 //===- DWARF.cpp ----------------------------------------------------------===//
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 //
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 //
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 #include "Dwarf.h"
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 #include "InputFiles.h"
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 #include "InputSection.h"
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 #include "OutputSegment.h"
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 #include <memory>
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 using namespace lld;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 using namespace lld::macho;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 using namespace llvm;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 std::unique_ptr<DwarfObject> DwarfObject::create(ObjFile *obj) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 auto dObj = std::make_unique<DwarfObject>();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 bool hasDwarfInfo = false;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 // LLD only needs to extract the source file path from the debug info, so we
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 // initialize DwarfObject with just the sections necessary to get that path.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 // The debugger will locate the debug info via the object file paths that we
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 // emit in our STABS symbols, so we don't need to process & emit them
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 // ourselves.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 for (const InputSection *isec : obj->debugSections) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 if (StringRef *s =
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 StringSwitch<StringRef *>(isec->name)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 .Case(section_names::debugInfo, &dObj->infoSection.Data)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 .Case(section_names::debugAbbrev, &dObj->abbrevSection)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 .Case(section_names::debugStr, &dObj->strSection)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 .Default(nullptr)) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 *s = toStringRef(isec->data);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 hasDwarfInfo = true;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 if (hasDwarfInfo)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 return dObj;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 return nullptr;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 }