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