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;
17
18void llvm::format_provider<DIERef>::format(const DIERef &ref, raw_ostream &OS,
19 StringRef Style) {
20 if (ref.file_index())
21 OS << format_hex_no_prefix(*ref.file_index(), 8) << "/";
22 OS << (ref.section() == DIERef::DebugInfo ? "INFO" : "TYPE");
23 OS << "/" << format_hex_no_prefix(ref.die_offset(), 8);
24}
25
26std::optional<DIERef> DIERef::Decode(const DataExtractor &data,
27 lldb::offset_t *offset_ptr) {
28 DIERef die_ref(data.GetU64(offset_ptr));
29
30 // DIE offsets can't be zero and if we fail to decode something from data,
31 // it will return 0
32 if (!die_ref.die_offset())
33 return std::nullopt;
34
35 return die_ref;
36}
37
38void DIERef::Encode(DataEncoder &encoder) const { encoder.AppendU64(get_id()); }
Identifies a DWARF debug info entry within a given Module.
Definition: DIERef.h:28
std::optional< uint32_t > file_index() const
Definition: DIERef.h:57
@ DebugInfo
Definition: DIERef.h:30
lldb::user_id_t get_id() const
Definition: DIERef.h:48
static std::optional< DIERef > Decode(const lldb_private::DataExtractor &data, lldb::offset_t *offset_ptr)
Decode a serialized version of this object from data.
Definition: DIERef.cpp:26
void Encode(lldb_private::DataEncoder &encoder) const
Encode this object into a data encoder object.
Definition: DIERef.cpp:38
dw_offset_t die_offset() const
Definition: DIERef.h:65
Section section() const
Definition: DIERef.h:63
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.
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Definition: SBAddress.h:15
uint64_t offset_t
Definition: lldb-types.h:83