40 lines · cpp
1//===-- DIERef.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-exception6//7//===----------------------------------------------------------------------===//8 9#include "DIERef.h"10#include "lldb/Utility/DataEncoder.h"11#include "lldb/Utility/DataExtractor.h"12#include "llvm/Support/Format.h"13#include <optional>14 15using namespace lldb;16using namespace lldb_private;17using namespace lldb_private::plugin::dwarf;18 19void llvm::format_provider<DIERef>::format(const DIERef &ref, raw_ostream &OS,20 StringRef Style) {21 if (ref.file_index())22 OS << format_hex_no_prefix(*ref.file_index(), 8) << "/";23 OS << (ref.section() == DIERef::DebugInfo ? "INFO" : "TYPE");24 OS << "/" << format_hex_no_prefix(ref.die_offset(), 8);25}26 27std::optional<DIERef> DIERef::Decode(const DataExtractor &data,28 lldb::offset_t *offset_ptr) {29 DIERef die_ref(data.GetU64(offset_ptr));30 31 // DIE offsets can't be zero and if we fail to decode something from data,32 // it will return 033 if (!die_ref.die_offset())34 return std::nullopt;35 36 return die_ref;37}38 39void DIERef::Encode(DataEncoder &encoder) const { encoder.AppendU64(get_id()); }40