LLDB  mainline
DynamicLoaderDarwin.cpp
Go to the documentation of this file.
1 //===-- DynamicLoaderDarwin.cpp -----------------------------*- 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 #include "DynamicLoaderDarwin.h"
10 
12 #include "lldb/Core/Debugger.h"
13 #include "lldb/Core/Module.h"
14 #include "lldb/Core/ModuleSpec.h"
16 #include "lldb/Core/Section.h"
18 #include "lldb/Host/FileSystem.h"
20 #include "lldb/Symbol/Function.h"
21 #include "lldb/Symbol/ObjectFile.h"
22 #include "lldb/Target/ABI.h"
25 #include "lldb/Target/StackFrame.h"
26 #include "lldb/Target/Target.h"
27 #include "lldb/Target/Thread.h"
32 #include "lldb/Utility/Log.h"
33 #include "lldb/Utility/State.h"
34 
35 //#define ENABLE_DEBUG_PRINTF // COMMENT THIS LINE OUT PRIOR TO CHECKIN
36 #ifdef ENABLE_DEBUG_PRINTF
37 #include <stdio.h>
38 #define DEBUG_PRINTF(fmt, ...) printf(fmt, ##__VA_ARGS__)
39 #else
40 #define DEBUG_PRINTF(fmt, ...)
41 #endif
42 
43 #ifndef __APPLE__
45 #else
46 #include <uuid/uuid.h>
47 #endif
48 
49 #include <memory>
50 
51 using namespace lldb;
52 using namespace lldb_private;
53 
54 // Constructor
55 DynamicLoaderDarwin::DynamicLoaderDarwin(Process *process)
56  : DynamicLoader(process), m_dyld_module_wp(), m_libpthread_module_wp(),
57  m_pthread_getspecific_addr(), m_tid_to_tls_map(), m_dyld_image_infos(),
58  m_dyld_image_infos_stop_id(UINT32_MAX), m_dyld(), m_mutex() {}
59 
60 // Destructor
62 
63 /// Called after attaching a process.
64 ///
65 /// Allow DynamicLoader plug-ins to execute some code after
66 /// attaching to a process.
71 }
72 
73 /// Called after attaching a process.
74 ///
75 /// Allow DynamicLoader plug-ins to execute some code after
76 /// attaching to a process.
81 }
82 
83 // Clear out the state of this class.
84 void DynamicLoaderDarwin::Clear(bool clear_process) {
85  std::lock_guard<std::recursive_mutex> guard(m_mutex);
86  if (clear_process)
87  m_process = NULL;
88  m_dyld_image_infos.clear();
90  m_dyld.Clear(false);
91 }
92 
94  ImageInfo &image_info, bool can_create, bool *did_create_ptr) {
95  if (did_create_ptr)
96  *did_create_ptr = false;
97 
98  Target &target = m_process->GetTarget();
99  const ModuleList &target_images = target.GetImages();
100  ModuleSpec module_spec(image_info.file_spec);
101  module_spec.GetUUID() = image_info.uuid;
102  ModuleSP module_sp(target_images.FindFirstModule(module_spec));
103 
104  if (module_sp && !module_spec.GetUUID().IsValid() &&
105  !module_sp->GetUUID().IsValid()) {
106  // No UUID, we must rely upon the cached module modification time and the
107  // modification time of the file on disk
108  if (module_sp->GetModificationTime() !=
109  FileSystem::Instance().GetModificationTime(module_sp->GetFileSpec()))
110  module_sp.reset();
111  }
112 
113  if (!module_sp) {
114  if (can_create) {
115  // We'll call Target::ModulesDidLoad after all the modules have been
116  // added to the target, don't let it be called for every one.
117  module_sp = target.GetOrCreateModule(module_spec, false /* notify */);
118  if (!module_sp || module_sp->GetObjectFile() == NULL)
119  module_sp = m_process->ReadModuleFromMemory(image_info.file_spec,
120  image_info.address);
121 
122  if (did_create_ptr)
123  *did_create_ptr = (bool)module_sp;
124  }
125  }
126  return module_sp;
127 }
128 
130  const std::vector<lldb::addr_t> &solib_addresses) {
131  std::lock_guard<std::recursive_mutex> guard(m_mutex);
133  return;
134 
136  Target &target = m_process->GetTarget();
137  if (log)
138  log->Printf("Removing %" PRId64 " modules.",
139  (uint64_t)solib_addresses.size());
140 
141  ModuleList unloaded_module_list;
142 
143  for (addr_t solib_addr : solib_addresses) {
144  Address header;
145  if (header.SetLoadAddress(solib_addr, &target)) {
146  if (header.GetOffset() == 0) {
147  ModuleSP module_to_remove(header.GetModule());
148  if (module_to_remove.get()) {
149  if (log)
150  log->Printf("Removing module at address 0x%" PRIx64, solib_addr);
151  // remove the sections from the Target
152  UnloadSections(module_to_remove);
153  // add this to the list of modules to remove
154  unloaded_module_list.AppendIfNeeded(module_to_remove);
155  // remove the entry from the m_dyld_image_infos
156  ImageInfo::collection::iterator pos, end = m_dyld_image_infos.end();
157  for (pos = m_dyld_image_infos.begin(); pos != end; pos++) {
158  if (solib_addr == (*pos).address) {
159  m_dyld_image_infos.erase(pos);
160  break;
161  }
162  }
163  }
164  }
165  }
166  }
167 
168  if (unloaded_module_list.GetSize() > 0) {
169  if (log) {
170  log->PutCString("Unloaded:");
171  unloaded_module_list.LogUUIDAndPaths(
172  log, "DynamicLoaderDarwin::UnloadModules");
173  }
174  m_process->GetTarget().GetImages().Remove(unloaded_module_list);
176  }
177 }
178 
181  ModuleList unloaded_modules_list;
182 
183  Target &target = m_process->GetTarget();
184  const ModuleList &target_modules = target.GetImages();
185  std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
186 
187  size_t num_modules = target_modules.GetSize();
188  ModuleSP dyld_sp(GetDYLDModule());
189 
190  for (size_t i = 0; i < num_modules; i++) {
191  ModuleSP module_sp = target_modules.GetModuleAtIndexUnlocked(i);
192 
193  // Don't remove dyld - else we'll lose our breakpoint notifying us about
194  // libraries being re-loaded...
195  if (module_sp.get() != nullptr && module_sp.get() != dyld_sp.get()) {
196  UnloadSections(module_sp);
197  unloaded_modules_list.Append(module_sp);
198  }
199  }
200 
201  if (unloaded_modules_list.GetSize() != 0) {
202  if (log) {
203  log->PutCString("Unloaded:");
204  unloaded_modules_list.LogUUIDAndPaths(
205  log, "DynamicLoaderDarwin::UnloadAllImages");
206  }
207  target.GetImages().Remove(unloaded_modules_list);
208  m_dyld_image_infos.clear();
210  }
211 }
212 
213 // Update the load addresses for all segments in MODULE using the updated INFO
214 // that is passed in.
216  ImageInfo &info) {
217  bool changed = false;
218  if (module) {
219  ObjectFile *image_object_file = module->GetObjectFile();
220  if (image_object_file) {
221  SectionList *section_list = image_object_file->GetSectionList();
222  if (section_list) {
223  std::vector<uint32_t> inaccessible_segment_indexes;
224  // We now know the slide amount, so go through all sections and update
225  // the load addresses with the correct values.
226  const size_t num_segments = info.segments.size();
227  for (size_t i = 0; i < num_segments; ++i) {
228  // Only load a segment if it has protections. Things like __PAGEZERO
229  // don't have any protections, and they shouldn't be slid
230  SectionSP section_sp(
231  section_list->FindSectionByName(info.segments[i].name));
232 
233  if (info.segments[i].maxprot == 0) {
234  inaccessible_segment_indexes.push_back(i);
235  } else {
236  const addr_t new_section_load_addr =
237  info.segments[i].vmaddr + info.slide;
238  static ConstString g_section_name_LINKEDIT("__LINKEDIT");
239 
240  if (section_sp) {
241  // __LINKEDIT sections from files in the shared cache can overlap
242  // so check to see what the segment name is and pass "false" so
243  // we don't warn of overlapping "Section" objects, and "true" for
244  // all other sections.
245  const bool warn_multiple =
246  section_sp->GetName() != g_section_name_LINKEDIT;
247 
249  section_sp, new_section_load_addr, warn_multiple);
250  }
251  }
252  }
253 
254  // If the loaded the file (it changed) and we have segments that are
255  // not readable or writeable, add them to the invalid memory region
256  // cache for the process. This will typically only be the __PAGEZERO
257  // segment in the main executable. We might be able to apply this more
258  // generally to more sections that have no protections in the future,
259  // but for now we are going to just do __PAGEZERO.
260  if (changed && !inaccessible_segment_indexes.empty()) {
261  for (uint32_t i = 0; i < inaccessible_segment_indexes.size(); ++i) {
262  const uint32_t seg_idx = inaccessible_segment_indexes[i];
263  SectionSP section_sp(
264  section_list->FindSectionByName(info.segments[seg_idx].name));
265 
266  if (section_sp) {
267  static ConstString g_pagezero_section_name("__PAGEZERO");
268  if (g_pagezero_section_name == section_sp->GetName()) {
269  // __PAGEZERO never slides...
270  const lldb::addr_t vmaddr = info.segments[seg_idx].vmaddr;
271  const lldb::addr_t vmsize = info.segments[seg_idx].vmsize;
272  Process::LoadRange pagezero_range(vmaddr, vmsize);
273  m_process->AddInvalidMemoryRegion(pagezero_range);
274  }
275  }
276  }
277  }
278  }
279  }
280  }
281  // We might have an in memory image that was loaded as soon as it was created
282  if (info.load_stop_id == m_process->GetStopID())
283  changed = true;
284  else if (changed) {
285  // Update the stop ID when this library was updated
286  info.load_stop_id = m_process->GetStopID();
287  }
288  return changed;
289 }
290 
291 // Unload the segments in MODULE using the INFO that is passed in.
293  ImageInfo &info) {
294  bool changed = false;
295  if (module) {
296  ObjectFile *image_object_file = module->GetObjectFile();
297  if (image_object_file) {
298  SectionList *section_list = image_object_file->GetSectionList();
299  if (section_list) {
300  const size_t num_segments = info.segments.size();
301  for (size_t i = 0; i < num_segments; ++i) {
302  SectionSP section_sp(
303  section_list->FindSectionByName(info.segments[i].name));
304  if (section_sp) {
305  const addr_t old_section_load_addr =
306  info.segments[i].vmaddr + info.slide;
308  section_sp, old_section_load_addr))
309  changed = true;
310  } else {
312  "warning: unable to find and unload segment named "
313  "'%s' in '%s' in macosx dynamic loader plug-in.\n",
314  info.segments[i].name.AsCString("<invalid>"),
315  image_object_file->GetFileSpec().GetPath().c_str());
316  }
317  }
318  }
319  }
320  }
321  return changed;
322 }
323 
324 // Given a JSON dictionary (from debugserver, most likely) of binary images
325 // loaded in the inferior process, add the images to the ImageInfo collection.
326 
328  StructuredData::ObjectSP image_details,
329  ImageInfo::collection &image_infos) {
330  StructuredData::ObjectSP images_sp =
331  image_details->GetAsDictionary()->GetValueForKey("images");
332  if (images_sp.get() == nullptr)
333  return false;
334 
335  image_infos.resize(images_sp->GetAsArray()->GetSize());
336 
337  for (size_t i = 0; i < image_infos.size(); i++) {
338  StructuredData::ObjectSP image_sp =
339  images_sp->GetAsArray()->GetItemAtIndex(i);
340  if (image_sp.get() == nullptr || image_sp->GetAsDictionary() == nullptr)
341  return false;
342  StructuredData::Dictionary *image = image_sp->GetAsDictionary();
343  // clang-format off
344  if (!image->HasKey("load_address") ||
345  !image->HasKey("pathname") ||
346  !image->HasKey("mod_date") ||
347  !image->HasKey("mach_header") ||
348  image->GetValueForKey("mach_header")->GetAsDictionary() == nullptr ||
349  !image->HasKey("segments") ||
350  image->GetValueForKey("segments")->GetAsArray() == nullptr ||
351  !image->HasKey("uuid")) {
352  return false;
353  }
354  // clang-format on
355  image_infos[i].address =
356  image->GetValueForKey("load_address")->GetAsInteger()->GetValue();
357  image_infos[i].mod_date =
358  image->GetValueForKey("mod_date")->GetAsInteger()->GetValue();
359  image_infos[i].file_spec.SetFile(
360  image->GetValueForKey("pathname")->GetAsString()->GetValue(),
361  FileSpec::Style::native);
362 
364  image->GetValueForKey("mach_header")->GetAsDictionary();
365  image_infos[i].header.magic =
366  mh->GetValueForKey("magic")->GetAsInteger()->GetValue();
367  image_infos[i].header.cputype =
368  mh->GetValueForKey("cputype")->GetAsInteger()->GetValue();
369  image_infos[i].header.cpusubtype =
370  mh->GetValueForKey("cpusubtype")->GetAsInteger()->GetValue();
371  image_infos[i].header.filetype =
372  mh->GetValueForKey("filetype")->GetAsInteger()->GetValue();
373 
374  if (image->HasKey("min_version_os_name")) {
375  std::string os_name = image->GetValueForKey("min_version_os_name")
376  ->GetAsString()
377  ->GetValue();
378  if (os_name == "macosx")
379  image_infos[i].os_type = llvm::Triple::MacOSX;
380  else if (os_name == "ios" || os_name == "iphoneos")
381  image_infos[i].os_type = llvm::Triple::IOS;
382  else if (os_name == "tvos")
383  image_infos[i].os_type = llvm::Triple::TvOS;
384  else if (os_name == "watchos")
385  image_infos[i].os_type = llvm::Triple::WatchOS;
386  // NEED_BRIDGEOS_TRIPLE else if (os_name == "bridgeos")
387  // NEED_BRIDGEOS_TRIPLE image_infos[i].os_type = llvm::Triple::BridgeOS;
388  }
389  if (image->HasKey("min_version_os_sdk")) {
390  image_infos[i].min_version_os_sdk =
391  image->GetValueForKey("min_version_os_sdk")
392  ->GetAsString()
393  ->GetValue();
394  }
395 
396  // Fields that aren't used by DynamicLoaderDarwin so debugserver doesn't
397  // currently send them in the reply.
398 
399  if (mh->HasKey("flags"))
400  image_infos[i].header.flags =
401  mh->GetValueForKey("flags")->GetAsInteger()->GetValue();
402  else
403  image_infos[i].header.flags = 0;
404 
405  if (mh->HasKey("ncmds"))
406  image_infos[i].header.ncmds =
407  mh->GetValueForKey("ncmds")->GetAsInteger()->GetValue();
408  else
409  image_infos[i].header.ncmds = 0;
410 
411  if (mh->HasKey("sizeofcmds"))
412  image_infos[i].header.sizeofcmds =
413  mh->GetValueForKey("sizeofcmds")->GetAsInteger()->GetValue();
414  else
415  image_infos[i].header.sizeofcmds = 0;
416 
417  StructuredData::Array *segments =
418  image->GetValueForKey("segments")->GetAsArray();
419  uint32_t segcount = segments->GetSize();
420  for (size_t j = 0; j < segcount; j++) {
421  Segment segment;
423  segments->GetItemAtIndex(j)->GetAsDictionary();
424  segment.name =
425  ConstString(seg->GetValueForKey("name")->GetAsString()->GetValue());
426  segment.vmaddr =
427  seg->GetValueForKey("vmaddr")->GetAsInteger()->GetValue();
428  segment.vmsize =
429  seg->GetValueForKey("vmsize")->GetAsInteger()->GetValue();
430  segment.fileoff =
431  seg->GetValueForKey("fileoff")->GetAsInteger()->GetValue();
432  segment.filesize =
433  seg->GetValueForKey("filesize")->GetAsInteger()->GetValue();
434  segment.maxprot =
435  seg->GetValueForKey("maxprot")->GetAsInteger()->GetValue();
436 
437  // Fields that aren't used by DynamicLoaderDarwin so debugserver doesn't
438  // currently send them in the reply.
439 
440  if (seg->HasKey("initprot"))
441  segment.initprot =
442  seg->GetValueForKey("initprot")->GetAsInteger()->GetValue();
443  else
444  segment.initprot = 0;
445 
446  if (seg->HasKey("flags"))
447  segment.flags =
448  seg->GetValueForKey("flags")->GetAsInteger()->GetValue();
449  else
450  segment.flags = 0;
451 
452  if (seg->HasKey("nsects"))
453  segment.nsects =
454  seg->GetValueForKey("nsects")->GetAsInteger()->GetValue();
455  else
456  segment.nsects = 0;
457 
458  image_infos[i].segments.push_back(segment);
459  }
460 
461  image_infos[i].uuid.SetFromOptionalStringRef(
462  image->GetValueForKey("uuid")->GetAsString()->GetValue());
463 
464  // All sections listed in the dyld image info structure will all either be
465  // fixed up already, or they will all be off by a single slide amount that
466  // is determined by finding the first segment that is at file offset zero
467  // which also has bytes (a file size that is greater than zero) in the
468  // object file.
469 
470  // Determine the slide amount (if any)
471  const size_t num_sections = image_infos[i].segments.size();
472  for (size_t k = 0; k < num_sections; ++k) {
473  // Iterate through the object file sections to find the first section
474  // that starts of file offset zero and that has bytes in the file...
475  if ((image_infos[i].segments[k].fileoff == 0 &&
476  image_infos[i].segments[k].filesize > 0) ||
477  (image_infos[i].segments[k].name == "__TEXT")) {
478  image_infos[i].slide =
479  image_infos[i].address - image_infos[i].segments[k].vmaddr;
480  // We have found the slide amount, so we can exit this for loop.
481  break;
482  }
483  }
484  }
485 
486  return true;
487 }
488 
490  ImageInfo::collection &image_infos) {
491  uint32_t exe_idx = UINT32_MAX;
492  uint32_t dyld_idx = UINT32_MAX;
493  Target &target = m_process->GetTarget();
495  ConstString g_dyld_sim_filename("dyld_sim");
496 
497  ArchSpec target_arch = target.GetArchitecture();
498  const size_t image_infos_size = image_infos.size();
499  for (size_t i = 0; i < image_infos_size; i++) {
500  if (image_infos[i].header.filetype == llvm::MachO::MH_DYLINKER) {
501  // In a "simulator" process (an x86 process that is
502  // ios/tvos/watchos/bridgeos) we will have two dyld modules --
503  // a "dyld" that we want to keep track of, and a "dyld_sim" which
504  // we don't need to keep track of here. If the target is an x86
505  // system and the OS of the dyld binary is ios/tvos/watchos/bridgeos,
506  // then we are looking at dyld_sym.
507 
508  // debugserver has only recently (late 2016) started sending up the os
509  // type for each binary it sees -- so if we don't have an os type, use a
510  // filename check as our next best guess.
511  if (image_infos[i].os_type == llvm::Triple::OSType::UnknownOS) {
512  if (image_infos[i].file_spec.GetFilename() != g_dyld_sim_filename) {
513  dyld_idx = i;
514  }
515  } else if (target_arch.GetTriple().getArch() == llvm::Triple::x86 ||
516  target_arch.GetTriple().getArch() == llvm::Triple::x86_64) {
517  if (image_infos[i].os_type != llvm::Triple::OSType::IOS &&
518  image_infos[i].os_type != llvm::Triple::TvOS &&
519  image_infos[i].os_type != llvm::Triple::WatchOS) {
520  // NEED_BRIDGEOS_TRIPLE image_infos[i].os_type != llvm::Triple::BridgeOS) {
521  dyld_idx = i;
522  }
523  }
524  else {
525  // catch-all for any other environment -- trust that dyld is actually
526  // dyld
527  dyld_idx = i;
528  }
529  } else if (image_infos[i].header.filetype == llvm::MachO::MH_EXECUTE) {
530  exe_idx = i;
531  }
532  }
533 
534  if (exe_idx != UINT32_MAX) {
535  const bool can_create = true;
536  ModuleSP exe_module_sp(
537  FindTargetModuleForImageInfo(image_infos[exe_idx], can_create, NULL));
538  if (exe_module_sp) {
539  if (log)
540  log->Printf("Found executable module: %s",
541  exe_module_sp->GetFileSpec().GetPath().c_str());
542  target.GetImages().AppendIfNeeded(exe_module_sp);
543  UpdateImageLoadAddress(exe_module_sp.get(), image_infos[exe_idx]);
544  if (exe_module_sp.get() != target.GetExecutableModulePointer()) {
545  target.SetExecutableModule(exe_module_sp, eLoadDependentsNo);
546  }
547  }
548  }
549 
550  if (dyld_idx != UINT32_MAX) {
551  const bool can_create = true;
552  ModuleSP dyld_sp =
553  FindTargetModuleForImageInfo(image_infos[dyld_idx], can_create, NULL);
554  if (dyld_sp.get()) {
555  if (log)
556  log->Printf("Found dyld module: %s",
557  dyld_sp->GetFileSpec().GetPath().c_str());
558  target.GetImages().AppendIfNeeded(dyld_sp);
559  UpdateImageLoadAddress(dyld_sp.get(), image_infos[dyld_idx]);
560  SetDYLDModule(dyld_sp);
561  }
562  }
563 }
564 
566  ImageInfo &image_info) {
567  if (image_info.header.filetype == llvm::MachO::MH_DYLINKER) {
568  const bool can_create = true;
569  ModuleSP dyld_sp =
570  FindTargetModuleForImageInfo(image_info, can_create, NULL);
571  if (dyld_sp.get()) {
572  Target &target = m_process->GetTarget();
573  target.GetImages().AppendIfNeeded(dyld_sp);
574  UpdateImageLoadAddress(dyld_sp.get(), image_info);
575  SetDYLDModule(dyld_sp);
576  }
577  }
578 }
579 
580 void DynamicLoaderDarwin::SetDYLDModule(lldb::ModuleSP &dyld_module_sp) {
581  m_dyld_module_wp = dyld_module_sp;
582 }
583 
585  ModuleSP dyld_sp(m_dyld_module_wp.lock());
586  return dyld_sp;
587 }
588 
590  ImageInfo::collection &image_infos) {
591  std::lock_guard<std::recursive_mutex> guard(m_mutex);
592  // Now add these images to the main list.
593  ModuleList loaded_module_list;
595  Target &target = m_process->GetTarget();
596  ModuleList &target_images = target.GetImages();
597 
598  for (uint32_t idx = 0; idx < image_infos.size(); ++idx) {
599  if (log) {
600  log->Printf("Adding new image at address=0x%16.16" PRIx64 ".",
601  image_infos[idx].address);
602  image_infos[idx].PutToLog(log);
603  }
604 
605  m_dyld_image_infos.push_back(image_infos[idx]);
606 
607  ModuleSP image_module_sp(
608  FindTargetModuleForImageInfo(image_infos[idx], true, NULL));
609 
610  if (image_module_sp) {
611  ObjectFile *objfile = image_module_sp->GetObjectFile();
612  if (objfile) {
613  SectionList *sections = objfile->GetSectionList();
614  if (sections) {
615  ConstString commpage_dbstr("__commpage");
616  Section *commpage_section =
617  sections->FindSectionByName(commpage_dbstr).get();
618  if (commpage_section) {
619  ModuleSpec module_spec(objfile->GetFileSpec(),
620  image_infos[idx].GetArchitecture());
621  module_spec.GetObjectName() = commpage_dbstr;
622  ModuleSP commpage_image_module_sp(
623  target_images.FindFirstModule(module_spec));
624  if (!commpage_image_module_sp) {
625  module_spec.SetObjectOffset(objfile->GetFileOffset() +
626  commpage_section->GetFileOffset());
627  module_spec.SetObjectSize(objfile->GetByteSize());
628  commpage_image_module_sp = target.GetOrCreateModule(module_spec,
629  true /* notify */);
630  if (!commpage_image_module_sp ||
631  commpage_image_module_sp->GetObjectFile() == NULL) {
632  commpage_image_module_sp = m_process->ReadModuleFromMemory(
633  image_infos[idx].file_spec, image_infos[idx].address);
634  // Always load a memory image right away in the target in case
635  // we end up trying to read the symbol table from memory... The
636  // __LINKEDIT will need to be mapped so we can figure out where
637  // the symbol table bits are...
638  bool changed = false;
639  UpdateImageLoadAddress(commpage_image_module_sp.get(),
640  image_infos[idx]);
641  target.GetImages().Append(commpage_image_module_sp);
642  if (changed) {
643  image_infos[idx].load_stop_id = m_process->GetStopID();
644  loaded_module_list.AppendIfNeeded(commpage_image_module_sp);
645  }
646  }
647  }
648  }
649  }
650  }
651 
652  // UpdateImageLoadAddress will return true if any segments change load
653  // address. We need to check this so we don't mention that all loaded
654  // shared libraries are newly loaded each time we hit out dyld breakpoint
655  // since dyld will list all shared libraries each time.
656  if (UpdateImageLoadAddress(image_module_sp.get(), image_infos[idx])) {
657  target_images.AppendIfNeeded(image_module_sp);
658  loaded_module_list.AppendIfNeeded(image_module_sp);
659  }
660  }
661  }
662 
663  if (loaded_module_list.GetSize() > 0) {
664  if (log)
665  loaded_module_list.LogUUIDAndPaths(log,
666  "DynamicLoaderDarwin::ModulesDidLoad");
667  m_process->GetTarget().ModulesDidLoad(loaded_module_list);
668  }
669  return true;
670 }
671 
672 // On Mac OS X libobjc (the Objective-C runtime) has several critical dispatch
673 // functions written in hand-written assembly, and also have hand-written
674 // unwind information in the eh_frame section. Normally we prefer analyzing
675 // the assembly instructions of a currently executing frame to unwind from that
676 // frame -- but on hand-written functions this profiling can fail. We should
677 // use the eh_frame instructions for these functions all the time.
678 //
679 // As an aside, it would be better if the eh_frame entries had a flag (or were
680 // extensible so they could have an Apple-specific flag) which indicates that
681 // the instructions are asynchronous -- accurate at every instruction, instead
682 // of our normal default assumption that they are not.
683 
685  ModuleSP module_sp;
686  if (sym_ctx.symbol) {
687  module_sp = sym_ctx.symbol->GetAddressRef().GetModule();
688  }
689  if (module_sp.get() == NULL && sym_ctx.function) {
690  module_sp =
692  }
693  if (module_sp.get() == NULL)
694  return false;
695 
697  return objc_runtime != NULL && objc_runtime->IsModuleObjCLibrary(module_sp);
698 }
699 
700 // Dump a Segment to the file handle provided.
702  lldb::addr_t slide) const {
703  if (log) {
704  if (slide == 0)
705  log->Printf("\t\t%16s [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ")",
706  name.AsCString(""), vmaddr + slide, vmaddr + slide + vmsize);
707  else
708  log->Printf("\t\t%16s [0x%16.16" PRIx64 " - 0x%16.16" PRIx64
709  ") slide = 0x%" PRIx64,
710  name.AsCString(""), vmaddr + slide, vmaddr + slide + vmsize,
711  slide);
712  }
713 }
714 
717  const size_t num_segments = segments.size();
718  for (size_t i = 0; i < num_segments; ++i) {
719  if (segments[i].name == name)
720  return &segments[i];
721  }
722  return NULL;
723 }
724 
725 // Dump an image info structure to the file handle provided.
727  if (!log)
728  return;
729  if (address == LLDB_INVALID_ADDRESS) {
730  LLDB_LOG(log, "modtime={0:x+8} uuid={1} path='{2}' (UNLOADED)", mod_date,
731  uuid.GetAsString(), file_spec.GetPath());
732  } else {
733  LLDB_LOG(log, "address={0:x+16} modtime={1:x+8} uuid={2} path='{3}'",
734  address, mod_date, uuid.GetAsString(), file_spec.GetPath());
735  for (uint32_t i = 0; i < segments.size(); ++i)
736  segments[i].PutToLog(log, slide);
737  }
738 }
739 
741  DEBUG_PRINTF("DynamicLoaderDarwin::%s() process state = %s\n", __FUNCTION__,
743  Clear(true);
744  m_process = process;
746 }
747 
748 // Member function that gets called when the process state changes.
750  StateType state) {
751  DEBUG_PRINTF("DynamicLoaderDarwin::%s(%s)\n", __FUNCTION__,
752  StateAsCString(state));
753  switch (state) {
754  case eStateConnected:
755  case eStateAttaching:
756  case eStateLaunching:
757  case eStateInvalid:
758  case eStateUnloaded:
759  case eStateExited:
760  case eStateDetached:
761  Clear(false);
762  break;
763 
764  case eStateStopped:
765  // Keep trying find dyld and set our notification breakpoint each time we
766  // stop until we succeed
770 
772  }
773  break;
774 
775  case eStateRunning:
776  case eStateStepping:
777  case eStateCrashed:
778  case eStateSuspended:
779  break;
780  }
781 }
782 
783 ThreadPlanSP
785  bool stop_others) {
786  ThreadPlanSP thread_plan_sp;
787  StackFrame *current_frame = thread.GetStackFrameAtIndex(0).get();
788  const SymbolContext &current_context =
789  current_frame->GetSymbolContext(eSymbolContextSymbol);
790  Symbol *current_symbol = current_context.symbol;
792  TargetSP target_sp(thread.CalculateTarget());
793 
794  if (current_symbol != NULL) {
795  std::vector<Address> addresses;
796 
797  if (current_symbol->IsTrampoline()) {
798  ConstString trampoline_name = current_symbol->GetMangled().GetName(
799  current_symbol->GetLanguage(), Mangled::ePreferMangled);
800 
801  if (trampoline_name) {
802  const ModuleList &images = target_sp->GetImages();
803 
804  SymbolContextList code_symbols;
805  images.FindSymbolsWithNameAndType(trampoline_name, eSymbolTypeCode,
806  code_symbols);
807  size_t num_code_symbols = code_symbols.GetSize();
808 
809  if (num_code_symbols > 0) {
810  for (uint32_t i = 0; i < num_code_symbols; i++) {
811  SymbolContext context;
812  AddressRange addr_range;
813  if (code_symbols.GetContextAtIndex(i, context)) {
814  context.GetAddressRange(eSymbolContextEverything, 0, false,
815  addr_range);
816  addresses.push_back(addr_range.GetBaseAddress());
817  if (log) {
818  addr_t load_addr =
819  addr_range.GetBaseAddress().GetLoadAddress(target_sp.get());
820 
821  log->Printf("Found a trampoline target symbol at 0x%" PRIx64
822  ".",
823  load_addr);
824  }
825  }
826  }
827  }
828 
829  SymbolContextList reexported_symbols;
831  trampoline_name, eSymbolTypeReExported, reexported_symbols);
832  size_t num_reexported_symbols = reexported_symbols.GetSize();
833  if (num_reexported_symbols > 0) {
834  for (uint32_t i = 0; i < num_reexported_symbols; i++) {
835  SymbolContext context;
836  if (reexported_symbols.GetContextAtIndex(i, context)) {
837  if (context.symbol) {
838  Symbol *actual_symbol =
839  context.symbol->ResolveReExportedSymbol(*target_sp.get());
840  if (actual_symbol) {
841  const Address actual_symbol_addr =
842  actual_symbol->GetAddress();
843  if (actual_symbol_addr.IsValid()) {
844  addresses.push_back(actual_symbol_addr);
845  if (log) {
846  lldb::addr_t load_addr =
847  actual_symbol_addr.GetLoadAddress(target_sp.get());
848  log->Printf(
849  "Found a re-exported symbol: %s at 0x%" PRIx64 ".",
850  actual_symbol->GetName().GetCString(), load_addr);
851  }
852  }
853  }
854  }
855  }
856  }
857  }
858 
859  SymbolContextList indirect_symbols;
860  images.FindSymbolsWithNameAndType(trampoline_name, eSymbolTypeResolver,
861  indirect_symbols);
862  size_t num_indirect_symbols = indirect_symbols.GetSize();
863  if (num_indirect_symbols > 0) {
864  for (uint32_t i = 0; i < num_indirect_symbols; i++) {
865  SymbolContext context;
866  AddressRange addr_range;
867  if (indirect_symbols.GetContextAtIndex(i, context)) {
868  context.GetAddressRange(eSymbolContextEverything, 0, false,
869  addr_range);
870  addresses.push_back(addr_range.GetBaseAddress());
871  if (log) {
872  addr_t load_addr =
873  addr_range.GetBaseAddress().GetLoadAddress(target_sp.get());
874 
875  log->Printf("Found an indirect target symbol at 0x%" PRIx64 ".",
876  load_addr);
877  }
878  }
879  }
880  }
881  }
882  } else if (current_symbol->GetType() == eSymbolTypeReExported) {
883  // I am not sure we could ever end up stopped AT a re-exported symbol.
884  // But just in case:
885 
886  const Symbol *actual_symbol =
887  current_symbol->ResolveReExportedSymbol(*(target_sp.get()));
888  if (actual_symbol) {
889  Address target_addr(actual_symbol->GetAddress());
890  if (target_addr.IsValid()) {
891  if (log)
892  log->Printf(
893  "Found a re-exported symbol: %s pointing to: %s at 0x%" PRIx64
894  ".",
895  current_symbol->GetName().GetCString(),
896  actual_symbol->GetName().GetCString(),
897  target_addr.GetLoadAddress(target_sp.get()));
898  addresses.push_back(target_addr.GetLoadAddress(target_sp.get()));
899  }
900  }
901  }
902 
903  if (addresses.size() > 0) {
904  // First check whether any of the addresses point to Indirect symbols,
905  // and if they do, resolve them:
906  std::vector<lldb::addr_t> load_addrs;
907  for (Address address : addresses) {
908  Symbol *symbol = address.CalculateSymbolContextSymbol();
909  if (symbol && symbol->IsIndirect()) {
910  Status error;
911  Address symbol_address = symbol->GetAddress();
912  addr_t resolved_addr = thread.GetProcess()->ResolveIndirectFunction(
913  &symbol_address, error);
914  if (error.Success()) {
915  load_addrs.push_back(resolved_addr);
916  if (log)
917  log->Printf("ResolveIndirectFunction found resolved target for "
918  "%s at 0x%" PRIx64 ".",
919  symbol->GetName().GetCString(), resolved_addr);
920  }
921  } else {
922  load_addrs.push_back(address.GetLoadAddress(target_sp.get()));
923  }
924  }
925  thread_plan_sp = std::make_shared<ThreadPlanRunToAddress>(
926  thread, load_addrs, stop_others);
927  }
928  } else {
929  if (log)
930  log->Printf("Could not find symbol for step through.");
931  }
932 
933  return thread_plan_sp;
934 }
935 
937  lldb_private::Symbol *original_symbol, lldb_private::ModuleList &images,
938  lldb_private::SymbolContextList &equivalent_symbols) {
939  ConstString trampoline_name = original_symbol->GetMangled().GetName(
940  original_symbol->GetLanguage(), Mangled::ePreferMangled);
941  if (!trampoline_name)
942  return 0;
943 
944  size_t initial_size = equivalent_symbols.GetSize();
945 
946  static const char *resolver_name_regex = "(_gc|_non_gc|\\$[A-Za-z0-9\\$]+)$";
947  std::string equivalent_regex_buf("^");
948  equivalent_regex_buf.append(trampoline_name.GetCString());
949  equivalent_regex_buf.append(resolver_name_regex);
950 
951  RegularExpression equivalent_name_regex(equivalent_regex_buf);
952  const bool append = true;
953  images.FindSymbolsMatchingRegExAndType(equivalent_name_regex, eSymbolTypeCode,
954  equivalent_symbols, append);
955 
956  return equivalent_symbols.GetSize() - initial_size;
957 }
958 
960  ModuleSP module_sp = m_libpthread_module_wp.lock();
961  if (!module_sp) {
962  SymbolContextList sc_list;
963  ModuleSpec module_spec;
964  module_spec.GetFileSpec().GetFilename().SetCString(
965  "libsystem_pthread.dylib");
966  ModuleList module_list;
967  if (m_process->GetTarget().GetImages().FindModules(module_spec,
968  module_list)) {
969  if (module_list.GetSize() == 1) {
970  module_sp = module_list.GetModuleAtIndex(0);
971  if (module_sp)
972  m_libpthread_module_wp = module_sp;
973  }
974  }
975  }
976  return module_sp;
977 }
978 
981  ModuleSP module_sp = GetPThreadLibraryModule();
982  if (module_sp) {
984  module_sp->FindSymbolsWithNameAndType(ConstString("pthread_getspecific"),
985  eSymbolTypeCode, sc_list);
986  SymbolContext sc;
987  if (sc_list.GetContextAtIndex(0, sc)) {
988  if (sc.symbol)
990  }
991  }
992  }
994 }
995 
997 DynamicLoaderDarwin::GetThreadLocalData(const lldb::ModuleSP module_sp,
998  const lldb::ThreadSP thread_sp,
999  lldb::addr_t tls_file_addr) {
1000  if (!thread_sp || !module_sp)
1001  return LLDB_INVALID_ADDRESS;
1002 
1003  std::lock_guard<std::recursive_mutex> guard(m_mutex);
1004 
1005  const uint32_t addr_size = m_process->GetAddressByteSize();
1006  uint8_t buf[sizeof(lldb::addr_t) * 3];
1007 
1008  lldb_private::Address tls_addr;
1009  if (module_sp->ResolveFileAddress(tls_file_addr, tls_addr)) {
1010  Status error;
1011  const size_t tsl_data_size = addr_size * 3;
1012  Target &target = m_process->GetTarget();
1013  if (target.ReadMemory(tls_addr, false, buf, tsl_data_size, error) ==
1014  tsl_data_size) {
1015  const ByteOrder byte_order = m_process->GetByteOrder();
1016  DataExtractor data(buf, sizeof(buf), byte_order, addr_size);
1017  lldb::offset_t offset = addr_size; // Skip the first pointer
1018  const lldb::addr_t pthread_key = data.GetAddress(&offset);
1019  const lldb::addr_t tls_offset = data.GetAddress(&offset);
1020  if (pthread_key != 0) {
1021  // First check to see if we have already figured out the location of
1022  // TLS data for the pthread_key on a specific thread yet. If we have we
1023  // can re-use it since its location will not change unless the process
1024  // execs.
1025  const tid_t tid = thread_sp->GetID();
1026  auto tid_pos = m_tid_to_tls_map.find(tid);
1027  if (tid_pos != m_tid_to_tls_map.end()) {
1028  auto tls_pos = tid_pos->second.find(pthread_key);
1029  if (tls_pos != tid_pos->second.end()) {
1030  return tls_pos->second + tls_offset;
1031  }
1032  }
1033  StackFrameSP frame_sp = thread_sp->GetStackFrameAtIndex(0);
1034  if (frame_sp) {
1035  ClangASTContext *clang_ast_context =
1036  target.GetScratchClangASTContext();
1037 
1038  if (!clang_ast_context)
1039  return LLDB_INVALID_ADDRESS;
1040 
1041  CompilerType clang_void_ptr_type =
1042  clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType();
1043  Address pthread_getspecific_addr = GetPthreadSetSpecificAddress();
1044  if (pthread_getspecific_addr.IsValid()) {
1045  EvaluateExpressionOptions options;
1046 
1047  lldb::ThreadPlanSP thread_plan_sp(new ThreadPlanCallFunction(
1048  *thread_sp, pthread_getspecific_addr, clang_void_ptr_type,
1049  llvm::ArrayRef<lldb::addr_t>(pthread_key), options));
1050 
1051  DiagnosticManager execution_errors;
1052  ExecutionContext exe_ctx(thread_sp);
1054  exe_ctx, thread_plan_sp, options, execution_errors);
1055 
1056  if (results == lldb::eExpressionCompleted) {
1057  lldb::ValueObjectSP result_valobj_sp =
1058  thread_plan_sp->GetReturnValueObject();
1059  if (result_valobj_sp) {
1060  const lldb::addr_t pthread_key_data =
1061  result_valobj_sp->GetValueAsUnsigned(0);
1062  if (pthread_key_data) {
1063  m_tid_to_tls_map[tid].insert(
1064  std::make_pair(pthread_key, pthread_key_data));
1065  return pthread_key_data + tls_offset;
1066  }
1067  }
1068  }
1069  }
1070  }
1071  }
1072  }
1073  }
1074  return LLDB_INVALID_ADDRESS;
1075 }
1076 
1079  bool use_new_spi_interface = false;
1080 
1081  llvm::VersionTuple version = process->GetHostOSVersion();
1082  if (!version.empty()) {
1083  const llvm::Triple::OSType os_type =
1084  process->GetTarget().GetArchitecture().GetTriple().getOS();
1085 
1086  // macOS 10.12 and newer
1087  if (os_type == llvm::Triple::MacOSX &&
1088  version >= llvm::VersionTuple(10, 12))
1089  use_new_spi_interface = true;
1090 
1091  // iOS 10 and newer
1092  if (os_type == llvm::Triple::IOS && version >= llvm::VersionTuple(10))
1093  use_new_spi_interface = true;
1094 
1095  // tvOS 10 and newer
1096  if (os_type == llvm::Triple::TvOS && version >= llvm::VersionTuple(10))
1097  use_new_spi_interface = true;
1098 
1099  // watchOS 3 and newer
1100  if (os_type == llvm::Triple::WatchOS && version >= llvm::VersionTuple(3))
1101  use_new_spi_interface = true;
1102 
1103  // NEED_BRIDGEOS_TRIPLE // Any BridgeOS
1104  // NEED_BRIDGEOS_TRIPLE if (os_type == llvm::Triple::BridgeOS)
1105  // NEED_BRIDGEOS_TRIPLE use_new_spi_interface = true;
1106  }
1107 
1108  if (log) {
1109  if (use_new_spi_interface)
1110  log->Printf(
1111  "DynamicLoaderDarwin::UseDYLDSPI: Use new DynamicLoader plugin");
1112  else
1113  log->Printf(
1114  "DynamicLoaderDarwin::UseDYLDSPI: Use old DynamicLoader plugin");
1115  }
1116  return use_new_spi_interface;
1117 }
Address & GetAddressRef()
Definition: Symbol.h:56
ConstString & GetFilename()
Filename string get accessor.
Definition: FileSpec.cpp:369
An data extractor class.
Definition: DataExtractor.h:47
Defines a list of symbol context objects.
const char * StateAsCString(lldb::StateType state)
Converts a StateType to a C string.
Definition: State.cpp:14
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
lldb::LanguageType GetLanguage() const
Definition: Symbol.h:112
const ArchSpec & GetArchitecture() const
Definition: Target.h:941
bool IsValid() const
Definition: UUID.h:65
lldb::ExpressionResults RunThreadPlan(ExecutionContext &exe_ctx, lldb::ThreadPlanSP &thread_plan_sp, const EvaluateExpressionOptions &options, DiagnosticManager &diagnostic_manager)
Definition: Process.cpp:4648
lldb::offset_t GetFileOffset() const
Definition: Section.h:148
Process is currently trying to attach.
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:33
virtual FileSpec & GetFileSpec()
Get accessor to the object file specification.
Definition: ObjectFile.h:269
virtual bool NeedToDoInitialImageFetch()=0
bool IsTrampoline() const
Definition: Symbol.cpp:170
bool AddModulesUsingImageInfos(ImageInfo::collection &image_infos)
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition: Address.cpp:292
void PrivateInitialize(lldb_private::Process *process)
#define DEBUG_PRINTF(fmt,...)
virtual ObjectFile * GetObjectFile()
Get the object file representation for the current architecture.
Definition: Module.cpp:1251
void DidLaunch() override
Called after attaching a process.
void DidAttach() override
Called after attaching a process.
"lldb/Utility/RegularExpression.h" A C++ wrapper class for regex.
An architecture specification class.
Definition: ArchSpec.h:32
lldb::StateType GetState()
Get accessor for the current process state.
Definition: Process.cpp:1347
bool SetSectionLoadAddress(const lldb::SectionSP &section, lldb::addr_t load_addr, bool warn_multiple=false)
Definition: Target.cpp:2756
static void SystemLog(SystemLogType type, const char *format,...) __attribute__((format(printf
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.
A plug-in interface definition class for object file parsers.
Definition: ObjectFile.h:58
virtual bool IsModuleObjCLibrary(const lldb::ModuleSP &module_sp)=0
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
lldb::ByteOrder GetByteOrder() const
Definition: Process.cpp:3366
Address GetAddress() const
Definition: Symbol.h:72
Process or thread is stopped and can be examined.
lldb_private::Address m_pthread_getspecific_addr
virtual void UnloadSections(const lldb::ModuleSP module)
Removes the loaded sections from the target in module.
void UpdateSpecialBinariesFromNewImageInfos(ImageInfo::collection &image_infos)
bool SetLoadAddress(lldb::addr_t load_addr, Target *target, bool allow_section_end=false)
Set the address to represent load_addr.
Definition: Address.cpp:998
Module * GetExecutableModulePointer()
Definition: Target.cpp:1394
#define LLDB_LOG(log,...)
Definition: Log.h:209
virtual ObjCLanguageRuntime * GetObjCLanguageRuntime(bool retry_if_null=true)
Definition: Process.cpp:1573
static FileSystem & Instance()
Process or thread has crashed and can be examined.
Symbol * symbol
The Symbol for a given query.
void UnloadImages(const std::vector< lldb::addr_t > &solib_addresses)
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:431
uint32_t GetSize() const
Get accessor for a symbol context list size.
virtual llvm::VersionTuple GetHostOSVersion()
Sometimes the connection to a process can detect the host OS version that the process is running on...
Definition: Process.h:1187
const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame&#39;s current pc value.
Definition: StackFrame.cpp:267
Function * function
The Function for a given query.
lldb::SymbolType GetType() const
Definition: Symbol.h:136
Process has exited and can&#39;t be examined.
bool Remove(const lldb::ModuleSP &module_sp, bool notify=true)
Remove a module from the module list.
lldb::addr_t GetOffset() const
Get the section relative offset value.
Definition: Address.h:317
virtual bool DidSetNotificationBreakpoint()=0
lldb::ModuleSP GetModuleAtIndexUnlocked(size_t idx) const
Get the module shared pointer for the module at index idx without acquiring the ModuleList mutex...
Definition: ModuleList.cpp:331
bool UnloadModuleSections(lldb_private::Module *module, ImageInfo &info)
#define UINT32_MAX
Definition: lldb-defines.h:31
uint64_t GetAddress(lldb::offset_t *offset_ptr) const
Extract an address from *offset_ptr.
virtual lldb::addr_t GetFileOffset() const
Returns the offset into a file at which this object resides.
Definition: ObjectFile.h:260
static bool UseDYLDSPI(lldb_private::Process *process)
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()
lldb::ModuleSP GetModuleAtIndex(size_t idx) const
Get the module shared pointer for the module at index idx.
Definition: ModuleList.cpp:326
void Append(const lldb::ModuleSP &module_sp, bool notify=true)
Append a module to the module list.
uint32_t GetStopID() const
Definition: Process.h:1337
uint64_t offset_t
Definition: lldb-types.h:87
lldb::ModuleSP ReadModuleFromMemory(const FileSpec &file_spec, lldb::addr_t header_addr, size_t size_to_read=512)
Definition: Process.cpp:2435
Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: Logging.cpp:57
A collection class for Module objects.
Definition: ModuleList.h:91
bool IsIndirect() const
Definition: Symbol.cpp:172
Process * m_process
The process that this dynamic loader plug-in is tracking.
A class that describes an executable image and its associated object and symbol files.
Definition: Module.h:109
Process is connected to remote debug services, but not launched or attached to anything yet...
lldb::TargetSP CalculateTarget() override
Definition: Thread.cpp:1584
lldb::SectionSP FindSectionByName(ConstString section_dstr) const
Definition: Section.cpp:505
Process has been detached and can&#39;t be examined.
lldb::ModuleSP FindFirstModule(const ModuleSpec &module_spec) const
Definition: ModuleList.cpp:599
lldb::ModuleSP FindTargetModuleForImageInfo(ImageInfo &image_info, bool can_create, bool *did_create_ptr)
virtual SectionList * GetSectionList(bool update_module_section_list=true)
Gets the section list for the currently selected architecture (and object for archives).
Definition: ObjectFile.cpp:605
size_t FindSymbolsWithNameAndType(ConstString name, lldb::SymbolType symbol_type, SymbolContextList &sc_list, bool append=false) const
Definition: ModuleList.cpp:457
lldb::ModuleSP GetOrCreateModule(const ModuleSpec &module_spec, bool notify, Status *error_ptr=nullptr)
Find a binary on the system and return its Module, or return an existing Module that is already in th...
Definition: Target.cpp:1999
ObjectSP GetValueForKey(llvm::StringRef key) const
Process is in the process of launching.
uint64_t tid_t
Definition: lldb-types.h:86
uint32_t GetAddressByteSize() const
Definition: Process.cpp:3370
size_t FindSymbolsMatchingRegExAndType(const RegularExpression &regex, lldb::SymbolType symbol_type, SymbolContextList &sc_list, bool append=false) const
Definition: ModuleList.cpp:472
A plug-in interface definition class for debugging a process.
Definition: Process.h:353
Symbol * CalculateSymbolContextSymbol() override
Definition: Symbol.cpp:391
bool Success() const
Test for success condition.
Definition: Status.cpp:287
bool UpdateImageLoadAddress(lldb_private::Module *module, ImageInfo &info)
Process or thread is in the process of stepping and can not be examined.
bool IsValid() const
Check if the object state is valid.
Definition: Address.h:343
A section + offset based address class.
Definition: Address.h:80
bool HasKey(llvm::StringRef key) const
void ModulesDidLoad(ModuleList &module_list)
Definition: Target.cpp:1651
Process is object is valid, but not currently loaded.
CompilerType GetPointerType() const
FileSpec & GetFileSpec()
Definition: ModuleSpec.h:75
lldb::ProcessSP GetProcess() const
Definition: Thread.h:154
void AddInvalidMemoryRegion(const LoadRange &region)
Definition: Process.cpp:5538
A plug-in interface definition class for dynamic loaders.
Definition: DynamicLoader.h:64
ClangASTContext * GetScratchClangASTContext(bool create_on_demand=true)
Definition: Target.cpp:2299
bool GetContextAtIndex(size_t idx, SymbolContext &sc) const
Get accessor for a symbol context at index idx.
Process or thread is in a suspended state as far as the debugger is concerned while other processes o...
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition: Target.h:899
#define LIBLLDB_LOG_DYNAMIC_LOADER
Definition: Logging.h:17
void PrivateProcessStateChanged(lldb_private::Process *process, lldb::StateType state)
size_t ReadMemory(const Address &addr, bool prefer_file_cache, void *dst, size_t dst_len, Status &error, lldb::addr_t *load_addr_ptr=nullptr)
Definition: Target.cpp:1761
void SetDYLDModule(lldb::ModuleSP &dyld_module_sp)
Target & GetTarget()
Get the target object pointer for this module.
Definition: Process.h:1194
Symbol * ResolveReExportedSymbol(Target &target) const
Definition: Symbol.cpp:466
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
void ClearAllLoadedSections()
Definition: Target.cpp:2827
bool SetSectionUnloaded(const lldb::SectionSP &section_sp)
Definition: Target.cpp:2805
size_t GetSize() const
Gets the size of the module list.
Definition: ModuleList.cpp:611
void LogUUIDAndPaths(Log *log, const char *prefix_cstr)
Definition: ModuleList.cpp:632
A uniqued constant string class.
Definition: ConstString.h:38
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
Definition: Address.cpp:264
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:247
virtual bool IsAlive()
Check if a process is still alive.
Definition: Process.cpp:1182
void PutCString(const char *cstr)
Definition: Log.cpp:109
virtual lldb::addr_t GetByteSize() const
Definition: ObjectFile.h:262
Log * GetLogIfAnyCategoriesSet(uint32_t mask)
Definition: Logging.cpp:61
ObjectSP GetItemAtIndex(size_t idx) const
Definition: SBAddress.h:15
void UpdateDYLDImageInfoFromNewImageInfo(ImageInfo &image_info)
ConstString GetName() const
Definition: Symbol.cpp:494
std::shared_ptr< Object > ObjectSP
bool GetAddressRange(uint32_t scope, uint32_t range_idx, bool use_inline_block_range, AddressRange &range) const
Get the address range contained within a symbol context.
Address & GetBaseAddress()
Get accessor for the base address of the range.
Definition: AddressRange.h:220
size_t FindModules(const ModuleSpec &module_spec, ModuleList &matching_module_list) const
Finds the first module whose file specification matches file_spec.
Definition: ModuleList.cpp:486
const Segment * FindSegment(lldb_private::ConstString name) const
std::recursive_mutex & GetMutex() const
Definition: ModuleList.h:214
bool JSONImageInformationIntoImageInfo(lldb_private::StructuredData::ObjectSP image_details, ImageInfo::collection &image_infos)
virtual lldb::StackFrameSP GetStackFrameAtIndex(uint32_t idx)
Definition: Thread.h:395
void PutToLog(lldb_private::Log *log) const
const AddressRange & GetAddressRange()
Definition: Function.h:371
ImageInfo::collection m_dyld_image_infos
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition: FileSpec.cpp:376
bool AppendIfNeeded(const lldb::ModuleSP &module_sp, bool notify=true)
Append a module to the module list, if it is not already there.
#define LIBLLDB_LOG_STEP
Definition: Logging.h:21
void SetExecutableModule(lldb::ModuleSP &module_sp, LoadDependentFiles load_dependent_files=eLoadDependentsDefault)
Set the main executable module.
Definition: Target.cpp:1431
void Printf(const char *format,...) __attribute__((format(printf
Definition: Log.cpp:113
A section + offset based address range class.
Definition: AddressRange.h:32
CompilerType GetBasicType(lldb::BasicType type)
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...
This base class provides an interface to stack frames.
Definition: StackFrame.h:40
llvm::sys::TimePoint GetModificationTime(const FileSpec &file_spec) const
Returns the modification time of the given file.
virtual bool SetNotificationBreakpoint()=0
An error handling class.
Definition: Status.h:44
ConstString & GetObjectName()
Definition: ModuleSpec.h:125
Process or thread is running and can&#39;t be examined.
void SetCString(const char *cstr)
Set the C string value.
Mangled & GetMangled()
Definition: Symbol.h:120