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 LLDB_LOGF(log, "%s found UUID @ %16.16" PRIx64 ": %s \"%s\"",
310 __FUNCTION__, entry.start, uuid.GetAsString().c_str(),
311 entry.path.c_str());
312 }
313 }
314}
315
317 // Always try to read the program name from core file memory first via the
318 // AUXV_AT_EXECFN entry. This value is the address of a null terminated C
319 // string that contains the program path.
320 AuxVector aux_vector(m_auxv);
321 std::string execfn_str;
322 if (auto execfn = aux_vector.GetAuxValue(AuxVector::AUXV_AT_EXECFN)) {
324 if (ReadCStringFromMemory(*execfn, execfn_str, error))
325 return execfn_str;
326 }
327
328 if (m_nt_file_entries.empty())
329 return {};
330
331 // The first entry in the NT_FILE might be our executable
332 std::string executable_path = m_nt_file_entries[0].path;
333 // Prefer the NT_FILE entry matching m_executable_name as main executable.
334 for (const NT_FILE_Entry &file_entry : m_nt_file_entries)
335 if (llvm::StringRef(file_entry.path).ends_with("/" + m_executable_name)) {
336 executable_path = file_entry.path;
337 break;
338 }
339 return executable_path;
340}
341
342UUID ProcessElfCore::FindModuleUUID(const llvm::StringRef path) {
343 // Lookup the UUID for the given path in the map.
344 // Note that this could be called by multiple threads so make sure
345 // we access the map in a thread safe way (i.e. don't use operator[]).
346 auto it = m_uuids.find(std::string(path));
347 if (it != m_uuids.end())
348 return it->second;
349 return UUID();
350}
351
358
360 ThreadList &new_thread_list) {
361 const uint32_t num_threads = GetNumThreadContexts();
363 return false;
364
365 for (lldb::tid_t tid = 0; tid < num_threads; ++tid) {
366 const ThreadData &td = m_thread_data[tid];
367 lldb::ThreadSP thread_sp(new ThreadElfCore(*this, td));
368 new_thread_list.AddThread(thread_sp);
369 }
370 return new_thread_list.GetSize(false) > 0;
371}
372
374
376
377// Process Queries
378
379bool ProcessElfCore::IsAlive() { return true; }
380
381// Process Memory
382size_t ProcessElfCore::ReadMemory(lldb::addr_t addr, void *buf, size_t size,
383 Status &error) {
384 if (lldb::ABISP abi_sp = GetABI())
385 addr = abi_sp->FixAnyAddress(addr);
386
387 // Don't allow the caching that lldb_private::Process::ReadMemory does since
388 // in core files we have it all cached our our core file anyway.
389 return DoReadMemory(addr, buf, size, error);
390}
391
393 MemoryRegionInfo &region_info) {
394 region_info.Clear();
395 const VMRangeToPermissions::Entry *permission_entry =
396 m_core_range_infos.FindEntryThatContainsOrFollows(load_addr);
397 if (permission_entry) {
398 if (permission_entry->Contains(load_addr)) {
399 region_info.GetRange().SetRangeBase(permission_entry->GetRangeBase());
400 region_info.GetRange().SetRangeEnd(permission_entry->GetRangeEnd());
401 const Flags permissions(permission_entry->data);
402 region_info.SetReadable(permissions.Test(lldb::ePermissionsReadable)
404 : eLazyBoolNo);
405 region_info.SetWritable(permissions.Test(lldb::ePermissionsWritable)
407 : eLazyBoolNo);
408 region_info.SetExecutable(permissions.Test(lldb::ePermissionsExecutable)
410 : eLazyBoolNo);
411 region_info.SetMapped(eLazyBoolYes);
412
413 // A region is memory tagged if there is a memory tag segment that covers
414 // the exact same range.
415 region_info.SetMemoryTagged(eLazyBoolNo);
416 const VMRangeToFileOffset::Entry *tag_entry =
417 m_core_tag_ranges.FindEntryStartsAt(permission_entry->GetRangeBase());
418 if (tag_entry &&
419 tag_entry->GetRangeEnd() == permission_entry->GetRangeEnd())
420 region_info.SetMemoryTagged(eLazyBoolYes);
421 } else if (load_addr < permission_entry->GetRangeBase()) {
422 region_info.GetRange().SetRangeBase(load_addr);
423 region_info.GetRange().SetRangeEnd(permission_entry->GetRangeBase());
424 region_info.SetReadable(eLazyBoolNo);
425 region_info.SetWritable(eLazyBoolNo);
426 region_info.SetExecutable(eLazyBoolNo);
427 region_info.SetMapped(eLazyBoolNo);
428 region_info.SetMemoryTagged(eLazyBoolNo);
429 }
430 return Status();
431 }
432
433 region_info.GetRange().SetRangeBase(load_addr);
435 region_info.SetReadable(eLazyBoolNo);
436 region_info.SetWritable(eLazyBoolNo);
437 region_info.SetExecutable(eLazyBoolNo);
438 region_info.SetMapped(eLazyBoolNo);
439 region_info.SetMemoryTagged(eLazyBoolNo);
440 return Status();
441}
442
443size_t ProcessElfCore::DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
444 Status &error) {
445 ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
446
447 if (core_objfile == nullptr)
448 return 0;
449
450 // Get the address range
451 const VMRangeToFileOffset::Entry *address_range =
452 m_core_aranges.FindEntryThatContains(addr);
453 if (address_range == nullptr || address_range->GetRangeEnd() < addr) {
455 "core file does not contain 0x%" PRIx64, addr);
456 return 0;
457 }
458
459 // Convert the address into core file offset
460 const lldb::addr_t offset = addr - address_range->GetRangeBase();
461 const lldb::addr_t file_start = address_range->data.GetRangeBase();
462 const lldb::addr_t file_end = address_range->data.GetRangeEnd();
463 size_t bytes_to_read = size; // Number of bytes to read from the core file
464 size_t bytes_copied = 0; // Number of bytes actually read from the core file
465 lldb::addr_t bytes_left =
466 0; // Number of bytes available in the core file from the given address
467
468 // Don't proceed if core file doesn't contain the actual data for this
469 // address range.
470 if (file_start == file_end)
471 return 0;
472
473 // Figure out how many on-disk bytes remain in this segment starting at the
474 // given offset
475 if (file_end > file_start + offset)
476 bytes_left = file_end - (file_start + offset);
477
478 if (bytes_to_read > bytes_left)
479 bytes_to_read = bytes_left;
480
481 // If there is data available on the core file read it
482 if (bytes_to_read)
483 bytes_copied =
484 core_objfile->CopyData(offset + file_start, bytes_to_read, buf);
485
486 return bytes_copied;
487}
488
489llvm::Expected<std::vector<lldb::addr_t>>
491 ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
492 if (core_objfile == nullptr)
493 return llvm::createStringError(llvm::inconvertibleErrorCode(),
494 "No core object file.");
495
496 llvm::Expected<const MemoryTagManager *> tag_manager_or_err =
498 if (!tag_manager_or_err)
499 return tag_manager_or_err.takeError();
500
501 // LLDB only supports AArch64 MTE tag segments so we do not need to worry
502 // about the segment type here. If you got here then you must have a tag
503 // manager (meaning you are debugging AArch64) and all the segments in this
504 // list will have had type PT_AARCH64_MEMTAG_MTE.
505 const VMRangeToFileOffset::Entry *tag_entry =
506 m_core_tag_ranges.FindEntryThatContains(addr);
507 // If we don't have a tag segment or the range asked for extends outside the
508 // segment.
509 if (!tag_entry || (addr + len) >= tag_entry->GetRangeEnd())
510 return llvm::createStringError(llvm::inconvertibleErrorCode(),
511 "No tag segment that covers this range.");
512
513 const MemoryTagManager *tag_manager = *tag_manager_or_err;
514 return tag_manager->UnpackTagsFromCoreFileSegment(
515 [core_objfile](lldb::offset_t offset, size_t length, void *dst) {
516 return core_objfile->CopyData(offset, length, dst);
517 },
518 tag_entry->GetRangeBase(), tag_entry->data.GetRangeBase(), addr, len);
519}
520
522 m_thread_list.Clear();
523
524 SetUnixSignals(std::make_shared<UnixSignals>());
525}
526
531
533 ObjectFile *obj_file = GetTarget().GetExecutableModule()->GetObjectFile();
534 Address addr = obj_file->GetImageInfoAddress(&GetTarget());
535
536 if (addr.IsValid())
537 return addr.GetLoadAddress(&GetTarget());
539}
540
541// Parse a FreeBSD NT_PRSTATUS note - see FreeBSD sys/procfs.h for details.
542static void ParseFreeBSDPrStatus(ThreadData &thread_data,
543 const DataExtractor &data,
544 bool lp64) {
545 lldb::offset_t offset = 0;
546 int pr_version = data.GetU32(&offset);
547
549 if (pr_version > 1)
550 LLDB_LOGF(log, "FreeBSD PRSTATUS unexpected version %d", pr_version);
551
552 // Skip padding, pr_statussz, pr_gregsetsz, pr_fpregsetsz, pr_osreldate
553 if (lp64)
554 offset += 32;
555 else
556 offset += 16;
557
558 thread_data.signo = data.GetU32(&offset); // pr_cursig
559 thread_data.tid = data.GetU32(&offset); // pr_pid
560 if (lp64)
561 offset += 4;
562
563 size_t len = data.GetByteSize() - offset;
564 thread_data.gpregset = DataExtractor(data, offset, len);
565}
566
567// Parse a FreeBSD NT_PRPSINFO note - see FreeBSD sys/procfs.h for details.
569 const DataExtractor &data,
570 bool lp64) {
571 lldb::offset_t offset = 0;
572 int pr_version = data.GetU32(&offset);
573
575 if (pr_version > 1)
576 LLDB_LOGF(log, "FreeBSD PRPSINFO unexpected version %d", pr_version);
577
578 // Skip pr_psinfosz, pr_fname, pr_psargs
579 offset += 108;
580 if (lp64)
581 offset += 4;
582
583 process.SetID(data.GetU32(&offset)); // pr_pid
584}
585
586static llvm::Error ParseNetBSDProcInfo(const DataExtractor &data,
587 uint32_t &cpi_nlwps,
588 uint32_t &cpi_signo,
589 uint32_t &cpi_siglwp,
590 uint32_t &cpi_pid) {
591 lldb::offset_t offset = 0;
592
593 uint32_t version = data.GetU32(&offset);
594 if (version != 1)
595 return llvm::createStringError(
596 "Error parsing NetBSD core(5) notes: Unsupported procinfo version");
597
598 uint32_t cpisize = data.GetU32(&offset);
599 if (cpisize != NETBSD::NT_PROCINFO_SIZE)
600 return llvm::createStringError(
601 "Error parsing NetBSD core(5) notes: Unsupported procinfo size");
602
603 cpi_signo = data.GetU32(&offset); /* killing signal */
604
610 cpi_pid = data.GetU32(&offset);
620 cpi_nlwps = data.GetU32(&offset); /* number of LWPs */
621
623 cpi_siglwp = data.GetU32(&offset); /* LWP target of killing signal */
624
625 return llvm::Error::success();
626}
627
628static void ParseOpenBSDProcInfo(ThreadData &thread_data,
629 const DataExtractor &data) {
630 lldb::offset_t offset = 0;
631
632 int version = data.GetU32(&offset);
633 if (version != 1)
634 return;
635
636 offset += 4;
637 thread_data.signo = data.GetU32(&offset);
638}
639
640llvm::Expected<std::vector<CoreNote>>
642 lldb::offset_t offset = 0;
643 std::vector<CoreNote> result;
644
645 while (offset < segment.GetByteSize()) {
646 ELFNote note = ELFNote();
647 if (!note.Parse(segment, &offset))
648 return llvm::createStringError("Unable to parse note segment");
649
650 size_t note_start = offset;
651 size_t note_size = llvm::alignTo(note.n_descsz, 4);
652
653 result.push_back({note, DataExtractor(segment, note_start, note_size)});
654 offset += note_size;
655 }
656
657 return std::move(result);
658}
659
660llvm::Error ProcessElfCore::parseFreeBSDNotes(llvm::ArrayRef<CoreNote> notes) {
661 ArchSpec arch = GetArchitecture();
662 bool lp64 = (arch.GetMachine() == llvm::Triple::aarch64 ||
663 arch.GetMachine() == llvm::Triple::ppc64 ||
664 arch.GetMachine() == llvm::Triple::x86_64);
665 bool have_prstatus = false;
666 bool have_prpsinfo = false;
667 ThreadData thread_data;
668 for (const auto &note : notes) {
669 if (note.info.n_name != "FreeBSD")
670 continue;
671
672 if ((note.info.n_type == ELF::NT_PRSTATUS && have_prstatus) ||
673 (note.info.n_type == ELF::NT_PRPSINFO && have_prpsinfo)) {
674 assert(thread_data.gpregset.GetByteSize() > 0);
675 // Add the new thread to thread list
676 m_thread_data.push_back(thread_data);
677 thread_data = ThreadData();
678 have_prstatus = false;
679 have_prpsinfo = false;
680 }
681
682 switch (note.info.n_type) {
683 case ELF::NT_PRSTATUS:
684 have_prstatus = true;
685 ParseFreeBSDPrStatus(thread_data, note.data, lp64);
686 break;
687 case ELF::NT_PRPSINFO:
688 have_prpsinfo = true;
689 ParseFreeBSDPrPsInfo(*this, note.data, lp64);
690 break;
691 case ELF::NT_FREEBSD_THRMISC: {
692 lldb::offset_t offset = 0;
693 thread_data.name = note.data.GetCStr(&offset, 20);
694 break;
695 }
696 case ELF::NT_FREEBSD_PROCSTAT_AUXV:
697 // FIXME: FreeBSD sticks an int at the beginning of the note
698 m_auxv = DataExtractor(note.data, 4, note.data.GetByteSize() - 4);
699 break;
700 default:
701 thread_data.notes.push_back(note);
702 break;
703 }
704 }
705 if (!have_prstatus) {
706 return llvm::createStringError(
707 "Could not find NT_PRSTATUS note in core file.");
708 }
709 m_thread_data.push_back(thread_data);
710 return llvm::Error::success();
711}
712
713/// NetBSD specific Thread context from PT_NOTE segment
714///
715/// NetBSD ELF core files use notes to provide information about
716/// the process's state. The note name is "NetBSD-CORE" for
717/// information that is global to the process, and "NetBSD-CORE@nn",
718/// where "nn" is the lwpid of the LWP that the information belongs
719/// to (such as register state).
720///
721/// NetBSD uses the following note identifiers:
722///
723/// ELF_NOTE_NETBSD_CORE_PROCINFO (value 1)
724/// Note is a "netbsd_elfcore_procinfo" structure.
725/// ELF_NOTE_NETBSD_CORE_AUXV (value 2; since NetBSD 8.0)
726/// Note is an array of AuxInfo structures.
727///
728/// NetBSD also uses ptrace(2) request numbers (the ones that exist in
729/// machine-dependent space) to identify register info notes. The
730/// info in such notes is in the same format that ptrace(2) would
731/// export that information.
732///
733/// For more information see /usr/include/sys/exec_elf.h
734///
735llvm::Error ProcessElfCore::parseNetBSDNotes(llvm::ArrayRef<CoreNote> notes) {
736 ThreadData thread_data;
737 bool had_nt_regs = false;
738
739 // To be extracted from struct netbsd_elfcore_procinfo
740 // Used to sanity check of the LWPs of the process
741 uint32_t nlwps = 0;
742 uint32_t signo = 0; // killing signal
743 uint32_t siglwp = 0; // LWP target of killing signal
744 uint32_t pr_pid = 0;
745
746 for (const auto &note : notes) {
747 llvm::StringRef name = note.info.n_name;
748
749 if (name == "NetBSD-CORE") {
750 if (note.info.n_type == NETBSD::NT_PROCINFO) {
751 llvm::Error error = ParseNetBSDProcInfo(note.data, nlwps, signo,
752 siglwp, pr_pid);
753 if (error)
754 return error;
755 SetID(pr_pid);
756 } else if (note.info.n_type == NETBSD::NT_AUXV) {
757 m_auxv = note.data;
758 }
759 } else if (name.consume_front("NetBSD-CORE@")) {
760 lldb::tid_t tid;
761 if (name.getAsInteger(10, tid))
762 return llvm::createStringError(
763 "Error parsing NetBSD core(5) notes: Cannot convert LWP ID "
764 "to integer");
765
766 switch (GetArchitecture().GetMachine()) {
767 case llvm::Triple::aarch64: {
768 // Assume order PT_GETREGS, PT_GETFPREGS
769 if (note.info.n_type == NETBSD::AARCH64::NT_REGS) {
770 // If this is the next thread, push the previous one first.
771 if (had_nt_regs) {
772 m_thread_data.push_back(thread_data);
773 thread_data = ThreadData();
774 had_nt_regs = false;
775 }
776
777 thread_data.gpregset = note.data;
778 thread_data.tid = tid;
779 if (thread_data.gpregset.GetByteSize() == 0)
780 return llvm::createStringError(
781 "Could not find general purpose registers note in core file.");
782 had_nt_regs = true;
783 } else if (note.info.n_type == NETBSD::AARCH64::NT_FPREGS) {
784 if (!had_nt_regs || tid != thread_data.tid)
785 return llvm::createStringError(
786 "Error parsing NetBSD core(5) notes: Unexpected order "
787 "of NOTEs PT_GETFPREG before PT_GETREG");
788 thread_data.notes.push_back(note);
789 }
790 } break;
791 case llvm::Triple::x86: {
792 // Assume order PT_GETREGS, PT_GETFPREGS
793 if (note.info.n_type == NETBSD::I386::NT_REGS) {
794 // If this is the next thread, push the previous one first.
795 if (had_nt_regs) {
796 m_thread_data.push_back(thread_data);
797 thread_data = ThreadData();
798 had_nt_regs = false;
799 }
800
801 thread_data.gpregset = note.data;
802 thread_data.tid = tid;
803 if (thread_data.gpregset.GetByteSize() == 0)
804 return llvm::createStringError(
805 "Could not find general purpose registers note in core file.");
806 had_nt_regs = true;
807 } else if (note.info.n_type == NETBSD::I386::NT_FPREGS) {
808 if (!had_nt_regs || tid != thread_data.tid)
809 return llvm::createStringError(
810 "Error parsing NetBSD core(5) notes: Unexpected order "
811 "of NOTEs PT_GETFPREG before PT_GETREG");
812 thread_data.notes.push_back(note);
813 }
814 } break;
815 case llvm::Triple::x86_64: {
816 // Assume order PT_GETREGS, PT_GETFPREGS
817 if (note.info.n_type == NETBSD::AMD64::NT_REGS) {
818 // If this is the next thread, push the previous one first.
819 if (had_nt_regs) {
820 m_thread_data.push_back(thread_data);
821 thread_data = ThreadData();
822 had_nt_regs = false;
823 }
824
825 thread_data.gpregset = note.data;
826 thread_data.tid = tid;
827 if (thread_data.gpregset.GetByteSize() == 0)
828 return llvm::createStringError(
829 "Could not find general purpose registers note in core file.");
830 had_nt_regs = true;
831 } else if (note.info.n_type == NETBSD::AMD64::NT_FPREGS) {
832 if (!had_nt_regs || tid != thread_data.tid)
833 return llvm::createStringError(
834 "Error parsing NetBSD core(5) notes: Unexpected order "
835 "of NOTEs PT_GETFPREG before PT_GETREG");
836 thread_data.notes.push_back(note);
837 }
838 } break;
839 default:
840 break;
841 }
842 }
843 }
844
845 // Push the last thread.
846 if (had_nt_regs)
847 m_thread_data.push_back(thread_data);
848
849 if (m_thread_data.empty())
850 return llvm::createStringError(
851 "Error parsing NetBSD core(5) notes: No threads information "
852 "specified in notes");
853
854 if (m_thread_data.size() != nlwps)
855 return llvm::createStringError(
856 "Error parsing NetBSD core(5) notes: Mismatch between the number "
857 "of LWPs in netbsd_elfcore_procinfo and the number of LWPs specified "
858 "by MD notes");
859
860 // Signal targeted at the whole process.
861 if (siglwp == 0) {
862 for (auto &data : m_thread_data)
863 data.signo = signo;
864 }
865 // Signal destined for a particular LWP.
866 else {
867 bool passed = false;
868
869 for (auto &data : m_thread_data) {
870 if (data.tid == siglwp) {
871 data.signo = signo;
872 passed = true;
873 break;
874 }
875 }
876
877 if (!passed)
878 return llvm::createStringError(
879 "Error parsing NetBSD core(5) notes: Signal passed to unknown LWP");
880 }
881
882 return llvm::Error::success();
883}
884
885llvm::Error ProcessElfCore::parseOpenBSDNotes(llvm::ArrayRef<CoreNote> notes) {
886 ThreadData thread_data = {};
887 for (const auto &note : notes) {
888 // OpenBSD per-thread information is stored in notes named "OpenBSD@nnn" so
889 // match on the initial part of the string.
890 if (!llvm::StringRef(note.info.n_name).starts_with("OpenBSD"))
891 continue;
892
893 switch (note.info.n_type) {
895 ParseOpenBSDProcInfo(thread_data, note.data);
896 break;
897 case OPENBSD::NT_AUXV:
898 m_auxv = note.data;
899 break;
900 case OPENBSD::NT_REGS:
901 thread_data.gpregset = note.data;
902 break;
903 default:
904 thread_data.notes.push_back(note);
905 break;
906 }
907 }
908 if (thread_data.gpregset.GetByteSize() == 0) {
909 return llvm::createStringError(
910 "Could not find general purpose registers note in core file.");
911 }
912 m_thread_data.push_back(thread_data);
913 return llvm::Error::success();
914}
915
916/// A description of a linux process usually contains the following NOTE
917/// entries:
918/// - NT_PRPSINFO - General process information like pid, uid, name, ...
919/// - NT_SIGINFO - Information about the signal that terminated the process
920/// - NT_AUXV - Process auxiliary vector
921/// - NT_FILE - Files mapped into memory
922///
923/// Additionally, for each thread in the process the core file will contain at
924/// least the NT_PRSTATUS note, containing the thread id and general purpose
925/// registers. It may include additional notes for other register sets (floating
926/// point and vector registers, ...). The tricky part here is that some of these
927/// notes have "CORE" in their owner fields, while other set it to "LINUX".
928llvm::Error ProcessElfCore::parseLinuxNotes(llvm::ArrayRef<CoreNote> notes) {
929 const ArchSpec &arch = GetArchitecture();
930 bool have_prstatus = false;
931 bool have_prpsinfo = false;
932 ThreadData thread_data;
933 for (const auto &note : notes) {
934 if (note.info.n_name != "CORE" && note.info.n_name != "LINUX")
935 continue;
936
937 if ((note.info.n_type == ELF::NT_PRSTATUS && have_prstatus) ||
938 (note.info.n_type == ELF::NT_PRPSINFO && have_prpsinfo)) {
939 assert(thread_data.gpregset.GetByteSize() > 0);
940 // Add the new thread to thread list
941 m_thread_data.push_back(thread_data);
942 thread_data = ThreadData();
943 have_prstatus = false;
944 have_prpsinfo = false;
945 }
946
947 switch (note.info.n_type) {
948 case ELF::NT_PRSTATUS: {
949 have_prstatus = true;
950 ELFLinuxPrStatus prstatus;
951 Status status = prstatus.Parse(note.data, arch);
952 if (status.Fail())
953 return status.ToError();
954 thread_data.prstatus_sig = prstatus.pr_cursig;
955 thread_data.tid = prstatus.pr_pid;
956 uint32_t header_size = ELFLinuxPrStatus::GetSize(arch);
957 size_t len = note.data.GetByteSize() - header_size;
958 thread_data.gpregset = DataExtractor(note.data, header_size, len);
959 break;
960 }
961 case ELF::NT_PRPSINFO: {
962 have_prpsinfo = true;
963 ELFLinuxPrPsInfo prpsinfo;
964 Status status = prpsinfo.Parse(note.data, arch);
965 if (status.Fail())
966 return status.ToError();
967 thread_data.name.assign (prpsinfo.pr_fname, strnlen (prpsinfo.pr_fname, sizeof (prpsinfo.pr_fname)));
968 SetID(prpsinfo.pr_pid);
969 m_executable_name = thread_data.name;
970 break;
971 }
972 case ELF::NT_SIGINFO: {
973 lldb::offset_t size = note.data.GetByteSize();
974 lldb::offset_t offset = 0;
975 const char *bytes =
976 static_cast<const char *>(note.data.GetData(&offset, size));
977 thread_data.siginfo_bytes = llvm::StringRef(bytes, size);
978 break;
979 }
980 case ELF::NT_FILE: {
981 m_nt_file_entries.clear();
982 lldb::offset_t offset = 0;
983 const uint64_t count = note.data.GetAddress(&offset);
984 note.data.GetAddress(&offset); // Skip page size
985 for (uint64_t i = 0; i < count; ++i) {
986 NT_FILE_Entry entry;
987 entry.start = note.data.GetAddress(&offset);
988 entry.end = note.data.GetAddress(&offset);
989 entry.file_ofs = note.data.GetAddress(&offset);
990 m_nt_file_entries.push_back(entry);
991 }
992 for (uint64_t i = 0; i < count; ++i) {
993 const char *path = note.data.GetCStr(&offset);
994 if (path && path[0])
995 m_nt_file_entries[i].path.assign(path);
996 }
997 break;
998 }
999 case ELF::NT_AUXV:
1000 m_auxv = note.data;
1001 break;
1002 default:
1003 thread_data.notes.push_back(note);
1004 break;
1005 }
1006 }
1007 // Add last entry in the note section
1008 if (have_prstatus)
1009 m_thread_data.push_back(thread_data);
1010 return llvm::Error::success();
1011}
1012
1013/// Parse Thread context from PT_NOTE segment and store it in the thread list
1014/// A note segment consists of one or more NOTE entries, but their types and
1015/// meaning differ depending on the OS.
1017 const elf::ELFProgramHeader &segment_header,
1018 const DataExtractor &segment_data) {
1019 assert(segment_header.p_type == llvm::ELF::PT_NOTE);
1020
1021 auto notes_or_error = parseSegment(segment_data);
1022 if(!notes_or_error)
1023 return notes_or_error.takeError();
1024 switch (GetArchitecture().GetTriple().getOS()) {
1025 case llvm::Triple::FreeBSD:
1026 return parseFreeBSDNotes(*notes_or_error);
1027 case llvm::Triple::Linux:
1028 return parseLinuxNotes(*notes_or_error);
1029 case llvm::Triple::NetBSD:
1030 return parseNetBSDNotes(*notes_or_error);
1031 case llvm::Triple::OpenBSD:
1032 return parseOpenBSDNotes(*notes_or_error);
1033 default:
1034 return llvm::createStringError(
1035 "Don't know how to parse core file. Unsupported OS.");
1036 }
1037}
1038
1040 UUID invalid_uuid;
1041 const uint32_t addr_size = GetAddressByteSize();
1042 const size_t elf_header_size = addr_size == 4 ? sizeof(llvm::ELF::Elf32_Ehdr)
1043 : sizeof(llvm::ELF::Elf64_Ehdr);
1044
1045 std::vector<uint8_t> elf_header_bytes;
1046 elf_header_bytes.resize(elf_header_size);
1047 Status error;
1048 size_t byte_read =
1049 ReadMemory(address, elf_header_bytes.data(), elf_header_size, error);
1050 if (byte_read != elf_header_size ||
1051 !elf::ELFHeader::MagicBytesMatch(elf_header_bytes.data()))
1052 return invalid_uuid;
1053 DataExtractor elf_header_data(elf_header_bytes.data(), elf_header_size,
1054 GetByteOrder(), addr_size);
1055 lldb::offset_t offset = 0;
1056
1057 elf::ELFHeader elf_header;
1058 elf_header.Parse(elf_header_data, &offset);
1059
1060 const lldb::addr_t ph_addr = address + elf_header.e_phoff;
1061
1062 std::vector<uint8_t> ph_bytes;
1063 ph_bytes.resize(elf_header.e_phentsize);
1064 lldb::addr_t base_addr = 0;
1065 bool found_first_load_segment = false;
1066 for (unsigned int i = 0; i < elf_header.e_phnum; ++i) {
1067 byte_read = ReadMemory(ph_addr + i * elf_header.e_phentsize,
1068 ph_bytes.data(), elf_header.e_phentsize, error);
1069 if (byte_read != elf_header.e_phentsize)
1070 break;
1071 DataExtractor program_header_data(ph_bytes.data(), elf_header.e_phentsize,
1072 GetByteOrder(), addr_size);
1073 offset = 0;
1074 elf::ELFProgramHeader program_header;
1075 program_header.Parse(program_header_data, &offset);
1076 if (program_header.p_type == llvm::ELF::PT_LOAD &&
1077 !found_first_load_segment) {
1078 base_addr = program_header.p_vaddr;
1079 found_first_load_segment = true;
1080 }
1081 if (program_header.p_type != llvm::ELF::PT_NOTE)
1082 continue;
1083
1084 std::vector<uint8_t> note_bytes;
1085 note_bytes.resize(program_header.p_memsz);
1086
1087 // We need to slide the address of the p_vaddr as these values don't get
1088 // relocated in memory.
1089 const lldb::addr_t vaddr = program_header.p_vaddr + address - base_addr;
1090 byte_read =
1091 ReadMemory(vaddr, note_bytes.data(), program_header.p_memsz, error);
1092 if (byte_read != program_header.p_memsz)
1093 continue;
1094 DataExtractor segment_data(note_bytes.data(), note_bytes.size(),
1095 GetByteOrder(), addr_size);
1096 auto notes_or_error = parseSegment(segment_data);
1097 if (!notes_or_error) {
1098 llvm::consumeError(notes_or_error.takeError());
1099 return invalid_uuid;
1100 }
1101 for (const CoreNote &note : *notes_or_error) {
1102 if (note.info.n_namesz == 4 &&
1103 note.info.n_type == llvm::ELF::NT_GNU_BUILD_ID &&
1104 "GNU" == note.info.n_name &&
1105 note.data.ValidOffsetForDataOfSize(0, note.info.n_descsz))
1106 return UUID(note.data.GetData().take_front(note.info.n_descsz));
1107 }
1108 }
1109 return invalid_uuid;
1110}
1111
1114 DoLoadCore();
1115 return m_thread_data.size();
1116}
1117
1119 ArchSpec arch = m_core_module_sp->GetObjectFile()->GetArchitecture();
1120
1121 ArchSpec target_arch = GetTarget().GetArchitecture();
1122 arch.MergeFrom(target_arch);
1123
1124 // On MIPS there is no way to differentiate betwenn 32bit and 64bit core
1125 // files and this information can't be merged in from the target arch so we
1126 // fail back to unconditionally returning the target arch in this config.
1127 if (target_arch.IsMIPS()) {
1128 return target_arch;
1129 }
1130
1131 return arch;
1132}
1133
1135 assert(m_auxv.GetByteSize() == 0 ||
1136 (m_auxv.GetByteOrder() == GetByteOrder() &&
1137 m_auxv.GetAddressByteSize() == GetAddressByteSize()));
1138 return DataExtractor(m_auxv);
1139}
1140
1142 info.Clear();
1143 info.SetProcessID(GetID());
1146 if (module_sp) {
1147 const bool add_exe_file_as_first_arg = false;
1148 info.SetExecutableFile(GetTarget().GetExecutableModule()->GetFileSpec(),
1149 add_exe_file_as_first_arg);
1150 }
1151 return true;
1152}
static llvm::raw_ostream & error(Stream &strm)
static llvm::raw_ostream & note(Stream &strm)
#define LLDB_LOGF(log,...)
Definition Log.h:383
#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
MemoryRegionInfo & SetMemoryTagged(LazyBool 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:442
@ 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:3706
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:2188
void SetCanJIT(bool can_jit)
Sets whether executing JIT-compiled code in this process is possible.
Definition Process.cpp:2557
lldb::DynamicLoaderUP m_dyld_up
Definition Process.h:3399
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:6577
lldb::ByteOrder GetByteOrder() const
Definition Process.cpp:3716
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:2594
void SetID(lldb::pid_t new_pid)
Sets the stored pid.
Definition Process.h:542
uint32_t GetAddressByteSize() const
Definition Process.cpp:3720
virtual void Finalize(bool destructing)
This object is about to be destroyed, do any necessary cleanup.
Definition Process.cpp:535
ThreadList m_thread_list
The threads for this process as the user will see them.
Definition Process.h:3372
const lldb::UnixSignalsSP & GetUnixSignals()
Definition Process.cpp:3711
const lldb::ABISP & GetABI()
Definition Process.cpp:1452
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:2347
bool SetArchitecture(const ArchSpec &arch_spec, bool set_platform=false, bool merge=true)
Set the architecture for this target.
Definition Target.cpp:1700
lldb::ModuleSP GetExecutableModule()
Gets the module for the main executable.
Definition Target.cpp:1525
const ArchSpec & GetArchitecture() const
Definition Target.h:1182
void SetExecutableModule(lldb::ModuleSP &module_sp, LoadDependentFiles load_dependent_files=eLoadDependentsDefault)
Set the main executable module.
Definition Target.cpp:1571
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