xref: /freebsd-src/contrib/llvm-project/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
10b57cec5SDimitry Andric //===-- NameToDIE.h ---------------------------------------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
95ffd83dbSDimitry Andric #ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_NAMETODIE_H
105ffd83dbSDimitry Andric #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_NAMETODIE_H
110b57cec5SDimitry Andric 
120b57cec5SDimitry Andric #include <functional>
130b57cec5SDimitry Andric 
140b57cec5SDimitry Andric #include "DIERef.h"
150b57cec5SDimitry Andric #include "lldb/Core/UniqueCStringMap.h"
160b57cec5SDimitry Andric #include "lldb/Core/dwarf.h"
170b57cec5SDimitry Andric #include "lldb/lldb-defines.h"
180b57cec5SDimitry Andric 
19*5f757f3fSDimitry Andric namespace lldb_private::plugin {
20*5f757f3fSDimitry Andric namespace dwarf {
210b57cec5SDimitry Andric class DWARFUnit;
220b57cec5SDimitry Andric 
230b57cec5SDimitry Andric class NameToDIE {
240b57cec5SDimitry Andric public:
NameToDIE()250b57cec5SDimitry Andric   NameToDIE() : m_map() {}
260b57cec5SDimitry Andric 
27fe6060f1SDimitry Andric   ~NameToDIE() = default;
280b57cec5SDimitry Andric 
29*5f757f3fSDimitry Andric   void Dump(Stream *s);
300b57cec5SDimitry Andric 
31*5f757f3fSDimitry Andric   void Insert(ConstString name, const DIERef &die_ref);
320b57cec5SDimitry Andric 
330b57cec5SDimitry Andric   void Append(const NameToDIE &other);
340b57cec5SDimitry Andric 
350b57cec5SDimitry Andric   void Finalize();
360b57cec5SDimitry Andric 
37*5f757f3fSDimitry Andric   bool Find(ConstString name,
385ffd83dbSDimitry Andric             llvm::function_ref<bool(DIERef ref)> callback) const;
390b57cec5SDimitry Andric 
40*5f757f3fSDimitry Andric   bool Find(const RegularExpression &regex,
415ffd83dbSDimitry Andric             llvm::function_ref<bool(DIERef ref)> callback) const;
420b57cec5SDimitry Andric 
43349cc55cSDimitry Andric   /// \a unit must be the skeleton unit if possible, not GetNonSkeletonUnit().
445ffd83dbSDimitry Andric   void
45349cc55cSDimitry Andric   FindAllEntriesForUnit(DWARFUnit &unit,
465ffd83dbSDimitry Andric                         llvm::function_ref<bool(DIERef ref)> callback) const;
470b57cec5SDimitry Andric 
480b57cec5SDimitry Andric   void
49*5f757f3fSDimitry Andric   ForEach(std::function<bool(ConstString name, const DIERef &die_ref)> const
500b57cec5SDimitry Andric               &callback) const;
510b57cec5SDimitry Andric 
5204eeddc0SDimitry Andric   /// Decode a serialized version of this object from data.
5304eeddc0SDimitry Andric   ///
5404eeddc0SDimitry Andric   /// \param data
5504eeddc0SDimitry Andric   ///   The decoder object that references the serialized data.
5604eeddc0SDimitry Andric   ///
5704eeddc0SDimitry Andric   /// \param offset_ptr
5804eeddc0SDimitry Andric   ///   A pointer that contains the offset from which the data will be decoded
5904eeddc0SDimitry Andric   ///   from that gets updated as data gets decoded.
6004eeddc0SDimitry Andric   ///
6104eeddc0SDimitry Andric   /// \param strtab
6204eeddc0SDimitry Andric   ///   All strings in cache files are put into string tables for efficiency
6304eeddc0SDimitry Andric   ///   and cache file size reduction. Strings are stored as uint32_t string
6404eeddc0SDimitry Andric   ///   table offsets in the cache data.
65*5f757f3fSDimitry Andric   bool Decode(const DataExtractor &data, lldb::offset_t *offset_ptr,
66*5f757f3fSDimitry Andric               const StringTableReader &strtab);
6704eeddc0SDimitry Andric 
6804eeddc0SDimitry Andric   /// Encode this object into a data encoder object.
6904eeddc0SDimitry Andric   ///
7004eeddc0SDimitry Andric   /// This allows this object to be serialized to disk.
7104eeddc0SDimitry Andric   ///
7204eeddc0SDimitry Andric   /// \param encoder
7304eeddc0SDimitry Andric   ///   A data encoder object that serialized bytes will be encoded into.
7404eeddc0SDimitry Andric   ///
7504eeddc0SDimitry Andric   /// \param strtab
7604eeddc0SDimitry Andric   ///   All strings in cache files are put into string tables for efficiency
7704eeddc0SDimitry Andric   ///   and cache file size reduction. Strings are stored as uint32_t string
7804eeddc0SDimitry Andric   ///   table offsets in the cache data.
79*5f757f3fSDimitry Andric   void Encode(DataEncoder &encoder, ConstStringTable &strtab) const;
8004eeddc0SDimitry Andric 
8104eeddc0SDimitry Andric   /// Used for unit testing the encoding and decoding.
8204eeddc0SDimitry Andric   bool operator==(const NameToDIE &rhs) const;
8304eeddc0SDimitry Andric 
IsEmpty()8404eeddc0SDimitry Andric   bool IsEmpty() const { return m_map.IsEmpty(); }
8504eeddc0SDimitry Andric 
Clear()8604eeddc0SDimitry Andric   void Clear() { m_map.Clear(); }
8704eeddc0SDimitry Andric 
880b57cec5SDimitry Andric protected:
89*5f757f3fSDimitry Andric   UniqueCStringMap<DIERef> m_map;
900b57cec5SDimitry Andric };
91*5f757f3fSDimitry Andric } // namespace dwarf
92*5f757f3fSDimitry Andric } // namespace lldb_private::plugin
930b57cec5SDimitry Andric 
945ffd83dbSDimitry Andric #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_NAMETODIE_H
95