Jez Ng | 3fcb0ee | 2020-12-01 22:45:01 | [diff] [blame] | 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 | |
| 16 | using namespace lld; |
| 17 | using namespace lld::macho; |
| 18 | using namespace llvm; |
| 19 | |
| 20 | std::unique_ptr<DwarfObject> DwarfObject::create(ObjFile *obj) { |
| 21 | auto dObj = std::make_unique<DwarfObject>(); |
| 22 | bool hasDwarfInfo = false; |
Daniel Bertalan | 5792797 | 2022-06-21 20:40:27 | [diff] [blame] | 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. |
Greg McGary | 98fe9e4 | 2021-03-10 05:41:34 | [diff] [blame] | 28 | for (const InputSection *isec : obj->debugSections) { |
Greg McGary | 465204d | 2021-04-27 19:22:44 | [diff] [blame] | 29 | if (StringRef *s = |
Jez Ng | f6b6e72 | 2021-07-02 00:33:55 | [diff] [blame] | 30 | StringSwitch<StringRef *>(isec->getName()) |
Greg McGary | 465204d | 2021-04-27 19:22:44 | [diff] [blame] | 31 | .Case(section_names::debugInfo, &dObj->infoSection.Data) |
Daniel Bertalan | 5792797 | 2022-06-21 20:40:27 | [diff] [blame] | 32 | .Case(section_names::debugLine, &dObj->lineSection.Data) |
Daniel Bertalan | f2c7f75 | 2022-07-26 10:06:39 | [diff] [blame] | 33 | .Case(section_names::debugStrOffs, &dObj->strOffsSection.Data) |
Greg McGary | 465204d | 2021-04-27 19:22:44 | [diff] [blame] | 34 | .Case(section_names::debugAbbrev, &dObj->abbrevSection) |
| 35 | .Case(section_names::debugStr, &dObj->strSection) |
| 36 | .Default(nullptr)) { |
Jez Ng | 863f7a7 | 2020-12-09 01:47:19 | [diff] [blame] | 37 | *s = toStringRef(isec->data); |
| 38 | hasDwarfInfo = true; |
Jez Ng | 3fcb0ee | 2020-12-01 22:45:01 | [diff] [blame] | 39 | } |
| 40 | } |
| 41 | |
| 42 | if (hasDwarfInfo) |
| 43 | return dObj; |
| 44 | return nullptr; |
| 45 | } |