LLDB  mainline
HexagonDYLDRendezvous.h
Go to the documentation of this file.
1 //===-- HexagonDYLDRendezvous.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_SOURCE_PLUGINS_DYNAMICLOADER_HEXAGON_DYLD_HEXAGONDYLDRENDEZVOUS_H
10 #define LLDB_SOURCE_PLUGINS_DYNAMICLOADER_HEXAGON_DYLD_HEXAGONDYLDRENDEZVOUS_H
11 
12 #include <limits.h>
13 #include <list>
14 #include <map>
15 #include <string>
16 
17 #include "lldb/lldb-defines.h"
18 #include "lldb/lldb-types.h"
19 
20 namespace lldb_private {
21 class Process;
22 }
23 
24 /// \class HexagonDYLDRendezvous
25 /// Interface to the runtime linker.
26 ///
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.
32 
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.
37  struct Rendezvous {
38  uint64_t version;
41  uint64_t state;
43 
46  state(0), ldbase(0) {}
47  };
48 
49 public:
50  // Various metadata supplied by the inferior's threading library to describe
51  // the per-thread state.
52  struct ThreadInfo {
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
58  };
59 
61 
62  /// Update the internal snapshot of runtime linker rendezvous and recompute
63  /// the currently loaded modules.
64  ///
65  /// This method should be called once one start up, then once each time the
66  /// runtime linker enters the function given by GetBreakAddress().
67  ///
68  /// \returns true on success and false on failure.
69  ///
70  /// \see GetBreakAddress().
71  bool Resolve();
72 
73  /// \returns true if this rendezvous has been located in the inferiors
74  /// address space and false otherwise.
75  bool IsValid();
76 
77  /// \returns the address of the rendezvous structure in the inferiors
78  /// address space.
80 
81  /// Provide the dyld structure address
83 
84  /// \returns the version of the rendezvous protocol being used.
85  uint64_t GetVersion() const { return m_current.version; }
86 
87  /// \returns address in the inferiors address space containing the linked
88  /// list of shared object descriptors.
90 
91  /// A breakpoint should be set at this address and Resolve called on each
92  /// hit.
93  ///
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.
96  ///
97  /// \see Resolve()
99 
100  /// In hexagon it is possible that we can know the dyld breakpoint without
101  /// having to find it from the rendezvous structure
102  ///
103  void SetBreakAddress(lldb::addr_t addr) { m_current.brk = addr; }
104 
105  /// Returns the current state of the rendezvous structure.
106  uint64_t GetState() const { return m_current.state; }
107 
108  /// \returns the base address of the runtime linker in the inferiors address
109  /// space.
111 
112  /// \returns the thread layout metadata from the inferiors thread library.
113  const ThreadInfo &GetThreadInfo();
114 
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(); }
118 
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(); }
122 
123  void DumpToLog(lldb_private::Log *log) const;
124 
125  /// Constants describing the state of the rendezvous.
126  ///
127  /// \see GetState().
132  };
133 
134  /// Structure representing the shared objects currently loaded into the
135  /// inferior process.
136  ///
137  /// This object is a rough analogue to the struct link_map object which
138  /// actually lives in the inferiors memory.
139  struct SOEntry {
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.
147 
148  SOEntry() { clear(); }
149 
150  bool operator==(const SOEntry &entry) { return this->path == entry.path; }
151 
152  void clear() {
153  link_addr = 0;
154  base_addr = 0;
155  path_addr = 0;
156  dyn_addr = 0;
157  next = 0;
158  prev = 0;
159  path.clear();
160  }
161  };
162 
163 protected:
164  typedef std::list<SOEntry> SOEntryList;
165 
166 public:
167  typedef SOEntryList::const_iterator iterator;
168 
169  /// Iterators over all currently loaded modules.
170  iterator begin() const { return m_soentries.begin(); }
171  iterator end() const { return m_soentries.end(); }
172 
173  /// Iterators over all modules loaded into the inferior since the last call
174  /// to Resolve().
175  iterator loaded_begin() const { return m_added_soentries.begin(); }
176  iterator loaded_end() const { return m_added_soentries.end(); }
177 
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(); }
182 
183 protected:
185 
186  // Cached copy of executable pathname
188 
189  /// Location of the r_debug structure in the inferiors address space.
191 
192  /// Current and previous snapshots of the rendezvous structure.
195 
196  /// List of SOEntry objects corresponding to the current link map state.
198 
199  /// List of SOEntry's added to the link map since the last call to
200  /// Resolve().
202 
203  /// List of SOEntry's removed from the link map since the last call to
204  /// Resolve().
206 
207  /// Threading metadata read from the inferior.
209 
210  /// Reads an unsigned integer of \p size bytes from the inferior's address
211  /// space starting at \p addr.
212  ///
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);
215 
216  /// Reads an address from the inferior's address space starting at \p addr.
217  ///
218  /// \returns addr + target address size if the read was successful and
219  /// 0 otherwise.
221 
222  /// Reads a null-terminated C string from the memory location starting at @p
223  /// addr.
225 
226  /// Reads an SOEntry starting at \p addr.
227  bool ReadSOEntryFromMemory(lldb::addr_t addr, SOEntry &entry);
228 
229  /// Updates the current set of SOEntries, the set of added entries, and the
230  /// set of removed entries.
231  bool UpdateSOEntries();
232 
234 
236 
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);
240 
242 
243  bool FindMetadata(const char *name, PThreadField field, uint32_t &value);
244 };
245 
246 #endif // LLDB_SOURCE_PLUGINS_DYNAMICLOADER_HEXAGON_DYLD_HEXAGONDYLDRENDEZVOUS_H
HexagonDYLDRendezvous::SOEntry::operator==
bool operator==(const SOEntry &entry)
Definition: HexagonDYLDRendezvous.h:150
HexagonDYLDRendezvous::ThreadInfo::dtv_offset
uint32_t dtv_offset
Definition: HexagonDYLDRendezvous.h:54
HexagonDYLDRendezvous::eOffset
@ eOffset
Definition: HexagonDYLDRendezvous.h:241
HexagonDYLDRendezvous::GetLinkMapAddress
lldb::addr_t GetLinkMapAddress() const
Definition: HexagonDYLDRendezvous.h:89
HexagonDYLDRendezvous::iterator
SOEntryList::const_iterator iterator
Definition: HexagonDYLDRendezvous.h:167
HexagonDYLDRendezvous::ModulesDidUnload
bool ModulesDidUnload() const
Definition: HexagonDYLDRendezvous.h:121
HexagonDYLDRendezvous::RendezvousState
RendezvousState
Constants describing the state of the rendezvous.
Definition: HexagonDYLDRendezvous.h:128
HexagonDYLDRendezvous::UpdateSOEntries
bool UpdateSOEntries()
Updates the current set of SOEntries, the set of added entries, and the set of removed entries.
Definition: HexagonDYLDRendezvous.cpp:111
lldb-defines.h
HexagonDYLDRendezvous::Rendezvous::state
uint64_t state
Definition: HexagonDYLDRendezvous.h:41
HexagonDYLDRendezvous::GetRendezvousAddress
lldb::addr_t GetRendezvousAddress() const
Definition: HexagonDYLDRendezvous.h:79
HexagonDYLDRendezvous::ModulesDidLoad
bool ModulesDidLoad() const
Definition: HexagonDYLDRendezvous.h:117
lldb_private::Process
Definition: Process.h:342
HexagonDYLDRendezvous::SOEntry
Structure representing the shared objects currently loaded into the inferior process.
Definition: HexagonDYLDRendezvous.h:139
HexagonDYLDRendezvous::Rendezvous::map_addr
lldb::addr_t map_addr
Definition: HexagonDYLDRendezvous.h:39
HexagonDYLDRendezvous::GetLDBase
lldb::addr_t GetLDBase() const
Definition: HexagonDYLDRendezvous.h:110
HexagonDYLDRendezvous::end
iterator end() const
Definition: HexagonDYLDRendezvous.h:171
HexagonDYLDRendezvous::Rendezvous::ldbase
lldb::addr_t ldbase
Definition: HexagonDYLDRendezvous.h:42
HexagonDYLDRendezvous::PThreadField
PThreadField
Definition: HexagonDYLDRendezvous.h:241
HexagonDYLDRendezvous::GetVersion
uint64_t GetVersion() const
Definition: HexagonDYLDRendezvous.h:85
HexagonDYLDRendezvous::TakeSnapshot
bool TakeSnapshot(SOEntryList &entry_list)
Reads the current list of shared objects according to the link map supplied by the runtime linker.
Definition: HexagonDYLDRendezvous.cpp:196
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
HexagonDYLDRendezvous::m_previous
Rendezvous m_previous
Definition: HexagonDYLDRendezvous.h:194
HexagonDYLDRendezvous::ThreadInfo::valid
bool valid
Definition: HexagonDYLDRendezvous.h:53
HexagonDYLDRendezvous::SOEntry::path
std::string path
File name of shared object.
Definition: HexagonDYLDRendezvous.h:146
HexagonDYLDRendezvous::GetBreakAddress
lldb::addr_t GetBreakAddress() const
A breakpoint should be set at this address and Resolve called on each hit.
Definition: HexagonDYLDRendezvous.h:98
HexagonDYLDRendezvous::m_process
lldb_private::Process * m_process
Definition: HexagonDYLDRendezvous.h:184
HexagonDYLDRendezvous::eAdd
@ eAdd
Definition: HexagonDYLDRendezvous.h:130
HexagonDYLDRendezvous::ThreadInfo::tls_offset
uint32_t tls_offset
Definition: HexagonDYLDRendezvous.h:57
HexagonDYLDRendezvous::SOEntry::prev
lldb::addr_t prev
Address of previous so_entry.
Definition: HexagonDYLDRendezvous.h:145
HexagonDYLDRendezvous::IsValid
bool IsValid()
Definition: HexagonDYLDRendezvous.cpp:107
HexagonDYLDRendezvous::m_added_soentries
SOEntryList m_added_soentries
List of SOEntry's added to the link map since the last call to Resolve().
Definition: HexagonDYLDRendezvous.h:201
HexagonDYLDRendezvous::SOEntry::clear
void clear()
Definition: HexagonDYLDRendezvous.h:152
HexagonDYLDRendezvous::m_removed_soentries
SOEntryList m_removed_soentries
List of SOEntry's removed from the link map since the last call to Resolve().
Definition: HexagonDYLDRendezvous.h:205
HexagonDYLDRendezvous::m_current
Rendezvous m_current
Current and previous snapshots of the rendezvous structure.
Definition: HexagonDYLDRendezvous.h:193
HexagonDYLDRendezvous::Resolve
bool Resolve()
Update the internal snapshot of runtime linker rendezvous and recompute the currently loaded modules.
Definition: HexagonDYLDRendezvous.cpp:61
HexagonDYLDRendezvous::ReadStringFromMemory
std::string ReadStringFromMemory(lldb::addr_t addr)
Reads a null-terminated C string from the memory location starting at addr.
Definition: HexagonDYLDRendezvous.cpp:239
HexagonDYLDRendezvous::ThreadInfo
Definition: HexagonDYLDRendezvous.h:52
HexagonDYLDRendezvous::loaded_end
iterator loaded_end() const
Definition: HexagonDYLDRendezvous.h:176
HexagonDYLDRendezvous::GetState
uint64_t GetState() const
Returns the current state of the rendezvous structure.
Definition: HexagonDYLDRendezvous.h:106
HexagonDYLDRendezvous::loaded_begin
iterator loaded_begin() const
Iterators over all modules loaded into the inferior since the last call to Resolve().
Definition: HexagonDYLDRendezvous.h:175
HexagonDYLDRendezvous::eDelete
@ eDelete
Definition: HexagonDYLDRendezvous.h:131
HexagonDYLDRendezvous::ThreadInfo::dtv_slot_size
uint32_t dtv_slot_size
Definition: HexagonDYLDRendezvous.h:55
HexagonDYLDRendezvous::SetBreakAddress
void SetBreakAddress(lldb::addr_t addr)
In hexagon it is possible that we can know the dyld breakpoint without having to find it from the ren...
Definition: HexagonDYLDRendezvous.h:103
HexagonDYLDRendezvous::Rendezvous::Rendezvous
Rendezvous()
Definition: HexagonDYLDRendezvous.h:44
HexagonDYLDRendezvous::eSize
@ eSize
Definition: HexagonDYLDRendezvous.h:241
HexagonDYLDRendezvous::UpdateSOEntriesForAddition
bool UpdateSOEntriesForAddition()
Definition: HexagonDYLDRendezvous.cpp:148
HexagonDYLDRendezvous::ReadSOEntryFromMemory
bool ReadSOEntryFromMemory(lldb::addr_t addr, SOEntry &entry)
Reads an SOEntry starting at addr.
Definition: HexagonDYLDRendezvous.cpp:263
HexagonDYLDRendezvous::HexagonDYLDRendezvous
HexagonDYLDRendezvous(lldb_private::Process *process)
Definition: HexagonDYLDRendezvous.cpp:48
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:38
HexagonDYLDRendezvous
Definition: HexagonDYLDRendezvous.h:31
HexagonDYLDRendezvous::Rendezvous::brk
lldb::addr_t brk
Definition: HexagonDYLDRendezvous.h:40
HexagonDYLDRendezvous::GetThreadInfo
const ThreadInfo & GetThreadInfo()
Definition: HexagonDYLDRendezvous.cpp:316
HexagonDYLDRendezvous::ReadWord
lldb::addr_t ReadWord(lldb::addr_t addr, uint64_t *dst, size_t size)
Reads an unsigned integer of size bytes from the inferior's address space starting at addr.
Definition: HexagonDYLDRendezvous.cpp:218
lldb-types.h
HexagonDYLDRendezvous::Rendezvous::version
uint64_t version
Definition: HexagonDYLDRendezvous.h:38
HexagonDYLDRendezvous::SOEntry::link_addr
lldb::addr_t link_addr
Address of this link_map.
Definition: HexagonDYLDRendezvous.h:140
HexagonDYLDRendezvous::begin
iterator begin() const
Iterators over all currently loaded modules.
Definition: HexagonDYLDRendezvous.h:170
uint32_t
HexagonDYLDRendezvous::ReadPointer
lldb::addr_t ReadPointer(lldb::addr_t addr, lldb::addr_t *dst)
Reads an address from the inferior's address space starting at addr.
Definition: HexagonDYLDRendezvous.cpp:229
HexagonDYLDRendezvous::SOEntryList
std::list< SOEntry > SOEntryList
Definition: HexagonDYLDRendezvous.h:164
HexagonDYLDRendezvous::SOEntry::dyn_addr
lldb::addr_t dyn_addr
Dynamic section of shared object.
Definition: HexagonDYLDRendezvous.h:143
HexagonDYLDRendezvous::DumpToLog
void DumpToLog(lldb_private::Log *log) const
Definition: HexagonDYLDRendezvous.cpp:336
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Invalid value definitions.
Definition: lldb-defines.h:85
HexagonDYLDRendezvous::SOEntry::next
lldb::addr_t next
Address of next so_entry.
Definition: HexagonDYLDRendezvous.h:144
HexagonDYLDRendezvous::eConsistent
@ eConsistent
Definition: HexagonDYLDRendezvous.h:129
HexagonDYLDRendezvous::SOEntry::base_addr
lldb::addr_t base_addr
Base address of the loaded object.
Definition: HexagonDYLDRendezvous.h:141
HexagonDYLDRendezvous::ThreadInfo::modid_offset
uint32_t modid_offset
Definition: HexagonDYLDRendezvous.h:56
HexagonDYLDRendezvous::unloaded_begin
iterator unloaded_begin() const
Iterators over all modules unloaded from the inferior since the last call to Resolve().
Definition: HexagonDYLDRendezvous.h:180
HexagonDYLDRendezvous::m_soentries
SOEntryList m_soentries
List of SOEntry objects corresponding to the current link map state.
Definition: HexagonDYLDRendezvous.h:197
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
HexagonDYLDRendezvous::m_rendezvous_addr
lldb::addr_t m_rendezvous_addr
Location of the r_debug structure in the inferiors address space.
Definition: HexagonDYLDRendezvous.h:190
HexagonDYLDRendezvous::SOEntry::SOEntry
SOEntry()
Definition: HexagonDYLDRendezvous.h:148
HexagonDYLDRendezvous::Rendezvous
Definition: HexagonDYLDRendezvous.h:37
lldb_private::Log
Definition: Log.h:49
HexagonDYLDRendezvous::unloaded_end
iterator unloaded_end() const
Definition: HexagonDYLDRendezvous.h:181
HexagonDYLDRendezvous::SetRendezvousAddress
void SetRendezvousAddress(lldb::addr_t)
Provide the dyld structure address.
Definition: HexagonDYLDRendezvous.cpp:103
HexagonDYLDRendezvous::FindMetadata
bool FindMetadata(const char *name, PThreadField field, uint32_t &value)
Definition: HexagonDYLDRendezvous.cpp:288
PATH_MAX
#define PATH_MAX
Definition: windows/PosixApi.h:25
HexagonDYLDRendezvous::m_exe_path
char m_exe_path[PATH_MAX]
Definition: HexagonDYLDRendezvous.h:187
HexagonDYLDRendezvous::UpdateSOEntriesForDeletion
bool UpdateSOEntriesForDeletion()
Definition: HexagonDYLDRendezvous.cpp:177
HexagonDYLDRendezvous::eNElem
@ eNElem
Definition: HexagonDYLDRendezvous.h:241
HexagonDYLDRendezvous::SOEntry::path_addr
lldb::addr_t path_addr
String naming the shared object.
Definition: HexagonDYLDRendezvous.h:142
HexagonDYLDRendezvous::m_thread_info
ThreadInfo m_thread_info
Threading metadata read from the inferior.
Definition: HexagonDYLDRendezvous.h:208