LLDB  mainline
ProcessElfCore.cpp
Go to the documentation of this file.
1 //===-- ProcessElfCore.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 <cstdlib>
10 
11 #include <memory>
12 #include <mutex>
13 
14 #include "lldb/Core/Module.h"
15 #include "lldb/Core/ModuleSpec.h"
17 #include "lldb/Core/Section.h"
18 #include "lldb/Target/ABI.h"
21 #include "lldb/Target/Target.h"
24 #include "lldb/Utility/LLDBLog.h"
25 #include "lldb/Utility/Log.h"
26 #include "lldb/Utility/State.h"
27 
28 #include "llvm/BinaryFormat/ELF.h"
29 #include "llvm/Support/Threading.h"
30 
34 #include "ProcessElfCore.h"
35 #include "ThreadElfCore.h"
36 
37 using namespace lldb_private;
38 namespace ELF = llvm::ELF;
39 
41 
42 llvm::StringRef ProcessElfCore::GetPluginDescriptionStatic() {
43  return "ELF core dump plug-in.";
44 }
45 
48 }
49 
50 lldb::ProcessSP ProcessElfCore::CreateInstance(lldb::TargetSP target_sp,
51  lldb::ListenerSP listener_sp,
52  const FileSpec *crash_file,
53  bool can_connect) {
54  lldb::ProcessSP process_sp;
55  if (crash_file && !can_connect) {
56  // Read enough data for a ELF32 header or ELF64 header Note: Here we care
57  // about e_type field only, so it is safe to ignore possible presence of
58  // the header extension.
59  const size_t header_size = sizeof(llvm::ELF::Elf64_Ehdr);
60 
61  auto data_sp = FileSystem::Instance().CreateDataBuffer(
62  crash_file->GetPath(), header_size, 0);
63  if (data_sp && data_sp->GetByteSize() == header_size &&
64  elf::ELFHeader::MagicBytesMatch(data_sp->GetBytes())) {
65  elf::ELFHeader elf_header;
66  DataExtractor data(data_sp, lldb::eByteOrderLittle, 4);
67  lldb::offset_t data_offset = 0;
68  if (elf_header.Parse(data, &data_offset)) {
69  // Check whether we're dealing with a raw FreeBSD "full memory dump"
70  // ELF vmcore that needs to be handled via FreeBSDKernel plugin instead.
71  if (elf_header.e_ident[7] == 0xFF && elf_header.e_version == 0)
72  return process_sp;
73  if (elf_header.e_type == llvm::ELF::ET_CORE)
74  process_sp = std::make_shared<ProcessElfCore>(target_sp, listener_sp,
75  *crash_file);
76  }
77  }
78  }
79  return process_sp;
80 }
81 
82 bool ProcessElfCore::CanDebug(lldb::TargetSP target_sp,
83  bool plugin_specified_by_name) {
84  // For now we are just making sure the file exists for a given module
85  if (!m_core_module_sp && FileSystem::Instance().Exists(m_core_file)) {
86  ModuleSpec core_module_spec(m_core_file, target_sp->GetArchitecture());
87  Status error(ModuleList::GetSharedModule(core_module_spec, m_core_module_sp,
88  nullptr, nullptr, nullptr));
89  if (m_core_module_sp) {
90  ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
91  if (core_objfile && core_objfile->GetType() == ObjectFile::eTypeCoreFile)
92  return true;
93  }
94  }
95  return false;
96 }
97 
98 // ProcessElfCore constructor
99 ProcessElfCore::ProcessElfCore(lldb::TargetSP target_sp,
100  lldb::ListenerSP listener_sp,
101  const FileSpec &core_file)
102  : PostMortemProcess(target_sp, listener_sp), m_core_file(core_file) {}
103 
104 // Destructor
106  Clear();
107  // We need to call finalize on the process before destroying ourselves to
108  // make sure all of the broadcaster cleanup goes as planned. If we destruct
109  // this class, then Process::~Process() might have problems trying to fully
110  // destroy the broadcaster.
111  Finalize();
112 }
113 
115  const elf::ELFProgramHeader &header) {
116  const lldb::addr_t addr = header.p_vaddr;
117  FileRange file_range(header.p_offset, header.p_filesz);
118  VMRangeToFileOffset::Entry range_entry(addr, header.p_memsz, file_range);
119 
120  // Only add to m_core_aranges if the file size is non zero. Some core files
121  // have PT_LOAD segments for all address ranges, but set f_filesz to zero for
122  // the .text sections since they can be retrieved from the object files.
123  if (header.p_filesz > 0) {
125  if (last_entry && last_entry->GetRangeEnd() == range_entry.GetRangeBase() &&
126  last_entry->data.GetRangeEnd() == range_entry.data.GetRangeBase() &&
127  last_entry->GetByteSize() == last_entry->data.GetByteSize()) {
128  last_entry->SetRangeEnd(range_entry.GetRangeEnd());
129  last_entry->data.SetRangeEnd(range_entry.data.GetRangeEnd());
130  } else {
131  m_core_aranges.Append(range_entry);
132  }
133  }
134  // Keep a separate map of permissions that that isn't coalesced so all ranges
135  // are maintained.
136  const uint32_t permissions =
137  ((header.p_flags & llvm::ELF::PF_R) ? lldb::ePermissionsReadable : 0u) |
138  ((header.p_flags & llvm::ELF::PF_W) ? lldb::ePermissionsWritable : 0u) |
139  ((header.p_flags & llvm::ELF::PF_X) ? lldb::ePermissionsExecutable : 0u);
140 
142  VMRangeToPermissions::Entry(addr, header.p_memsz, permissions));
143 
144  return addr;
145 }
146 
148  const elf::ELFProgramHeader &header) {
149  // If lldb understood multiple kinds of tag segments we would record the type
150  // of the segment here also. As long as there is only 1 type lldb looks for,
151  // there is no need.
152  FileRange file_range(header.p_offset, header.p_filesz);
154  VMRangeToFileOffset::Entry(header.p_vaddr, header.p_memsz, file_range));
155 
156  return header.p_vaddr;
157 }
158 
159 // Process Control
161  Status error;
162  if (!m_core_module_sp) {
163  error.SetErrorString("invalid core module");
164  return error;
165  }
166 
167  ObjectFileELF *core = (ObjectFileELF *)(m_core_module_sp->GetObjectFile());
168  if (core == nullptr) {
169  error.SetErrorString("invalid core object file");
170  return error;
171  }
172 
173  llvm::ArrayRef<elf::ELFProgramHeader> segments = core->ProgramHeaders();
174  if (segments.size() == 0) {
175  error.SetErrorString("core file has no segments");
176  return error;
177  }
178 
179  SetCanJIT(false);
180 
181  m_thread_data_valid = true;
182 
183  bool ranges_are_sorted = true;
184  lldb::addr_t vm_addr = 0;
185  lldb::addr_t tag_addr = 0;
186  /// Walk through segments and Thread and Address Map information.
187  /// PT_NOTE - Contains Thread and Register information
188  /// PT_LOAD - Contains a contiguous range of Process Address Space
189  /// PT_AARCH64_MEMTAG_MTE - Contains AArch64 MTE memory tags for a range of
190  /// Process Address Space.
191  for (const elf::ELFProgramHeader &H : segments) {
192  DataExtractor data = core->GetSegmentData(H);
193 
194  // Parse thread contexts and auxv structure
195  if (H.p_type == llvm::ELF::PT_NOTE) {
197  return Status(std::move(error));
198  }
199  // PT_LOAD segments contains address map
200  if (H.p_type == llvm::ELF::PT_LOAD) {
202  if (vm_addr > last_addr)
203  ranges_are_sorted = false;
204  vm_addr = last_addr;
205  } else if (H.p_type == llvm::ELF::PT_AARCH64_MEMTAG_MTE) {
207  if (tag_addr > last_addr)
208  ranges_are_sorted = false;
209  tag_addr = last_addr;
210  }
211  }
212 
213  if (!ranges_are_sorted) {
217  }
218 
219  // Even if the architecture is set in the target, we need to override it to
220  // match the core file which is always single arch.
221  ArchSpec arch(m_core_module_sp->GetArchitecture());
222 
223  ArchSpec target_arch = GetTarget().GetArchitecture();
224  ArchSpec core_arch(m_core_module_sp->GetArchitecture());
225  target_arch.MergeFrom(core_arch);
226  GetTarget().SetArchitecture(target_arch);
227 
228  SetUnixSignals(UnixSignals::Create(GetArchitecture()));
229 
230  // Ensure we found at least one thread that was stopped on a signal.
231  bool siginfo_signal_found = false;
232  bool prstatus_signal_found = false;
233  // Check we found a signal in a SIGINFO note.
234  for (const auto &thread_data : m_thread_data) {
235  if (thread_data.signo != 0)
236  siginfo_signal_found = true;
237  if (thread_data.prstatus_sig != 0)
238  prstatus_signal_found = true;
239  }
240  if (!siginfo_signal_found) {
241  // If we don't have signal from SIGINFO use the signal from each threads
242  // PRSTATUS note.
243  if (prstatus_signal_found) {
244  for (auto &thread_data : m_thread_data)
245  thread_data.signo = thread_data.prstatus_sig;
246  } else if (m_thread_data.size() > 0) {
247  // If all else fails force the first thread to be SIGSTOP
248  m_thread_data.begin()->signo =
249  GetUnixSignals()->GetSignalNumberFromName("SIGSTOP");
250  }
251  }
252 
253  // Core files are useless without the main executable. See if we can locate
254  // the main executable using data we found in the core file notes.
255  lldb::ModuleSP exe_module_sp = GetTarget().GetExecutableModule();
256  if (!exe_module_sp) {
257  // The first entry in the NT_FILE might be our executable
258  if (!m_nt_file_entries.empty()) {
259  ModuleSpec exe_module_spec;
260  exe_module_spec.GetArchitecture() = arch;
261  exe_module_spec.GetFileSpec().SetFile(
262  m_nt_file_entries[0].path.GetCString(), FileSpec::Style::native);
263  if (exe_module_spec.GetFileSpec()) {
264  exe_module_sp = GetTarget().GetOrCreateModule(exe_module_spec,
265  true /* notify */);
266  if (exe_module_sp)
268  }
269  }
270  }
271  return error;
272 }
273 
275  if (m_dyld_up.get() == nullptr)
276  m_dyld_up.reset(DynamicLoader::FindPlugin(
278  return m_dyld_up.get();
279 }
280 
282  ThreadList &new_thread_list) {
283  const uint32_t num_threads = GetNumThreadContexts();
284  if (!m_thread_data_valid)
285  return false;
286 
287  for (lldb::tid_t tid = 0; tid < num_threads; ++tid) {
288  const ThreadData &td = m_thread_data[tid];
289  lldb::ThreadSP thread_sp(new ThreadElfCore(*this, td));
290  new_thread_list.AddThread(thread_sp);
291  }
292  return new_thread_list.GetSize(false) > 0;
293 }
294 
296 
298 
299 // Process Queries
300 
301 bool ProcessElfCore::IsAlive() { return true; }
302 
303 // Process Memory
304 size_t ProcessElfCore::ReadMemory(lldb::addr_t addr, void *buf, size_t size,
305  Status &error) {
306  if (lldb::ABISP abi_sp = GetABI())
307  addr = abi_sp->FixAnyAddress(addr);
308 
309  // Don't allow the caching that lldb_private::Process::ReadMemory does since
310  // in core files we have it all cached our our core file anyway.
311  return DoReadMemory(addr, buf, size, error);
312 }
313 
315  MemoryRegionInfo &region_info) {
316  region_info.Clear();
317  const VMRangeToPermissions::Entry *permission_entry =
319  if (permission_entry) {
320  if (permission_entry->Contains(load_addr)) {
321  region_info.GetRange().SetRangeBase(permission_entry->GetRangeBase());
322  region_info.GetRange().SetRangeEnd(permission_entry->GetRangeEnd());
323  const Flags permissions(permission_entry->data);
324  region_info.SetReadable(permissions.Test(lldb::ePermissionsReadable)
325  ? MemoryRegionInfo::eYes
326  : MemoryRegionInfo::eNo);
327  region_info.SetWritable(permissions.Test(lldb::ePermissionsWritable)
328  ? MemoryRegionInfo::eYes
329  : MemoryRegionInfo::eNo);
330  region_info.SetExecutable(permissions.Test(lldb::ePermissionsExecutable)
331  ? MemoryRegionInfo::eYes
332  : MemoryRegionInfo::eNo);
333  region_info.SetMapped(MemoryRegionInfo::eYes);
334 
335  // A region is memory tagged if there is a memory tag segment that covers
336  // the exact same range.
337  region_info.SetMemoryTagged(MemoryRegionInfo::eNo);
338  const VMRangeToFileOffset::Entry *tag_entry =
339  m_core_tag_ranges.FindEntryStartsAt(permission_entry->GetRangeBase());
340  if (tag_entry &&
341  tag_entry->GetRangeEnd() == permission_entry->GetRangeEnd())
342  region_info.SetMemoryTagged(MemoryRegionInfo::eYes);
343  } else if (load_addr < permission_entry->GetRangeBase()) {
344  region_info.GetRange().SetRangeBase(load_addr);
345  region_info.GetRange().SetRangeEnd(permission_entry->GetRangeBase());
346  region_info.SetReadable(MemoryRegionInfo::eNo);
347  region_info.SetWritable(MemoryRegionInfo::eNo);
348  region_info.SetExecutable(MemoryRegionInfo::eNo);
349  region_info.SetMapped(MemoryRegionInfo::eNo);
350  region_info.SetMemoryTagged(MemoryRegionInfo::eNo);
351  }
352  return Status();
353  }
354 
355  region_info.GetRange().SetRangeBase(load_addr);
357  region_info.SetReadable(MemoryRegionInfo::eNo);
358  region_info.SetWritable(MemoryRegionInfo::eNo);
359  region_info.SetExecutable(MemoryRegionInfo::eNo);
360  region_info.SetMapped(MemoryRegionInfo::eNo);
361  region_info.SetMemoryTagged(MemoryRegionInfo::eNo);
362  return Status();
363 }
364 
365 size_t ProcessElfCore::DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
366  Status &error) {
367  ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
368 
369  if (core_objfile == nullptr)
370  return 0;
371 
372  // Get the address range
373  const VMRangeToFileOffset::Entry *address_range =
375  if (address_range == nullptr || address_range->GetRangeEnd() < addr) {
376  error.SetErrorStringWithFormat("core file does not contain 0x%" PRIx64,
377  addr);
378  return 0;
379  }
380 
381  // Convert the address into core file offset
382  const lldb::addr_t offset = addr - address_range->GetRangeBase();
383  const lldb::addr_t file_start = address_range->data.GetRangeBase();
384  const lldb::addr_t file_end = address_range->data.GetRangeEnd();
385  size_t bytes_to_read = size; // Number of bytes to read from the core file
386  size_t bytes_copied = 0; // Number of bytes actually read from the core file
387  lldb::addr_t bytes_left =
388  0; // Number of bytes available in the core file from the given address
389 
390  // Don't proceed if core file doesn't contain the actual data for this
391  // address range.
392  if (file_start == file_end)
393  return 0;
394 
395  // Figure out how many on-disk bytes remain in this segment starting at the
396  // given offset
397  if (file_end > file_start + offset)
398  bytes_left = file_end - (file_start + offset);
399 
400  if (bytes_to_read > bytes_left)
401  bytes_to_read = bytes_left;
402 
403  // If there is data available on the core file read it
404  if (bytes_to_read)
405  bytes_copied =
406  core_objfile->CopyData(offset + file_start, bytes_to_read, buf);
407 
408  return bytes_copied;
409 }
410 
411 llvm::Expected<std::vector<lldb::addr_t>>
413  ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
414  if (core_objfile == nullptr)
415  return llvm::createStringError(llvm::inconvertibleErrorCode(),
416  "No core object file.");
417 
418  llvm::Expected<const MemoryTagManager *> tag_manager_or_err =
420  if (!tag_manager_or_err)
421  return tag_manager_or_err.takeError();
422 
423  // LLDB only supports AArch64 MTE tag segments so we do not need to worry
424  // about the segment type here. If you got here then you must have a tag
425  // manager (meaning you are debugging AArch64) and all the segments in this
426  // list will have had type PT_AARCH64_MEMTAG_MTE.
427  const VMRangeToFileOffset::Entry *tag_entry =
429  // If we don't have a tag segment or the range asked for extends outside the
430  // segment.
431  if (!tag_entry || (addr + len) >= tag_entry->GetRangeEnd())
432  return llvm::createStringError(llvm::inconvertibleErrorCode(),
433  "No tag segment that covers this range.");
434 
435  const MemoryTagManager *tag_manager = *tag_manager_or_err;
436  return tag_manager->UnpackTagsFromCoreFileSegment(
437  [core_objfile](lldb::offset_t offset, size_t length, void *dst) {
438  return core_objfile->CopyData(offset, length, dst);
439  },
440  tag_entry->GetRangeBase(), tag_entry->data.GetRangeBase(), addr, len);
441 }
442 
445 
446  SetUnixSignals(std::make_shared<UnixSignals>());
447 }
448 
450  static llvm::once_flag g_once_flag;
451 
452  llvm::call_once(g_once_flag, []() {
453  PluginManager::RegisterPlugin(GetPluginNameStatic(),
455  });
456 }
457 
459  ObjectFile *obj_file = GetTarget().GetExecutableModule()->GetObjectFile();
460  Address addr = obj_file->GetImageInfoAddress(&GetTarget());
461 
462  if (addr.IsValid())
463  return addr.GetLoadAddress(&GetTarget());
464  return LLDB_INVALID_ADDRESS;
465 }
466 
467 // Parse a FreeBSD NT_PRSTATUS note - see FreeBSD sys/procfs.h for details.
468 static void ParseFreeBSDPrStatus(ThreadData &thread_data,
469  const DataExtractor &data,
470  bool lp64) {
471  lldb::offset_t offset = 0;
472  int pr_version = data.GetU32(&offset);
473 
474  Log *log = GetLog(LLDBLog::Process);
475  if (log) {
476  if (pr_version > 1)
477  LLDB_LOGF(log, "FreeBSD PRSTATUS unexpected version %d", pr_version);
478  }
479 
480  // Skip padding, pr_statussz, pr_gregsetsz, pr_fpregsetsz, pr_osreldate
481  if (lp64)
482  offset += 32;
483  else
484  offset += 16;
485 
486  thread_data.signo = data.GetU32(&offset); // pr_cursig
487  thread_data.tid = data.GetU32(&offset); // pr_pid
488  if (lp64)
489  offset += 4;
490 
491  size_t len = data.GetByteSize() - offset;
492  thread_data.gpregset = DataExtractor(data, offset, len);
493 }
494 
495 // Parse a FreeBSD NT_PRPSINFO note - see FreeBSD sys/procfs.h for details.
497  const DataExtractor &data,
498  bool lp64) {
499  lldb::offset_t offset = 0;
500  int pr_version = data.GetU32(&offset);
501 
502  Log *log = GetLog(LLDBLog::Process);
503  if (log) {
504  if (pr_version > 1)
505  LLDB_LOGF(log, "FreeBSD PRPSINFO unexpected version %d", pr_version);
506  }
507 
508  // Skip pr_psinfosz, pr_fname, pr_psargs
509  offset += 108;
510  if (lp64)
511  offset += 4;
512 
513  process.SetID(data.GetU32(&offset)); // pr_pid
514 }
515 
517  uint32_t &cpi_nlwps,
518  uint32_t &cpi_signo,
519  uint32_t &cpi_siglwp,
520  uint32_t &cpi_pid) {
521  lldb::offset_t offset = 0;
522 
523  uint32_t version = data.GetU32(&offset);
524  if (version != 1)
525  return llvm::make_error<llvm::StringError>(
526  "Error parsing NetBSD core(5) notes: Unsupported procinfo version",
527  llvm::inconvertibleErrorCode());
528 
529  uint32_t cpisize = data.GetU32(&offset);
530  if (cpisize != NETBSD::NT_PROCINFO_SIZE)
531  return llvm::make_error<llvm::StringError>(
532  "Error parsing NetBSD core(5) notes: Unsupported procinfo size",
533  llvm::inconvertibleErrorCode());
534 
535  cpi_signo = data.GetU32(&offset); /* killing signal */
536 
542  cpi_pid = data.GetU32(&offset);
552  cpi_nlwps = data.GetU32(&offset); /* number of LWPs */
553 
555  cpi_siglwp = data.GetU32(&offset); /* LWP target of killing signal */
556 
557  return llvm::Error::success();
558 }
559 
560 static void ParseOpenBSDProcInfo(ThreadData &thread_data,
561  const DataExtractor &data) {
562  lldb::offset_t offset = 0;
563 
564  int version = data.GetU32(&offset);
565  if (version != 1)
566  return;
567 
568  offset += 4;
569  thread_data.signo = data.GetU32(&offset);
570 }
571 
572 llvm::Expected<std::vector<CoreNote>>
574  lldb::offset_t offset = 0;
575  std::vector<CoreNote> result;
576 
577  while (offset < segment.GetByteSize()) {
578  ELFNote note = ELFNote();
579  if (!note.Parse(segment, &offset))
580  return llvm::make_error<llvm::StringError>(
581  "Unable to parse note segment", llvm::inconvertibleErrorCode());
582 
583  size_t note_start = offset;
584  size_t note_size = llvm::alignTo(note.n_descsz, 4);
585 
586  result.push_back({note, DataExtractor(segment, note_start, note_size)});
587  offset += note_size;
588  }
589 
590  return std::move(result);
591 }
592 
593 llvm::Error ProcessElfCore::parseFreeBSDNotes(llvm::ArrayRef<CoreNote> notes) {
594  ArchSpec arch = GetArchitecture();
595  bool lp64 = (arch.GetMachine() == llvm::Triple::aarch64 ||
596  arch.GetMachine() == llvm::Triple::mips64 ||
597  arch.GetMachine() == llvm::Triple::ppc64 ||
598  arch.GetMachine() == llvm::Triple::x86_64);
599  bool have_prstatus = false;
600  bool have_prpsinfo = false;
601  ThreadData thread_data;
602  for (const auto &note : notes) {
603  if (note.info.n_name != "FreeBSD")
604  continue;
605 
606  if ((note.info.n_type == ELF::NT_PRSTATUS && have_prstatus) ||
607  (note.info.n_type == ELF::NT_PRPSINFO && have_prpsinfo)) {
608  assert(thread_data.gpregset.GetByteSize() > 0);
609  // Add the new thread to thread list
610  m_thread_data.push_back(thread_data);
611  thread_data = ThreadData();
612  have_prstatus = false;
613  have_prpsinfo = false;
614  }
615 
616  switch (note.info.n_type) {
617  case ELF::NT_PRSTATUS:
618  have_prstatus = true;
619  ParseFreeBSDPrStatus(thread_data, note.data, lp64);
620  break;
621  case ELF::NT_PRPSINFO:
622  have_prpsinfo = true;
623  ParseFreeBSDPrPsInfo(*this, note.data, lp64);
624  break;
625  case ELF::NT_FREEBSD_THRMISC: {
626  lldb::offset_t offset = 0;
627  thread_data.name = note.data.GetCStr(&offset, 20);
628  break;
629  }
630  case ELF::NT_FREEBSD_PROCSTAT_AUXV:
631  // FIXME: FreeBSD sticks an int at the beginning of the note
632  m_auxv = DataExtractor(note.data, 4, note.data.GetByteSize() - 4);
633  break;
634  default:
635  thread_data.notes.push_back(note);
636  break;
637  }
638  }
639  if (!have_prstatus) {
640  return llvm::make_error<llvm::StringError>(
641  "Could not find NT_PRSTATUS note in core file.",
642  llvm::inconvertibleErrorCode());
643  }
644  m_thread_data.push_back(thread_data);
645  return llvm::Error::success();
646 }
647 
648 /// NetBSD specific Thread context from PT_NOTE segment
649 ///
650 /// NetBSD ELF core files use notes to provide information about
651 /// the process's state. The note name is "NetBSD-CORE" for
652 /// information that is global to the process, and "NetBSD-CORE@nn",
653 /// where "nn" is the lwpid of the LWP that the information belongs
654 /// to (such as register state).
655 ///
656 /// NetBSD uses the following note identifiers:
657 ///
658 /// ELF_NOTE_NETBSD_CORE_PROCINFO (value 1)
659 /// Note is a "netbsd_elfcore_procinfo" structure.
660 /// ELF_NOTE_NETBSD_CORE_AUXV (value 2; since NetBSD 8.0)
661 /// Note is an array of AuxInfo structures.
662 ///
663 /// NetBSD also uses ptrace(2) request numbers (the ones that exist in
664 /// machine-dependent space) to identify register info notes. The
665 /// info in such notes is in the same format that ptrace(2) would
666 /// export that information.
667 ///
668 /// For more information see /usr/include/sys/exec_elf.h
669 ///
670 llvm::Error ProcessElfCore::parseNetBSDNotes(llvm::ArrayRef<CoreNote> notes) {
671  ThreadData thread_data;
672  bool had_nt_regs = false;
673 
674  // To be extracted from struct netbsd_elfcore_procinfo
675  // Used to sanity check of the LWPs of the process
676  uint32_t nlwps = 0;
677  uint32_t signo = 0; // killing signal
678  uint32_t siglwp = 0; // LWP target of killing signal
679  uint32_t pr_pid = 0;
680 
681  for (const auto &note : notes) {
682  llvm::StringRef name = note.info.n_name;
683 
684  if (name == "NetBSD-CORE") {
685  if (note.info.n_type == NETBSD::NT_PROCINFO) {
686  llvm::Error error = ParseNetBSDProcInfo(note.data, nlwps, signo,
687  siglwp, pr_pid);
688  if (error)
689  return error;
690  SetID(pr_pid);
691  } else if (note.info.n_type == NETBSD::NT_AUXV) {
692  m_auxv = note.data;
693  }
694  } else if (name.consume_front("NetBSD-CORE@")) {
695  lldb::tid_t tid;
696  if (name.getAsInteger(10, tid))
697  return llvm::make_error<llvm::StringError>(
698  "Error parsing NetBSD core(5) notes: Cannot convert LWP ID "
699  "to integer",
700  llvm::inconvertibleErrorCode());
701 
702  switch (GetArchitecture().GetMachine()) {
703  case llvm::Triple::aarch64: {
704  // Assume order PT_GETREGS, PT_GETFPREGS
705  if (note.info.n_type == NETBSD::AARCH64::NT_REGS) {
706  // If this is the next thread, push the previous one first.
707  if (had_nt_regs) {
708  m_thread_data.push_back(thread_data);
709  thread_data = ThreadData();
710  had_nt_regs = false;
711  }
712 
713  thread_data.gpregset = note.data;
714  thread_data.tid = tid;
715  if (thread_data.gpregset.GetByteSize() == 0)
716  return llvm::make_error<llvm::StringError>(
717  "Could not find general purpose registers note in core file.",
718  llvm::inconvertibleErrorCode());
719  had_nt_regs = true;
720  } else if (note.info.n_type == NETBSD::AARCH64::NT_FPREGS) {
721  if (!had_nt_regs || tid != thread_data.tid)
722  return llvm::make_error<llvm::StringError>(
723  "Error parsing NetBSD core(5) notes: Unexpected order "
724  "of NOTEs PT_GETFPREG before PT_GETREG",
725  llvm::inconvertibleErrorCode());
726  thread_data.notes.push_back(note);
727  }
728  } break;
729  case llvm::Triple::x86: {
730  // Assume order PT_GETREGS, PT_GETFPREGS
731  if (note.info.n_type == NETBSD::I386::NT_REGS) {
732  // If this is the next thread, push the previous one first.
733  if (had_nt_regs) {
734  m_thread_data.push_back(thread_data);
735  thread_data = ThreadData();
736  had_nt_regs = false;
737  }
738 
739  thread_data.gpregset = note.data;
740  thread_data.tid = tid;
741  if (thread_data.gpregset.GetByteSize() == 0)
742  return llvm::make_error<llvm::StringError>(
743  "Could not find general purpose registers note in core file.",
744  llvm::inconvertibleErrorCode());
745  had_nt_regs = true;
746  } else if (note.info.n_type == NETBSD::I386::NT_FPREGS) {
747  if (!had_nt_regs || tid != thread_data.tid)
748  return llvm::make_error<llvm::StringError>(
749  "Error parsing NetBSD core(5) notes: Unexpected order "
750  "of NOTEs PT_GETFPREG before PT_GETREG",
751  llvm::inconvertibleErrorCode());
752  thread_data.notes.push_back(note);
753  }
754  } break;
755  case llvm::Triple::x86_64: {
756  // Assume order PT_GETREGS, PT_GETFPREGS
757  if (note.info.n_type == NETBSD::AMD64::NT_REGS) {
758  // If this is the next thread, push the previous one first.
759  if (had_nt_regs) {
760  m_thread_data.push_back(thread_data);
761  thread_data = ThreadData();
762  had_nt_regs = false;
763  }
764 
765  thread_data.gpregset = note.data;
766  thread_data.tid = tid;
767  if (thread_data.gpregset.GetByteSize() == 0)
768  return llvm::make_error<llvm::StringError>(
769  "Could not find general purpose registers note in core file.",
770  llvm::inconvertibleErrorCode());
771  had_nt_regs = true;
772  } else if (note.info.n_type == NETBSD::AMD64::NT_FPREGS) {
773  if (!had_nt_regs || tid != thread_data.tid)
774  return llvm::make_error<llvm::StringError>(
775  "Error parsing NetBSD core(5) notes: Unexpected order "
776  "of NOTEs PT_GETFPREG before PT_GETREG",
777  llvm::inconvertibleErrorCode());
778  thread_data.notes.push_back(note);
779  }
780  } break;
781  default:
782  break;
783  }
784  }
785  }
786 
787  // Push the last thread.
788  if (had_nt_regs)
789  m_thread_data.push_back(thread_data);
790 
791  if (m_thread_data.empty())
792  return llvm::make_error<llvm::StringError>(
793  "Error parsing NetBSD core(5) notes: No threads information "
794  "specified in notes",
795  llvm::inconvertibleErrorCode());
796 
797  if (m_thread_data.size() != nlwps)
798  return llvm::make_error<llvm::StringError>(
799  "Error parsing NetBSD core(5) notes: Mismatch between the number "
800  "of LWPs in netbsd_elfcore_procinfo and the number of LWPs specified "
801  "by MD notes",
802  llvm::inconvertibleErrorCode());
803 
804  // Signal targeted at the whole process.
805  if (siglwp == 0) {
806  for (auto &data : m_thread_data)
807  data.signo = signo;
808  }
809  // Signal destined for a particular LWP.
810  else {
811  bool passed = false;
812 
813  for (auto &data : m_thread_data) {
814  if (data.tid == siglwp) {
815  data.signo = signo;
816  passed = true;
817  break;
818  }
819  }
820 
821  if (!passed)
822  return llvm::make_error<llvm::StringError>(
823  "Error parsing NetBSD core(5) notes: Signal passed to unknown LWP",
824  llvm::inconvertibleErrorCode());
825  }
826 
827  return llvm::Error::success();
828 }
829 
830 llvm::Error ProcessElfCore::parseOpenBSDNotes(llvm::ArrayRef<CoreNote> notes) {
831  ThreadData thread_data = {};
832  for (const auto &note : notes) {
833  // OpenBSD per-thread information is stored in notes named "OpenBSD@nnn" so
834  // match on the initial part of the string.
835  if (!llvm::StringRef(note.info.n_name).startswith("OpenBSD"))
836  continue;
837 
838  switch (note.info.n_type) {
840  ParseOpenBSDProcInfo(thread_data, note.data);
841  break;
842  case OPENBSD::NT_AUXV:
843  m_auxv = note.data;
844  break;
845  case OPENBSD::NT_REGS:
846  thread_data.gpregset = note.data;
847  break;
848  default:
849  thread_data.notes.push_back(note);
850  break;
851  }
852  }
853  if (thread_data.gpregset.GetByteSize() == 0) {
854  return llvm::make_error<llvm::StringError>(
855  "Could not find general purpose registers note in core file.",
856  llvm::inconvertibleErrorCode());
857  }
858  m_thread_data.push_back(thread_data);
859  return llvm::Error::success();
860 }
861 
862 /// A description of a linux process usually contains the following NOTE
863 /// entries:
864 /// - NT_PRPSINFO - General process information like pid, uid, name, ...
865 /// - NT_SIGINFO - Information about the signal that terminated the process
866 /// - NT_AUXV - Process auxiliary vector
867 /// - NT_FILE - Files mapped into memory
868 ///
869 /// Additionally, for each thread in the process the core file will contain at
870 /// least the NT_PRSTATUS note, containing the thread id and general purpose
871 /// registers. It may include additional notes for other register sets (floating
872 /// point and vector registers, ...). The tricky part here is that some of these
873 /// notes have "CORE" in their owner fields, while other set it to "LINUX".
874 llvm::Error ProcessElfCore::parseLinuxNotes(llvm::ArrayRef<CoreNote> notes) {
875  const ArchSpec &arch = GetArchitecture();
876  bool have_prstatus = false;
877  bool have_prpsinfo = false;
878  ThreadData thread_data;
879  for (const auto &note : notes) {
880  if (note.info.n_name != "CORE" && note.info.n_name != "LINUX")
881  continue;
882 
883  if ((note.info.n_type == ELF::NT_PRSTATUS && have_prstatus) ||
884  (note.info.n_type == ELF::NT_PRPSINFO && have_prpsinfo)) {
885  assert(thread_data.gpregset.GetByteSize() > 0);
886  // Add the new thread to thread list
887  m_thread_data.push_back(thread_data);
888  thread_data = ThreadData();
889  have_prstatus = false;
890  have_prpsinfo = false;
891  }
892 
893  switch (note.info.n_type) {
894  case ELF::NT_PRSTATUS: {
895  have_prstatus = true;
896  ELFLinuxPrStatus prstatus;
897  Status status = prstatus.Parse(note.data, arch);
898  if (status.Fail())
899  return status.ToError();
900  thread_data.prstatus_sig = prstatus.pr_cursig;
901  thread_data.tid = prstatus.pr_pid;
902  uint32_t header_size = ELFLinuxPrStatus::GetSize(arch);
903  size_t len = note.data.GetByteSize() - header_size;
904  thread_data.gpregset = DataExtractor(note.data, header_size, len);
905  break;
906  }
907  case ELF::NT_PRPSINFO: {
908  have_prpsinfo = true;
909  ELFLinuxPrPsInfo prpsinfo;
910  Status status = prpsinfo.Parse(note.data, arch);
911  if (status.Fail())
912  return status.ToError();
913  thread_data.name.assign (prpsinfo.pr_fname, strnlen (prpsinfo.pr_fname, sizeof (prpsinfo.pr_fname)));
914  SetID(prpsinfo.pr_pid);
915  break;
916  }
917  case ELF::NT_SIGINFO: {
918  ELFLinuxSigInfo siginfo;
919  Status status = siginfo.Parse(note.data, arch);
920  if (status.Fail())
921  return status.ToError();
922  thread_data.signo = siginfo.si_signo;
923  break;
924  }
925  case ELF::NT_FILE: {
926  m_nt_file_entries.clear();
927  lldb::offset_t offset = 0;
928  const uint64_t count = note.data.GetAddress(&offset);
929  note.data.GetAddress(&offset); // Skip page size
930  for (uint64_t i = 0; i < count; ++i) {
931  NT_FILE_Entry entry;
932  entry.start = note.data.GetAddress(&offset);
933  entry.end = note.data.GetAddress(&offset);
934  entry.file_ofs = note.data.GetAddress(&offset);
935  m_nt_file_entries.push_back(entry);
936  }
937  for (uint64_t i = 0; i < count; ++i) {
938  const char *path = note.data.GetCStr(&offset);
939  if (path && path[0])
940  m_nt_file_entries[i].path.SetCString(path);
941  }
942  break;
943  }
944  case ELF::NT_AUXV:
945  m_auxv = note.data;
946  break;
947  default:
948  thread_data.notes.push_back(note);
949  break;
950  }
951  }
952  // Add last entry in the note section
953  if (have_prstatus)
954  m_thread_data.push_back(thread_data);
955  return llvm::Error::success();
956 }
957 
958 /// Parse Thread context from PT_NOTE segment and store it in the thread list
959 /// A note segment consists of one or more NOTE entries, but their types and
960 /// meaning differ depending on the OS.
962  const elf::ELFProgramHeader &segment_header,
963  const DataExtractor &segment_data) {
964  assert(segment_header.p_type == llvm::ELF::PT_NOTE);
965 
966  auto notes_or_error = parseSegment(segment_data);
967  if(!notes_or_error)
968  return notes_or_error.takeError();
969  switch (GetArchitecture().GetTriple().getOS()) {
970  case llvm::Triple::FreeBSD:
971  return parseFreeBSDNotes(*notes_or_error);
972  case llvm::Triple::Linux:
973  return parseLinuxNotes(*notes_or_error);
974  case llvm::Triple::NetBSD:
975  return parseNetBSDNotes(*notes_or_error);
976  case llvm::Triple::OpenBSD:
977  return parseOpenBSDNotes(*notes_or_error);
978  default:
979  return llvm::make_error<llvm::StringError>(
980  "Don't know how to parse core file. Unsupported OS.",
981  llvm::inconvertibleErrorCode());
982  }
983 }
984 
986  if (!m_thread_data_valid)
987  DoLoadCore();
988  return m_thread_data.size();
989 }
990 
992  ArchSpec arch = m_core_module_sp->GetObjectFile()->GetArchitecture();
993 
994  ArchSpec target_arch = GetTarget().GetArchitecture();
995  arch.MergeFrom(target_arch);
996 
997  // On MIPS there is no way to differentiate betwenn 32bit and 64bit core
998  // files and this information can't be merged in from the target arch so we
999  // fail back to unconditionally returning the target arch in this config.
1000  if (target_arch.IsMIPS()) {
1001  return target_arch;
1002  }
1003 
1004  return arch;
1005 }
1006 
1008  const uint8_t *start = m_auxv.GetDataStart();
1009  size_t len = m_auxv.GetByteSize();
1010  lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(start, len));
1011  return DataExtractor(buffer, GetByteOrder(), GetAddressByteSize());
1012 }
1013 
1015  info.Clear();
1016  info.SetProcessID(GetID());
1018  lldb::ModuleSP module_sp = GetTarget().GetExecutableModule();
1019  if (module_sp) {
1020  const bool add_exe_file_as_first_arg = false;
1021  info.SetExecutableFile(GetTarget().GetExecutableModule()->GetFileSpec(),
1022  add_exe_file_as_first_arg);
1023  }
1024  return true;
1025 }
lldb_private::NETBSD::NT_PROCINFO_CPI_SIGCATCH_SIZE
@ NT_PROCINFO_CPI_SIGCATCH_SIZE
Definition: RegisterUtilities.h:34
lldb_private::ProcessInstanceInfo
Definition: ProcessInfo.h:106
ELFLinuxPrPsInfo::pr_fname
char pr_fname[16]
Definition: ThreadElfCore.h:107
ProcessElfCore::ReadMemoryTags
llvm::Expected< std::vector< lldb::addr_t > > ReadMemoryTags(lldb::addr_t addr, size_t len) override
Read memory tags for the range addr to addr+len.
Definition: ProcessElfCore.cpp:412
lldb_private::Range::GetRangeBase
BaseType GetRangeBase() const
Definition: RangeMap.h:46
llvm
Definition: Debugger.h:50
ProcessElfCore::Initialize
static void Initialize()
Definition: ProcessElfCore.cpp:449
lldb_private::FileSystem::CreateDataBuffer
std::shared_ptr< DataBuffer > CreateDataBuffer(const llvm::Twine &path, uint64_t size=0, uint64_t offset=0)
Create memory buffer from path.
Definition: common/FileSystem.cpp:308
ELFLinuxPrStatus::GetSize
static size_t GetSize(const lldb_private::ArchSpec &arch)
Definition: ThreadElfCore.cpp:236
ProcessElfCore::GetAuxvData
lldb_private::DataExtractor GetAuxvData() override
Definition: ProcessElfCore.cpp:1007
lldb_private::ArchSpec
Definition: ArchSpec.h:32
ProcessElfCore::parseLinuxNotes
llvm::Error parseLinuxNotes(llvm::ArrayRef< lldb_private::CoreNote > notes)
A description of a linux process usually contains the following NOTE entries:
Definition: ProcessElfCore.cpp:874
lldb_private::ArchSpec::IsMIPS
bool IsMIPS() const
if MIPS architecture return true.
Definition: ArchSpec.cpp:542
ObjectFileELF::ProgramHeaders
llvm::ArrayRef< elf::ELFProgramHeader > ProgramHeaders()
Definition: ObjectFileELF.cpp:3407
ELFLinuxPrStatus
Definition: ThreadElfCore.h:34
ThreadData::gpregset
lldb_private::DataExtractor gpregset
Definition: ThreadElfCore.h:127
lldb_private::NETBSD::NT_PROCINFO_CPI_PGRP_SIZE
@ NT_PROCINFO_CPI_PGRP_SIZE
Definition: RegisterUtilities.h:37
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
lldb_private::Address::IsValid
bool IsValid() const
Check if the object state is valid.
Definition: Address.h:345
lldb_private::ProcessInfo::SetExecutableFile
void SetExecutableFile(const FileSpec &exe_file, bool add_exe_file_as_first_arg)
Definition: ProcessInfo.cpp:60
elf::ELFHeader
Definition: ELFHeader.h:56
lldb_private::ProcessInfo::SetArchitecture
void SetArchitecture(const ArchSpec &arch)
Definition: ProcessInfo.h:64
ThreadData::prstatus_sig
int prstatus_sig
Definition: ThreadElfCore.h:131
lldb_private::ArchSpec::GetMachine
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition: ArchSpec.cpp:666
lldb_private::NETBSD::NT_PROCINFO_CPI_SVGID_SIZE
@ NT_PROCINFO_CPI_SVGID_SIZE
Definition: RegisterUtilities.h:44
ModuleSpec.h
elf::ELFProgramHeader::p_vaddr
elf_addr p_vaddr
Virtual address of segment in memory.
Definition: ELFHeader.h:196
ELFLinuxSigInfo::Parse
lldb_private::Status Parse(const lldb_private::DataExtractor &data, const lldb_private::ArchSpec &arch)
Definition: ThreadElfCore.cpp:399
lldb_private::ProcessInstanceInfo::Clear
void Clear()
Definition: ProcessInfo.h:114
ProcessElfCore.h
ThreadData::signo
int signo
Definition: ThreadElfCore.h:130
elf::ELFHeader::Parse
bool Parse(lldb_private::DataExtractor &data, lldb::offset_t *offset)
Parse an ELFHeader entry starting at position offset and update the data extractor with the address s...
Definition: ELFHeader.cpp:114
elf::ELFHeader::e_version
elf_word e_version
Version of object file (always 1).
Definition: ELFHeader.h:62
lldb_private::Target::GetOrCreateModule
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:2073
ProcessElfCore::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: ProcessElfCore.cpp:304
ProcessElfCore::AddAddressRangeFromLoadSegment
lldb::addr_t AddAddressRangeFromLoadSegment(const elf::ELFProgramHeader &header)
Definition: ProcessElfCore.cpp:114
elf::ELFHeader::e_ident
unsigned char e_ident[llvm::ELF::EI_NIDENT]
ELF file identification.
Definition: ELFHeader.h:57
lldb_private::MemoryTagManager::UnpackTagsFromCoreFileSegment
virtual std::vector< lldb::addr_t > UnpackTagsFromCoreFileSegment(CoreReaderFn reader, lldb::addr_t tag_segment_virtual_address, lldb::addr_t tag_segment_data_address, lldb::addr_t addr, size_t len) const =0
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:344
lldb_private::MemoryRegionInfo::Clear
void Clear()
Definition: MemoryRegionInfo.h:40
lldb_private::ArchSpec::MergeFrom
void MergeFrom(const ArchSpec &other)
Merges fields from another ArchSpec into this ArchSpec.
Definition: ArchSpec.cpp:800
lldb_private::Target::GetExecutableModule
lldb::ModuleSP GetExecutableModule()
Gets the module for the main executable.
Definition: Target.cpp:1369
Module.h
ProcessElfCore::IsAlive
bool IsAlive() override
Check if a process is still alive.
Definition: ProcessElfCore.cpp:301
ProcessElfCore::RefreshStateAfterStop
void RefreshStateAfterStop() override
Currently called as part of ShouldStop.
Definition: ProcessElfCore.cpp:295
lldb_private::NETBSD::AARCH64::NT_FPREGS
@ NT_FPREGS
Definition: RegisterUtilities.h:51
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
RegisterUtilities.h
lldb_private::Flags
Definition: Flags.h:22
ProcessElfCore::m_core_range_infos
VMRangeToPermissions m_core_range_infos
Definition: ProcessElfCore.h:147
elf::ELFProgramHeader::p_memsz
elf_xword p_memsz
Byte size of the segment in memory.
Definition: ELFHeader.h:199
lldb_private::MemoryRegionInfo::SetMemoryTagged
void SetMemoryTagged(OptionalBool val)
Definition: MemoryRegionInfo.h:78
ProcessElfCore::m_thread_data_valid
bool m_thread_data_valid
Definition: ProcessElfCore.h:135
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::ProcessInfo::SetProcessID
void SetProcessID(lldb::pid_t pid)
Definition: ProcessInfo.h:68
lldb_private::Process::SetID
void SetID(lldb::pid_t new_pid)
Sets the stored pid.
Definition: Process.h:531
lldb_private::RangeData
Definition: RangeMap.h:415
ThreadElfCore.h
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::MemoryRegionInfo::SetReadable
void SetReadable(OptionalBool val)
Definition: MemoryRegionInfo.h:58
ProcessElfCore::DoLoadCore
lldb_private::Status DoLoadCore() override
Definition: ProcessElfCore.cpp:160
ProcessElfCore::m_core_aranges
VMRangeToFileOffset m_core_aranges
Definition: ProcessElfCore.h:144
ELFLinuxPrStatus::Parse
lldb_private::Status Parse(const lldb_private::DataExtractor &data, const lldb_private::ArchSpec &arch)
Definition: ThreadElfCore.cpp:262
ProcessElfCore::NT_FILE_Entry
Definition: ProcessElfCore.h:116
ProcessElfCore::GetPluginNameStatic
static llvm::StringRef GetPluginNameStatic()
Definition: ProcessElfCore.h:43
Section.h
ProcessElfCore::GetDynamicLoader
lldb_private::DynamicLoader * GetDynamicLoader() override
Get the dynamic loader plug-in for this process.
Definition: ProcessElfCore.cpp:274
ABI.h
ELFLinuxPrPsInfo::Parse
lldb_private::Status Parse(const lldb_private::DataExtractor &data, const lldb_private::ArchSpec &arch)
Definition: ThreadElfCore.cpp:331
lldb_private::NETBSD::NT_AUXV
@ NT_AUXV
Definition: RegisterUtilities.h:20
elf::ELFProgramHeader::p_flags
elf_word p_flags
Segment attributes.
Definition: ELFHeader.h:194
lldb_private::MemoryTagManager
Definition: MemoryTagManager.h:28
ELFLinuxPrPsInfo
Definition: ThreadElfCore.h:95
ELFNote
Definition: ObjectFileELF.h:24
Target.h
ProcessElfCore::GetImageInfoAddress
lldb::addr_t GetImageInfoAddress() override
Get the image information address for the current process.
Definition: ProcessElfCore.cpp:458
ELFNote::n_descsz
elf::elf_word n_descsz
Definition: ObjectFileELF.h:26
lldb_private::RangeDataVector::FindEntryThatContains
Entry * FindEntryThatContains(B addr)
Definition: RangeMap.h:563
lldb_private::FileSpec
Definition: FileSpec.h:55
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
lldb_private::NETBSD::NT_PROCINFO_CPI_SVUID_SIZE
@ NT_PROCINFO_CPI_SVUID_SIZE
Definition: RegisterUtilities.h:41
lldb_private::RangeDataVector::Append
void Append(const Entry &entry)
Definition: RangeMap.h:451
ProcessElfCore::Terminate
static void Terminate()
Definition: ProcessElfCore.cpp:46
lldb_private::PluginManager::UnregisterPlugin
static bool UnregisterPlugin(ABICreateInstance create_callback)
Definition: PluginManager.cpp:293
lldb_private::DataExtractor
Definition: DataExtractor.h:48
elf::ELFHeader::e_type
elf_half e_type
Object file type.
Definition: ELFHeader.h:63
Log.h
lldb_private::eLoadDependentsNo
@ eLoadDependentsNo
Definition: lldb-private-enumerations.h:231
MemoryRegionInfo.h
ProcessElfCore::~ProcessElfCore
~ProcessElfCore() override
Definition: ProcessElfCore.cpp:105
UnixSignals.h
lldb_private::MemoryRegionInfo::SetExecutable
void SetExecutable(OptionalBool val)
Definition: MemoryRegionInfo.h:62
ProcessElfCore::GetNumThreadContexts
uint32_t GetNumThreadContexts()
Definition: ProcessElfCore.cpp:985
ProcessElfCore::m_core_tag_ranges
VMRangeToFileOffset m_core_tag_ranges
Definition: ProcessElfCore.h:150
lldb_private::Status::Fail
bool Fail() const
Test for error condition.
Definition: Status.cpp:181
lldb_private::Process::m_dyld_up
lldb::DynamicLoaderUP m_dyld_up
Definition: Process.h:2895
ProcessElfCore::GetProcessInfo
bool GetProcessInfo(lldb_private::ProcessInstanceInfo &info) override
Definition: ProcessElfCore.cpp:1014
lldb_private::ObjectFile::GetImageInfoAddress
virtual lldb_private::Address GetImageInfoAddress(Target *target)
Similar to Process::GetImageInfoAddress().
Definition: ObjectFile.h:477
lldb_private::NETBSD::NT_PROCINFO_CPI_SIGMASK_SIZE
@ NT_PROCINFO_CPI_SIGMASK_SIZE
Definition: RegisterUtilities.h:32
ObjectFileELF.h
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::eTypeCoreFile
@ eTypeCoreFile
A core file that has a checkpoint of a program's execution state.
Definition: ObjectFile.h:69
lldb_private::DataExtractor::GetDataStart
const uint8_t * GetDataStart() const
Get the data start pointer.
Definition: DataExtractor.h:422
ProcessElfCore::m_auxv
lldb_private::DataExtractor m_auxv
Definition: ProcessElfCore.h:141
lldb_private::Process::GetAddressByteSize
uint32_t GetAddressByteSize() const
Definition: Process.cpp:3366
lldb_private::ThreadList
Definition: ThreadList.h:26
ProcessElfCore::AddAddressRangeFromMemoryTagSegment
lldb::addr_t AddAddressRangeFromMemoryTagSegment(const elf::ELFProgramHeader &header)
Definition: ProcessElfCore.cpp:147
ThreadData::tid
lldb::tid_t tid
Definition: ThreadElfCore.h:129
ProcessElfCore::ParseThreadContextsFromNoteSegment
llvm::Error ParseThreadContextsFromNoteSegment(const elf::ELFProgramHeader &segment_header, const lldb_private::DataExtractor &segment_data)
Parse Thread context from PT_NOTE segment and store it in the thread list A note segment consists of ...
Definition: ProcessElfCore.cpp:961
lldb_private::NETBSD::NT_PROCINFO_CPI_SIGPEND_SIZE
@ NT_PROCINFO_CPI_SIGPEND_SIZE
Definition: RegisterUtilities.h:31
lldb_private::PostMortemProcess
Definition: PostMortemProcess.h:23
ParseFreeBSDPrStatus
static void ParseFreeBSDPrStatus(ThreadData &thread_data, const DataExtractor &data, bool lp64)
Definition: ProcessElfCore.cpp:468
ProcessElfCore::m_thread_data
std::vector< ThreadData > m_thread_data
Definition: ProcessElfCore.h:138
ProcessElfCore::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: ProcessElfCore.cpp:314
lldb_private::Range< lldb::addr_t, lldb::addr_t >
elf::ELFProgramHeader::p_type
elf_word p_type
Type of program segment.
Definition: ELFHeader.h:193
ProcessElfCore::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: ProcessElfCore.cpp:281
ProcessElfCore::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: ProcessElfCore.cpp:365
ProcessElfCore::parseSegment
llvm::Expected< std::vector< lldb_private::CoreNote > > parseSegment(const lldb_private::DataExtractor &segment)
Definition: ProcessElfCore.cpp:573
lldb_private::DynamicLoader
Definition: DynamicLoader.h:52
lldb_private::Process::GetMemoryTagManager
llvm::Expected< const MemoryTagManager * > GetMemoryTagManager()
If this architecture and process supports memory tagging, return a tag manager that can be used to ma...
Definition: Process.cpp:6108
ProcessElfCore::ProcessElfCore
ProcessElfCore(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, const lldb_private::FileSpec &core_file)
Definition: ProcessElfCore.cpp:99
ELFLinuxSigInfo::si_signo
int32_t si_signo
Definition: ThreadElfCore.h:71
DynamicLoaderPOSIXDYLD::GetPluginNameStatic
static llvm::StringRef GetPluginNameStatic()
Definition: DynamicLoaderPOSIXDYLD.h:33
lldb_private::Process::SetUnixSignals
void SetUnixSignals(lldb::UnixSignalsSP &&signals_sp)
Definition: Process.cpp:3352
ParseFreeBSDPrPsInfo
static void ParseFreeBSDPrPsInfo(ProcessElfCore &process, const DataExtractor &data, bool lp64)
Definition: ProcessElfCore.cpp:496
lldb_private::Process::GetUnixSignals
const lldb::UnixSignalsSP & GetUnixSignals()
Definition: Process.cpp:3357
ProcessElfCore::m_core_module_sp
lldb::ModuleSP m_core_module_sp
Definition: ProcessElfCore.h:130
ELFLinuxSigInfo
Definition: ThreadElfCore.h:70
lldb_private::Target::SetExecutableModule
void SetExecutableModule(lldb::ModuleSP &module_sp, LoadDependentFiles load_dependent_files=eLoadDependentsDefault)
Set the main executable module.
Definition: Target.cpp:1418
lldb_private::RangeDataVector::FindEntryStartsAt
const Entry * FindEntryStartsAt(B addr) const
Definition: RangeMap.h:592
lldb_private::MemoryRegionInfo::SetWritable
void SetWritable(OptionalBool val)
Definition: MemoryRegionInfo.h:60
ELFLinuxPrStatus::pr_pid
uint32_t pr_pid
Definition: ThreadElfCore.h:44
lldb_private::RangeDataVector::Back
Entry * Back()
Definition: RangeMap.h:646
ProcessElfCore::Clear
void Clear()
Definition: ProcessElfCore.cpp:443
ProcessElfCore::GetPluginDescriptionStatic
static llvm::StringRef GetPluginDescriptionStatic()
Definition: ProcessElfCore.cpp:42
ELFLinuxPrStatus::pr_cursig
int16_t pr_cursig
Definition: ThreadElfCore.h:39
lldb_private::ModuleSpec::GetFileSpec
FileSpec & GetFileSpec()
Definition: ModuleSpec.h:53
lldb_private::ModuleSpec
Definition: ModuleSpec.h:27
lldb_private::Target::GetArchitecture
const ArchSpec & GetArchitecture() const
Definition: Target.h:989
ProcessElfCore::NT_FILE_Entry::file_ofs
lldb::addr_t file_ofs
Definition: ProcessElfCore.h:119
lldb_private::Status
Definition: Status.h:44
ParseNetBSDProcInfo
static llvm::Error ParseNetBSDProcInfo(const DataExtractor &data, uint32_t &cpi_nlwps, uint32_t &cpi_signo, uint32_t &cpi_siglwp, uint32_t &cpi_pid)
Definition: ProcessElfCore.cpp:516
lldb_private::NETBSD::AARCH64::NT_REGS
@ NT_REGS
Definition: RegisterUtilities.h:51
uint32_t
lldb_private::Address
Definition: Address.h:59
ProcessElfCore::NT_FILE_Entry::start
lldb::addr_t start
Definition: ProcessElfCore.h:117
ThreadData
Definition: ThreadElfCore.h:126
DynamicLoaderPOSIXDYLD.h
lldb_private::NETBSD::NT_PROCINFO_CPI_RUID_SIZE
@ NT_PROCINFO_CPI_RUID_SIZE
Definition: RegisterUtilities.h:39
lldb_private::MemoryRegionInfo::SetMapped
void SetMapped(OptionalBool val)
Definition: MemoryRegionInfo.h:66
lldb_private::Address::GetLoadAddress
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition: Address.cpp:311
elf::ELFHeader::MagicBytesMatch
static bool MagicBytesMatch(const uint8_t *magic)
Examines at most EI_NIDENT bytes starting from the given pointer and determines if the magic ELF iden...
Definition: ELFHeader.cpp:157
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
lldb_private::NETBSD::NT_PROCINFO_CPI_RGID_SIZE
@ NT_PROCINFO_CPI_RGID_SIZE
Definition: RegisterUtilities.h:42
lldb_private::Range::GetByteSize
SizeType GetByteSize() const
Definition: RangeMap.h:87
elf::ELFProgramHeader
Definition: ELFHeader.h:192
ObjectFileELF::GetSegmentData
lldb_private::DataExtractor GetSegmentData(const elf::ELFProgramHeader &H)
Definition: ObjectFileELF.cpp:3412
ObjectFileELF
Definition: ObjectFileELF.h:57
ProcessElfCore::parseNetBSDNotes
llvm::Error parseNetBSDNotes(llvm::ArrayRef< lldb_private::CoreNote > notes)
NetBSD specific Thread context from PT_NOTE segment.
Definition: ProcessElfCore.cpp:670
lldb_private::DataExtractor::GetU32
uint32_t GetU32(lldb::offset_t *offset_ptr) const
Extract a uint32_t value from *offset_ptr.
Definition: DataExtractor.cpp:425
PluginManager.h
lldb_private::NETBSD::NT_PROCINFO_SIZE
@ NT_PROCINFO_SIZE
Definition: RegisterUtilities.h:23
ProcessElfCore::DoDestroy
lldb_private::Status DoDestroy() override
Definition: ProcessElfCore.cpp:297
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:74
ProcessElfCore::parseFreeBSDNotes
llvm::Error parseFreeBSDNotes(llvm::ArrayRef< lldb_private::CoreNote > notes)
Definition: ProcessElfCore.cpp:593
lldb_private::ModuleSpec::GetArchitecture
ArchSpec & GetArchitecture()
Definition: ModuleSpec.h:89
lldb_private::Process::GetID
lldb::pid_t GetID() const
Returns the pid of the process or LLDB_INVALID_PROCESS_ID if there is no known pid.
Definition: Process.h:526
lldb_private::MemoryRegionInfo::GetRange
RangeType & GetRange()
Definition: MemoryRegionInfo.h:38
lldb_private::FileSystem::Instance
static FileSystem & Instance()
Definition: common/FileSystem.cpp:46
ParseOpenBSDProcInfo
static void ParseOpenBSDProcInfo(ThreadData &thread_data, const DataExtractor &data)
Definition: ProcessElfCore.cpp:560
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::NETBSD::NT_PROCINFO_CPI_SIGCODE_SIZE
@ NT_PROCINFO_CPI_SIGCODE_SIZE
Definition: RegisterUtilities.h:30
ProcessElfCore::parseOpenBSDNotes
llvm::Error parseOpenBSDNotes(llvm::ArrayRef< lldb_private::CoreNote > notes)
Definition: ProcessElfCore.cpp:830
Error
llvm::Error Error
Definition: UdtRecordCompleter.cpp:30
ProcessElfCore::m_nt_file_entries
std::vector< NT_FILE_Entry > m_nt_file_entries
Definition: ProcessElfCore.h:153
ThreadData::notes
std::vector< lldb_private::CoreNote > notes
Definition: ThreadElfCore.h:128
ThreadData::name
std::string name
Definition: ThreadElfCore.h:132
lldb_private::Status::ToError
llvm::Error ToError() const
Definition: Status.cpp:89
lldb_private::Process::GetABI
const lldb::ABISP & GetABI()
Definition: Process.cpp:1483
ELFLinuxPrPsInfo::pr_pid
int32_t pr_pid
Definition: ThreadElfCore.h:103
State.h
lldb_private::ThreadCollection::AddThread
void AddThread(const lldb::ThreadSP &thread_sp)
Definition: ThreadCollection.cpp:24
elf::ELFProgramHeader::p_filesz
elf_xword p_filesz
Byte size of the segment in file.
Definition: ELFHeader.h:198
ProcessElfCore::NT_FILE_Entry::end
lldb::addr_t end
Definition: ProcessElfCore.h:118
ProcessElfCore
Definition: ProcessElfCore.h:31
lldb_private::Process::GetByteOrder
lldb::ByteOrder GetByteOrder() const
Definition: Process.cpp:3362
LLDB_PLUGIN_DEFINE
#define LLDB_PLUGIN_DEFINE(PluginName)
Definition: PluginManager.h:31
lldb_private::Log
Definition: Log.h:115
ProcessElfCore::CreateInstance
static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, const lldb_private::FileSpec *crash_file_path, bool can_connect)
Definition: ProcessElfCore.cpp:50
lldb_private::FileSpec::SetFile
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
Definition: FileSpec.cpp:172
lldb_private::NETBSD::NT_PROCINFO_CPI_NAME_SIZE
@ NT_PROCINFO_CPI_NAME_SIZE
Definition: RegisterUtilities.h:46
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::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
lldb_private::NETBSD::NT_PROCINFO_CPI_EGID_SIZE
@ NT_PROCINFO_CPI_EGID_SIZE
Definition: RegisterUtilities.h:43
lldb_private::DataExtractor::GetByteSize
uint64_t GetByteSize() const
Get the number of bytes contained in this object.
Definition: DataExtractor.h:270
lldb::eByteOrderLittle
@ eByteOrderLittle
Definition: lldb-enumerations.h:142
ProcessElfCore::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: ProcessElfCore.cpp:82
DynamicLoader.h
lldb_private::DataBufferHeap
Definition: DataBufferHeap.h:30
lldb_private::Range::Contains
bool Contains(BaseType r) const
Definition: RangeMap.h:93
lldb_private::ModuleList::GetSharedModule
static Status GetSharedModule(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp, const FileSpecList *module_search_paths_ptr, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr, bool always_create=false)
Definition: ModuleList.cpp:786
ProcessElfCore::GetArchitecture
lldb_private::ArchSpec GetArchitecture()
Definition: ProcessElfCore.cpp:991
ThreadElfCore
Definition: ThreadElfCore.h:135
LLDBLog.h
lldb_private::NETBSD::NT_PROCINFO_CPI_EUID_SIZE
@ NT_PROCINFO_CPI_EUID_SIZE
Definition: RegisterUtilities.h:40
lldb_private::NETBSD::NT_PROCINFO_CPI_SIGIGNORE_SIZE
@ NT_PROCINFO_CPI_SIGIGNORE_SIZE
Definition: RegisterUtilities.h:33
lldb_private::ObjectFile
Definition: ObjectFile.h:60
DataBufferHeap.h
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
ELFNote::Parse
bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset)
Parse an ELFNote entry from the given DataExtractor starting at position offset.
Definition: ObjectFileELF.cpp:219
lldb_private::NETBSD::NT_PROCINFO_CPI_PPID_SIZE
@ NT_PROCINFO_CPI_PPID_SIZE
Definition: RegisterUtilities.h:36
lldb_private::NETBSD::NT_PROCINFO
@ NT_PROCINFO
Definition: RegisterUtilities.h:20
lldb_private::ObjectFile::GetType
Type GetType()
Definition: ObjectFile.h:637
lldb::tid_t
uint64_t tid_t
Definition: lldb-types.h:86
elf::ELFProgramHeader::p_offset
elf_off p_offset
Start of segment from beginning of file.
Definition: ELFHeader.h:195
lldb_private::NETBSD::NT_PROCINFO_CPI_SID_SIZE
@ NT_PROCINFO_CPI_SID_SIZE
Definition: RegisterUtilities.h:38
lldb_private::Range::GetRangeEnd
BaseType GetRangeEnd() const
Definition: RangeMap.h:78