LLDB  mainline
ProcessMachCore.cpp
Go to the documentation of this file.
1 //===-- ProcessMachCore.cpp -----------------------------------------------===//
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 <cerrno>
10 #include <cstdlib>
11 
12 #include "llvm/Support/MathExtras.h"
13 #include "llvm/Support/Threading.h"
14 
15 #include "lldb/Core/Debugger.h"
16 #include "lldb/Core/Module.h"
17 #include "lldb/Core/ModuleSpec.h"
19 #include "lldb/Core/Section.h"
20 #include "lldb/Host/Host.h"
22 #include "lldb/Symbol/ObjectFile.h"
25 #include "lldb/Target/Target.h"
26 #include "lldb/Target/Thread.h"
28 #include "lldb/Utility/LLDBLog.h"
29 #include "lldb/Utility/Log.h"
30 #include "lldb/Utility/State.h"
31 
32 #include "ProcessMachCore.h"
34 #include "ThreadMachCore.h"
35 
36 // Needed for the plug-in names for the dynamic loaders.
37 #include "lldb/Host/SafeMachO.h"
38 
44 
45 #include <memory>
46 #include <mutex>
47 
48 using namespace lldb;
49 using namespace lldb_private;
50 
52 
53 llvm::StringRef ProcessMachCore::GetPluginDescriptionStatic() {
54  return "Mach-O core file debugging plug-in.";
55 }
56 
58  PluginManager::UnregisterPlugin(ProcessMachCore::CreateInstance);
59 }
60 
61 lldb::ProcessSP ProcessMachCore::CreateInstance(lldb::TargetSP target_sp,
62  ListenerSP listener_sp,
63  const FileSpec *crash_file,
64  bool can_connect) {
65  lldb::ProcessSP process_sp;
66  if (crash_file && !can_connect) {
67  const size_t header_size = sizeof(llvm::MachO::mach_header);
68  auto data_sp = FileSystem::Instance().CreateDataBuffer(
69  crash_file->GetPath(), header_size, 0);
70  if (data_sp && data_sp->GetByteSize() == header_size) {
71  DataExtractor data(data_sp, lldb::eByteOrderLittle, 4);
72 
73  lldb::offset_t data_offset = 0;
74  llvm::MachO::mach_header mach_header;
75  if (ObjectFileMachO::ParseHeader(data, &data_offset, mach_header)) {
76  if (mach_header.filetype == llvm::MachO::MH_CORE)
77  process_sp = std::make_shared<ProcessMachCore>(target_sp, listener_sp,
78  *crash_file);
79  }
80  }
81  }
82  return process_sp;
83 }
84 
85 bool ProcessMachCore::CanDebug(lldb::TargetSP target_sp,
86  bool plugin_specified_by_name) {
87  if (plugin_specified_by_name)
88  return true;
89 
90  // For now we are just making sure the file exists for a given module
91  if (!m_core_module_sp && FileSystem::Instance().Exists(m_core_file)) {
92  // Don't add the Target's architecture to the ModuleSpec - we may be
93  // working with a core file that doesn't have the correct cpusubtype in the
94  // header but we should still try to use it -
95  // ModuleSpecList::FindMatchingModuleSpec enforces a strict arch mach.
96  ModuleSpec core_module_spec(m_core_file);
97  Status error(ModuleList::GetSharedModule(core_module_spec, m_core_module_sp,
98  nullptr, nullptr, nullptr));
99 
100  if (m_core_module_sp) {
101  ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
102  if (core_objfile && core_objfile->GetType() == ObjectFile::eTypeCoreFile)
103  return true;
104  }
105  }
106  return false;
107 }
108 
109 // ProcessMachCore constructor
110 ProcessMachCore::ProcessMachCore(lldb::TargetSP target_sp,
111  ListenerSP listener_sp,
112  const FileSpec &core_file)
113  : PostMortemProcess(target_sp, listener_sp), m_core_aranges(),
114  m_core_range_infos(), m_core_module_sp(), m_core_file(core_file),
115  m_dyld_addr(LLDB_INVALID_ADDRESS),
116  m_mach_kernel_addr(LLDB_INVALID_ADDRESS) {}
117 
118 // Destructor
120  Clear();
121  // We need to call finalize on the process before destroying ourselves to
122  // make sure all of the broadcaster cleanup goes as planned. If we destruct
123  // this class, then Process::~Process() might have problems trying to fully
124  // destroy the broadcaster.
125  Finalize();
126 }
127 
129  addr_t &dyld,
130  addr_t &kernel) {
131  Log *log(GetLog(LLDBLog::DynamicLoader | LLDBLog::Process));
132  llvm::MachO::mach_header header;
133  Status error;
134  dyld = kernel = LLDB_INVALID_ADDRESS;
135  if (DoReadMemory(addr, &header, sizeof(header), error) != sizeof(header))
136  return false;
137  if (header.magic == llvm::MachO::MH_CIGAM ||
138  header.magic == llvm::MachO::MH_CIGAM_64) {
139  header.magic = llvm::ByteSwap_32(header.magic);
140  header.cputype = llvm::ByteSwap_32(header.cputype);
141  header.cpusubtype = llvm::ByteSwap_32(header.cpusubtype);
142  header.filetype = llvm::ByteSwap_32(header.filetype);
143  header.ncmds = llvm::ByteSwap_32(header.ncmds);
144  header.sizeofcmds = llvm::ByteSwap_32(header.sizeofcmds);
145  header.flags = llvm::ByteSwap_32(header.flags);
146  }
147 
148  if (header.magic == llvm::MachO::MH_MAGIC ||
149  header.magic == llvm::MachO::MH_MAGIC_64) {
150  // Check MH_EXECUTABLE to see if we can find the mach image that contains
151  // the shared library list. The dynamic loader (dyld) is what contains the
152  // list for user applications, and the mach kernel contains a global that
153  // has the list of kexts to load
154  switch (header.filetype) {
155  case llvm::MachO::MH_DYLINKER:
156  LLDB_LOGF(log,
157  "ProcessMachCore::%s found a user "
158  "process dyld binary image at 0x%" PRIx64,
159  __FUNCTION__, addr);
160  dyld = addr;
161  return true;
162 
163  case llvm::MachO::MH_EXECUTE:
164  // Check MH_EXECUTABLE file types to see if the dynamic link object flag
165  // is NOT set. If it isn't, then we have a mach_kernel.
166  if ((header.flags & llvm::MachO::MH_DYLDLINK) == 0) {
167  LLDB_LOGF(log,
168  "ProcessMachCore::%s found a mach "
169  "kernel binary image at 0x%" PRIx64,
170  __FUNCTION__, addr);
171  // Address of the mach kernel "struct mach_header" in the core file.
172  kernel = addr;
173  return true;
174  }
175  break;
176  }
177  }
178  return false;
179 }
180 
182  ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
183  SectionList *section_list = core_objfile->GetSectionList();
184  const uint32_t num_sections = section_list->GetNumSections(0);
185 
186  bool ranges_are_sorted = true;
187  addr_t vm_addr = 0;
188  for (uint32_t i = 0; i < num_sections; ++i) {
189  Section *section = section_list->GetSectionAtIndex(i).get();
190  if (section && section->GetFileSize() > 0) {
191  lldb::addr_t section_vm_addr = section->GetFileAddress();
192  FileRange file_range(section->GetFileOffset(), section->GetFileSize());
193  VMRangeToFileOffset::Entry range_entry(
194  section_vm_addr, section->GetByteSize(), file_range);
195 
196  if (vm_addr > section_vm_addr)
197  ranges_are_sorted = false;
198  vm_addr = section->GetFileAddress();
200 
201  if (last_entry &&
202  last_entry->GetRangeEnd() == range_entry.GetRangeBase() &&
203  last_entry->data.GetRangeEnd() == range_entry.data.GetRangeBase()) {
204  last_entry->SetRangeEnd(range_entry.GetRangeEnd());
205  last_entry->data.SetRangeEnd(range_entry.data.GetRangeEnd());
206  } else {
207  m_core_aranges.Append(range_entry);
208  }
209  // Some core files don't fill in the permissions correctly. If that is
210  // the case assume read + execute so clients don't think the memory is
211  // not readable, or executable. The memory isn't writable since this
212  // plug-in doesn't implement DoWriteMemory.
213  uint32_t permissions = section->GetPermissions();
214  if (permissions == 0)
215  permissions = lldb::ePermissionsReadable | lldb::ePermissionsExecutable;
217  section_vm_addr, section->GetByteSize(), permissions));
218  }
219  }
220  if (!ranges_are_sorted) {
223  }
224 }
225 
227  Log *log(GetLog(LLDBLog::DynamicLoader | LLDBLog::Process));
228  ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
229  bool found_main_binary_definitively = false;
230 
231  addr_t objfile_binary_value;
232  bool objfile_binary_value_is_offset;
233  UUID objfile_binary_uuid;
235 
236  if (core_objfile->GetCorefileMainBinaryInfo(objfile_binary_value,
237  objfile_binary_value_is_offset,
238  objfile_binary_uuid, type)) {
239  if (log) {
240  log->Printf("ProcessMachCore::LoadBinariesViaMetadata: using binary hint "
241  "from 'main bin spec' "
242  "LC_NOTE with UUID %s value 0x%" PRIx64
243  " value is offset %d and type %d",
244  objfile_binary_uuid.GetAsString().c_str(),
245  objfile_binary_value, objfile_binary_value_is_offset, type);
246  }
247 
248  // If this is the xnu kernel, don't load it now. Note the correct
249  // DynamicLoader plugin to use, and the address of the kernel, and
250  // let the DynamicLoader handle the finding & loading of the binary.
251  if (type == ObjectFile::eBinaryTypeKernel) {
252  m_mach_kernel_addr = objfile_binary_value;
254  found_main_binary_definitively = true;
255  } else {
256  const bool force_symbol_search = true;
257  const bool notify = true;
258  if (DynamicLoader::LoadBinaryWithUUIDAndAddress(
259  this, llvm::StringRef(), objfile_binary_uuid,
260  objfile_binary_value, objfile_binary_value_is_offset,
261  force_symbol_search, notify)) {
262  found_main_binary_definitively = true;
264  }
265  if (type == ObjectFile::eBinaryTypeUser) {
266  m_dyld_addr = objfile_binary_value;
268  }
269  }
270  }
271 
272  // This checks for the presence of an LC_IDENT string in a core file;
273  // LC_IDENT is very obsolete and should not be used in new code, but if the
274  // load command is present, let's use the contents.
275  UUID ident_uuid;
276  addr_t ident_binary_addr = LLDB_INVALID_ADDRESS;
277  if (!found_main_binary_definitively) {
278  std::string corefile_identifier = core_objfile->GetIdentifierString();
279 
280  // Search for UUID= and stext= strings in the identifier str.
281  if (corefile_identifier.find("UUID=") != std::string::npos) {
282  size_t p = corefile_identifier.find("UUID=") + strlen("UUID=");
283  std::string uuid_str = corefile_identifier.substr(p, 36);
284  ident_uuid.SetFromStringRef(uuid_str);
285  if (log)
286  log->Printf("Got a UUID from LC_IDENT/kern ver str LC_NOTE: %s",
287  ident_uuid.GetAsString().c_str());
288  }
289  if (corefile_identifier.find("stext=") != std::string::npos) {
290  size_t p = corefile_identifier.find("stext=") + strlen("stext=");
291  if (corefile_identifier[p] == '0' && corefile_identifier[p + 1] == 'x') {
292  ident_binary_addr =
293  ::strtoul(corefile_identifier.c_str() + p, nullptr, 16);
294  if (log)
295  log->Printf("Got a load address from LC_IDENT/kern ver str "
296  "LC_NOTE: 0x%" PRIx64,
297  ident_binary_addr);
298  }
299  }
300 
301  // Search for a "Darwin Kernel" str indicating kernel; else treat as
302  // standalone
303  if (corefile_identifier.find("Darwin Kernel") != std::string::npos &&
304  ident_uuid.IsValid() && ident_binary_addr != LLDB_INVALID_ADDRESS) {
305  if (log)
306  log->Printf(
307  "ProcessMachCore::LoadBinariesViaMetadata: Found kernel binary via "
308  "LC_IDENT/kern ver str LC_NOTE");
309  m_mach_kernel_addr = ident_binary_addr;
310  found_main_binary_definitively = true;
311  } else if (ident_uuid.IsValid()) {
312  // We have no address specified, only a UUID. Load it at the file
313  // address.
314  const bool value_is_offset = false;
315  const bool force_symbol_search = true;
316  const bool notify = true;
317  if (DynamicLoader::LoadBinaryWithUUIDAndAddress(
318  this, llvm::StringRef(), ident_uuid, ident_binary_addr,
319  value_is_offset, force_symbol_search, notify)) {
320  found_main_binary_definitively = true;
322  }
323  }
324  }
325 
326  // Finally, load any binaries noted by "load binary" LC_NOTEs in the
327  // corefile
328  core_objfile->LoadCoreFileImages(*this);
329 
330  // LoadCoreFileImges may have set the dynamic loader; if we now have
331  // a dynamic loader, save its name so we don't un-set it later.
332  if (GetDynamicLoader())
334 }
335 
337  Log *log(GetLog(LLDBLog::DynamicLoader | LLDBLog::Process));
338 
339  // Search the pages of the corefile for dyld or mach kernel
340  // binaries. There may be multiple things that look like a kernel
341  // in the corefile; disambiguating to the correct one can be difficult.
342 
343  std::vector<addr_t> dylds_found;
344  std::vector<addr_t> kernels_found;
345 
346  const size_t num_core_aranges = m_core_aranges.GetSize();
347  for (size_t i = 0; i < num_core_aranges; ++i) {
349  lldb::addr_t section_vm_addr_start = entry->GetRangeBase();
350  lldb::addr_t section_vm_addr_end = entry->GetRangeEnd();
351  for (lldb::addr_t section_vm_addr = section_vm_addr_start;
352  section_vm_addr < section_vm_addr_end; section_vm_addr += 0x1000) {
353  addr_t dyld, kernel;
354  if (CheckAddressForDyldOrKernel(section_vm_addr, dyld, kernel)) {
355  if (dyld != LLDB_INVALID_ADDRESS)
356  dylds_found.push_back(dyld);
357  if (kernel != LLDB_INVALID_ADDRESS)
358  kernels_found.push_back(dyld);
359  }
360  }
361  }
362 
363  // If we found more than one dyld mach-o header in the corefile,
364  // pick the first one.
365  if (dylds_found.size() > 0)
366  m_dyld_addr = dylds_found[0];
367  if (kernels_found.size() > 0)
368  m_mach_kernel_addr = kernels_found[0];
369 
370  // Zero or one kernels found, we're done.
371  if (kernels_found.size() < 2)
372  return;
373 
374  // In the case of multiple kernel images found in the core file via
375  // exhaustive search, we may not pick the correct one. See if the
376  // DynamicLoaderDarwinKernel's search heuristics might identify the correct
377  // one.
378 
379  // SearchForDarwinKernel will call this class' GetImageInfoAddress method
380  // which will give it the addresses we already have.
381  // Save those aside and set
382  // m_mach_kernel_addr/m_dyld_addr to an invalid address temporarily so
383  // DynamicLoaderDarwinKernel does a real search for the kernel using its
384  // own heuristics.
385 
386  addr_t saved_mach_kernel_addr = m_mach_kernel_addr;
387  addr_t saved_user_dyld_addr = m_dyld_addr;
390 
391  addr_t better_kernel_address =
393 
394  m_mach_kernel_addr = saved_mach_kernel_addr;
395  m_dyld_addr = saved_user_dyld_addr;
396 
397  if (better_kernel_address != LLDB_INVALID_ADDRESS) {
398  LLDB_LOGF(log,
399  "ProcessMachCore::%s: Using "
400  "the kernel address "
401  "from DynamicLoaderDarwinKernel",
402  __FUNCTION__);
403  m_mach_kernel_addr = better_kernel_address;
404  }
405 }
406 
408  Log *log(GetLog(LLDBLog::DynamicLoader | LLDBLog::Process));
409 
411  if (m_dyld_plugin_name.empty())
413 
414  if (m_dyld_plugin_name.empty()) {
415  // If we found both a user-process dyld and a kernel binary, we need to
416  // decide which to prefer.
419  LLDB_LOGF(log,
420  "ProcessMachCore::%s: Using kernel "
421  "corefile image "
422  "at 0x%" PRIx64,
423  __FUNCTION__, m_mach_kernel_addr);
425  } else if (m_dyld_addr != LLDB_INVALID_ADDRESS) {
426  LLDB_LOGF(log,
427  "ProcessMachCore::%s: Using user process dyld "
428  "image at 0x%" PRIx64,
429  __FUNCTION__, m_dyld_addr);
431  }
432  } else {
434  LLDB_LOGF(log,
435  "ProcessMachCore::%s: Using user process dyld "
436  "image at 0x%" PRIx64,
437  __FUNCTION__, m_dyld_addr);
440  LLDB_LOGF(log,
441  "ProcessMachCore::%s: Using kernel "
442  "corefile image "
443  "at 0x%" PRIx64,
444  __FUNCTION__, m_mach_kernel_addr);
446  }
447  }
448  }
449 }
450 
453  // For non-user process core files, the permissions on the core file
454  // segments are usually meaningless, they may be just "read", because we're
455  // dealing with kernel coredumps or early startup coredumps and the dumper
456  // is grabbing pages of memory without knowing what they are. If they
457  // aren't marked as "executable", that can break the unwinder which will
458  // check a pc value to see if it is in an executable segment and stop the
459  // backtrace early if it is not ("executable" and "unknown" would both be
460  // fine, but "not executable" will break the unwinder).
461  size_t core_range_infos_size = m_core_range_infos.GetSize();
462  for (size_t i = 0; i < core_range_infos_size; i++) {
465  ent->data = lldb::ePermissionsReadable | lldb::ePermissionsExecutable;
466  }
467  }
468 }
469 
470 // Process Control
472  Status error;
473  if (!m_core_module_sp) {
474  error.SetErrorString("invalid core module");
475  return error;
476  }
477 
478  ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
479  if (core_objfile == nullptr) {
480  error.SetErrorString("invalid core object file");
481  return error;
482  }
483 
484  if (core_objfile->GetNumThreadContexts() == 0) {
485  error.SetErrorString("core file doesn't contain any LC_THREAD load "
486  "commands, or the LC_THREAD architecture is not "
487  "supported in this lldb");
488  return error;
489  }
490 
491  SetCanJIT(false);
492 
493  // The corefile's architecture is our best starting point.
494  ArchSpec arch(m_core_module_sp->GetArchitecture());
495  if (arch.IsValid())
496  GetTarget().SetArchitecture(arch);
497 
499 
501 
503 
504  addr_t address_mask = core_objfile->GetAddressMask();
505  if (address_mask != 0) {
506  SetCodeAddressMask(address_mask);
507  SetDataAddressMask(address_mask);
508  }
509  return error;
510 }
511 
513  if (m_dyld_up.get() == nullptr)
514  m_dyld_up.reset(DynamicLoader::FindPlugin(this, m_dyld_plugin_name));
515  return m_dyld_up.get();
516 }
517 
519  ThreadList &new_thread_list) {
520  if (old_thread_list.GetSize(false) == 0) {
521  // Make up the thread the first time this is called so we can setup our one
522  // and only core thread state.
523  ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
524 
525  if (core_objfile) {
526  const uint32_t num_threads = core_objfile->GetNumThreadContexts();
527  for (lldb::tid_t tid = 0; tid < num_threads; ++tid) {
528  ThreadSP thread_sp(new ThreadMachCore(*this, tid));
529  new_thread_list.AddThread(thread_sp);
530  }
531  }
532  } else {
533  const uint32_t num_threads = old_thread_list.GetSize(false);
534  for (uint32_t i = 0; i < num_threads; ++i)
535  new_thread_list.AddThread(old_thread_list.GetThreadAtIndex(i, false));
536  }
537  return new_thread_list.GetSize(false) > 0;
538 }
539 
541  // Let all threads recover from stopping and do any clean up based on the
542  // previous thread state (if any).
544  // SetThreadStopInfo (m_last_stop_packet);
545 }
546 
548 
549 // Process Queries
550 
551 bool ProcessMachCore::IsAlive() { return true; }
552 
553 bool ProcessMachCore::WarnBeforeDetach() const { return false; }
554 
555 // Process Memory
556 size_t ProcessMachCore::ReadMemory(addr_t addr, void *buf, size_t size,
557  Status &error) {
558  // Don't allow the caching that lldb_private::Process::ReadMemory does since
559  // in core files we have it all cached our our core file anyway.
560  return DoReadMemory(addr, buf, size, error);
561 }
562 
563 size_t ProcessMachCore::DoReadMemory(addr_t addr, void *buf, size_t size,
564  Status &error) {
565  ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
566  size_t bytes_read = 0;
567 
568  if (core_objfile) {
569  // Segments are not always contiguous in mach-o core files. We have core
570  // files that have segments like:
571  // Address Size File off File size
572  // ---------- ---------- ---------- ----------
573  // LC_SEGMENT 0x000f6000 0x00001000 0x1d509ee8 0x00001000 --- --- 0
574  // 0x00000000 __TEXT LC_SEGMENT 0x0f600000 0x00100000 0x1d50aee8 0x00100000
575  // --- --- 0 0x00000000 __TEXT LC_SEGMENT 0x000f7000 0x00001000
576  // 0x1d60aee8 0x00001000 --- --- 0 0x00000000 __TEXT
577  //
578  // Any if the user executes the following command:
579  //
580  // (lldb) mem read 0xf6ff0
581  //
582  // We would attempt to read 32 bytes from 0xf6ff0 but would only get 16
583  // unless we loop through consecutive memory ranges that are contiguous in
584  // the address space, but not in the file data.
585  while (bytes_read < size) {
586  const addr_t curr_addr = addr + bytes_read;
587  const VMRangeToFileOffset::Entry *core_memory_entry =
589 
590  if (core_memory_entry) {
591  const addr_t offset = curr_addr - core_memory_entry->GetRangeBase();
592  const addr_t bytes_left = core_memory_entry->GetRangeEnd() - curr_addr;
593  const size_t bytes_to_read =
594  std::min(size - bytes_read, (size_t)bytes_left);
595  const size_t curr_bytes_read = core_objfile->CopyData(
596  core_memory_entry->data.GetRangeBase() + offset, bytes_to_read,
597  (char *)buf + bytes_read);
598  if (curr_bytes_read == 0)
599  break;
600  bytes_read += curr_bytes_read;
601  } else {
602  // Only set the error if we didn't read any bytes
603  if (bytes_read == 0)
604  error.SetErrorStringWithFormat(
605  "core file does not contain 0x%" PRIx64, curr_addr);
606  break;
607  }
608  }
609  }
610 
611  return bytes_read;
612 }
613 
615  MemoryRegionInfo &region_info) {
616  region_info.Clear();
617  const VMRangeToPermissions::Entry *permission_entry =
619  if (permission_entry) {
620  if (permission_entry->Contains(load_addr)) {
621  region_info.GetRange().SetRangeBase(permission_entry->GetRangeBase());
622  region_info.GetRange().SetRangeEnd(permission_entry->GetRangeEnd());
623  const Flags permissions(permission_entry->data);
624  region_info.SetReadable(permissions.Test(ePermissionsReadable)
625  ? MemoryRegionInfo::eYes
626  : MemoryRegionInfo::eNo);
627  region_info.SetWritable(permissions.Test(ePermissionsWritable)
628  ? MemoryRegionInfo::eYes
629  : MemoryRegionInfo::eNo);
630  region_info.SetExecutable(permissions.Test(ePermissionsExecutable)
631  ? MemoryRegionInfo::eYes
632  : MemoryRegionInfo::eNo);
633  region_info.SetMapped(MemoryRegionInfo::eYes);
634  } else if (load_addr < permission_entry->GetRangeBase()) {
635  region_info.GetRange().SetRangeBase(load_addr);
636  region_info.GetRange().SetRangeEnd(permission_entry->GetRangeBase());
637  region_info.SetReadable(MemoryRegionInfo::eNo);
638  region_info.SetWritable(MemoryRegionInfo::eNo);
639  region_info.SetExecutable(MemoryRegionInfo::eNo);
640  region_info.SetMapped(MemoryRegionInfo::eNo);
641  }
642  return Status();
643  }
644 
645  region_info.GetRange().SetRangeBase(load_addr);
647  region_info.SetReadable(MemoryRegionInfo::eNo);
648  region_info.SetWritable(MemoryRegionInfo::eNo);
649  region_info.SetExecutable(MemoryRegionInfo::eNo);
650  region_info.SetMapped(MemoryRegionInfo::eNo);
651  return Status();
652 }
653 
655 
657  static llvm::once_flag g_once_flag;
658 
659  llvm::call_once(g_once_flag, []() {
660  PluginManager::RegisterPlugin(GetPluginNameStatic(),
662  });
663 }
664 
666  // If we found both a user-process dyld and a kernel binary, we need to
667  // decide which to prefer.
670  return m_mach_kernel_addr;
671  }
672  return m_dyld_addr;
673  } else {
675  return m_dyld_addr;
676  }
677  return m_mach_kernel_addr;
678  }
679 }
680 
682  return m_core_module_sp->GetObjectFile();
683 }
lldb_private::UUID
Definition: UUID.h:23
lldb_private::Range::GetRangeBase
BaseType GetRangeBase() const
Definition: RangeMap.h:46
llvm
Definition: Debugger.h:50
ProcessMachCore::CreateMemoryRegions
void CreateMemoryRegions()
Definition: ProcessMachCore.cpp:181
lldb_private::ArchSpec
Definition: ArchSpec.h:32
ProcessMachCore::ReadMemory
size_t ReadMemory(lldb::addr_t addr, void *buf, size_t size, lldb_private::Status &error) override
Read of memory from a process.
Definition: ProcessMachCore.cpp:556
lldb_private::Process::m_thread_list
ThreadList m_thread_list
The threads for this process as the user will see them.
Definition: Process.h:2871
ProcessMachCore::CanDebug
bool CanDebug(lldb::TargetSP target_sp, bool plugin_specified_by_name) override
Check if a plug-in instance can debug the file in module.
Definition: ProcessMachCore.cpp:85
ModuleSpec.h
ProcessMachCore::GetPluginNameStatic
static llvm::StringRef GetPluginNameStatic()
Definition: ProcessMachCore.h:38
ProcessMachCore::CleanupMemoryRegionPermissions
void CleanupMemoryRegionPermissions()
Definition: ProcessMachCore.cpp:451
Host.h
ProcessMachCore::m_core_module_sp
lldb::ModuleSP m_core_module_sp
Definition: ProcessMachCore.h:124
StopInfoMachException.h
ProcessMachCore::GetPluginDescriptionStatic
static llvm::StringRef GetPluginDescriptionStatic()
Definition: ProcessMachCore.cpp:53
lldb_private::UUID::IsValid
bool IsValid() const
Definition: UUID.h:69
lldb_private::Process::SetCodeAddressMask
void SetCodeAddressMask(lldb::addr_t code_address_mask)
Definition: Process.h:1362
ProcessMachCore::Initialize
static void Initialize()
Definition: ProcessMachCore.cpp:656
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:344
lldb_private::MemoryRegionInfo::Clear
void Clear()
Definition: MemoryRegionInfo.h:40
ProcessMachCore::m_mach_kernel_addr
lldb::addr_t m_mach_kernel_addr
Definition: ProcessMachCore.h:127
DynamicLoaderDarwinKernel::SearchForDarwinKernel
static lldb::addr_t SearchForDarwinKernel(lldb_private::Process *process)
Definition: DynamicLoaderDarwinKernel.cpp:195
Module.h
lldb_private::Process::GetTarget
Target & GetTarget()
Get the target object pointer for this module.
Definition: Process.h:1219
lldb_private::RangeDataVector::Sort
void Sort()
Definition: RangeMap.h:460
ProcessMachCore::ThreadMachCore
friend class ThreadMachCore
Definition: ProcessMachCore.h:74
lldb_private::Flags
Definition: Flags.h:22
lldb_private::ThreadList::RefreshStateAfterStop
void RefreshStateAfterStop()
Definition: ThreadList.cpp:486
SectionLoadList.h
LocateSymbolFile.h
lldb_private::SectionList
Definition: Section.h:34
lldb_private::Section::GetFileSize
lldb::offset_t GetFileSize() const
Definition: Section.h:152
DynamicLoaderStatic.h
lldb::offset_t
uint64_t offset_t
Definition: lldb-types.h:87
lldb_private::Flags::Test
bool Test(ValueType bit) const
Test a single flag bit.
Definition: Flags.h:96
lldb_private::MemoryRegionInfo
Definition: MemoryRegionInfo.h:21
lldb_private::RangeDataVector::GetEntryAtIndex
const Entry * GetEntryAtIndex(size_t i) const
Definition: RangeMap.h:528
ProcessMachCore::GetCoreObjectFile
lldb_private::ObjectFile * GetCoreObjectFile()
Definition: ProcessMachCore.cpp:681
ProcessMachCore::m_dyld_plugin_name
llvm::StringRef m_dyld_plugin_name
Definition: ProcessMachCore.h:128
lldb_private::RangeData
Definition: RangeMap.h:415
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::MemoryRegionInfo::SetReadable
void SetReadable(OptionalBool val)
Definition: MemoryRegionInfo.h:58
ProcessMachCore::DoDestroy
lldb_private::Status DoDestroy() override
Definition: ProcessMachCore.cpp:547
Debugger.h
lldb_private::SectionList::GetNumSections
size_t GetNumSections(uint32_t depth) const
Definition: Section.cpp:527
Section.h
lldb_private::PluginInterface::GetPluginName
virtual llvm::StringRef GetPluginName()=0
lldb_private::UUID::GetAsString
std::string GetAsString(llvm::StringRef separator="-") const
Definition: UUID.cpp:49
SafeMachO.h
ProcessMachCore.h
Target.h
lldb_private::Section::GetFileAddress
lldb::addr_t GetFileAddress() const
Definition: Section.cpp:189
lldb_private::RangeDataVector::FindEntryThatContains
Entry * FindEntryThatContains(B addr)
Definition: RangeMap.h:563
lldb_private::FileSpec
Definition: FileSpec.h:55
lldb_private::Log::Printf
void Printf(const char *format,...) __attribute__((format(printf
Prefer using LLDB_LOGF whenever possible.
Definition: Log.cpp:138
lldb_private::ThreadList::Clear
void Clear()
Definition: ThreadList.cpp:471
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::Range::SetRangeEnd
void SetRangeEnd(BaseType end)
Definition: RangeMap.h:80
ProcessMachCore
Definition: ProcessMachCore.h:21
lldb_private::ObjectFile::GetSectionList
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:588
ProcessMachCore::GetDynamicLoader
lldb_private::DynamicLoader * GetDynamicLoader() override
Get the dynamic loader plug-in for this process.
Definition: ProcessMachCore.cpp:512
lldb_private::RangeDataVector::Append
void Append(const Entry &entry)
Definition: RangeMap.h:451
ProcessMachCore::RefreshStateAfterStop
void RefreshStateAfterStop() override
Currently called as part of ShouldStop.
Definition: ProcessMachCore.cpp:540
ProcessMachCore::Clear
void Clear()
Definition: ProcessMachCore.cpp:654
ProcessMachCore::GetCorefilePreference
CorefilePreference GetCorefilePreference()
If a core file can be interpreted multiple ways, this establishes which style wins.
Definition: ProcessMachCore.h:108
lldb_private::DataExtractor
Definition: DataExtractor.h:48
Log.h
MemoryRegionInfo.h
lldb_private::Process::SetDataAddressMask
void SetDataAddressMask(lldb::addr_t data_address_mask)
Definition: Process.h:1366
lldb_private::MemoryRegionInfo::SetExecutable
void SetExecutable(OptionalBool val)
Definition: MemoryRegionInfo.h:62
ProcessMachCore::~ProcessMachCore
~ProcessMachCore() override
Definition: ProcessMachCore.cpp:119
ThreadMachCore.h
lldb_private::Process::m_dyld_up
lldb::DynamicLoaderUP m_dyld_up
Definition: Process.h:2895
ProcessMachCore::LoadBinariesViaMetadata
void LoadBinariesViaMetadata()
Definition: ProcessMachCore.cpp:226
lldb_private::Process::Finalize
virtual void Finalize()
This object is about to be destroyed, do any necessary cleanup.
Definition: Process.cpp:512
lldb_private::ObjectFile::GetIdentifierString
virtual std::string GetIdentifierString()
Some object files may have an identifier string embedded in them, e.g.
Definition: ObjectFile.h:510
ProcessMachCore::DoReadMemory
size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size, lldb_private::Status &error) override
Actually do the reading of memory from a process.
Definition: ProcessMachCore.cpp:563
lldb_private::ThreadList
Definition: ThreadList.h:26
DynamicLoaderDarwinKernel.h
lldb_private::PostMortemProcess
Definition: PostMortemProcess.h:23
ProcessMachCore::IsAlive
bool IsAlive() override
Check if a process is still alive.
Definition: ProcessMachCore.cpp:551
lldb_private::SectionList::GetSectionAtIndex
lldb::SectionSP GetSectionAtIndex(size_t idx) const
Definition: Section.cpp:538
lldb_private::Range< lldb::addr_t, lldb::addr_t >
lldb_private::DynamicLoader
Definition: DynamicLoader.h:52
ProcessMachCore::DoGetMemoryRegionInfo
lldb_private::Status DoGetMemoryRegionInfo(lldb::addr_t load_addr, lldb_private::MemoryRegionInfo &region_info) override
DoGetMemoryRegionInfo is called by GetMemoryRegionInfo after it has removed non address bits from loa...
Definition: ProcessMachCore.cpp:614
DynamicLoaderMacOSXDYLD.h
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::ThreadList::GetThreadAtIndex
lldb::ThreadSP GetThreadAtIndex(uint32_t idx, bool can_update=true)
Definition: ThreadList.cpp:91
lldb_private::ArchSpec::IsValid
bool IsValid() const
Tests if this ArchSpec is valid.
Definition: ArchSpec.h:352
lldb_private::ObjectFile::BinaryType
BinaryType
If we have a corefile binary hint, this enum specifies the binary type which we can use to select the...
Definition: ObjectFile.h:99
Thread.h
ObjectFile.h
lldb_private::Section
Definition: Section.h:102
lldb_private::MemoryRegionInfo::SetWritable
void SetWritable(OptionalBool val)
Definition: MemoryRegionInfo.h:60
ProcessMachCore::ProcessMachCore
ProcessMachCore(lldb::TargetSP target_sp, lldb::ListenerSP listener, const lldb_private::FileSpec &core_file)
Definition: ProcessMachCore.cpp:110
ProcessMachCore::CreateInstance
static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener, const lldb_private::FileSpec *crash_file_path, bool can_connect)
Definition: ProcessMachCore.cpp:61
lldb_private::ObjectFile::LoadCoreFileImages
virtual bool LoadCoreFileImages(lldb_private::Process &process)
Load binaries listed in a corefile.
Definition: ObjectFile.h:714
lldb_private::RangeDataVector::Back
Entry * Back()
Definition: RangeMap.h:646
lldb_private::Section::GetByteSize
lldb::addr_t GetByteSize() const
Definition: Section.h:162
lldb_private::ModuleSpec
Definition: ModuleSpec.h:27
lldb_private::Status
Definition: Status.h:44
uint32_t
ProcessMachCore::CheckAddressForDyldOrKernel
bool CheckAddressForDyldOrKernel(lldb::addr_t addr, lldb::addr_t &dyld, lldb::addr_t &kernel)
Definition: ProcessMachCore.cpp:128
lldb_private::RangeDataVector::GetSize
size_t GetSize() const
Definition: RangeMap.h:526
ProcessMachCore::LoadBinariesViaExhaustiveSearch
void LoadBinariesViaExhaustiveSearch()
Definition: ProcessMachCore.cpp:336
PlatformDarwinKernel.h
lldb_private::UUID::SetFromStringRef
bool SetFromStringRef(llvm::StringRef str)
Definition: UUID.cpp:97
lldb_private::MemoryRegionInfo::SetMapped
void SetMapped(OptionalBool val)
Definition: MemoryRegionInfo.h:66
lldb_private::ObjectFile::GetNumThreadContexts
virtual uint32_t GetNumThreadContexts()
Definition: ObjectFile.h:501
ProcessMachCore::eKernelCorefile
@ eKernelCorefile
Definition: ProcessMachCore.h:97
lldb_private::Range::SetRangeBase
void SetRangeBase(BaseType b)
Definition: RangeMap.h:48
lldb_private::ThreadList::GetSize
uint32_t GetSize(bool can_update=true)
Definition: ThreadList.cpp:83
ProcessMachCore::WarnBeforeDetach
bool WarnBeforeDetach() const override
Before lldb detaches from a process, it warns the user that they are about to lose their debug sessio...
Definition: ProcessMachCore.cpp:553
DynamicLoaderDarwinKernel::GetPluginNameStatic
static llvm::StringRef GetPluginNameStatic()
Definition: DynamicLoaderDarwinKernel.h:36
PluginManager.h
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:74
DynamicLoaderMacOSXDYLD::GetPluginNameStatic
static llvm::StringRef GetPluginNameStatic()
Definition: DynamicLoaderMacOSXDYLD.h:46
lldb_private::MemoryRegionInfo::GetRange
RangeType & GetRange()
Definition: MemoryRegionInfo.h:38
ObjectFileMachO.h
ObjectFileMachO::ParseHeader
bool ParseHeader() override
Attempts to parse the object header.
Definition: ObjectFileMachO.cpp:1038
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::RangeDataVector::GetMutableEntryAtIndex
Entry * GetMutableEntryAtIndex(size_t i)
Definition: RangeMap.h:532
lldb_private::Section::GetFileOffset
lldb::offset_t GetFileOffset() const
Definition: Section.h:146
ProcessMachCore::DoUpdateThreadList
bool DoUpdateThreadList(lldb_private::ThreadList &old_thread_list, lldb_private::ThreadList &new_thread_list) override
Update the thread list following process plug-in's specific logic.
Definition: ProcessMachCore.cpp:518
State.h
lldb_private::ThreadCollection::AddThread
void AddThread(const lldb::ThreadSP &thread_sp)
Definition: ThreadCollection.cpp:24
ProcessMachCore::LoadBinariesAndSetDYLD
void LoadBinariesAndSetDYLD()
Definition: ProcessMachCore.cpp:407
ProcessMachCore::GetImageInfoAddress
lldb::addr_t GetImageInfoAddress() override
Get the image information address for the current process.
Definition: ProcessMachCore.cpp:665
LLDB_PLUGIN_DEFINE
#define LLDB_PLUGIN_DEFINE(PluginName)
Definition: PluginManager.h:31
lldb_private::Log
Definition: Log.h:115
lldb_private::ObjectFile::CopyData
size_t CopyData(lldb::offset_t offset, size_t length, void *dst) const
Definition: ObjectFile.cpp:467
lldb_private::RangeDataVector::FindEntryThatContainsOrFollows
const Entry * FindEntryThatContainsOrFollows(B addr) const
Definition: RangeMap.h:614
lldb_private::Process::SetCanJIT
void SetCanJIT(bool can_jit)
Sets whether executing JIT-compiled code in this process is possible.
Definition: Process.cpp:2325
lldb_private::RangeData::data
DataType data
Definition: RangeMap.h:418
lldb_private::ObjectFile::GetCorefileMainBinaryInfo
virtual bool GetCorefileMainBinaryInfo(lldb::addr_t &value, bool &value_is_offset, UUID &uuid, ObjectFile::BinaryType &type)
When the ObjectFile is a core file, lldb needs to locate the "binary" in the core file.
Definition: ObjectFile.h:550
lldb_private::GetLog
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:309
lldb_private::FileSpec::GetPath
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition: FileSpec.cpp:364
DynamicLoaderStatic::GetPluginNameStatic
static llvm::StringRef GetPluginNameStatic()
Definition: DynamicLoaderStatic.h:26
DataBuffer.h
lldb::eByteOrderLittle
@ eByteOrderLittle
Definition: lldb-enumerations.h:142
lldb_private::Range::Contains
bool Contains(BaseType r) const
Definition: RangeMap.h:93
ProcessMachCore::Terminate
static void Terminate()
Definition: ProcessMachCore.cpp:57
lldb
Definition: SBAddress.h:15
LLDBLog.h
ProcessMachCore::m_core_range_infos
VMRangeToPermissions m_core_range_infos
Definition: ProcessMachCore.h:123
ProcessMachCore::DoLoadCore
lldb_private::Status DoLoadCore() override
Definition: ProcessMachCore.cpp:471
lldb_private::ObjectFile
Definition: ObjectFile.h:60
lldb_private::Target::SetArchitecture
bool SetArchitecture(const ArchSpec &arch_spec, bool set_platform=false, bool merge=true)
Set the architecture for this target.
Definition: Target.cpp:1484
lldb_private::Section::GetPermissions
uint32_t GetPermissions() const
Get the permissions as OR'ed bits from lldb::Permissions.
Definition: Section.cpp:354
lldb_private::ObjectFile::GetType
Type GetType()
Definition: ObjectFile.h:637
lldb_private::ObjectFile::GetAddressMask
virtual lldb::addr_t GetAddressMask()
Some object files may have the number of bits used for addressing embedded in them,...
Definition: ObjectFile.h:522
lldb::tid_t
uint64_t tid_t
Definition: lldb-types.h:86
ProcessMachCore::m_core_aranges
VMRangeToFileOffset m_core_aranges
Definition: ProcessMachCore.h:122
ProcessMachCore::m_dyld_addr
lldb::addr_t m_dyld_addr
Definition: ProcessMachCore.h:126
lldb_private::Range::GetRangeEnd
BaseType GetRangeEnd() const
Definition: RangeMap.h:78