Path: blob/main/contrib/llvm-project/lldb/source/Plugins/SymbolFile/DWARF/DIERef.cpp
39645 views
//===-- DIERef.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 "DIERef.h"9#include "lldb/Utility/DataEncoder.h"10#include "lldb/Utility/DataExtractor.h"11#include "llvm/Support/Format.h"12#include <optional>1314using namespace lldb;15using namespace lldb_private;16using namespace lldb_private::plugin::dwarf;1718void llvm::format_provider<DIERef>::format(const DIERef &ref, raw_ostream &OS,19StringRef Style) {20if (ref.file_index())21OS << format_hex_no_prefix(*ref.file_index(), 8) << "/";22OS << (ref.section() == DIERef::DebugInfo ? "INFO" : "TYPE");23OS << "/" << format_hex_no_prefix(ref.die_offset(), 8);24}2526std::optional<DIERef> DIERef::Decode(const DataExtractor &data,27lldb::offset_t *offset_ptr) {28DIERef die_ref(data.GetU64(offset_ptr));2930// DIE offsets can't be zero and if we fail to decode something from data,31// it will return 032if (!die_ref.die_offset())33return std::nullopt;3435return die_ref;36}3738void DIERef::Encode(DataEncoder &encoder) const { encoder.AppendU64(get_id()); }394041