LLDB  mainline
ProcessMachCore.cpp
Go to the documentation of this file.
1 //===-- ProcessMachCore.cpp ------------------------------------------*- C++
2 //-*-===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include <errno.h>
11 #include <stdlib.h>
12 
13 #include "llvm/Support/MathExtras.h"
14 #include "llvm/Support/Threading.h"
15 
16 #include "lldb/Core/Debugger.h"
17 #include "lldb/Core/Module.h"
18 #include "lldb/Core/ModuleSpec.h"
20 #include "lldb/Core/Section.h"
21 #include "lldb/Host/Host.h"
22 #include "lldb/Symbol/ObjectFile.h"
24 #include "lldb/Target/Target.h"
25 #include "lldb/Target/Thread.h"
27 #include "lldb/Utility/Log.h"
28 #include "lldb/Utility/State.h"
29 
30 #include "ProcessMachCore.h"
32 #include "ThreadMachCore.h"
33 
34 // Needed for the plug-in names for the dynamic loaders.
35 #include "lldb/Host/SafeMachO.h"
36 
40 
41 #include <memory>
42 #include <mutex>
43 
44 using namespace lldb;
45 using namespace lldb_private;
46 
48  static ConstString g_name("mach-o-core");
49  return g_name;
50 }
51 
53  return "Mach-O core file debugging plug-in.";
54 }
55 
57  PluginManager::UnregisterPlugin(ProcessMachCore::CreateInstance);
58 }
59 
60 lldb::ProcessSP ProcessMachCore::CreateInstance(lldb::TargetSP target_sp,
61  ListenerSP listener_sp,
62  const FileSpec *crash_file) {
63  lldb::ProcessSP process_sp;
64  if (crash_file) {
65  const size_t header_size = sizeof(llvm::MachO::mach_header);
66  auto data_sp = FileSystem::Instance().CreateDataBuffer(
67  crash_file->GetPath(), header_size, 0);
68  if (data_sp && data_sp->GetByteSize() == header_size) {
69  DataExtractor data(data_sp, lldb::eByteOrderLittle, 4);
70 
71  lldb::offset_t data_offset = 0;
72  llvm::MachO::mach_header mach_header;
73  if (ObjectFileMachO::ParseHeader(data, &data_offset, mach_header)) {
74  if (mach_header.filetype == llvm::MachO::MH_CORE)
75  process_sp = std::make_shared<ProcessMachCore>(target_sp, listener_sp,
76  *crash_file);
77  }
78  }
79  }
80  return process_sp;
81 }
82 
83 bool ProcessMachCore::CanDebug(lldb::TargetSP target_sp,
84  bool plugin_specified_by_name) {
85  if (plugin_specified_by_name)
86  return true;
87 
88  // For now we are just making sure the file exists for a given module
89  if (!m_core_module_sp && FileSystem::Instance().Exists(m_core_file)) {
90  // Don't add the Target's architecture to the ModuleSpec - we may be
91  // working with a core file that doesn't have the correct cpusubtype in the
92  // header but we should still try to use it -
93  // ModuleSpecList::FindMatchingModuleSpec enforces a strict arch mach.
94  ModuleSpec core_module_spec(m_core_file);
95  Status error(ModuleList::GetSharedModule(core_module_spec, m_core_module_sp,
96  NULL, NULL, NULL));
97 
98  if (m_core_module_sp) {
99  ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
100  if (core_objfile && core_objfile->GetType() == ObjectFile::eTypeCoreFile)
101  return true;
102  }
103  }
104  return false;
105 }
106 
107 // ProcessMachCore constructor
108 ProcessMachCore::ProcessMachCore(lldb::TargetSP target_sp,
109  ListenerSP listener_sp,
110  const FileSpec &core_file)
111  : Process(target_sp, listener_sp), m_core_aranges(), m_core_range_infos(),
112  m_core_module_sp(), m_core_file(core_file),
113  m_dyld_addr(LLDB_INVALID_ADDRESS),
114  m_mach_kernel_addr(LLDB_INVALID_ADDRESS), m_dyld_plugin_name() {}
115 
116 // Destructor
118  Clear();
119  // We need to call finalize on the process before destroying ourselves to
120  // make sure all of the broadcaster cleanup goes as planned. If we destruct
121  // this class, then Process::~Process() might have problems trying to fully
122  // destroy the broadcaster.
123  Finalize();
124 }
125 
126 // PluginInterface
128 
130 
131 bool ProcessMachCore::GetDynamicLoaderAddress(lldb::addr_t addr) {
134  llvm::MachO::mach_header header;
135  Status error;
136  if (DoReadMemory(addr, &header, sizeof(header), error) != sizeof(header))
137  return false;
138  if (header.magic == llvm::MachO::MH_CIGAM ||
139  header.magic == llvm::MachO::MH_CIGAM_64) {
140  header.magic = llvm::ByteSwap_32(header.magic);
141  header.cputype = llvm::ByteSwap_32(header.cputype);
142  header.cpusubtype = llvm::ByteSwap_32(header.cpusubtype);
143  header.filetype = llvm::ByteSwap_32(header.filetype);
144  header.ncmds = llvm::ByteSwap_32(header.ncmds);
145  header.sizeofcmds = llvm::ByteSwap_32(header.sizeofcmds);
146  header.flags = llvm::ByteSwap_32(header.flags);
147  }
148 
149  // TODO: swap header if needed...
150  // printf("0x%16.16" PRIx64 ": magic = 0x%8.8x, file_type= %u\n", vaddr,
151  // header.magic, header.filetype);
152  if (header.magic == llvm::MachO::MH_MAGIC ||
153  header.magic == llvm::MachO::MH_MAGIC_64) {
154  // Check MH_EXECUTABLE to see if we can find the mach image that contains
155  // the shared library list. The dynamic loader (dyld) is what contains the
156  // list for user applications, and the mach kernel contains a global that
157  // has the list of kexts to load
158  switch (header.filetype) {
159  case llvm::MachO::MH_DYLINKER:
160  // printf("0x%16.16" PRIx64 ": file_type = MH_DYLINKER\n", vaddr);
161  // Address of dyld "struct mach_header" in the core file
162  if (log)
163  log->Printf("ProcessMachCore::GetDynamicLoaderAddress found a user "
164  "process dyld binary image at 0x%" PRIx64,
165  addr);
166  m_dyld_addr = addr;
167  return true;
168 
169  case llvm::MachO::MH_EXECUTE:
170  // printf("0x%16.16" PRIx64 ": file_type = MH_EXECUTE\n", vaddr);
171  // Check MH_EXECUTABLE file types to see if the dynamic link object flag
172  // is NOT set. If it isn't, then we have a mach_kernel.
173  if ((header.flags & llvm::MachO::MH_DYLDLINK) == 0) {
174  if (log)
175  log->Printf("ProcessMachCore::GetDynamicLoaderAddress found a mach "
176  "kernel binary image at 0x%" PRIx64,
177  addr);
178  // Address of the mach kernel "struct mach_header" in the core file.
179  m_mach_kernel_addr = addr;
180  return true;
181  }
182  break;
183  }
184  }
185  return false;
186 }
187 
188 // Process Control
192  Status error;
193  if (!m_core_module_sp) {
194  error.SetErrorString("invalid core module");
195  return error;
196  }
197 
198  ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
199  if (core_objfile == NULL) {
200  error.SetErrorString("invalid core object file");
201  return error;
202  }
203 
204  if (core_objfile->GetNumThreadContexts() == 0) {
205  error.SetErrorString("core file doesn't contain any LC_THREAD load "
206  "commands, or the LC_THREAD architecture is not "
207  "supported in this lldb");
208  return error;
209  }
210 
211  SectionList *section_list = core_objfile->GetSectionList();
212  if (section_list == NULL) {
213  error.SetErrorString("core file has no sections");
214  return error;
215  }
216 
217  const uint32_t num_sections = section_list->GetNumSections(0);
218  if (num_sections == 0) {
219  error.SetErrorString("core file has no sections");
220  return error;
221  }
222 
223  SetCanJIT(false);
224 
225  llvm::MachO::mach_header header;
226  DataExtractor data(&header, sizeof(header),
227  m_core_module_sp->GetArchitecture().GetByteOrder(),
228  m_core_module_sp->GetArchitecture().GetAddressByteSize());
229 
230  bool ranges_are_sorted = true;
231  addr_t vm_addr = 0;
232  for (uint32_t i = 0; i < num_sections; ++i) {
233  Section *section = section_list->GetSectionAtIndex(i).get();
234  if (section) {
235  lldb::addr_t section_vm_addr = section->GetFileAddress();
236  FileRange file_range(section->GetFileOffset(), section->GetFileSize());
237  VMRangeToFileOffset::Entry range_entry(
238  section_vm_addr, section->GetByteSize(), file_range);
239 
240  if (vm_addr > section_vm_addr)
241  ranges_are_sorted = false;
242  vm_addr = section->GetFileAddress();
243  VMRangeToFileOffset::Entry *last_entry = m_core_aranges.Back();
244  // printf ("LC_SEGMENT[%u] arange=[0x%16.16" PRIx64 " -
245  // 0x%16.16" PRIx64 "), frange=[0x%8.8x - 0x%8.8x)\n",
246  // i,
247  // range_entry.GetRangeBase(),
248  // range_entry.GetRangeEnd(),
249  // range_entry.data.GetRangeBase(),
250  // range_entry.data.GetRangeEnd());
251 
252  if (last_entry &&
253  last_entry->GetRangeEnd() == range_entry.GetRangeBase() &&
254  last_entry->data.GetRangeEnd() == range_entry.data.GetRangeBase()) {
255  last_entry->SetRangeEnd(range_entry.GetRangeEnd());
256  last_entry->data.SetRangeEnd(range_entry.data.GetRangeEnd());
257  // puts("combine");
258  } else {
259  m_core_aranges.Append(range_entry);
260  }
261  // Some core files don't fill in the permissions correctly. If that is
262  // the case assume read + execute so clients don't think the memory is
263  // not readable, or executable. The memory isn't writable since this
264  // plug-in doesn't implement DoWriteMemory.
265  uint32_t permissions = section->GetPermissions();
266  if (permissions == 0)
267  permissions = lldb::ePermissionsReadable | lldb::ePermissionsExecutable;
268  m_core_range_infos.Append(VMRangeToPermissions::Entry(
269  section_vm_addr, section->GetByteSize(), permissions));
270  }
271  }
272  if (!ranges_are_sorted) {
273  m_core_aranges.Sort();
274  m_core_range_infos.Sort();
275  }
276 
277 
278  bool found_main_binary_definitively = false;
279 
280  addr_t objfile_binary_addr;
281  UUID objfile_binary_uuid;
282  if (core_objfile->GetCorefileMainBinaryInfo (objfile_binary_addr, objfile_binary_uuid))
283  {
284  if (objfile_binary_addr != LLDB_INVALID_ADDRESS)
285  {
286  m_mach_kernel_addr = objfile_binary_addr;
287  found_main_binary_definitively = true;
288  if (log)
289  log->Printf ("ProcessMachCore::DoLoadCore: using kernel address 0x%" PRIx64
290  " from LC_NOTE 'main bin spec' load command.", m_mach_kernel_addr);
291  }
292  }
293 
294  // This checks for the presence of an LC_IDENT string in a core file;
295  // LC_IDENT is very obsolete and should not be used in new code, but if the
296  // load command is present, let's use the contents.
297  std::string corefile_identifier = core_objfile->GetIdentifierString();
298  if (!found_main_binary_definitively &&
299  corefile_identifier.find("Darwin Kernel") != std::string::npos) {
300  UUID uuid;
302  if (corefile_identifier.find("UUID=") != std::string::npos) {
303  size_t p = corefile_identifier.find("UUID=") + strlen("UUID=");
304  std::string uuid_str = corefile_identifier.substr(p, 36);
305  uuid.SetFromStringRef(uuid_str);
306  }
307  if (corefile_identifier.find("stext=") != std::string::npos) {
308  size_t p = corefile_identifier.find("stext=") + strlen("stext=");
309  if (corefile_identifier[p] == '0' && corefile_identifier[p + 1] == 'x') {
310  errno = 0;
311  addr = ::strtoul(corefile_identifier.c_str() + p, NULL, 16);
312  if (errno != 0 || addr == 0)
313  addr = LLDB_INVALID_ADDRESS;
314  }
315  }
316  if (uuid.IsValid() && addr != LLDB_INVALID_ADDRESS) {
317  m_mach_kernel_addr = addr;
318  found_main_binary_definitively = true;
319  if (log)
320  log->Printf(
321  "ProcessMachCore::DoLoadCore: Using the kernel address 0x%" PRIx64
322  " from LC_IDENT/LC_NOTE 'kern ver str' string: '%s'",
323  addr, corefile_identifier.c_str());
324  }
325  }
326 
327  if (!found_main_binary_definitively &&
328  (m_dyld_addr == LLDB_INVALID_ADDRESS ||
329  m_mach_kernel_addr == LLDB_INVALID_ADDRESS)) {
330  // We need to locate the main executable in the memory ranges we have in
331  // the core file. We need to search for both a user-process dyld binary
332  // and a kernel binary in memory; we must look at all the pages in the
333  // binary so we don't miss one or the other. Step through all memory
334  // segments searching for a kernel binary and for a user process dyld --
335  // we'll decide which to prefer later if both are present.
336 
337  const size_t num_core_aranges = m_core_aranges.GetSize();
338  for (size_t i = 0; i < num_core_aranges; ++i) {
339  const VMRangeToFileOffset::Entry *entry =
340  m_core_aranges.GetEntryAtIndex(i);
341  lldb::addr_t section_vm_addr_start = entry->GetRangeBase();
342  lldb::addr_t section_vm_addr_end = entry->GetRangeEnd();
343  for (lldb::addr_t section_vm_addr = section_vm_addr_start;
344  section_vm_addr < section_vm_addr_end; section_vm_addr += 0x1000) {
345  GetDynamicLoaderAddress(section_vm_addr);
346  }
347  }
348  }
349 
350  if (!found_main_binary_definitively &&
351  m_mach_kernel_addr != LLDB_INVALID_ADDRESS) {
352  // In the case of multiple kernel images found in the core file via
353  // exhaustive search, we may not pick the correct one. See if the
354  // DynamicLoaderDarwinKernel's search heuristics might identify the correct
355  // one. Most of the time, I expect the address from SearchForDarwinKernel()
356  // will be the same as the address we found via exhaustive search.
357 
358  if (!GetTarget().GetArchitecture().IsValid() && m_core_module_sp.get()) {
359  GetTarget().SetArchitecture(m_core_module_sp->GetArchitecture());
360  }
361 
362  // SearchForDarwinKernel will end up calling back into this this class in
363  // the GetImageInfoAddress method which will give it the
364  // m_mach_kernel_addr/m_dyld_addr it already has. Save that aside and set
365  // m_mach_kernel_addr/m_dyld_addr to an invalid address temporarily so
366  // DynamicLoaderDarwinKernel does a real search for the kernel using its
367  // own heuristics.
368 
369  addr_t saved_mach_kernel_addr = m_mach_kernel_addr;
370  addr_t saved_user_dyld_addr = m_dyld_addr;
371  m_mach_kernel_addr = LLDB_INVALID_ADDRESS;
372  m_dyld_addr = LLDB_INVALID_ADDRESS;
373 
374  addr_t better_kernel_address =
376 
377  m_mach_kernel_addr = saved_mach_kernel_addr;
378  m_dyld_addr = saved_user_dyld_addr;
379 
380  if (better_kernel_address != LLDB_INVALID_ADDRESS) {
381  if (log)
382  log->Printf("ProcessMachCore::DoLoadCore: Using the kernel address "
383  "from DynamicLoaderDarwinKernel");
384  m_mach_kernel_addr = better_kernel_address;
385  }
386  }
387 
388  // If we found both a user-process dyld and a kernel binary, we need to
389  // decide which to prefer.
390  if (GetCorefilePreference() == eKernelCorefile) {
391  if (m_mach_kernel_addr != LLDB_INVALID_ADDRESS) {
392  if (log)
393  log->Printf("ProcessMachCore::DoLoadCore: Using kernel corefile image "
394  "at 0x%" PRIx64,
395  m_mach_kernel_addr);
396  m_dyld_plugin_name = DynamicLoaderDarwinKernel::GetPluginNameStatic();
397  } else if (m_dyld_addr != LLDB_INVALID_ADDRESS) {
398  if (log)
399  log->Printf("ProcessMachCore::DoLoadCore: Using user process dyld "
400  "image at 0x%" PRIx64,
401  m_dyld_addr);
402  m_dyld_plugin_name = DynamicLoaderMacOSXDYLD::GetPluginNameStatic();
403  }
404  } else {
405  if (m_dyld_addr != LLDB_INVALID_ADDRESS) {
406  if (log)
407  log->Printf("ProcessMachCore::DoLoadCore: Using user process dyld "
408  "image at 0x%" PRIx64,
409  m_dyld_addr);
410  m_dyld_plugin_name = DynamicLoaderMacOSXDYLD::GetPluginNameStatic();
411  } else if (m_mach_kernel_addr != LLDB_INVALID_ADDRESS) {
412  if (log)
413  log->Printf("ProcessMachCore::DoLoadCore: Using kernel corefile image "
414  "at 0x%" PRIx64,
415  m_mach_kernel_addr);
416  m_dyld_plugin_name = DynamicLoaderDarwinKernel::GetPluginNameStatic();
417  }
418  }
419 
420  if (m_dyld_plugin_name != DynamicLoaderMacOSXDYLD::GetPluginNameStatic()) {
421  // For non-user process core files, the permissions on the core file
422  // segments are usually meaningless, they may be just "read", because we're
423  // dealing with kernel coredumps or early startup coredumps and the dumper
424  // is grabbing pages of memory without knowing what they are. If they
425  // aren't marked as "exeuctable", that can break the unwinder which will
426  // check a pc value to see if it is in an executable segment and stop the
427  // backtrace early if it is not ("executable" and "unknown" would both be
428  // fine, but "not executable" will break the unwinder).
429  size_t core_range_infos_size = m_core_range_infos.GetSize();
430  for (size_t i = 0; i < core_range_infos_size; i++) {
432  m_core_range_infos.GetMutableEntryAtIndex(i);
433  ent->data = lldb::ePermissionsReadable | lldb::ePermissionsExecutable;
434  }
435  }
436 
437  // Even if the architecture is set in the target, we need to override it to
438  // match the core file which is always single arch.
439  ArchSpec arch(m_core_module_sp->GetArchitecture());
440  if (arch.GetCore() == ArchSpec::eCore_x86_32_i486) {
441  arch = Platform::GetAugmentedArchSpec(GetTarget().GetPlatform().get(), "i386");
442  }
443  if (arch.IsValid())
444  GetTarget().SetArchitecture(arch);
445 
446  return error;
447 }
448 
450  if (m_dyld_up.get() == NULL)
451  m_dyld_up.reset(DynamicLoader::FindPlugin(
452  this,
453  m_dyld_plugin_name.IsEmpty() ? NULL : m_dyld_plugin_name.GetCString()));
454  return m_dyld_up.get();
455 }
456 
458  ThreadList &new_thread_list) {
459  if (old_thread_list.GetSize(false) == 0) {
460  // Make up the thread the first time this is called so we can setup our one
461  // and only core thread state.
462  ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
463 
464  if (core_objfile) {
465  const uint32_t num_threads = core_objfile->GetNumThreadContexts();
466  for (lldb::tid_t tid = 0; tid < num_threads; ++tid) {
467  ThreadSP thread_sp(new ThreadMachCore(*this, tid));
468  new_thread_list.AddThread(thread_sp);
469  }
470  }
471  } else {
472  const uint32_t num_threads = old_thread_list.GetSize(false);
473  for (uint32_t i = 0; i < num_threads; ++i)
474  new_thread_list.AddThread(old_thread_list.GetThreadAtIndex(i, false));
475  }
476  return new_thread_list.GetSize(false) > 0;
477 }
478 
480  // Let all threads recover from stopping and do any clean up based on the
481  // previous thread state (if any).
483  // SetThreadStopInfo (m_last_stop_packet);
484 }
485 
487 
488 // Process Queries
489 
490 bool ProcessMachCore::IsAlive() { return true; }
491 
492 bool ProcessMachCore::WarnBeforeDetach() const { return false; }
493 
494 // Process Memory
495 size_t ProcessMachCore::ReadMemory(addr_t addr, void *buf, size_t size,
496  Status &error) {
497  // Don't allow the caching that lldb_private::Process::ReadMemory does since
498  // in core files we have it all cached our our core file anyway.
499  return DoReadMemory(addr, buf, size, error);
500 }
501 
502 size_t ProcessMachCore::DoReadMemory(addr_t addr, void *buf, size_t size,
503  Status &error) {
504  ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
505  size_t bytes_read = 0;
506 
507  if (core_objfile) {
508  // Segments are not always contiguous in mach-o core files. We have core
509  // files that have segments like:
510  // Address Size File off File size
511  // ---------- ---------- ---------- ----------
512  // LC_SEGMENT 0x000f6000 0x00001000 0x1d509ee8 0x00001000 --- --- 0
513  // 0x00000000 __TEXT LC_SEGMENT 0x0f600000 0x00100000 0x1d50aee8 0x00100000
514  // --- --- 0 0x00000000 __TEXT LC_SEGMENT 0x000f7000 0x00001000
515  // 0x1d60aee8 0x00001000 --- --- 0 0x00000000 __TEXT
516  //
517  // Any if the user executes the following command:
518  //
519  // (lldb) mem read 0xf6ff0
520  //
521  // We would attempt to read 32 bytes from 0xf6ff0 but would only get 16
522  // unless we loop through consecutive memory ranges that are contiguous in
523  // the address space, but not in the file data.
524  while (bytes_read < size) {
525  const addr_t curr_addr = addr + bytes_read;
526  const VMRangeToFileOffset::Entry *core_memory_entry =
527  m_core_aranges.FindEntryThatContains(curr_addr);
528 
529  if (core_memory_entry) {
530  const addr_t offset = curr_addr - core_memory_entry->GetRangeBase();
531  const addr_t bytes_left = core_memory_entry->GetRangeEnd() - curr_addr;
532  const size_t bytes_to_read =
533  std::min(size - bytes_read, (size_t)bytes_left);
534  const size_t curr_bytes_read = core_objfile->CopyData(
535  core_memory_entry->data.GetRangeBase() + offset, bytes_to_read,
536  (char *)buf + bytes_read);
537  if (curr_bytes_read == 0)
538  break;
539  bytes_read += curr_bytes_read;
540  } else {
541  // Only set the error if we didn't read any bytes
542  if (bytes_read == 0)
544  "core file does not contain 0x%" PRIx64, curr_addr);
545  break;
546  }
547  }
548  }
549 
550  return bytes_read;
551 }
552 
554  MemoryRegionInfo &region_info) {
555  region_info.Clear();
556  const VMRangeToPermissions::Entry *permission_entry =
557  m_core_range_infos.FindEntryThatContainsOrFollows(load_addr);
558  if (permission_entry) {
559  if (permission_entry->Contains(load_addr)) {
560  region_info.GetRange().SetRangeBase(permission_entry->GetRangeBase());
561  region_info.GetRange().SetRangeEnd(permission_entry->GetRangeEnd());
562  const Flags permissions(permission_entry->data);
563  region_info.SetReadable(permissions.Test(ePermissionsReadable)
564  ? MemoryRegionInfo::eYes
565  : MemoryRegionInfo::eNo);
566  region_info.SetWritable(permissions.Test(ePermissionsWritable)
567  ? MemoryRegionInfo::eYes
568  : MemoryRegionInfo::eNo);
569  region_info.SetExecutable(permissions.Test(ePermissionsExecutable)
570  ? MemoryRegionInfo::eYes
571  : MemoryRegionInfo::eNo);
572  region_info.SetMapped(MemoryRegionInfo::eYes);
573  } else if (load_addr < permission_entry->GetRangeBase()) {
574  region_info.GetRange().SetRangeBase(load_addr);
575  region_info.GetRange().SetRangeEnd(permission_entry->GetRangeBase());
576  region_info.SetReadable(MemoryRegionInfo::eNo);
577  region_info.SetWritable(MemoryRegionInfo::eNo);
578  region_info.SetExecutable(MemoryRegionInfo::eNo);
579  region_info.SetMapped(MemoryRegionInfo::eNo);
580  }
581  return Status();
582  }
583 
584  region_info.GetRange().SetRangeBase(load_addr);
586  region_info.SetReadable(MemoryRegionInfo::eNo);
587  region_info.SetWritable(MemoryRegionInfo::eNo);
588  region_info.SetExecutable(MemoryRegionInfo::eNo);
589  region_info.SetMapped(MemoryRegionInfo::eNo);
590  return Status();
591 }
592 
594 
596  static llvm::once_flag g_once_flag;
597 
598  llvm::call_once(g_once_flag, []() {
599  PluginManager::RegisterPlugin(GetPluginNameStatic(),
601  });
602 }
603 
605  // If we found both a user-process dyld and a kernel binary, we need to
606  // decide which to prefer.
607  if (GetCorefilePreference() == eKernelCorefile) {
608  if (m_mach_kernel_addr != LLDB_INVALID_ADDRESS) {
609  return m_mach_kernel_addr;
610  }
611  return m_dyld_addr;
612  } else {
613  if (m_dyld_addr != LLDB_INVALID_ADDRESS) {
614  return m_dyld_addr;
615  }
616  return m_mach_kernel_addr;
617  }
618 }
619 
621  return m_core_module_sp->GetObjectFile();
622 }
bool WarnBeforeDetach() const override
Before lldb detaches from a process, it warns the user that they are about to lose their debug sessio...
An data extractor class.
Definition: DataExtractor.h:47
const Entry * GetEntryAtIndex(size_t i) const
Definition: RangeMap.h:698
static const char * GetPluginDescriptionStatic()
#define LIBLLDB_LOG_PROCESS
Definition: Logging.h:15
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
void SetExecutable(OptionalBool val)
virtual uint32_t GetNumThreadContexts()
Definition: ObjectFile.h:482
bool Contains(BaseType r) const
Definition: RangeMap.h:77
bool IsValid() const
Definition: UUID.h:65
static lldb_private::ConstString GetPluginNameStatic()
lldb::offset_t GetFileOffset() const
Definition: Section.h:148
A file utility class.
Definition: FileSpec.h:55
static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener, const lldb_private::FileSpec *crash_file_path)
An architecture specification class.
Definition: ArchSpec.h:32
A plug-in interface definition class for object file parsers.
Definition: ObjectFile.h:58
void SetMapped(OptionalBool val)
bool SetArchitecture(const ArchSpec &arch_spec, bool set_platform=false)
Set the architecture for this target.
Definition: Target.cpp:1498
bool IsAlive() override
Check if a process is still alive.
bool IsValid() const
Return whether this object is valid (i.e.
Definition: Process.h:581
void SetRangeEnd(BaseType end)
Definition: RangeMap.h:64
virtual std::string GetIdentifierString()
Some object files may have an identifier string embedded in them, e.g.
Definition: ObjectFile.h:491
lldb::offset_t GetFileSize() const
Definition: Section.h:154
size_t CopyData(lldb::offset_t offset, size_t length, void *dst) const
Definition: ObjectFile.cpp:481
lldb_private::ObjectFile * GetCoreObjectFile()
size_t SetFromStringRef(llvm::StringRef str, uint32_t num_uuid_bytes=16)
Definition: UUID.cpp:92
size_t ReadMemory(lldb::addr_t addr, void *buf, size_t size, lldb_private::Status &error) override
Read of memory from a process.
const Entry * FindEntryThatContainsOrFollows(B addr) const
Definition: RangeMap.h:788
lldb::addr_t GetFileAddress() const
Definition: Section.cpp:194
void RefreshStateAfterStop() override
Currently called as part of ShouldStop.
lldb::ThreadSP GetThreadAtIndex(uint32_t idx, bool can_update=true)
Definition: ThreadList.cpp:90
#define LLDB_INVALID_ADDRESS
Invalid value definitions.
Definition: lldb-defines.h:85
bool Test(ValueType bit) const
Test a single flag bit.
Definition: Flags.h:107
uint64_t offset_t
Definition: lldb-types.h:87
Entry * FindEntryThatContains(B addr)
Definition: RangeMap.h:737
virtual void Finalize()
This object is about to be destroyed, do any necessary cleanup.
Definition: Process.cpp:615
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.
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
uint64_t tid_t
Definition: lldb-types.h:86
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
Definition: Status.cpp:241
lldb::addr_t GetByteSize() const
Definition: Section.h:164
A plug-in interface definition class for debugging a process.
Definition: Process.h:353
lldb::SectionSP GetSectionAtIndex(size_t idx) const
Definition: Section.cpp:497
static lldb_private::ConstString GetPluginNameStatic()
lldb_private::Status GetMemoryRegionInfo(lldb::addr_t load_addr, lldb_private::MemoryRegionInfo &region_info) override
Locate the memory region that contains load_addr.
uint32_t GetPermissions() const
Get the permissions as OR&#39;ed bits from lldb::Permissions.
Definition: Section.cpp:385
lldb_private::DynamicLoader * GetDynamicLoader() override
Get the dynamic loader plug-in for this process.
A plug-in interface definition class for dynamic loaders.
Definition: DynamicLoader.h:64
static void Terminate()
#define LIBLLDB_LOG_DYNAMIC_LOADER
Definition: Logging.h:17
A class to manage flags.
Definition: Flags.h:22
Target & GetTarget()
Get the target object pointer for this module.
Definition: Process.h:1194
~ProcessMachCore() override
uint64_t addr_t
Definition: lldb-types.h:83
void SetReadable(OptionalBool val)
size_t GetNumSections(uint32_t depth) const
Definition: Section.cpp:486
lldb_private::Status DoDestroy() override
A uniqued constant string class.
Definition: ConstString.h:38
friend class ThreadMachCore
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:247
bool ParseHeader() override
Attempts to parse the object header.
Log * GetLogIfAnyCategoriesSet(uint32_t mask)
Definition: Logging.cpp:61
Definition: SBAddress.h:15
Entry * GetMutableEntryAtIndex(size_t i)
Definition: RangeMap.h:702
ThreadList m_thread_list
The threads for this process as the user will see them.
Definition: Process.h:2657
lldb_private::Status DoLoadCore() override
void SetRangeBase(BaseType b)
Definition: RangeMap.h:48
void SetWritable(OptionalBool val)
bool CanDebug(lldb::TargetSP target_sp, bool plugin_specified_by_name) override
Check if a plug-in instance can debug the file in module.
static lldb::addr_t SearchForDarwinKernel(lldb_private::Process *process)
BaseType GetRangeEnd() const
Definition: RangeMap.h:62
void AddThread(const lldb::ThreadSP &thread_sp)
uint32_t GetSize(bool can_update=true)
Definition: ThreadList.cpp:82
int SetErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Set the current error string to a formatted error string.
Definition: Status.cpp:255
lldb_private::ConstString GetPluginName() override
bool UpdateThreadList(lldb_private::ThreadList &old_thread_list, lldb_private::ThreadList &new_thread_list) override
lldb::addr_t GetImageInfoAddress() override
Get the image information address for the current process.
ProcessMachCore(lldb::TargetSP target_sp, lldb::ListenerSP listener, const lldb_private::FileSpec &core_file)
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
virtual bool GetCorefileMainBinaryInfo(lldb::addr_t &address, UUID &uuid)
When the ObjectFile is a core file, lldb needs to locate the "binary" in the core file...
Definition: ObjectFile.h:513
void Printf(const char *format,...) __attribute__((format(printf
Definition: Log.cpp:113
void SetCanJIT(bool can_jit)
Sets whether executing JIT-compiled code in this process is possible.
Definition: Process.cpp:2406
bool IsEmpty() const
Test for empty string.
Definition: ConstString.h:340
uint32_t GetPluginVersion() override
static lldb_private::ConstString GetPluginNameStatic()
lldb::DynamicLoaderUP m_dyld_up
Definition: Process.h:2677
static void Initialize()
An error handling class.
Definition: Status.h:44
BaseType GetRangeBase() const
Definition: RangeMap.h:46
void Append(const Entry &entry)
Definition: RangeMap.h:635