1 //===-- HexagonDYLDRendezvous.h ---------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_HexagonDYLDRendezvous_H_
10 #define liblldb_HexagonDYLDRendezvous_H_
17 #include "lldb/lldb-defines.h"
18 #include "lldb/lldb-types.h"
20 namespace lldb_private {
24 /// \class HexagonDYLDRendezvous
25 /// Interface to the runtime linker.
27 /// A structure is present in a processes memory space which is updated by the
28 /// runtime liker each time a module is loaded or unloaded. This class
29 /// provides an interface to this structure and maintains a consistent
30 /// snapshot of the currently loaded modules.
31 class HexagonDYLDRendezvous {
33 // This structure is used to hold the contents of the debug rendezvous
34 // information (struct r_debug) as found in the inferiors memory. Note that
35 // the layout of this struct is not binary compatible, it is simply large
36 // enough to hold the information on both 32 and 64 bit platforms.
39 lldb::addr_t map_addr;
45 : version(0), map_addr(LLDB_INVALID_ADDRESS), brk(LLDB_INVALID_ADDRESS),
46 state(0), ldbase(0) {}
50 // Various metadata supplied by the inferior's threading library to describe
51 // the per-thread state.
53 bool valid; // whether we read valid metadata
54 uint32_t dtv_offset; // offset of DTV pointer within pthread
55 uint32_t dtv_slot_size; // size of one DTV slot
56 uint32_t modid_offset; // offset of module ID within link_map
57 uint32_t tls_offset; // offset of TLS pointer within DTV slot
60 HexagonDYLDRendezvous(lldb_private::Process *process);
62 /// Update the internal snapshot of runtime linker rendezvous and recompute
63 /// the currently loaded modules.
65 /// This method should be called once one start up, then once each time the
66 /// runtime linker enters the function given by GetBreakAddress().
68 /// \returns true on success and false on failure.
70 /// \see GetBreakAddress().
73 /// \returns true if this rendezvous has been located in the inferiors
74 /// address space and false otherwise.
77 /// \returns the address of the rendezvous structure in the inferiors
79 lldb::addr_t GetRendezvousAddress() const { return m_rendezvous_addr; }
81 /// Provide the dyld structure address
82 void SetRendezvousAddress(lldb::addr_t);
84 /// \returns the version of the rendezvous protocol being used.
85 uint64_t GetVersion() const { return m_current.version; }
87 /// \returns address in the inferiors address space containing the linked
88 /// list of shared object descriptors.
89 lldb::addr_t GetLinkMapAddress() const { return m_current.map_addr; }
91 /// A breakpoint should be set at this address and Resolve called on each
94 /// \returns the address of a function called by the runtime linker each
95 /// time a module is loaded/unloaded, or about to be loaded/unloaded.
98 lldb::addr_t GetBreakAddress() const { return m_current.brk; }
100 /// In hexagon it is possible that we can know the dyld breakpoint without
101 /// having to find it from the rendezvous structure
103 void SetBreakAddress(lldb::addr_t addr) { m_current.brk = addr; }
105 /// Returns the current state of the rendezvous structure.
106 uint64_t GetState() const { return m_current.state; }
108 /// \returns the base address of the runtime linker in the inferiors address
110 lldb::addr_t GetLDBase() const { return m_current.ldbase; }
112 /// \returns the thread layout metadata from the inferiors thread library.
113 const ThreadInfo &GetThreadInfo();
115 /// \returns true if modules have been loaded into the inferior since the
116 /// last call to Resolve().
117 bool ModulesDidLoad() const { return !m_added_soentries.empty(); }
119 /// \returns true if modules have been unloaded from the inferior since the
120 /// last call to Resolve().
121 bool ModulesDidUnload() const { return !m_removed_soentries.empty(); }
123 void DumpToLog(lldb_private::Log *log) const;
125 /// Constants describing the state of the rendezvous.
128 enum RendezvousState {
134 /// Structure representing the shared objects currently loaded into the
135 /// inferior process.
137 /// This object is a rough analogue to the struct link_map object which
138 /// actually lives in the inferiors memory.
140 lldb::addr_t link_addr; ///< Address of this link_map.
141 lldb::addr_t base_addr; ///< Base address of the loaded object.
142 lldb::addr_t path_addr; ///< String naming the shared object.
143 lldb::addr_t dyn_addr; ///< Dynamic section of shared object.
144 lldb::addr_t next; ///< Address of next so_entry.
145 lldb::addr_t prev; ///< Address of previous so_entry.
146 std::string path; ///< File name of shared object.
148 SOEntry() { clear(); }
150 bool operator==(const SOEntry &entry) { return this->path == entry.path; }
164 typedef std::list<SOEntry> SOEntryList;
167 typedef SOEntryList::const_iterator iterator;
169 /// Iterators over all currently loaded modules.
170 iterator begin() const { return m_soentries.begin(); }
171 iterator end() const { return m_soentries.end(); }
173 /// Iterators over all modules loaded into the inferior since the last call
175 iterator loaded_begin() const { return m_added_soentries.begin(); }
176 iterator loaded_end() const { return m_added_soentries.end(); }
178 /// Iterators over all modules unloaded from the inferior since the last
179 /// call to Resolve().
180 iterator unloaded_begin() const { return m_removed_soentries.begin(); }
181 iterator unloaded_end() const { return m_removed_soentries.end(); }
184 lldb_private::Process *m_process;
186 // Cached copy of executable pathname
187 char m_exe_path[PATH_MAX];
189 /// Location of the r_debug structure in the inferiors address space.
190 lldb::addr_t m_rendezvous_addr;
192 /// Current and previous snapshots of the rendezvous structure.
193 Rendezvous m_current;
194 Rendezvous m_previous;
196 /// List of SOEntry objects corresponding to the current link map state.
197 SOEntryList m_soentries;
199 /// List of SOEntry's added to the link map since the last call to
201 SOEntryList m_added_soentries;
203 /// List of SOEntry's removed from the link map since the last call to
205 SOEntryList m_removed_soentries;
207 /// Threading metadata read from the inferior.
208 ThreadInfo m_thread_info;
210 /// Reads an unsigned integer of \p size bytes from the inferior's address
211 /// space starting at \p addr.
213 /// \returns addr + size if the read was successful and false otherwise.
214 lldb::addr_t ReadWord(lldb::addr_t addr, uint64_t *dst, size_t size);
216 /// Reads an address from the inferior's address space starting at \p addr.
218 /// \returns addr + target address size if the read was successful and
220 lldb::addr_t ReadPointer(lldb::addr_t addr, lldb::addr_t *dst);
222 /// Reads a null-terminated C string from the memory location starting at @p
224 std::string ReadStringFromMemory(lldb::addr_t addr);
226 /// Reads an SOEntry starting at \p addr.
227 bool ReadSOEntryFromMemory(lldb::addr_t addr, SOEntry &entry);
229 /// Updates the current set of SOEntries, the set of added entries, and the
230 /// set of removed entries.
231 bool UpdateSOEntries();
233 bool UpdateSOEntriesForAddition();
235 bool UpdateSOEntriesForDeletion();
237 /// Reads the current list of shared objects according to the link map
238 /// supplied by the runtime linker.
239 bool TakeSnapshot(SOEntryList &entry_list);
241 enum PThreadField { eSize, eNElem, eOffset };
243 bool FindMetadata(const char *name, PThreadField field, uint32_t &value);
246 #endif // liblldb_HexagonDYLDRendezvous_H_