HashedNameToDIE.h revision 4ec7b85a4445f779915c79e91085cbaf1b776a87
1//===-- HashedNameToDIE.h ---------------------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef SymbolFileDWARF_HashedNameToDIE_h_
11#define SymbolFileDWARF_HashedNameToDIE_h_
12
13#include <vector>
14#include "lldb/lldb-defines.h"
15#include "lldb/Core/dwarf.h"
16
17class SymbolFileDWARF;
18
19typedef std::vector<dw_offset_t> DIEArray;
20
21class HashedNameToDIE
22{
23public:
24    struct Header
25	{
26		uint16_t version;
27		 uint8_t hash_type;
28		 uint8_t hash_index_bitsize;
29		uint32_t num_buckets;
30		uint32_t num_hashes;
31		uint32_t die_offset_base;
32
33		Header() :
34            version(1),
35            hash_type (0),
36            hash_index_bitsize (0),
37            num_buckets(0),
38            num_hashes (0),
39            die_offset_base(0)
40		{
41		}
42	};
43
44
45    HashedNameToDIE (SymbolFileDWARF *dwarf,
46                     const lldb_private::DataExtractor &data);
47
48    ~HashedNameToDIE ()
49    {
50    }
51
52    uint32_t
53    GetHashIndexMask () const
54    {
55        return (1u << m_header.hash_index_bitsize) - 1u;
56    }
57
58    uint32_t
59    GetOffsetForBucket (uint32_t idx) const
60    {
61        if (idx < m_header.num_buckets)
62            return sizeof(Header) + 4 * idx;
63        return UINT32_MAX;
64    }
65
66    uint32_t
67    GetOffsetForHash (uint32_t idx) const
68    {
69        if (idx < m_header.num_hashes)
70            return sizeof(Header) + 4 * m_header.num_buckets + 4 * idx;
71        return UINT32_MAX;
72    }
73
74    uint32_t
75    GetOffsetForOffset (uint32_t idx) const
76    {
77        if (idx < m_header.num_hashes)
78            return sizeof(Header) + 4 * m_header.num_buckets + 4 * m_header.num_hashes + 4 * idx;
79        return UINT32_MAX;
80    }
81
82    void
83    Dump (lldb_private::Stream *s);
84
85    size_t
86    Find (const lldb_private::ConstString &name,
87          DIEArray &die_ofsets) const;
88
89    size_t
90    Find (const lldb_private::RegularExpression& regex,
91          DIEArray &die_ofsets) const;
92
93protected:
94    SymbolFileDWARF *m_dwarf;
95    const lldb_private::DataExtractor &m_data;
96    Header m_header;
97};
98
99#endif  // SymbolFileDWARF_HashedNameToDIE_h_
100