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
13#include "lldb/Core/Module.h"
16#include "lldb/Core/Section.h"
17#include "lldb/Target/ABI.h"
20#include "lldb/Target/Target.h"
24#include "lldb/Utility/Log.h"
25#include "lldb/Utility/State.h"
26
27#include "llvm/BinaryFormat/ELF.h"
28
32#include "ProcessElfCore.h"
33#include "ThreadElfCore.h"
34
35using namespace lldb_private;
36namespace ELF = llvm::ELF;
37
39
41 return "ELF core dump plug-in.";
42}
43
47
49 lldb::ListenerSP listener_sp,
50 const FileSpec *crash_file,
51 bool can_connect) {
52 lldb::ProcessSP process_sp;
53 if (crash_file && !can_connect) {
54 // Read enough data for an ELF32 header or ELF64 header Note: Here we care
55 // about e_type field only, so it is safe to ignore possible presence of
56 // the header extension.
57 const size_t header_size = sizeof(llvm::ELF::Elf64_Ehdr);
58
60 crash_file->GetPath(), header_size, 0);
61 if (data_sp && data_sp->GetByteSize() == header_size &&
62 elf::ELFHeader::MagicBytesMatch(data_sp->GetBytes())) {
63 elf::ELFHeader elf_header;
64 DataExtractor data(data_sp, lldb::eByteOrderLittle, 4);
65 lldb::offset_t data_offset = 0;
66 if (elf_header.Parse(data, &data_offset)) {
67 // Check whether we're dealing with a raw FreeBSD "full memory dump"
68 // ELF vmcore that needs to be handled via FreeBSDKernel plugin instead.
69 if (elf_header.e_ident[7] == 0xFF && elf_header.e_version == 0)
70 return process_sp;
71 if (elf_header.e_type == llvm::ELF::ET_CORE)
72 process_sp = std::make_shared<ProcessElfCore>(target_sp, listener_sp,
73 *crash_file);
74 }
75 }
76 }
77 return process_sp;
78}
79
81 bool plugin_specified_by_name) {
82 // For now we are just making sure the file exists for a given module
84 ModuleSpec core_module_spec(m_core_file, target_sp->GetArchitecture());
85 core_module_spec.SetTarget(target_sp);
87 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
99 lldb::ListenerSP listener_sp,
100 const FileSpec &core_file)
101 : PostMortemProcess(target_sp, listener_sp, core_file), m_uuids() {}
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(true /* destructing */);
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) {
123 VMRangeToFileOffset::Entry *last_entry = m_core_aranges.Back();
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 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
140 m_core_range_infos.Append(
141 VMRangeToPermissions::Entry(addr, header.p_memsz, permissions));
142
143 return addr;
144}
145
147 const elf::ELFProgramHeader &header) {
148 // If lldb understood multiple kinds of tag segments we would record the type
149 // of the segment here also. As long as there is only 1 type lldb looks for,
150 // there is no need.
151 FileRange file_range(header.p_offset, header.p_filesz);
152 m_core_tag_ranges.Append(
153 VMRangeToFileOffset::Entry(header.p_vaddr, header.p_memsz, file_range));
154
155 return header.p_vaddr;
156}
157
158// Process Control
161 if (!m_core_module_sp) {
162 error = Status::FromErrorString("invalid core module");
163 return error;
164 }
165
166 ObjectFileELF *core = (ObjectFileELF *)(m_core_module_sp->GetObjectFile());
167 if (core == nullptr) {
168 error = Status::FromErrorString("invalid core object file");
169 return error;
170 }
171
172 llvm::ArrayRef<elf::ELFProgramHeader> segments = core->ProgramHeaders();
173 if (segments.size() == 0) {
174 error = Status::FromErrorString("core file has no segments");
175 return error;
176 }
177
178 // Even if the architecture is set in the target, we need to override it to
179 // match the core file which is always single arch.
180 ArchSpec arch(m_core_module_sp->GetArchitecture());
181
182 ArchSpec target_arch = GetTarget().GetArchitecture();
183 ArchSpec core_arch(m_core_module_sp->GetArchitecture());
184 target_arch.MergeFrom(core_arch);
185 GetTarget().SetArchitecture(target_arch, /*set_platform*/ true);
186
188
189 SetCanJIT(false);
190
191 m_thread_data_valid = true;
192
193 bool ranges_are_sorted = true;
194 lldb::addr_t vm_addr = 0;
195 lldb::addr_t tag_addr = 0;
196 /// Walk through segments and Thread and Address Map information.
197 /// PT_NOTE - Contains Thread and Register information
198 /// PT_LOAD - Contains a contiguous range of Process Address Space
199 /// PT_AARCH64_MEMTAG_MTE - Contains AArch64 MTE memory tags for a range of
200 /// Process Address Space.
201 for (const elf::ELFProgramHeader &H : segments) {
202 DataExtractor data = core->GetSegmentData(H);
203
204 // Parse thread contexts and auxv structure
205 if (H.p_type == llvm::ELF::PT_NOTE) {
206 if (llvm::Error error = ParseThreadContextsFromNoteSegment(H, data))
207 return Status::FromError(std::move(error));
208 }
209 // PT_LOAD segments contains address map
210 if (H.p_type == llvm::ELF::PT_LOAD) {
212 if (vm_addr > last_addr)
213 ranges_are_sorted = false;
214 vm_addr = last_addr;
215 } else if (H.p_type == llvm::ELF::PT_AARCH64_MEMTAG_MTE) {
217 if (tag_addr > last_addr)
218 ranges_are_sorted = false;
219 tag_addr = last_addr;
220 }
221 }
222
223 if (!ranges_are_sorted) {
224 m_core_aranges.Sort();
225 m_core_range_infos.Sort();
226 m_core_tag_ranges.Sort();
227 }
228
229 // Ensure we found at least one thread that was stopped on a signal.
230 bool siginfo_signal_found = false;
231 bool prstatus_signal_found = false;
232 // Check we found a signal in a SIGINFO note.
233 for (const auto &thread_data : m_thread_data) {
234 if (!thread_data.siginfo_bytes.empty() || thread_data.signo != 0)
235 siginfo_signal_found = true;
236 if (thread_data.prstatus_sig != 0)
237 prstatus_signal_found = true;
238 }
239 if (!siginfo_signal_found) {
240 // If we don't have signal from SIGINFO use the signal from each threads
241 // PRSTATUS note.
242 if (prstatus_signal_found) {
243 for (auto &thread_data : m_thread_data)
244 thread_data.signo = thread_data.prstatus_sig;
245 } else if (m_thread_data.size() > 0) {
246 // If all else fails force the first thread to be SIGSTOP
247 m_thread_data.begin()->signo =
248 GetUnixSignals()->GetSignalNumberFromName("SIGSTOP");
249 }
250 }
251
252 // Try to find gnu build id before we load the executable.
254
255 // Core files are useless without the main executable. See if we can locate
256 // the main executable using data we found in the core file notes.
257 lldb::ModuleSP exe_module_sp = GetTarget().GetExecutableModule();
258 if (!exe_module_sp) {
259 if (!m_nt_file_entries.empty()) {
260 std::string executable_path = GetMainExecutablePath();
261 ModuleSpec exe_module_spec;
262 exe_module_spec.GetArchitecture() = arch;
263 exe_module_spec.GetUUID() = FindModuleUUID(executable_path);
264 exe_module_spec.GetFileSpec().SetFile(executable_path,
265 FileSpec::Style::native);
266 if (exe_module_spec.GetFileSpec()) {
267 exe_module_sp =
268 GetTarget().GetOrCreateModule(exe_module_spec, true /* notify */);
269 if (!exe_module_sp) {
270 // Create an ELF file from memory for the main executable. The dynamic
271 // loader requires the main executable so that it can extract the
272 // DT_DEBUG key/value pair from the dynamic section and get the list
273 // of shared libraries.
274 std::optional<lldb::addr_t> exe_header_addr;
275
276 // We need to find its load address
277 for (const NT_FILE_Entry &file_entry : m_nt_file_entries) {
278 if (file_entry.path == executable_path) {
279 exe_header_addr = file_entry.start;
280 break;
281 }
282 }
283 if (exe_header_addr) {
284 if (llvm::Expected<lldb::ModuleSP> module_sp_or_err =
285 ReadModuleFromMemory(exe_module_spec.GetFileSpec(),
286 *exe_header_addr))
287 exe_module_sp = *module_sp_or_err;
288 else
289 llvm::consumeError(module_sp_or_err.takeError());
290 }
291 }
292 if (exe_module_sp)
294 }
295 }
296 }
297 return error;
298}
299
302 m_uuids.clear();
303 for (NT_FILE_Entry &entry : m_nt_file_entries) {
304 UUID uuid = FindBuidIdInCoreMemory(entry.start);
305 if (uuid.IsValid()) {
306 // Assert that either the path is not in the map or the UUID matches
307 assert(m_uuids.count(entry.path) == 0 || m_uuids[entry.path] == uuid);
308 m_uuids[entry.path] = uuid;
309 if (log)
310 LLDB_LOGF(log, "%s found UUID @ %16.16" PRIx64 ": %s \"%s\"",
311 __FUNCTION__, entry.start, uuid.GetAsString().c_str(),
312 entry.path.c_str());
313 }
314 }
315}
316
318 // Always try to read the program name from core file memory first via the
319 // AUXV_AT_EXECFN entry. This value is the address of a null terminated C
320 // string that contains the program path.
321 AuxVector aux_vector(m_auxv);
322 std::string execfn_str;
323 if (auto execfn = aux_vector.GetAuxValue(AuxVector::AUXV_AT_EXECFN)) {
325 if (ReadCStringFromMemory(*execfn, execfn_str, error))
326 return execfn_str;
327 }
328
329 if (m_nt_file_entries.empty())
330 return {};
331
332 // The first entry in the NT_FILE might be our executable
333 std::string executable_path = m_nt_file_entries[0].path;
334 // Prefer the NT_FILE entry matching m_executable_name as main executable.
335 for (const NT_FILE_Entry &file_entry : m_nt_file_entries)
336 if (llvm::StringRef(file_entry.path).ends_with("/" + m_executable_name)) {
337 executable_path = file_entry.path;
338 break;
339 }
340 return executable_path;
341}
342
343UUID ProcessElfCore::FindModuleUUID(const llvm::StringRef path) {
344 // Lookup the UUID for the given path in the map.
345 // Note that this could be called by multiple threads so make sure
346 // we access the map in a thread safe way (i.e. don't use operator[]).
347 auto it = m_uuids.find(std::string(path));
348 if (it != m_uuids.end())
349 return it->second;
350 return UUID();
351}
352
359
361 ThreadList &new_thread_list) {
362 const uint32_t num_threads = GetNumThreadContexts();
364 return false;
365
366 for (lldb::tid_t tid = 0; tid < num_threads; ++tid) {
367 const ThreadData &td = m_thread_data[tid];
368 lldb::ThreadSP thread_sp(new ThreadElfCore(*this, td));
369 new_thread_list.AddThread(thread_sp);
370 }
371 return new_thread_list.GetSize(false) > 0;
372}
373
375
377
378// Process Queries
379
380bool ProcessElfCore::IsAlive() { return true; }
381
382// Process Memory
383size_t ProcessElfCore::ReadMemory(lldb::addr_t addr, void *buf, size_t size,
384 Status &error) {
385 if (lldb::ABISP abi_sp = GetABI())
386 addr = abi_sp->FixAnyAddress(addr);
387
388 // Don't allow the caching that lldb_private::Process::ReadMemory does since
389 // in core files we have it all cached our our core file anyway.
390 return DoReadMemory(addr, buf, size, error);
391}
392
394 MemoryRegionInfo &region_info) {
395 region_info.Clear();
396 const VMRangeToPermissions::Entry *permission_entry =
397 m_core_range_infos.FindEntryThatContainsOrFollows(load_addr);
398 if (permission_entry) {
399 if (permission_entry->Contains(load_addr)) {
400 region_info.GetRange().SetRangeBase(permission_entry->GetRangeBase());
401 region_info.GetRange().SetRangeEnd(permission_entry->GetRangeEnd());
402 const Flags permissions(permission_entry->data);
403 region_info.SetReadable(permissions.Test(lldb::ePermissionsReadable)
406 region_info.SetWritable(permissions.Test(lldb::ePermissionsWritable)
409 region_info.SetExecutable(permissions.Test(lldb::ePermissionsExecutable)
413
414 // A region is memory tagged if there is a memory tag segment that covers
415 // the exact same range.
417 const VMRangeToFileOffset::Entry *tag_entry =
418 m_core_tag_ranges.FindEntryStartsAt(permission_entry->GetRangeBase());
419 if (tag_entry &&
420 tag_entry->GetRangeEnd() == permission_entry->GetRangeEnd())
422 } else if (load_addr < permission_entry->GetRangeBase()) {
423 region_info.GetRange().SetRangeBase(load_addr);
424 region_info.GetRange().SetRangeEnd(permission_entry->GetRangeBase());
428 region_info.SetMapped(MemoryRegionInfo::eNo);
430 }
431 return Status();
432 }
433
434 region_info.GetRange().SetRangeBase(load_addr);
439 region_info.SetMapped(MemoryRegionInfo::eNo);
441 return Status();
442}
443
444size_t ProcessElfCore::DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
445 Status &error) {
446 ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
447
448 if (core_objfile == nullptr)
449 return 0;
450
451 // Get the address range
452 const VMRangeToFileOffset::Entry *address_range =
453 m_core_aranges.FindEntryThatContains(addr);
454 if (address_range == nullptr || address_range->GetRangeEnd() < addr) {
456 "core file does not contain 0x%" PRIx64, addr);
457 return 0;
458 }
459
460 // Convert the address into core file offset
461 const lldb::addr_t offset = addr - address_range->GetRangeBase();
462 const lldb::addr_t file_start = address_range->data.GetRangeBase();
463 const lldb::addr_t file_end = address_range->data.GetRangeEnd();
464 size_t bytes_to_read = size; // Number of bytes to read from the core file
465 size_t bytes_copied = 0; // Number of bytes actually read from the core file
466 lldb::addr_t bytes_left =
467 0; // Number of bytes available in the core file from the given address
468
469 // Don't proceed if core file doesn't contain the actual data for this
470 // address range.
471 if (file_start == file_end)
472 return 0;
473
474 // Figure out how many on-disk bytes remain in this segment starting at the
475 // given offset
476 if (file_end > file_start + offset)
477 bytes_left = file_end - (file_start + offset);
478
479 if (bytes_to_read > bytes_left)
480 bytes_to_read = bytes_left;
481
482 // If there is data available on the core file read it
483 if (bytes_to_read)
484 bytes_copied =
485 core_objfile->CopyData(offset + file_start, bytes_to_read, buf);
486
487 return bytes_copied;
488}
489
490llvm::Expected<std::vector<lldb::addr_t>>
492 ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
493 if (core_objfile == nullptr)
494 return llvm::createStringError(llvm::inconvertibleErrorCode(),
495 "No core object file.");
496
497 llvm::Expected<const MemoryTagManager *> tag_manager_or_err =
499 if (!tag_manager_or_err)
500 return tag_manager_or_err.takeError();
501
502 // LLDB only supports AArch64 MTE tag segments so we do not need to worry
503 // about the segment type here. If you got here then you must have a tag
504 // manager (meaning you are debugging AArch64) and all the segments in this
505 // list will have had type PT_AARCH64_MEMTAG_MTE.
506 const VMRangeToFileOffset::Entry *tag_entry =
507 m_core_tag_ranges.FindEntryThatContains(addr);
508 // If we don't have a tag segment or the range asked for extends outside the
509 // segment.
510 if (!tag_entry || (addr + len) >= tag_entry->GetRangeEnd())
511 return llvm::createStringError(llvm::inconvertibleErrorCode(),
512 "No tag segment that covers this range.");
513
514 const MemoryTagManager *tag_manager = *tag_manager_or_err;
515 return tag_manager->UnpackTagsFromCoreFileSegment(
516 [core_objfile](lldb::offset_t offset, size_t length, void *dst) {
517 return core_objfile->CopyData(offset, length, dst);
518 },
519 tag_entry->GetRangeBase(), tag_entry->data.GetRangeBase(), addr, len);
520}
521
523 m_thread_list.Clear();
524
525 SetUnixSignals(std::make_shared<UnixSignals>());
526}
527
532
534 ObjectFile *obj_file = GetTarget().GetExecutableModule()->GetObjectFile();
535 Address addr = obj_file->GetImageInfoAddress(&GetTarget());
536
537 if (addr.IsValid())
538 return addr.GetLoadAddress(&GetTarget());
540}
541
542// Parse a FreeBSD NT_PRSTATUS note - see FreeBSD sys/procfs.h for details.
543static void ParseFreeBSDPrStatus(ThreadData &thread_data,
544 const DataExtractor &data,
545 bool lp64) {
546 lldb::offset_t offset = 0;
547 int pr_version = data.GetU32(&offset);
548
550 if (log) {
551 if (pr_version > 1)
552 LLDB_LOGF(log, "FreeBSD PRSTATUS unexpected version %d", pr_version);
553 }
554
555 // Skip padding, pr_statussz, pr_gregsetsz, pr_fpregsetsz, pr_osreldate
556 if (lp64)
557 offset += 32;
558 else
559 offset += 16;
560
561 thread_data.signo = data.GetU32(&offset); // pr_cursig
562 thread_data.tid = data.GetU32(&offset); // pr_pid
563 if (lp64)
564 offset += 4;
565
566 size_t len = data.GetByteSize() - offset;
567 thread_data.gpregset = DataExtractor(data, offset, len);
568}
569
570// Parse a FreeBSD NT_PRPSINFO note - see FreeBSD sys/procfs.h for details.
572 const DataExtractor &data,
573 bool lp64) {
574 lldb::offset_t offset = 0;
575 int pr_version = data.GetU32(&offset);
576
578 if (log) {
579 if (pr_version > 1)
580 LLDB_LOGF(log, "FreeBSD PRPSINFO unexpected version %d", pr_version);
581 }
582
583 // Skip pr_psinfosz, pr_fname, pr_psargs
584 offset += 108;
585 if (lp64)
586 offset += 4;
587
588 process.SetID(data.GetU32(&offset)); // pr_pid
589}
590
591static llvm::Error ParseNetBSDProcInfo(const DataExtractor &data,
592 uint32_t &cpi_nlwps,
593 uint32_t &cpi_signo,
594 uint32_t &cpi_siglwp,
595 uint32_t &cpi_pid) {
596 lldb::offset_t offset = 0;
597
598 uint32_t version = data.GetU32(&offset);
599 if (version != 1)
600 return llvm::createStringError(
601 "Error parsing NetBSD core(5) notes: Unsupported procinfo version");
602
603 uint32_t cpisize = data.GetU32(&offset);
604 if (cpisize != NETBSD::NT_PROCINFO_SIZE)
605 return llvm::createStringError(
606 "Error parsing NetBSD core(5) notes: Unsupported procinfo size");
607
608 cpi_signo = data.GetU32(&offset); /* killing signal */
609
615 cpi_pid = data.GetU32(&offset);
625 cpi_nlwps = data.GetU32(&offset); /* number of LWPs */
626
628 cpi_siglwp = data.GetU32(&offset); /* LWP target of killing signal */
629
630 return llvm::Error::success();
631}
632
633static void ParseOpenBSDProcInfo(ThreadData &thread_data,
634 const DataExtractor &data) {
635 lldb::offset_t offset = 0;
636
637 int version = data.GetU32(&offset);
638 if (version != 1)
639 return;
640
641 offset += 4;
642 thread_data.signo = data.GetU32(&offset);
643}
644
645llvm::Expected<std::vector<CoreNote>>
647 lldb::offset_t offset = 0;
648 std::vector<CoreNote> result;
649
650 while (offset < segment.GetByteSize()) {
651 ELFNote note = ELFNote();
652 if (!note.Parse(segment, &offset))
653 return llvm::createStringError("Unable to parse note segment");
654
655 size_t note_start = offset;
656 size_t note_size = llvm::alignTo(note.n_descsz, 4);
657
658 result.push_back({note, DataExtractor(segment, note_start, note_size)});
659 offset += note_size;
660 }
661
662 return std::move(result);
663}
664
665llvm::Error ProcessElfCore::parseFreeBSDNotes(llvm::ArrayRef<CoreNote> notes) {
666 ArchSpec arch = GetArchitecture();
667 bool lp64 = (arch.GetMachine() == llvm::Triple::aarch64 ||
668 arch.GetMachine() == llvm::Triple::ppc64 ||
669 arch.GetMachine() == llvm::Triple::x86_64);
670 bool have_prstatus = false;
671 bool have_prpsinfo = false;
672 ThreadData thread_data;
673 for (const auto &note : notes) {
674 if (note.info.n_name != "FreeBSD")
675 continue;
676
677 if ((note.info.n_type == ELF::NT_PRSTATUS && have_prstatus) ||
678 (note.info.n_type == ELF::NT_PRPSINFO && have_prpsinfo)) {
679 assert(thread_data.gpregset.GetByteSize() > 0);
680 // Add the new thread to thread list
681 m_thread_data.push_back(thread_data);
682 thread_data = ThreadData();
683 have_prstatus = false;
684 have_prpsinfo = false;
685 }
686
687 switch (note.info.n_type) {
688 case ELF::NT_PRSTATUS:
689 have_prstatus = true;
690 ParseFreeBSDPrStatus(thread_data, note.data, lp64);
691 break;
692 case ELF::NT_PRPSINFO:
693 have_prpsinfo = true;
694 ParseFreeBSDPrPsInfo(*this, note.data, lp64);
695 break;
696 case ELF::NT_FREEBSD_THRMISC: {
697 lldb::offset_t offset = 0;
698 thread_data.name = note.data.GetCStr(&offset, 20);
699 break;
700 }
701 case ELF::NT_FREEBSD_PROCSTAT_AUXV:
702 // FIXME: FreeBSD sticks an int at the beginning of the note
703 m_auxv = DataExtractor(note.data, 4, note.data.GetByteSize() - 4);
704 break;
705 default:
706 thread_data.notes.push_back(note);
707 break;
708 }
709 }
710 if (!have_prstatus) {
711 return llvm::createStringError(
712 "Could not find NT_PRSTATUS note in core file.");
713 }
714 m_thread_data.push_back(thread_data);
715 return llvm::Error::success();
716}
717
718/// NetBSD specific Thread context from PT_NOTE segment
719///
720/// NetBSD ELF core files use notes to provide information about
721/// the process's state. The note name is "NetBSD-CORE" for
722/// information that is global to the process, and "NetBSD-CORE@nn",
723/// where "nn" is the lwpid of the LWP that the information belongs
724/// to (such as register state).
725///
726/// NetBSD uses the following note identifiers:
727///
728/// ELF_NOTE_NETBSD_CORE_PROCINFO (value 1)
729/// Note is a "netbsd_elfcore_procinfo" structure.
730/// ELF_NOTE_NETBSD_CORE_AUXV (value 2; since NetBSD 8.0)
731/// Note is an array of AuxInfo structures.
732///
733/// NetBSD also uses ptrace(2) request numbers (the ones that exist in
734/// machine-dependent space) to identify register info notes. The
735/// info in such notes is in the same format that ptrace(2) would
736/// export that information.
737///
738/// For more information see /usr/include/sys/exec_elf.h
739///
740llvm::Error ProcessElfCore::parseNetBSDNotes(llvm::ArrayRef<CoreNote> notes) {
741 ThreadData thread_data;
742 bool had_nt_regs = false;
743
744 // To be extracted from struct netbsd_elfcore_procinfo
745 // Used to sanity check of the LWPs of the process
746 uint32_t nlwps = 0;
747 uint32_t signo = 0; // killing signal
748 uint32_t siglwp = 0; // LWP target of killing signal
749 uint32_t pr_pid = 0;
750
751 for (const auto &note : notes) {
752 llvm::StringRef name = note.info.n_name;
753
754 if (name == "NetBSD-CORE") {
755 if (note.info.n_type == NETBSD::NT_PROCINFO) {
756 llvm::Error error = ParseNetBSDProcInfo(note.data, nlwps, signo,
757 siglwp, pr_pid);
758 if (error)
759 return error;
760 SetID(pr_pid);
761 } else if (note.info.n_type == NETBSD::NT_AUXV) {
762 m_auxv = note.data;
763 }
764 } else if (name.consume_front("NetBSD-CORE@")) {
765 lldb::tid_t tid;
766 if (name.getAsInteger(10, tid))
767 return llvm::createStringError(
768 "Error parsing NetBSD core(5) notes: Cannot convert LWP ID "
769 "to integer");
770
771 switch (GetArchitecture().GetMachine()) {
772 case llvm::Triple::aarch64: {
773 // Assume order PT_GETREGS, PT_GETFPREGS
774 if (note.info.n_type == NETBSD::AARCH64::NT_REGS) {
775 // If this is the next thread, push the previous one first.
776 if (had_nt_regs) {
777 m_thread_data.push_back(thread_data);
778 thread_data = ThreadData();
779 had_nt_regs = false;
780 }
781
782 thread_data.gpregset = note.data;
783 thread_data.tid = tid;
784 if (thread_data.gpregset.GetByteSize() == 0)
785 return llvm::createStringError(
786 "Could not find general purpose registers note in core file.");
787 had_nt_regs = true;
788 } else if (note.info.n_type == NETBSD::AARCH64::NT_FPREGS) {
789 if (!had_nt_regs || tid != thread_data.tid)
790 return llvm::createStringError(
791 "Error parsing NetBSD core(5) notes: Unexpected order "
792 "of NOTEs PT_GETFPREG before PT_GETREG");
793 thread_data.notes.push_back(note);
794 }
795 } break;
796 case llvm::Triple::x86: {
797 // Assume order PT_GETREGS, PT_GETFPREGS
798 if (note.info.n_type == NETBSD::I386::NT_REGS) {
799 // If this is the next thread, push the previous one first.
800 if (had_nt_regs) {
801 m_thread_data.push_back(thread_data);
802 thread_data = ThreadData();
803 had_nt_regs = false;
804 }
805
806 thread_data.gpregset = note.data;
807 thread_data.tid = tid;
808 if (thread_data.gpregset.GetByteSize() == 0)
809 return llvm::createStringError(
810 "Could not find general purpose registers note in core file.");
811 had_nt_regs = true;
812 } else if (note.info.n_type == NETBSD::I386::NT_FPREGS) {
813 if (!had_nt_regs || tid != thread_data.tid)
814 return llvm::createStringError(
815 "Error parsing NetBSD core(5) notes: Unexpected order "
816 "of NOTEs PT_GETFPREG before PT_GETREG");
817 thread_data.notes.push_back(note);
818 }
819 } break;
820 case llvm::Triple::x86_64: {
821 // Assume order PT_GETREGS, PT_GETFPREGS
822 if (note.info.n_type == NETBSD::AMD64::NT_REGS) {
823 // If this is the next thread, push the previous one first.
824 if (had_nt_regs) {
825 m_thread_data.push_back(thread_data);
826 thread_data = ThreadData();
827 had_nt_regs = false;
828 }
829
830 thread_data.gpregset = note.data;
831 thread_data.tid = tid;
832 if (thread_data.gpregset.GetByteSize() == 0)
833 return llvm::createStringError(
834 "Could not find general purpose registers note in core file.");
835 had_nt_regs = true;
836 } else if (note.info.n_type == NETBSD::AMD64::NT_FPREGS) {
837 if (!had_nt_regs || tid != thread_data.tid)
838 return llvm::createStringError(
839 "Error parsing NetBSD core(5) notes: Unexpected order "
840 "of NOTEs PT_GETFPREG before PT_GETREG");
841 thread_data.notes.push_back(note);
842 }
843 } break;
844 default:
845 break;
846 }
847 }
848 }
849
850 // Push the last thread.
851 if (had_nt_regs)
852 m_thread_data.push_back(thread_data);
853
854 if (m_thread_data.empty())
855 return llvm::createStringError(
856 "Error parsing NetBSD core(5) notes: No threads information "
857 "specified in notes");
858
859 if (m_thread_data.size() != nlwps)
860 return llvm::createStringError(
861 "Error parsing NetBSD core(5) notes: Mismatch between the number "
862 "of LWPs in netbsd_elfcore_procinfo and the number of LWPs specified "
863 "by MD notes");
864
865 // Signal targeted at the whole process.
866 if (siglwp == 0) {
867 for (auto &data : m_thread_data)
868 data.signo = signo;
869 }
870 // Signal destined for a particular LWP.
871 else {
872 bool passed = false;
873
874 for (auto &data : m_thread_data) {
875 if (data.tid == siglwp) {
876 data.signo = signo;
877 passed = true;
878 break;
879 }
880 }
881
882 if (!passed)
883 return llvm::createStringError(
884 "Error parsing NetBSD core(5) notes: Signal passed to unknown LWP");
885 }
886
887 return llvm::Error::success();
888}
889
890llvm::Error ProcessElfCore::parseOpenBSDNotes(llvm::ArrayRef<CoreNote> notes) {
891 ThreadData thread_data = {};
892 for (const auto &note : notes) {
893 // OpenBSD per-thread information is stored in notes named "OpenBSD@nnn" so
894 // match on the initial part of the string.
895 if (!llvm::StringRef(note.info.n_name).starts_with("OpenBSD"))
896 continue;
897
898 switch (note.info.n_type) {
900 ParseOpenBSDProcInfo(thread_data, note.data);
901 break;
902 case OPENBSD::NT_AUXV:
903 m_auxv = note.data;
904 break;
905 case OPENBSD::NT_REGS:
906 thread_data.gpregset = note.data;
907 break;
908 default:
909 thread_data.notes.push_back(note);
910 break;
911 }
912 }
913 if (thread_data.gpregset.GetByteSize() == 0) {
914 return llvm::createStringError(
915 "Could not find general purpose registers note in core file.");
916 }
917 m_thread_data.push_back(thread_data);
918 return llvm::Error::success();
919}
920
921/// A description of a linux process usually contains the following NOTE
922/// entries:
923/// - NT_PRPSINFO - General process information like pid, uid, name, ...
924/// - NT_SIGINFO - Information about the signal that terminated the process
925/// - NT_AUXV - Process auxiliary vector
926/// - NT_FILE - Files mapped into memory
927///
928/// Additionally, for each thread in the process the core file will contain at
929/// least the NT_PRSTATUS note, containing the thread id and general purpose
930/// registers. It may include additional notes for other register sets (floating
931/// point and vector registers, ...). The tricky part here is that some of these
932/// notes have "CORE" in their owner fields, while other set it to "LINUX".
933llvm::Error ProcessElfCore::parseLinuxNotes(llvm::ArrayRef<CoreNote> notes) {
934 const ArchSpec &arch = GetArchitecture();
935 bool have_prstatus = false;
936 bool have_prpsinfo = false;
937 ThreadData thread_data;
938 for (const auto &note : notes) {
939 if (note.info.n_name != "CORE" && note.info.n_name != "LINUX")
940 continue;
941
942 if ((note.info.n_type == ELF::NT_PRSTATUS && have_prstatus) ||
943 (note.info.n_type == ELF::NT_PRPSINFO && have_prpsinfo)) {
944 assert(thread_data.gpregset.GetByteSize() > 0);
945 // Add the new thread to thread list
946 m_thread_data.push_back(thread_data);
947 thread_data = ThreadData();
948 have_prstatus = false;
949 have_prpsinfo = false;
950 }
951
952 switch (note.info.n_type) {
953 case ELF::NT_PRSTATUS: {
954 have_prstatus = true;
955 ELFLinuxPrStatus prstatus;
956 Status status = prstatus.Parse(note.data, arch);
957 if (status.Fail())
958 return status.ToError();
959 thread_data.prstatus_sig = prstatus.pr_cursig;
960 thread_data.tid = prstatus.pr_pid;
961 uint32_t header_size = ELFLinuxPrStatus::GetSize(arch);
962 size_t len = note.data.GetByteSize() - header_size;
963 thread_data.gpregset = DataExtractor(note.data, header_size, len);
964 break;
965 }
966 case ELF::NT_PRPSINFO: {
967 have_prpsinfo = true;
968 ELFLinuxPrPsInfo prpsinfo;
969 Status status = prpsinfo.Parse(note.data, arch);
970 if (status.Fail())
971 return status.ToError();
972 thread_data.name.assign (prpsinfo.pr_fname, strnlen (prpsinfo.pr_fname, sizeof (prpsinfo.pr_fname)));
973 SetID(prpsinfo.pr_pid);
974 m_executable_name = thread_data.name;
975 break;
976 }
977 case ELF::NT_SIGINFO: {
978 lldb::offset_t size = note.data.GetByteSize();
979 lldb::offset_t offset = 0;
980 const char *bytes =
981 static_cast<const char *>(note.data.GetData(&offset, size));
982 thread_data.siginfo_bytes = llvm::StringRef(bytes, size);
983 break;
984 }
985 case ELF::NT_FILE: {
986 m_nt_file_entries.clear();
987 lldb::offset_t offset = 0;
988 const uint64_t count = note.data.GetAddress(&offset);
989 note.data.GetAddress(&offset); // Skip page size
990 for (uint64_t i = 0; i < count; ++i) {
991 NT_FILE_Entry entry;
992 entry.start = note.data.GetAddress(&offset);
993 entry.end = note.data.GetAddress(&offset);
994 entry.file_ofs = note.data.GetAddress(&offset);
995 m_nt_file_entries.push_back(entry);
996 }
997 for (uint64_t i = 0; i < count; ++i) {
998 const char *path = note.data.GetCStr(&offset);
999 if (path && path[0])
1000 m_nt_file_entries[i].path.assign(path);
1001 }
1002 break;
1003 }
1004 case ELF::NT_AUXV:
1005 m_auxv = note.data;
1006 break;
1007 default:
1008 thread_data.notes.push_back(note);
1009 break;
1010 }
1011 }
1012 // Add last entry in the note section
1013 if (have_prstatus)
1014 m_thread_data.push_back(thread_data);
1015 return llvm::Error::success();
1016}
1017
1018/// Parse Thread context from PT_NOTE segment and store it in the thread list
1019/// A note segment consists of one or more NOTE entries, but their types and
1020/// meaning differ depending on the OS.
1022 const elf::ELFProgramHeader &segment_header,
1023 const DataExtractor &segment_data) {
1024 assert(segment_header.p_type == llvm::ELF::PT_NOTE);
1025
1026 auto notes_or_error = parseSegment(segment_data);
1027 if(!notes_or_error)
1028 return notes_or_error.takeError();
1029 switch (GetArchitecture().GetTriple().getOS()) {
1030 case llvm::Triple::FreeBSD:
1031 return parseFreeBSDNotes(*notes_or_error);
1032 case llvm::Triple::Linux:
1033 return parseLinuxNotes(*notes_or_error);
1034 case llvm::Triple::NetBSD:
1035 return parseNetBSDNotes(*notes_or_error);
1036 case llvm::Triple::OpenBSD:
1037 return parseOpenBSDNotes(*notes_or_error);
1038 default:
1039 return llvm::createStringError(
1040 "Don't know how to parse core file. Unsupported OS.");
1041 }
1042}
1043
1045 UUID invalid_uuid;
1046 const uint32_t addr_size = GetAddressByteSize();
1047 const size_t elf_header_size = addr_size == 4 ? sizeof(llvm::ELF::Elf32_Ehdr)
1048 : sizeof(llvm::ELF::Elf64_Ehdr);
1049
1050 std::vector<uint8_t> elf_header_bytes;
1051 elf_header_bytes.resize(elf_header_size);
1052 Status error;
1053 size_t byte_read =
1054 ReadMemory(address, elf_header_bytes.data(), elf_header_size, error);
1055 if (byte_read != elf_header_size ||
1056 !elf::ELFHeader::MagicBytesMatch(elf_header_bytes.data()))
1057 return invalid_uuid;
1058 DataExtractor elf_header_data(elf_header_bytes.data(), elf_header_size,
1059 GetByteOrder(), addr_size);
1060 lldb::offset_t offset = 0;
1061
1062 elf::ELFHeader elf_header;
1063 elf_header.Parse(elf_header_data, &offset);
1064
1065 const lldb::addr_t ph_addr = address + elf_header.e_phoff;
1066
1067 std::vector<uint8_t> ph_bytes;
1068 ph_bytes.resize(elf_header.e_phentsize);
1069 lldb::addr_t base_addr = 0;
1070 bool found_first_load_segment = false;
1071 for (unsigned int i = 0; i < elf_header.e_phnum; ++i) {
1072 byte_read = ReadMemory(ph_addr + i * elf_header.e_phentsize,
1073 ph_bytes.data(), elf_header.e_phentsize, error);
1074 if (byte_read != elf_header.e_phentsize)
1075 break;
1076 DataExtractor program_header_data(ph_bytes.data(), elf_header.e_phentsize,
1077 GetByteOrder(), addr_size);
1078 offset = 0;
1079 elf::ELFProgramHeader program_header;
1080 program_header.Parse(program_header_data, &offset);
1081 if (program_header.p_type == llvm::ELF::PT_LOAD &&
1082 !found_first_load_segment) {
1083 base_addr = program_header.p_vaddr;
1084 found_first_load_segment = true;
1085 }
1086 if (program_header.p_type != llvm::ELF::PT_NOTE)
1087 continue;
1088
1089 std::vector<uint8_t> note_bytes;
1090 note_bytes.resize(program_header.p_memsz);
1091
1092 // We need to slide the address of the p_vaddr as these values don't get
1093 // relocated in memory.
1094 const lldb::addr_t vaddr = program_header.p_vaddr + address - base_addr;
1095 byte_read =
1096 ReadMemory(vaddr, note_bytes.data(), program_header.p_memsz, error);
1097 if (byte_read != program_header.p_memsz)
1098 continue;
1099 DataExtractor segment_data(note_bytes.data(), note_bytes.size(),
1100 GetByteOrder(), addr_size);
1101 auto notes_or_error = parseSegment(segment_data);
1102 if (!notes_or_error) {
1103 llvm::consumeError(notes_or_error.takeError());
1104 return invalid_uuid;
1105 }
1106 for (const CoreNote &note : *notes_or_error) {
1107 if (note.info.n_namesz == 4 &&
1108 note.info.n_type == llvm::ELF::NT_GNU_BUILD_ID &&
1109 "GNU" == note.info.n_name &&
1110 note.data.ValidOffsetForDataOfSize(0, note.info.n_descsz))
1111 return UUID(note.data.GetData().take_front(note.info.n_descsz));
1112 }
1113 }
1114 return invalid_uuid;
1115}
1116
1119 DoLoadCore();
1120 return m_thread_data.size();
1121}
1122
1124 ArchSpec arch = m_core_module_sp->GetObjectFile()->GetArchitecture();
1125
1126 ArchSpec target_arch = GetTarget().GetArchitecture();
1127 arch.MergeFrom(target_arch);
1128
1129 // On MIPS there is no way to differentiate betwenn 32bit and 64bit core
1130 // files and this information can't be merged in from the target arch so we
1131 // fail back to unconditionally returning the target arch in this config.
1132 if (target_arch.IsMIPS()) {
1133 return target_arch;
1134 }
1135
1136 return arch;
1137}
1138
1140 assert(m_auxv.GetByteSize() == 0 ||
1141 (m_auxv.GetByteOrder() == GetByteOrder() &&
1142 m_auxv.GetAddressByteSize() == GetAddressByteSize()));
1143 return DataExtractor(m_auxv);
1144}
1145
1147 info.Clear();
1148 info.SetProcessID(GetID());
1151 if (module_sp) {
1152 const bool add_exe_file_as_first_arg = false;
1153 info.SetExecutableFile(GetTarget().GetExecutableModule()->GetFileSpec(),
1154 add_exe_file_as_first_arg);
1155 }
1156 return true;
1157}
static llvm::raw_ostream & error(Stream &strm)
static llvm::raw_ostream & note(Stream &strm)
#define LLDB_LOGF(log,...)
Definition Log.h:376
#define LLDB_PLUGIN_DEFINE(PluginName)
static void ParseOpenBSDProcInfo(ThreadData &thread_data, const DataExtractor &data)
static void ParseFreeBSDPrPsInfo(ProcessElfCore &process, const DataExtractor &data, bool lp64)
static void ParseFreeBSDPrStatus(ThreadData &thread_data, const DataExtractor &data, bool lp64)
static llvm::Error ParseNetBSDProcInfo(const DataExtractor &data, uint32_t &cpi_nlwps, uint32_t &cpi_signo, uint32_t &cpi_siglwp, uint32_t &cpi_pid)
@ AUXV_AT_EXECFN
Filename of executable.
Definition AuxVector.h:61
std::optional< uint64_t > GetAuxValue(enum EntryType entry_type) const
Definition AuxVector.cpp:34
static llvm::StringRef GetPluginNameStatic()
Generic COFF object file reader.
lldb_private::DataExtractor GetSegmentData(const elf::ELFProgramHeader &H)
llvm::ArrayRef< elf::ELFProgramHeader > ProgramHeaders()
std::vector< NT_FILE_Entry > m_nt_file_entries
lldb_private::UUID FindModuleUUID(const llvm::StringRef path) override
lldb::addr_t GetImageInfoAddress() override
Get the image information address for the current process.
lldb::addr_t AddAddressRangeFromMemoryTagSegment(const elf::ELFProgramHeader &header)
lldb_private::DataExtractor m_auxv
llvm::Error parseLinuxNotes(llvm::ArrayRef< lldb_private::CoreNote > notes)
A description of a linux process usually contains the following NOTE entries:
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 ...
void UpdateBuildIdForNTFileEntries()
std::string GetMainExecutablePath()
std::vector< ThreadData > m_thread_data
lldb_private::Range< lldb::addr_t, lldb::addr_t > FileRange
static void Initialize()
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.
size_t ReadMemory(lldb::addr_t addr, void *buf, size_t size, lldb_private::Status &error) override
Read of memory from a process.
VMRangeToPermissions m_core_range_infos
static llvm::StringRef GetPluginDescriptionStatic()
std::unordered_map< std::string, lldb_private::UUID > m_uuids
llvm::Expected< std::vector< lldb_private::CoreNote > > parseSegment(const lldb_private::DataExtractor &segment)
lldb::addr_t AddAddressRangeFromLoadSegment(const elf::ELFProgramHeader &header)
~ProcessElfCore() override
llvm::Error parseFreeBSDNotes(llvm::ArrayRef< lldb_private::CoreNote > notes)
lldb_private::UUID FindBuidIdInCoreMemory(lldb::addr_t address)
VMRangeToFileOffset m_core_aranges
lldb_private::Status DoGetMemoryRegionInfo(lldb::addr_t load_addr, lldb_private::MemoryRegionInfo &region_info) override
DoGetMemoryRegionInfo is called by GetMemoryRegionInfo after it has removed non address bits from loa...
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.
VMRangeToFileOffset m_core_tag_ranges
llvm::Error parseNetBSDNotes(llvm::ArrayRef< lldb_private::CoreNote > notes)
NetBSD specific Thread context from PT_NOTE segment.
lldb_private::Status DoLoadCore() override
static void Terminate()
ProcessElfCore(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, const lldb_private::FileSpec &core_file)
lldb_private::DynamicLoader * GetDynamicLoader() override
Get the dynamic loader plug-in for this process.
llvm::Expected< std::vector< lldb::addr_t > > ReadMemoryTags(lldb::addr_t addr, size_t len) override
Read memory tags for the range addr to addr+len.
lldb_private::DataExtractor GetAuxvData() override
bool IsAlive() override
Check if a process is still alive.
uint32_t GetNumThreadContexts()
std::string m_executable_name
static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, const lldb_private::FileSpec *crash_file_path, bool can_connect)
llvm::Error parseOpenBSDNotes(llvm::ArrayRef< lldb_private::CoreNote > notes)
void RefreshStateAfterStop() override
Currently called as part of ShouldStop.
lldb_private::ArchSpec GetArchitecture()
bool CanDebug(lldb::TargetSP target_sp, bool plugin_specified_by_name) override
Check if a plug-in instance can debug the file in module.
bool GetProcessInfo(lldb_private::ProcessInstanceInfo &info) override
static llvm::StringRef GetPluginNameStatic()
lldb::ModuleSP m_core_module_sp
lldb_private::Status DoDestroy() override
A section + offset based address class.
Definition Address.h:62
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition Address.cpp:301
bool IsValid() const
Check if the object state is valid.
Definition Address.h:355
An architecture specification class.
Definition ArchSpec.h:32
void MergeFrom(const ArchSpec &other)
Merges fields from another ArchSpec into this ArchSpec.
Definition ArchSpec.cpp:801
bool IsMIPS() const
if MIPS architecture return true.
Definition ArchSpec.cpp:555
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition ArchSpec.cpp:673
An data extractor class.
virtual uint64_t GetByteSize() const
Get the number of bytes contained in this object.
uint32_t GetU32(lldb::offset_t *offset_ptr) const
Extract a uint32_t value from *offset_ptr.
A plug-in interface definition class for dynamic loaders.
static DynamicLoader * FindPlugin(Process *process, llvm::StringRef plugin_name)
Find a dynamic loader plugin for a given process.
A file utility class.
Definition FileSpec.h:57
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
Definition FileSpec.cpp:174
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition FileSpec.cpp:374
static FileSystem & Instance()
std::shared_ptr< DataBuffer > CreateDataBuffer(const llvm::Twine &path, uint64_t size=0, uint64_t offset=0)
Create memory buffer from path.
A class to manage flags.
Definition Flags.h:22
bool Test(ValueType bit) const
Test a single flag bit.
Definition Flags.h:96
void SetMapped(OptionalBool val)
void SetMemoryTagged(OptionalBool val)
void SetReadable(OptionalBool val)
void SetExecutable(OptionalBool val)
void SetWritable(OptionalBool val)
virtual llvm::Expected< std::vector< lldb::addr_t > > UnpackTagsFromCoreFileSegment(CoreReaderFn reader, lldb::addr_t tag_segment_virtual_address, lldb::addr_t tag_segment_data_address, lldb::addr_t addr, size_t len) const =0
static Status GetSharedModule(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr, bool invoke_locate_callback=true)
FileSpec & GetFileSpec()
Definition ModuleSpec.h:57
ArchSpec & GetArchitecture()
Definition ModuleSpec.h:93
void SetTarget(lldb::TargetSP target)
Set the target to be used when resolving a module.
Definition ModuleSpec.h:141
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:46
virtual lldb_private::Address GetImageInfoAddress(Target *target)
Similar to Process::GetImageInfoAddress().
Definition ObjectFile.h:444
@ eTypeCoreFile
A core file that has a checkpoint of a program's execution state.
Definition ObjectFile.h:53
size_t CopyData(lldb::offset_t offset, size_t length, void *dst) const
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
PostMortemProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, const FileSpec &core_file)
void SetExecutableFile(const FileSpec &exe_file, bool add_exe_file_as_first_arg)
void SetArchitecture(const ArchSpec &arch)
Definition ProcessInfo.h:66
void SetProcessID(lldb::pid_t pid)
Definition ProcessInfo.h:70
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:537
void SetUnixSignals(lldb::UnixSignalsSP &&signals_sp)
Definition Process.cpp:3711
size_t ReadCStringFromMemory(lldb::addr_t vm_addr, char *cstr, size_t cstr_max_len, Status &error)
Read a NULL terminated C string from memory.
Definition Process.cpp:2193
void SetCanJIT(bool can_jit)
Sets whether executing JIT-compiled code in this process is possible.
Definition Process.cpp:2562
lldb::DynamicLoaderUP m_dyld_up
Definition Process.h:3407
llvm::Expected< const MemoryTagManager * > GetMemoryTagManager()
If this architecture and process supports memory tagging, return a tag manager that can be used to ma...
Definition Process.cpp:6588
lldb::ByteOrder GetByteOrder() const
Definition Process.cpp:3721
llvm::Expected< lldb::ModuleSP > ReadModuleFromMemory(const FileSpec &file_spec, lldb::addr_t header_addr, size_t size_to_read=512)
Creates and populates a module using an in-memory object file.
Definition Process.cpp:2599
void SetID(lldb::pid_t new_pid)
Sets the stored pid.
Definition Process.h:542
uint32_t GetAddressByteSize() const
Definition Process.cpp:3725
virtual void Finalize(bool destructing)
This object is about to be destroyed, do any necessary cleanup.
Definition Process.cpp:537
ThreadList m_thread_list
The threads for this process as the user will see them.
Definition Process.h:3380
const lldb::UnixSignalsSP & GetUnixSignals()
Definition Process.cpp:3716
const lldb::ABISP & GetABI()
Definition Process.cpp:1457
friend class ThreadList
Definition Process.h:361
Target & GetTarget()
Get the target object pointer for this module.
Definition Process.h:1250
RangeData< lldb::addr_t, lldb::addr_t, FileRange > Entry
Definition RangeMap.h:462
An error handling class.
Definition Status.h:118
llvm::Error ToError() const
FIXME: Replace all uses with takeError() instead.
Definition Status.cpp:138
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
static Status FromErrorString(const char *str)
Definition Status.h:141
bool Fail() const
Test for error condition.
Definition Status.cpp:293
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
Definition Status.cpp:136
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:2352
bool SetArchitecture(const ArchSpec &arch_spec, bool set_platform=false, bool merge=true)
Set the architecture for this target.
Definition Target.cpp:1705
lldb::ModuleSP GetExecutableModule()
Gets the module for the main executable.
Definition Target.cpp:1525
const ArchSpec & GetArchitecture() const
Definition Target.h:1183
void SetExecutableModule(lldb::ModuleSP &module_sp, LoadDependentFiles load_dependent_files=eLoadDependentsDefault)
Set the main executable module.
Definition Target.cpp:1576
void AddThread(const lldb::ThreadSP &thread_sp)
uint32_t GetSize(bool can_update=true)
Represents UUID's of various sizes.
Definition UUID.h:27
std::string GetAsString(llvm::StringRef separator="-") const
Definition UUID.cpp:54
bool IsValid() const
Definition UUID.h:69
static lldb::UnixSignalsSP Create(const ArchSpec &arch)
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:332
std::shared_ptr< lldb_private::ABI > ABISP
std::shared_ptr< lldb_private::Thread > ThreadSP
uint64_t offset_t
Definition lldb-types.h:85
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::Listener > ListenerSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
uint64_t tid_t
Definition lldb-types.h:84
std::shared_ptr< lldb_private::Module > ModuleSP
lldb_private::Status Parse(const lldb_private::DataExtractor &data, const lldb_private::ArchSpec &arch)
static size_t GetSize(const lldb_private::ArchSpec &arch)
lldb_private::Status Parse(const lldb_private::DataExtractor &data, const lldb_private::ArchSpec &arch)
lldb::addr_t file_ofs
lldb::addr_t end
lldb::addr_t start
llvm::StringRef siginfo_bytes
lldb::tid_t tid
std::string name
lldb_private::DataExtractor gpregset
std::vector< lldb_private::CoreNote > notes
Generic representation of an ELF file header.
Definition ELFHeader.h:56
elf_off e_phoff
File offset of program header table.
Definition ELFHeader.h:59
elf_half e_phentsize
Size of a program header table entry.
Definition ELFHeader.h:66
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...
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...
elf_word e_phnum
Number of program header entries.
Definition ELFHeader.h:75
elf_word e_version
Version of object file (always 1).
Definition ELFHeader.h:62
unsigned char e_ident[llvm::ELF::EI_NIDENT]
ELF file identification.
Definition ELFHeader.h:57
elf_half e_type
Object file type.
Definition ELFHeader.h:63
Generic representation of an ELF program header.
Definition ELFHeader.h:192
bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset)
Parse an ELFProgramHeader entry from the given DataExtractor starting at position offset.
elf_word p_flags
Segment attributes.
Definition ELFHeader.h:194
elf_xword p_filesz
Byte size of the segment in file.
Definition ELFHeader.h:198
elf_off p_offset
Start of segment from beginning of file.
Definition ELFHeader.h:195
elf_addr p_vaddr
Virtual address of segment in memory.
Definition ELFHeader.h:196
elf_xword p_memsz
Byte size of the segment in memory.
Definition ELFHeader.h:199
elf_word p_type
Type of program segment.
Definition ELFHeader.h:193
bool Contains(BaseType r) const
Definition RangeMap.h:93
BaseType GetRangeBase() const
Definition RangeMap.h:45
void SetRangeEnd(BaseType end)
Definition RangeMap.h:80
SizeType GetByteSize() const
Definition RangeMap.h:87
void SetRangeBase(BaseType b)
Set the start value for the range, and keep the same size.
Definition RangeMap.h:48
BaseType GetRangeEnd() const
Definition RangeMap.h:78