Path: blob/main/contrib/llvm-project/lld/MachO/Dwarf.cpp
34878 views
//===- DWARF.cpp ----------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "Dwarf.h"9#include "InputFiles.h"10#include "InputSection.h"11#include "OutputSegment.h"1213#include <memory>1415using namespace lld;16using namespace lld::macho;17using namespace llvm;1819std::unique_ptr<DwarfObject> DwarfObject::create(ObjFile *obj) {20auto dObj = std::make_unique<DwarfObject>();21bool hasDwarfInfo = false;22// LLD only needs to extract the source file path and line numbers from the23// debug info, so we initialize DwarfObject with just the sections necessary24// to get that path. The debugger will locate the debug info via the object25// file paths that we emit in our STABS symbols, so we don't need to process &26// emit them ourselves.27for (const InputSection *isec : obj->debugSections) {28if (StringRef *s =29StringSwitch<StringRef *>(isec->getName())30.Case(section_names::debugInfo, &dObj->infoSection.Data)31.Case(section_names::debugLine, &dObj->lineSection.Data)32.Case(section_names::debugStrOffs, &dObj->strOffsSection.Data)33.Case(section_names::debugAbbrev, &dObj->abbrevSection)34.Case(section_names::debugStr, &dObj->strSection)35.Default(nullptr)) {36*s = toStringRef(isec->data);37hasDwarfInfo = true;38}39}4041if (hasDwarfInfo)42return dObj;43return nullptr;44}454647