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