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