xref: /freebsd/contrib/llvm-project/lldb/include/lldb/Core/LoadedModuleInfoList.h (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
1 //===-- LoadedModuleInfoList.h ----------------------------------*- C++ -*-===//
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 #ifndef LLDB_CORE_LOADEDMODULEINFOLIST_H
10 #define LLDB_CORE_LOADEDMODULEINFOLIST_H
11 
12 #include <cassert>
13 #include <string>
14 #include <vector>
15 
16 #include "lldb/lldb-defines.h"
17 #include "lldb/lldb-private-forward.h"
18 #include "lldb/lldb-types.h"
19 
20 namespace lldb_private {
21 class LoadedModuleInfoList {
22 public:
23   class LoadedModuleInfo {
24   public:
25     enum e_data_point {
26       e_has_name = 0,
27       e_has_base,
28       e_has_dynamic,
29       e_has_link_map,
30       e_num
31     };
32 
LoadedModuleInfo()33     LoadedModuleInfo() {
34       for (uint32_t i = 0; i < e_num; ++i)
35         m_has[i] = false;
36     };
37 
set_name(const std::string & name)38     void set_name(const std::string &name) {
39       m_name = name;
40       m_has[e_has_name] = true;
41     }
get_name(std::string & out)42     bool get_name(std::string &out) const {
43       out = m_name;
44       return m_has[e_has_name];
45     }
46 
set_base(const lldb::addr_t base)47     void set_base(const lldb::addr_t base) {
48       m_base = base;
49       m_has[e_has_base] = true;
50     }
get_base(lldb::addr_t & out)51     bool get_base(lldb::addr_t &out) const {
52       out = m_base;
53       return m_has[e_has_base];
54     }
55 
set_base_is_offset(bool is_offset)56     void set_base_is_offset(bool is_offset) { m_base_is_offset = is_offset; }
get_base_is_offset(bool & out)57     bool get_base_is_offset(bool &out) const {
58       out = m_base_is_offset;
59       return m_has[e_has_base];
60     }
61 
set_link_map(const lldb::addr_t addr)62     void set_link_map(const lldb::addr_t addr) {
63       m_link_map = addr;
64       m_has[e_has_link_map] = true;
65     }
get_link_map(lldb::addr_t & out)66     bool get_link_map(lldb::addr_t &out) const {
67       out = m_link_map;
68       return m_has[e_has_link_map];
69     }
70 
set_dynamic(const lldb::addr_t addr)71     void set_dynamic(const lldb::addr_t addr) {
72       m_dynamic = addr;
73       m_has[e_has_dynamic] = true;
74     }
get_dynamic(lldb::addr_t & out)75     bool get_dynamic(lldb::addr_t &out) const {
76       out = m_dynamic;
77       return m_has[e_has_dynamic];
78     }
79 
has_info(e_data_point datum)80     bool has_info(e_data_point datum) const {
81       assert(datum < e_num);
82       return m_has[datum];
83     }
84 
85     bool operator==(LoadedModuleInfo const &rhs) const {
86       for (size_t i = 0; i < e_num; ++i) {
87         if (m_has[i] != rhs.m_has[i])
88           return false;
89       }
90 
91       return (m_base == rhs.m_base) && (m_link_map == rhs.m_link_map) &&
92              (m_dynamic == rhs.m_dynamic) && (m_name == rhs.m_name);
93     }
94 
95   protected:
96     bool m_has[e_num];
97     std::string m_name;
98     lldb::addr_t m_link_map = LLDB_INVALID_ADDRESS;
99     lldb::addr_t m_base = LLDB_INVALID_ADDRESS;
100     bool m_base_is_offset = false;
101     lldb::addr_t m_dynamic = LLDB_INVALID_ADDRESS;
102   };
103 
104   LoadedModuleInfoList() = default;
105 
add(const LoadedModuleInfo & mod)106   void add(const LoadedModuleInfo &mod) { m_list.push_back(mod); }
107 
clear()108   void clear() { m_list.clear(); }
109 
110   std::vector<LoadedModuleInfo> m_list;
111   lldb::addr_t m_link_map = LLDB_INVALID_ADDRESS;
112 };
113 } // namespace lldb_private
114 
115 #endif // LLDB_CORE_LOADEDMODULEINFOLIST_H
116