LLDB mainline
DIERef.cpp
Go to the documentation of this file.
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-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "DIERef.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 0
33 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()); }
An binary data encoding class.
Definition: DataEncoder.h:42
void AppendU64(uint64_t value)
An data extractor class.
Definition: DataExtractor.h:48
uint64_t GetU64(lldb::offset_t *offset_ptr) const
Extract a uint64_t value from *offset_ptr.
Identifies a DWARF debug info entry within a given Module.
Definition: DIERef.h:30
lldb::user_id_t get_id() const
Definition: DIERef.h:50
std::optional< uint32_t > file_index() const
Definition: DIERef.h:59
void Encode(DataEncoder &encoder) const
Encode this object into a data encoder object.
Definition: DIERef.cpp:39
static std::optional< DIERef > Decode(const DataExtractor &data, lldb::offset_t *offset_ptr)
Decode a serialized version of this object from data.
Definition: DIERef.cpp:27
dw_offset_t die_offset() const
Definition: DIERef.h:67
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
uint64_t offset_t
Definition: lldb-types.h:85