LLDB  mainline
DynamicLoaderDarwin.h
Go to the documentation of this file.
1 //===-- DynamicLoaderDarwin.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 liblldb_DynamicLoaderDarwin_h_
10 #define liblldb_DynamicLoaderDarwin_h_
11 
12 #include <map>
13 #include <mutex>
14 #include <vector>
15 
16 #include "lldb/Host/SafeMachO.h"
18 #include "lldb/Target/Process.h"
19 #include "lldb/Utility/FileSpec.h"
21 #include "lldb/Utility/UUID.h"
22 
23 #include "llvm/ADT/Triple.h"
24 
25 namespace lldb_private {
26 
28 public:
30 
31  ~DynamicLoaderDarwin() override;
32 
33  /// Called after attaching a process.
34  ///
35  /// Allow DynamicLoader plug-ins to execute some code after
36  /// attaching to a process.
37  void DidAttach() override;
38 
39  void DidLaunch() override;
40 
41  lldb::ThreadPlanSP GetStepThroughTrampolinePlan(lldb_private::Thread &thread,
42  bool stop_others) override;
43 
44  size_t FindEquivalentSymbols(
45  lldb_private::Symbol *original_symbol,
46  lldb_private::ModuleList &module_list,
47  lldb_private::SymbolContextList &equivalent_symbols) override;
48 
49  lldb::addr_t GetThreadLocalData(const lldb::ModuleSP module,
50  const lldb::ThreadSP thread,
51  lldb::addr_t tls_file_addr) override;
52 
54 
55  virtual void DoInitialImageFetch() = 0;
56 
57  virtual bool NeedToDoInitialImageFetch() = 0;
58 
59 protected:
61 
63  lldb::StateType state);
64 
65  void Clear(bool clear_process);
66 
67  // Clear method for classes derived from this one
68  virtual void DoClear() = 0;
69 
70  void SetDYLDModule(lldb::ModuleSP &dyld_module_sp);
71 
72  lldb::ModuleSP GetDYLDModule();
73 
74  class Segment {
75  public:
78  filesize(0), maxprot(0), initprot(0), nsects(0), flags(0) {}
79 
89 
90  bool operator==(const Segment &rhs) const {
91  return name == rhs.name && vmaddr == rhs.vmaddr && vmsize == rhs.vmsize;
92  }
93 
94  void PutToLog(lldb_private::Log *log, lldb::addr_t slide) const;
95  };
96 
97  struct ImageInfo {
98  lldb::addr_t address; // Address of mach header for this dylib
99  lldb::addr_t slide; // The amount to slide all segments by if there is a
100  // global slide.
101  lldb::addr_t mod_date; // Modification date for this dylib
102  lldb_private::FileSpec file_spec; // Resolved path for this dylib
104  uuid; // UUID for this dylib if it has one, else all zeros
105  llvm::MachO::mach_header header; // The mach header for this image
106  std::vector<Segment> segments; // All segment vmaddr and vmsize pairs for
107  // this executable (from memory of inferior)
108  uint32_t load_stop_id; // The process stop ID that the sections for this
109  // image were loaded
110  llvm::Triple::OSType os_type; // LC_VERSION_MIN_... load command os type
111  std::string min_version_os_sdk; // LC_VERSION_MIN_... sdk value
112 
114  : address(LLDB_INVALID_ADDRESS), slide(0), mod_date(0), file_spec(),
115  uuid(), header(), segments(), load_stop_id(0),
116  os_type(llvm::Triple::OSType::UnknownOS), min_version_os_sdk() {}
117 
118  void Clear(bool load_cmd_data_only) {
119  if (!load_cmd_data_only) {
120  address = LLDB_INVALID_ADDRESS;
121  slide = 0;
122  mod_date = 0;
123  file_spec.Clear();
124  ::memset(&header, 0, sizeof(header));
125  }
126  uuid.Clear();
127  segments.clear();
128  load_stop_id = 0;
129  os_type = llvm::Triple::OSType::UnknownOS;
130  min_version_os_sdk.clear();
131  }
132 
133  bool operator==(const ImageInfo &rhs) const {
134  return address == rhs.address && slide == rhs.slide &&
135  mod_date == rhs.mod_date && file_spec == rhs.file_spec &&
136  uuid == rhs.uuid &&
137  memcmp(&header, &rhs.header, sizeof(header)) == 0 &&
138  segments == rhs.segments && os_type == rhs.os_type;
139  }
140 
141  bool UUIDValid() const { return uuid.IsValid(); }
142 
144  if (header.cputype) {
145  if (header.cputype & llvm::MachO::CPU_ARCH_ABI64)
146  return 8;
147  else
148  return 4;
149  }
150  return 0;
151  }
152 
155  header.cputype, header.cpusubtype);
156  }
157 
158  const Segment *FindSegment(lldb_private::ConstString name) const;
159 
160  void PutToLog(lldb_private::Log *log) const;
161 
162  typedef std::vector<ImageInfo> collection;
163  typedef collection::iterator iterator;
164  typedef collection::const_iterator const_iterator;
165  };
166 
168 
170 
171  lldb::ModuleSP FindTargetModuleForImageInfo(ImageInfo &image_info,
172  bool can_create,
173  bool *did_create_ptr);
174 
175  void UnloadImages(const std::vector<lldb::addr_t> &solib_addresses);
176 
177  void UnloadAllImages();
178 
179  virtual bool SetNotificationBreakpoint() = 0;
180 
181  virtual void ClearNotificationBreakpoint() = 0;
182 
183  virtual bool DidSetNotificationBreakpoint() = 0;
184 
185  typedef std::map<uint64_t, lldb::addr_t> PthreadKeyToTLSMap;
186  typedef std::map<lldb::user_id_t, PthreadKeyToTLSMap> ThreadIDToTLSMap;
187 
188  std::recursive_mutex &GetMutex() const { return m_mutex; }
189 
190  lldb::ModuleSP GetPThreadLibraryModule();
191 
193 
196  ImageInfo::collection &image_infos);
197 
198  // If image_infos contains / may contain dyld or executable image, call this
199  // method
200  // to keep our internal record keeping of the special binaries up-to-date.
201  void
203 
204  // if image_info is a dyld binary, call this method
206 
207  // If image_infos contains / may contain executable image, call this method
208  // to keep our internal record keeping of the special dyld binary up-to-date.
210 
212 
213  // Whether we should use the new dyld SPI to get shared library information,
214  // or read
215  // it directly out of the dyld_all_image_infos. Whether we use the (newer)
216  // DynamicLoaderMacOS
217  // plugin or the (older) DynamicLoaderMacOSX plugin.
218  static bool UseDYLDSPI(lldb_private::Process *process);
219 
220  lldb::ModuleWP m_dyld_module_wp; // the dyld whose file type (mac, ios, etc)
221  // matches the process
222  lldb::ModuleWP m_libpthread_module_wp;
224  ThreadIDToTLSMap m_tid_to_tls_map;
226  m_dyld_image_infos; // Current shared libraries information
227  uint32_t m_dyld_image_infos_stop_id; // The process stop ID that
228  // "m_dyld_image_infos" is valid for
230  mutable std::recursive_mutex m_mutex;
231 
232 private:
233  DISALLOW_COPY_AND_ASSIGN(DynamicLoaderDarwin);
234 };
235 
236 } // namespace lldb_private
237 
238 #endif // liblldb_DynamicLoaderDarwin_h_
std::map< lldb::user_id_t, PthreadKeyToTLSMap > ThreadIDToTLSMap
bool operator==(const Segment &rhs) const
Defines a list of symbol context objects.
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
DynamicLoaderDarwin(lldb_private::Process *process)
Definition: Debugger.h:71
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:33
virtual bool NeedToDoInitialImageFetch()=0
bool AddModulesUsingImageInfos(ImageInfo::collection &image_infos)
void PrivateInitialize(lldb_private::Process *process)
void DidLaunch() override
Called after attaching a process.
A file utility class.
Definition: FileSpec.h:55
void DidAttach() override
Called after attaching a process.
An architecture specification class.
Definition: ArchSpec.h:32
lldb::addr_t GetThreadLocalData(const lldb::ModuleSP module, const lldb::ThreadSP thread, lldb::addr_t tls_file_addr) override
Retrieves the per-module TLS block for a given thread.
void Clear()
Clears the object state.
Definition: FileSpec.cpp:285
lldb_private::Address m_pthread_getspecific_addr
void UpdateSpecialBinariesFromNewImageInfos(ImageInfo::collection &image_infos)
void UnloadImages(const std::vector< lldb::addr_t > &solib_addresses)
bool operator==(const ImageInfo &rhs) const
virtual bool DidSetNotificationBreakpoint()=0
bool UnloadModuleSections(lldb_private::Module *module, ImageInfo &info)
static bool UseDYLDSPI(lldb_private::Process *process)
std::map< uint64_t, lldb::addr_t > PthreadKeyToTLSMap
void PutToLog(lldb_private::Log *log, lldb::addr_t slide) const
#define LLDB_INVALID_ADDRESS
Invalid value definitions.
Definition: lldb-defines.h:85
size_t FindEquivalentSymbols(lldb_private::Symbol *original_symbol, lldb_private::ModuleList &module_list, lldb_private::SymbolContextList &equivalent_symbols) override
Some dynamic loaders provide features where there are a group of symbols "equivalent to" a given symb...
virtual void DoInitialImageFetch()=0
lldb_private::Address GetPthreadSetSpecificAddress()
A collection class for Module objects.
Definition: ModuleList.h:91
A class that describes an executable image and its associated object and symbol files.
Definition: Module.h:109
lldb::ModuleSP FindTargetModuleForImageInfo(ImageInfo &image_info, bool can_create, bool *did_create_ptr)
A plug-in interface definition class for debugging a process.
Definition: Process.h:353
bool UpdateImageLoadAddress(lldb_private::Module *module, ImageInfo &info)
A section + offset based address class.
Definition: Address.h:80
A plug-in interface definition class for dynamic loaders.
Definition: DynamicLoader.h:64
void PrivateProcessStateChanged(lldb_private::Process *process, lldb::StateType state)
void SetDYLDModule(lldb::ModuleSP &dyld_module_sp)
lldb_private::ArchSpec GetArchitecture() const
lldb::ThreadPlanSP GetStepThroughTrampolinePlan(lldb_private::Thread &thread, bool stop_others) override
Provides a plan to step through the dynamic loader trampoline for the current state of thread...
uint64_t addr_t
Definition: lldb-types.h:83
A uniqued constant string class.
Definition: ConstString.h:38
virtual void ClearNotificationBreakpoint()=0
void UpdateDYLDImageInfoFromNewImageInfo(ImageInfo &image_info)
std::shared_ptr< Object > ObjectSP
bool JSONImageInformationIntoImageInfo(lldb_private::StructuredData::ObjectSP image_details, ImageInfo::collection &image_infos)
std::recursive_mutex & GetMutex() const
ImageInfo::collection m_dyld_image_infos
bool AlwaysRelyOnEHUnwindInfo(lldb_private::SymbolContext &sym_ctx) override
Ask if the eh_frame information for the given SymbolContext should be relied on even when it&#39;s the fi...
void AddExecutableModuleIfInImageInfos(ImageInfo::collection &image_infos)
virtual bool SetNotificationBreakpoint()=0